ATLAS Offline Software
TileRawChannelVerify.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 : TileRawChannelVerify.cxx
7 // Author : Zhifang
8 // Created : May, 2002
9 //
10 // DESCRIPTION:
11 // Implement the TileRawChannelVerify class
12 //
13 // HISTORY:
14 //
15 // BUGS:
16 //
17 //*****************************************************************************
18 
19 // Tile includes
22 #include "StoreGate/ReadHandle.h"
23 
24 // Atlas includes
25 // access all RawChannels inside container
28 
29 // Gaudi includes
30 #include "GaudiKernel/Bootstrap.h"
31 #include "GaudiKernel/ISvcLocator.h"
32 
33 // C++ STL includes
34 #include <vector>
35 #include <algorithm>
36 
37 // C includes
38 #include <cmath>
39 
40 using namespace std;
41 
42 
49  public:
50  bool operator()(const TileRawChannel* p1, const TileRawChannel* p2) {
51  return p1->amplitude() < p2->amplitude();
52  }
53 };
54 
55 //==========================================================================
56 // TileRawChannelVerify's implementations
57 //==========================================================================
58 
59 // Constructor
60 TileRawChannelVerify::TileRawChannelVerify(const std::string& name, ISvcLocator* pSvcLocator)
61  : AthAlgorithm(name, pSvcLocator)
62  , m_tileHWID(0)
63 {
64  declareProperty("Precision", m_precision = 0);
65  declareProperty("DumpRawChannels", m_dumpRawChannels = false);
66  declareProperty("SortFlag", m_sortFlag = false);
67 }
68 
70 }
71 
72 // Alg standard interfacw function
74 
75  // retrieve TileHWID helper from det store
77 
80 
81  ATH_MSG_INFO( "TileRawChannelVerify initialization completed" );
82 
83  return StatusCode::SUCCESS;
84 }
85 
87 
88  // step1: read two cell containers from TES
91 
92  SelectAllObject<TileRawChannelContainer> selAll1(rawChannelContainer1.cptr());
95 
96  SelectAllObject<TileRawChannelContainer> selAll2(rawChannelContainer2.cptr());
99 
100  // step2: first compare the number of cells in the two containers
101  int nSize1 = 0;
102  for (; rawItr1 != end1; ++rawItr1) ++nSize1;
103 
104  int nSize2 = 0;
105  for (; rawItr2 != end2; ++rawItr2) ++nSize2;
106 
107  ATH_MSG_INFO( "The number of cells in " << m_rawChannelContainer1Key.key() << " is " << nSize1 );
108  ATH_MSG_INFO( "The number of cells in " << m_rawChannelContainer2Key.key() << " is " << nSize2 );
109 
110  if (nSize1 != nSize2) {
111  ATH_MSG_ERROR( "The number of rawChannels is not equal in the two containers" );
112  return (StatusCode::SUCCESS);
113  }
114 
115  // step3: to sort the cells in the containers by amplitude
116  vector<const TileRawChannel*> rawChannels1;
117  vector<const TileRawChannel*> rawChannels2;
118  const TileRawChannel* rawChannel1;
119  const TileRawChannel* rawChannel2;
120  if (m_sortFlag) {
121  rawItr1 = selAll1.begin();
122  end1 = selAll1.end();
123  for (; rawItr1 != end1; ++rawItr1)
124  rawChannels1.push_back((*rawItr1));
125 
126  sort(rawChannels1.begin(), rawChannels1.end(), CompRawChannel());
127 
128  rawItr2 = selAll2.begin();
129  end2 = selAll2.end();
130  for (; rawItr2 != end2; ++rawItr2)
131  rawChannels2.push_back((*rawItr2));
132 
133  sort(rawChannels2.begin(), rawChannels2.end(), CompRawChannel());
134  }
135 
136  rawItr1 = selAll1.begin();
137  end1 = selAll1.end();
138 
139  rawItr2 = selAll2.begin();
140  end2 = selAll2.end();
141 
142  // step4: then compare every cell-pair in the containers
143  bool bErrorFlag = false;
144  bool bHeaderFlag = true;
145  for (int i = 0; i < nSize1; ++i) {
146  if (m_sortFlag) {
147  rawChannel1 = rawChannels1[i];
148  rawChannel2 = rawChannels2[i];
149  } else {
150  rawChannel1 = (*rawItr1);
151  ++rawItr1;
152  rawChannel2 = (*rawItr2);
153  ++rawItr2;
154  }
155  HWIdentifier id1 = rawChannel1->adc_HWID();
156  HWIdentifier id2 = rawChannel2->adc_HWID();
157  double amp1 = rawChannel1->amplitude();
158  double amp2 = rawChannel2->amplitude();
159  double diff = fabs(amp1 - amp2);
160  if (id1 != id2 || diff > m_precision) bErrorFlag = true;
161  if (msgLvl(MSG::VERBOSE) && (m_dumpRawChannels || bErrorFlag)) {
162  if (bHeaderFlag) {
164  << "=== ===" << m_rawChannelContainer2Key.key() << "===" << endmsg;
165  msg(MSG::VERBOSE) << " Index e1 id1 | e2 id2" << endmsg;
166  msg(MSG::VERBOSE) << "--------------------------------------------------------------------------------" << endmsg;
167  bHeaderFlag = false;
168  }
169  msg(MSG::VERBOSE) << setw(5) << i
170  << " " << setw(12) << amp1
171  << " [" << m_tileHWID->to_string(id1) << "]"
172  << " | " << setw(12) << amp2
173  << " [" << m_tileHWID->to_string(id2) << "]";
174  if (diff > m_precision) {
175  msg(MSG::VERBOSE) << " A* ";
176  }
177  if (id1 != id2) {
178  msg(MSG::VERBOSE) << " I* ";
179  }
180  msg(MSG::VERBOSE) << endmsg;
181  } else if (bErrorFlag) {
182  break;
183  }
184  }
185  if (!bHeaderFlag) {
186  msg(MSG::VERBOSE) << "--------------------------------------------------------------------------------" << endmsg;
187  }
188  if (!bErrorFlag) {
189  ATH_MSG_INFO( "The two cellContainers (" << m_rawChannelContainer1Key.key()
190  << " and " << m_rawChannelContainer2Key.key() << ") are the same!!!" );
191  } else {
192  ATH_MSG_INFO( "The two cellContainers (" << m_rawChannelContainer1Key.key()
193  << " and " << m_rawChannelContainer2Key.key() << ") are not the same!!!" );
194  }
195 
196  // Execution completed.
197  ATH_MSG_INFO( "TileRawChannelVerify execution completed successfully" );
198 
199  return StatusCode::SUCCESS;
200 }
201 
203 
204  ATH_MSG_INFO( "TileRawChannelVerify finalized successfully" );
205 
206  return StatusCode::SUCCESS;
207 }
208 
python.PyKernel.retrieve
def retrieve(aClass, aKey=None)
Definition: PyKernel.py:110
TileRawChannelVerify::m_sortFlag
bool m_sortFlag
if true=> TileRawChannels are sorted by amplitude
Definition: TileRawChannelVerify.h:76
ATH_MSG_INFO
#define ATH_MSG_INFO(x)
Definition: AthMsgStreamMacros.h:31
SelectAllObjectMT::end
const_iterator end()
Definition: SelectAllObjectMT.h:131
SG::ReadHandle::cptr
const_pointer_type cptr()
Dereference the pointer.
SG::ReadHandle
Definition: StoreGate/StoreGate/ReadHandle.h:70
AthCommonDataStore< AthCommonMsg< Algorithm > >::declareProperty
Gaudi::Details::PropertyBase & declareProperty(Gaudi::Property< T > &t)
Definition: AthCommonDataStore.h:145
TileRawChannelVerify::m_dumpRawChannels
bool m_dumpRawChannels
if true=> Differences found in the TileRawChannels are dumped on the screen
Definition: TileRawChannelVerify.h:75
TRTCalib_cfilter.p1
p1
Definition: TRTCalib_cfilter.py:130
TileRawChannelVerify::m_tileHWID
const TileHWID * m_tileHWID
Pointer to TileHWID
Definition: TileRawChannelVerify.h:63
mc.diff
diff
Definition: mc.SFGenPy8_MuMu_DD.py:14
AthCommonMsg< Algorithm >::msgLvl
bool msgLvl(const MSG::Level lvl) const
Definition: AthCommonMsg.h:30
TileRawChannelVerify::m_rawChannelContainer2Key
SG::ReadHandleKey< TileRawChannelContainer > m_rawChannelContainer2Key
Definition: TileRawChannelVerify.h:69
SG::VarHandleKey::key
const std::string & key() const
Return the StoreGate ID for the referenced object.
Definition: AthToolSupport/AsgDataHandles/Root/VarHandleKey.cxx:141
TileRawChannelVerify::m_precision
double m_precision
maximum difference between the amplitudes of the TileRawChannels to be compared
Definition: TileRawChannelVerify.h:73
TileRawData::adc_HWID
HWIdentifier adc_HWID(void) const
Definition: TileRawData.h:53
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
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
TRTCalib_cfilter.p2
p2
Definition: TRTCalib_cfilter.py:131
SelectAllObjectMT::begin
const_iterator begin()
Definition: SelectAllObjectMT.h:115
SelectAllObjectMT
Definition: SelectAllObjectMT.h:11
TileRawChannel::amplitude
float amplitude(int ind=0) const
Definition: TileRawChannel.h:101
TileRawChannelVerify.h
TileHWID.h
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
TileRawChannelVerify::execute
StatusCode execute()
execute method
Definition: TileRawChannelVerify.cxx:86
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
TileRawChannel
Definition: TileRawChannel.h:35
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
TileRawChannelVerify::m_rawChannelContainer1Key
SG::ReadHandleKey< TileRawChannelContainer > m_rawChannelContainer1Key
Definition: TileRawChannelVerify.h:65
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
SelectAllObjectMT::const_iterator
Definition: SelectAllObjectMT.h:22
TileRawChannelVerify::finalize
StatusCode finalize()
finalize method
Definition: TileRawChannelVerify.cxx:202
AthAlgorithm
Definition: AthAlgorithm.h:47
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:228
errorcheck.h
Helpers for checking error return status codes and reporting errors.
TileRawChannelVerify::~TileRawChannelVerify
virtual ~TileRawChannelVerify()
Destructor
Definition: TileRawChannelVerify.cxx:69
CompRawChannel
Small class holding a single method to compare two different TileRawChannel
Definition: TileRawChannelVerify.cxx:48
CompRawChannel::operator()
bool operator()(const TileRawChannel *p1, const TileRawChannel *p2)
Definition: TileRawChannelVerify.cxx:50
TileRawChannelVerify::initialize
StatusCode initialize()
initialize method
Definition: TileRawChannelVerify.cxx:73
AthCommonMsg< Algorithm >::msg
MsgStream & msg() const
Definition: AthCommonMsg.h:24
SelectAllObject.h
python.Constants.VERBOSE
int VERBOSE
Definition: Control/AthenaCommon/python/Constants.py:14
TileHWID::to_string
std::string to_string(const HWIdentifier &id, int level=0) const
extract all fields from HW identifier HWIdentifier get_all_fields ( const HWIdentifier & id,...
Definition: TileHWID.cxx:50
ReadHandle.h
Handle class for reading from StoreGate.
TileRawChannelVerify::TileRawChannelVerify
TileRawChannelVerify(const std::string &name, ISvcLocator *pSvcLocator)
Constructor.
Definition: TileRawChannelVerify.cxx:60