ATLAS Offline Software
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 
29 class AskForROBs : public ParallelCallTest {
30 public:
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 
52 private:
54  std::vector<uint32_t> m_ROBIDs;
55  EventContext m_context;
57 };
58 
59 
60 
61 StatusCode 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 
beamspotman.r
def r
Definition: beamspotman.py:676
ParallelCallTest
Provides interface and helper functions to perform stress testing of the thread-safe code.
Definition: ParallelCallTest.h:30
ROBDataProviderMTTest::~ROBDataProviderMTTest
virtual ~ROBDataProviderMTTest()
Definition: ROBDataProviderMTTest.cxx:17
xAOD::uint32_t
setEventNumber uint32_t
Definition: EventInfo_v1.cxx:127
ROBDataProviderMTTest::ROBDataProviderMTTest
ROBDataProviderMTTest()
RawEvent
OFFLINE_FRAGMENTS_NAMESPACE::FullEventFragment RawEvent
data type for reading raw event
Definition: RawEvent.h:37
D3PDTest::rng
uint32_t rng()
Definition: FillerAlg.cxx:40
AskForROBs::firstCall
virtual void firstCall() override
a method that will be called to obtain first results from the service It should set the reference qua...
Definition: ROBDataProviderMTTest.cxx:41
ParallelCallTest.h
XMLtoHeader.count
count
Definition: XMLtoHeader.py:85
AthReentrantAlgorithm
An algorithm that can be simultaneously executed in multiple threads.
Definition: AthReentrantAlgorithm.h:83
random.h
Very simple random numbers for regression testing.
ROBDataProviderMTTest::execute
StatusCode execute(const EventContext &context) const override
Definition: ROBDataProviderMTTest.cxx:61
ev
int ev
Definition: globals.cxx:25
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
eformat::ROBFragment
Definition: L1CaloBsDecoderUtil.h:12
lumiFormat.i
int i
Definition: lumiFormat.py:85
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
ATH_MSG_DEBUG
#define ATH_MSG_DEBUG(x)
Definition: AthMsgStreamMacros.h:29
checkxAOD.frac
frac
Definition: Tools/PyUtils/bin/checkxAOD.py:257
ROBDataProviderMTTest.h
python.HLT.CommonSequences.EventBuildingSequences.robs
robs
Definition: EventBuildingSequences.py:401
plotIsoValidation.el
el
Definition: plotIsoValidation.py:197
CHECK
#define CHECK(...)
Evaluate an expression and check for errors.
Definition: Control/AthenaKernel/AthenaKernel/errorcheck.h:422
IROBDataProviderSvc::VROBFRAG
std::vector< const ROBF * > VROBFRAG
Definition: IROBDataProviderSvc.h:27
Handler::svc
AthROOTErrorHandlerSvc * svc
Definition: AthROOTErrorHandlerSvc.cxx:10
ParallelCallTest::launchTests
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...
Definition: ParallelCallTest.cxx:83
AskForROBs::AskForROBs
AskForROBs(const EventContext &context, const ServiceHandle< IROBDataProviderSvc > &svc, uint32_t lvl1ID, const std::vector< eformat::read::ROBFragment > &robs, size_t frac=8)
Definition: ROBDataProviderMTTest.cxx:31
ROBDataProviderMTTest::finalize
StatusCode finalize() override
Definition: ROBDataProviderMTTest.cxx:25
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:221
AskForROBs::m_ROBIDs
std::vector< uint32_t > m_ROBIDs
Definition: ROBDataProviderMTTest.cxx:54
AskForROBs::nrobs
size_t nrobs() const
Definition: ROBDataProviderMTTest.cxx:40
ROBDataProviderMTTest::m_robDataProvider
ServiceHandle< IROBDataProviderSvc > m_robDataProvider
Definition: ROBDataProviderMTTest.h:36
AskForROBs::m_context
EventContext m_context
Definition: ROBDataProviderMTTest.cxx:55
AskForROBs::callAndCompare
virtual bool callAndCompare() const override
a function that performs request, and compares the results obtained with the result of the first exec...
Definition: ROBDataProviderMTTest.cxx:42
AskForROBs::m_lvl1ID
uint32_t m_lvl1ID
Definition: ROBDataProviderMTTest.cxx:53
Athena_test::URNG
Generator compatible with the C++11 STL UniformRandomNumberGenerator.
Definition: random.h:78
AskForROBs
Definition: ROBDataProviderMTTest.cxx:29
AskForROBs::m_svc
const ServiceHandle< IROBDataProviderSvc > & m_svc
Definition: ROBDataProviderMTTest.cxx:56
merge.status
status
Definition: merge.py:17
ROBDataProviderMTTest::initialize
StatusCode initialize() override
Definition: ROBDataProviderMTTest.cxx:19
ServiceHandle< IROBDataProviderSvc >