rivet is hosted by Hepforge, IPPP Durham
Rivet 3.1.6
ProjectionHandler.hh
1// -*- C++ -*-
2#ifndef RIVET_ProjectionHandler_HH
3#define RIVET_ProjectionHandler_HH
4
5// @todo all thread/mutex code belongs to a temporary fix to allow for
6// basic threading
7#include <thread>
8#include <mutex>
9#include "Rivet/Config/RivetCommon.hh"
10#include "Rivet/Projection.fhh"
11
12namespace Rivet {
13
14
16 typedef std::shared_ptr<const Projection> ProjHandle;
17
18 // Forward declaration.
20
44 public:
45
47 friend class ProjectionApplier;
48
50 typedef set<ProjHandle> ProjHandles;
51
54 typedef map<string, ProjHandle> NamedProjs;
55
57 enum ProjDepth { SHALLOW, DEEP };
58
59
60 private:
61
64 typedef map<const ProjectionApplier*, NamedProjs> NamedProjsMap;
65
68 NamedProjsMap _namedprojs;
69
72 ProjHandles _projs;
73
74
75 public:
76
78
79
81 ~ProjectionHandler() = default;
82
85
88
90 ProjectionHandler() = default;
91
93
94 // @todo the following is a temporary fix to allow for basic
95 // threading. The proper fix will involve the AnalysisHandler
96 // having it's own ProjectionHandler object.
97
98 // private:
99 public:
100
102 static std::mutex mtx;
103 static ProjectionHandler& getInstance() {
104 // static ProjectionHandler _instance;
105 // return _instance;
106 std::unique_lock<std::mutex> lock(mtx);
107 static map<std::thread::id,ProjectionHandler> _instances;
108 return _instances[std::this_thread::get_id()];
109
110 }
111
112
113 public:
114
116
117
119 const Projection& proj,
120 const string& name);
122
123
124 private:
125
127
128
131 ProjHandle _getEquiv(const Projection& proj) const;
132
134 unique_ptr<Projection> _clone(const Projection& proj);
135
137 const Projection& _register(const ProjectionApplier& parent,
138 ProjHandle proj,
139 const string& name);
140
142 string _getStatus() const;
143
145 bool _checkDuplicate(const ProjectionApplier& parent,
146 const Projection& proj,
147 const string& name) const;
148
150
151
152 public:
153
155
156
158 bool hasProjection(const ProjectionApplier& parent, const string& name) const;
159
165 const string& name) const;
166
172 set<const Projection*> getChildProjections(const ProjectionApplier& parent,
173 ProjDepth depth=SHALLOW) const;
175
176
177 private:
178
180 void removeProjectionApplier(ProjectionApplier& parent);
181
182
183 private:
184
185 // /// Get map of named projections belonging to @a parent.
186 // /// Throws an exception if @a parent has not got any registered projections.
187 // const NamedProjs& namedProjs(const ProjectionApplier* parent) const {
188 // NamedProjsMap::const_iterator nps = _namedprojs.find(parent);
189 // if (nps == _namedprojs.end()) {
190 // stringstream ss;
191 // ss << "No NamedProjs registered for parent " << parent;
192 // throw Error(ss.str());
193 // }
194 // return *nps;
195 // }
196
197
198 };
199
200
201}
202
203#endif
Common base class for Projection and Analysis, used for internal polymorphism.
Definition: ProjectionApplier.hh:21
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
ProjectionHandler & operator=(const ProjectionHandler &)=delete
The assignment operator is hidden.
bool hasProjection(const ProjectionApplier &parent, const string &name) const
Check if there is a name projection registered by parent.
const Projection & registerProjection(const ProjectionApplier &parent, const Projection &proj, const string &name)
Attach and retrieve a projection as a reference.
static std::mutex mtx
Singleton creation function.
Definition: ProjectionHandler.hh:102
set< ProjHandle > ProjHandles
Typedef for a vector of Projection pointers.
Definition: ProjectionHandler.hh:50
ProjectionHandler()=default
The standard constructor.
ProjDepth
Enum to specify depth of projection search.
Definition: ProjectionHandler.hh:57
ProjectionHandler(const ProjectionHandler &)=delete
The copy constructor is hidden.
map< string, ProjHandle > NamedProjs
Typedef for the structure used to contain named projections for a particular containing Analysis or P...
Definition: ProjectionHandler.hh:54
~ProjectionHandler()=default
Private destructor means no inheritance from this class.
Base class for all Rivet projections.
Definition: Projection.hh:29
Definition: MC_Cent_pPb.hh:10
std::shared_ptr< const Projection > ProjHandle
Typedef for Projection (smart) pointer.
Definition: ProjectionHandler.hh:16