ATLAS Offline Software
Loading...
Searching...
No Matches
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
16namespace Trk {
18}
19
20class IdentifierHash;
21
22
24{
25public:
26 TrkEDMTestAlg(const std::string& name, ISvcLocator* pSvcLocator);
28 StatusCode initialize();
29 StatusCode execute();
30 StatusCode finalize();
31
32protected:
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
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
83template <class T>
84void
85TrkEDMTestAlg::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
120template <class T>
121void
122TrkEDMTestAlg::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
152template <class T>
153void
154TrkEDMTestAlg::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
166template <class T>
167unsigned int
168TrkEDMTestAlg::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
#define ATH_MSG_VERBOSE(x)
#define ATH_MSG_WARNING(x)
static Double_t sc
AthAlgorithm(const std::string &name, ISvcLocator *pSvcLocator)
Constructor with parameters:
This is a "hash" representation of an Identifier.
std::pair< const Trk::TrkDetElementBase *, const Trk::TrkDetElementBase * > getReadoutElements(const PRD *prd) const
std::map< std::string, unsigned int > m_numConstObjsFound
void loadAndDumpIdentifiableContainer(const std::string &collectionName, std::ofstream &stream)
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...
virtual StatusCode runTest()=0
TrkEDMTestAlg(const std::string &name, ISvcLocator *pSvcLocator)
StatusCode initialize()
bool testDetectorElement(IdentifierHash idhash, const IDHELPER *helper, const PRD *prd) const
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...
void checkPRD(const PRD *prd, const IDHELPER *helper, const COLLECTION &coll)
std::map< std::string, unsigned int > m_numContsFound
bool m_doDetailedChecks
If true, try to examine the PRDs etc in detail and catch any errors.
void checkPRDCollectionValidity(const COLLECTION &coll)
bool m_dumpSummaryToFile
std::string m_summaryDumpFileName
unsigned int m_eventNum
numbers of event
StatusCode finalize()
unsigned int dumpAndTestElements(const T *container, std::ofstream &stream)
StatusCode execute()
unsigned int m_numDetailedWarnings
Count of detailed warning found.
std::ofstream m_summaryFileOutput
This is the base class for all tracking detector elements with read-out relevant information.
bool contains(const std::string &s, const std::string &regx)
does a string contain the substring
Definition hcg.cxx:114
Ensure that the ATLAS eigen extensions are properly loaded.
STL namespace.