ATLAS Offline Software
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
24 #include "CaloIdentifier/TileID.h"
25 
26 // Atlas includes
27 #include "StoreGate/ReadHandle.h"
29 
30 
31 //C++ STL includes
32 #include <vector>
33 #include <algorithm>
34 
35 using namespace std;
36 
37 class 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
49 TileCellVerify::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 
61 }
62 
63 // Alg standard interfacw function
65 
66  // retrieve TileID helper from det store
68 
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 
python.PyKernel.retrieve
def retrieve(aClass, aKey=None)
Definition: PyKernel.py:110
TileCellVerify.h
ReadCellNoiseFromCool.cell
cell
Definition: ReadCellNoiseFromCool.py:53
ATH_MSG_INFO
#define ATH_MSG_INFO(x)
Definition: AthMsgStreamMacros.h:31
SG::ReadHandle
Definition: StoreGate/StoreGate/ReadHandle.h:70
AthCommonDataStore< AthCommonMsg< Algorithm > >::declareProperty
Gaudi::Details::PropertyBase & declareProperty(Gaudi::Property< T > &t)
Definition: AthCommonDataStore.h:145
TileCellVerify::TileCellVerify
TileCellVerify(const std::string &name, ISvcLocator *pSvcLocator)
Definition: TileCellVerify.cxx:49
TRTCalib_cfilter.p1
p1
Definition: TRTCalib_cfilter.py:130
AthCommonMsg< Algorithm >::msgLvl
bool msgLvl(const MSG::Level lvl) const
Definition: AthCommonMsg.h:30
TileCellVerify::execute
StatusCode execute()
Definition: TileCellVerify.cxx:77
CompCell::operator()
bool operator()(const CaloCell *p1, const CaloCell *p2)
Definition: TileCellVerify.cxx:39
TileCellVerify::m_cellContainer1Key
SG::ReadHandleKey< CaloCellContainer > m_cellContainer1Key
Definition: TileCellVerify.h:61
TileCellVerify::finalize
StatusCode finalize()
Definition: TileCellVerify.cxx:175
SG::VarHandleKey::key
const std::string & key() const
Return the StoreGate ID for the referenced object.
Definition: AthToolSupport/AsgDataHandles/Root/VarHandleKey.cxx:141
std::sort
void sort(typename DataModel_detail::iterator< DVL > beg, typename DataModel_detail::iterator< DVL > end)
Specialization of sort for DataVector/List.
Definition: DVL_algorithms.h:554
TileID.h
AthCommonDataStore< AthCommonMsg< Algorithm > >::detStore
const ServiceHandle< StoreGateSvc > & detStore() const
The standard StoreGateSvc/DetectorStore Returns (kind of) a pointer to the StoreGateSvc.
Definition: AthCommonDataStore.h:95
CaloCell::energy
double energy() const
get energy (data member)
Definition: CaloCell.h:311
CompCell
Definition: TileCellVerify.cxx:37
TileCellVerify::~TileCellVerify
virtual ~TileCellVerify()
Definition: TileCellVerify.cxx:60
TRTCalib_cfilter.p2
p2
Definition: TRTCalib_cfilter.py:131
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
id2
HWIdentifier id2
Definition: LArRodBlockPhysicsV0.cxx:562
lumiFormat.i
int i
Definition: lumiFormat.py:85
endmsg
#define endmsg
Definition: AnalysisConfig_Ntuple.cxx:63
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
TileCell.h
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
CHECK
#define CHECK(...)
Evaluate an expression and check for errors.
Definition: Control/AthenaKernel/AthenaKernel/errorcheck.h:422
SG::VarHandleKey::initialize
StatusCode initialize(bool used=true)
If this object is used as a property, then this should be called during the initialize phase.
Definition: AthToolSupport/AsgDataHandles/Root/VarHandleKey.cxx:103
AthAlgorithm
Definition: AthAlgorithm.h:47
SG::ReadHandle::isValid
virtual bool isValid() override final
Can the handle be successfully dereferenced?
TileCellVerify::m_tileID
const TileID * m_tileID
Definition: TileCellVerify.h:70
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:228
errorcheck.h
Helpers for checking error return status codes and reporting errors.
CaloCell::ID
Identifier ID() const
get ID (from cached data member) non-virtual and inline for fast access
Definition: CaloCell.h:279
CaloCell
Data object for each calorimeter readout cell.
Definition: CaloCell.h:57
Tile_Base_ID::to_string
std::string to_string(const Identifier &id, int level=0) const
Definition: Tile_Base_ID.cxx:52
AthCommonMsg< Algorithm >::msg
MsgStream & msg() const
Definition: AthCommonMsg.h:24
TileCellVerify::initialize
StatusCode initialize()
Definition: TileCellVerify.cxx:64
TileCellVerify::m_dumpCells
bool m_dumpCells
Definition: TileCellVerify.h:72
TileCellVerify::m_sortFlag
bool m_sortFlag
Definition: TileCellVerify.h:73
python.Constants.VERBOSE
int VERBOSE
Definition: Control/AthenaCommon/python/Constants.py:14
ReadHandle.h
Handle class for reading from StoreGate.
DataVector::size
size_type size() const noexcept
Returns the number of elements in the collection.
TileCellVerify::m_cellContainer2Key
SG::ReadHandleKey< CaloCellContainer > m_cellContainer2Key
Definition: TileCellVerify.h:65
Identifier
Definition: IdentifierFieldParser.cxx:14