ATLAS Offline Software
ToFLocParamDBTool.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 
8 namespace AFP
9 {
10  ToFLocParamDBTool::ToFLocParamDBTool(const std::string& type, const std::string& name, const IInterface* parent) :
11  base_class(type, name, parent)
12  {
13  }
14 
15 
17  {
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 ToFLocParamDBTool, bye bye");
26  return StatusCode::SUCCESS;
27  }
28 
29 
30  nlohmann::json ToFLocParamDBTool::parametersData(const EventContext& ctx) const
31  {
32  ATH_MSG_DEBUG("will get local ToF parameters 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 ToF parameters 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 
44  CondAttrListCollection::const_iterator itr = attrLocList->begin();
45  const coral::AttributeList &atr = itr->second;
46  std::string data = *(static_cast<const std::string *>((atr["data"]).addressOfData()));
47 
49  }
50 
51 
52  const ToFLocParamData ToFLocParamDBTool::parameters(const nlohmann::json& jsondata, const int stationID, const int trainID, const int barID) const
53  {
54  ATH_MSG_DEBUG("will get local ToF parameters for station "<<stationID<<", trainID "<<trainID<<", barID "<<barID);
55  nlohmann::json channeldata=jsondata["data"];
56 
57  // first, try to guess the channel nr.
58  int guess_ch=(stationID/3)*16+trainID*4+barID;
59 
60  nlohmann::json paramdata=channeldata.at(std::to_string(guess_ch)); // because using int would be too simple
61  int st=paramdata["stationID"];
62  int tr=paramdata["trainID"];
63  int ba=paramdata["barID"];
64  if(stationID==st && trainID==tr && barID==ba)
65  {
66  ATH_MSG_DEBUG("channel guessed correctly, stationID "<<st<<", trainID "<<trainID<<", barID "<<barID<<", channel guess "<<guess_ch);
67  return ToFLocParamData(st, tr, ba, paramdata["barWeight"], paramdata["barTimeOffset"]);
68  }
69  else
70  {
71  ATH_MSG_DEBUG("channel was not guessed correctly, stationID "<<st<<", trainID "<<trainID<<", barID "<<barID<<", channel guess "<<guess_ch);
72  }
73 
74  // if guess is not correct, loop over all channels
75  for(auto& chan : channeldata.items())
76  {
77  // channels are ordered alphabetically: 0,1,10,...,19,2,20,21,...29,3,30,31,4,...,9
78  nlohmann::json paramdata=chan.value();
79 
80  int st=paramdata["stationID"];
81  int tr=paramdata["trainID"];
82  int ba=paramdata["barID"];
83 
84  if(stationID==st && trainID==tr && barID==ba)
85  {
86  ATH_MSG_DEBUG("channel found for stationID "<<st<<", trainID "<<trainID<<", barID "<<barID<<", channel nr. "<<chan.key());
87  return ToFLocParamData(st, tr, ba, paramdata["barWeight"], paramdata["barTimeOffset"]);
88  }
89  }
90 
91  ATH_MSG_WARNING("local ToF parameters data stationID "<<stationID<<", trainID "<<trainID<<", barID "<<barID<<" not found in any channels, returning zeros");
92  return ToFLocParamData(stationID, trainID, barID);
93  }
94 
95 } // AFP namespace
data
char data[hepevt_bytes_allocation_ATLAS]
Definition: HepEvt.cxx:11
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
AFP::ToFLocParamDBTool::ToFLocParamDBTool
ToFLocParamDBTool(const std::string &type, const std::string &name, const IInterface *parent)
Definition: ToFLocParamDBTool.cxx:10
parse
std::map< std::string, std::string > parse(const std::string &list)
Definition: egammaLayerRecalibTool.cxx:1041
AFP::ToFLocParamDBTool::initialize
virtual StatusCode initialize() override
Does nothing.
Definition: ToFLocParamDBTool.cxx:16
AFP::ToFLocParamDBTool::parametersData
nlohmann::json parametersData(const EventContext &ctx) const override
Provide ToF parameters for a given bar. Returns zeros if no data available.
Definition: ToFLocParamDBTool.cxx:30
python.PyKernel.AttributeList
AttributeList
Definition: PyKernel.py:36
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::ToFLocParamDBTool::finalize
virtual StatusCode finalize() override
Does nothing.
Definition: ToFLocParamDBTool.cxx:23
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::ToFLocParamDBTool::parameters
const ToFLocParamData parameters(const nlohmann::json &jsondata, const int stationID, const int trainID, const int barID) const override
Definition: ToFLocParamDBTool.cxx:52
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:195
ActsTrk::to_string
std::string to_string(const DetectorType &type)
Definition: GeometryDefs.h:34
SG::CondHandleKey::initialize
StatusCode initialize(bool used=true)
AFP::ToFLocParamDBTool::m_rch_loc
SG::ReadCondHandleKey< CondAttrListCollection > m_rch_loc
Definition: ToFLocParamDBTool.h:52
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::ToFLocParamData
Class storing information about alignment.
Definition: ToFLocParamData.h:24
ToFLocParamDBTool.h
Header file for ToFLocParamDBTool used to read local ToF parameters from database.