Belle II Software development
GlobalLabel.h
1/**************************************************************************
2 * basf2 (Belle II Analysis Software Framework) *
3 * Author: The Belle II Collaboration *
4 * *
5 * See git log for contributors and copyright holders. *
6 * This file is licensed under LGPL-3.0, see LICENSE.md. *
7 **************************************************************************/
8
9#pragma once
10
11#include <map>
12#include <set>
13
14namespace Belle2 {
42
43 public:
44
45 typedef unsigned int gidTYPE;
46 static const gidTYPE maxPID = 99;
47 static const gidTYPE maxEID = 9999999;
48 static const gidTYPE maxTIF = 1;
49 static const gidTYPE maxTEID = 9999;
50 static const gidTYPE maxTID = 999;
51 static const gidTYPE pidOffset = 1;
52 static const gidTYPE eidOffest = pidOffset * (maxPID + 1);
53 static const gidTYPE tifOffset = eidOffest * (maxEID + 1);
54 static const gidTYPE teidOffset = eidOffest;
55 static const gidTYPE tidOffset = eidOffest * (maxTEID + 1);
57 maxTIF;
58 static const gidTYPE maxLabel =
59 maxGID;
63
71 explicit GlobalLabel(gidTYPE globalLabel);
72
80 template<class DBObjType>
81 static GlobalLabel construct(gidTYPE element, gidTYPE param)
82 {
83 GlobalLabel theLabel;
84 theLabel.construct(DBObjType::getGlobalUniqueID(), element, param);
85 return theLabel;
86 }
87
95 void construct(gidTYPE dbObjId, gidTYPE element, gidTYPE param)
96 {
97 if (m_components.empty() or m_components.find(dbObjId) != m_components.end())
98 construct(100000 * dbObjId + element, param);
99 else
100 construct(0, 0);
101 }
102
107 static void setComponents(const std::set<unsigned short>& components)
108 {
109 m_components = components;
110 }
111
126 void registerTimeDependent(gidTYPE start, gidTYPE end = maxTID);
127
135
141 int label() {return gid;}
142
146 operator int() {return (int)label();}
147
151 operator unsigned int() {return (unsigned int)label();}
152
156 gidTYPE getUniqueId() const {return eid / 100000;}
157
161 gidTYPE getElementId() const {return eid % 100000;}
162
164 gidTYPE getParameterId() const {return pid;}
165
167 gidTYPE getTimeId() const {return tid;}
168
170 bool getTimeFlag() const {return tif;}
171
173 bool isValid() {return 0 != gid;}
174
176 void dump(int level = 0) const;
177
180 {
181 if (!tif)
182 return maxTID;
184 if (it == GlobalLabel::getTimeIntervals().end())
185 return tid;
186 for (unsigned int i = tid; i < maxTID; i++) {
187 if (it->second.get(i) != tid)
188 return i - 1;
189 }
190 return tid;
191 }
192
196 static void clearTimeDependentParamaters();
197
199 static unsigned int& getCurrentTimeIntervalRef()
200 {
201 static unsigned int subrun = 0;
202 return subrun;
203 }
204
208 {
210 timeref = time;
211 }
212
215 {
217 }
218
219 private:
221 static std::set<unsigned short> m_components;
222
226 void construct(gidTYPE elementId, gidTYPE paramId);
227
228 public:
231
232 private:
233
236
239
240 public:
241
246 TimeInterval(gidTYPE TEIDPID, gidTYPE start, gidTYPE end)
247 {
248 teidpid_ = TEIDPID;
249 for (gidTYPE i = 0; i <= maxTID; i++) {
250 if (i >= start && i <= end)
251 arr_[i] = start;
252 else
253 arr_[i] = 0;
254 }
255 }
256
259
261 gidTYPE get(gidTYPE timeid) {return arr_[timeid];}
262
264 void set(gidTYPE start, gidTYPE end)
265 {
266 for (gidTYPE i = 0; i <= maxTID; i++) {
267 if (i >= start && i <= end)
268 arr_[i] = start;
269 }
270 }
271 };
272 public:
274 static std::map<gidTYPE, TimeInterval >& getTimeIntervals()
275 {
276 // Map EIDPID -> (TEIDPID, time intervals)
277 static std::map<gidTYPE, TimeInterval > intervals;
278 return intervals;
279 }
280
282 static std::map<gidTYPE, gidTYPE>& getDictionary()
283 {
284 // Map TEIDPID -> EIDPID
285 static std::map<gidTYPE, gidTYPE> dictionary;
286 return dictionary;
287 }
288
290 gidTYPE makeEIDPID(gidTYPE eid_, gidTYPE pid_) {return pid_ * pidOffset + eid_ * eidOffest;}
291
293 gidTYPE makeTEIDPID(gidTYPE teid_, gidTYPE pid_) {return pid_ * pidOffset + teid_ * teidOffset;}
294 private:
297
300
303
306
309
310 };
311
313}
Class to convert to/from global labels for Millepede II to/from detector & parameter identificators.
Definition: GlobalLabel.h:41
static const gidTYPE tidOffset
Offset of time slice id = 1.000.000.
Definition: GlobalLabel.h:55
static gidTYPE getCurrentTimeInterval()
Get current time id.
Definition: GlobalLabel.h:214
int label()
Returns encoded Pede label.
Definition: GlobalLabel.h:141
static void clearTimeDependentParamaters()
Forget all previously registered time dependent parameters.
Definition: GlobalLabel.cc:66
gidTYPE tid
time id
Definition: GlobalLabel.h:305
static const gidTYPE maxTEID
max time-dep.
Definition: GlobalLabel.h:49
static const gidTYPE maxEID
max 9.999.999 detector elements 1..9999999 (NOT time-dep-)
Definition: GlobalLabel.h:47
gidTYPE setParameterId(gidTYPE paramId)
Usefull setter to quickly change only the parameter id and return back the encoded label (for use in ...
Definition: GlobalLabel.cc:72
static const gidTYPE eidOffest
Offset of detector element id = 100.
Definition: GlobalLabel.h:52
gidTYPE gid
global id
Definition: GlobalLabel.h:296
gidTYPE getUniqueId() const
Returns the global id identifing DB object for constantwith this label.
Definition: GlobalLabel.h:156
static std::map< gidTYPE, gidTYPE > & getDictionary()
Reference to dictionary/map TEIDPID -> EIDPID.
Definition: GlobalLabel.h:282
void dump(int level=0) const
Dumps the label to std::cout.
Definition: GlobalLabel.cc:128
static const gidTYPE teidOffset
Offset of time dependent element(detector+parameter) = 100.
Definition: GlobalLabel.h:54
GlobalLabel()
Default constuctor. Members initialized in declaration.
Definition: GlobalLabel.h:62
gidTYPE getParameterId() const
Get id of alignment/calibration parameter.
Definition: GlobalLabel.h:164
static const gidTYPE maxPID
max 99 parameter types 1..99
Definition: GlobalLabel.h:46
bool getTimeFlag() const
Is label time-dependent?
Definition: GlobalLabel.h:170
unsigned int gidTYPE
shortcut for main data type (unsigned int)
Definition: GlobalLabel.h:45
gidTYPE getElementId() const
Returns the element id (like VxdID for silicon sensors) to identify sets of parameters in DB objects.
Definition: GlobalLabel.h:161
int getEndOfValidity()
Get the last time id, where this label is valid.
Definition: GlobalLabel.h:179
static const gidTYPE maxTID
max time slices for a parameter 1..999
Definition: GlobalLabel.h:50
static void setCurrentTimeInterval(gidTYPE time)
Sets current time id.
Definition: GlobalLabel.h:207
static GlobalLabel construct(gidTYPE element, gidTYPE param)
Construct label for given DB object (template argument) and its element and parameter.
Definition: GlobalLabel.h:81
void registerTimeDependent(gidTYPE start, gidTYPE end=maxTID)
Register this Detector element and parameter as time dependent with instance starting at "start" time...
Definition: GlobalLabel.cc:45
gidTYPE makeEIDPID(gidTYPE eid_, gidTYPE pid_)
Helper to compose elemnt id & param id.
Definition: GlobalLabel.h:290
static const gidTYPE pidOffset
parameter number are the last 2 decimal digits
Definition: GlobalLabel.h:51
gidTYPE makeTEIDPID(gidTYPE teid_, gidTYPE pid_)
Helper to compose time elemnt id & param id.
Definition: GlobalLabel.h:293
gidTYPE tif
time identification flag
Definition: GlobalLabel.h:308
static const gidTYPE tifOffset
Offset of time flag = 1.000.000.000.
Definition: GlobalLabel.h:53
gidTYPE eid
element id
Definition: GlobalLabel.h:299
static const gidTYPE maxLabel
Label and internal id ("gid") are the same numbers (label is signed but 0 and <0 values are invalid t...
Definition: GlobalLabel.h:58
static unsigned int & getCurrentTimeIntervalRef()
Returns reference to current time id.
Definition: GlobalLabel.h:199
static std::map< gidTYPE, TimeInterval > & getTimeIntervals()
Reference to map EIDPID -> (TEIDPID, time intervals)
Definition: GlobalLabel.h:274
static const gidTYPE maxTIF
time-dep.
Definition: GlobalLabel.h:48
static std::set< unsigned short > m_components
Set of global ids of components for which to return non-zero labels.
Definition: GlobalLabel.h:221
void construct(gidTYPE dbObjId, gidTYPE element, gidTYPE param)
Construct label for given DB object id and its element and parameter.
Definition: GlobalLabel.h:95
static const gidTYPE maxGID
max internal id = 1.999.999.999
Definition: GlobalLabel.h:56
gidTYPE getTimeId() const
Get time id.
Definition: GlobalLabel.h:167
static void setComponents(const std::set< unsigned short > &components)
Set which DB objects have non-zero labels (by their id)
Definition: GlobalLabel.h:107
gidTYPE pid
parameter id
Definition: GlobalLabel.h:302
bool isValid()
Is label valid? (non-zero)
Definition: GlobalLabel.h:173
Abstract base class for different kinds of events.
Struct to hold intervals of validity.
Definition: GlobalLabel.h:230
gidTYPE get(gidTYPE timeid)
Get the start time id for validity interval valid at given timeid.
Definition: GlobalLabel.h:261
void set(gidTYPE start, gidTYPE end)
Set new parameter validity interval from start to end.
Definition: GlobalLabel.h:264
gidTYPE teidpid_
Time element id & parameter id.
Definition: GlobalLabel.h:235
gidTYPE arr_[maxTID+1]
Array of time ids.
Definition: GlobalLabel.h:238
gidTYPE teidpid()
Get composed time element id & param id.
Definition: GlobalLabel.h:258
TimeInterval(gidTYPE TEIDPID, gidTYPE start, gidTYPE end)
Constructor for given validity interval.
Definition: GlobalLabel.h:246