ATLAS Offline Software
Loading...
Searching...
No Matches
ROBDataProviderMTTest.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2019 CERN for the benefit of the ATLAS collaboration
3*/
4#include <algorithm>
5#include "Gaudi/Property.h"
7#include "TestTools/random.h"
9
10
11
13 ISvcLocator* pSvcLocator ) :
14 ::AthReentrantAlgorithm( name, pSvcLocator ) {
15}
16
18
20 CHECK( m_robDataProvider.retrieve() );
21
22 return StatusCode::SUCCESS;
23}
24
26 return StatusCode::SUCCESS;
27}
28
30public:
31 AskForROBs( const EventContext& context, const ServiceHandle<IROBDataProviderSvc>& svc, uint32_t lvl1ID, const std::vector<eformat::read::ROBFragment>& robs, size_t frac=8 )
32 : m_lvl1ID( lvl1ID ),
33 m_context( context ),
34 m_svc( svc ) {
35 // pick some fraction of robs at random
36 for ( size_t el = 0; el < robs.size()/frac; ++el ) {
37 m_ROBIDs.push_back( robs[el].rob_source_id() );
38 }
39 }
40 size_t nrobs() const { return m_ROBIDs.size(); }
41 virtual void firstCall() override {}
42 virtual bool callAndCompare() const override {
44 m_svc->getROBData( m_context, m_ROBIDs, robs );
45 for ( auto& rob: robs ) {
46 if ( rob->rod_lvl1_id() != m_lvl1ID )
47 return false;
48 }
49 return true;
50 }
51
52private:
53 uint32_t m_lvl1ID;
54 std::vector<uint32_t> m_ROBIDs;
55 EventContext m_context;
57};
58
59
60
61StatusCode ROBDataProviderMTTest::execute( const EventContext& context ) const
62{
63 // will be asking for many ROBs from the list and check if all of them come from the same physical event
64 const RawEvent* ev = m_robDataProvider->getEvent( context );
65 ATH_MSG_DEBUG( "Obtained event, global id: " << ev->global_id() << " lvl1 id: " << ev->lvl1_id() );
66 uint32_t lvl1ID = ev->lvl1_id();
67
68
69 // we try now the other method, getROBData, in 8 steps, concurrently
70 std::vector<ParallelCallTest*> requests;
71 std::vector<eformat::read::ROBFragment> robs;
72 ev->robs( robs );
73
75 rng.seed = context.evt();
76 for ( size_t i = 0; i < 8; ++i ) {
77 std::shuffle( robs.begin(), robs.end(), rng );
78 auto r = new AskForROBs( context, m_robDataProvider, lvl1ID, robs );
79 ATH_MSG_DEBUG( "Prepared parallel request with " << r->nrobs() << " robs" );
80 requests.push_back( r );
81 }
82
83
84 bool status = ParallelCallTest::launchTests( 100, requests );
85 if ( status == false )
86 ATH_MSG_ERROR( "Concurrent ROB requests resulted in inconsistent information" );
87
88 size_t count = 0;
89 m_robDataProvider->processCachedROBs( context,
90 [&]( const IROBDataProviderSvc::ROBF* ){ count++; } );
91 ATH_MSG_DEBUG( "Size of the cache " << count );
92
93 m_robDataProvider->processCachedROBs( context,
94 [&]( const IROBDataProviderSvc::ROBF* rob ){
95 if ( 1120005 == rob->rob_source_id() )
96 ATH_MSG_DEBUG( "rob in the cache " << rob->rob_source_id() ); }
97 );
98
99
100
101 return StatusCode::SUCCESS;
102}
103
104
#define ATH_MSG_ERROR(x)
#define ATH_MSG_DEBUG(x)
#define CHECK(...)
Evaluate an expression and check for errors.
OFFLINE_FRAGMENTS_NAMESPACE::FullEventFragment RawEvent
data type for reading raw event
Definition RawEvent.h:37
EventContext m_context
const ServiceHandle< IROBDataProviderSvc > & m_svc
virtual bool callAndCompare() const override
a function that performs request, and compares the results obtained with the result of the first exec...
std::vector< uint32_t > m_ROBIDs
virtual void firstCall() override
a method that will be called to obtain first results from the service It should set the reference qua...
size_t nrobs() const
AskForROBs(const EventContext &context, const ServiceHandle< IROBDataProviderSvc > &svc, uint32_t lvl1ID, const std::vector< eformat::read::ROBFragment > &robs, size_t frac=8)
An algorithm that can be simultaneously executed in multiple threads.
OFFLINE_FRAGMENTS_NAMESPACE::ROBFragment ROBF
std::vector< const ROBF * > VROBFRAG
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...
StatusCode initialize() override
ServiceHandle< IROBDataProviderSvc > m_robDataProvider
StatusCode execute(const EventContext &context) const override
StatusCode finalize() override
int r
Definition globals.cxx:22
int ev
Definition globals.cxx:25
int count(std::string s, const std::string &regx)
count how many occurances of a regx are in a string
Definition hcg.cxx:146
void shuffle(typename DataModel_detail::iterator< DVL > beg, typename DataModel_detail::iterator< DVL > end, UniformRandom &g)
Specialization of shuffle for DataVector/List.
Very simple random numbers for regression testing.
Generator compatible with the C++11 STL UniformRandomNumberGenerator.
Definition random.h:78