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