ATLAS Offline Software
TrkEDMTestAlg.h
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration
3 */
4 
5 #ifndef TRACKINGTESTEDM_H
6 #define TRACKINGTESTEDM_H
7 
9 #include <vector>
10 #include <string>
11 #include <fstream>
12 #include <map>
13 #include <iostream>
14 #include <iomanip>
15 
16 namespace Trk {
17  class TrkDetElementBase;
18 }
19 
20 class IdentifierHash;
21 
22 
24 {
25 public:
26  TrkEDMTestAlg(const std::string& name, ISvcLocator* pSvcLocator);
31 
32 protected:
33  virtual StatusCode runTest() = 0;
34 
36  template <class T>
37  void loadAndDumpContainer(const std::string& collectionName, std::ofstream& stream);
38 
39  template <class T>
40  void loadAndDumpIdentifiableContainer(const std::string& collectionName, std::ofstream& stream);
41 
43  template <class T>
44  void loadAndDumpMultipleContainers(std::vector<std::string>& collectionNames, std::ofstream& stream);
45 
46  template <class T>
47  unsigned int dumpAndTestElements (const T* container, std::ofstream& stream);
48 
49  template <class COLLECTION>
50  void checkPRDCollectionValidity(const COLLECTION& coll);
51 
52  template < class PRD, class IDHELPER, class COLLECTION >
53  void checkPRD(const PRD* prd, const IDHELPER* helper, const COLLECTION& coll);
54 
55  template <class PRD>
56  std::pair<const Trk::TrkDetElementBase*, const Trk::TrkDetElementBase*> getReadoutElements(const PRD* prd) const;
57 
58  template <class IDHELPER, class PRD>
59  bool testDetectorElement(IdentifierHash idhash, const IDHELPER* helper, const PRD* prd) const;
60 
62  unsigned int m_eventNum;
63 
67 
68  std::string m_summaryDumpFileName;
69  std::ofstream m_summaryFileOutput;
70 
72  unsigned int m_numDetailedWarnings;
73 
74  /*Count of number of times successfully retrieved. 1st is SG key, 2nd is count.*/
75  std::map<std::string, unsigned int> m_numContsFound;
76 
77  /*Count of number of component objects. 1st is SG key, 2nd is count.*/
78  std::map<std::string, unsigned int> m_numConstObjsFound;
79 
80 };
81 
82 
83 template <class T>
84 void
85 TrkEDMTestAlg::loadAndDumpIdentifiableContainer( const std::string& containerName, std::ofstream& stream)
86 {
87  using namespace std;
88 
89  const T* container;
90  if (!evtStore()->contains<T>(containerName)) return;
91  StatusCode sc = evtStore()->retrieve(container, containerName);
92  if (sc.isSuccess())
93  {
94  typename T::const_iterator::const_iterator element = container->begin();
95  typename T::const_iterator::const_iterator lastElement = container->end();
96  if (m_dumpToFile)
97  stream <<"Found container "<<containerName<<", which has "<<container->numberOfCollections()<<" collections (see below)."<<std::endl;
98  if (m_dumpToMsg)
99  ATH_MSG_VERBOSE("Found container "<<containerName<<", which has "<<container->numberOfCollections()<<" collections (see below).");
100 
101  m_numContsFound[containerName]++; // increment counter.
102 
103  unsigned int totalConsituents = dumpAndTestElements(container, stream);
104 
105  if (m_dumpToFile)
106  stream<<"Found "<<totalConsituents<<" constituent objects."<<std::endl;
107  if (m_dumpToMsg)
108  ATH_MSG_VERBOSE("Found "<<totalConsituents<<" constituent objects.");
109  m_numConstObjsFound[containerName]+=totalConsituents; // increment counter.
110  }else{
111  if (m_dumpToFile)
112  stream<<"WARNING! Could not find container: "<<containerName<<"!"<<std::endl;
113  if (m_dumpToMsg)
114  ATH_MSG_WARNING("Could not find container: "<<containerName<<"!");
115  }
116 
117  return;
118 }
119 
120 template <class T>
121 void
122 TrkEDMTestAlg::loadAndDumpContainer( const std::string& containerName, std::ofstream& stream)
123 {
124  using namespace std;
125  const T* container;
126  if (!evtStore()->contains<T>(containerName)) return;
127  if (evtStore()->retrieve(container, containerName).isSuccess()) {
128  if (m_dumpToFile)
129  stream <<"Found container "<<containerName<<", which has "<<container->size()
130  <<" elements (see below)."<<std::endl;
131  if (m_dumpToMsg)
132  ATH_MSG_VERBOSE("Found container "<<containerName<<", which has "<<container->size()
133  <<" elements (see below).");
134 
135  m_numContsFound[containerName]++; // increment counter.
136  m_numConstObjsFound[containerName]+=container->size(); // increment counter.
137  unsigned int totalConsituents = dumpAndTestElements(container, stream);
138  if (m_dumpToFile)
139  stream<<"Found "<<totalConsituents<<" constituent objects. (size was reported as "<<container->size()<<")"<<std::endl;
140  if (m_dumpToMsg)
141  ATH_MSG_VERBOSE("Found "<<totalConsituents<<" constituent objects.(size was reported as "<<container->size()<<")");
142  }else{
143  if (m_dumpToFile)
144  stream<<"WARNING! Could not find container: "<<containerName<<"!"<<std::endl;
145  if (m_dumpToMsg)
146  ATH_MSG_WARNING("Could not find container: "<<containerName<<"!");
147  }
148  return;
149 }
150 
151 
152 template <class T>
153 void
154 TrkEDMTestAlg::loadAndDumpMultipleContainers( std::vector<std::string>& containerNames, std::ofstream& stream)
155 {
156  using namespace std;
157  //loads tracks
158  for (vector<string>::const_iterator it=containerNames.begin(); it!=containerNames.end() ; ++it)
159  {
160  const std::string& containerLoc = *it;
161  loadAndDumpContainer<T>( containerLoc, stream );
162  }
163  return;
164 }
165 
166 template <class T>
167 unsigned int
168 TrkEDMTestAlg::dumpAndTestElements (const T* container, std::ofstream& stream)
169 {
170  unsigned int numConsituents=0;
171 
172  typename T::const_iterator element = container->begin();
173  typename T::const_iterator lastElement = container->end();
174 
175  for ( ; element!=lastElement ; ++element) {
176  if (*element!=0){
177  ++numConsituents;
178  // dumping collections
179  if (m_dumpToFile)
180  stream << std::setprecision(6) << **element<<std::endl;
181  if (m_dumpToMsg)
182  ATH_MSG_VERBOSE(**element);
183  }else{
184  if (m_dumpToFile)
185  stream<<"WARNING! Zero pointer!"<<std::endl;
186  if (m_dumpToMsg)
187  ATH_MSG_WARNING("Zero pointer!");
188  }
189  }
190  return numConsituents;
191 }
192 
193 
194 
195 #endif
python.PyKernel.retrieve
def retrieve(aClass, aKey=None)
Definition: PyKernel.py:110
TrkEDMTestAlg::~TrkEDMTestAlg
~TrkEDMTestAlg()
TrkEDMTestAlg::TrkEDMTestAlg
TrkEDMTestAlg(const std::string &name, ISvcLocator *pSvcLocator)
Definition: TrkEDMTestAlg.cxx:8
TrkEDMTestAlg::getReadoutElements
std::pair< const Trk::TrkDetElementBase *, const Trk::TrkDetElementBase * > getReadoutElements(const PRD *prd) const
skel.it
it
Definition: skel.GENtoEVGEN.py:396
TrkEDMTestAlg::m_dumpToMsg
bool m_dumpToMsg
Definition: TrkEDMTestAlg.h:64
TrkEDMTestAlg::loadAndDumpIdentifiableContainer
void loadAndDumpIdentifiableContainer(const std::string &collectionName, std::ofstream &stream)
Definition: TrkEDMTestAlg.h:85
TrkEDMTestAlg::checkPRDCollectionValidity
void checkPRDCollectionValidity(const COLLECTION &coll)
TrkEDMTestAlg::m_dumpSummaryToFile
bool m_dumpSummaryToFile
Definition: TrkEDMTestAlg.h:66
ATH_MSG_VERBOSE
#define ATH_MSG_VERBOSE(x)
Definition: AthMsgStreamMacros.h:28
TrkEDMTestAlg::checkPRD
void checkPRD(const PRD *prd, const IDHELPER *helper, const COLLECTION &coll)
AthenaPoolTestWrite.stream
string stream
Definition: AthenaPoolTestWrite.py:12
AthenaPoolTestRead.sc
sc
Definition: AthenaPoolTestRead.py:27
runBeamSpotCalibration.helper
helper
Definition: runBeamSpotCalibration.py:112
TrkEDMTestAlg::m_summaryFileOutput
std::ofstream m_summaryFileOutput
Definition: TrkEDMTestAlg.h:69
AthAlgorithm.h
AthCommonDataStore< AthCommonMsg< Algorithm > >::evtStore
ServiceHandle< StoreGateSvc > & evtStore()
The standard StoreGateSvc (event store) Returns (kind of) a pointer to the StoreGateSvc.
Definition: AthCommonDataStore.h:85
TrkEDMTestAlg::m_numDetailedWarnings
unsigned int m_numDetailedWarnings
Count of detailed warning found.
Definition: TrkEDMTestAlg.h:72
TrkEDMTestAlg::dumpAndTestElements
unsigned int dumpAndTestElements(const T *container, std::ofstream &stream)
Definition: TrkEDMTestAlg.h:168
TrkEDMTestAlg::loadAndDumpContainer
void loadAndDumpContainer(const std::string &collectionName, std::ofstream &stream)
load container of objects, and dump each contained object to MsgStream, and or external file (dependi...
Definition: TrkEDMTestAlg.h:122
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
TrkEDMTestAlg::testDetectorElement
bool testDetectorElement(IdentifierHash idhash, const IDHELPER *helper, const PRD *prd) const
TrkEDMTestAlg::m_eventNum
unsigned int m_eventNum
numbers of event
Definition: TrkEDMTestAlg.h:62
TrkEDMTestAlg::m_dumpToFile
bool m_dumpToFile
Definition: TrkEDMTestAlg.h:65
AthAlgorithm
Definition: AthAlgorithm.h:47
Trk
Ensure that the ATLAS eigen extensions are properly loaded.
Definition: FakeTrackBuilder.h:9
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:228
TrkEDMTestAlg
Definition: TrkEDMTestAlg.h:24
ATH_MSG_WARNING
#define ATH_MSG_WARNING(x)
Definition: AthMsgStreamMacros.h:32
TrkEDMTestAlg::m_numConstObjsFound
std::map< std::string, unsigned int > m_numConstObjsFound
Definition: TrkEDMTestAlg.h:78
TrkEDMTestAlg::m_summaryDumpFileName
std::string m_summaryDumpFileName
Definition: TrkEDMTestAlg.h:68
TrkEDMTestAlg::m_doDetailedChecks
bool m_doDetailedChecks
If true, try to examine the PRDs etc in detail and catch any errors.
Definition: TrkEDMTestAlg.h:71
TrkEDMTestAlg::loadAndDumpMultipleContainers
void loadAndDumpMultipleContainers(std::vector< std::string > &collectionNames, std::ofstream &stream)
load container of objects, and dump each contained object to MsgStream, and or external file (dependi...
Definition: TrkEDMTestAlg.h:154
TrkEDMTestAlg::finalize
StatusCode finalize()
Definition: TrkEDMTestAlg.cxx:49
TrkEDMTestAlg::initialize
StatusCode initialize()
Definition: TrkEDMTestAlg.cxx:27
TrkEDMTestAlg::m_numContsFound
std::map< std::string, unsigned int > m_numContsFound
Definition: TrkEDMTestAlg.h:75
IdentifierHash
This is a "hash" representation of an Identifier. This encodes a 32 bit index which can be used to lo...
Definition: IdentifierHash.h:25
TrkEDMTestAlg::runTest
virtual StatusCode runTest()=0
TrkEDMTestAlg::execute
StatusCode execute()
Definition: TrkEDMTestAlg.cxx:40
TSU::T
unsigned long long T
Definition: L1TopoDataTypes.h:35