ATLAS Offline Software
Loading...
Searching...
No Matches
TileCellVerify.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2020 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 , m_tileID(0)
52 , m_dumpCells(false)
53 , m_sortFlag(false)
54
55{
56 declareProperty("DumpCells", m_dumpCells);
57 declareProperty("SortFlag", m_sortFlag);
58}
59
62
63// Alg standard interfacw function
65
66 // retrieve TileID helper from det store
67 CHECK( detStore()->retrieve(m_tileID) );
68
69 ATH_CHECK( m_cellContainer1Key.initialize() );
70 ATH_CHECK( m_cellContainer2Key.initialize() );
71
72 ATH_MSG_INFO( "TileCellVerify initialization completed" );
73
74 return StatusCode::SUCCESS;
75}
76
78
79 // step1: read two cell containers from TES
81 ATH_CHECK(cellContainer1.isValid());
82
84 ATH_CHECK(cellContainer2.isValid());
85
86 // step2: first compare the number of cells in the two containers
87 int nCells1 = cellContainer1->size();
88 int nCells2 = cellContainer2->size();
89 ATH_MSG_INFO( "The number of cells in " << m_cellContainer1Key.key() << " is " << nCells1 );
90 ATH_MSG_INFO( "The number of cells in " << m_cellContainer2Key.key() << " is " << nCells2 );
91
92 if (nCells1 != nCells2) {
93 ATH_MSG_ERROR( "The number of cells is not equal in the two cell "
94 << "containers: " << m_cellContainer1Key.key()
95 << " and " << m_cellContainer2Key.key() );
96
97 return (StatusCode::SUCCESS);
98 }
99
100 // step3: to sort the cells in the container read above by energy
101 vector<const CaloCell*> cells1;
102 vector<const CaloCell*> cells2;
103 const CaloCell* cell1(nullptr);
104 const CaloCell* cell2(nullptr);
105 if (m_sortFlag) {
106
107 for (const CaloCell* cell : *cellContainer1) {
108 cells1.push_back(cell);
109 }
110
111 for (const CaloCell* cell : *cellContainer2) {
112 cells2.push_back(cell);
113 }
114
115 sort(cells1.begin(), cells1.end(), CompCell());
116 sort(cells2.begin(), cells2.end(), CompCell());
117 }
118
119 // step4: then compare every cell-pair in the containers
120 bool bErrorFlag = false;
121 bool bOnlyOnceFlag = false;
122 bool lVerbose = msgLvl(MSG::VERBOSE);
123 for (int i = 0; i < nCells1; ++i) {
124
125 if (m_sortFlag) {
126 cell1 = cells1[i];
127 cell2 = cells2[i];
128 } else {
129 cell1 = (*cellContainer1)[i];
130 cell2 = (*cellContainer2)[i];
131 }
132
133 Identifier id1 = cell1->ID();
134 Identifier id2 = cell2->ID();
135 if (id1 != id2) bErrorFlag = true;
136 if (lVerbose && (m_dumpCells || bErrorFlag)) {
137
138 if (!bOnlyOnceFlag) {
139 msg(MSG::VERBOSE) << " ===" << m_cellContainer1Key.key() << "=== ===" << m_cellContainer2Key.key() << "===" << endmsg;
140 msg(MSG::VERBOSE) << " Index e1 id1 | e2 id2" << endmsg;
141 msg(MSG::VERBOSE) << "--------------------------------------------------------------------------------" << endmsg;
142 bOnlyOnceFlag = true;
143 }
144
145 msg(MSG::VERBOSE) << setw(5) << i << " " << setw(12) << cell1->energy() << " [";
146 msg(MSG::VERBOSE) << m_tileID->to_string(id1, -2) << "]";
147 msg(MSG::VERBOSE) << " | " << setw(12) << cell2->energy() << " [";
148 msg(MSG::VERBOSE) << m_tileID->to_string(id2, -2) << "]";
149
150 if (bErrorFlag) msg(MSG::VERBOSE) << " * ";
151
152 msg(MSG::VERBOSE) << endmsg;
153
154 } else if (bErrorFlag){
155 break;
156 }
157 }
158 if (bOnlyOnceFlag) {
159 msg(MSG::VERBOSE) << "--------------------------------------------------------------------------------" << endmsg;
160 }
161 if (!bErrorFlag) {
162 ATH_MSG_INFO( "The two cellContainers (" << m_cellContainer1Key.key()
163 << " and " << m_cellContainer2Key.key() << ") are same!!!" );
164 } else {
165 ATH_MSG_INFO( "The two cellContainers (" << m_cellContainer1Key.key()
166 << " and " << m_cellContainer2Key.key() << ") are not same!!!" );
167 }
168
169 // Execution completed.
170 ATH_MSG_INFO( "TileCellVerify execution completed successfully" );
171
172 return StatusCode::SUCCESS;
173}
174
176
177 ATH_MSG_INFO( "TileCellVerify::finalize() end" );
178
179 return StatusCode::SUCCESS;
180}
181
#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.
HWIdentifier id2
Handle class for reading from StoreGate.
AthAlgorithm(const std::string &name, ISvcLocator *pSvcLocator)
Constructor with parameters:
Gaudi::Details::PropertyBase & declareProperty(Gaudi::Property< T, V, H > &t)
const ServiceHandle< StoreGateSvc > & detStore() const
bool msgLvl(const MSG::Level lvl) const
MsgStream & msg() 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
StatusCode execute()
SG::ReadHandleKey< CaloCellContainer > m_cellContainer1Key
StatusCode initialize()
TileCellVerify(const std::string &name, ISvcLocator *pSvcLocator)
STL namespace.
void sort(typename DataModel_detail::iterator< DVL > beg, typename DataModel_detail::iterator< DVL > end)
Specialization of sort for DataVector/List.