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