Loading [MathJax]/extensions/tex2jax.js
ATLAS Offline Software
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
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 
12 HiveAlgBase::HiveAlgBase( const std::string& name,
13  ISvcLocator* pSvcLocator ) :
14  ::AthAlgorithm( name, pSvcLocator )
15 {}
16 
17 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
18 
19 HiveAlgBase::~HiveAlgBase() = default;
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 
39 unsigned 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 }
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()
ATH_MSG_INFO
#define ATH_MSG_INFO(x)
Definition: AthMsgStreamMacros.h:31
HiveAlgBase::sleep
unsigned int sleep()
Definition: HiveAlgBase.cxx:40
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:23
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:240
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,...