ATLAS Offline Software
Loading...
Searching...
No Matches
SiLocAlignDBTool.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2022 CERN for the benefit of the ATLAS collaboration
3*/
4
5
7
8namespace AFP
9{
10 SiLocAlignDBTool::SiLocAlignDBTool(const std::string& type, const std::string& name, const IInterface* parent) :
11 base_class(type, name, parent)
12 {
13 }
14
15
17 {
18 ATH_CHECK( m_rch_loc.initialize() );
19 ATH_MSG_DEBUG( "using DB with key " << m_rch_loc.fullKey() );
20 return StatusCode::SUCCESS;
21 }
22
24 {
25 ATH_MSG_DEBUG("in the finalize of SiLocAlignDBTool, bye bye");
26 return StatusCode::SUCCESS;
27 }
28
29
30 nlohmann::json SiLocAlignDBTool::alignmentData(const EventContext& ctx) const
31 {
32 ATH_MSG_DEBUG("will get local alignment for run "<<ctx.eventID().run_number()<<", lb "<<ctx.eventID().lumi_block()<<", event "<<ctx.eventID().event_number());
33
35 const CondAttrListCollection* attrLocList { *ch_loc};
36 if ( attrLocList == nullptr )
37 {
38 ATH_MSG_WARNING("local alignment data for key " << m_rch_loc.fullKey() << " not found, returning empty string");
39 return nlohmann::json::parse("");
40 }
41
42 if(attrLocList->size()>1) ATH_MSG_INFO("there should be only one real channel in "<< m_rch_loc.fullKey() <<", there are "<<attrLocList->size()<<" real channels, only the first one will be used ");
43
45 const coral::AttributeList &atr = itr->second;
46 std::string data = *(static_cast<const std::string *>((atr["data"]).addressOfData()));
47
48 return nlohmann::json::parse(data);
49 }
50
51
52 const SiLocAlignData SiLocAlignDBTool::alignment(const nlohmann::json& jsondata, const int stationID, const int layerID) const
53 {
54 ATH_MSG_DEBUG("will get local alignment for station "<<stationID<<", layerID "<<layerID);
55 nlohmann::json channeldata=jsondata["data"];
56
57 // first, try to guess the channel nr.
58 int guess_ch=stationID*4+layerID;
59
60 nlohmann::json aligndata=channeldata.at(std::to_string(guess_ch)); // because using int would be too simple
61 int st=aligndata["stationID"];
62 int la=aligndata["layerID"];
63 if(stationID==st && layerID==la)
64 {
65 ATH_MSG_DEBUG("channel guessed correctly, stationID "<<st<<", layerId "<<la<<", channel guess "<<guess_ch);
66 return SiLocAlignData(st, la, aligndata["shiftX"], aligndata["shiftY"], aligndata["shiftZ"], aligndata["alpha"], aligndata["beta"], aligndata["gamma"]);
67 }
68 else
69 {
70 ATH_MSG_DEBUG("channel was not guessed correctly, stationID "<<st<<", layerId "<<la<<", channel guess "<<guess_ch);
71 }
72
73 // if guess is not correct, loop over all channels
74 for(auto& chan : channeldata.items())
75 {
76 // channels are ordered alphabetically: 0,1,10,...,15,2,3,...,9
77 nlohmann::json aligndata=chan.value();
78
79 int st=aligndata["stationID"];
80 int la=aligndata["layerID"];
81
82 if(stationID==st && layerID==la)
83 {
84 ATH_MSG_DEBUG("channel found for stationID "<<st<<", layerId "<<la<<", channel nr. "<<chan.key());
85 return SiLocAlignData(st, la, aligndata["shiftX"], aligndata["shiftY"], aligndata["shiftZ"], aligndata["alpha"], aligndata["beta"], aligndata["gamma"]);
86 }
87 }
88
89 ATH_MSG_WARNING("local alignment data stationID "<<stationID<<", layerId "<<layerID<<" not found in any channels, returning zeros");
90 return SiLocAlignData(stationID,layerID);
91 }
92
93} // AFP namespace
#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 SiLocAlignDBTool used to read local alignment for database.
virtual StatusCode initialize() override
Does nothing.
SiLocAlignDBTool(const std::string &type, const std::string &name, const IInterface *parent)
nlohmann::json alignmentData(const EventContext &ctx) const override
Provide alignment parameters for a given plane. Returns zeros if no data available.
const SiLocAlignData alignment(const nlohmann::json &jsondata, const int stationID, const int planeID) const override
virtual StatusCode finalize() override
Does nothing.
SG::ReadCondHandleKey< CondAttrListCollection > m_rch_loc
Class storing information about alignment.
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.