ATLAS Offline Software
CaloTTOnOffIdMap.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
3 */
4 
9 
10 #include "GaudiKernel/ISvcLocator.h"
11 #include "GaudiKernel/Bootstrap.h"
12 #include "GaudiKernel/MsgStream.h"
13 #include "GaudiKernel/IMessageSvc.h"
14 
16 #include "StoreGate/StoreGateSvc.h"
17 
18 #include <iostream>
19 
21 }
22 
23 
25 }
26 
27 //------------------------------------------//
29 
30  convert_to_P(m);
31 
32  SmartIF<IMessageSvc> msgSvc{Gaudi::svcLocator()->service("MessageSvc")};
33  if(!msgSvc){
34  throw std::runtime_error("Cannot locate MessageSvc");
35  }
36  MsgStream log( msgSvc, "CaloTTOnOffIdMap");
37 
38  log<<MSG::DEBUG<<" CaloTTOnOffId size = "<<m.size() <<endmsg;
39 
40  SmartIF<StoreGateSvc> detStore{Gaudi::svcLocator()->service("DetectorStore")};
41  if(!detStore){
42  log << MSG::ERROR << "Cannot locate DetectorStore" << endmsg;
43  }
44 
45  const TTOnlineID* online_id = nullptr;
46  const CaloLVL1_ID* offline_id = nullptr;
47 
48  StatusCode status=detStore->retrieve(online_id);
49  if(status.isFailure()){
50  log << MSG::ERROR << "Cannot retrieve online_id" << endmsg;
51  }
52  status=detStore->retrieve(offline_id);
53  if(status.isFailure()){
54  log << MSG::ERROR << "Cannot retrieve offline_id" << endmsg;
55  }
56 
57  CaloTTOnOffId::const_iterator it = m.begin();
58  CaloTTOnOffId::const_iterator it_e = m.end();
59 
60  try {
61  for (; it!=it_e; ++it) {
62  const CaloTTOnOffId_t& t = *it;
63 
64  Identifier id = offline_id->tower_id(t.pn, t.sampling, t.region, t.eta, t.phi);
65  HWIdentifier sid = online_id->channelId(t.crate, t.module, t.submodule, t.channel);
66 
67  if (log.level()<=MSG::VERBOSE) {
69  << " db struct= "
70  <<" pn="<<t.pn<<" sampling="<<t.sampling
71  <<" region="<<t.region
72  <<" eta="<<t.eta<<" phi="<<t.phi<<" layer="<<t.layer<<" | "
73  <<" crate="<<t.crate<<" module="<<t.module
74  <<" submodule="<<t.submodule
75  <<" channel="<<t.channel
76  << endmsg;
77 
78  log<<MSG::VERBOSE<< " onl id = " << sid<<" offline id ="<<id<<endmsg;
79  }
80 
81  m_off2onIdMap[id] = sid;
82  m_on2offIdMap[sid] = id;
83  }
84  if (log.level()<=MSG::DEBUG) {
85  log<<MSG::DEBUG<<" CaloTTOnOffIdMap::set : number of Ids="<<m_on2offIdMap.size()<<std::endl;
86  }
87  } catch (CaloID_Exception& except) {
88  log<<MSG::ERROR<<" Failed in CaloTTOnOffIdMap::set " << endmsg;
89  log<<MSG::ERROR<< (std::string) except << endmsg ;
90  }
91  return;
92 }
93 
94 //--------------------------------------------------------------------------//
96 
97  std::map<Identifier,HWIdentifier>::const_iterator it =m_off2onIdMap.find(id);
98 
99  if(it!=m_off2onIdMap.end()){
100  return (*it).second;
101  }
102 
103  if(bQuiet) {
104  return HWIdentifier(0);
105 
106  } else {
107 
108  REPORT_MESSAGE_WITH_CONTEXT(MSG::ERROR, "CaloTTOnOffIdMap") <<
109  "Offline ID not found "<< id <<endmsg;
110 
111  return HWIdentifier(0);
112  }
113 }
114 
115 
116 //---------------------------------------------------------------------//
118 
119  std::map<HWIdentifier,Identifier>::const_iterator it=m_on2offIdMap.find(sid);
120 
121  if(it!=m_on2offIdMap.end()){
122  return (*it).second;
123  }
124 
125  if(bQuiet) {
126  return Identifier(0);
127 
128  } else {
129 
130  // ERROR, can not find the channelId.
131  REPORT_MESSAGE_WITH_CONTEXT(MSG::ERROR, "CaloTTOnOffIdMap") <<
132  "Online ID not found, id = " <<sid.get_compact()<< endmsg;
133 
134  return Identifier(0) ;
135  }
136 }
137 
139  return &m_persData;
140 }
141 
143 
144  CaloTTOnOffId::const_iterator it = d.begin();
145  CaloTTOnOffId::const_iterator it_e = d.end();
146 
147  for ( ;it!=it_e;++it){
148  const CaloTTOnOffId_t& t = *it;
150 
151  t2.pn = t.pn;
152  t2.sampling = t.sampling;
153  t2.region = t.region;
154  t2.eta = t.eta;
155  t2.phi = t.phi;
156  t2.layer = t.layer;
157 
158  t2.crate = t.crate ;
159  t2.module = t.module;
160  t2.submodule= t.submodule;
161  t2.channel = t.channel;
162 
163  m_persData.m_v.push_back(t2);
164  }
165 }
166 
167 
169 
170  std::vector<CaloTTOnOffId_P::__t>::const_iterator it = p.m_v.begin();
171  std::vector<CaloTTOnOffId_P::__t>::const_iterator it_e = p.m_v.end();
172 
173  d.clear();
174  for ( ;it!=it_e;++it){
175  const CaloTTOnOffId_P::__t& t = *it;
177 
178  t2.pn = t.pn;
179  t2.sampling = t.sampling;
180  t2.region = t.region;
181  t2.eta = t.eta;
182  t2.phi = t.phi;
183  t2.layer = t.layer;
184 
185  t2.crate = t.crate ;
186  t2.module = t.module;
187  t2.submodule= t.submodule;
188  t2.channel = t.channel;
189 
190  d.push_back(t2);
191  }
192 }
193 
195 
197  convert_to_D(p,d);
198  set(d);
199  m_persData.m_version = p.m_version;
200  return;
201 }
CaloTTOnOffIdMap::m_persData
CaloTTOnOffId_P m_persData
Definition: CaloTTOnOffIdMap.h:63
CaloID_Exception
Exception class for Calo Identifiers.
Definition: CaloID_Exception.h:20
hist_file_dump.d
d
Definition: hist_file_dump.py:142
TTOnlineID
Helper class for Calo TT online identifiers.
Definition: TTOnlineID.h:37
CaloTTOnOffIdMap::convert_to_P
void convert_to_P(const CaloTTOnOffId &t)
Definition: CaloTTOnOffIdMap.cxx:142
skel.it
it
Definition: skel.GENtoEVGEN.py:407
CaloTTOnOffId_P::m_version
int m_version
Definition: CaloTTOnOffId_P.h:50
Identifier::get_compact
value_type get_compact() const
Get the compact id.
CaloTTOnOffId_t
Structure definition of the LArTTOnOffIdMap.
Definition: CaloTTOnOffId.h:15
CaloTTOnOffIdMap::~CaloTTOnOffIdMap
~CaloTTOnOffIdMap()
Definition: CaloTTOnOffIdMap.cxx:24
CaloTTOnOffIdMap::createSignalChannelID
HWIdentifier createSignalChannelID(const Identifier &id, bool bQuiet=false) const
return the corresponfing online Id of an offline one
Definition: CaloTTOnOffIdMap.cxx:95
read_hist_ntuple.t
t
Definition: read_hist_ntuple.py:5
HWIdentifier
Definition: HWIdentifier.h:13
CaloTTOnOffId_P::CaloTTOnOffId_P_t
Structure of the map.
Definition: CaloTTOnOffId_P.h:27
CaloTTOnOffIdMap.h
python.utils.AtlRunQueryDQUtils.p
p
Definition: AtlRunQueryDQUtils.py:209
CaloTTOnOffIdMap::cnvToIdentifier
Identifier cnvToIdentifier(const HWIdentifier &sid, bool bQuiet=false) const
return the corresponfing offline Id of an online one
Definition: CaloTTOnOffIdMap.cxx:117
StdJOSetup.msgSvc
msgSvc
Provide convenience handles for various services.
Definition: StdJOSetup.py:36
CaloTTOnOffIdMap::m_off2onIdMap
std::map< Identifier, HWIdentifier > m_off2onIdMap
Definition: CaloTTOnOffIdMap.h:60
endmsg
#define endmsg
Definition: AnalysisConfig_Ntuple.cxx:63
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
TTOnlineID.h
CaloTTOnOffIdMap::CaloTTOnOffIdMap
CaloTTOnOffIdMap()
Definition: CaloTTOnOffIdMap.cxx:20
CaloTTOnOffIdMap::convert_to_D
void convert_to_D(const CaloTTOnOffId_P &t, CaloTTOnOffId &d)
Definition: CaloTTOnOffIdMap.cxx:168
REPORT_MESSAGE_WITH_CONTEXT
#define REPORT_MESSAGE_WITH_CONTEXT(LVL, CONTEXT_NAME)
Report a message, with an explicitly specified context name.
Definition: Control/AthenaKernel/AthenaKernel/errorcheck.h:345
python.PyKernel.detStore
detStore
Definition: PyKernel.py:41
CaloLVL1_ID
Helper class for offline TT identifiers.
Definition: CaloLVL1_ID.h:66
id
SG::auxid_t id
Definition: Control/AthContainers/Root/debug.cxx:239
errorcheck.h
Helpers for checking error return status codes and reporting errors.
CaloTTOnOffId_P
This is a database object holding the TT online-offline map.
Definition: CaloTTOnOffId_P.h:22
ALFA_EventTPCnv_Dict::t2
std::vector< ALFA_RawDataContainer_p1 > t2
Definition: ALFA_EventTPCnvDict.h:44
CaloTTOnOffIdMap::set
void set(const PDATA &t)
initialize from Nova
Definition: CaloTTOnOffIdMap.cxx:28
CaloLVL1_ID.h
CaloTTOnOffIdMap::m_on2offIdMap
std::map< HWIdentifier, Identifier > m_on2offIdMap
Definition: CaloTTOnOffIdMap.h:61
DEBUG
#define DEBUG
Definition: page_access.h:11
python.CaloCondTools.log
log
Definition: CaloCondTools.py:20
TTOnlineID::channelId
HWIdentifier channelId(int crate, int module, int submodule, int channel) const
(1) create towerId from fields
Definition: TTOnlineID.h:398
CaloTTOnOffIdMap::getP
CaloTTOnOffId_P * getP()
return the persistified map
Definition: CaloTTOnOffIdMap.cxx:138
merge.status
status
Definition: merge.py:16
python.Constants.VERBOSE
int VERBOSE
Definition: Control/AthenaCommon/python/Constants.py:13
CaloID_Exception.h
CaloLVL1_ID::tower_id
Identifier tower_id(int pos_neg_z, int sampling, int region, int eta, int phi) const
build a tower identifier
Definition: CaloLVL1_ID.h:429
StoreGateSvc.h
CaloTTOnOffId
std::vector< CaloTTOnOffId_t > CaloTTOnOffId
Definition: CaloTTOnOffId.h:30
python.SystemOfUnits.m
float m
Definition: SystemOfUnits.py:106
CaloTTOnOffId_P::m_v
std::vector< __t > m_v
Definition: CaloTTOnOffId_P.h:48
Identifier
Definition: IdentifierFieldParser.cxx:14