ATLAS Offline Software
Loading...
Searching...
No Matches
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
17
18#include <iostream>
19
22
23
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) {
68 log<<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
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;
176 CaloTTOnOffId_t t2 ;
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}
#define endmsg
std::vector< CaloTTOnOffId_t > CaloTTOnOffId
Helpers for checking error return status codes and reporting errors.
#define REPORT_MESSAGE_WITH_CONTEXT(LVL, CONTEXT_NAME)
Report a message, with an explicitly specified context name.
Exception class for Calo Identifiers.
Helper class for offline TT identifiers.
Definition CaloLVL1_ID.h:66
Identifier tower_id(int pos_neg_z, int sampling, int region, int eta, int phi) const
build a tower identifier
CaloTTOnOffId_P * getP()
return the persistified map
std::map< Identifier, HWIdentifier > m_off2onIdMap
CaloTTOnOffId_P m_persData
void convert_to_D(const CaloTTOnOffId_P &t, CaloTTOnOffId &d)
void set(const PDATA &t)
initialize from Nova
std::map< HWIdentifier, Identifier > m_on2offIdMap
Identifier cnvToIdentifier(const HWIdentifier &sid, bool bQuiet=false) const
return the corresponfing offline Id of an online one
HWIdentifier createSignalChannelID(const Identifier &id, bool bQuiet=false) const
return the corresponfing online Id of an offline one
void convert_to_P(const CaloTTOnOffId &t)
This is a database object holding the TT online-offline map.
CaloTTOnOffId_P_t __t
value_type get_compact() const
Get the compact id.
Helper class for Calo TT online identifiers.
Definition TTOnlineID.h:29
HWIdentifier channelId(int crate, int module, int submodule, int channel) const
(1) create towerId from fields
Definition TTOnlineID.h:390
Structure definition of the LArTTOnOffIdMap.