Warning, file /include/Gaudi/Algorithm.h was not indexed
or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011 #pragma once
0012
0013
0014
0015 #include <GaudiKernel/IAlgorithm.h>
0016 #include <GaudiKernel/IMessageSvc.h>
0017 #include <GaudiKernel/IProperty.h>
0018 #include <GaudiKernel/IService.h>
0019 #include <GaudiKernel/IStateful.h>
0020 #include <GaudiKernel/ISvcLocator.h>
0021 #include <GaudiKernel/ITimelineSvc.h>
0022
0023 #include <string>
0024 #include <vector>
0025
0026
0027 #include <Gaudi/PluginService.h>
0028 #include <Gaudi/Property.h>
0029 #include <GaudiKernel/CommonMessaging.h>
0030 #include <GaudiKernel/DataObjID.h> // must be include before Property.h, which is included in PropertyHolder.h
0031 #include <GaudiKernel/IAlgContextSvc.h>
0032 #include <GaudiKernel/IAuditorSvc.h>
0033 #include <GaudiKernel/IChronoStatSvc.h>
0034 #include <GaudiKernel/IConversionSvc.h>
0035 #include <GaudiKernel/IDataProviderSvc.h>
0036 #include <GaudiKernel/IExceptionSvc.h>
0037 #include <GaudiKernel/IHistogramSvc.h>
0038 #include <GaudiKernel/IHiveWhiteBoard.h>
0039 #include <GaudiKernel/IMonitorSvc.h>
0040 #include <GaudiKernel/INTupleSvc.h>
0041 #include <GaudiKernel/IRndmGenSvc.h>
0042 #include <GaudiKernel/IToolSvc.h>
0043 #include <GaudiKernel/PropertyHolder.h>
0044 #include <GaudiKernel/System.h>
0045 #include <GaudiKernel/ToolHandle.h>
0046
0047
0048 #include <GaudiKernel/DataHandle.h>
0049 #include <GaudiKernel/DataHandleHolderBase.h>
0050 #include <GaudiKernel/EventContext.h>
0051 #include <GaudiKernel/IAlgExecStateSvc.h>
0052
0053 class IAlgTool;
0054 class ToolHandleInfo;
0055 class AlgorithmManager;
0056
0057 #ifndef PACKAGE_VERSION
0058 # define PACKAGE_VERSION "unknown"
0059 #endif
0060 namespace Gaudi {
0061 namespace Details {
0062 bool getDefaultAuditorValue( ISvcLocator* loc );
0063 }
0064
0065
0066
0067
0068
0069
0070
0071
0072
0073
0074
0075
0076
0077
0078
0079
0080
0081
0082
0083
0084
0085
0086
0087
0088 class GAUDI_API Algorithm
0089 : public DataHandleHolderBase<
0090 PropertyHolder<CommonMessaging<implements<IAlgorithm, IDataHandleHolder, IProperty, IStateful>>>> {
0091 public:
0092 #ifndef __REFLEX__
0093 typedef Gaudi::PluginService::Factory<IAlgorithm*( const std::string&, ISvcLocator* )> Factory;
0094 #endif
0095 friend AlgorithmManager;
0096
0097
0098
0099
0100
0101 Algorithm( std::string name, ISvcLocator* svcloc, std::string version = PACKAGE_VERSION )
0102 : m_name( std::move( name ) )
0103 , m_version( std::move( version ) )
0104 , m_pSvcLocator( svcloc ) {}
0105
0106
0107
0108
0109
0110
0111 StatusCode sysStart() override;
0112
0113
0114
0115
0116
0117
0118 StatusCode sysInitialize() override;
0119
0120
0121
0122
0123
0124
0125 StatusCode sysReinitialize() override;
0126
0127
0128
0129
0130
0131 StatusCode sysRestart() override;
0132
0133
0134
0135
0136
0137
0138
0139
0140 StatusCode sysExecute( const EventContext& ctx ) override;
0141
0142
0143
0144
0145 StatusCode sysStop() override;
0146
0147
0148
0149
0150
0151 StatusCode sysFinalize() override;
0152
0153
0154
0155
0156
0157
0158
0159
0160 const std::string& name() const override;
0161 const Gaudi::StringKey& nameKey() const override;
0162
0163
0164
0165 const std::string& type() const override { return m_type; }
0166 void setType( std::string type ) override { m_type = std::move( type ); }
0167
0168 const std::string& version() const override;
0169
0170 unsigned int index() const override;
0171
0172
0173 StatusCode configure() override { return StatusCode::SUCCESS; }
0174
0175 StatusCode terminate() override { return StatusCode::SUCCESS; }
0176
0177
0178 StatusCode initialize() override { return StatusCode::SUCCESS; }
0179
0180 StatusCode start() override { return StatusCode::SUCCESS; }
0181
0182 StatusCode stop() override { return StatusCode::SUCCESS; }
0183
0184 StatusCode finalize() override { return StatusCode::SUCCESS; }
0185
0186 StatusCode reinitialize() override;
0187
0188 StatusCode restart() override;
0189
0190 Gaudi::StateMachine::State FSMState() const override { return m_state; }
0191
0192 Gaudi::StateMachine::State targetFSMState() const override { return m_targetState; }
0193
0194
0195 bool isEnabled() const override;
0196
0197
0198 bool isSequence() const override { return false; }
0199
0200
0201 unsigned int errorCount() const;
0202
0203
0204 template <class T>
0205 [[deprecated( "use service<T>(name, createIf) -> SmartIF<T>" )]] StatusCode
0206 service( std::string_view name, T*& psvc, bool createIf = true ) const {
0207 return service_i( name, createIf, T::interfaceID(), (void**)&psvc );
0208 }
0209
0210
0211 template <class T>
0212 [[deprecated( "use service<T>(name, createIf) -> SmartIF<T>" )]] StatusCode
0213 service( std::string_view svcType, std::string_view svcName, T*& psvc ) const {
0214 return service_i( svcType, svcName, T::interfaceID(), reinterpret_cast<void**>( &psvc ) );
0215 }
0216
0217
0218 SmartIF<IService> service( std::string_view name, const bool createIf = true, const bool quiet = false ) const;
0219
0220 template <class T>
0221 SmartIF<T> service( std::string_view name, bool createIf = true, bool quiet = false ) const {
0222 return service( name, createIf, quiet ).as<T>();
0223 }
0224
0225
0226
0227
0228 SmartIF<IAuditorSvc>& auditorSvc() const;
0229
0230
0231
0232
0233 SmartIF<IChronoStatSvc>& chronoSvc() const;
0234
0235
0236
0237
0238 SmartIF<IDataProviderSvc>& detSvc() const;
0239
0240
0241
0242
0243 SmartIF<IConversionSvc>& detCnvSvc() const;
0244
0245
0246
0247
0248 SmartIF<IDataProviderSvc>& eventSvc() const;
0249
0250 SmartIF<IDataProviderSvc>& evtSvc() const { return eventSvc(); }
0251
0252
0253
0254
0255 SmartIF<IConversionSvc>& eventCnvSvc() const;
0256
0257
0258
0259
0260 SmartIF<IHistogramSvc>& histoSvc() const;
0261
0262
0263
0264
0265 SmartIF<INTupleSvc>& ntupleSvc() const;
0266
0267
0268
0269
0270 SmartIF<IRndmGenSvc>& randSvc() const;
0271
0272
0273 SmartIF<IToolSvc>& toolSvc() const;
0274
0275
0276 SmartIF<IExceptionSvc>& exceptionSvc() const;
0277
0278
0279 SmartIF<IAlgContextSvc>& contextSvc() const;
0280
0281 SmartIF<ITimelineSvc>& timelineSvc() const;
0282
0283
0284
0285
0286
0287
0288 SmartIF<ISvcLocator>& serviceLocator() const override;
0289
0290 SmartIF<ISvcLocator>& svcLoc() const { return serviceLocator(); }
0291
0292 SmartIF<IHiveWhiteBoard>& whiteboard() const;
0293
0294 SmartIF<IAlgExecStateSvc>& algExecStateSvc() const;
0295
0296
0297 bool registerContext() const { return m_registerContext; }
0298
0299
0300 using PropertyHolderImpl::declareProperty;
0301
0302
0303 template <class T>
0304 Gaudi::Details::PropertyBase* declareProperty( const std::string& name, ToolHandle<T>& hndl,
0305 const std::string& doc = "none" ) {
0306 this->declareTool( hndl, hndl.typeAndName() ).ignore();
0307 return PropertyHolderImpl::declareProperty( name, hndl, doc );
0308 }
0309
0310
0311
0312
0313 template <class T>
0314 Gaudi::Details::PropertyBase* declareProperty( const std::string& name, ToolHandleArray<T>& hndlArr,
0315 const std::string& doc = "none" ) {
0316 addToolsArray( hndlArr );
0317 return PropertyHolderImpl::declareProperty( name, hndlArr, doc );
0318 }
0319
0320
0321
0322
0323
0324
0325
0326
0327
0328
0329
0330 SmartIF<IMonitorSvc>& monitorSvc() const {
0331
0332 if ( !m_pMonitorSvc ) {
0333 m_pMonitorSvc = service( m_monitorSvcName, false, true );
0334 }
0335 return m_pMonitorSvc;
0336 }
0337
0338
0339
0340
0341
0342
0343 template <class T>
0344 void declareInfo( const std::string& name, const T& var, const std::string& desc ) const {
0345 IMonitorSvc* mS = monitorSvc().get();
0346 if ( mS ) mS->declareInfo( name, var, desc, this );
0347 }
0348
0349
0350
0351
0352
0353
0354
0355
0356 void declareInfo( const std::string& name, const std::string& format, const void* var, int size,
0357 const std::string& desc ) const {
0358 IMonitorSvc* mS = monitorSvc().get();
0359 if ( mS ) mS->declareInfo( name, format, var, size, desc, this );
0360 }
0361
0362 public:
0363 void acceptDHVisitor( IDataHandleVisitor* ) const override;
0364
0365 void registerTool( IAlgTool* tool ) const;
0366 void deregisterTool( IAlgTool* tool ) const;
0367
0368 template <class T>
0369 StatusCode declareTool( ToolHandle<T>& handle, bool createIf = true ) {
0370 return this->declareTool( handle, handle.typeAndName(), createIf );
0371 }
0372
0373 template <class T>
0374 StatusCode declareTool( ToolHandle<T>& handle, const std::string& toolTypeAndName, bool createIf = true ) {
0375
0376 StatusCode sc = handle.initialize( toolTypeAndName, handle.isPublic() ? nullptr : this, createIf );
0377 if ( !sc ) {
0378 throw GaudiException{ std::string{ "Cannot create handle for " } +
0379 ( handle.isPublic() ? "public" : "private" ) + " tool " + toolTypeAndName,
0380 name(), sc };
0381 }
0382
0383 m_toolHandles.push_back( &handle );
0384
0385 return sc;
0386 }
0387
0388 template <class T>
0389 void addToolsArray( ToolHandleArray<T>& hndlArr ) {
0390 m_toolHandleArrays.push_back( &hndlArr );
0391 }
0392
0393 const std::vector<IAlgTool*>& tools() const;
0394
0395
0396 bool isAsynchronous() const { return m_asynchronous; }
0397
0398 void setAsynchronous( bool value ) { m_asynchronous = value; }
0399
0400 protected:
0401 std::vector<IAlgTool*>& tools();
0402
0403
0404
0405
0406 private:
0407
0408 void initToolHandles() const;
0409
0410 public:
0411
0412
0413
0414
0415 unsigned int cardinality() const override { return m_cardinality; }
0416
0417 const std::vector<std::string>& neededResources() const override { return m_neededResources; }
0418
0419 protected:
0420
0421 bool isInitialized() const override { return Gaudi::StateMachine::INITIALIZED == m_state; }
0422
0423
0424 bool isFinalized() const override { return Gaudi::StateMachine::CONFIGURED == m_state; }
0425
0426
0427 void setIndex( const unsigned int& idx ) override;
0428
0429 public:
0430
0431 AlgExecState& execState( const EventContext& ctx ) const override;
0432
0433
0434 std::ostream& toControlFlowExpression( std::ostream& os ) const override;
0435
0436 private:
0437 unsigned int maxErrors() const { return m_errorMax; }
0438
0439 protected:
0440 bool isReEntrant() const override { return true; }
0441
0442 private:
0443 Gaudi::StringKey m_name;
0444 std::string m_type;
0445 std::string m_version;
0446 unsigned int m_index = 0;
0447
0448
0449 mutable std::vector<IAlgTool*> m_tools;
0450 mutable std::vector<BaseToolHandle*> m_toolHandles;
0451 mutable std::vector<GaudiHandleArrayBase*> m_toolHandleArrays;
0452
0453 private:
0454 template <typename IFace>
0455 SmartIF<IFace>& get_svc_( SmartIF<IFace>& p, const char* service_name ) const;
0456
0457 mutable SmartIF<IMessageSvc> m_MS;
0458 mutable SmartIF<IDataProviderSvc> m_EDS;
0459 mutable SmartIF<IHiveWhiteBoard> m_WB;
0460 mutable SmartIF<IConversionSvc> m_ECS;
0461 mutable SmartIF<IDataProviderSvc> m_DDS;
0462 mutable SmartIF<IConversionSvc> m_DCS;
0463 mutable SmartIF<IHistogramSvc> m_HDS;
0464 mutable SmartIF<INTupleSvc> m_NTS;
0465 mutable SmartIF<IChronoStatSvc> m_CSS;
0466 mutable SmartIF<IRndmGenSvc> m_RGS;
0467 mutable SmartIF<IExceptionSvc> m_EXS;
0468 mutable SmartIF<IAuditorSvc> m_pAuditorSvc;
0469 mutable SmartIF<IToolSvc> m_ptoolSvc;
0470 mutable SmartIF<IMonitorSvc> m_pMonitorSvc;
0471 mutable SmartIF<IAlgContextSvc> m_contextSvc;
0472
0473 mutable SmartIF<ITimelineSvc> m_timelineSvc;
0474 mutable SmartIF<IAlgExecStateSvc> m_aess;
0475
0476 SmartIF<ISvcLocator> m_pSvcLocator;
0477
0478 protected:
0479
0480 std::unique_ptr<IDataHandleVisitor> m_updateDataHandles;
0481
0482 private:
0483
0484 Gaudi::Property<int> m_outputLevel{
0485 this, "OutputLevel", MSG::NIL,
0486 [this]( Gaudi::Details::PropertyBase& ) { this->updateMsgStreamOutputLevel( this->m_outputLevel ); },
0487 "output level" };
0488 Gaudi::Property<bool> m_isEnabled{ this, "Enable", true, "should the algorithm be executed or not" };
0489
0490 Gaudi::Property<unsigned int> m_errorMax{ this, "ErrorMax", 1, "[[deprecated]] max number of errors" };
0491
0492 Gaudi::Property<bool> m_auditInit{ this, "AuditAlgorithms", Details::getDefaultAuditorValue( m_pSvcLocator ),
0493 "[[deprecated]] unused" };
0494 Gaudi::Property<bool> m_auditorInitialize{ this, "AuditInitialize", m_auditInit.value(),
0495 "trigger auditor on initialize()" };
0496 Gaudi::Property<bool> m_auditorReinitialize{ this, "AuditReinitialize", m_auditInit.value(),
0497 "trigger auditor on reinitialize()" };
0498 Gaudi::Property<bool> m_auditorRestart{ this, "AuditRestart", m_auditInit.value(), "trigger auditor on restart()" };
0499 Gaudi::Property<bool> m_auditorExecute{ this, "AuditExecute", m_auditInit.value(), "trigger auditor on execute()" };
0500 Gaudi::Property<bool> m_auditorFinalize{ this, "AuditFinalize", m_auditInit.value(),
0501 "trigger auditor on finalize()" };
0502 Gaudi::Property<bool> m_auditorStart{ this, "AuditStart", m_auditInit.value(), "trigger auditor on start()" };
0503 Gaudi::Property<bool> m_auditorStop{ this, "AuditStop", m_auditInit.value(), "trigger auditor on stop()" };
0504
0505 Gaudi::Property<bool> m_doTimeline{ this, "Timeline", true, "send events to TimelineSvc" };
0506
0507 Gaudi::Property<std::string> m_monitorSvcName{ this, "MonitorService", "MonitorSvc",
0508 "name to use for Monitor Service" };
0509
0510 Gaudi::Property<bool> m_registerContext{ this, "RegisterForContextService", false,
0511 "flag to enforce the registration for Algorithm Context Service" };
0512
0513 Gaudi::Property<int> m_cardinality{ this, "Cardinality", 0,
0514 "how many clones to create - 0 means algo is reentrant" };
0515 Gaudi::Property<std::vector<std::string>> m_neededResources{
0516 this, "NeededResources", {}, "named resources needed during event looping" };
0517
0518 Gaudi::Property<bool> m_asynchronous{ this, "Asynchronous", false,
0519 "whether algorithm is asynchronous and uses Boost Fiber to suspend "
0520 "while offloaded code is running." };
0521
0522 Gaudi::Property<bool> m_filterCircDeps{ this, "FilterCircularDependencies", true,
0523 "filter out circular data dependencies" };
0524
0525 mutable bool m_toolHandlesInit = false;
0526
0527 Gaudi::StateMachine::State m_state = Gaudi::StateMachine::CONFIGURED;
0528 Gaudi::StateMachine::State m_targetState = Gaudi::StateMachine::CONFIGURED;
0529
0530
0531 [[deprecated]] StatusCode service_i( std::string_view svcName, bool createIf, const InterfaceID& iid,
0532 void** ppSvc ) const;
0533 [[deprecated]] StatusCode service_i( std::string_view svcType, std::string_view svcName, const InterfaceID& iid,
0534 void** ppSvc ) const;
0535
0536
0537 Algorithm( const Algorithm& ) = delete;
0538
0539
0540 Algorithm& operator=( const Algorithm& ) = delete;
0541 };
0542 }