ATLAS Offline Software
Loading...
Searching...
No Matches
TestCaloDataAccess.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2022 CERN for the benefit of the ATLAS collaboration
3*/
4#include <iostream>
5#include <random>
6#include "tbb/parallel_reduce.h"
7#include "tbb/blocked_range.h"
8#include "TestTools/expect.h"
10#include "Gaudi/Property.h"
15#include "TestCaloDataAccess.h"
16#include <sys/time.h>
17
18
19#define DIFF(_name, _a, _b) if ( _a != _b ) \
20 ATH_MSG_WARNING( "Difference in " << _name << " " << _a << " ref " << _b ); \
21 else \
22 ATH_MSG_DEBUG( "Identical " << _name << " " << _a << " ref " << _b );
23
24
29
30class AskForRoI : public ParallelCallTest, public AthMessaging {
31public:
32 AskForRoI( const EventContext& context,
34 const TrigRoiDescriptor& roi )
35 : AthMessaging ("TestCaloDataAccess"),
36 m_context( context ),
37 m_svc( svc ),
38 m_roi ( roi ) {
40 }
42 if ( m_colRef ) { m_colRef->clear(); delete m_colRef; }
43 }
44
46 if ( m_roi.isFullscan() ){
47 std::cout << "wrong RoI descriptor used for RoI" << std::endl;
48 return StatusCode::FAILURE;
49 }
50 else{
51 // keep this for test reasons
52 //usleep (5000);
53 return m_svc->loadCollections( m_context, m_roi, TTEM, 2, sel );
54 }
55 }
56
57 StatusCode request( CaloConstCellContainer& c ) const {
58 if ( m_roi.isFullscan() ){
59 return m_svc->loadFullCollections( m_context, c );
60 }
61 else{
62 std::cout << "wrong RoI descriptor used for FS" << std::endl;
63 return StatusCode::FAILURE;
64 }
65 }
66
67 // calculate reference quantities in the first call
68 void firstCall() override {
69 Gaudi::Hive::setCurrentContext (m_context);
70 if ( m_roi.isFullscan() ) {
71 struct timeval t1{},t2{};
72 gettimeofday(&t1,NULL);
74 m_statusRef.ignore();
75 gettimeofday(&t2,NULL);
76
77 for ( const auto cell : *m_colRef ) {
78 if ( !cell ) continue;
79 m_etSumRef += cell->et();
80 m_countRef ++;
81 m_minEtaRef = std::min( m_minEtaRef, cell->eta() );
82 m_maxEtaRef = std::max( m_maxEtaRef, cell->eta() );
83 m_minPhiRef = std::min( m_minPhiRef, cell->phi() );
84 m_maxPhiRef = std::max( m_maxPhiRef, cell->phi() );
85 }
86 std::cout << "t lFC : " << m_context << " " << m_etSumRef << " " << t1.tv_sec << " " << t1.tv_usec << " " << t2.tv_sec << " " << t2.tv_usec << " " << ((t2.tv_sec-t1.tv_sec)*1e6+(t2.tv_usec-t1.tv_usec) )*1e-6 << std::endl;
87
88 } else {
89
90 struct timeval t1{},t2{};
91 gettimeofday(&t1,NULL);
93 m_statusRef.ignore();
94 gettimeofday(&t2,NULL);
95
96 for ( const auto cell : m_selRef ) {
97 m_etSumRef += cell->et();
98 m_countRef ++;
99 m_minEtaRef = std::min( m_minEtaRef, cell->eta() );
100 m_maxEtaRef = std::max( m_maxEtaRef, cell->eta() );
101 m_minPhiRef = std::min( m_minPhiRef, cell->phi() );
102 m_maxPhiRef = std::max( m_maxPhiRef, cell->phi() );
103 }
104 std::cout << "t RoI : " << m_context << " " << m_etSumRef << " " << t1.tv_sec << " " << t1.tv_usec << " " << t2.tv_sec << " " << t2.tv_usec << " " << ((t2.tv_sec-t1.tv_sec)*1e6+(t2.tv_usec-t1.tv_usec) )*1e-6 << std::endl;
105 }
106 }
107
108 bool callAndCompare() const override {
109
110 Gaudi::Hive::setCurrentContext (m_context);
113 double etSum = 0;
114 size_t count = 0;
115 double minEta = 100;
116 double maxEta = -100;
117 double minPhi = 100;
118 double maxPhi = -100;
119 StatusCode status;
120 if ( m_roi.isFullscan() ) {
121 status = request( col );
122 status.ignore();
123
124 for ( const auto cell : col ) {
125 if ( !cell ) continue;
126 etSum += cell->et();
127 count ++;
128 minEta = std::min( minEta, cell->eta() );
129 maxEta = std::max( maxEta, cell->eta() );
130 minPhi = std::min( minPhi, cell->phi() );
131 maxPhi = std::max( maxPhi, cell->phi() );
132 }
133 } else {
134
135 status = request( sel );
136 status.ignore();
137
138 for ( const auto cell : sel ) {
139 etSum += cell->et();
140 count ++;
141 minEta = std::min( minEta, cell->eta() );
142 maxEta = std::max( maxEta, cell->eta() );
143 minPhi = std::min( minPhi, cell->phi() );
144 maxPhi = std::max( maxPhi, cell->phi() );
145 }
146 std::cout << "callAndCompare : " << m_context << " " << count << " " << etSum << " " << minEta << " " << maxEta << " " << minPhi << " " << maxPhi << " " << " " << m_minEtaRef << " " << m_maxEtaRef << " " << m_minPhiRef << " " << m_maxPhiRef << " " << m_etSumRef << " " << m_countRef << std::endl;
147 }
148
149 DIFF( "RoI mask", status.getCode(), m_statusRef.getCode() );
150 DIFF( "RoI count ", count , m_countRef );
151 DIFF( "RoI etSum ", etSum , m_etSumRef );
152 DIFF( "RoI minEta", minEta, m_minEtaRef );
153 DIFF( "RoI maxEta", maxEta, m_maxEtaRef );
154 DIFF( "RoI minPhi", minPhi, m_minPhiRef );
155 DIFF( "RoI maxPhi", maxPhi, m_maxPhiRef );
156
157 bool checkStatus = m_statusRef == status
158 and m_countRef == count
159 and m_etSumRef == etSum
160 and m_minEtaRef == minEta
161 and m_maxEtaRef == maxEta
162 and m_minPhiRef == minPhi
163 and m_maxPhiRef == maxPhi;
164
165 if ( checkStatus == false ) {
166
167 // iterate over two slectors and compare cell by cell
168 for ( LArTT_Selector<LArCellCont>::const_iterator refIter = m_selRef.begin(), thisIter = sel.begin();
169 refIter != m_selRef.end() and thisIter != sel.end(); ++refIter, ++thisIter ) {
170 const LArCell* refCell = *refIter;
171 const LArCell* thisCell = *thisIter;
172 if ( thisCell->et() != refCell->et() ) {
173 ATH_MSG_WARNING( "eta/phi/et Reference cell " << refCell->eta() << "/" << refCell->phi() << "/" << refCell->et()
174 << " differ from the one in this request " << thisCell->eta() << "/" << thisCell->phi() << "/" << thisCell->et() );
175 }
176 }
177 }
178
179 return checkStatus;
180 }
181
182private:
183 const EventContext& m_context;
186
189 StatusCode m_statusRef;
190 double m_etSumRef = 0;
191 size_t m_countRef = 0;
192 double m_minEtaRef = 100;
193 double m_maxEtaRef = -100;
194 double m_minPhiRef = 100;
195 double m_maxPhiRef = -100;
196};
197
199 ISvcLocator* pSvcLocator ) :
200 ::AthReentrantAlgorithm( name, pSvcLocator ),
201 m_dataAccessSvc( "TrigCaloDataAccessSvc/TrigCaloDataAccessSvc", name ),
202 m_emulateRoIs ( true ),
203 m_emulateFixedRoIs (false)
204{
205 declareProperty("nFixedRoIs", m_nFixedRoIs = 1);
206 declareProperty("emulateRoIs", m_emulateRoIs);
207 declareProperty("emulateFixedRoIs", m_emulateFixedRoIs);
208
209}
210
212
214 CHECK( m_dataAccessSvc.retrieve() );
215 return StatusCode::SUCCESS;
216}
217
218void TestCaloDataAccess::emulateRoIs( const EventContext& context, std::vector<ParallelCallTest*>& allRoIs ) const{
219
220 std::default_random_engine generator;
221 std::normal_distribution<double> N1(0.0, 1.7);
222 std::normal_distribution<double> N2(0.0, 0.2);
223 std::uniform_real_distribution<double> U(0.0, 1.0);
224 std::uniform_real_distribution<double> Uphi(-M_PI, M_PI);
225
226 double RoI_phi1 = Uphi(generator);
227 double RoI_eta1 = N1(generator);
228 if ( RoI_eta1 < -2.5 ) RoI_eta1 = -2.5;
229 if ( RoI_eta1 > 2.5 ) RoI_eta1 = 2.5;
230 double chance = U(generator);
231 double width = 0.1;
232 TrigRoiDescriptor roi( RoI_eta1, RoI_eta1-width, RoI_eta1+width, // eta
233 RoI_phi1, RoI_phi1-width, RoI_phi1+width, // phi
234 0 );
235 AskForRoI* afr = new AskForRoI( context, m_dataAccessSvc, roi );
236 allRoIs.push_back( afr );
237
238 chance = U(generator);
239 if ( chance > 0.6 ) {
240 double RoI_eta2 = -RoI_eta1 + N2(generator);
241 double RoI_phi2 = -RoI_phi1 + N2(generator);
242 if ( RoI_eta2 < -2.5 ) RoI_eta2 = -2.5;
243 if ( RoI_eta2 > 2.5 ) RoI_eta2 = 2.5;
244 TrigRoiDescriptor roi( RoI_eta2, RoI_eta2-width, RoI_eta2+width, // eta
245 RoI_phi2, RoI_phi2-width, RoI_phi2+width, // phi
246 0 );
247 AskForRoI* afr = new AskForRoI( context, m_dataAccessSvc, roi );
248 allRoIs.push_back( afr );
249 }
250
251 for(int i=0;i<10;i++){
252 chance = U(generator);
253 if ( chance > 0.75 ) {
254 double RoI_phi3 = Uphi(generator);
255 double RoI_eta3 = N1(generator);
256 if ( RoI_eta3 < -2.5 ) RoI_eta3 = -2.5;
257 if ( RoI_eta3 > 2.5 ) RoI_eta3 = 2.5;
258 width = 0.1;
259 if ( chance > 0.8 ) width=0.3;
260 TrigRoiDescriptor roi( RoI_eta3, RoI_eta3-width, RoI_eta3+width, // eta
261 RoI_phi3, RoI_phi3-width, RoI_phi3+width, // phi
262 0 );
263 AskForRoI* afr = new AskForRoI( context, m_dataAccessSvc, roi );
264 allRoIs.push_back( afr );
265 }
266 }
267
268 chance = U(generator);
269 if ( chance > 0.6 ) {
270 TrigRoiDescriptor roi( true );
271 AskForRoI* afr = new AskForRoI( context, m_dataAccessSvc, roi );
272 allRoIs.push_back( afr );
273 }
274
275}
276
277void TestCaloDataAccess::emulateFixedRoIs( const EventContext& context, std::vector<ParallelCallTest*>& allRoIs ) const{
278
279 std::vector<TrigRoiDescriptor> rois;
280 TrigRoiDescriptor roi1( 0.7, 0.7-0.1, 0.7+0.1, // eta
281 0.1, 0.1-0.1, 0.1+0.1, // phi
282 0 );
283 TrigRoiDescriptor roi2( 0.8, 0.8-0.2, 0.7+0.2, // eta
284 0.2, 0.2-0.2, 0.2+0.2, // phi
285 0 );
286 TrigRoiDescriptor roi3( -1.7, -1.7-0.4, -1.7+0.4, // eta
287 2.1, 2.1-0.4, 2.1+0.4, // phi
288 0 );
289 TrigRoiDescriptor roi4( -1.0, -1.0-1.4, -1.0+1.4, // eta
290 1.1, 1.1-1.4, 1.1+1.4, // phi
291 0 );
292 rois.push_back(roi1);
293 rois.push_back(roi2);
294 rois.push_back(roi3);
295 rois.push_back(roi4);
296 TrigRoiDescriptor roi5( true );
297 for( int i=0;i<std::min(m_nFixedRoIs,4);++i) {
298 AskForRoI* t1 = new AskForRoI( context, m_dataAccessSvc, rois[i]);
299 allRoIs.push_back(t1);
300 }
301 AskForRoI* t6 = new AskForRoI( context, m_dataAccessSvc, roi5); // FS
302 allRoIs.push_back(t6);
303
304
305}
306
307StatusCode TestCaloDataAccess::execute( const EventContext& context ) const {
308 ATH_MSG_DEBUG ( "Executing " << name() << "..." );
309
310 std::vector<ParallelCallTest*> allRoIs;
311
312 if ( m_emulateRoIs ) emulateRoIs ( context, allRoIs );
313 if ( m_emulateFixedRoIs ) emulateFixedRoIs ( context, allRoIs );
314
315
316 timeval ti1{},ti2{};
317 gettimeofday(&ti1,NULL);
318 bool result = ParallelCallTest::launchTests( 2, allRoIs);
319 gettimeofday(&ti2,NULL);
320 std::cout << ti1.tv_sec << " " << ti1.tv_usec << std::endl;
321 std::cout << ti2.tv_sec << " " << ti2.tv_usec << std::endl;
322 std::cout << name() << "; time : " << 1e-6*( 1e6*(ti2.tv_sec - ti1.tv_sec) + ( ti2.tv_usec - ti1.tv_usec ) ) << std::endl;
323
324 if ( result == false ) {
325 ATH_MSG_ERROR( "Test of data access failed " );
326 return StatusCode::SUCCESS;
327 }
328
329 return StatusCode::SUCCESS;
330}
331
332
#define M_PI
#define ATH_MSG_ERROR(x)
#define ATH_MSG_WARNING(x)
#define ATH_MSG_DEBUG(x)
CaloCellContainer that can accept const cell pointers.
#define CHECK(...)
Evaluate an expression and check for errors.
@ TTEM
Definition RegSelEnums.h:28
const double width
#define DIFF(_name, _a, _b)
The test calls for RoI data access for each RoI returned bunch of quantiries are checked,...
bool callAndCompare() const override
a function that performs request, and compares the results obtained with the result of the first exec...
StatusCode request(LArTT_Selector< LArCellCont > &sel) const
const ServiceHandle< ITrigCaloDataAccessSvc > & m_svc
const EventContext & m_context
StatusCode request(CaloConstCellContainer &c) const
StatusCode m_statusRef
const TrigRoiDescriptor m_roi
void firstCall() override
a method that will be called to obtain first results from the service It should set the reference qua...
LArTT_Selector< LArCellCont > m_selRef
AskForRoI(const EventContext &context, const ServiceHandle< ITrigCaloDataAccessSvc > &svc, const TrigRoiDescriptor &roi)
CaloConstCellContainer * m_colRef
Gaudi::Details::PropertyBase & declareProperty(Gaudi::Property< T, V, H > &t)
AthMessaging(IMessageSvc *msgSvc, const std::string &name)
Constructor.
An algorithm that can be simultaneously executed in multiple threads.
virtual double phi() const override final
get phi (through CaloDetDescrElement)
Definition CaloCell.h:375
virtual double eta() const override final
get eta (through CaloDetDescrElement)
Definition CaloCell.h:382
virtual double et() const override final
get et
Definition CaloCell.h:423
CaloCellContainer that can accept const cell pointers.
Data object for LAr calorimeter readout cell.
Definition LArCell.h:53
Provides interface and helper functions to perform stress testing of the thread-safe code.
static bool launchTests(size_t nrepeats, const std::vector< ParallelCallTest * > &tests)
Method to run launch number of tests in parallel (increasing the stress of the calle) It has a potent...
ServiceHandle< ITrigCaloDataAccessSvc > m_dataAccessSvc
virtual StatusCode initialize() override
void emulateFixedRoIs(const EventContext &context, std::vector< ParallelCallTest * > &allRoIs) const
void emulateRoIs(const EventContext &context, std::vector< ParallelCallTest * > &allRoIs) const
virtual StatusCode execute(const EventContext &context) const override
nope - should be used for standalone also, perhaps need to protect the class def bits ifndef XAOD_ANA...
int count(std::string s, const std::string &regx)
count how many occurances of a regx are in a string
Definition hcg.cxx:146
@ VIEW_ELEMENTS
this data object is a view, it does not own its elmts