rivet is hosted by Hepforge, IPPP Durham
Rivet  2.7.0
ProjectionApplier.hh
1 // -*- C++ -*-
2 #ifndef RIVET_ProjectionApplier_HH
3 #define RIVET_ProjectionApplier_HH
4 
5 #include "Rivet/Config/RivetCommon.hh"
6 #include "Rivet/Projection.fhh"
7 #include "Rivet/ProjectionHandler.hh"
8 #include "Rivet/Tools/Logging.hh"
9 
10 namespace Rivet {
11 
12 
13  // Forward declarations
14  class Event;
15 
16 
22  public:
23 
24  // The proj handler needs access to reset the _allowProjReg flag before calling a.init()
25  // friend class ProjectionHandler;
26 
29 
30  // Virtual destructor: ensure that inheritance is possible.
31  virtual ~ProjectionApplier();
32 
33 
35 
36  virtual std::string name() const = 0;
39 
41 
42 
44  std::set<ConstProjectionPtr> getProjections() const {
45  return getProjHandler().getChildProjections(*this, ProjectionHandler::DEEP);
46  }
47 
49  bool hasProjection(const std::string& name) const {
50  return getProjHandler().hasProjection(*this, name);
51  }
52 
55  template <typename PROJ>
56  const PROJ& getProjection(const std::string& name) const {
57  const Projection& p = getProjHandler().getProjection(*this, name);
58  return pcast<PROJ>(p);
59  }
62  template <typename PROJ>
63  const PROJ& get(const std::string& name) const { return getProjection<PROJ>(name); }
64 
67  const Projection& getProjection(const std::string& name) const {
68  return getProjHandler().getProjection(*this, name);
69  }
70 
72 
73 
75 
76 
78  template <typename PROJ>
80  const PROJ& applyProjection(const Event& evt, const Projection& proj) const {
81  return pcast<PROJ>(_applyProjection(evt, proj));
82  }
85  template <typename PROJ>
86  const PROJ& apply(const Event& evt, const Projection& proj) const { return applyProjection<PROJ>(evt, proj); }
87 
88 
90  template <typename PROJ>
92  const PROJ& applyProjection(const Event& evt, const PROJ& proj) const {
93  return pcast<PROJ>(_applyProjection(evt, proj));
94  }
97  template <typename PROJ>
98  const PROJ& apply(const Event& evt, const PROJ& proj) const { return applyProjection<PROJ>(evt, proj); }
99 
100 
103  template <typename PROJ>
104  const PROJ& applyProjection(const Event& evt, const std::string& name) const {
105  return pcast<PROJ>(_applyProjection(evt, name));
106  }
109  template <typename PROJ>
110  const PROJ& apply(const Event& evt, const std::string& name) const { return applyProjection<PROJ>(evt, name); }
113  template <typename PROJ>
114  const PROJ& apply(const std::string& name, const Event& evt) const { return applyProjection<PROJ>(evt, name); }
115 
117 
118 
120  void markAsOwned() const { _owned = true; }
121 
122 
123  protected:
124 
125  Log& getLog() const {
126  return Log::getLog("Rivet.ProjectionHandler");
127  }
128 
129 
132  return _projhandler;
133  }
134 
135 
137 
138 
150  template <typename PROJ>
151  const PROJ& declareProjection(const PROJ& proj, const std::string& name) {
152  const Projection& reg = _declareProjection(proj, name);
153  const PROJ& rtn = dynamic_cast<const PROJ&>(reg);
154  return rtn;
155  }
156 
159  template <typename PROJ>
160  const PROJ& declare(const PROJ& proj, const std::string& name) { return declareProjection(proj, name); }
163  template <typename PROJ>
164  const PROJ& declare(const std::string& name, const PROJ& proj) { return declareProjection(proj, name); }
165 
169  template <typename PROJ>
170  const PROJ& addProjection(const PROJ& proj, const std::string& name) { return declareProjection(proj, name); }
171 
172 
174  const Projection& _declareProjection(const Projection& proj, const std::string& name);
175 
177 
178 
181  const Projection& _applyProjection(const Event& evt, const std::string& name) const;
182 
185  const Projection& _applyProjection(const Event& evt, const Projection& proj) const;
186 
187 
189  bool _allowProjReg;
190 
191 
192  private:
193 
195  mutable bool _owned;
196 
198  ProjectionHandler& _projhandler;
199 
200  };
201 
202 
203 }
204 
205 #endif
Definition: ALICE_2010_I880049.cc:13
bool hasProjection(const std::string &name) const
Does this applier have a projection registered under the name name?
Definition: ProjectionApplier.hh:49
const PROJ & applyProjection(const Event &evt, const Projection &proj) const
Apply the supplied projection on event evt.
Definition: ProjectionApplier.hh:80
void markAsOwned() const
Mark this object as owned by a proj-handler.
Definition: ProjectionApplier.hh:120
set< const Projection * > getChildProjections(const ProjectionApplier &parent, ProjDepth depth=SHALLOW) const
Definition: ProjectionHandler.cc:209
const PROJ & apply(const std::string &name, const Event &evt) const
Definition: ProjectionApplier.hh:114
const PROJ & apply(const Event &evt, const PROJ &proj) const
Definition: ProjectionApplier.hh:98
std::set< ConstProjectionPtr > getProjections() const
Get the contained projections, including recursion.
Definition: ProjectionApplier.hh:44
const PROJ & applyProjection(const Event &evt, const std::string &name) const
Definition: ProjectionApplier.hh:104
const PROJ & apply(const Event &evt, const std::string &name) const
Definition: ProjectionApplier.hh:110
static Log & getLog(const std::string &name)
Definition: Logging.cc:55
Definition: Logging.hh:9
virtual std::string name() const =0
Get the name of this Projection or Analysis class.
The projection handler is a central repository for projections to be used in a Rivet analysis run...
Definition: ProjectionHandler.hh:39
const PROJ & declareProjection(const PROJ &proj, const std::string &name)
Register a contained projection.
Definition: ProjectionApplier.hh:151
Definition: Event.hh:22
ProjectionHandler & getProjHandler() const
Get a reference to the ProjectionHandler for this thread.
Definition: ProjectionApplier.hh:131
const Projection & getProjection(const ProjectionApplier &parent, const string &name) const
Definition: ProjectionHandler.cc:241
Common base class for Projection and Analysis, used for internal polymorphism.
Definition: ProjectionApplier.hh:21
const PROJ & apply(const Event &evt, const Projection &proj) const
Definition: ProjectionApplier.hh:86
const PROJ & getProjection(const std::string &name) const
Definition: ProjectionApplier.hh:56
const Projection & getProjection(const std::string &name) const
Definition: ProjectionApplier.hh:67
const PROJ & declare(const PROJ &proj, const std::string &name)
Register a contained projection (user-facing version)
Definition: ProjectionApplier.hh:160
const PROJ & addProjection(const PROJ &proj, const std::string &name)
Register a contained projection (user-facing version)
Definition: ProjectionApplier.hh:170
const PROJ & applyProjection(const Event &evt, const PROJ &proj) const
Apply the supplied projection on event evt.
Definition: ProjectionApplier.hh:92
bool hasProjection(const ProjectionApplier &parent, const string &name) const
Check if there is a name projection registered by parent.
Definition: ProjectionHandler.cc:232
ProjectionApplier()
Constructor.
Definition: ProjectionApplier.cc:10
const PROJ & declare(const std::string &name, const PROJ &proj)
Register a contained projection (user-facing, arg-reordered version)
Definition: ProjectionApplier.hh:164
Base class for all Rivet projections.
Definition: Projection.hh:29