Belle II Software  release-05-02-19
GlobalLabel.h
1 /**************************************************************************
2  * BASF2 (Belle Analysis Framework 2) *
3  * Copyright(C) 2015 Belle II Collaboration *
4  * *
5  * Author: The Belle II Collaboration *
6  * Contributors: Tadeas Bilka *
7  * *
8  * This software is provided "as is" without any warranty. *
9  **************************************************************************/
10 
11 #pragma once
12 
13 #include <map>
14 #include <set>
15 
16 namespace Belle2 {
43  class GlobalLabel {
44 
45  public:
46 
47  typedef unsigned int gidTYPE;
48  static const gidTYPE maxPID = 99;
49  static const gidTYPE maxEID = 9999999;
50  static const gidTYPE maxTIF = 1;
51  static const gidTYPE maxTEID = 9999;
52  static const gidTYPE maxTID = 999;
53  static const gidTYPE pidOffset = 1;
54  static const gidTYPE eidOffest = pidOffset * (maxPID + 1);
55  static const gidTYPE tifOffset = eidOffest * (maxEID + 1);
56  static const gidTYPE teidOffset = eidOffest;
57  static const gidTYPE tidOffset = eidOffest * (maxTEID + 1);
60  static const gidTYPE maxLabel =
65 
73  explicit GlobalLabel(gidTYPE globalLabel);
74 
82  template<class DBObjType>
83  static GlobalLabel construct(gidTYPE element, gidTYPE param)
84  {
85  GlobalLabel theLabel;
86  theLabel.construct(DBObjType::getGlobalUniqueID(), element, param);
87  return theLabel;
88  }
89 
98  void construct(gidTYPE dbObjId, gidTYPE element, gidTYPE param)
99  {
100  if (m_components.empty() or m_components.find(dbObjId) != m_components.end())
101  construct(100000 * dbObjId + element, param);
102  else
103  construct(0, 0);
104  }
105 
110  static void setComponents(const std::set<unsigned short>& components)
111  {
112  m_components = components;
113  }
114 
129  void registerTimeDependent(gidTYPE start, gidTYPE end = maxTID);
130 
137  gidTYPE setParameterId(gidTYPE paramId);
138 
144  int label() {return gid;}
145 
149  operator int() {return (int)label();}
150 
154  operator unsigned int() {return (unsigned int)label();}
155 
159  gidTYPE getUniqueId() const {return eid / 100000;}
160 
164  gidTYPE getElementId() const {return eid % 100000;}
165 
167  gidTYPE getParameterId() const {return pid;}
168 
170  gidTYPE getTimeId() const {return tid;}
171 
173  bool getTimeFlag() const {return tif;}
174 
176  bool isValid() {return 0 != gid;}
177 
179  void dump(int level = 0) const;
180 
182  int getEndOfValidity()
183  {
184  if (!tif)
185  return maxTID;
186  auto it = GlobalLabel::getTimeIntervals().find(makeEIDPID(eid, pid));
187  if (it == GlobalLabel::getTimeIntervals().end())
188  return tid;
189  for (unsigned int i = tid; i < maxTID; i++) {
190  if (it->second.get(i) != tid)
191  return i - 1;
192  }
193  return tid;
194  }
195 
199  static void clearTimeDependentParamaters();
200 
202  static unsigned int& getCurrentTimeIntervalRef()
203  {
204  static unsigned int subrun = 0;
205  return subrun;
206  }
207 
210  static void setCurrentTimeInterval(gidTYPE time)
211  {
213  timeref = time;
214  }
215 
218  {
220  }
221 
222  private:
224  static std::set<unsigned short> m_components;
225 
229  void construct(gidTYPE elementId, gidTYPE paramId);
230 
231  public:
233  struct TimeInterval {
234 
235  private:
236 
239 
242 
243  public:
244 
249  TimeInterval(gidTYPE TEIDPID, gidTYPE start, gidTYPE end)
250  {
251  teidpid_ = TEIDPID;
252  for (gidTYPE i = 0; i <= maxTID; i++) {
253  if (i >= start && i <= end)
254  arr_[i] = start;
255  else
256  arr_[i] = 0;
257  }
258  }
259 
261  gidTYPE teidpid() {return teidpid_;}
262 
264  gidTYPE get(gidTYPE timeid) {return arr_[timeid];}
265 
267  void set(gidTYPE start, gidTYPE end)
268  {
269  for (gidTYPE i = 0; i <= maxTID; i++) {
270  if (i >= start && i <= end)
271  arr_[i] = start;
272  }
273  }
274  };
275  public:
277  static std::map<gidTYPE, TimeInterval >& getTimeIntervals()
278  {
279  // Map EIDPID -> (TEIDPID, time intervals)
280  static std::map<gidTYPE, TimeInterval > intervals;
281  return intervals;
282  }
283 
285  static std::map<gidTYPE, gidTYPE>& getDictionary()
286  {
287  // Map TEIDPID -> EIDPID
288  static std::map<gidTYPE, gidTYPE> dictionary;
289  return dictionary;
290  }
291 
293  gidTYPE makeEIDPID(gidTYPE eid_, gidTYPE pid_) {return pid_ * pidOffset + eid_ * eidOffest;}
294 
296  gidTYPE makeTEIDPID(gidTYPE teid_, gidTYPE pid_) {return pid_ * pidOffset + teid_ * teidOffset;}
297  private:
299  gidTYPE gid {0};
300 
302  gidTYPE eid {0};
303 
305  gidTYPE pid {0};
306 
308  gidTYPE tid {0};
309 
311  gidTYPE tif {0};
312 
313  };
314 
316 }
Belle2::GlobalLabel::TimeInterval::arr_
gidTYPE arr_[maxTID+1]
Array of time ids.
Definition: GlobalLabel.h:249
Belle2::GlobalLabel::setCurrentTimeInterval
static void setCurrentTimeInterval(gidTYPE time)
Sets current time id.
Definition: GlobalLabel.h:218
Belle2::GlobalLabel::TimeInterval::TimeInterval
TimeInterval(gidTYPE TEIDPID, gidTYPE start, gidTYPE end)
Constructor for given validity interval.
Definition: GlobalLabel.h:257
Belle2::GlobalLabel::isValid
bool isValid()
Is label valid? (non-zero)
Definition: GlobalLabel.h:184
Belle2::GlobalLabel::getEndOfValidity
int getEndOfValidity()
Get the last time id, where this label is valid.
Definition: GlobalLabel.h:190
Belle2::GlobalLabel::getTimeFlag
bool getTimeFlag() const
Is label time-dependent?
Definition: GlobalLabel.h:181
Belle2::GlobalLabel::TimeInterval
Struct to hold intervals of validity.
Definition: GlobalLabel.h:241
Belle2::GlobalLabel::getElementId
gidTYPE getElementId() const
Returns the element id (like VxdID for silicon sensors) to identify sets of parameters in DB objects.
Definition: GlobalLabel.h:172
Belle2::GlobalLabel::GlobalLabel
GlobalLabel()
Default constuctor. Members initialized in declaration.
Definition: GlobalLabel.h:72
Belle2::GlobalLabel::maxGID
static const gidTYPE maxGID
max internal id = 1.999.999.999
Definition: GlobalLabel.h:66
Belle2::GlobalLabel::getCurrentTimeInterval
static gidTYPE getCurrentTimeInterval()
Get current time id.
Definition: GlobalLabel.h:225
Belle2::GlobalLabel::eidOffest
static const gidTYPE eidOffest
Offset of detector element id = 100.
Definition: GlobalLabel.h:62
Belle2::GlobalLabel::tid
gidTYPE tid
time id
Definition: GlobalLabel.h:316
Belle2::GlobalLabel::TimeInterval::set
void set(gidTYPE start, gidTYPE end)
Set new parameter validity interval from start to end.
Definition: GlobalLabel.h:275
Belle2::GlobalLabel::teidOffset
static const gidTYPE teidOffset
Offset of time dependent element(detector+parameter) = 100.
Definition: GlobalLabel.h:64
Belle2::GlobalLabel::getTimeId
gidTYPE getTimeId() const
Get time id.
Definition: GlobalLabel.h:178
Belle2::GlobalLabel::maxTIF
static const gidTYPE maxTIF
time-dep.
Definition: GlobalLabel.h:58
Belle2::GlobalLabel::getCurrentTimeIntervalRef
static unsigned int & getCurrentTimeIntervalRef()
Returns reference to current time id.
Definition: GlobalLabel.h:210
Belle2::GlobalLabel::TimeInterval::teidpid_
gidTYPE teidpid_
Time element id & parameter id.
Definition: GlobalLabel.h:246
Belle2::GlobalLabel::tidOffset
static const gidTYPE tidOffset
Offset of time slice id = 1.000.000.
Definition: GlobalLabel.h:65
Belle2::GlobalLabel::getUniqueId
gidTYPE getUniqueId() const
Returns the global id identifing DB object for constantwith this label.
Definition: GlobalLabel.h:167
Belle2::GlobalLabel
Class to convert to/from global labels for Millepede II to/from detector & parameter identificators.
Definition: GlobalLabel.h:51
Belle2::GlobalLabel::makeEIDPID
gidTYPE makeEIDPID(gidTYPE eid_, gidTYPE pid_)
Helper to compose elemnt id & param id.
Definition: GlobalLabel.h:301
Belle2::GlobalLabel::gid
gidTYPE gid
global id
Definition: GlobalLabel.h:307
Belle2::GlobalLabel::m_components
static std::set< unsigned short > m_components
Set of global ids of components for which to return non-zero labels.
Definition: GlobalLabel.h:232
Belle2::GlobalLabel::registerTimeDependent
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:47
Belle2::GlobalLabel::TimeInterval::get
gidTYPE get(gidTYPE timeid)
Get the start time id for validity interval valid at given timeid.
Definition: GlobalLabel.h:272
Belle2::GlobalLabel::maxTID
static const gidTYPE maxTID
max time slices for a parameter 1..999
Definition: GlobalLabel.h:60
Belle2::GlobalLabel::tifOffset
static const gidTYPE tifOffset
Offset of time flag = 1.000.000.000.
Definition: GlobalLabel.h:63
Belle2::GlobalLabel::maxLabel
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:68
Belle2::GlobalLabel::clearTimeDependentParamaters
static void clearTimeDependentParamaters()
Forget all previously registered time dependent parameters.
Definition: GlobalLabel.cc:68
Belle2
Abstract base class for different kinds of events.
Definition: MillepedeAlgorithm.h:19
Belle2::GlobalLabel::setComponents
static void setComponents(const std::set< unsigned short > &components)
Set which DB objects have non-zero labels (by their id)
Definition: GlobalLabel.h:118
Belle2::GlobalLabel::gidTYPE
unsigned int gidTYPE
shortcut for main data type (unsigned int)
Definition: GlobalLabel.h:55
Belle2::GlobalLabel::maxEID
static const gidTYPE maxEID
max 9.999.999 detector elements 1..9999999 (NOT time-dep-)
Definition: GlobalLabel.h:57
Belle2::GlobalLabel::maxTEID
static const gidTYPE maxTEID
max time-dep.
Definition: GlobalLabel.h:59
Belle2::GlobalLabel::getDictionary
static std::map< gidTYPE, gidTYPE > & getDictionary()
Reference to dictionary/map TEIDPID -> EIDPID.
Definition: GlobalLabel.h:293
Belle2::GlobalLabel::pidOffset
static const gidTYPE pidOffset
parameter number are the last 2 decimal digits
Definition: GlobalLabel.h:61
Belle2::GlobalLabel::tif
gidTYPE tif
time identification flag
Definition: GlobalLabel.h:319
Belle2::GlobalLabel::construct
static GlobalLabel construct(gidTYPE element, gidTYPE param)
Construct label for given DB object (template argument) and its element and parameter.
Definition: GlobalLabel.h:91
Belle2::GlobalLabel::label
int label()
Returns encoded Pede label.
Definition: GlobalLabel.h:152
Belle2::GlobalLabel::getParameterId
gidTYPE getParameterId() const
Get id of alignment/calibration parameter.
Definition: GlobalLabel.h:175
Belle2::GlobalLabel::dump
void dump(int level=0) const
Dumps the label to std::cout.
Definition: GlobalLabel.cc:130
Belle2::GlobalLabel::eid
gidTYPE eid
element id
Definition: GlobalLabel.h:310
Belle2::GlobalLabel::makeTEIDPID
gidTYPE makeTEIDPID(gidTYPE teid_, gidTYPE pid_)
Helper to compose time elemnt id & param id.
Definition: GlobalLabel.h:304
Belle2::GlobalLabel::getTimeIntervals
static std::map< gidTYPE, TimeInterval > & getTimeIntervals()
Reference to map EIDPID -> (TEIDPID, time intervals)
Definition: GlobalLabel.h:285
Belle2::GlobalLabel::maxPID
static const gidTYPE maxPID
max 99 parameter types 1..99
Definition: GlobalLabel.h:56
Belle2::GlobalLabel::TimeInterval::teidpid
gidTYPE teidpid()
Get composed time element id & param id.
Definition: GlobalLabel.h:269
Belle2::GlobalLabel::setParameterId
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:74
Belle2::GlobalLabel::pid
gidTYPE pid
parameter id
Definition: GlobalLabel.h:313