rivet is hosted by Hepforge, IPPP Durham
Rivet 3.1.6
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
10namespace 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
37 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
80 template <typename PROJ=Projection>
81 typename std::enable_if_t<std::is_base_of<Projection, PROJ>::value, const PROJ&>
82 applyProjection(const Event& evt, const Projection& proj) const {
83 return pcast<PROJ>(_applyProjection(evt, proj));
84 }
85
87 template <typename PROJ=Projection>
88 typename std::enable_if_t<std::is_base_of<Projection, PROJ>::value, const PROJ&>
89 apply(const Event& evt, const Projection& proj) const { return applyProjection<PROJ>(evt, proj); }
90
91
95 template <typename PROJ=Projection>
96 typename std::enable_if_t<std::is_base_of<Projection, PROJ>::value, const PROJ&>
97 applyProjection(const Event& evt, const PROJ& proj) const {
98 return pcast<PROJ>(_applyProjection(evt, proj));
99 }
100
102 template <typename PROJ=Projection>
103 typename std::enable_if_t<std::is_base_of<Projection, PROJ>::value, const PROJ&>
104 apply(const Event& evt, const PROJ& proj) const { return applyProjection<PROJ>(evt, proj); }
105
106
110 template <typename PROJ=Projection>
111 typename std::enable_if_t<std::is_base_of<Projection, PROJ>::value, const PROJ&>
112 applyProjection(const Event& evt, const std::string& name) const {
113 return pcast<PROJ>(_applyProjection(evt, name));
114 }
115
117 template <typename PROJ=Projection>
118 typename std::enable_if_t<std::is_base_of<Projection, PROJ>::value, const PROJ&>
119 apply(const Event& evt, const std::string& name) const { return applyProjection<PROJ>(evt, name); }
120
122 template <typename PROJ=Projection>
123 typename std::enable_if_t<std::is_base_of<Projection, PROJ>::value, const PROJ&>
124 apply(const std::string& name, const Event& evt) const { return applyProjection<PROJ>(evt, name); }
125
127
128
130 void markAsOwned() const { _owned = true; }
131
132
133 protected:
134
135 Log& getLog() const {
136 return Log::getLog("Rivet.ProjectionHandler");
137 }
138
139
142 return _projhandler;
143 }
144
145
147
148
160 template <typename PROJ>
161 const PROJ& declareProjection(const PROJ& proj, const std::string& name) {
162 const Projection& reg = _declareProjection(proj, name);
163 const PROJ& rtn = dynamic_cast<const PROJ&>(reg);
164 return rtn;
165 }
166
169 template <typename PROJ>
170 const PROJ& declare(const PROJ& proj, const std::string& name) { return declareProjection(proj, name); }
173 template <typename PROJ>
174 const PROJ& declare(const std::string& name, const PROJ& proj) { return declareProjection(proj, name); }
175
176
178 const Projection& _declareProjection(const Projection& proj, const std::string& name);
179
181
182
185 const Projection& _applyProjection(const Event& evt, const std::string& name) const;
186
189 const Projection& _applyProjection(const Event& evt, const Projection& proj) const;
190
191
193 bool _allowProjReg;
194
195
196 private:
197
199 mutable bool _owned;
200
202 ProjectionHandler& _projhandler;
203
204 };
205
206
207}
208
209#endif
Representation of a HepMC event, and enabler of Projection caching.
Definition: Event.hh:22
Logging system for controlled & formatted writing to stdout.
Definition: Logging.hh:10
static Log & getLog(const std::string &name)
Common base class for Projection and Analysis, used for internal polymorphism.
Definition: ProjectionApplier.hh:21
const Projection & getProjection(const std::string &name) const
Definition: ProjectionApplier.hh:67
std::enable_if_t< std::is_base_of< Projection, PROJ >::value, const PROJ & > applyProjection(const Event &evt, const Projection &proj) const
Definition: ProjectionApplier.hh:82
const PROJ & get(const std::string &name) const
Definition: ProjectionApplier.hh:63
const PROJ & getProjection(const std::string &name) const
Definition: ProjectionApplier.hh:56
const PROJ & declare(const PROJ &proj, const std::string &name)
Register a contained projection (user-facing version)
Definition: ProjectionApplier.hh:170
std::set< ConstProjectionPtr > getProjections() const
Get the contained projections, including recursion.
Definition: ProjectionApplier.hh:44
std::enable_if_t< std::is_base_of< Projection, PROJ >::value, const PROJ & > apply(const std::string &name, const Event &evt) const
Apply the supplied projection on event evt (convenience arg-reordering alias).
Definition: ProjectionApplier.hh:124
ProjectionHandler & getProjHandler() const
Get a reference to the ProjectionHandler for this thread.
Definition: ProjectionApplier.hh:141
std::enable_if_t< std::is_base_of< Projection, PROJ >::value, const PROJ & > applyProjection(const Event &evt, const std::string &name) const
Definition: ProjectionApplier.hh:112
std::enable_if_t< std::is_base_of< Projection, PROJ >::value, const PROJ & > apply(const Event &evt, const Projection &proj) const
Apply the supplied projection on event evt (user-facing alias).
Definition: ProjectionApplier.hh:89
const PROJ & declareProjection(const PROJ &proj, const std::string &name)
Register a contained projection.
Definition: ProjectionApplier.hh:161
const PROJ & declare(const std::string &name, const PROJ &proj)
Register a contained projection (user-facing, arg-reordered version)
Definition: ProjectionApplier.hh:174
std::enable_if_t< std::is_base_of< Projection, PROJ >::value, const PROJ & > apply(const Event &evt, const PROJ &proj) const
Apply the supplied projection on event evt (user-facing alias).
Definition: ProjectionApplier.hh:104
bool hasProjection(const std::string &name) const
Does this applier have a projection registered under the name name?
Definition: ProjectionApplier.hh:49
void markAsOwned() const
Mark this object as owned by a proj-handler.
Definition: ProjectionApplier.hh:130
std::enable_if_t< std::is_base_of< Projection, PROJ >::value, const PROJ & > applyProjection(const Event &evt, const PROJ &proj) const
Definition: ProjectionApplier.hh:97
std::enable_if_t< std::is_base_of< Projection, PROJ >::value, const PROJ & > apply(const Event &evt, const std::string &name) const
Apply the supplied projection on event evt (user-facing alias).
Definition: ProjectionApplier.hh:119
virtual std::string name() const =0
Get the name of this Projection or Analysis class.
ProjectionApplier()
Constructor.
The projection handler is a central repository for projections to be used in a Rivet analysis run.
Definition: ProjectionHandler.hh:43
const Projection & getProjection(const ProjectionApplier &parent, const string &name) const
set< const Projection * > getChildProjections(const ProjectionApplier &parent, ProjDepth depth=SHALLOW) const
bool hasProjection(const ProjectionApplier &parent, const string &name) const
Check if there is a name projection registered by parent.
Base class for all Rivet projections.
Definition: Projection.hh:29
double p(const ParticleBase &p)
Unbound function access to p.
Definition: ParticleBaseUtils.hh:653
Definition: MC_Cent_pPb.hh:10