ATLAS Offline Software
Loading...
Searching...
No Matches
LArTTCellMap.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2022 CERN for the benefit of the ATLAS collaboration
3*/
4
10#include "GaudiKernel/MsgStream.h"
11#include "GaudiKernel/ServiceHandle.h"
12
14
15#include <iostream>
16
18 : AthMessaging ("LArTTCellMap")
19{
20}
21
22
27
28
30{
31
32 convert_to_P(m);
33
34 ATH_MSG_DEBUG( " LArTTCell size = "<<m.size() );
35
36 ServiceHandle<StoreGateSvc> detStore ("DetectorStore", "LArTTCellMap");
37
38 const LArEM_ID* em_id = nullptr;
39 const LArHEC_ID* hec_id = nullptr;
40 const LArFCAL_ID* fcal_id = nullptr;
41 const CaloLVL1_ID* lvl1_id = nullptr;
42
43 StatusCode status=detStore->retrieve(em_id);
44 if(status.isFailure()){
45 ATH_MSG_ERROR( "Cannot retrieve em_id" );
46 }
47 status=detStore->retrieve(hec_id);
48 if(status.isFailure()){
49 ATH_MSG_ERROR( "Cannot retrieve hec_id" );
50 }
51 status=detStore->retrieve(fcal_id);
52 if(status.isFailure()){
53 ATH_MSG_ERROR( "Cannot retrieve fcal_id" );
54 }
55 status=detStore->retrieve(lvl1_id);
56 if(status.isFailure()){
57 ATH_MSG_ERROR( "Cannot retrieve lvl1_id" );
58 }
59 LArTTCell::const_iterator it = m.begin();
60 LArTTCell::const_iterator it_e = m.end();
61
62 // useful in debug phase; can be removed afterwards
63 std::set<Identifier> cellIdSet;
64
65 try {
66 for (; it!=it_e; ++it) {
67 const LArTTCell_t& t = *it;
68
69 Identifier id ;
70
71 if(t.det==0){
72 // EM
73 id = em_id->channel_id(t.pn,t.sample,t.region,t.eta,t.phi);
74 } else if(t.det==1){
75 // HEC
76 id = hec_id->channel_id(t.pn,t.sample,t.region,t.eta,t.phi);
77 } else if(t.det==2){
78 // FCAL sample==region
79 id = fcal_id->channel_id(t.pn,t.region,t.eta,t.phi);
80
81 } else {
82 ATH_MSG_ERROR( " Wrong input Detector Number " << t.det );
83 }
84
85 Identifier sid = lvl1_id->layer_id(t.tpn,t.tsample,t.tregion,t.teta,t.tphi,t.layer);
86
87 ATH_MSG_VERBOSE( " db struct= "
88 <<" det="<<t.det
89 <<" pn="<<t.pn
90 <<" region="<<t.region
91 <<" sample="<<t.sample
92 <<" eta="<<t.eta<<" phi="<<t.phi
93 <<" trig pn="<<t.tpn
94 <<" trig region="<<t.tregion
95 <<" trig sample="<<t.tsample
96 <<" trig eta="<<t.teta<<" trig phi="<<t.tphi
97 <<" layer="<<t.layer );
98 ATH_MSG_VERBOSE( " lvl1 id = " << sid<<" offline id ="<<id );
99
100 if(!(cellIdSet.insert(id)).second) {
101 ATH_MSG_ERROR( " Duplicate cell id "
102 << lvl1_id->show_to_string(id)
103 << " in TT= "
104 << lvl1_id->show_to_string(sid) );
105 }
106 m_cell2ttIdMap[id] = sid;
107
108 std::map<Identifier,std::vector<Identifier> >::const_iterator it_find = m_tt2cellIdMap.find(sid);
109 if(it_find==m_tt2cellIdMap.end()) {
110 // a vector of Ids does not already exist for this sid, we reserve the number of elements
111 int nElements = 1;
112
113 if(t.tsample==0) {
114 if(t.tregion==0) {
115 if(t.layer==0) {
116 nElements = 4;
117 } else if(t.layer==1) {
118 nElements = 32;
119 } else if(t.layer==2) {
120 nElements = 16;
121 } else if(t.layer==3) {
122 nElements = 8;
123 }
124
125 } else if(t.tregion==1) {
126 nElements = 4;
127 } else if(t.tregion==2) {
128 nElements = 2;
129 } else if(t.tregion==3) {
130 nElements = 16;
131 }
132
133 } else if(t.tsample==1) {
134 if(t.tregion==3) {
135 if(t.layer==0) {
136 nElements = 8;
137 } else if(t.layer==1) {
138 nElements = 4;
139 }
140 }
141 }
142 m_tt2cellIdMap[sid].reserve(nElements);
143 }
144 m_tt2cellIdMap[sid].push_back(id);
145 }
146 }
147
148
149 catch (LArID_Exception& except) {
150 ATH_MSG_ERROR( " Failed in LArTTCellMap::set " );
151 ATH_MSG_ERROR( (std::string) except );
152 }
153
154 ATH_MSG_DEBUG( " LArTTCellMap::set : number of cell Ids="<<m_cell2ttIdMap.size() );
155
156 detStore->release() ;
157
158 return;
159
160}
161
163{
164
165 std::map<Identifier,Identifier>::const_iterator it =m_cell2ttIdMap.find(id);
166
167 if(it!=m_cell2ttIdMap.end()){
168 return (*it).second;
169 }
170
171 ATH_MSG_ERROR( " Offline TT ID not found for cell "<< id );
172
173 return Identifier();
174
175}
176
177
178
179
180
181const std::vector<Identifier>&
183{
184
185 std::map<Identifier,std::vector<Identifier> >::const_iterator
186 it=m_tt2cellIdMap.find(sid);
187
188 if(it!=m_tt2cellIdMap.end()){
189 return (*it).second;
190 }
191
192 ATH_MSG_VERBOSE( " vector of offline cell ID not found, TT id = " <<sid.get_compact() );
193
194 static const std::vector<Identifier> v;
195 return v ;
196
197}
198
200{
201 return &m_persData;
202}
203
205{
206 return &m_persData;
207}
208
210{
211
212 LArTTCell::const_iterator it = d.begin();
213 LArTTCell::const_iterator it_e = d.end();
214
215 for ( ;it!=it_e;++it){
216 const LArTTCell_t& t = *it;
218
219 t2.det = t.det;
220 t2.pn = t.pn;
221 t2.sample = t.sample;
222 t2.region = t.region;
223 t2.eta = t.eta;
224 t2.phi = t. phi;
225
226 t2.tpn = t.tpn ;
227 t2.tsample = t.tsample;
228 t2.tregion = t.tregion;
229 t2.teta = t.teta;
230 t2.tphi = t.tphi;
231 t2.layer = t.layer;
232
233 m_persData.m_v.push_back(t2);
234 }
235
236}
237
238
240{
241
242 std::vector<LArTTCell_P::__t>::const_iterator it = p.m_v.begin();
243 std::vector<LArTTCell_P::__t>::const_iterator it_e = p.m_v.end();
244
245 d.clear();
246 for ( ;it!=it_e;++it){
247 const LArTTCell_P::__t& t = *it;
248 LArTTCell_t t2 ;
249
250 t2.det = t.det ;
251 t2.pn = t.pn ;
252 t2.region = t.region;
253 t2.sample = t.sample;
254 t2.eta = t.eta ;
255 t2.phi = t.phi ;
256
257 t2.tpn = t.tpn ;
258 t2.tregion = t.tregion;
259 t2.tsample = t.tsample;
260 t2.teta = t.teta ;
261 t2.tphi = t.tphi ;
262 t2.layer = t.layer ;
263
264 d.push_back(t2);
265 }
266
267}
268
270{
271 LArTTCell d ;
272 convert_to_D(p,d);
273 set(d);
274 m_persData.m_version = p.m_version;
275 return ;
276}
Scalar phi() const
phi method
#define ATH_MSG_ERROR(x)
#define ATH_MSG_VERBOSE(x)
#define ATH_MSG_DEBUG(x)
std::vector< LArTTCell_t > LArTTCell
Definition LArTTCell.h:35
AthMessaging(IMessageSvc *msgSvc, const std::string &name)
Constructor.
std::string show_to_string(Identifier id, const IdContext *context=0, char sep='.') const
or provide the printout in string form
Helper class for offline TT identifiers.
Definition CaloLVL1_ID.h:66
Identifier layer_id(int pos_neg_z, int sampling, int region, int eta, int phi, int layer) const
build a layer identifier
value_type get_compact() const
Get the compact id.
Identifier channel_id(const ExpandedIdentifier &exp_id) const
Build a cell identifier from an expanded identifier.
Helper class for LArEM offline identifiers.
Definition LArEM_ID.h:111
Identifier channel_id(const ExpandedIdentifier &exp_id) const
cell identifier for a channel from ExpandedIdentifier
Helper class for LArFCAL offline identifiers.
Definition LArFCAL_ID.h:49
Identifier channel_id(const ExpandedIdentifier &exp_id) const
channel identifier for a channel from ExpandedIdentifier
Helper class for LArHEC offline identifiers.
Definition LArHEC_ID.h:76
Exception class for LAr Identifiers.
Identifier whichTTID(const Identifier &id) const
return the offline id (CaloLVL1_ID) of the TT to which a cell (CaloCell_ID) belongs
std::map< Identifier, Identifier > m_cell2ttIdMap
LArTTCell_P m_persData
const std::vector< Identifier > & createCellIDvec(const Identifier &id) const
Return a vector of offline Identifiers (corresponding helpers = LArEM_ID, LArHEC_ID,...
const LArTTCell_P * getP() const
return the persistified map
void convert_to_P(const LArTTCell &t)
void set(const PDATA &t)
initialize from Nova
std::map< Identifier, std::vector< Identifier > > m_tt2cellIdMap
void convert_to_D(const LArTTCell_P &t, LArTTCell &d)
This is a database object holding the offline TT-cell map.
Definition LArTTCell_P.h:23
LArTTCell_P_t __t
Definition LArTTCell_P.h:47
Structure definition of the LArTTCellMap.
Definition LArTTCell.h:18