Belle II Software  release-08-01-10
GlobalLabel.cc
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 #include <alignment/GlobalLabel.h>
10 
11 #include <iostream>
12 
13 using namespace std;
14 
15 using namespace Belle2;
16 
17 std::set<unsigned short> GlobalLabel::m_components = {};
18 
19 GlobalLabel::GlobalLabel(GlobalLabel::gidTYPE globalLabel) :
20  gid(0), eid(0), pid(0), tid(0), tif(0)
21 {
22  if (globalLabel > maxLabel)
23  return;
24  gid = globalLabel;
25  tif = gid / tifOffset;
26  pid = gid % eidOffest / pidOffset;
27 
28  if (!tif) {
29  eid = gid % tifOffset / eidOffest;
30  } else {
31  // Time-dep label
32  gidTYPE teid = gid % tidOffset / teidOffset;
33  gidTYPE teidpid = makeTEIDPID(teid, pid);
34  gidTYPE eidpid = 0;
35  auto& dict = GlobalLabel::getDictionary();
36  auto it = dict.find(teidpid);
37  if (it != dict.end())
38  eidpid = it->second;
39 
40  eid = eidpid / eidOffest;
41  tid = gid % tifOffset / tidOffset;
42  }
43 }
44 
47 {
48  auto& dict = GlobalLabel::getDictionary();
49  auto& ints = GlobalLabel::getTimeIntervals();
50  tif = 1;
51  tid = start;
52  gidTYPE eidpid = makeEIDPID(eid, pid);
53 
54  auto it = ints.find(eidpid);
55  if (it == ints.end()) {
56  // Not found, insert new record
57  gidTYPE teidpid = makeTEIDPID(dict.size() + 1, pid);
58  dict.insert(make_pair(teidpid, eidpid));
59  ints.insert(make_pair(eidpid, TimeInterval(teidpid, start, end)));
60  } else {
61  // Found, add time interval
62  it->second.set(start, end);
63  }
64 }
65 
67 {
70 }
71 
73 {
74  if (!getUniqueId() or paramId > maxPID) {
75  return label();
76  }
77  construct(getUniqueId(), getElementId(), paramId);
78  return label();
79 }
80 
82  GlobalLabel::gidTYPE paramId)
83 {
84  if (elementId > maxEID || paramId > maxPID)
85  return;
86  pid = paramId;
87  eid = elementId;
88 
89  gidTYPE eidpid = makeEIDPID(eid, pid);
90  gidTYPE teidpid = 0;
91  auto& ints = GlobalLabel::getTimeIntervals();
92  auto it = ints.find(eidpid);
93  if (it != ints.end())
94  teidpid = it->second.teidpid();
95 
96  if (teidpid)
97  tif = 1;
98  else
99  tif = 0;
100 
101  if (!tif)
102  gid = (tif * tifOffset + eid * eidOffest + pid * pidOffset);
103  else {
104  tid = it->second.get(GlobalLabel::getCurrentTimeIntervalRef());
105  gid = (tif * tifOffset + tid * tidOffset + teidpid);
106  }
107  /*
108  if (!teidpid) {
109  // time indep.
110  tif = 0;
111  gid = (tif * tifOffset + eid * eidOffest + pid * pidOffset);
112  }
113  else {
114  tid = it->second.get(GlobalLabel::getCurrentTimeIntervalRef());
115  if (tid == 0) {
116  // actually the first instance of time dep. parameter -> def with orginal time. indep. label
117  //FIXME: code copied from above!
118  tif = 0;
119  gid = (tif * tifOffset + eid * eidOffest + pid * pidOffset);
120  } else {
121  tif = 1;
122  gid = (tif * tifOffset + tid * tidOffset + teidpid);
123  }
124  }
125  */
126 }
127 
128 void GlobalLabel::dump(int level) const
129 {
130  cout << "GlobalLabel: gid=" << gid << endl;
131  cout << " eid=" << eid << endl;
132  cout << " pid=" << pid << endl;
133  cout << " tid=" << tid << endl;
134  cout << " tif=" << tif << endl;
135  if (level == 0)
136  return;
137  cout << " Time-dependent map:" << endl;
138  cout << " [EIDPID : TEIDPID] (registered time intervals)" << endl;
139  for (auto& it : getTimeIntervals()) {
140  cout << " " << it.first << " : " << it.second.teidpid() << endl;
141  cout << " ";
142  if (level > 1) {
143  for (unsigned int i = 0; i <= GlobalLabel::maxTID; i++) {
144  cout << it.second.get(i) << " ";
145  if ((i + 1) % 40 == 0)
146  cout << endl << " ";
147  }
148  cout << endl;
149  }
150  cout << endl;
151  }
152  cout << endl;
153 }
154 
static const gidTYPE tidOffset
Offset of time slice id = 1.000.000.
Definition: GlobalLabel.h:55
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 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
static const gidTYPE maxPID
max 99 parameter types 1..99
Definition: GlobalLabel.h:46
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
static const gidTYPE maxTID
max time slices for a parameter 1..999
Definition: GlobalLabel.h:50
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 std::map< gidTYPE, TimeInterval > & getTimeIntervals()
Reference to map EIDPID -> (TEIDPID, time intervals)
Definition: GlobalLabel.h:275
gidTYPE pid
parameter id
Definition: GlobalLabel.h:303
Abstract base class for different kinds of events.
Struct to hold intervals of validity.
Definition: GlobalLabel.h:231