Belle II Software  release-08-01-10
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 
14 namespace Belle2 {
41  class GlobalLabel {
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 
96  void construct(gidTYPE dbObjId, gidTYPE element, gidTYPE param)
97  {
98  if (m_components.empty() or m_components.find(dbObjId) != m_components.end())
99  construct(100000 * dbObjId + element, param);
100  else
101  construct(0, 0);
102  }
103 
108  static void setComponents(const std::set<unsigned short>& components)
109  {
110  m_components = components;
111  }
112 
127  void registerTimeDependent(gidTYPE start, gidTYPE end = maxTID);
128 
135  gidTYPE setParameterId(gidTYPE paramId);
136 
142  int label() {return gid;}
143 
147  operator int() {return (int)label();}
148 
152  operator unsigned int() {return (unsigned int)label();}
153 
157  gidTYPE getUniqueId() const {return eid / 100000;}
158 
162  gidTYPE getElementId() const {return eid % 100000;}
163 
165  gidTYPE getParameterId() const {return pid;}
166 
168  gidTYPE getTimeId() const {return tid;}
169 
171  bool getTimeFlag() const {return tif;}
172 
174  bool isValid() {return 0 != gid;}
175 
177  void dump(int level = 0) const;
178 
181  {
182  if (!tif)
183  return maxTID;
184  auto it = GlobalLabel::getTimeIntervals().find(makeEIDPID(eid, pid));
185  if (it == GlobalLabel::getTimeIntervals().end())
186  return tid;
187  for (unsigned int i = tid; i < maxTID; i++) {
188  if (it->second.get(i) != tid)
189  return i - 1;
190  }
191  return tid;
192  }
193 
197  static void clearTimeDependentParamaters();
198 
200  static unsigned int& getCurrentTimeIntervalRef()
201  {
202  static unsigned int subrun = 0;
203  return subrun;
204  }
205 
208  static void setCurrentTimeInterval(gidTYPE time)
209  {
211  timeref = time;
212  }
213 
216  {
218  }
219 
220  private:
222  static std::set<unsigned short> m_components;
223 
227  void construct(gidTYPE elementId, gidTYPE paramId);
228 
229  public:
231  struct TimeInterval {
232 
233  private:
234 
237 
240 
241  public:
242 
247  TimeInterval(gidTYPE TEIDPID, gidTYPE start, gidTYPE end)
248  {
249  teidpid_ = TEIDPID;
250  for (gidTYPE i = 0; i <= maxTID; i++) {
251  if (i >= start && i <= end)
252  arr_[i] = start;
253  else
254  arr_[i] = 0;
255  }
256  }
257 
260 
262  gidTYPE get(gidTYPE timeid) {return arr_[timeid];}
263 
265  void set(gidTYPE start, gidTYPE end)
266  {
267  for (gidTYPE i = 0; i <= maxTID; i++) {
268  if (i >= start && i <= end)
269  arr_[i] = start;
270  }
271  }
272  };
273  public:
275  static std::map<gidTYPE, TimeInterval >& getTimeIntervals()
276  {
277  // Map EIDPID -> (TEIDPID, time intervals)
278  static std::map<gidTYPE, TimeInterval > intervals;
279  return intervals;
280  }
281 
283  static std::map<gidTYPE, gidTYPE>& getDictionary()
284  {
285  // Map TEIDPID -> EIDPID
286  static std::map<gidTYPE, gidTYPE> dictionary;
287  return dictionary;
288  }
289 
291  gidTYPE makeEIDPID(gidTYPE eid_, gidTYPE pid_) {return pid_ * pidOffset + eid_ * eidOffest;}
292 
294  gidTYPE makeTEIDPID(gidTYPE teid_, gidTYPE pid_) {return pid_ * pidOffset + teid_ * teidOffset;}
295  private:
298 
301 
304 
307 
310 
311  };
312 
314 }
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:215
int label()
Returns encoded Pede label.
Definition: GlobalLabel.h:142
static void clearTimeDependentParamaters()
Forget all previously registered time dependent parameters.
Definition: GlobalLabel.cc:66
static std::map< gidTYPE, gidTYPE > & getDictionary()
Reference to dictionary/map TEIDPID -> EIDPID.
Definition: GlobalLabel.h:283
gidTYPE tid
time id
Definition: GlobalLabel.h:306
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:297
gidTYPE getUniqueId() const
Returns the global id identifing DB object for constantwith this label.
Definition: GlobalLabel.h:157
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:165
static const gidTYPE maxPID
max 99 parameter types 1..99
Definition: GlobalLabel.h:46
bool getTimeFlag() const
Is label time-dependent?
Definition: GlobalLabel.h:171
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:162
int getEndOfValidity()
Get the last time id, where this label is valid.
Definition: GlobalLabel.h:180
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:208
static GlobalLabel construct(gidTYPE element, gidTYPE param)
Construct label for given DB object (template argument) and its element and parameter.
Definition: GlobalLabel.h:81
static unsigned int & getCurrentTimeIntervalRef()
Returns reference to current time id.
Definition: GlobalLabel.h:200
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:291
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:294
gidTYPE tif
time identification flag
Definition: GlobalLabel.h:309
static const gidTYPE tifOffset
Offset of time flag = 1.000.000.000.
Definition: GlobalLabel.h:53
gidTYPE eid
element id
Definition: GlobalLabel.h:300
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 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:222
void construct(gidTYPE dbObjId, gidTYPE element, gidTYPE param)
Construct label for given DB object id and its element and parameter.
Definition: GlobalLabel.h:96
static const gidTYPE maxGID
max internal id = 1.999.999.999
Definition: GlobalLabel.h:56
gidTYPE getTimeId() const
Get time id.
Definition: GlobalLabel.h:168
static std::map< gidTYPE, TimeInterval > & getTimeIntervals()
Reference to map EIDPID -> (TEIDPID, time intervals)
Definition: GlobalLabel.h:275
static void setComponents(const std::set< unsigned short > &components)
Set which DB objects have non-zero labels (by their id)
Definition: GlobalLabel.h:108
gidTYPE pid
parameter id
Definition: GlobalLabel.h:303
bool isValid()
Is label valid? (non-zero)
Definition: GlobalLabel.h:174
Abstract base class for different kinds of events.
Struct to hold intervals of validity.
Definition: GlobalLabel.h:231
gidTYPE get(gidTYPE timeid)
Get the start time id for validity interval valid at given timeid.
Definition: GlobalLabel.h:262
void set(gidTYPE start, gidTYPE end)
Set new parameter validity interval from start to end.
Definition: GlobalLabel.h:265
gidTYPE teidpid_
Time element id & parameter id.
Definition: GlobalLabel.h:236
gidTYPE arr_[maxTID+1]
Array of time ids.
Definition: GlobalLabel.h:239
gidTYPE teidpid()
Get composed time element id & param id.
Definition: GlobalLabel.h:259
TimeInterval(gidTYPE TEIDPID, gidTYPE start, gidTYPE end)
Constructor for given validity interval.
Definition: GlobalLabel.h:247