ATLAS Offline Software
Loading...
Searching...
No Matches
CalibHitIDCheck.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2026 CERN for the benefit of the ATLAS collaboration
3*/
4
5//*************************************************************************************
6// Filename : CalibHitIDCheck.cxx
7//
8// Author : Gia gia@mail.cern.ch
9// Created : April, 2005
10//
11// DESCRIPTION:
12//
13// Helper tool for CalibHits Identifiers checking
14//
15//*************************************************************************************
16
17#include "CalibHitIDCheck.h"
18
19//Gaudi Includes
20#include "GaudiKernel/Bootstrap.h"
21#include "GaudiKernel/ISvcLocator.h"
22#include "GaudiKernel/IMessageSvc.h"
23#include "GaudiKernel/IDataProviderSvc.h"
24
25// Calo include
27
29
30// Constructor & destructor
31CalibHitIDCheck::CalibHitIDCheck(const std::string& name, ISvcLocator* pSvcLocator)
32 : AthAlgorithm(name, pSvcLocator)
33{
34}
35
37
40{
41 ATH_CHECK( detStore()->retrieve(m_id_helper) );
42 ATH_MSG_INFO("initialisation completed" );
43 return StatusCode::SUCCESS;
44}
45
46
47
48
51{
58
59 //We need merge only Inactive and Active
60 //LAr CalibHit Containers only once
61 m_Merge=false;
62
63
64 //check containers separately
65 if(m_Check) {
66 if(m_InactiveHitCnt) { check(0); }
67 if(m_ActiveHitCnt) { check(1); }
69 if(m_TileActiveHitCnt) { check(3); }
70 if(m_LArDMHitCnt) { check(4); }
71 if(m_TileDMHitCnt) { check(5); }
72 }
73
74
75 //show all IDs from all containers
76 if(m_ShowAll) show_all();
77
78
79 //check all containers
81
82
83 //reset member 'm_id_vec'
84 reset();
85
86
87 ATH_MSG_DEBUG("execute() completed successfully" );
88 return StatusCode::SUCCESS;
89}
90
91
92//**********************************************************
93// ------------------------ METHODS ------------------------
94//**********************************************************
95
96//This method checks separately all the presented CalibHit
97//containers for not valid, container not respected
98//('alien') and repeated Identifiers
99void CalibHitIDCheck::check(int l_cnt) {
100
101 std::vector<Identifier> id_vec;
102 std::map<Identifier, int> id_map;
103 std::map<Identifier, int>::iterator map_it;
105
106 bool no_invalid = true;
107 bool no_alien = true;
108
109 //define appropriate iterator over the container
110 switch(l_cnt) {
111 case 0:
112
113 if((m_InactiveHitCnt->Size()) != 0 )
114 {
115 ATH_MSG_INFO(" " );
116 ATH_MSG_INFO("*************************************************************" );
117 ATH_MSG_INFO("Investigate CalibHit IDs from LAr Inactive CalibHit Container" );
118 ATH_MSG_INFO("*************************************************************" );
119
120 it = m_InactiveHitCnt->begin();
121 end = m_InactiveHitCnt->end();
122 }
123 else
124 {
125 return;
126 }
127 break;
128
129
130 case 1:
131
132 if((m_ActiveHitCnt->Size()) != 0 )
133 {
134 ATH_MSG_INFO(" " );
135 ATH_MSG_INFO("***********************************************************" );
136 ATH_MSG_INFO("Investigate CalibHit IDs from LAr Active CalibHit Container" );
137 ATH_MSG_INFO("***********************************************************" );
138
139 it = m_ActiveHitCnt->begin();
140 end = m_ActiveHitCnt->end();
141
142 m_Merge=true;
143 }
144 else
145 {
146 return;
147 }
148 break;
149
150
151 case 2:
152
153 if((m_TileInactiveHitCnt->Size()) != 0 )
154 {
155 ATH_MSG_INFO(" " );
156 ATH_MSG_INFO("**************************************************************" );
157 ATH_MSG_INFO("Investigate CalibHit IDs from Tile Inactive CalibHit container" );
158 ATH_MSG_INFO("**************************************************************" );
159
160 it = m_TileInactiveHitCnt->begin();
161 end = m_TileInactiveHitCnt->end();
162 }
163 else
164 {
165 return;
166 }
167 break;
168
169
170 case 3:
171
172 if((m_TileActiveHitCnt->Size()) != 0 )
173 {
174 ATH_MSG_INFO(" " );
175 ATH_MSG_INFO("************************************************************" );
176 ATH_MSG_INFO("Investigate CalibHit IDs from Tile Active CalibHit container" );
177 ATH_MSG_INFO("************************************************************" );
178
179 it = m_TileActiveHitCnt->begin();
180 end = m_TileActiveHitCnt->end();
181
182 m_Merge=true;
183 }
184 else
185 {
186 return;
187 }
188 break;
189
190
191 case 4:
192
193 if((m_LArDMHitCnt->Size()) != 0 )
194 {
195 ATH_MSG_INFO(" " );
196 ATH_MSG_INFO("*******************************************************" );
197 ATH_MSG_INFO("Investigate CalibHit IDs from LAr DM CalibHit Container" );
198 ATH_MSG_INFO("*******************************************************" );
199
200 it = m_LArDMHitCnt->begin();
201 end = m_LArDMHitCnt->end();
202 }
203 else
204 {
205 return;
206 }
207 break;
208
209
210 case 5:
211
212 if((m_TileDMHitCnt->Size()) != 0 )
213 {
214 ATH_MSG_INFO(" " );
215 ATH_MSG_INFO("********************************************************" );
216 ATH_MSG_INFO("Investigate CalibHit IDs from Tile DM CalibHit Container" );
217 ATH_MSG_INFO("********************************************************" );
218
219 it = m_TileDMHitCnt->begin();
220 end = m_TileDMHitCnt->end();
221 }
222 else
223 {
224 return;
225 }
226 break;
227
228 default:
229 return;
230 }
231
232
233 //Now, iterate over the container to find
234 //not valid, 'alien' and repeated IDs
235 for(; it != end; ++it) {
236
237 Identifier id=(*it)->cellID();
238
239
240 //Check ID whether is it valid or not
241 if(!id.is_valid()) {
242
243 ATH_MSG_ERROR("Invalid Identifier of CalibHit is found! "
244 <<m_id_helper->show_to_string(id) );
245
246 no_invalid=false;
247 }
248
249
250
251 //Check for 'alien' IDs in the container
252 switch(l_cnt) {
253 case 0:
254 case 1:
255 if( !(m_id_helper->is_lar(id)) ) {
256 ATH_MSG_INFO("Found CalibHit with NO LAr ID "
257 <<m_id_helper->show_to_string(id) );
258 no_alien=false;
259 }
260 break;
261
262 case 2:
263 case 3:
264 if( !(m_id_helper->is_tile(id)) ) {
265 ATH_MSG_INFO("Found CalibHit with NO Tile ID "
266 <<m_id_helper->show_to_string(id) );
267 no_alien=false;
268 }
269 break;
270
271 case 4:
272 if( !(m_id_helper->is_lar_dm(id)) &&
273 //It's normal to find Tile DM ID
274 //recorded by Default Calculator
275 !(m_id_helper->is_tile_dm(id)) ) {
276 ATH_MSG_INFO("Found CalibHit with NO LAr DM ID "
277 <<m_id_helper->show_to_string(id) );
278 no_alien=false;
279 }
280 break;
281
282 case 5:
283 if( !(m_id_helper->is_tile_dm(id)) ) {
284 ATH_MSG_INFO("Found CalibHit with NO Tile DM ID "
285 <<m_id_helper->show_to_string(id) );
286 no_alien=false;
287 }
288 break;
289
290 }
291
292
293 bool no_rep = true;
294
295 //Fill id_map with IDs, which are repeted more then once in the container
296 for (int iter=0; iter<static_cast<int>(id_vec.size()); iter++) {
297 if(id == id_vec[iter]) {
298
299 if(id_map.find(id)==id_map.end()) {
300 id_map.insert(std::make_pair(id,2));
301 }
302 else {
303 map_it=id_map.find(id);
304 (map_it->second)++ ;
305 }
306
307 no_rep = false;
308 break;
309 }
310 }
311
312 if(no_rep) {
313 id_vec.push_back(id);
314
315 //store id in the vector for all containers and
316 //don't forget merge Inactive & Active CalibHit IDs
317 if(m_Merge) merge(id);
318 else m_id_vec.push_back(id);
319 }
320 else {
321 //repeated ID should not be stored because
322 //its first pattern was already stored &
323 //should not be merged still the same reason
324 //as above.
325 }
326
327 }//End of looping over the CalibHits inside the container
328
329
330 //reset merge flag anyway.
331 //It is needed 'true' only twice
332 m_Merge=false;
333
334
335 //tell if no invalid IDs were eppeared
336 if(no_invalid) {
337
338 ATH_MSG_INFO("------------------------------------- " );
339 ATH_MSG_INFO("No invalid Identifiers has been found " );
340 ATH_MSG_INFO("------------------------------------- " );
341
342 }
343
344
345 //tell if no 'alien' IDs were eppeared
346 if(no_alien) {
347
348 ATH_MSG_INFO("------------------------------------------------------" );
349 ATH_MSG_INFO("No container not-respective Identifiers has been found" );
350 ATH_MSG_INFO("------------------------------------------------------" );
351
352 }
353
354
355 //Print the result of looking for repeated IDs
356 if(!id_map.empty()) {
357
358 ATH_MSG_INFO("----------------------------------------------- " );
359 ATH_MSG_INFO("Found repeated Identifiers | how many times " );
360 ATH_MSG_INFO("----------------------------------------------- " );
361
362 for (const std::pair<const Identifier, int>& p : id_map) {
363 ATH_MSG_INFO(m_id_helper->show_to_string(p.first)
364 <<" "<< p.second );
365 }
366
367 }
368 else {
369 ATH_MSG_INFO("----------------------------------------------- " );
370 ATH_MSG_INFO("No repeated CalibHit Identifiers has been found " );
371 ATH_MSG_INFO("----------------------------------------------- " );
372 }
373
374}
375
376
377
378//This method merges CalibHits from Inactive & Active
379//containers in case they have the same Identifiers,
380//what is the normal situation if that happens
381//only once for the given Identifier
383
384 bool new_id = false;
385
386 if(!m_id_vec.empty()) {
387
388 for (int iter=0; iter != static_cast<int>(m_id_vec.size()); iter++) {
389 if(id == m_id_vec[iter]) {
390 new_id = false;
391 break;
392 }
393 else {
394 new_id = true;
395 }
396 }
397
398 if(new_id) m_id_vec.push_back(id);
399 }
400 else {
401 //nothing to merge.
402 //push all IDs in the vector
403 m_id_vec.push_back(id) ;
404 }
405
406}
407
408
409
410
411//This method shows all IDs into the string format
413
414 ATH_MSG_INFO("=================================================" );
415 ATH_MSG_INFO("Show all CalibHits Identifiers for current events" );
416 ATH_MSG_INFO("=================================================" );
417
418 for (int iter=0; iter != static_cast<int>(m_id_vec.size()); iter++) {
419
420 ATH_MSG_INFO(m_id_helper->show_to_string(m_id_vec[iter]) );
421
422 }
423
424}
425
426
427
428
429//This method is useful to find those IDs, which are
430//probably not repeated inside the same CalibHits
431//container but in the different ones.
432//
433//If there aren't repeated IDs in the different
434//CalibHit containers then this method must tell
435//that it did not find any of them.
436//
437//This is claimed because 'm_id_vec' keeps only
438//one pattern of those IDs, which were repeated
439//inside the one particular container.
440//
441//Otherwise, if this method found a repeated ID
442//it means that this ID belongs to the CalibHits
443//contained inside the different containers!
445
446 ATH_MSG_INFO("======================================================" );
447 ATH_MSG_INFO("Check for the CalibHits Identifiers has been repeated " );
448 ATH_MSG_INFO(" inside the different CalibHit containers " );
449 ATH_MSG_INFO("======================================================" );
450
451
452 bool no_rep=true;
453
454 for (size_t i=0; i < m_id_vec.size(); i++) {
455
456 auto it_end = std::remove (m_id_vec.begin()+i+1,
457 m_id_vec.end(),
458 m_id_vec[i]);
459 int same = m_id_vec.end() - it_end;
460 m_id_vec.erase (it_end, m_id_vec.end());
461
462 if(same!=0) {
463 ATH_MSG_INFO("Identifier "
464 <<m_id_helper->show_to_string(m_id_vec[i])
465 <<" is repeated "<<(same+1)<<" times"
466 <<" inside different containers " );
467
468 no_rep=false;
469 }
470 } //end looping
471
472
473 if(no_rep) {
474 ATH_MSG_INFO("*** No repeated CalibHit Identifier "
475 <<"in the different containers was found ***" );
476 }
477
478}
479
480
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_ERROR(x)
#define ATH_MSG_INFO(x)
#define ATH_MSG_DEBUG(x)
This class provides an interface to generate or decode an identifier for the upper levels of the dete...
AthAlgorithm(const std::string &name, ISvcLocator *pSvcLocator)
Constructor with parameters:
const ServiceHandle< StoreGateSvc > & detStore() const
boost::transform_iterator< make_const, typename CONT::const_iterator > const_iterator
virtual StatusCode execute() override
Gaudi::Property< std::string > m_tiledmHitContainer
std::vector< Identifier > m_id_vec
const CaloCalibrationHitContainer * m_LArDMHitCnt
Gaudi::Property< std::string > m_tileInactiveHitContainer
const CaloCalibrationHitContainer * m_TileInactiveHitCnt
const CaloCalibrationHitContainer * m_ActiveHitCnt
const CaloCalibrationHitContainer * m_TileDMHitCnt
CalibHitIDCheck(const std::string &name, ISvcLocator *pSvcLocator)
Gaudi::Property< std::string > m_tileActiveHitContainer
Gaudi::Property< std::string > m_larActiveHitContainer
Gaudi::Property< std::string > m_larInactiveHitContainer
void merge(Identifier)
Gaudi::Property< bool > m_ShowAll
virtual ~CalibHitIDCheck()
const AtlasDetectorID * m_id_helper
virtual StatusCode initialize() override
const CaloCalibrationHitContainer * m_TileActiveHitCnt
Gaudi::Property< bool > m_CheckAll
Gaudi::Property< std::string > m_larDMHitContainer
Gaudi::Property< bool > m_Check
const CaloCalibrationHitContainer * m_InactiveHitCnt
Definition merge.py:1
DataModel_detail::iterator< DVL > remove(typename DataModel_detail::iterator< DVL > beg, typename DataModel_detail::iterator< DVL > end, const T &value)
Specialization of remove for DataVector/List.