ATLAS Offline Software
Loading...
Searching...
No Matches
TileCellVerify.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 : TileCellVerify.cxx
7// Author : Zhifang
8// Created : May, 2002
9//
10// DESCRIPTION:
11// Implement the TileCellVerify class
12//
13// HISTORY:
14//
15// BUGS:
16//
17//*****************************************************************************
18
19// Tile includes
20#include "TileCellVerify.h"
21#include "TileEvent/TileCell.h"
22
23// Calo includes
25
26// Atlas includes
29
30
31//C++ STL includes
32#include <vector>
33#include <algorithm>
34
35using namespace std;
36
37class CompCell {
38 public:
39 bool operator()(const CaloCell* p1, const CaloCell* p2) {
40 return p1->energy() < p2->energy();
41 }
42};
43
44//==========================================================================
45// TileCellVerify's implementations
46//==========================================================================
47
48// Constructor
49TileCellVerify::TileCellVerify(const std::string& name, ISvcLocator* pSvcLocator)
50 : AthAlgorithm(name, pSvcLocator)
51{
52}
53
56
57// Alg standard interfacw function
59
60 // retrieve TileID helper from det store
61 CHECK( detStore()->retrieve(m_tileID) );
62
63 ATH_CHECK( m_cellContainer1Key.initialize() );
64 ATH_CHECK( m_cellContainer2Key.initialize() );
65
66 ATH_MSG_INFO( "TileCellVerify initialization completed" );
67
68 return StatusCode::SUCCESS;
69}
70
71StatusCode TileCellVerify::execute(const EventContext& ctx) {
72
73 // step1: read two cell containers from TES
75 ATH_CHECK(cellContainer1.isValid());
76
78 ATH_CHECK(cellContainer2.isValid());
79
80 // step2: first compare the number of cells in the two containers
81 int nCells1 = cellContainer1->size();
82 int nCells2 = cellContainer2->size();
83 ATH_MSG_INFO( "The number of cells in " << m_cellContainer1Key.key() << " is " << nCells1 );
84 ATH_MSG_INFO( "The number of cells in " << m_cellContainer2Key.key() << " is " << nCells2 );
85
86 if (nCells1 != nCells2) {
87 ATH_MSG_ERROR( "The number of cells is not equal in the two cell "
88 << "containers: " << m_cellContainer1Key.key()
89 << " and " << m_cellContainer2Key.key() );
90
91 return (StatusCode::SUCCESS);
92 }
93
94 // step3: to sort the cells in the container read above by energy
95 vector<const CaloCell*> cells1;
96 vector<const CaloCell*> cells2;
97 const CaloCell* cell1(nullptr);
98 const CaloCell* cell2(nullptr);
99 if (m_sortFlag) {
100
101 for (const CaloCell* cell : *cellContainer1) {
102 cells1.push_back(cell);
103 }
104
105 for (const CaloCell* cell : *cellContainer2) {
106 cells2.push_back(cell);
107 }
108
109 sort(cells1.begin(), cells1.end(), CompCell());
110 sort(cells2.begin(), cells2.end(), CompCell());
111 }
112
113 // step4: then compare every cell-pair in the containers
114 bool bErrorFlag = false;
115 bool bOnlyOnceFlag = false;
116 bool lVerbose = msgLvl(MSG::VERBOSE);
117 for (int i = 0; i < nCells1; ++i) {
118
119 if (m_sortFlag) {
120 cell1 = cells1[i];
121 cell2 = cells2[i];
122 } else {
123 cell1 = (*cellContainer1)[i];
124 cell2 = (*cellContainer2)[i];
125 }
126
127 Identifier id1 = cell1->ID();
128 Identifier id2 = cell2->ID();
129 if (id1 != id2) bErrorFlag = true;
130 if (lVerbose && (m_dumpCells || bErrorFlag)) {
131
132 if (!bOnlyOnceFlag) {
133 msg(MSG::VERBOSE) << " ===" << m_cellContainer1Key.key() << "=== ===" << m_cellContainer2Key.key() << "===" << endmsg;
134 msg(MSG::VERBOSE) << " Index e1 id1 | e2 id2" << endmsg;
135 msg(MSG::VERBOSE) << "--------------------------------------------------------------------------------" << endmsg;
136 bOnlyOnceFlag = true;
137 }
138
139 msg(MSG::VERBOSE) << setw(5) << i << " " << setw(12) << cell1->energy() << " [";
140 msg(MSG::VERBOSE) << m_tileID->to_string(id1, -2) << "]";
141 msg(MSG::VERBOSE) << " | " << setw(12) << cell2->energy() << " [";
142 msg(MSG::VERBOSE) << m_tileID->to_string(id2, -2) << "]";
143
144 if (bErrorFlag) msg(MSG::VERBOSE) << " * ";
145
146 msg(MSG::VERBOSE) << endmsg;
147
148 } else if (bErrorFlag){
149 break;
150 }
151 }
152 if (bOnlyOnceFlag) {
153 msg(MSG::VERBOSE) << "--------------------------------------------------------------------------------" << endmsg;
154 }
155 if (!bErrorFlag) {
156 ATH_MSG_INFO( "The two cellContainers (" << m_cellContainer1Key.key()
157 << " and " << m_cellContainer2Key.key() << ") are same!!!" );
158 } else {
159 ATH_MSG_INFO( "The two cellContainers (" << m_cellContainer1Key.key()
160 << " and " << m_cellContainer2Key.key() << ") are not same!!!" );
161 }
162
163 // Execution completed.
164 ATH_MSG_INFO( "TileCellVerify execution completed successfully" );
165
166 return StatusCode::SUCCESS;
167}
168
170
171 ATH_MSG_INFO( "TileCellVerify::finalize() end" );
172
173 return StatusCode::SUCCESS;
174}
175
#define endmsg
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_ERROR(x,...)
#define ATH_MSG_INFO(x,...)
Helpers for checking error return status codes and reporting errors.
#define CHECK(...)
Evaluate an expression and check for errors.
Handle class for reading from StoreGate.
AthAlgorithm(const std::string &name, ISvcLocator *pSvcLocator)
Constructor.
const ServiceHandle< StoreGateSvc > & detStore() const
bool msgLvl(const MSG::Level lvl) const
Data object for each calorimeter readout cell.
Definition CaloCell.h:57
double energy() const
get energy (data member)
Definition CaloCell.h:327
Identifier ID() const
get ID (from cached data member) non-virtual and inline for fast access
Definition CaloCell.h:295
bool operator()(const CaloCell *p1, const CaloCell *p2)
virtual bool isValid() override final
Can the handle be successfully dereferenced?
virtual ~TileCellVerify()
SG::ReadHandleKey< CaloCellContainer > m_cellContainer2Key
StatusCode finalize()
const TileID * m_tileID
Gaudi::Property< bool > m_sortFlag
SG::ReadHandleKey< CaloCellContainer > m_cellContainer1Key
StatusCode initialize()
Gaudi::Property< bool > m_dumpCells
TileCellVerify(const std::string &name, ISvcLocator *pSvcLocator)
StatusCode execute(const EventContext &ctx)
Execute method.
STL namespace.
void sort(typename DataModel_detail::iterator< DVL > beg, typename DataModel_detail::iterator< DVL > end)
Specialization of sort for DataVector/List.