ATLAS Offline Software
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 
14 
15 
16 namespace 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  {
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 
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 
data
char data[hepevt_bytes_allocation_ATLAS]
Definition: HepEvt.cxx:11
AFP::SiGlobAlignDBTool::SiGlobAlignDBTool
SiGlobAlignDBTool(const std::string &type, const std::string &name, const IInterface *parent)
Definition: SiGlobAlignDBTool.cxx:18
AFP::SiGlobAlignDBTool::alignment
const SiGlobAlignData alignment(const nlohmann::json &jsondata, const int stationID) const override
Definition: SiGlobAlignDBTool.cxx:59
AFP::SiGlobAlignData::setRP
void setRP(double x, double y, double z, double a, double b, double g)
Definition: SiGlobAlignData.h:52
SG::ReadCondHandle
Definition: ReadCondHandle.h:44
ATH_MSG_INFO
#define ATH_MSG_INFO(x)
Definition: AthMsgStreamMacros.h:31
json
nlohmann::json json
Definition: HistogramDef.cxx:9
parse
std::map< std::string, std::string > parse(const std::string &list)
Definition: egammaLayerRecalibTool.cxx:1054
AFP::SiGlobAlignData::setCorr
void setCorr(double x, double y, double z, double a, double b, double g)
Definition: SiGlobAlignData.h:61
python.PyKernel.AttributeList
AttributeList
Definition: PyKernel.py:36
AFP::SiGlobAlignData::setBeam
void setBeam(double x, double y, double z, double a, double b, double g)
Definition: SiGlobAlignData.h:43
CondAttrListCollection
This class is a collection of AttributeLists where each one is associated with a channel number....
Definition: CondAttrListCollection.h:52
AFP
Header file for interface of SiGlobAlignDBTool used to read global alignment for database.
Definition: ISiGlobAlignDBTool.h:18
AFP::SiGlobAlignDBTool::m_rch_glob
SG::ReadCondHandleKey< CondAttrListCollection > m_rch_glob
Definition: SiGlobAlignDBTool.h:52
ReadCellNoiseFromCool.chan
chan
Definition: ReadCellNoiseFromCool.py:52
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
ATH_MSG_DEBUG
#define ATH_MSG_DEBUG(x)
Definition: AthMsgStreamMacros.h:29
test_pyathena.parent
parent
Definition: test_pyathena.py:15
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
AFP::SiGlobAlignData
Definition: SiGlobAlignData.h:23
AFP::SiGlobAlignDBTool::alignmentData
nlohmann::json alignmentData(const EventContext &ctx) const override
Provide alignment parameters for a given station. Returns nullptr if no data available.
Definition: SiGlobAlignDBTool.cxx:37
AFP::SiGlobAlignData::setTracker
void setTracker(double x, double y, double z, double a, double b, double g)
Definition: SiGlobAlignData.h:34
SiGlobAlignDBTool.h
Header file for SiGlobAlignDBTool used to read local alignment for database.
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:221
ActsTrk::to_string
std::string to_string(const DetectorType &type)
Definition: GeometryDefs.h:34
SG::CondHandleKey::initialize
StatusCode initialize(bool used=true)
AFP::SiGlobAlignDBTool::finalize
virtual StatusCode finalize() override
Does nothing.
Definition: SiGlobAlignDBTool.cxx:30
ATH_MSG_WARNING
#define ATH_MSG_WARNING(x)
Definition: AthMsgStreamMacros.h:32
CondAttrListCollection::const_iterator
ChanAttrListMap::const_iterator const_iterator
Definition: CondAttrListCollection.h:63
python.CaloScaleNoiseConfig.type
type
Definition: CaloScaleNoiseConfig.py:78
AFP::SiGlobAlignDBTool::initialize
virtual StatusCode initialize() override
Does nothing.
Definition: SiGlobAlignDBTool.cxx:23