ATLAS Offline Software
Loading...
Searching...
No Matches
HiveAlgBase.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2025 CERN for the benefit of the ATLAS collaboration
3*/
4
5#include "HiveAlgBase.h"
6#include <thread>
7
9#include "CLHEP/Random/RandomEngine.h"
10#include "CLHEP/Random/RandFlat.h"
11
12HiveAlgBase::HiveAlgBase( const std::string& name,
13 ISvcLocator* pSvcLocator ) :
14 ::AthAlgorithm( name, pSvcLocator )
15{}
16
17/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
18
20
21/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
22
24 ATH_MSG_DEBUG("initialize " << name() << " for " << this );
25
26 // retrieve the CPUCrunchSvc if Alg chooses to Crunch instead of Sleep
27 if (m_doCrunch) {
28 ATH_CHECK( m_ccs.retrieve() );
29 }
30
31 ATH_CHECK( m_hes.retrieve() );
32 ATH_CHECK( m_rngSvc.retrieve() );
33
34 return StatusCode::SUCCESS;
35}
36
37/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
38
39unsigned int
41
42 const auto& ctx = Gaudi::Hive::currentContext();
43 ATHRNG::RNGWrapper* rngWrapper = m_rngSvc->getEngine(this);
44 rngWrapper->setSeed( name(), ctx );
45
46 // add a bit of variability to the sleep/crunch time
47 const unsigned int sleep = CLHEP::RandFlat::shoot(rngWrapper->getEngine(ctx), 0, m_time);
48
49 if (m_doCrunch) {
50 ATH_MSG_INFO(" crunch for: " << sleep << " ms");
51 m_ccs->crunch_for( std::chrono::milliseconds(sleep) );
52 } else {
53 ATH_MSG_INFO(" sleep for: " << sleep << " ms");
54 std::this_thread::sleep_for(std::chrono::milliseconds( sleep ));
55 }
56
57 // accumulate data in the HiveExSvc
58 m_hes->add( name(),sleep );
59
60 return sleep;
61
62}
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_INFO(x)
#define ATH_MSG_DEBUG(x)
Base class for AthExHive example Algs to provide functionality to sleep for a certain amount of time,...
A wrapper class for event-slot-local random engines.
Definition RNGWrapper.h:56
void setSeed(const std::string &algName, const EventContext &ctx)
Set the random seed using a string (e.g.
Definition RNGWrapper.h:169
CLHEP::HepRandomEngine * getEngine(const EventContext &ctx) const
Retrieve the random engine corresponding to the provided EventContext.
Definition RNGWrapper.h:134
AthAlgorithm(const std::string &name, ISvcLocator *pSvcLocator)
Constructor with parameters:
unsigned int sleep()
Gaudi::Property< unsigned int > m_time
Definition HiveAlgBase.h:54
HiveAlgBase(const std::string &name, ISvcLocator *pSvcLocator)
ServiceHandle< ICPUCrunchSvc > m_ccs
Definition HiveAlgBase.h:47
ServiceHandle< IAthRNGSvc > m_rngSvc
Definition HiveAlgBase.h:50
ServiceHandle< IHiveExSvc > m_hes
Definition HiveAlgBase.h:44
virtual StatusCode initialize() override
virtual ~HiveAlgBase()
Gaudi::Property< bool > m_doCrunch
Definition HiveAlgBase.h:55