The Gaudi Framework  v33r1 (b1225454)
CPUCruncher Class Reference

A class that implements a search for prime numbers. More...

#include <src/CPUCruncher.h>

Inheritance diagram for CPUCruncher:
Collaboration diagram for CPUCruncher:

Public Types

typedef tbb::concurrent_hash_map< std::string, unsigned int > CHM
 

Public Member Functions

bool isClonable () const override
 
StatusCode execute () override
 the execution of the algorithm More...
 
StatusCode initialize () override
 Its initialization. More...
 
StatusCode finalize () override
 the finalization of the algorithm More...
 
double get_runtime () const
 
 CPUCruncher (const std::string &name, ISvcLocator *pSvc)
 
virtual ~CPUCruncher ()
 virtual & protected desctrustor More...
 
- Public Member Functions inherited from GaudiAlgorithm
StatusCode initialize () override
 standard initialization method More...
 
StatusCode execute () override
 standard execution method More...
 
StatusCode finalize () override
 standard finalization method More...
 
StatusCode sysExecute (const EventContext &ctx) override
 the generic actions for the execution. More...
 
void put (IDataProviderSvc *svc, DataObject *object, const std::string &address, const bool useRootInTES=true) const
 Register a data object or container into Gaudi Event Transient Store. More...
 
void put (IDataProviderSvc *svc, std::unique_ptr< DataObject > object, const std::string &address, const bool useRootInTES=true) const
 
const DataObjectput (DataObject *object, const std::string &address, const bool useRootInTES=true) const
 Register a data object or container into Gaudi Event Transient Store. More...
 
const DataObjectput (std::unique_ptr< DataObject > object, const std::string &address, const bool useRootInTES=true) const
 
template<class TYPE >
Gaudi::Utils::GetData< TYPE >::return_type get (IDataProviderSvc *svc, const std::string &location, const bool useRootInTES=true) const
 Templated access to the data in Gaudi Transient Store. More...
 
template<class TYPE >
Gaudi::Utils::GetData< TYPE >::return_type getIfExists (IDataProviderSvc *svc, const std::string &location, const bool useRootInTES=true) const
 Templated access to the data in Gaudi Transient Store. More...
 
template<class TYPE >
Gaudi::Utils::GetData< TYPE >::return_type get (const std::string &location, const bool useRootInTES=true) const
 Templated access to the data from Gaudi Event Transient Store. More...
 
template<class TYPE >
Gaudi::Utils::GetData< TYPE >::return_type getIfExists (const std::string &location, const bool useRootInTES=true) const
 Templated access to the data in Gaudi Transient Store. More...
 
template<class TYPE >
TYPE * getDet (IDataProviderSvc *svc, const std::string &location) const
 Templated access to the detector data from the Gaudi Detector Transient Store. More...
 
template<class TYPE >
Gaudi::Utils::GetData< TYPE >::return_type getDetIfExists (IDataProviderSvc *svc, const std::string &location) const
 Templated access to the detector data from the Gaudi Detector Transient Store. More...
 
template<class TYPE >
TYPE * getDet (const std::string &location) const
 Templated access to the detector data from the Gaudi Detector Transient Store. More...
 
template<class TYPE >
Gaudi::Utils::GetData< TYPE >::return_type getDetIfExists (const std::string &location) const
 Templated access to the detector data from the Gaudi Detector Transient Store. More...
 
template<class TYPE >
bool exist (IDataProviderSvc *svc, const std::string &location, const bool useRootInTES=true) const
 Check the existence of a data object or container in the Gaudi Transient Event Store. More...
 
template<class TYPE >
bool exist (const std::string &location, const bool useRootInTES=true) const
 Check the existence of a data object or container in the Gaudi Transient Event Store. More...
 
template<class TYPE >
bool existDet (IDataProviderSvc *svc, const std::string &location) const
 Check the existence of detector objects in the Gaudi Transient Detector Store. More...
 
template<class TYPE >
bool existDet (const std::string &location) const
 Check the existence of detector objects in the Gaudi Transient Detector Store. More...
 
template<class TYPE , class TYPE2 >
Gaudi::Utils::GetData< TYPE >::return_type getOrCreate (IDataProviderSvc *svc, std::string_view location, const bool useRootInTES=true) const
 Get the existing data object from Gaudi Event Transient store. More...
 
template<class TYPE , class TYPE2 >
Gaudi::Utils::GetData< TYPE >::return_type getOrCreate (const std::string &location, const bool useRootInTES=true) const
 Get the existing data object from Gaudi Event Transient store. More...
 
 GaudiAlgorithm (std::string name, ISvcLocator *pSvcLocator)
 Standard constructor. More...
 
 GaudiAlgorithm (const GaudiAlgorithm &)=delete
 
GaudiAlgorithmoperator= (const GaudiAlgorithm &)=delete
 
SmartIF< INTupleSvc > & evtColSvc () const
 Access the standard event collection service. More...
 
- Public Member Functions inherited from GaudiCommon< Algorithm >
Gaudi::Utils::GetData< TYPE >::return_type get (IDataProviderSvc *svc, std::string_view location, const bool useRootInTES=true) const
 Templated access to the data in Gaudi Transient Store. More...
 
Gaudi::Utils::GetData< TYPE >::return_type getIfExists (IDataProviderSvc *svc, std::string_view location, const bool useRootInTES=true) const
 Quicker version of the get function which bypasses the check on the retrieved data. More...
 
bool exist (IDataProviderSvc *svc, std::string_view location, const bool useRootInTES=true) const
 Check the existence of a data object or container in the Gaudi Transient Event Store. More...
 
Gaudi::Utils::GetData< TYPE >::return_type getOrCreate (IDataProviderSvc *svc, std::string_view location, const bool useRootInTES=true) const
 Get the existing data object from Gaudi Event Transient store. More...
 
DataObjectput (IDataProviderSvc *svc, std::unique_ptr< DataObject > object, std::string_view location, const bool useRootInTES=true) const
 Register a data object or container into Gaudi Event Transient Store. More...
 
DataObjectput (IDataProviderSvc *svc, DataObject *object, std::string_view location, const bool useRootInTES=true) const
 
TOOL * tool (std::string_view type, std::string_view name, const IInterface *parent=0, bool create=true) const
 Useful method for the easy location of tools. More...
 
TOOL * tool (std::string_view type, const IInterface *parent=0, bool create=true) const
 A useful method for the easy location of tools. More...
 
SmartIF< SERVICE > svc (std::string_view name, const bool create=true) const
 A useful method for the easy location of services. More...
 
IUpdateManagerSvcupdMgrSvc () const
 Short-cut to locate the Update Manager Service. More...
 
StatusCode Error (std::string_view msg, const StatusCode st=StatusCode::FAILURE, const size_t mx=10) const
 Print the error message and return with the given StatusCode. More...
 
StatusCode Warning (std::string_view msg, const StatusCode st=StatusCode::FAILURE, const size_t mx=10) const
 Print the warning message and return with the given StatusCode. More...
 
StatusCode Info (std::string_view msg, const StatusCode st=StatusCode::SUCCESS, const size_t mx=10) const
 Print the info message and return with the given StatusCode. More...
 
StatusCode Print (std::string_view msg, const StatusCode st=StatusCode::SUCCESS, const MSG::Level lev=MSG::INFO) const
 Print the message and return with the given StatusCode. More...
 
void Assert (const bool ok, std::string_view message="", const StatusCode sc=StatusCode(StatusCode::FAILURE, true)) const
 Assertion - throw exception if the given condition is not fulfilled. More...
 
void Exception (std::string_view msg, const GaudiException &exc, const StatusCode sc=StatusCode(StatusCode::FAILURE, true)) const
 Create and (re)-throw a given GaudiException. More...
 
void Exception (std::string_view msg, const std::exception &exc, const StatusCode sc=StatusCode(StatusCode::FAILURE, true)) const
 Create and (re)-throw a given exception. More...
 
void Exception (std::string_view msg="no message", const StatusCode sc=StatusCode(StatusCode::FAILURE, true)) const
 Create and throw an exception with the given message. More...
 
StatEntitycounter (std::string_view tag) const
 accessor to certain counter by name More...
 
StatEntitycounter (std::string_view tag)
 
bool typePrint () const
 Insert the actual C++ type of the algorithm/tool in the messages ? More...
 
bool propsPrint () const
 Print properties at initialization ? More...
 
bool statPrint () const
 Print statistical counters at finalization ? More...
 
bool errorsPrint () const
 Print error counters at finalization ? More...
 
long printStat (const MSG::Level level=MSG::ALWAYS) const
 perform the actual printout of statistical counters More...
 
long printErrors (const MSG::Level level=MSG::ALWAYS) const
 perform the actual printout of error counters More...
 
long printProps (const MSG::Level level=MSG::ALWAYS) const
 perform the actual printout of properties More...
 
void registerCondition (const std::string &condition, StatusCode(CallerClass::*mf)()=nullptr)
 register the current instance to the UpdateManagerSvc as a consumer for a condition. More...
 
void registerCondition (const std::string &condition, CondType *&condPtrDest, StatusCode(CallerClass::*mf)()=NULL)
 register the current instance to the UpdateManagerSvc as a consumer for a condition. More...
 
void registerCondition (char *condition, StatusCode(CallerClass::*mf)()=NULL)
 just to avoid conflicts with the version using a pointer to a template class. More...
 
void registerCondition (TargetClass *condition, StatusCode(CallerClass::*mf)()=NULL)
 register the current instance to the UpdateManagerSvc as a consumer for a condition. More...
 
StatusCode runUpdate ()
 asks the UpdateManagerSvc to perform an update of the instance (if needed) without waiting the next BeginEvent incident. More...
 
 GaudiCommon (std::string name, ISvcLocator *pSvcLocator)
 Algorithm constructor - the SFINAE constraint below ensures that this is constructor is only defined if PBASE derives from Algorithm. More...
 
 GaudiCommon (std::string type, std::string name, const IInterface *ancestor)
 Tool constructor - SFINAE-ed to insure this constructor is only defined if PBASE derives from AlgTool. More...
 
 GaudiCommon ()=delete
 
 GaudiCommon (const GaudiCommon &)=delete
 
StatusCode initialize () override
 standard initialization method More...
 
StatusCode finalize () override
 standard finalization method More...
 
GaudiCommonoperator= (const GaudiCommon &)=delete
 
StatusCode release (const IInterface *interface) const
 Manual forced (and 'safe') release of the active tool or service. More...
 
const Servicesservices () const
 get the list of aquired services More...
 
const std::stringcontext () const
 Returns the "context" string. Used to identify different processing states. More...
 
- Public Member Functions inherited from FixTESPath< BASE >
template<typename U = BASE, typename = std::enable_if_t<std::is_base_of_v<Gaudi::Algorithm, BASE>, U>>
 FixTESPath (std::string name, ISvcLocator *pSvcLocator)
 Algorithm constructor - the SFINAE constraint below ensures that this is constructor is only defined if BASE derives from Algorithm. More...
 
template<typename U = BASE, typename = std::enable_if_t<std::is_base_of_v<AlgTool, BASE>, U>>
 FixTESPath (std::string type, std::string name, const IInterface *ancestor)
 Tool constructor - SFINAE-ed to insure this constructor is only defined if BASE derives from AlgTool. More...
 
StatusCode initialize () override
 
const std::stringrootInTES () const
 Returns the "rootInTES" string. More...
 
std::string fullTESLocation (std::string_view location, bool useRootInTES) const
 Returns the full correct event location given the rootInTes settings. More...
 

Private Member Functions

 CPUCruncher ()
 the default constructor is disabled More...
 
 CPUCruncher (const CPUCruncher &)
 the copy constructor is disabled More...
 
CPUCruncheroperator= (const CPUCruncher &)
 the assignement operator is disabled More...
 
void declareRuntimeRequestedOutputs ()
 The CPU intensive function. More...
 

Private Attributes

bool m_declAugmented {false}
 
Gaudi::Property< bool > m_loader {this, "Loader", false, "Declare the algorithm to be a data loader"}
 
Gaudi::Property< std::vector< std::string > > m_inpKeys {this, "inpKeys", {}, ""}
 
Gaudi::Property< std::vector< std::string > > m_outKeys {this, "outKeys", {}, ""}
 
Gaudi::Property< double > m_avg_runtime {this, "avgRuntime", 1., "Average runtime of the module."}
 
Gaudi::Property< double > m_var_runtime {this, "varRuntime", 0.01, "Variance of the runtime of the module."}
 
Gaudi::Property< bool > m_local_rndm_gen {this, "localRndm", true, "Decide if the local random generator is to be used"}
 
Gaudi::Property< unsigned int > m_rwRepetitions {this, "RwRepetitions", 1, "Increase access to the WB"}
 
Gaudi::Property< float > m_sleepFraction
 
Gaudi::Property< bool > m_invertCFD {this, "InvertDecision", false, "Invert control flow decision."}
 
Gaudi::Property< unsigned int > m_failNEvents {this, "FailNEvents", 0, "Return FAILURE on every Nth event"}
 
const uint MAX_INPUTS = 40
 
const uint MAX_OUTPUTS = 10
 
std::vector< DataObjectHandle< DataObject > * > m_inputHandles
 
std::vector< DataObjectHandle< DataObject > * > m_outputHandles
 
SmartIF< ICPUCrunchSvcm_crunchSvc
 

Static Private Attributes

static CHM m_name_ncopies_map
 

Additional Inherited Members

- Protected Types inherited from GaudiCommon< Algorithm >
using base_class = FixTESPath< Algorithm >
 
typedef std::map< std::string, StatEntity, std::less<> > StatisticsOwn
 the actual type of general counters More...
 
typedef std::map< std::string, std::reference_wrapper< Gaudi::Accumulators::PrintableCounter >, std::less<> > Statistics
 
typedef std::map< std::string, unsigned int, std::less<> > Counter
 the actual type error/warning counter More...
 
typedef std::vector< IAlgTool * > AlgTools
 storage for active tools More...
 
typedef std::vector< SmartIF< IService > > Services
 storage for active services More...
 
- Protected Member Functions inherited from GaudiCommon< Algorithm >
StatusCode releaseTool (const IAlgTool *tool) const
 manual forced (and 'safe') release of the tool More...
 
StatusCode releaseSvc (const IInterface *svc) const
 manual forced (and 'safe') release of the service More...
 
- Protected Attributes inherited from GaudiCommon< Algorithm >
SmartIF< ICounterSummarySvcm_counterSummarySvc
 a pointer to the CounterSummarySvc More...
 
- Static Protected Attributes inherited from GaudiCommon< Algorithm >
static const bool IgnoreRootInTES
 Simple definition to be used with the new useRootInTES argument get<TYPE> and put methods. More...
 
static const bool UseRootInTES
 Simple definition to be used with the new useRootInTES argument get<TYPE> and put methods. More...
 

Detailed Description

A class that implements a search for prime numbers.

A lot of allocations are performed on purpose not to stress only the FP unit of the CPU.

Definition at line 29 of file CPUCruncher.h.

Member Typedef Documentation

◆ CHM

typedef tbb::concurrent_hash_map<std::string, unsigned int> CPUCruncher::CHM

Definition at line 32 of file CPUCruncher.h.

Constructor & Destructor Documentation

◆ CPUCruncher() [1/3]

CPUCruncher::CPUCruncher ( const std::string name,
ISvcLocator pSvc 
)

Definition at line 33 of file CPUCruncher.cpp.

35  : GaudiAlgorithm( name, pSvc ) {
36 
37  // Register the algo in the static concurrent hash map in order to
38  // monitor the # of copies
39  CHM::accessor name_ninstances;
40  m_name_ncopies_map.insert( name_ninstances, name );
41  name_ninstances->second += 1;
42 }
GaudiAlgorithm(std::string name, ISvcLocator *pSvcLocator)
Standard constructor.
static CHM m_name_ncopies_map
Definition: CPUCruncher.h:85

◆ ~CPUCruncher()

CPUCruncher::~CPUCruncher ( )
virtual

virtual & protected desctrustor

Definition at line 44 of file CPUCruncher.cpp.

44  {
45  for ( uint i = 0; i < m_inputHandles.size(); ++i ) delete m_inputHandles[i];
46 
47  for ( uint i = 0; i < m_outputHandles.size(); ++i ) delete m_outputHandles[i];
48 }
std::vector< DataObjectHandle< DataObject > * > m_outputHandles
Definition: CPUCruncher.h:83
std::vector< DataObjectHandle< DataObject > * > m_inputHandles
Definition: CPUCruncher.h:82
T size(T... args)

◆ CPUCruncher() [2/3]

CPUCruncher::CPUCruncher ( )
private

the default constructor is disabled

◆ CPUCruncher() [3/3]

CPUCruncher::CPUCruncher ( const CPUCruncher )
private

the copy constructor is disabled

Member Function Documentation

◆ declareRuntimeRequestedOutputs()

void CPUCruncher::declareRuntimeRequestedOutputs ( )
private

The CPU intensive function.

Pick up late-attributed data outputs

Definition at line 89 of file CPUCruncher.cpp.

89  {
90  //
91  for ( const auto& k : outputDataObjs() ) {
92  auto outputHandle = new DataObjectHandle<DataObject>( k, Gaudi::DataHandle::Writer, this );
93  VERBOSE_MSG << "found late-attributed output: " << outputHandle->objKey() << endmsg;
94  m_outputHandles.push_back( outputHandle );
95  declareProperty( "dummy_out_" + outputHandle->objKey(), *( m_outputHandles.back() ) );
96  }
97 
98  initDataHandleHolder();
99 
100  m_declAugmented = true;
101 }
std::vector< DataObjectHandle< DataObject > * > m_outputHandles
Definition: CPUCruncher.h:83
#define VERBOSE_MSG
Definition: CPUCruncher.cpp:29
T push_back(T... args)
T back(T... args)
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:202
bool m_declAugmented
Definition: CPUCruncher.h:62

◆ execute()

StatusCode CPUCruncher::execute ( )
override

the execution of the algorithm

Definition at line 105 of file CPUCruncher.cpp.

106 {
107 
109 
110  float crunchtime;
111 
112  if ( m_local_rndm_gen ) {
113  /* This will disappear with a thread safe random number generator service.
114  * Use basic Box-Muller to generate Gaussian random numbers.
115  * The quality is not good for in depth study given that the generator is a
116  * linear congruent.
117  * Throw away basically a free number: we are in a cpu cruncher after all.
118  * The seed is taken from the clock, but we could assign a seed per module to
119  * ensure reproducibility.
120  *
121  * This is not an overkill but rather an exercise towards a thread safe
122  * random number generation.
123  */
124 
125  auto getGausRandom = []( double mean, double sigma ) -> double {
126  unsigned int seed = std::clock();
127 
128  auto getUnifRandom = []( unsigned int& seed ) -> double {
129  // from "Numerical Recipes"
130  constexpr unsigned int m = 232;
131  constexpr unsigned int a = 1664525;
132  constexpr unsigned int c = 1013904223;
133  seed = ( a * seed + c ) % m;
134  const double unif = double( seed ) / m;
135  return unif;
136  };
137 
138  double unif1, unif2;
139  do {
140  unif1 = getUnifRandom( seed );
141  unif2 = getUnifRandom( seed );
142  } while ( unif1 == 0. );
143 
144  const double normal = sqrt( -2. * log( unif1 ) ) * cos( 2 * M_PI * unif2 );
145 
146  return normal * sigma + mean;
147  };
148 
149  crunchtime = fabs( getGausRandom( m_avg_runtime * ( 1. - m_sleepFraction ), m_var_runtime ) );
150  // End Of temp block
151  } else {
152  // Should be a member.
153  HiveRndm::HiveNumbers rndmgaus( randSvc(), Rndm::Gauss( m_avg_runtime * ( 1. - m_sleepFraction ), m_var_runtime ) );
154  crunchtime = std::fabs( rndmgaus() );
155  }
156  unsigned int crunchtime_ms = 1000 * crunchtime;
157 
158  // Prepare to sleep (even if we won't enter the following if clause for sleeping).
159  // This is needed to distribute evenly among all algorithms the overhead (around sleeping) which is harmful when
160  // trying to achieve uniform distribution of algorithm timings.
161  const double dreamtime = m_avg_runtime * m_sleepFraction;
162  const std::chrono::duration<double> dreamtime_duration( dreamtime );
163  tbb::tick_count startSleeptbb;
164  tbb::tick_count endSleeptbb;
165 
166  // Start to measure the total time here, together with the dreaming process straight ahead
167  tbb::tick_count starttbb = tbb::tick_count::now();
168 
169  // If the algorithm was set as I/O-bound, we will replace requested part of crunching with plain sleeping
170  if ( isIOBound() ) {
171  // in this block (and not in other places around) msgLevel is checked for the same reason as above, when
172  // preparing to sleep several lines above: to reduce as much as possible the overhead around sleeping
173  DEBUG_MSG << "Dreaming time will be: " << int( 1000 * dreamtime ) << " ms" << endmsg;
174 
175  ON_DEBUG startSleeptbb = tbb::tick_count::now();
176  std::this_thread::sleep_for( dreamtime_duration );
177  ON_DEBUG endSleeptbb = tbb::tick_count::now();
178 
179  // actual sleeping time can be longer due to scheduling or resource contention delays
180  ON_DEBUG {
181  const double actualDreamTime = ( endSleeptbb - startSleeptbb ).seconds();
182  debug() << "Actual dreaming time was: " << int( 1000 * actualDreamTime ) << "ms" << endmsg;
183  }
184  } // end of "sleeping block"
185 
186  DEBUG_MSG << "Crunching time will be: " << crunchtime_ms << " ms" << endmsg;
188  DEBUG_MSG << "Start event " << context.evt() << " in slot " << context.slot() << " on pthreadID " << std::hex
189  << pthread_self() << std::dec << endmsg;
190 
191  VERBOSE_MSG << "inputs number: " << m_inputHandles.size() << endmsg;
192  for ( auto& inputHandle : m_inputHandles ) {
193  if ( !inputHandle->isValid() ) continue;
194 
195  VERBOSE_MSG << "get from TS: " << inputHandle->objKey() << endmsg;
196  DataObject* obj = nullptr;
197  for ( unsigned int i = 0; i < m_rwRepetitions; ++i ) { obj = inputHandle->get(); }
198  if ( obj == nullptr ) error() << "A read object was a null pointer." << endmsg;
199  }
200 
201  m_crunchSvc->crunch_for( std::chrono::milliseconds( crunchtime_ms ) );
202 
203  // Return error on fraction of events if configured
204  if ( m_failNEvents > 0 && context.evt() > 0 && ( context.evt() % m_failNEvents ) == 0 ) {
205  return StatusCode::FAILURE;
206  }
207 
208  VERBOSE_MSG << "outputs number: " << m_outputHandles.size() << endmsg;
209  for ( auto& outputHandle : m_outputHandles ) {
210  if ( !outputHandle->isValid() ) continue;
211 
212  VERBOSE_MSG << "put to TS: " << outputHandle->objKey() << endmsg;
213  outputHandle->put( new DataObject() );
214  }
215 
216  tbb::tick_count endtbb = tbb::tick_count::now();
217  const double actualRuntime = ( endtbb - starttbb ).seconds();
218 
219  DEBUG_MSG << "Finish event " << context.evt() << " in " << int( 1000 * actualRuntime ) << " ms" << endmsg;
220 
221  DEBUG_MSG << "Timing: ExpectedCrunchtime= " << crunchtime_ms << " ms. ExpectedDreamtime= " << int( 1000 * dreamtime )
222  << " ms. ActualTotalRuntime= " << int( 1000 * actualRuntime )
223  << " ms. Ratio= " << ( crunchtime + dreamtime ) / actualRuntime << endmsg;
224 
225  setFilterPassed( !m_invertCFD );
226 
227  return StatusCode::SUCCESS;
228 }
SmartIF< ICPUCrunchSvc > m_crunchSvc
Definition: CPUCruncher.h:88
virtual std::chrono::milliseconds crunch_for(const std::chrono::milliseconds &) const =0
Gaudi::Property< float > m_sleepFraction
Definition: CPUCruncher.h:72
Gaudi::Property< bool > m_loader
Definition: CPUCruncher.h:63
T clock(T... args)
Gaudi::Property< unsigned int > m_rwRepetitions
Definition: CPUCruncher.h:71
constexpr static const auto SUCCESS
Definition: StatusCode.h:100
T sleep_for(T... args)
Parameters for the Gauss random number generation.
std::vector< DataObjectHandle< DataObject > * > m_outputHandles
Definition: CPUCruncher.h:83
This class represents an entry point to all the event specific data.
Definition: EventContext.h:34
#define VERBOSE_MSG
Definition: CPUCruncher.cpp:29
constexpr double m
Gaudi::Property< bool > m_invertCFD
Definition: CPUCruncher.h:75
std::vector< DataObjectHandle< DataObject > * > m_inputHandles
Definition: CPUCruncher.h:82
GAUDI_API const EventContext & currentContext()
T cos(T... args)
const std::string & context() const
Returns the "context" string. Used to identify different processing states.
Definition: GaudiCommon.h:694
T fabs(T... args)
#define DEBUG_MSG
Definition: CPUCruncher.cpp:26
auto sqrt(std::chrono::duration< Rep, Period > d)
sqrt for std::chrono::duration
Definition: Counters.h:34
T size(T... args)
void declareRuntimeRequestedOutputs()
The CPU intensive function.
Definition: CPUCruncher.cpp:89
Gaudi::Property< double > m_avg_runtime
Definition: CPUCruncher.h:68
constexpr static const auto FAILURE
Definition: StatusCode.h:101
Gaudi::Property< unsigned int > m_failNEvents
Definition: CPUCruncher.h:76
T hex(T... args)
A DataObject is the base class of any identifiable object on any data store.
Definition: DataObject.h:40
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:202
Gaudi::Property< bool > m_local_rndm_gen
Definition: CPUCruncher.h:70
Gaudi::Property< double > m_var_runtime
Definition: CPUCruncher.h:69
#define ON_DEBUG
Definition: CPUCruncher.cpp:25
bool m_declAugmented
Definition: CPUCruncher.h:62

◆ finalize()

StatusCode CPUCruncher::finalize ( )
override

the finalization of the algorithm

Definition at line 232 of file CPUCruncher.cpp.

233 {
234  MsgStream log( msgSvc(), name() );
235 
236  unsigned int ninstances;
237 
238  {
239  CHM::const_accessor const_name_ninstances;
240  m_name_ncopies_map.find( const_name_ninstances, name() );
241  ninstances = const_name_ninstances->second;
242  }
243 
244  constexpr double s2ms = 1000.;
245  // do not show repetitions
246  if ( ninstances != 0 ) {
247  info() << "Summary: name= " << name() << "\t avg_runtime= " << m_avg_runtime * s2ms << "\t n_clones= " << ninstances
248  << endmsg;
249 
250  CHM::accessor name_ninstances;
251  m_name_ncopies_map.find( name_ninstances, name() );
252  name_ninstances->second = 0;
253  }
254 
255  return GaudiAlgorithm::finalize();
256 }
Definition of the MsgStream class used to transmit messages.
Definition: MsgStream.h:34
static CHM m_name_ncopies_map
Definition: CPUCruncher.h:85
StatusCode finalize() override
standard finalization method
Gaudi::Property< double > m_avg_runtime
Definition: CPUCruncher.h:68
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:202

◆ get_runtime()

double CPUCruncher::get_runtime ( ) const
inline

Definition at line 43 of file CPUCruncher.h.

43 { return m_avg_runtime; }
Gaudi::Property< double > m_avg_runtime
Definition: CPUCruncher.h:68

◆ initialize()

StatusCode CPUCruncher::initialize ( )
override

Its initialization.

Definition at line 50 of file CPUCruncher.cpp.

50  {
51  auto sc = GaudiAlgorithm::initialize();
52  if ( !sc ) return sc;
53 
54  m_crunchSvc = serviceLocator()->service( "CPUCrunchSvc" );
55  if ( !m_crunchSvc.isValid() ) {
56  fatal() << "unable to acquire CPUCruncSvc" << endmsg;
57  return StatusCode::FAILURE;
58  }
59 
60  // if an algorithm was setup to sleep, for whatever period, it effectively becomes I/O-bound
61  if ( m_sleepFraction != 0.0f ) setIOBound( true );
62 
63  // This is a bit ugly. There is no way to declare a vector of DataObjectHandles, so
64  // we need to wait until initialize when we've read in the input and output key
65  // properties, and know their size, and then turn them
66  // into Handles and register them with the framework by calling declareProperty. We
67  // could call declareInput/declareOutput on them too.
68 
69  int i = 0;
70  for ( auto k : m_inpKeys ) {
71  DEBUG_MSG << "adding input key " << k << endmsg;
73  declareProperty( "dummy_in_" + std::to_string( i ), *( m_inputHandles.back() ) );
74  i++;
75  }
76 
77  i = 0;
78  for ( auto k : m_outKeys ) {
79  DEBUG_MSG << "adding output key " << k << endmsg;
81  declareProperty( "dummy_out_" + std::to_string( i ), *( m_outputHandles.back() ) );
82  i++;
83  }
84 
85  return sc;
86 }
SmartIF< ICPUCrunchSvc > m_crunchSvc
Definition: CPUCruncher.h:88
Gaudi::Property< float > m_sleepFraction
Definition: CPUCruncher.h:72
StatusCode initialize() override
standard initialization method
T to_string(T... args)
bool isValid() const
Allow for check if smart pointer is valid.
Definition: SmartIF.h:72
std::vector< DataObjectHandle< DataObject > * > m_outputHandles
Definition: CPUCruncher.h:83
T push_back(T... args)
std::vector< DataObjectHandle< DataObject > * > m_inputHandles
Definition: CPUCruncher.h:82
#define DEBUG_MSG
Definition: CPUCruncher.cpp:26
T back(T... args)
constexpr static const auto FAILURE
Definition: StatusCode.h:101
Gaudi::Property< std::vector< std::string > > m_outKeys
Definition: CPUCruncher.h:66
Gaudi::Property< std::vector< std::string > > m_inpKeys
Definition: CPUCruncher.h:65
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:202

◆ isClonable()

bool CPUCruncher::isClonable ( ) const
inlineoverride

Definition at line 34 of file CPUCruncher.h.

34 { return true; }

◆ operator=()

CPUCruncher& CPUCruncher::operator= ( const CPUCruncher )
private

the assignement operator is disabled

Member Data Documentation

◆ m_avg_runtime

Gaudi::Property<double> CPUCruncher::m_avg_runtime {this, "avgRuntime", 1., "Average runtime of the module."}
private

Definition at line 68 of file CPUCruncher.h.

◆ m_crunchSvc

SmartIF<ICPUCrunchSvc> CPUCruncher::m_crunchSvc
private

Definition at line 88 of file CPUCruncher.h.

◆ m_declAugmented

bool CPUCruncher::m_declAugmented {false}
private

Definition at line 62 of file CPUCruncher.h.

◆ m_failNEvents

Gaudi::Property<unsigned int> CPUCruncher::m_failNEvents {this, "FailNEvents", 0, "Return FAILURE on every Nth event"}
private

Definition at line 76 of file CPUCruncher.h.

◆ m_inpKeys

Gaudi::Property<std::vector<std::string> > CPUCruncher::m_inpKeys {this, "inpKeys", {}, ""}
private

Definition at line 65 of file CPUCruncher.h.

◆ m_inputHandles

std::vector<DataObjectHandle<DataObject>*> CPUCruncher::m_inputHandles
private

Definition at line 82 of file CPUCruncher.h.

◆ m_invertCFD

Gaudi::Property<bool> CPUCruncher::m_invertCFD {this, "InvertDecision", false, "Invert control flow decision."}
private

Definition at line 75 of file CPUCruncher.h.

◆ m_loader

Gaudi::Property<bool> CPUCruncher::m_loader {this, "Loader", false, "Declare the algorithm to be a data loader"}
private

Definition at line 63 of file CPUCruncher.h.

◆ m_local_rndm_gen

Gaudi::Property<bool> CPUCruncher::m_local_rndm_gen {this, "localRndm", true, "Decide if the local random generator is to be used"}
private

Definition at line 70 of file CPUCruncher.h.

◆ m_name_ncopies_map

CPUCruncher::CHM CPUCruncher::m_name_ncopies_map
staticprivate

Definition at line 85 of file CPUCruncher.h.

◆ m_outKeys

Gaudi::Property<std::vector<std::string> > CPUCruncher::m_outKeys {this, "outKeys", {}, ""}
private

Definition at line 66 of file CPUCruncher.h.

◆ m_outputHandles

std::vector<DataObjectHandle<DataObject>*> CPUCruncher::m_outputHandles
private

Definition at line 83 of file CPUCruncher.h.

◆ m_rwRepetitions

Gaudi::Property<unsigned int> CPUCruncher::m_rwRepetitions {this, "RwRepetitions", 1, "Increase access to the WB"}
private

Definition at line 71 of file CPUCruncher.h.

◆ m_sleepFraction

Gaudi::Property<float> CPUCruncher::m_sleepFraction
private
Initial value:
{
this, "SleepFraction", 0.0f,
"Fraction of time, between 0 and 1, when an algorithm is actually sleeping instead of crunching"}

Definition at line 72 of file CPUCruncher.h.

◆ m_var_runtime

Gaudi::Property<double> CPUCruncher::m_var_runtime {this, "varRuntime", 0.01, "Variance of the runtime of the module."}
private

Definition at line 69 of file CPUCruncher.h.

◆ MAX_INPUTS

const uint CPUCruncher::MAX_INPUTS = 40
private

Definition at line 79 of file CPUCruncher.h.

◆ MAX_OUTPUTS

const uint CPUCruncher::MAX_OUTPUTS = 10
private

Definition at line 80 of file CPUCruncher.h.


The documentation for this class was generated from the following files: