ATLAS Offline Software
Loading...
Searching...
No Matches
SiGlobAlignDBTool.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2022 CERN for the benefit of the ATLAS collaboration
3*/
4
12
14
15
16namespace AFP
17{
18 SiGlobAlignDBTool::SiGlobAlignDBTool(const std::string& type, const std::string& name, const IInterface* parent) :
19 base_class(type, name, parent)
20 {
21 }
22
24 {
25 ATH_CHECK( m_rch_glob.initialize() );
26 ATH_MSG_DEBUG( "using DB with key " << m_rch_glob.fullKey() );
27 return StatusCode::SUCCESS;
28 }
29
31 {
32 ATH_MSG_DEBUG("in the finalize of SiGlobAlignDBTool, bye bye");
33 return StatusCode::SUCCESS;
34 }
35
36
37 nlohmann::json SiGlobAlignDBTool::alignmentData(const EventContext& ctx) const
38 {
39 ATH_MSG_DEBUG("will get global alignment for run "<<ctx.eventID().run_number()<<", lb "<<ctx.eventID().lumi_block()<<", event "<<ctx.eventID().event_number());
40
42 const CondAttrListCollection* attrGlobList { *ch_glob};
43 if ( attrGlobList == nullptr )
44 {
45 ATH_MSG_WARNING("global alignment data for key " << m_rch_glob.fullKey() << " not found, returning empty string");
46 return nlohmann::json::parse("");
47 }
48
49 if(attrGlobList->size()>1) ATH_MSG_INFO("there should be only one real channel in "<< m_rch_glob.fullKey() <<", there are "<<attrGlobList->size()<<" real channels, only the first one will be used ");
50
51 CondAttrListCollection::const_iterator itr = attrGlobList->begin();
52 const coral::AttributeList &atr = itr->second;
53 std::string data = *(static_cast<const std::string *>((atr["data"]).addressOfData()));
54
55 return nlohmann::json::parse(data);
56 }
57
58
59 const SiGlobAlignData SiGlobAlignDBTool::alignment(const nlohmann::json& jsondata, const int stationID) const
60 {
61 ATH_MSG_DEBUG("will get global alignment for station "<<stationID);
62 nlohmann::json channeldata=jsondata["data"];
63
64 // first, try to guess the channel nr.
65 SiGlobAlignData GA_guess(stationID);
66 std::vector<int> guess_ch_vec{stationID*4, stationID*4+1, stationID*4+2, stationID*4+3};
67 int guess_ch_correct=0;
68 for(auto guess_ch : guess_ch_vec)
69 {
70 nlohmann::json aligndata=channeldata.at(std::to_string(guess_ch)); // because using int would be too simple
71 int st=aligndata["stationID"];
72 std::string alignType=aligndata["alignType"];
73 if(stationID==st)
74 {
75 if(alignType=="tracker" && !(guess_ch_correct&1))
76 {
77 ATH_MSG_DEBUG("channel guessed correctly, stationID "<<st<<", alignType "<<alignType<<", channel guess "<<guess_ch);
78 GA_guess.setTracker(aligndata["shiftX"], aligndata["shiftY"], aligndata["shiftZ"], aligndata["alpha"], aligndata["beta"], aligndata["gamma"]);
79 guess_ch_correct+=1;
80 }
81 else if(alignType=="beam" && !(guess_ch_correct&2))
82 {
83 ATH_MSG_DEBUG("channel guessed correctly, stationID "<<st<<", alignType "<<alignType<<", channel guess "<<guess_ch);
84 GA_guess.setBeam(aligndata["shiftX"], aligndata["shiftY"], aligndata["shiftZ"], aligndata["alpha"], aligndata["beta"], aligndata["gamma"]);
85 guess_ch_correct+=2;
86 }
87 else if(alignType=="RP" && !(guess_ch_correct&4))
88 {
89 ATH_MSG_DEBUG("channel guessed correctly, stationID "<<st<<", alignType "<<alignType<<", channel guess "<<guess_ch);
90 GA_guess.setRP(aligndata["shiftX"], aligndata["shiftY"], aligndata["shiftZ"], aligndata["alpha"], aligndata["beta"], aligndata["gamma"]);
91 guess_ch_correct+=4;
92 }
93 else if(alignType=="correction" && !(guess_ch_correct&8))
94 {
95 ATH_MSG_DEBUG("channel guessed correctly, stationID "<<st<<", alignType "<<alignType<<", channel guess "<<guess_ch);
96 GA_guess.setCorr(aligndata["shiftX"], aligndata["shiftY"], aligndata["shiftZ"], aligndata["alpha"], aligndata["beta"], aligndata["gamma"]);
97 guess_ch_correct+=8;
98 }
99 else ATH_MSG_DEBUG("alignType or channel is probably incorrect, stationID "<<stationID<<", alignType "<<alignType<<", channel guess "<<guess_ch<<", guess_ch_correct "<<guess_ch_correct);
100 }
101 }
102
103 if(guess_ch_correct==15)
104 {
105 ATH_MSG_DEBUG("channels guessed correctly, stationID "<<stationID);
106 return GA_guess;
107 }
108 else
109 {
110 ATH_MSG_DEBUG("channels were not guessed correctly, stationID "<<stationID);
111 }
112
113 // if guess is not correct, loop over all channels
114 SiGlobAlignData GA_loop(stationID);
115 int loop_ch_correct=0;
116 for(auto& chan : channeldata.items())
117 {
118 // channels are ordered alphabetically: 0,1,10,...,15,2,3,...,9
119 nlohmann::json aligndata=chan.value();
120
121 int st=aligndata["stationID"];
122 std::string alignType=aligndata["alignType"];
123
124 if(stationID==st)
125 {
126 if(alignType=="tracker" && !(loop_ch_correct&1))
127 {
128 ATH_MSG_DEBUG("channel found for stationID "<<st<<", alignType "<<alignType<<", channel nr. "<<chan.key());
129 GA_loop.setTracker(aligndata["shiftX"], aligndata["shiftY"], aligndata["shiftZ"], aligndata["alpha"], aligndata["beta"], aligndata["gamma"]);
130 loop_ch_correct+=1;
131 }
132 else if(alignType=="beam" && !(loop_ch_correct&2))
133 {
134 ATH_MSG_DEBUG("channel found for stationID "<<st<<", alignType "<<alignType<<", channel nr. "<<chan.key());
135 GA_loop.setBeam(aligndata["shiftX"], aligndata["shiftY"], aligndata["shiftZ"], aligndata["alpha"], aligndata["beta"], aligndata["gamma"]);
136 loop_ch_correct+=2;
137 }
138 else if(alignType=="RP" && !(loop_ch_correct&4))
139 {
140 ATH_MSG_DEBUG("channel found for stationID "<<st<<", alignType "<<alignType<<", channel nr. "<<chan.key());
141 GA_loop.setRP(aligndata["shiftX"], aligndata["shiftY"], aligndata["shiftZ"], aligndata["alpha"], aligndata["beta"], aligndata["gamma"]);
142 loop_ch_correct+=4;
143 }
144 else if(alignType=="correction" && !(loop_ch_correct&8))
145 {
146 ATH_MSG_DEBUG("channel found for stationID "<<st<<", alignType "<<alignType<<", channel nr. "<<chan.key());
147 GA_loop.setCorr(aligndata["shiftX"], aligndata["shiftY"], aligndata["shiftZ"], aligndata["alpha"], aligndata["beta"], aligndata["gamma"]);
148 loop_ch_correct+=8;
149 }
150 else ATH_MSG_DEBUG("alignType is probably incorrect, stationID "<<stationID<<", alignType "<<alignType<<", channel nr. "<<chan.key()<<", loop_ch_correct "<<loop_ch_correct);
151 }
152
153 if(loop_ch_correct==15)
154 {
155 ATH_MSG_DEBUG("channels found correctly, stationID "<<stationID);
156 return GA_loop;
157 }
158 else
159 {
160 ATH_MSG_DEBUG("channels were not found correctly, stationID "<<stationID);
161 }
162 }
163
164 ATH_MSG_WARNING("global alignment data stationID "<<stationID<<" not found in any channels, returning zeros");
165 return SiGlobAlignData(stationID);
166 }
167
168
169
170} // AFP namespace
171
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_INFO(x)
#define ATH_MSG_WARNING(x)
#define ATH_MSG_DEBUG(x)
char data[hepevt_bytes_allocation_ATLAS]
Definition HepEvt.cxx:11
Header file for SiGlobAlignDBTool used to read local alignment for database.
nlohmann::json alignmentData(const EventContext &ctx) const override
Provide alignment parameters for a given station. Returns nullptr if no data available.
virtual StatusCode initialize() override
Does nothing.
SG::ReadCondHandleKey< CondAttrListCollection > m_rch_glob
virtual StatusCode finalize() override
Does nothing.
const SiGlobAlignData alignment(const nlohmann::json &jsondata, const int stationID) const override
SiGlobAlignDBTool(const std::string &type, const std::string &name, const IInterface *parent)
void setCorr(double x, double y, double z, double a, double b, double g)
void setRP(double x, double y, double z, double a, double b, double g)
void setTracker(double x, double y, double z, double a, double b, double g)
void setBeam(double x, double y, double z, double a, double b, double g)
This class is a collection of AttributeLists where each one is associated with a channel number.
const_iterator begin() const
Access to Chan/AttributeList pairs via iterators.
size_type size() const
number of Chan/AttributeList pairs
ChanAttrListMap::const_iterator const_iterator
Header file for interface of SiGlobAlignDBTool used to read global alignment for database.