Belle II Software development
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
13using namespace std;
14
15using namespace Belle2;
16
17std::set<unsigned short> GlobalLabel::m_components = {};
18
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;
27
28 if (!tif) {
30 } else {
31 // Time-dep label
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;
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
71
73{
74 if (!getUniqueId() or paramId > maxPID) {
75 return label();
76 }
77 construct(getUniqueId(), getElementId(), paramId);
78 return label();
79}
80
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 {
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 original 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
128void 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.
static void clearTimeDependentParamaters()
Forget all previously registered time dependent parameters.
gidTYPE tid
time id
static const gidTYPE maxEID
max 9.999.999 detector elements 1..9999999 (NOT time-dep-)
Definition GlobalLabel.h:47
gidTYPE setParameterId(gidTYPE paramId)
Useful setter to quickly change only the parameter id and return back the encoded label (for use in R...
static const gidTYPE eidOffest
Offset of detector element id = 100.
Definition GlobalLabel.h:52
gidTYPE gid
global id
gidTYPE getUniqueId() const
Returns the global id identifying DB object for constant with this label.
static std::map< gidTYPE, gidTYPE > & getDictionary()
Reference to dictionary/map TEIDPID -> EIDPID.
void dump(int level=0) const
Dumps the label to std::cout.
static const gidTYPE teidOffset
Offset of time dependent element(detector+parameter) = 100.
Definition GlobalLabel.h:54
GlobalLabel()
Default constructor. Members initialized in declaration.
Definition GlobalLabel.h:62
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.
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
void registerTimeDependent(gidTYPE start, gidTYPE end=maxTID)
Register this Detector element and parameter as time dependent with instance starting at "start" time...
gidTYPE makeEIDPID(gidTYPE eid_, gidTYPE pid_)
Helper to compose element id & param id.
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 element id & param id.
gidTYPE tif
time identification flag
static const gidTYPE tifOffset
Offset of time flag = 1.000.000.000.
Definition GlobalLabel.h:53
gidTYPE eid
element id
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.
static std::map< gidTYPE, TimeInterval > & getTimeIntervals()
Reference to map EIDPID -> (TEIDPID, time intervals)
static std::set< unsigned short > m_components
Set of global ids of components for which to return non-zero labels.
gidTYPE pid
parameter id
Abstract base class for different kinds of events.
STL namespace.
Struct to hold intervals of validity.