diff --git a/Control/AthenaExamples/AthExHive/AthExHive/CondDataObj.h b/Control/AthenaExamples/AthExHive/AthExHive/CondDataObj.h new file mode 100644 index 0000000000000000000000000000000000000000..842d40d27960668cb77f0ca34fdb7750ea035fb8 --- /dev/null +++ b/Control/AthenaExamples/AthExHive/AthExHive/CondDataObj.h @@ -0,0 +1,40 @@ +/* + Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration +*/ + +#ifndef CONDALGS_CONDDATAOBJ_H +#define CONDALGS_CONDDATAOBJ_H + +class CondDataObj { + +public: + + CondDataObj():m_val(0) {}; + CondDataObj(int i): m_val(i) {}; + virtual ~CondDataObj(){}; + + void val(int i) { m_val = i; } + int val() const { return m_val; } + +private: + int m_val; +}; + +#include <iostream> +inline std::ostream& operator<<(std::ostream& ost, const CondDataObj& rhs) { + ost << rhs.val(); + return ost; +} + + +//using the macros below we can assign an identifier (and a version) +//to the type CondDataObj +//This is required and checked at compile time when you try to record/retrieve +#include "SGTools/CLASS_DEF.h" +CLASS_DEF( CondDataObj , 232539028 , 1 ) +CLASS_DEF( CondCont<CondDataObj> , 261788530 , 1 ) + +#include "SGTools/BaseInfo.h" +SG_BASE( CondCont<CondDataObj>, CondContBase ); + +#endif diff --git a/Control/AthenaExamples/AthExHive/AthExHive/CondDataObjY.h b/Control/AthenaExamples/AthExHive/AthExHive/CondDataObjY.h new file mode 100644 index 0000000000000000000000000000000000000000..b2008c0e78f03b9f15209a90e23dad970e03df82 --- /dev/null +++ b/Control/AthenaExamples/AthExHive/AthExHive/CondDataObjY.h @@ -0,0 +1,40 @@ +/* + Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration +*/ + +#ifndef CONDALGS_CONDDATAOBJY_H +#define CONDALGS_CONDDATAOBJY_H + +class CondDataObjY { + +public: + + CondDataObjY():m_val(0) {}; + CondDataObjY(float f): m_val(f) {}; + virtual ~CondDataObjY(){}; + + void val(float f) { m_val = f; } + float val() const { return m_val; } + +private: + float m_val; +}; + +#include <iostream> +inline std::ostream& operator<<(std::ostream& ost, const CondDataObjY& rhs) { + ost << rhs.val(); + return ost; +} + + +//using the macros below we can assign an identifier (and a version) +//to the type CondDataObjY +//This is required and checked at compile time when you try to record/retrieve +#include "SGTools/CLASS_DEF.h" +CLASS_DEF( CondDataObjY , 6664392 , 1 ) +CLASS_DEF( CondCont<CondDataObjY> , 207255848 , 1 ) + +#include "SGTools/BaseInfo.h" +SG_BASE( CondCont<CondDataObjY>, CondContBase ); + +#endif diff --git a/Control/AthenaExamples/AthExHive/AthExHive/HiveDataObj.h b/Control/AthenaExamples/AthExHive/AthExHive/HiveDataObj.h new file mode 100644 index 0000000000000000000000000000000000000000..ff9b4b7961f9cf8d5094df25dbd7f5b8c6e95449 --- /dev/null +++ b/Control/AthenaExamples/AthExHive/AthExHive/HiveDataObj.h @@ -0,0 +1,42 @@ +/* + Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration +*/ + +#ifndef ATHEXHIVE_HIVEDATAOBJ_H +#define ATHEXHIVE_HIVEDATAOBJ_H + +//sample data class for the Read/Write example +//it just wraps an int. Notice that is does not inherit from Gaudi DataObject + +//a dummy base class to test the symlinks +class BaseClass { }; + +class HiveDataObj { + +public: + + HiveDataObj():m_val(0) {}; + HiveDataObj(int i): m_val(i) {}; + virtual ~HiveDataObj(){}; + + void val(int i) { m_val = i; } + int val() const { return m_val; } + +private: + int m_val; +}; + +#include <iostream> + inline std::ostream& operator<<(std::ostream& ost, const HiveDataObj& rhs) { + ost << "HDO: " << rhs.val(); + return ost; + } + + +//using the macros below we can assign an identifier (and a version) +//to the type HiveDataObj +//This is required and checked at compile time when you try to record/retrieve +#include "SGTools/CLASS_DEF.h" +CLASS_DEF( HiveDataObj , 37539154 , 1 ) + +#endif diff --git a/Control/AthenaExamples/AthExHive/AthExHive/IASCIICondDbSvc.h b/Control/AthenaExamples/AthExHive/AthExHive/IASCIICondDbSvc.h new file mode 100644 index 0000000000000000000000000000000000000000..a2578799264abeca4e33ee4fb37f919b17f7926d --- /dev/null +++ b/Control/AthenaExamples/AthExHive/AthExHive/IASCIICondDbSvc.h @@ -0,0 +1,30 @@ +/* + Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration +*/ + +#ifndef ATHEXHIVE_IASCIICONDDBSVC_H +#define ATHEXHIVE_IASCIICONDDBSVC_H + +#include "GaudiKernel/IService.h" +#include "GaudiKernel/EventContext.h" +#include "GaudiKernel/EventIDRange.h" + +#include <string> + + +class GAUDI_API IASCIICondDbSvc: virtual public IService { +public: + DeclareInterfaceID(IASCIICondDbSvc, 1, 0); + + typedef float dbData_t; + + virtual ~IASCIICondDbSvc() = default; + + virtual StatusCode getRange(const std::string&, const EventContext& ctx, + EventIDRange& rng, dbData_t&) const = 0; + + virtual void dump() const = 0; + +}; + +#endif diff --git a/Control/AthenaExamples/AthExHive/AthExHive/IHiveExSvc.h b/Control/AthenaExamples/AthExHive/AthExHive/IHiveExSvc.h new file mode 100644 index 0000000000000000000000000000000000000000..57b5246460ad253fe1e380544183dcfc5cd39ebf --- /dev/null +++ b/Control/AthenaExamples/AthExHive/AthExHive/IHiveExSvc.h @@ -0,0 +1,36 @@ +/* + Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration +*/ + +#ifndef ATHEXHIVE_IHIVEEXSVC_H +#define ATHEXHIVE_IHIVEEXSVC_H 1 + +#include "GaudiKernel/IService.h" +#include <string> + + +class GAUDI_API IHiveExSvc : virtual public IService { + + public: + + virtual ~IHiveExSvc() {}; + + DeclareInterfaceID(IHiveExSvc,1,0); + + public: + + virtual int get() const = 0; + virtual int getTL() const = 0; + + virtual void set(const int&) = 0; + virtual void setTL(const int&) = 0; + + virtual void add(const std::string&, const int&) = 0; + +}; + +#endif + + + + diff --git a/Control/AthenaExamples/AthExHive/AthExHive/IHiveTool.h b/Control/AthenaExamples/AthExHive/AthExHive/IHiveTool.h new file mode 100644 index 0000000000000000000000000000000000000000..ba1c3ce0ebcf6414e9bbeeef665d97efd8db1e7d --- /dev/null +++ b/Control/AthenaExamples/AthExHive/AthExHive/IHiveTool.h @@ -0,0 +1,19 @@ +/* + Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration +*/ + +#ifndef ATHEXHIVE_IHIVETOOL +#define ATHEXHIVE_IHIVETOOL + +#include "GaudiKernel/IAlgTool.h" + +class GAUDI_API IHiveTool : virtual public IAlgTool { +public: + virtual StatusCode saySomething() const = 0; + virtual void ss() = 0; + virtual ~IHiveTool() {}; + + DeclareInterfaceID(IHiveTool,1,0); + +}; +#endif // !ATHEXHIVE_IHIVETOOL diff --git a/Control/AthenaExamples/AthExHive/CMakeLists.txt b/Control/AthenaExamples/AthExHive/CMakeLists.txt new file mode 100644 index 0000000000000000000000000000000000000000..4c4c8164ffef0dd82d7536064195bb58081e65de --- /dev/null +++ b/Control/AthenaExamples/AthExHive/CMakeLists.txt @@ -0,0 +1,28 @@ +################################################################################ +# Package: AthExHive +################################################################################ + +# Declare the package name: +atlas_subdir( AthExHive ) + +# Declare the package's dependencies: +atlas_depends_on_subdirs( PUBLIC + Control/SGTools + PRIVATE + Control/AthenaBaseComps + Control/CxxUtils + Control/StoreGate + Event/EventInfo + GaudiKernel ) + +# Component(s) in the package: +atlas_add_component( AthExHive + src/*.cxx + src/components/*.cxx + LINK_LIBRARIES AthenaKernel AthenaBaseComps EventInfo ) + +# Install files from the package: +atlas_install_headers( AthExHive ) +atlas_install_joboptions( share/*.py ) +atlas_install_runtime( share/condDb.txt ) + diff --git a/Control/AthenaExamples/AthExHive/README.txt b/Control/AthenaExamples/AthExHive/README.txt new file mode 100644 index 0000000000000000000000000000000000000000..236bbe904ac098eb39cec7b40db23e72c8a6e446 --- /dev/null +++ b/Control/AthenaExamples/AthExHive/README.txt @@ -0,0 +1,90 @@ + + + + Data Dependency Graph of AthExHiveOpts.py + =========================================== + + B A + | / \ + b1| a1/ \a2 + | / \ + \ C D + \ / \ | + \ c1/ \c2 |d1 + \ / \ | + E | | + \ | | + \e1 | | + \ | / \ + \ | / \ + \ | / G + \ |/ | + F |g1 + + + \|/ + V : runtime configurable ReadHandleKeyArray + + + + + Data Dependency Graph for CondHandles + ======================================== + + A -----------------------\ + CX2 /|\ CX1 a1 \ CY1 + /\ / | \ /\ \ |\ + /X2\ a2/ | \a1 /X1\ \ Y1| \Y2 + / \ / |a1 \ / \ \ | | + | C2 B C1 | \ | / + \ \_________ | \|/ + \ a3 \| D2 + \-------------------D1 + + + + Data Dependency Graph of DataLoopTest.py + =========================================== + + B A + | / \ + b1| a1/ \a2 + | / \ + \ C L1 + \ / \ | + \ c1/ \c2 |l1 + \ / \ | + E L2 + | | + |e1 |l1 + | + L3 + \ | + a2\ |l1 + \| + M + + the sequence that encloses [L1,L2,L3,M] is meant to have strict ordering + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Control/AthenaExamples/AthExHive/cmt/requirements b/Control/AthenaExamples/AthExHive/cmt/requirements new file mode 100644 index 0000000000000000000000000000000000000000..87a73ddad231a441447de70f2379c890c87d8988 --- /dev/null +++ b/Control/AthenaExamples/AthExHive/cmt/requirements @@ -0,0 +1,22 @@ +package AthExHive + +use AtlasPolicy AtlasPolicy-* +# use AthenaKernel AthenaKernel-* Control +use SGTools SGTools-* Control + +private +#need make_unique +use CxxUtils CxxUtils-* Control +use AthenaBaseComps AthenaBaseComps-* Control +use EventInfo EventInfo-* Event +use GaudiInterface GaudiInterface-* External +use StoreGate StoreGate-* Control +end_private + +library AthExHive *.cxx -s=components *.cxx + +apply_pattern component_library + +apply_pattern declare_joboptions files="*.py" +apply_pattern declare_runtime_extras extras="condDb.txt" + diff --git a/Control/AthenaExamples/AthExHive/share/AthExHiveOpts.py b/Control/AthenaExamples/AthExHive/share/AthExHiveOpts.py new file mode 100644 index 0000000000000000000000000000000000000000..07e00ba7fb5a4eaf6ba722699ec0f1aa51596a84 --- /dev/null +++ b/Control/AthenaExamples/AthExHive/share/AthExHiveOpts.py @@ -0,0 +1,139 @@ + +# +## can only run if Hive enabled +# +from AthenaCommon.Logging import log as msg + +from AthenaCommon.ConcurrencyFlags import jobproperties as jp +nThreads = jp.ConcurrencyFlags.NumThreads() +if (nThreads < 1) : + msg.fatal('numThreads must be >0. Did you set the --threads=N option?') + sys.exit(AthenaCommon.ExitCodes.CONFIGURATION_ERROR) + +# +## Override Setup for Hive +# + +from AthenaServices.AthenaServicesConf import AthenaHiveEventLoopMgr +# svcMgr.AthenaHiveEventLoopMgr.OutputLevel = INFO + +from StoreGate.StoreGateConf import SG__HiveMgrSvc +# svcMgr.EventDataSvc.OutputLevel = INFO + +from GaudiHive.GaudiHiveConf import AlgResourcePool +# svcMgr += AlgResourcePool( OutputLevel = INFO ); + +from GaudiHive.GaudiHiveConf import ForwardSchedulerSvc +svcMgr.ForwardSchedulerSvc.OutputLevel = INFO +svcMgr.ForwardSchedulerSvc.CheckDependencies = True + +# +## Override defaults for numStores and numAlgsInFlight +## Otherwise these are BOTH EQUAL to the number of threads set with the +## command line opt --threads=N +# + +# numStores = 1 +# numAlgsInFlight = 1 + +# svcMgr.EventDataSvc.NSlots = numStores +# svcMgr.ForwardSchedulerSvc.MaxEventsInFlight = numStores +# svcMgr.ForwardSchedulerSvc.MaxAlgosInFlight = numAlgsInFlight + +# ThreadPoolService thread local initialization +from GaudiHive.GaudiHiveConf import ThreadPoolSvc +svcMgr += ThreadPoolSvc("ThreadPoolSvc") +svcMgr.ThreadPoolSvc.ThreadInitTools = ["ThreadInitTool"] + +#---------------------------------------------------------------------------------# + +# +## Uncomment following to avoid long waits when segfaulting, +## and add "Root.Stacktrace: no" to your .rootrc file +# +# import ROOT +# ROOT.SetSignalPolicy( ROOT.kSignalFast ) + +#---------------------------------------------------------------------------------# + + +# +## AlgSequence +# + +from AthenaCommon.AlgSequence import AlgSequence +topSequence = AlgSequence() + +from SGComps.SGCompsConf import SGInputLoader +topSequence+=SGInputLoader(OutputLevel=INFO, ShowEventDump=False) +topSequence.SGInputLoader.Load = [ ('EventInfo','McEventInfo') ] + +from AthExHive.AthExHiveConf import * +topSequence+=HiveAlgA(OutputLevel=DEBUG,Time=20) +topSequence+=HiveAlgB(OutputLevel=DEBUG,Time=10) +topSequence+=HiveAlgC(OutputLevel=DEBUG,Time=190) +topSequence+=HiveAlgD(OutputLevel=DEBUG,Time=10) +topSequence+=HiveAlgE(OutputLevel=DEBUG,Time=30) +topSequence+=HiveAlgG(OutputLevel=DEBUG,Time=10) +topSequence+=HiveAlgF(OutputLevel=DEBUG,Time=30) + +topSequence+=HiveAlgV(OutputLevel=DEBUG,Time=30) +topSequence.HiveAlgV.Key_RV = [ "a1", "a2", "d1", "e1", "c1" ] + +#-------------------------------------------------------------- +# Event related parameters +#-------------------------------------------------------------- + +theApp.EvtMax = 20 + +nProc = jp.ConcurrencyFlags.NumProcs() +if (nProc > 0) : + + # + ## Basic setup for MP/Hive + # + import AthenaCommon.AtlasUnixGeneratorJob + + # + ## For MP/Hive we need to set the chunk size + # + + from AthenaCommon.Logging import log as msg + if (theApp.EvtMax == -1) : + msg.fatal('EvtMax must be >0 for hybrid configuration') + sys.exit(AthenaCommon.ExitCodes.CONFIGURATION_ERROR) + + if ( theApp.EvtMax % nProc != 0 ) : + msg.warning('EvtMax[%s] is not divisible by nProcs[%s]: MP Workers will not process all requested events',theApp.EvtMax,nProc) + + chunkSize = int (theApp.EvtMax / nProc) + + from AthenaMP.AthenaMPFlags import jobproperties as jps + jps.AthenaMPFlags.PreCountedEvents=theApp.EvtMax + jps.AthenaMPFlags.ChunkSize= chunkSize + + msg.info('AthenaMP workers will process %s events each',chunkSize) + + + +print "==========================================================================================\n" + +# +## set which Algorithms can be cloned +# + +# set algCardinality = 1 to disable cloning for all Algs +algCardinality = jp.ConcurrencyFlags.NumThreads() + +if (algCardinality != 1): + for alg in topSequence: + name = alg.name() + if name in [ "" ] : + # Don't clone these algs + alg.Cardinality = 1 + alg.IsClonable = False + print " --> cloning suppressed for ", name + else: + alg.Cardinality = algCardinality + alg.IsClonable = True + diff --git a/Control/AthenaExamples/AthExHive/share/AthExHiveOpts_MP.py b/Control/AthenaExamples/AthExHive/share/AthExHiveOpts_MP.py new file mode 100644 index 0000000000000000000000000000000000000000..3bd8c9f89d6af05f4c8184b243842830bbf51c1e --- /dev/null +++ b/Control/AthenaExamples/AthExHive/share/AthExHiveOpts_MP.py @@ -0,0 +1,27 @@ +import AthenaCommon.AtlasUnixGeneratorJob + +# Full job is a list of algorithms +from AthenaCommon.AlgSequence import AlgSequence +job = AlgSequence() + +from SGComps.SGCompsConf import SGInputLoader +job += SGInputLoader(OutputLevel=INFO, ShowEventDump=False) +job.SGInputLoader.Load = [ ('EventInfo','McEventInfo') ] + +from AthExHive.AthExHiveConf import * +job += HiveAlgA(OutputLevel=DEBUG,Time=20) +job += HiveAlgB(OutputLevel=DEBUG,Time=10) +job += HiveAlgC(OutputLevel=DEBUG,Time=190) +job += HiveAlgD(OutputLevel=DEBUG,Time=10) +job += HiveAlgE(OutputLevel=DEBUG,Time=30) +job += HiveAlgG(OutputLevel=DEBUG,Time=10) +job += HiveAlgF(OutputLevel=DEBUG,Time=30) + +#from StoreGate.StoreGateConf import StoreGateSvc +#svcMgr.StoreGateSvc.Dump=True + +#-------------------------------------------------------------- +# Event related parameters +#-------------------------------------------------------------- +theApp.EvtMax = 100 + diff --git a/Control/AthenaExamples/AthExHive/share/AthExHiveOpts_Serial.py b/Control/AthenaExamples/AthExHive/share/AthExHiveOpts_Serial.py new file mode 100644 index 0000000000000000000000000000000000000000..f6f02f6be47e160d167e915e269e164572bae056 --- /dev/null +++ b/Control/AthenaExamples/AthExHive/share/AthExHiveOpts_Serial.py @@ -0,0 +1,27 @@ +import AthenaCommon.AtlasUnixGeneratorJob + +# Full job is a list of algorithms +from AthenaCommon.AlgSequence import AlgSequence +job = AlgSequence() + +from AthExHive.AthExHiveConf import * +job+=HiveAlgA(OutputLevel=DEBUG,Time=20) +job+=HiveAlgB(OutputLevel=DEBUG,Time=10) +job+=HiveAlgC(OutputLevel=DEBUG,Time=190) +job+=HiveAlgD(OutputLevel=DEBUG,Time=10) +job+=HiveAlgE(OutputLevel=DEBUG,Time=30) +job+=HiveAlgG(OutputLevel=DEBUG,Time=10) +job+=HiveAlgF(OutputLevel=DEBUG,Time=30) + +job+=HiveAlgV(OutputLevel=DEBUG,Time=30) +job.HiveAlgV.Key_RV = [ "a1", "a2", "d1", "e1", "c1" ] + + +#from StoreGate.StoreGateConf import StoreGateSvc +#svcMgr.StoreGateSvc.Dump=True + +#-------------------------------------------------------------- +# Event related parameters +#-------------------------------------------------------------- +theApp.EvtMax = 10 + diff --git a/Control/AthenaExamples/AthExHive/share/CondAlgsOpts.py b/Control/AthenaExamples/AthExHive/share/CondAlgsOpts.py new file mode 100644 index 0000000000000000000000000000000000000000..d9bb5fcd78c86725154992e634e86501ce6b4f90 --- /dev/null +++ b/Control/AthenaExamples/AthExHive/share/CondAlgsOpts.py @@ -0,0 +1,159 @@ + +# +## can only run if Hive enabled +# +from AthenaCommon.Logging import log as msg + +from AthenaCommon.ConcurrencyFlags import jobproperties as jp +nThreads = jp.ConcurrencyFlags.NumThreads() +if (nThreads < 1) : + msg.fatal('numThreads must be >0. Did you set the --threads=N option?') + sys.exit(AthenaCommon.ExitCodes.CONFIGURATION_ERROR) + +# +## Override Setup for Hive +# + +from AthenaServices.AthenaServicesConf import AthenaHiveEventLoopMgr +# svcMgr.AthenaHiveEventLoopMgr.OutputLevel = INFO + +from StoreGate.StoreGateConf import StoreGateSvc +# svcMgr.StoreGateSvc.Dump = True +# svcMgr += StoreGateSvc("ConditionStore", Dump=True) + +# from StoreGate.StoreGateConf import StoreGateSvc +# theApp.CreateSvc += ["StoreGateSvc/ConditionStore"] + + +from StoreGate.StoreGateConf import SG__HiveMgrSvc +# svcMgr.EventDataSvc.OutputLevel = INFO + +from GaudiHive.GaudiHiveConf import AlgResourcePool +# svcMgr += AlgResourcePool( OutputLevel = INFO ); + +from GaudiHive.GaudiHiveConf import ForwardSchedulerSvc +svcMgr.ForwardSchedulerSvc.OutputLevel = INFO +svcMgr.ForwardSchedulerSvc.CheckDependencies = True +svcMgr.ForwardSchedulerSvc.EnableConditions = True + +# +## Override defaults for numStores and numAlgsInFlight +## Otherwise these are BOTH EQUAL to the number of threads set with the +## command line opt --threads=N +# + +# numStores = 1 +# numAlgsInFlight = 1 + +# svcMgr.EventDataSvc.NSlots = numStores +# svcMgr.ForwardSchedulerSvc.MaxEventsInFlight = numStores +# svcMgr.ForwardSchedulerSvc.MaxAlgosInFlight = numAlgsInFlight + +# ThreadPoolService thread local initialization +# from GaudiHive.GaudiHiveConf import ThreadPoolSvc +# svcMgr += ThreadPoolSvc("ThreadPoolSvc") +# svcMgr.ThreadPoolSvc.ThreadInitTools = ["ThreadInitTool"] + + +from IOVSvc.IOVSvcConf import CondSvc +svcMgr += CondSvc( OutputLevel=DEBUG ) + +#-----------------------------------------------------------------------------# + +# +## Uncomment following to avoid long waits when segfaulting, +## and add "Root.Stacktrace: no" to your .rootrc file +# +# import ROOT +# ROOT.SetSignalPolicy( ROOT.kSignalFast ) + +#-----------------------------------------------------------------------------# + + +# from StoreGate.StoreGateConf import StoreGateSvc +# theApp.CreateSvc += ["StoreGateSvc/ConditionStore"] + +# +## AlgSequence +# + +from AthenaCommon.AlgSequence import AlgSequence +topSequence = AlgSequence() + +from SGComps.SGCompsConf import SGInputLoader +topSequence+=SGInputLoader(OutputLevel=INFO, ShowEventDump=False) +topSequence.SGInputLoader.Load = [ ('EventInfo','McEventInfo') ] + +from AthExHive.AthExHiveConf import * +topSequence+=AlgA(OutputLevel=DEBUG) +topSequence+=AlgB(OutputLevel=DEBUG, Key_R1="a1", Key_W1="a3") +topSequence+=AlgC("AlgC1", OutputLevel=DEBUG, Key_R1="a2", Key_CH="X1") +topSequence+=AlgC("AlgC2", OutputLevel=DEBUG, Key_R1="a1", Key_CH="X2") +topSequence+=AlgD("AlgD1", OutputLevel=DEBUG, Key_R1="a3", Key_CH1="X1", Key_CH2="X2") +#topSequence+=AlgD("AlgD2", OutputLevel=DEBUG, Key_R1="a1", Key_CH1="Y1", Key_CH2="Y2") + +topSequence+=CondAlgX("CondAlgX1", OutputLevel=DEBUG, Key_CH="X1", Key_DB="X1") +topSequence+=CondAlgX("CondAlgX2", OutputLevel=DEBUG, Key_CH="X2", Key_DB="X2") + +topSequence+=CondAlgY("CondAlgY1", OutputLevel=DEBUG, Key_CH1="Y1", Key_CH2="Y2", Key_DB1="Y1", Key_DB2="Y2") + +svcMgr += ASCIICondDbSvc( OutputLevel=DEBUG, CondFile = "condDb.txt" ) + + +#-------------------------------------------------------------- +# Event related parameters +#-------------------------------------------------------------- + +theApp.EvtMax = 20 + +nProc = jp.ConcurrencyFlags.NumProcs() +if (nProc > 0) : + + # + ## Basic setup for MP/Hive + # + import AthenaCommon.AtlasUnixGeneratorJob + + # + ## For MP/Hive we need to set the chunk size + # + + from AthenaCommon.Logging import log as msg + if (theApp.EvtMax == -1) : + msg.fatal('EvtMax must be >0 for hybrid configuration') + sys.exit(AthenaCommon.ExitCodes.CONFIGURATION_ERROR) + + if ( theApp.EvtMax % nProc != 0 ) : + msg.warning('EvtMax[%s] is not divisible by nProcs[%s]: MP Workers will not process all requested events',theApp.EvtMax,nProc) + + chunkSize = int (theApp.EvtMax / nProc) + + from AthenaMP.AthenaMPFlags import jobproperties as jps + jps.AthenaMPFlags.PreCountedEvents=theApp.EvtMax + jps.AthenaMPFlags.ChunkSize= chunkSize + + msg.info('AthenaMP workers will process %s events each',chunkSize) + + + +print "==========================================================================================\n" + +# +## set which Algorithms can be cloned +# + +# set algCardinality = 1 to disable cloning for all Algs +algCardinality = jp.ConcurrencyFlags.NumThreads() + +if (algCardinality != 1): + for alg in topSequence: + name = alg.name() + if name in [ "" ] : + # Don't clone these algs + alg.Cardinality = 1 + alg.IsClonable = False + print " --> cloning suppressed for ", name + else: + alg.Cardinality = algCardinality + alg.IsClonable = True + diff --git a/Control/AthenaExamples/AthExHive/share/DataLoopTest.py b/Control/AthenaExamples/AthExHive/share/DataLoopTest.py new file mode 100644 index 0000000000000000000000000000000000000000..03e5036bcc599cf26a3e728212eb4ca3b1f9583e --- /dev/null +++ b/Control/AthenaExamples/AthExHive/share/DataLoopTest.py @@ -0,0 +1,161 @@ + +# +## can only run if Hive enabled +# +from AthenaCommon.Logging import log as msg + +from AthenaCommon.ConcurrencyFlags import jobproperties as jp +nThreads = jp.ConcurrencyFlags.NumThreads() +if (nThreads < 1) : + msg.fatal('numThreads must be >0. Did you set the --threads=N option?') + sys.exit(AthenaCommon.ExitCodes.CONFIGURATION_ERROR) + +# +## Override Setup for Hive +# + +from AthenaServices.AthenaServicesConf import AthenaHiveEventLoopMgr +# svcMgr.AthenaHiveEventLoopMgr.OutputLevel = INFO + +from StoreGate.StoreGateConf import SG__HiveMgrSvc +# svcMgr.EventDataSvc.OutputLevel = INFO + +from GaudiHive.GaudiHiveConf import AlgResourcePool +# svcMgr += AlgResourcePool( OutputLevel = INFO ); + +from GaudiHive.GaudiHiveConf import ForwardSchedulerSvc +svcMgr.ForwardSchedulerSvc.OutputLevel = INFO +svcMgr.ForwardSchedulerSvc.CheckDependencies = True +svcMgr.ForwardSchedulerSvc.useGraphFlowManagement = True + +# +## Override defaults for numStores and numAlgsInFlight +## Otherwise these are BOTH EQUAL to the number of threads set with the +## command line opt --threads=N +# + +# numStores = 1 +# numAlgsInFlight = 1 + +# svcMgr.EventDataSvc.NSlots = numStores +# svcMgr.ForwardSchedulerSvc.MaxEventsInFlight = numStores +# svcMgr.ForwardSchedulerSvc.MaxAlgosInFlight = numAlgsInFlight + +# ThreadPoolService thread local initialization +from GaudiHive.GaudiHiveConf import ThreadPoolSvc +svcMgr += ThreadPoolSvc("ThreadPoolSvc") +svcMgr.ThreadPoolSvc.ThreadInitTools = ["ThreadInitTool"] + +from GaudiHive.GaudiHiveConf import AlgResourcePool +svcMgr += AlgResourcePool(OutputLevel=DEBUG) + +#---------------------------------------------------------------------------------# + +# +## Uncomment following to avoid long waits when segfaulting, +## and add "Root.Stacktrace: no" to your .rootrc file +# +# import ROOT +# ROOT.SetSignalPolicy( ROOT.kSignalFast ) + +#---------------------------------------------------------------------------------# + + +# +## AlgSequence +# + +from AthenaCommon.AlgSequence import AlgSequence +topSequence = AlgSequence() + +from SGComps.SGCompsConf import SGInputLoader +topSequence+=SGInputLoader(OutputLevel=INFO, ShowEventDump=False) +topSequence.SGInputLoader.Load = [ ('EventInfo','McEventInfo') ] + +from AthExHive.AthExHiveConf import * +HA = HiveAlgA("AlgA",OutputLevel=DEBUG,Time=20) +HB = HiveAlgB("AlgB",OutputLevel=DEBUG,Time=10) +HC = HiveAlgC("AlgC",OutputLevel=DEBUG,Time=190) +HE = HiveAlgE("AlgE",OutputLevel=DEBUG,Time=10) + +# add a data loop in a sequence to test strict ordering +from AthenaCommon.AlgSequence import AthSequencer +alp = AthSequencer("LoopSeq", OutputLevel=DEBUG) + +loopKey = "l2" +HL1 = HiveAlgL1("AlgL1",OutputLevel=DEBUG,Key_W1=loopKey,Time=110) +HL2 = HiveAlgL2("AlgL2",OutputLevel=DEBUG,Key_R1=loopKey,Key_U1=loopKey,Time=320) +HL3 = HiveAlgL3("AlgL3",OutputLevel=DEBUG,Key_U1=loopKey,Time=120) + +# AlgM tests to see if sequence was ordered properly +HM = HiveAlgM("AlgM",OutputLevel=DEBUG,Key_R2=loopKey,Offset=3,Time=30) + +alp += HL1 +alp += HL2 +alp += HL3 +alp += HM +topSequence += alp + +topSequence += HA +topSequence += HB +topSequence += HC +topSequence += HE + + +#-------------------------------------------------------------- +# Event related parameters +#-------------------------------------------------------------- + +theApp.EvtMax = 10 + +nProc = jp.ConcurrencyFlags.NumProcs() +if (nProc > 0) : + + # + ## Basic setup for MP/Hive + # + import AthenaCommon.AtlasUnixGeneratorJob + + # + ## For MP/Hive we need to set the chunk size + # + + from AthenaCommon.Logging import log as msg + if (theApp.EvtMax == -1) : + msg.fatal('EvtMax must be >0 for hybrid configuration') + sys.exit(AthenaCommon.ExitCodes.CONFIGURATION_ERROR) + + if ( theApp.EvtMax % nProc != 0 ) : + msg.warning('EvtMax[%s] is not divisible by nProcs[%s]: MP Workers will not process all requested events',theApp.EvtMax,nProc) + + chunkSize = int (theApp.EvtMax / nProc) + + from AthenaMP.AthenaMPFlags import jobproperties as jps + jps.AthenaMPFlags.PreCountedEvents=theApp.EvtMax + jps.AthenaMPFlags.ChunkSize= chunkSize + + msg.info('AthenaMP workers will process %s events each',chunkSize) + + + +print "==========================================================================================\n" + +# +## set which Algorithms can be cloned +# + +# set algCardinality = 1 to disable cloning for all Algs +algCardinality = jp.ConcurrencyFlags.NumThreads() + +if (algCardinality != 1): + for alg in topSequence: + name = alg.name() + if name in [ "" ] : + # Don't clone these algs + alg.Cardinality = 1 + alg.IsClonable = False + print " --> cloning suppressed for ", name + else: + alg.Cardinality = algCardinality + alg.IsClonable = True + diff --git a/Control/AthenaExamples/AthExHive/share/RAthExHiveOpts.py b/Control/AthenaExamples/AthExHive/share/RAthExHiveOpts.py new file mode 100644 index 0000000000000000000000000000000000000000..19af7dbc477bd18b5f523433706c806dbc9625b8 --- /dev/null +++ b/Control/AthenaExamples/AthExHive/share/RAthExHiveOpts.py @@ -0,0 +1,133 @@ + +# +## can only run if Hive enabled +# +from AthenaCommon.Logging import log as msg + +from AthenaCommon.ConcurrencyFlags import jobproperties as jp +nThreads = jp.ConcurrencyFlags.NumThreads() +if (nThreads < 1) : + msg.fatal('numThreads must be >0. Did you set the --threads=N option?') + sys.exit(AthenaCommon.ExitCodes.CONFIGURATION_ERROR) + +# +## Override Setup for Hive +# + +from AthenaServices.AthenaServicesConf import AthenaHiveEventLoopMgr +# svcMgr.AthenaHiveEventLoopMgr.OutputLevel = INFO + +from StoreGate.StoreGateConf import SG__HiveMgrSvc +# svcMgr.EventDataSvc.OutputLevel = INFO + +from GaudiHive.GaudiHiveConf import AlgResourcePool +# svcMgr += AlgResourcePool( OutputLevel = INFO ); + +from GaudiHive.GaudiHiveConf import ForwardSchedulerSvc +svcMgr.ForwardSchedulerSvc.OutputLevel = INFO +svcMgr.ForwardSchedulerSvc.CheckDependencies = True + +# +## Override defaults for numStores and numAlgsInFlight +## Otherwise these are BOTH EQUAL to the number of threads set with the +## command line opt --threads=N +# + +# numStores = 1 +# numAlgsInFlight = 1 + +# svcMgr.EventDataSvc.NSlots = numStores +# svcMgr.ForwardSchedulerSvc.MaxEventsInFlight = numStores +# svcMgr.ForwardSchedulerSvc.MaxAlgosInFlight = numAlgsInFlight + +# ThreadPoolService thread local initialization +# from GaudiHive.GaudiHiveConf import ThreadPoolSvc +# svcMgr += ThreadPoolSvc("ThreadPoolSvc") +# svcMgr.ThreadPoolSvc.ThreadInitTools = ["ThreadInitTool"] + +#---------------------------------------------------------------------------------# + +# +## Uncomment following to avoid long waits when segfaulting, +## and add "Root.Stacktrace: no" to your .rootrc file +# +# import ROOT +# ROOT.SetSignalPolicy( ROOT.kSignalFast ) + +#---------------------------------------------------------------------------------# + + +# +## AlgSequence +# + +from AthenaCommon.AlgSequence import AlgSequence +topSequence = AlgSequence() + +from SGComps.SGCompsConf import SGInputLoader +topSequence+=SGInputLoader(OutputLevel=INFO, ShowEventDump=False) +topSequence.SGInputLoader.Load = [ ('EventInfo','McEventInfo') ] + +from AthExHive.AthExHiveConf import * +topSequence+=HiveAlgR(OutputLevel=DEBUG) +topSequence+=HiveAlgA(OutputLevel=DEBUG,Time=20) +topSequence+=HiveAlgB(OutputLevel=DEBUG,Time=10) +topSequence+=HiveAlgC(OutputLevel=DEBUG,Time=190) + +#-------------------------------------------------------------- +# Event related parameters +#-------------------------------------------------------------- + +theApp.EvtMax = 20 + +nProc = jp.ConcurrencyFlags.NumProcs() +if (nProc > 0) : + + # + ## Basic setup for MP/Hive + # + import AthenaCommon.AtlasUnixGeneratorJob + + # + ## For MP/Hive we need to set the chunk size + # + + from AthenaCommon.Logging import log as msg + if (theApp.EvtMax == -1) : + msg.fatal('EvtMax must be >0 for hybrid configuration') + sys.exit(AthenaCommon.ExitCodes.CONFIGURATION_ERROR) + + if ( theApp.EvtMax % nProc != 0 ) : + msg.warning('EvtMax[%s] is not divisible by nProcs[%s]: MP Workers will not process all requested events',theApp.EvtMax,nProc) + + chunkSize = int (theApp.EvtMax / nProc) + + from AthenaMP.AthenaMPFlags import jobproperties as jps + jps.AthenaMPFlags.PreCountedEvents=theApp.EvtMax + jps.AthenaMPFlags.ChunkSize= chunkSize + + msg.info('AthenaMP workers will process %s events each',chunkSize) + + + +print "==========================================================================================\n" + +# +## set which Algorithms can be cloned +# + +# set algCardinality = 1 to disable cloning for all Algs +algCardinality = jp.ConcurrencyFlags.NumThreads() + +if (algCardinality != 1): + for alg in topSequence: + name = alg.name() + if name in [ "" ] : + # Don't clone these algs + alg.Cardinality = 1 + alg.IsClonable = False + print " --> cloning suppressed for ", name + else: + alg.Cardinality = algCardinality + alg.IsClonable = True + diff --git a/Control/AthenaExamples/AthExHive/share/condDb.txt b/Control/AthenaExamples/AthExHive/share/condDb.txt new file mode 100644 index 0000000000000000000000000000000000000000..76263c335650ddae60fa6c87469f38187810b958 --- /dev/null +++ b/Control/AthenaExamples/AthExHive/share/condDb.txt @@ -0,0 +1,10 @@ +# general format: dbKey IOVRANGE_1=VAL1 IOVRANGE_2=VAL2 ... +# VAL is an integer +# IOVRange format: {IOVTIME_START-IOVTIME_END} +# IOVTime format: [RUN#,EVENT#] +# +X1 {[1,0]-[1,3]}=1. {[1,3]-[1,8]}=3.3 {[1,8]-[1,15]}=7.1 {[1,15]-[999,999]}=5 +X2 {[1,0]-[1,2]}=11 {[1,2]-[1,18]}=13 {[1,18]-[1,100]}=25.5 +# +Y1 {[1,0]-[1,4]}=31 {[1,4]-[1,7]}=33.1 {[1,7]-[1,16]}=35 {[1,16]-[999,999]}=37 +Y2 {[1,0]-[1,5]}=51 {[1,5]-[1,6]}=55 {[1,6]-[1,12]}=57 {[1,12]-[1,17]}=53 {[1,17]-[999,999]}=999 diff --git a/Control/AthenaExamples/AthExHive/src/ASCIICondDbSvc.cxx b/Control/AthenaExamples/AthExHive/src/ASCIICondDbSvc.cxx new file mode 100644 index 0000000000000000000000000000000000000000..2e762cde239e23ff19e311aa529ab8d7fdc7e7df --- /dev/null +++ b/Control/AthenaExamples/AthExHive/src/ASCIICondDbSvc.cxx @@ -0,0 +1,251 @@ +/* + Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration +*/ + +#include "ASCIICondDbSvc.h" +#include "AthenaKernel/CondCont.h" +#include "GaudiKernel/SvcFactory.h" + +#include <boost/tokenizer.hpp> +#include <boost/algorithm/string.hpp> +#include <boost/regex.hpp> + +#include <fstream> + +std::string r_t("\\[([0-9]+),([0-9]+)\\]"); +std::string r_r = "\\s*\\{" + r_t + "-" + r_t + "\\}\\s*"; +std::string r_e = "\\s*\\{" + r_t + "-" + r_t + "\\}=([0-9]+)\\s*"; +std::string r_ef = "\\s*\\{" + r_t + "-" + r_t + "\\}=(-*[0-9]*\\.*[0-9]*)\\s*"; +boost::regex rr(r_r); +boost::regex re(r_e); +boost::regex ref(r_ef); + + +//--------------------------------------------------------------------------- + +ASCIICondDbSvc::ASCIICondDbSvc( const std::string& name, ISvcLocator* svcLoc ): + base_class(name,svcLoc) +{ + + declareProperty("CondFile",m_file=""); + +} + +//--------------------------------------------------------------------------- + +ASCIICondDbSvc::~ASCIICondDbSvc() { + +} + +//--------------------------------------------------------------------------- + +StatusCode +ASCIICondDbSvc::initialize() { + + // Initialise mother class in order to print DEBUG messages during initialize() + StatusCode sc(AthService::initialize()); + msg().setLevel( m_outputLevel.value() ); + + if (!sc.isSuccess()) { + warning () << "Base class could not be initialized" << endmsg; + return StatusCode::FAILURE; + } + + if (m_file == "") { + ATH_MSG_DEBUG("db file not set"); + return StatusCode::SUCCESS; + } + + if (readDbFile(m_file).isFailure()) { + return StatusCode::FAILURE; + } + + std::ostringstream ost; + ost << " Printing CondDB registry"; + for (auto e : m_registry) { + ost << std::endl << " - id: " << e.first << " r:"; + for (auto r : e.second) { + ost << " " << r.range() << " :: " << *r.objPtr(); + } + } + + ATH_MSG_DEBUG( ost.str() ); + + return StatusCode::SUCCESS; + +} +//--------------------------------------------------------------------------- + +StatusCode +ASCIICondDbSvc::readDbFile(const std::string& fname) { + + StatusCode sc(StatusCode::SUCCESS); + + ATH_MSG_DEBUG("reading cond db from \"" << fname << "\""); + + std::ifstream ifs (fname); + std::string line; + if(ifs.is_open()) { + + typedef boost::tokenizer<boost::char_separator<char> > tokenizer; + boost::char_separator<char> sep(" "); + + IOVEntryT<IASCIICondDbSvc::dbData_t> ie; + + while( getline (ifs, line) ) { + + // ignore anything after a "#" and blank lines + size_t fh = line.find("#"); + if(fh != std::string::npos) + line.erase(fh,line.length()-fh); + if (line.length() == 0) continue; + + tokenizer tokens(line, sep); + auto it = tokens.begin(); + + std::string dbKey = *it; + + ++it; + + while (it != tokens.end()) { + if (parse(ie,*it)) { + m_registry[dbKey].push_back( ie ); + } else { + error() << "while reading " << fname << " problem parsing " << *it + << " in line\n" << line << endmsg; + sc = StatusCode::FAILURE; + } + ++it; + } + } + ifs.close(); + } else { + error() << "unable to open file " << m_file << endmsg; + sc = StatusCode::FAILURE; + } + + return sc; + +} +//--------------------------------------------------------------------------- + +void +ASCIICondDbSvc::dump() const { + + std::ostringstream ost; + dump(ost); + + info() << ost.str() << endmsg; + +} + + +//--------------------------------------------------------------------------- + +void +ASCIICondDbSvc::dump(std::ostringstream& ost) const { + + std::lock_guard<std::recursive_mutex> lock(m_lock); + + ost << "ASCIICondDbSvc::dump()"; + + ost << "\n"; + +} + +//--------------------------------------------------------------------------- + +StatusCode +ASCIICondDbSvc::finalize() { + + ATH_MSG_DEBUG( "ASCIICondDbSvc::finalize()" ); + + if (msgLvl(MSG::DEBUG)) { + std::ostringstream ost; + dump(ost); + + ATH_MSG_DEBUG( ost.str() ); + } + + for ( auto e : m_registry ) { + for ( auto ie : e.second ) { + delete ie.objPtr(); + ie.setPtr(0); + } + } + + + return StatusCode::SUCCESS; + +} + +//--------------------------------------------------------------------------- + +bool +ASCIICondDbSvc::parse(EventIDRange& t, const std::string& s) { + + boost::smatch m; + boost::regex_match(s,m,rr); + + // for (auto res : m) { + // cout << " - " << res << endl; + // } + + if (m.size() != 5) { return false; } + + t = EventIDRange( EventIDBase(std::stoi(m[1]),std::stoi(m[2])), + EventIDBase(std::stoi(m[3]), std::stoi(m[4]))); + + return true; + +} + +//--------------------------------------------------------------------------- + +bool +ASCIICondDbSvc::parse(IOVEntryT<IASCIICondDbSvc::dbData_t>& ie, const std::string& s) { + + boost::smatch m; + boost::regex_match(s,m,ref); + + if (m.size() != 6) { return false; } + + ie.setRange( EventIDRange( EventIDBase(std::stoi(m[1]), std::stoi(m[2])), + EventIDBase(std::stoi(m[3]), std::stoi(m[4])) ) ); + + IASCIICondDbSvc::dbData_t *v = new IASCIICondDbSvc::dbData_t( std::stof(m[5]) ); + ie.setPtr(v); + + return true; + +} + +//--------------------------------------------------------------------------- + +StatusCode +ASCIICondDbSvc::getRange(const std::string& dbKey , const EventContext& ctx, + EventIDRange& rng, IASCIICondDbSvc::dbData_t& val) const { + + std::lock_guard<std::recursive_mutex> lock(m_lock); + + registry_t::const_iterator itr = m_registry.find(dbKey); + + if (itr == m_registry.end()) { + error() << "getRange: no dbKey " << dbKey << " found in registry" + << endmsg; + return StatusCode::FAILURE; + } + + for (auto e : itr->second) { + if (e.range().isInRange(EventIDBase(ctx.eventID()))) { + rng = e.range(); + val = *(e.objPtr()); + return StatusCode::SUCCESS; + } + } + + error() << "getRange: no range for Time " << ctx.eventID() + << " found for dbKey " << dbKey << endmsg; + + return StatusCode::FAILURE; +} diff --git a/Control/AthenaExamples/AthExHive/src/ASCIICondDbSvc.h b/Control/AthenaExamples/AthExHive/src/ASCIICondDbSvc.h new file mode 100644 index 0000000000000000000000000000000000000000..79dbecd1f25ad335fa57466845263ebb6f6c9823 --- /dev/null +++ b/Control/AthenaExamples/AthExHive/src/ASCIICondDbSvc.h @@ -0,0 +1,55 @@ +/* + Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration +*/ + +#ifndef ATHEXHIVE_ASCIICONDDBSVC_H +#define ATHEXHIVE_ASCIICONDDBSVC_H 1 + +#include "GaudiKernel/Service.h" +#include "GaudiKernel/EventIDBase.h" +#include "GaudiKernel/EventIDRange.h" +#include "AthenaBaseComps/AthService.h" +#include "AthenaBaseComps/AthService.h" + +#include "AthExHive/IASCIICondDbSvc.h" + +#include <map> +#include <set> +#include <vector> +#include <mutex> + +class ASCIICondDbSvc: public extends1<AthService, IASCIICondDbSvc> { +public: + + ASCIICondDbSvc(const std::string& name, ISvcLocator* svc); + ~ASCIICondDbSvc(); + + virtual StatusCode initialize(); + virtual StatusCode finalize(); + + // from IASCIICondDbSvc +public: + + virtual StatusCode getRange(const std::string&, const EventContext&, EventIDRange&, + IASCIICondDbSvc::dbData_t&) const; + + virtual void dump() const; + virtual void dump(std::ostringstream&) const; + +private: + + bool parse(EventIDRange& t, const std::string& s); + bool parse(IOVEntryT<IASCIICondDbSvc::dbData_t>& t, const std::string& s); + + StatusCode readDbFile(const std::string&); + + std::string m_file; + + typedef std::map<std::string, std::vector<IOVEntryT<IASCIICondDbSvc::dbData_t>>> registry_t; + registry_t m_registry; + + mutable std::recursive_mutex m_lock; + +}; + +#endif diff --git a/Control/AthenaExamples/AthExHive/src/AlgA.cxx b/Control/AthenaExamples/AthExHive/src/AlgA.cxx new file mode 100644 index 0000000000000000000000000000000000000000..dab727d2c1de1fa6aefaaf10f147e8239bbbff82 --- /dev/null +++ b/Control/AthenaExamples/AthExHive/src/AlgA.cxx @@ -0,0 +1,84 @@ +/* + Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration +*/ + +#include "AlgA.h" +#include "CxxUtils/make_unique.h" +#include "EventInfo/EventInfo.h" +#include "EventInfo/EventID.h" +#include "StoreGate/ReadHandle.h" +#include "StoreGate/WriteHandle.h" + +#include "GaudiKernel/ServiceHandle.h" + +#include <thread> +#include <chrono> +#include <ctime> + +AlgA::AlgA( const std::string& name, + ISvcLocator* pSvcLocator ) : + ::AthAlgorithm( name, pSvcLocator ), + m_wrh1("a1"), + m_wrh2("a2"), + m_evt("McEventInfo") +{ + + declareProperty("Key_W1",m_wrh1); + declareProperty("Key_W2",m_wrh2); + declareProperty("EvtInfo", m_evt); + + m_i = 1; + +} + +//--------------------------------------------------------------------------- + +AlgA::~AlgA() {} + +StatusCode AlgA::initialize() { + ATH_MSG_DEBUG("initialize " << name()); + + ATH_CHECK( m_wrh1.initialize() ); + ATH_CHECK( m_wrh2.initialize() ); + ATH_CHECK( m_evt.initialize() ); + + return StatusCode::SUCCESS; +} + +//--------------------------------------------------------------------------- + +StatusCode AlgA::finalize() { + ATH_MSG_DEBUG("finalize " << name()); + return StatusCode::SUCCESS; +} + +//--------------------------------------------------------------------------- + +StatusCode AlgA::execute() { + + ATH_MSG_DEBUG("execute " << name()); + + SG::ReadHandle<EventInfo> evt(m_evt); + ATH_MSG_INFO(" EventInfo: r: " << evt->event_ID()->run_number() + << " e: " << evt->event_ID()->event_number() ); + + + SG::WriteHandle<HiveDataObj> wh1(m_wrh1); + ATH_CHECK( wh1.record( CxxUtils::make_unique<HiveDataObj> + ( HiveDataObj(10000 + + evt->event_ID()->event_number()*100 + + m_i) ) ) + ); + ATH_MSG_INFO(" write: " << wh1.key() << " = " << wh1->val() ); + + + SG::WriteHandle<HiveDataObj> wh2(m_wrh2); + ATH_CHECK( wh2.record( CxxUtils::make_unique< HiveDataObj >( HiveDataObj(10050+m_i) ) ) ); + ATH_MSG_INFO(" write: " << wh2.key() << " = " << wh2->val() ); + + m_i += 1; + + return StatusCode::SUCCESS; + +} + diff --git a/Control/AthenaExamples/AthExHive/src/AlgA.h b/Control/AthenaExamples/AthExHive/src/AlgA.h new file mode 100644 index 0000000000000000000000000000000000000000..ae692f1a8566747d7f0ee7940377b907f1f8f77b --- /dev/null +++ b/Control/AthenaExamples/AthExHive/src/AlgA.h @@ -0,0 +1,37 @@ +/* + Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration +*/ + +#ifndef CONDALGS_ALGA_H +#define CONDALGS_ALGA_H 1 + +#include "AthenaBaseComps/AthAlgorithm.h" +#include "StoreGate/WriteHandleKey.h" +#include "StoreGate/ReadHandleKey.h" +#include "AthExHive/HiveDataObj.h" + +#include "EventInfo/EventInfo.h" + +#include <string> + +class AlgA : public AthAlgorithm { + +public: + + AlgA (const std::string& name, ISvcLocator* pSvcLocator); + ~AlgA (); + + StatusCode initialize(); + StatusCode execute(); + StatusCode finalize(); + +private: + + SG::WriteHandleKey<HiveDataObj> m_wrh1; + SG::WriteHandleKey<HiveDataObj> m_wrh2; + SG::ReadHandleKey<EventInfo> m_evt; + + std::atomic<int> m_i {1}; + +}; +#endif diff --git a/Control/AthenaExamples/AthExHive/src/AlgB.cxx b/Control/AthenaExamples/AthExHive/src/AlgB.cxx new file mode 100644 index 0000000000000000000000000000000000000000..d3247a0997c8be024f932bb6e6a7d702dc432d29 --- /dev/null +++ b/Control/AthenaExamples/AthExHive/src/AlgB.cxx @@ -0,0 +1,62 @@ +/* + Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration +*/ + +#include "AlgB.h" +#include "CxxUtils/make_unique.h" +#include "StoreGate/ReadHandle.h" +#include "StoreGate/WriteHandle.h" +#include "GaudiKernel/ServiceHandle.h" +#include <thread> +#include <chrono> + +AlgB::AlgB( const std::string& name, + ISvcLocator* pSvcLocator ) : + ::AthAlgorithm( name, pSvcLocator ), + m_rdh1("a1"), + m_wrh1("a3") +{ + + declareProperty("Key_R1",m_rdh1); + declareProperty("Key_W1",m_wrh1); + +} + +AlgB::~AlgB() {} + +StatusCode AlgB::initialize() { + ATH_MSG_DEBUG("initialize " << name()); + + ATH_CHECK( m_rdh1.initialize() ); + ATH_CHECK( m_wrh1.initialize() ); + + return StatusCode::SUCCESS; +} + +StatusCode AlgB::finalize() { + ATH_MSG_DEBUG("finalize " << name()); + return StatusCode::SUCCESS; +} + +StatusCode AlgB::execute() { + ATH_MSG_DEBUG("execute " << name()); + + SG::ReadHandle<HiveDataObj> rh1(m_rdh1); + if (!rh1.isValid()) { + ATH_MSG_ERROR ("Could not retrieve HiveDataObj with key " << m_rdh1.key()); + return StatusCode::FAILURE; + } + + ATH_MSG_INFO(" read: " << rh1.key() << " = " << rh1->val() ); + + SG::WriteHandle<HiveDataObj> wh1(m_wrh1); + ATH_CHECK( wh1.record( CxxUtils::make_unique< HiveDataObj > + ( HiveDataObj(3300 + rh1->val()) ) ) ); + + ATH_MSG_INFO(" write: " << wh1.key() << " = " << wh1->val() ); + ATH_CHECK(wh1.isValid()); + + return StatusCode::SUCCESS; + +} + diff --git a/Control/AthenaExamples/AthExHive/src/AlgB.h b/Control/AthenaExamples/AthExHive/src/AlgB.h new file mode 100644 index 0000000000000000000000000000000000000000..72a5aa95d83c5da2c6f9a5bedbc3158ee2151c82 --- /dev/null +++ b/Control/AthenaExamples/AthExHive/src/AlgB.h @@ -0,0 +1,32 @@ +/* + Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration +*/ + +#ifndef CONDALGS_ALGB_H +#define CONDALGS_ALGB_H 1 + +#include "AthenaBaseComps/AthAlgorithm.h" +#include "StoreGate/WriteHandleKey.h" +#include "StoreGate/ReadHandleKey.h" +#include "AthExHive/HiveDataObj.h" + +#include <string> + +class AlgB : public AthAlgorithm { + +public: + + AlgB (const std::string& name, ISvcLocator* pSvcLocator); + ~AlgB(); + + StatusCode initialize(); + StatusCode execute(); + StatusCode finalize(); + +private: + + SG::ReadHandleKey<HiveDataObj> m_rdh1; + SG::WriteHandleKey<HiveDataObj> m_wrh1; + +}; +#endif diff --git a/Control/AthenaExamples/AthExHive/src/AlgC.cxx b/Control/AthenaExamples/AthExHive/src/AlgC.cxx new file mode 100644 index 0000000000000000000000000000000000000000..e72e0a1b3d1b460c0c5cf7b1b84b554cdb2e5799 --- /dev/null +++ b/Control/AthenaExamples/AthExHive/src/AlgC.cxx @@ -0,0 +1,84 @@ +/* + Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration +*/ + +#include "AlgC.h" + +#include "CxxUtils/make_unique.h" +#include "StoreGate/ReadCondHandleKey.h" +#include "EventInfo/EventInfo.h" +#include "EventInfo/EventID.h" + +#include "GaudiKernel/ServiceHandle.h" +#include <thread> +#include <chrono> + + +AlgC::AlgC( const std::string& name, + ISvcLocator* pSvcLocator ) : + ::AthAlgorithm( name, pSvcLocator ), + m_rdh1("a2"), + m_rch("X1") +{ + + declareProperty("Key_R1",m_rdh1); + declareProperty("Key_CH", m_rch); + +} + +//--------------------------------------------------------------------------- + +AlgC::~AlgC() {} + +//--------------------------------------------------------------------------- + +StatusCode AlgC::initialize() { + ATH_MSG_DEBUG("initialize " << name()); + + ATH_CHECK(m_rdh1.initialize()); + ATH_CHECK(m_rch.initialize()); + + ATH_MSG_INFO( "m_rdh1 id: " << m_rdh1.fullKey() ); + ATH_MSG_INFO( "m_rch id: " << m_rch.fullKey() ); + + + return StatusCode::SUCCESS; +} + +//--------------------------------------------------------------------------- + +StatusCode AlgC::finalize() { + ATH_MSG_DEBUG("finalize " << name()); + return StatusCode::SUCCESS; +} + +//--------------------------------------------------------------------------- + +StatusCode AlgC::execute() { + ATH_MSG_DEBUG("execute " << name()); + + SG::ReadHandle<HiveDataObj> rh1(m_rdh1); + if (!rh1.isValid()) { + ATH_MSG_ERROR ("Could not retrieve HiveDataObj with key " << m_rdh1.key()); + return StatusCode::FAILURE; + } + + ATH_MSG_INFO(" read: " << rh1.key() << " = " << rh1->val() ); + + EventIDBase t( getContext().eventID() ); + + // const CondDataObj *cdo = m_rch.retrieve(t); + // const CondDataObj *cdo = m_rch.retrieve(); + + SG::ReadCondHandle<CondDataObj> rch( m_rch ); + const CondDataObj *cdo = *rch; + if (cdo != 0) { + ATH_MSG_INFO(" read CH: " << rch.key() << " = " << *cdo ); + } else { + ATH_MSG_ERROR(" CDO ptr for " << rch.key() << " == zero"); + } + + return StatusCode::SUCCESS; + +} + diff --git a/Control/AthenaExamples/AthExHive/src/AlgC.h b/Control/AthenaExamples/AthExHive/src/AlgC.h new file mode 100644 index 0000000000000000000000000000000000000000..e256d4b60b4a135ed4c77dd71bbbbd6a123e7a61 --- /dev/null +++ b/Control/AthenaExamples/AthExHive/src/AlgC.h @@ -0,0 +1,35 @@ +/* + Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration +*/ + +#ifndef CONDALGS_ALGC_H +#define CONDALGS_ALGC_H 1 + +#include "AthenaBaseComps/AthAlgorithm.h" +#include "StoreGate/ReadHandleKey.h" +#include "StoreGate/ReadCondHandleKey.h" + +#include "AthExHive/HiveDataObj.h" +#include "AthExHive/CondDataObj.h" + +#include <string> + +class AlgC : public AthAlgorithm { + +public: + + AlgC (const std::string& name, ISvcLocator* pSvcLocator); + ~AlgC(); + + StatusCode initialize(); + StatusCode execute(); + StatusCode finalize(); + +private: + + SG::ReadHandleKey<HiveDataObj> m_rdh1; + + SG::ReadCondHandleKey<CondDataObj> m_rch; + +}; +#endif diff --git a/Control/AthenaExamples/AthExHive/src/AlgD.cxx b/Control/AthenaExamples/AthExHive/src/AlgD.cxx new file mode 100644 index 0000000000000000000000000000000000000000..9a04377f64b550d4f3c3f09877d85d5391c6a5d0 --- /dev/null +++ b/Control/AthenaExamples/AthExHive/src/AlgD.cxx @@ -0,0 +1,95 @@ +/* + Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration +*/ + +#include "AlgD.h" +#include "CxxUtils/make_unique.h" +#include "StoreGate/ReadHandle.h" +#include "StoreGate/ReadCondHandle.h" +#include "EventInfo/EventInfo.h" +#include "EventInfo/EventID.h" + +#include "GaudiKernel/ServiceHandle.h" +#include <thread> +#include <chrono> + + +AlgD::AlgD( const std::string& name, + ISvcLocator* pSvcLocator ) : + ::AthAlgorithm( name, pSvcLocator ), + m_rdh1("a1"), + m_rch1("X1"), + m_rch2("X2") +{ + + declareProperty("Key_R1",m_rdh1); + declareProperty("Key_CH1",m_rch1); + declareProperty("Key_CH2",m_rch2); + +} + +//--------------------------------------------------------------------------- + +AlgD::~AlgD() {} + +//--------------------------------------------------------------------------- + +StatusCode AlgD::initialize() { + ATH_MSG_DEBUG("initialize " << name()); + + ATH_CHECK( m_rdh1.initialize() ); + ATH_CHECK( m_rch1.initialize() ); + ATH_CHECK( m_rch2.initialize() ); + + ATH_MSG_INFO( "m_rdh1 id: " << m_rdh1.fullKey() ); + ATH_MSG_INFO( "m_rch1 id: " << m_rch1.fullKey() ); + ATH_MSG_INFO( "m_rch2 id: " << m_rch2.fullKey() ); + + return StatusCode::SUCCESS; +} + +//--------------------------------------------------------------------------- + +StatusCode AlgD::finalize() { + ATH_MSG_DEBUG("finalize " << name()); + return StatusCode::SUCCESS; +} + +//--------------------------------------------------------------------------- + +StatusCode AlgD::execute() { + ATH_MSG_DEBUG("execute " << name()); + + SG::ReadHandle<HiveDataObj> rh1(m_rdh1); + if (!rh1.isValid()) { + ATH_MSG_ERROR ("Could not retrieve HiveDataObj with key " << m_rdh1.key()); + return StatusCode::FAILURE; + } + + ATH_MSG_INFO(" read: " << rh1.key() << " = " << rh1->val() ); + + SG::ReadCondHandle<CondDataObj> ch1( m_rch1 ); + SG::ReadCondHandle<CondDataObj> ch2( m_rch2 ); + + EventIDBase t( getContext().eventID() ); + + // const CondDataObj *cdo = m_rch.retrieve(t); + // const CondDataObj *cdo = m_rch.retrieve(); + const CondDataObj *cdo = *ch1; + if (cdo != 0) { + ATH_MSG_INFO(" CDO1: " << *cdo ); + } else { + ATH_MSG_ERROR(" CDO1 ptr == zero"); + } + + cdo = *ch2; + if (cdo != 0) { + ATH_MSG_INFO(" CDO2: " << *cdo ); + } else { + ATH_MSG_ERROR(" CDO2 ptr == zero"); + } + + return StatusCode::SUCCESS; + +} + diff --git a/Control/AthenaExamples/AthExHive/src/AlgD.h b/Control/AthenaExamples/AthExHive/src/AlgD.h new file mode 100644 index 0000000000000000000000000000000000000000..b1a2e37ab35c0a517963e953aee6db697f022107 --- /dev/null +++ b/Control/AthenaExamples/AthExHive/src/AlgD.h @@ -0,0 +1,36 @@ +/* + Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration +*/ + +#ifndef CONDALGS_ALGD_H +#define CONDALGS_ALGD_H 1 + +#include "AthenaBaseComps/AthAlgorithm.h" +#include "StoreGate/ReadHandleKey.h" +#include "StoreGate/ReadCondHandleKey.h" + +#include "AthExHive/HiveDataObj.h" +#include "AthExHive/CondDataObj.h" + +#include <string> + +class AlgD : public AthAlgorithm { + +public: + + AlgD (const std::string& name, ISvcLocator* pSvcLocator); + ~AlgD(); + + StatusCode initialize(); + StatusCode execute(); + StatusCode finalize(); + +private: + + SG::ReadHandleKey<HiveDataObj> m_rdh1; + + SG::ReadCondHandleKey<CondDataObj> m_rch1; + SG::ReadCondHandleKey<CondDataObj> m_rch2; + +}; +#endif diff --git a/Control/AthenaExamples/AthExHive/src/CondAlgX.cxx b/Control/AthenaExamples/AthExHive/src/CondAlgX.cxx new file mode 100644 index 0000000000000000000000000000000000000000..355fea63e73f4f9e23accb274f76ba004ce206be --- /dev/null +++ b/Control/AthenaExamples/AthExHive/src/CondAlgX.cxx @@ -0,0 +1,129 @@ +/* + Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration +*/ + +#include "CondAlgX.h" +#include "CxxUtils/make_unique.h" + +#include "StoreGate/WriteCondHandle.h" + +#include "GaudiKernel/ServiceHandle.h" + +#include "GaudiKernel/EventIDBase.h" +#include "GaudiKernel/EventIDRange.h" + +#include "EventInfo/EventInfo.h" +#include "EventInfo/EventID.h" + +#include <thread> +#include <chrono> + +CondAlgX::CondAlgX( const std::string& name, + ISvcLocator* pSvcLocator ) : + ::AthAlgorithm( name, pSvcLocator ), + m_evt("McEventInfo"), + m_wchk("X2","X2"), + m_cs("CondSvc",name), + m_cds("ASCIICondDbSvc",name) +{ + + declareProperty("EvtInfo", m_evt); + declareProperty("Key_CH", m_wchk); + declareProperty("Key_DB", m_dbKey); + +} + +CondAlgX::~CondAlgX() {} + +StatusCode CondAlgX::initialize() { + ATH_MSG_DEBUG("initialize " << name()); + + if (m_cs.retrieve().isFailure()) { + ATH_MSG_ERROR("unable to retrieve CondSvc"); + } + + if (m_cds.retrieve().isFailure()) { + ATH_MSG_ERROR("unable to retrieve ASCIICondDbSvc"); + } + + m_wchk.setDbKey(m_dbKey); + + if (m_wchk.initialize().isFailure()) { + ATH_MSG_ERROR("unable to initialize WriteCondHandle with key" << m_wchk.key() ); + return StatusCode::FAILURE; + } + + if (m_cs->regHandle(this, m_wchk, m_wchk.dbKey()).isFailure()) { + ATH_MSG_ERROR("unable to register WriteCondHandle " << m_wchk.fullKey() + << " with CondSvc"); + return StatusCode::FAILURE; + } + + return StatusCode::SUCCESS; +} + +StatusCode CondAlgX::finalize() { + ATH_MSG_DEBUG("finalize " << name()); + return StatusCode::SUCCESS; +} + +StatusCode CondAlgX::execute() { + ATH_MSG_DEBUG("execute " << name()); + + if (!m_evt.isValid()) { + ATH_MSG_ERROR ("Could not retrieve EventInfo"); + return StatusCode::FAILURE; + } + + ATH_MSG_DEBUG(" EventInfo: r: " << m_evt->event_ID()->run_number() + << " e: " << m_evt->event_ID()->event_number() ); + + + SG::WriteCondHandle<CondDataObj> wch(m_wchk); + + EventIDBase now(getContext().eventID()); + + if (m_evt->event_ID()->event_number() == 10) { + std::this_thread::sleep_for(std::chrono::milliseconds( 500 )); + } + + // do we have a valid m_wch for current time? + if ( wch.isValid(now) ) { + // in theory this should never be called + wch.updateStore(); + ATH_MSG_DEBUG("CondHandle is already valid for " << now + << ". In theory this should not be called, but may happen" + << " if multiple concurrent events are being processed out of order." + << " Forcing update of Store contents"); + + } else { + + ATH_MSG_DEBUG(" CondHandle " << wch.key() + << " not valid. Getting new info for dbKey \"" + << wch.dbKey() << "\" from CondDb"); + + EventIDRange r; + ICondSvc::dbData_t val; + if (m_cds->getRange(wch.dbKey(), getContext(), r, val).isFailure()) { + ATH_MSG_ERROR(" could not find dbKey \"" << wch.dbKey() + << "\" in CondSvc registry"); + return StatusCode::FAILURE; + } + + CondDataObj* cdo = new CondDataObj( val ); + if (wch.record(r, cdo).isFailure()) { + ATH_MSG_ERROR("could not record CondDataObj " << wch.key() + << " = " << *cdo + << " with EventRange " << r); + return StatusCode::FAILURE; + } + ATH_MSG_INFO("recorded new CDO " << wch.key() << " = " << *cdo + << " with range " << r); + } + + + + return StatusCode::SUCCESS; + +} + diff --git a/Control/AthenaExamples/AthExHive/src/CondAlgX.h b/Control/AthenaExamples/AthExHive/src/CondAlgX.h new file mode 100644 index 0000000000000000000000000000000000000000..479fad0e5fb0ae68f7beb7d523d6b3233a905a74 --- /dev/null +++ b/Control/AthenaExamples/AthExHive/src/CondAlgX.h @@ -0,0 +1,44 @@ +/* + Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration +*/ + +#ifndef CONDALGS_CONDALGX_H +#define CONDALGS_CONDALGX_H 1 + +#include "AthenaBaseComps/AthAlgorithm.h" +#include "StoreGate/ReadHandle.h" +#include "StoreGate/WriteCondHandleKey.h" + +#include "AthExHive/CondDataObj.h" +#include "AthExHive/IASCIICondDbSvc.h" + +#include "EventInfo/EventInfo.h" +#include "GaudiKernel/ICondSvc.h" + +#include <string> + +class CondAlgX : public AthAlgorithm { + +public: + + CondAlgX (const std::string& name, ISvcLocator* pSvcLocator); + ~CondAlgX(); + + StatusCode initialize(); + StatusCode execute(); + StatusCode finalize(); + +private: + + SG::ReadHandle<EventInfo> m_evt; + + SG::WriteCondHandleKey<CondDataObj> m_wchk; + + ServiceHandle<ICondSvc> m_cs; + ServiceHandle<IASCIICondDbSvc> m_cds; + + std::string m_dbKey; + +}; + +#endif diff --git a/Control/AthenaExamples/AthExHive/src/CondAlgY.cxx b/Control/AthenaExamples/AthExHive/src/CondAlgY.cxx new file mode 100644 index 0000000000000000000000000000000000000000..d03c7c6d95164306355587cfdb22e8ba61ca8446 --- /dev/null +++ b/Control/AthenaExamples/AthExHive/src/CondAlgY.cxx @@ -0,0 +1,151 @@ +/* + Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration +*/ + +#include "CondAlgY.h" +#include "CxxUtils/make_unique.h" +#include "StoreGate/WriteCondHandle.h" + +#include "GaudiKernel/ServiceHandle.h" + +#include "EventInfo/EventInfo.h" +#include "EventInfo/EventID.h" + +#include <thread> +#include <chrono> + +CondAlgY::CondAlgY( const std::string& name, + ISvcLocator* pSvcLocator ) : + ::AthAlgorithm( name, pSvcLocator ), + m_wch1("Y1","Y1"), m_wch2("Y2","Y2"), + m_dbk1("Y1"), m_dbk2("Y2"), + m_cs("CondSvc",name), + m_cds("ASCIICondDbSvc",name) +{ + + declareProperty("Key_CH1", m_wch1); + declareProperty("Key_CH2", m_wch2); + + declareProperty("Key_DB1", m_dbk1); + declareProperty("Key_DB2", m_dbk2); + +} + +CondAlgY::~CondAlgY() {} + +StatusCode CondAlgY::initialize() { + ATH_MSG_DEBUG("initialize " << name()); + + if (m_cs.retrieve().isFailure()) { + ATH_MSG_ERROR("unable to retrieve CondSvc"); + } + + if (m_cds.retrieve().isFailure()) { + ATH_MSG_ERROR("unable to retrieve ASCIICondDbSvc"); + } + + m_wch1.setDbKey(m_dbk1); + m_wch2.setDbKey(m_dbk2); + + if (m_wch1.initialize().isFailure()) { + ATH_MSG_ERROR("unable to initialize WriteHandleKey with key" << m_wch1.key() ); + return StatusCode::FAILURE; + } + + if (m_wch2.initialize().isFailure()) { + ATH_MSG_ERROR("unable to initialize WriteCondHandle with key" << m_wch2.key() ); + return StatusCode::FAILURE; + } + + if (m_cs->regHandle(this, m_wch1, m_wch1.dbKey()).isFailure()) { + ATH_MSG_ERROR("unable to register WriteCondHandle " << m_wch1.fullKey() + << " with CondSvc"); + return StatusCode::FAILURE; + } + + if (m_cs->regHandle(this, m_wch2, m_wch2.dbKey()).isFailure()) { + ATH_MSG_ERROR("unable to register WriteCondHandle " << m_wch2.fullKey() + << " with CondSvc"); + return StatusCode::FAILURE; + } + + return StatusCode::SUCCESS; +} + +StatusCode CondAlgY::finalize() { + ATH_MSG_DEBUG("finalize " << name()); + return StatusCode::SUCCESS; +} + +StatusCode CondAlgY::execute() { + ATH_MSG_DEBUG("execute " << name()); + + EventIDBase now(getContext().eventID()); + + SG::WriteCondHandle<CondDataObjY> wch1(m_wch1); + SG::WriteCondHandle<CondDataObjY> wch2(m_wch2); + + // do we have a valid m_wch for current time? + if ( wch1.isValid(now) ) { + // in theory this should never be called + wch1.updateStore(); + + } else { + + ATH_MSG_DEBUG(" CondHandle " << wch1.key() + << " not valid. Getting new info for dbKey \"" + << wch1.dbKey() << "\" from CondDb"); + + EventIDRange r; + ICondSvc::dbData_t val; + if (m_cds->getRange(wch1.dbKey(), getContext(), r, val).isFailure()) { + ATH_MSG_ERROR(" could not find dbKey \"" << wch1.dbKey() + << "\" in CondSvc registry"); + return StatusCode::FAILURE; + } + + CondDataObjY* cdo = new CondDataObjY( val ); + if (wch1.record(r, cdo).isFailure()) { + ATH_MSG_ERROR("could not record CondDataObjY " << wch1.key() + << " = " << *cdo + << " with EventRange " << r); + return StatusCode::FAILURE; + } + ATH_MSG_INFO("recorded new CDO " << wch1.key() << " = " << *cdo + << " with range " << r); + } + + // do we have a valid wch for current time? + if ( wch2.isValid(now) ) { + // in theory this should never be called + wch2.updateStore(); + + } else { + + ATH_MSG_DEBUG(" CondHandle " << wch2.key() + << " not valid. Getting new info for dbKey \"" + << wch2.dbKey() << "\" from CondDb"); + + EventIDRange r; + ICondSvc::dbData_t val; + if (m_cds->getRange(wch2.dbKey(), getContext(), r, val).isFailure()) { + ATH_MSG_ERROR(" could not find dbKey \"" << wch2.dbKey() + << "\" in CondSvc registry"); + return StatusCode::FAILURE; + } + + CondDataObjY* cdo = new CondDataObjY( val ); + if (wch2.record(r, cdo).isFailure()) { + ATH_MSG_ERROR("could not record CondDataObjY " << wch2.key() + << " = " << *cdo + << " with EventRange " << r); + return StatusCode::FAILURE; + } + ATH_MSG_INFO("recorded new CDO " << wch2.key() << " = " << *cdo + << " with range " << r); + } + + return StatusCode::SUCCESS; + +} + diff --git a/Control/AthenaExamples/AthExHive/src/CondAlgY.h b/Control/AthenaExamples/AthExHive/src/CondAlgY.h new file mode 100644 index 0000000000000000000000000000000000000000..f3bd0e7e1d33a5229cc9742a7293438ffe64e989 --- /dev/null +++ b/Control/AthenaExamples/AthExHive/src/CondAlgY.h @@ -0,0 +1,41 @@ +/* + Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration +*/ + +#ifndef CONDALGS_CONDALGY_H +#define CONDALGS_CONDALGY_H 1 + +#include "AthenaBaseComps/AthAlgorithm.h" +#include "StoreGate/ReadHandle.h" +#include "StoreGate/WriteCondHandleKey.h" + +#include "AthExHive/CondDataObjY.h" +#include "AthExHive/IASCIICondDbSvc.h" + +#include "EventInfo/EventInfo.h" +#include "GaudiKernel/ICondSvc.h" + +#include <string> + +class CondAlgY : public AthAlgorithm { + +public: + + CondAlgY (const std::string& name, ISvcLocator* pSvcLocator); + ~CondAlgY(); + + StatusCode initialize(); + StatusCode execute(); + StatusCode finalize(); + +private: + + SG::WriteCondHandleKey<CondDataObjY> m_wch1, m_wch2; + std::string m_dbk1, m_dbk2; + + ServiceHandle<ICondSvc> m_cs; + ServiceHandle<IASCIICondDbSvc> m_cds; + +}; + +#endif diff --git a/Control/AthenaExamples/AthExHive/src/HiveAlgA.cxx b/Control/AthenaExamples/AthExHive/src/HiveAlgA.cxx new file mode 100644 index 0000000000000000000000000000000000000000..2b6c18ecb8dc4c914fbb9510ee862b9ecd4b046e --- /dev/null +++ b/Control/AthenaExamples/AthExHive/src/HiveAlgA.cxx @@ -0,0 +1,81 @@ +/* + Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration +*/ + +#include "HiveAlgA.h" +#include "CxxUtils/make_unique.h" +#include "GaudiKernel/ServiceHandle.h" +#include "EventInfo/EventInfo.h" +#include "EventInfo/EventID.h" + +#include <thread> +#include <chrono> +#include <ctime> + +HiveAlgA::HiveAlgA( const std::string& name, + ISvcLocator* pSvcLocator ) : + ::HiveAlgBase( name, pSvcLocator ), + m_evt("McEventInfo"), + m_wrh1("a1"), + m_wrh2("a2") +{ + + declareProperty("Key_W1",m_wrh1); + declareProperty("Key_W2",m_wrh2); + declareProperty("EvtInfo", m_evt); + + m_i = 1; + +} + +HiveAlgA::~HiveAlgA() {} + +StatusCode HiveAlgA::initialize() { + ATH_MSG_DEBUG("initialize " << name()); + + ATH_CHECK( m_evt.initialize() ); + ATH_CHECK( m_wrh1.initialize() ); + ATH_CHECK( m_wrh2.initialize() ); + + return HiveAlgBase::initialize(); +} + +StatusCode HiveAlgA::finalize() { + ATH_MSG_DEBUG("finalize " << name()); + return StatusCode::SUCCESS; +} + +StatusCode HiveAlgA::execute() { + + ATH_MSG_DEBUG("execute " << name()); + + SG::ReadHandle<EventInfo> evt( m_evt ); + if (!evt.isValid()) { + ATH_MSG_ERROR ("Could not retrieve EventInfo"); + return StatusCode::FAILURE; + } else { + ATH_MSG_INFO(" EventInfo: r: " << evt->event_ID()->run_number() + << " e: " << evt->event_ID()->event_number() ); + } + + sleep(); + + SG::WriteHandle<HiveDataObj> wrh1( m_wrh1 ); + wrh1 = CxxUtils::make_unique< HiveDataObj > + ( HiveDataObj(10000 + evt->event_ID()->event_number()*100 + m_i) ); + + SG::WriteHandle<HiveDataObj> wrh2( m_wrh2 ); + wrh2 = CxxUtils::make_unique< HiveDataObj >( HiveDataObj(10050+m_i) ); + + ATH_MSG_INFO(" write: " << wrh1.key() << " = " << wrh1->val() ); + ATH_MSG_INFO(" write: " << wrh2.key() << " = " << wrh2->val() ); + + ATH_CHECK(wrh1.isValid()); + ATH_CHECK(wrh2.isValid()); + + m_i += 1; + + return StatusCode::SUCCESS; + +} + diff --git a/Control/AthenaExamples/AthExHive/src/HiveAlgA.h b/Control/AthenaExamples/AthExHive/src/HiveAlgA.h new file mode 100644 index 0000000000000000000000000000000000000000..5460cc27fa7c854d1652bab1a3606b86bf5fda79 --- /dev/null +++ b/Control/AthenaExamples/AthExHive/src/HiveAlgA.h @@ -0,0 +1,42 @@ +/* + Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration +*/ + +#ifndef ATHEXHIVE_ALGA_H +#define ATHEXHIVE_ALGA_H 1 + +#include "HiveAlgBase.h" +#include "StoreGate/ReadHandleKey.h" +#include "StoreGate/WriteHandleKey.h" +#include "AthExHive/HiveDataObj.h" + +#include "EventInfo/EventInfo.h" + +#include <string> + +class HiveAlgA : public HiveAlgBase { + +public: + + // Standard Algorithm Constructor: + + HiveAlgA (const std::string& name, ISvcLocator* pSvcLocator); + ~HiveAlgA (); + + // Define the initialize, execute and finalize methods: + + StatusCode initialize(); + StatusCode execute(); + StatusCode finalize(); + +private: + + SG::ReadHandleKey<EventInfo> m_evt; + + SG::WriteHandleKey<HiveDataObj> m_wrh1; + SG::WriteHandleKey<HiveDataObj> m_wrh2; + + std::atomic<int> m_i; + +}; +#endif diff --git a/Control/AthenaExamples/AthExHive/src/HiveAlgB.cxx b/Control/AthenaExamples/AthExHive/src/HiveAlgB.cxx new file mode 100644 index 0000000000000000000000000000000000000000..3e7e3599a95e048bcce257d22461353f97290f1f --- /dev/null +++ b/Control/AthenaExamples/AthExHive/src/HiveAlgB.cxx @@ -0,0 +1,86 @@ +/* + Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration +*/ + +#include "HiveAlgB.h" +#include "CxxUtils/make_unique.h" +#include <thread> +#include <chrono> + +HiveAlgB::HiveAlgB( const std::string& name, + ISvcLocator* pSvcLocator ) : + HiveAlgBase( name, pSvcLocator ), + m_wrh1("b1"), + m_di(0) +{ + + declareProperty("Key_W1",m_wrh1); + +} + +HiveAlgB::~HiveAlgB() {} + +StatusCode HiveAlgB::initialize() { + ATH_MSG_DEBUG("initialize " << name()); + + ATH_MSG_INFO("context: " << Gaudi::Hive::currentContext() << " for " + << this ); + + ATH_MSG_INFO(" m_di was: " << m_di << " setting to -1 "); + m_di = -1; + + dump(); + + + ATH_CHECK( m_wrh1.initialize() ); + + return HiveAlgBase::initialize(); + +} + +StatusCode HiveAlgB::finalize() { + ATH_MSG_INFO("context: " << Gaudi::Hive::currentContext()); + ATH_MSG_DEBUG("finalize " << name()); + + MsgStream log(msgSvc(),name()); + + dump(); + + return StatusCode::SUCCESS; +} + +StatusCode HiveAlgB::execute() { + + ATH_MSG_DEBUG("execute " << name()); + + ATH_MSG_INFO("context: " << Gaudi::Hive::currentContext() << " for " + << this); + + int s = sleep(); + + ATH_MSG_INFO("m_di was: " << m_di << " setting to " << s); + m_di = s; + + SG::WriteHandle<HiveDataObj> wrh1( m_wrh1 ); + wrh1 = CxxUtils::make_unique< HiveDataObj >( HiveDataObj(20000) ); + ATH_MSG_INFO(" write: " << wrh1.key() << " = " << wrh1->val() ); + + return StatusCode::SUCCESS; + +} + + +void +HiveAlgB::dump() { + + + std::ostringstream ost; + + m_di.for_all([this, &ost] (size_t s, const int i) + { ost << " s: " << s << " v: " << i << std::endl; } ); + + ATH_MSG_INFO("dumping m_di: \n" << ost.str()); + +} + + diff --git a/Control/AthenaExamples/AthExHive/src/HiveAlgB.h b/Control/AthenaExamples/AthExHive/src/HiveAlgB.h new file mode 100644 index 0000000000000000000000000000000000000000..83f5840bb2803e88170e860f5c50c36718eb5dc9 --- /dev/null +++ b/Control/AthenaExamples/AthExHive/src/HiveAlgB.h @@ -0,0 +1,41 @@ +/* + Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration +*/ + +#ifndef ATHEXHIVE_ALGB_H +#define ATHEXHIVE_ALGB_H 1 + +#include "HiveAlgBase.h" +#include "StoreGate/WriteHandleKey.h" +#include "AthExHive/HiveDataObj.h" +#include "GaudiKernel/ContextSpecificPtr.h" +#include "GaudiKernel/ServiceHandle.h" +#include "AthExHive/IHiveExSvc.h" + +#include <string> + +class HiveAlgB : public HiveAlgBase { + +public: + + // Standard Algorithm Constructor: + + HiveAlgB (const std::string& name, ISvcLocator* pSvcLocator); + ~HiveAlgB(); + + // Define the initialize, execute and finalize methods: + + StatusCode initialize(); + StatusCode execute(); + StatusCode finalize(); + +private: + + void dump(); + + SG::WriteHandleKey<HiveDataObj> m_wrh1; + + Gaudi::Hive::ContextSpecificData<int> m_di; + +}; +#endif diff --git a/Control/AthenaExamples/AthExHive/src/HiveAlgBase.cxx b/Control/AthenaExamples/AthExHive/src/HiveAlgBase.cxx new file mode 100644 index 0000000000000000000000000000000000000000..219c0c5c929f514c36e2e22ec4d7bdf9e72da54a --- /dev/null +++ b/Control/AthenaExamples/AthExHive/src/HiveAlgBase.cxx @@ -0,0 +1,63 @@ +/* + Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration +*/ + +#include "HiveAlgBase.h" + +#include "CxxUtils/make_unique.h" +#include <thread> +#include <chrono> + + + +HiveAlgBase::HiveAlgBase( const std::string& name, + ISvcLocator* pSvcLocator ) : + ::AthAlgorithm( name, pSvcLocator ), + m_hes("HiveExSvc",name) +{ + + declareProperty("Time",m_time=0); + +} + +HiveAlgBase::~HiveAlgBase() {} + +StatusCode HiveAlgBase::initialize() { + ATH_MSG_DEBUG("initialize " << name() << " for " << this ); + + + if (m_hes.retrieve().isFailure()) { + ATH_MSG_ERROR("unable to retrieve the HiveExSvc"); + return StatusCode::FAILURE; + } + + return StatusCode::SUCCESS; +} + +int +HiveAlgBase::sleep() { + + int sleep = igen( m_time ); + + ATH_MSG_INFO(" sleep for: " << sleep << " ms"); + std::this_thread::sleep_for(std::chrono::milliseconds( sleep )); + + m_hes->set( sleep ); + m_hes->add( name(),sleep ); + + return sleep; + +} + +int +HiveAlgBase::sleep_for(int s) { + + int sleep = igen( s ); + + ATH_MSG_INFO(" sleep for: " << sleep); + + m_hes->set( sleep ); + + return sleep; + +} diff --git a/Control/AthenaExamples/AthExHive/src/HiveAlgBase.h b/Control/AthenaExamples/AthExHive/src/HiveAlgBase.h new file mode 100644 index 0000000000000000000000000000000000000000..19e4b465b5745e39f567a3c4fd14e17818eca531 --- /dev/null +++ b/Control/AthenaExamples/AthExHive/src/HiveAlgBase.h @@ -0,0 +1,52 @@ +/* + Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration +*/ + +#ifndef ATHEXHIVE_BASEALG_H +#define ATHEXHIVE_BASEALG_H 1 + + +#include "AthenaBaseComps/AthAlgorithm.h" +#include "StoreGate/WriteHandle.h" +#include "AthExHive/HiveDataObj.h" +#include "GaudiKernel/ContextSpecificPtr.h" +#include "GaudiKernel/ServiceHandle.h" +#include "AthExHive/IHiveExSvc.h" +#include "rGen.h" + +#include <string> + +/* + + This is the HEADER file for the Algorithm SGWrite. + It illustrates how to write a data object into StoreGate + +*/ + +class HiveAlgBase : public AthAlgorithm, public rGen { + +public: + + HiveAlgBase (const std::string& name, ISvcLocator* pSvcLocator); + ~HiveAlgBase(); + + // Define the initialize, execute and finalize methods: + + StatusCode initialize(); + // StatusCode execute(); + // StatusCode finalize(); + +protected: + + int sleep_for(int); + int sleep(); + + ServiceHandle<IHiveExSvc> m_hes; + +private: + + int m_time; + + +}; +#endif diff --git a/Control/AthenaExamples/AthExHive/src/HiveAlgC.cxx b/Control/AthenaExamples/AthExHive/src/HiveAlgC.cxx new file mode 100644 index 0000000000000000000000000000000000000000..31052394a4f78a55814278f8fc4b466af5c1189b --- /dev/null +++ b/Control/AthenaExamples/AthExHive/src/HiveAlgC.cxx @@ -0,0 +1,68 @@ +/* + Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration +*/ + +#include "HiveAlgC.h" +#include "CxxUtils/make_unique.h" +#include "GaudiKernel/ServiceHandle.h" +#include <thread> +#include <chrono> + +HiveAlgC::HiveAlgC( const std::string& name, + ISvcLocator* pSvcLocator ) : + ::HiveAlgBase( name, pSvcLocator ), + m_rdh1("a1"), + m_wrh1("c1"), + m_wrh2("c2") +{ + + declareProperty("Key_R1",m_rdh1); + declareProperty("Key_W1",m_wrh1); + declareProperty("Key_W2",m_wrh2); + +} + +HiveAlgC::~HiveAlgC() {} + +StatusCode HiveAlgC::initialize() { + ATH_MSG_DEBUG("initialize " << name()); + + ATH_CHECK( m_rdh1.initialize() ); + ATH_CHECK( m_wrh1.initialize() ); + ATH_CHECK( m_wrh2.initialize() ); + + return HiveAlgBase::initialize(); +} + +StatusCode HiveAlgC::finalize() { + ATH_MSG_DEBUG("finalize " << name()); + return StatusCode::SUCCESS; +} + +StatusCode HiveAlgC::execute() { + + ATH_MSG_DEBUG("execute " << name()); + + sleep(); + + SG::ReadHandle<HiveDataObj> rdh1( m_rdh1 ); + if (!rdh1.isValid()) { + ATH_MSG_ERROR ("Could not retrieve HiveDataObj with key " << rdh1.key()); + return StatusCode::FAILURE; + } + + ATH_MSG_INFO(" read: " << rdh1.key() << " = " << rdh1->val() ); + + SG::WriteHandle<HiveDataObj> wrh1( m_wrh1 ); + wrh1 = CxxUtils::make_unique< HiveDataObj >( HiveDataObj(30000) ); + + SG::WriteHandle<HiveDataObj> wrh2( m_wrh2 ); + wrh2 = CxxUtils::make_unique< HiveDataObj >( HiveDataObj(30001) ); + + ATH_MSG_INFO(" write: " << wrh1.key() << " = " << wrh1->val() ); + ATH_MSG_INFO(" write: " << wrh2.key() << " = " << wrh2->val() ); + + return StatusCode::SUCCESS; + +} + diff --git a/Control/AthenaExamples/AthExHive/src/HiveAlgC.h b/Control/AthenaExamples/AthExHive/src/HiveAlgC.h new file mode 100644 index 0000000000000000000000000000000000000000..507e24d6760fbd2047ecaef3b85c3bfe98efd826 --- /dev/null +++ b/Control/AthenaExamples/AthExHive/src/HiveAlgC.h @@ -0,0 +1,38 @@ +/* + Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration +*/ + +#ifndef ATHEXHIVE_ALGC_H +#define ATHEXHIVE_ALGC_H 1 + +#include "HiveAlgBase.h" +#include "StoreGate/WriteHandleKey.h" +#include "StoreGate/ReadHandleKey.h" +#include "AthExHive/HiveDataObj.h" +#include "HiveAlgBase.h" + +#include <string> + +class HiveAlgC : public HiveAlgBase { + +public: + + // Standard Algorithm Constructor: + + HiveAlgC (const std::string& name, ISvcLocator* pSvcLocator); + ~HiveAlgC(); + + // Define the initialize, execute and finalize methods: + + StatusCode initialize(); + StatusCode execute(); + StatusCode finalize(); + +private: + + SG::ReadHandleKey<HiveDataObj> m_rdh1; + SG::WriteHandleKey<HiveDataObj> m_wrh1; + SG::WriteHandleKey<HiveDataObj> m_wrh2; + +}; +#endif diff --git a/Control/AthenaExamples/AthExHive/src/HiveAlgD.cxx b/Control/AthenaExamples/AthExHive/src/HiveAlgD.cxx new file mode 100644 index 0000000000000000000000000000000000000000..2915dc65396f492701aa5658ec878429cef5fb1a --- /dev/null +++ b/Control/AthenaExamples/AthExHive/src/HiveAlgD.cxx @@ -0,0 +1,59 @@ +/* + Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration +*/ + +#include "HiveAlgD.h" +#include "CxxUtils/make_unique.h" +#include <thread> +#include <chrono> + +HiveAlgD::HiveAlgD( const std::string& name, + ISvcLocator* pSvcLocator ) : + ::HiveAlgBase( name, pSvcLocator ), + m_rdh1("a2"), + m_wrh1("d1") +{ + + declareProperty("Key_R1",m_rdh1); + declareProperty("Key_W1",m_wrh1); + +} + +HiveAlgD::~HiveAlgD() {} + +StatusCode HiveAlgD::initialize() { + ATH_MSG_DEBUG("initialize " << name()); + + ATH_CHECK( m_rdh1.initialize() ); + ATH_CHECK( m_wrh1.initialize() ); + + return HiveAlgBase::initialize(); +} + +StatusCode HiveAlgD::finalize() { + ATH_MSG_DEBUG("finalize " << name()); + return StatusCode::SUCCESS; +} + +StatusCode HiveAlgD::execute() { + + ATH_MSG_DEBUG("execute " << name()); + + sleep(); + + SG::ReadHandle<HiveDataObj> rdh1( m_rdh1 ); + if (!rdh1.isValid()) { + ATH_MSG_ERROR ("Could not retrieve HiveDataObj with key " << rdh1.key()); + return StatusCode::FAILURE; + } + + ATH_MSG_INFO(" read: " << rdh1.key() << " = " << rdh1->val() ); + + SG::WriteHandle<HiveDataObj> wrh1( m_wrh1 ); + wrh1 = CxxUtils::make_unique< HiveDataObj >( HiveDataObj(40000) ); + ATH_MSG_INFO(" write: " << wrh1.key() << " = " << wrh1->val() ); + + return StatusCode::SUCCESS; + +} + diff --git a/Control/AthenaExamples/AthExHive/src/HiveAlgD.h b/Control/AthenaExamples/AthExHive/src/HiveAlgD.h new file mode 100644 index 0000000000000000000000000000000000000000..ce7dc72ad95c5ff82b55d67c23f9da286b194f88 --- /dev/null +++ b/Control/AthenaExamples/AthExHive/src/HiveAlgD.h @@ -0,0 +1,38 @@ +/* + Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration +*/ + +#ifndef ATHEXHIVE_ALGD_H +#define ATHEXHIVE_ALGD_H 1 + +#include "HiveAlgBase.h" +#include "StoreGate/WriteHandleKey.h" +#include "StoreGate/ReadHandleKey.h" +#include "AthExHive/HiveDataObj.h" + +#include <string> + +class HiveAlgD : public HiveAlgBase { + +public: + + // Standard Algorithm Constructor: + + HiveAlgD (const std::string& name, ISvcLocator* pSvcLocator); + ~HiveAlgD(); + + // Define the initialize, execute and finalize methods: + + StatusCode initialize(); + StatusCode execute(); + StatusCode finalize(); + +private: + + SG::ReadHandleKey<HiveDataObj> m_rdh1; + SG::WriteHandleKey<HiveDataObj> m_wrh1; + + + +}; +#endif diff --git a/Control/AthenaExamples/AthExHive/src/HiveAlgE.cxx b/Control/AthenaExamples/AthExHive/src/HiveAlgE.cxx new file mode 100644 index 0000000000000000000000000000000000000000..3f17ca2508ab3d785b38f8e96061425a48517b0b --- /dev/null +++ b/Control/AthenaExamples/AthExHive/src/HiveAlgE.cxx @@ -0,0 +1,71 @@ +/* + Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration +*/ + +#include "HiveAlgE.h" +#include "CxxUtils/make_unique.h" +#include <thread> +#include <chrono> + +HiveAlgE::HiveAlgE( const std::string& name, + ISvcLocator* pSvcLocator ) : + ::HiveAlgBase( name, pSvcLocator ), + m_rdh1("c1"), + m_rdh2("b1"), + m_wrh1("e1") +{ + + declareProperty("Key_R1",m_rdh1); + declareProperty("Key_R2",m_rdh2); + declareProperty("Key_W1",m_wrh1); + +} + +HiveAlgE::~HiveAlgE() {} + +StatusCode HiveAlgE::initialize() { + ATH_MSG_DEBUG("initialize " << name()); + + ATH_CHECK( m_rdh1.initialize() ); + ATH_CHECK( m_rdh2.initialize() ); + ATH_CHECK( m_wrh1.initialize() ); + + return HiveAlgBase::initialize(); +} + +StatusCode HiveAlgE::finalize() { + ATH_MSG_DEBUG("finalize " << name()); + return StatusCode::SUCCESS; +} + +StatusCode HiveAlgE::execute() { + + ATH_MSG_DEBUG("execute " << name()); + + sleep(); + + SG::ReadHandle<HiveDataObj> rdh1( m_rdh1 ); + if (!rdh1.isValid()) { + ATH_MSG_ERROR ("Could not retrieve HiveDataObj with key " << rdh1.key()); + return StatusCode::FAILURE; + } + + SG::ReadHandle<HiveDataObj> rdh2( m_rdh2 ); + if (!rdh2.isValid()) { + ATH_MSG_ERROR ("Could not retrieve HiveDataObj with key " << rdh2.key()); + return StatusCode::FAILURE; + } + + ATH_MSG_INFO(" read: " << rdh1.key() << " = " << rdh1->val() ); + ATH_MSG_INFO(" read: " << rdh2.key() << " = " << rdh2->val() ); + + SG::WriteHandle<HiveDataObj> wrh1( m_wrh1 ); + wrh1 = CxxUtils::make_unique< HiveDataObj >( HiveDataObj(50000) ); + + ATH_MSG_INFO(" write: " << wrh1.key() << " = " << wrh1->val() ); + + + return StatusCode::SUCCESS; + +} + diff --git a/Control/AthenaExamples/AthExHive/src/HiveAlgE.h b/Control/AthenaExamples/AthExHive/src/HiveAlgE.h new file mode 100644 index 0000000000000000000000000000000000000000..11ebb2422632dae55f587d24c25131136bd8736c --- /dev/null +++ b/Control/AthenaExamples/AthExHive/src/HiveAlgE.h @@ -0,0 +1,40 @@ +/* + Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration +*/ + +#ifndef ATHEXHIVE_ALGE_H +#define ATHEXHIVE_ALGE_H 1 + +#include "HiveAlgBase.h" +#include "StoreGate/WriteHandleKey.h" +#include "StoreGate/ReadHandleKey.h" +#include "AthExHive/HiveDataObj.h" +#include "rGen.h" + +#include <string> + +class HiveAlgE : public HiveAlgBase { + +public: + + // Standard Algorithm Constructor: + + HiveAlgE (const std::string& name, ISvcLocator* pSvcLocator); + ~HiveAlgE(); + + // Define the initialize, execute and finalize methods: + + StatusCode initialize(); + StatusCode execute(); + StatusCode finalize(); + +private: + + SG::ReadHandleKey<HiveDataObj> m_rdh1; + SG::ReadHandleKey<HiveDataObj> m_rdh2; + SG::WriteHandleKey<HiveDataObj> m_wrh1; + + + +}; +#endif diff --git a/Control/AthenaExamples/AthExHive/src/HiveAlgF.cxx b/Control/AthenaExamples/AthExHive/src/HiveAlgF.cxx new file mode 100644 index 0000000000000000000000000000000000000000..99ed9aac3a79d0cb40ed62303a7577bd1ff58e9e --- /dev/null +++ b/Control/AthenaExamples/AthExHive/src/HiveAlgF.cxx @@ -0,0 +1,72 @@ +/* + Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration +*/ + +#include "HiveAlgF.h" +#include "CxxUtils/make_unique.h" +#include <thread> +#include <chrono> + +HiveAlgF::HiveAlgF( const std::string& name, + ISvcLocator* pSvcLocator ) : + ::HiveAlgBase( name, pSvcLocator ), + m_rdh1("c2"), + m_rdh2("e1"), + m_rdh3("d1") +{ + + declareProperty("Key_R1",m_rdh1); + declareProperty("Key_R2",m_rdh2); + declareProperty("Key_R3",m_rdh3); + +} + +HiveAlgF::~HiveAlgF() {} + +StatusCode HiveAlgF::initialize() { + ATH_MSG_DEBUG("initialize " << name()); + + ATH_CHECK( m_rdh1.initialize() ); + ATH_CHECK( m_rdh2.initialize() ); + ATH_CHECK( m_rdh3.initialize() ); + + return HiveAlgBase::initialize (); +} + +StatusCode HiveAlgF::finalize() { + ATH_MSG_DEBUG("finalize " << name()); + return StatusCode::SUCCESS; +} + +StatusCode HiveAlgF::execute() { + + ATH_MSG_DEBUG("execute " << name()); + + sleep(); + + SG::ReadHandle<HiveDataObj> rdh1( m_rdh1 ); + if (!rdh1.isValid()) { + ATH_MSG_ERROR ("Could not retrieve HiveDataObj with key " << rdh1.key()); + return StatusCode::FAILURE; + } + + SG::ReadHandle<HiveDataObj> rdh2( m_rdh2 ); + if (!rdh2.isValid()) { + ATH_MSG_ERROR ("Could not retrieve HiveDataObj with key " << rdh2.key()); + return StatusCode::FAILURE; + } + + SG::ReadHandle<HiveDataObj> rdh3( m_rdh3 ); + if (!rdh3.isValid()) { + ATH_MSG_ERROR ("Could not retrieve HiveDataObj with key " << rdh3.key()); + return StatusCode::FAILURE; + } + + ATH_MSG_INFO(" read: " << rdh1.key() << " = " << rdh1->val() ); + ATH_MSG_INFO(" read: " << rdh2.key() << " = " << rdh2->val() ); + ATH_MSG_INFO(" read: " << rdh3.key() << " = " << rdh3->val() ); + + return StatusCode::SUCCESS; + +} + diff --git a/Control/AthenaExamples/AthExHive/src/HiveAlgF.h b/Control/AthenaExamples/AthExHive/src/HiveAlgF.h new file mode 100644 index 0000000000000000000000000000000000000000..c53554415dbae58bc9e51504ebdc7a78d419aa72 --- /dev/null +++ b/Control/AthenaExamples/AthExHive/src/HiveAlgF.h @@ -0,0 +1,39 @@ +/* + Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration +*/ + +#ifndef ATHEXHIVE_ALGF_H +#define ATHEXHIVE_ALGF_H 1 + +#include "HiveAlgBase.h" +#include "StoreGate/ReadHandleKey.h" +#include "AthExHive/HiveDataObj.h" +#include "rGen.h" + +#include <string> + +class HiveAlgF : public HiveAlgBase { + +public: + + // Standard Algorithm Constructor: + + HiveAlgF (const std::string& name, ISvcLocator* pSvcLocator); + ~HiveAlgF(); + + // Define the initialize, execute and finalize methods: + + StatusCode initialize(); + StatusCode execute(); + StatusCode finalize(); + +private: + + SG::ReadHandleKey<HiveDataObj> m_rdh1; + SG::ReadHandleKey<HiveDataObj> m_rdh2; + SG::ReadHandleKey<HiveDataObj> m_rdh3; + + + +}; +#endif diff --git a/Control/AthenaExamples/AthExHive/src/HiveAlgG.cxx b/Control/AthenaExamples/AthExHive/src/HiveAlgG.cxx new file mode 100644 index 0000000000000000000000000000000000000000..975b9b67bb21b6770abc70849e2e184224dd0097 --- /dev/null +++ b/Control/AthenaExamples/AthExHive/src/HiveAlgG.cxx @@ -0,0 +1,59 @@ +/* + Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration +*/ + +#include "HiveAlgG.h" +#include "CxxUtils/make_unique.h" +#include <thread> +#include <chrono> + +HiveAlgG::HiveAlgG( const std::string& name, + ISvcLocator* pSvcLocator ) : + ::HiveAlgBase( name, pSvcLocator ), + m_rdh1("d1"), + m_wrh1("g1") +{ + + declareProperty("Key_R1",m_rdh1); + declareProperty("Key_W1",m_wrh1); + +} + +HiveAlgG::~HiveAlgG() {} + +StatusCode HiveAlgG::initialize() { + ATH_MSG_DEBUG("initialize " << name()); + + ATH_CHECK( m_rdh1.initialize() ); + ATH_CHECK( m_wrh1.initialize() ); + + return HiveAlgBase::initialize(); +} + +StatusCode HiveAlgG::finalize() { + ATH_MSG_DEBUG("finalize " << name()); + return StatusCode::SUCCESS; +} + +StatusCode HiveAlgG::execute() { + + ATH_MSG_DEBUG("execute " << name()); + + sleep(); + + SG::ReadHandle<HiveDataObj> rdh1( m_rdh1 ); + if (!rdh1.isValid()) { + ATH_MSG_ERROR ("Could not retrieve HiveDataObj with key " << rdh1.key()); + return StatusCode::FAILURE; + } + + ATH_MSG_INFO(" read: " << rdh1.key() << " = " << rdh1->val() ); + + SG::WriteHandle<HiveDataObj> wrh1( m_wrh1 ); + wrh1 = CxxUtils::make_unique< HiveDataObj >( HiveDataObj(70000) ); + ATH_MSG_INFO(" write: " << wrh1.key() << " = " << wrh1->val() ); + + return StatusCode::SUCCESS; + +} + diff --git a/Control/AthenaExamples/AthExHive/src/HiveAlgG.h b/Control/AthenaExamples/AthExHive/src/HiveAlgG.h new file mode 100644 index 0000000000000000000000000000000000000000..3c57a1c0674dba1cda9719c01307289ab5629e94 --- /dev/null +++ b/Control/AthenaExamples/AthExHive/src/HiveAlgG.h @@ -0,0 +1,39 @@ +/* + Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration +*/ + +#ifndef ATHEXHIVE_ALGG_H +#define ATHEXHIVE_ALGG_H 1 + +#include "HiveAlgBase.h" +#include "StoreGate/WriteHandleKey.h" +#include "StoreGate/ReadHandleKey.h" +#include "AthExHive/HiveDataObj.h" +#include "rGen.h" + +#include <string> + +class HiveAlgG : public HiveAlgBase { + +public: + + // Standard Algorithm Constructor: + + HiveAlgG (const std::string& name, ISvcLocator* pSvcLocator); + ~HiveAlgG(); + + // Define the initialize, execute and finalize methods: + + StatusCode initialize(); + StatusCode execute(); + StatusCode finalize(); + +private: + + SG::ReadHandleKey<HiveDataObj> m_rdh1; + SG::WriteHandleKey<HiveDataObj> m_wrh1; + + + +}; +#endif diff --git a/Control/AthenaExamples/AthExHive/src/HiveAlgL1.cxx b/Control/AthenaExamples/AthExHive/src/HiveAlgL1.cxx new file mode 100644 index 0000000000000000000000000000000000000000..9030d8e8a06180f72d96afa72d8108ec1466179b --- /dev/null +++ b/Control/AthenaExamples/AthExHive/src/HiveAlgL1.cxx @@ -0,0 +1,65 @@ +/* + Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration +*/ + +#include "HiveAlgL1.h" +#include "CxxUtils/make_unique.h" +#include "GaudiKernel/ServiceHandle.h" +#include <thread> +#include <chrono> + +HiveAlgL1::HiveAlgL1( const std::string& name, + ISvcLocator* pSvcLocator ) : + ::HiveAlgBase( name, pSvcLocator ), + m_rdh1("a2"), + m_wrh1("l1") +{ + + declareProperty("Key_R1",m_rdh1); + declareProperty("Key_W1",m_wrh1); + +} + +HiveAlgL1::~HiveAlgL1() {} + +StatusCode HiveAlgL1::initialize() { + ATH_MSG_DEBUG("initialize " << name()); + + // setProperties(); + + // ATH_MSG_INFO("time: " << sleep() ); + + ATH_CHECK( m_rdh1.initialize() ); + ATH_CHECK( m_wrh1.initialize() ); + + return HiveAlgBase::initialize(); +} + +StatusCode HiveAlgL1::finalize() { + ATH_MSG_DEBUG("finalize " << name()); + return StatusCode::SUCCESS; +} + +StatusCode HiveAlgL1::execute() { + + ATH_MSG_DEBUG("execute " << name()); + + sleep(); + + SG::ReadHandle<HiveDataObj> rdh1( m_rdh1 ); + if (!rdh1.isValid()) { + ATH_MSG_ERROR ("Could not retrieve HiveDataObj with key " << rdh1.key()); + return StatusCode::FAILURE; + } + + ATH_MSG_INFO(" read: " << rdh1.key() << " = " << rdh1->val() ); + + SG::WriteHandle<HiveDataObj> wrh1( m_wrh1 ); + wrh1 = CxxUtils::make_unique< HiveDataObj >( HiveDataObj(rdh1->val()+1) ); + + ATH_MSG_INFO(" write: " << wrh1.key() << " = " << wrh1->val() ); + + return StatusCode::SUCCESS; + +} + diff --git a/Control/AthenaExamples/AthExHive/src/HiveAlgL1.h b/Control/AthenaExamples/AthExHive/src/HiveAlgL1.h new file mode 100644 index 0000000000000000000000000000000000000000..0d00b95baee7a444065b05a2f66bf85f0542c3ac --- /dev/null +++ b/Control/AthenaExamples/AthExHive/src/HiveAlgL1.h @@ -0,0 +1,37 @@ +/* + Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration +*/ + +#ifndef ATHEXHIVE_ALGL1_H +#define ATHEXHIVE_ALGL1_H 1 + +#include "HiveAlgBase.h" +#include "StoreGate/WriteHandleKey.h" +#include "StoreGate/ReadHandleKey.h" +#include "AthExHive/HiveDataObj.h" +#include "HiveAlgBase.h" + +#include <string> + +class HiveAlgL1 : public HiveAlgBase { + +public: + + // Standard Algorithm Constructor: + + HiveAlgL1 (const std::string& name, ISvcLocator* pSvcLocator); + ~HiveAlgL1(); + + // Define the initialize, execute and finalize methods: + + StatusCode initialize(); + StatusCode execute(); + StatusCode finalize(); + +private: + + SG::ReadHandleKey<HiveDataObj> m_rdh1; + SG::WriteHandleKey<HiveDataObj> m_wrh1; + +}; +#endif diff --git a/Control/AthenaExamples/AthExHive/src/HiveAlgL2.cxx b/Control/AthenaExamples/AthExHive/src/HiveAlgL2.cxx new file mode 100644 index 0000000000000000000000000000000000000000..c91e073c496cc232489f818ec0e4976f9a143ac0 --- /dev/null +++ b/Control/AthenaExamples/AthExHive/src/HiveAlgL2.cxx @@ -0,0 +1,64 @@ +/* + Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration +*/ + +#include "HiveAlgL2.h" +#include "CxxUtils/make_unique.h" +#include "GaudiKernel/ServiceHandle.h" +#include <thread> +#include <chrono> + +HiveAlgL2::HiveAlgL2( const std::string& name, + ISvcLocator* pSvcLocator ) : + ::HiveAlgBase( name, pSvcLocator ), + m_rdh1("l1"), + m_udh1("l1") +{ + + declareProperty("Key_R1",m_rdh1); + declareProperty("Key_U1",m_udh1); + +} + +HiveAlgL2::~HiveAlgL2() {} + +StatusCode HiveAlgL2::initialize() { + ATH_MSG_DEBUG("initialize " << name()); + + ATH_CHECK( m_rdh1.initialize() ); + ATH_CHECK( m_udh1.initialize() ); + + return HiveAlgBase::initialize(); +} + +StatusCode HiveAlgL2::finalize() { + ATH_MSG_DEBUG("finalize " << name()); + return StatusCode::SUCCESS; +} + +StatusCode HiveAlgL2::execute() { + + ATH_MSG_DEBUG("execute " << name()); + + sleep(); + + SG::ReadHandle<HiveDataObj> rdh1( m_rdh1 ); + if (!rdh1.isValid()) { + ATH_MSG_ERROR ("Could not retrieve HiveDataObj with key " << rdh1.key()); + return StatusCode::FAILURE; + } + + ATH_MSG_INFO(" read: " << rdh1.key() << " = " << rdh1->val() ); + + SG::UpdateHandle<HiveDataObj> udh1( m_udh1 ); + + udh1->val( udh1->val() + 1); + + // wrh1 = CxxUtils::make_unique< HiveDataObj >( HiveDataObj(rdh1->val()+1) ); + + ATH_MSG_INFO(" update: " << udh1.key() << " = " << udh1->val() ); + + return StatusCode::SUCCESS; + +} + diff --git a/Control/AthenaExamples/AthExHive/src/HiveAlgL2.h b/Control/AthenaExamples/AthExHive/src/HiveAlgL2.h new file mode 100644 index 0000000000000000000000000000000000000000..b0d51bb7088455027158aea4335a6c4b14b796f6 --- /dev/null +++ b/Control/AthenaExamples/AthExHive/src/HiveAlgL2.h @@ -0,0 +1,38 @@ +/* + Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration +*/ + +#ifndef ATHEXHIVE_ALGL2_H +#define ATHEXHIVE_ALGL2_H 1 + +#include "HiveAlgBase.h" +#include "StoreGate/WriteHandleKey.h" +#include "StoreGate/ReadHandleKey.h" +#include "StoreGate/UpdateHandleKey.h" +#include "AthExHive/HiveDataObj.h" +#include "HiveAlgBase.h" + +#include <string> + +class HiveAlgL2 : public HiveAlgBase { + +public: + + // Standard Algorithm Constructor: + + HiveAlgL2 (const std::string& name, ISvcLocator* pSvcLocator); + ~HiveAlgL2(); + + // Define the initialize, execute and finalize methods: + + StatusCode initialize(); + StatusCode execute(); + StatusCode finalize(); + +private: + + SG::ReadHandleKey<HiveDataObj> m_rdh1; + SG::UpdateHandleKey<HiveDataObj> m_udh1; + +}; +#endif diff --git a/Control/AthenaExamples/AthExHive/src/HiveAlgL3.cxx b/Control/AthenaExamples/AthExHive/src/HiveAlgL3.cxx new file mode 100644 index 0000000000000000000000000000000000000000..f84005f40fda9912ec22a884292fe5a946aa4774 --- /dev/null +++ b/Control/AthenaExamples/AthExHive/src/HiveAlgL3.cxx @@ -0,0 +1,51 @@ +/* + Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration +*/ + +#include "HiveAlgL3.h" +#include "CxxUtils/make_unique.h" +#include "GaudiKernel/ServiceHandle.h" +#include <thread> +#include <chrono> + +HiveAlgL3::HiveAlgL3( const std::string& name, + ISvcLocator* pSvcLocator ) : + ::HiveAlgBase( name, pSvcLocator ), + m_udh1("l1") +{ + + declareProperty("Key_U1",m_udh1); + +} + +HiveAlgL3::~HiveAlgL3() {} + +StatusCode HiveAlgL3::initialize() { + ATH_MSG_DEBUG("initialize " << name()); + + ATH_CHECK( m_udh1.initialize() ); + + return HiveAlgBase::initialize(); +} + +StatusCode HiveAlgL3::finalize() { + ATH_MSG_DEBUG("finalize " << name()); + return StatusCode::SUCCESS; +} + +StatusCode HiveAlgL3::execute() { + + ATH_MSG_DEBUG("execute " << name()); + + sleep(); + + SG::UpdateHandle<HiveDataObj> udh1( m_udh1 ); + + udh1->val( udh1->val() + 1); + + ATH_MSG_INFO(" update: " << udh1.key() << " = " << udh1->val() ); + + return StatusCode::SUCCESS; + +} + diff --git a/Control/AthenaExamples/AthExHive/src/HiveAlgL3.h b/Control/AthenaExamples/AthExHive/src/HiveAlgL3.h new file mode 100644 index 0000000000000000000000000000000000000000..40cc8b13498588a7ab6186e1f12b022f9db1d600 --- /dev/null +++ b/Control/AthenaExamples/AthExHive/src/HiveAlgL3.h @@ -0,0 +1,37 @@ +/* + Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration +*/ + +#ifndef ATHEXHIVE_ALGL3_H +#define ATHEXHIVE_ALGL3_H 1 + +#include "HiveAlgBase.h" +#include "StoreGate/WriteHandleKey.h" +#include "StoreGate/ReadHandleKey.h" +#include "StoreGate/UpdateHandleKey.h" +#include "AthExHive/HiveDataObj.h" +#include "HiveAlgBase.h" + +#include <string> + +class HiveAlgL3 : public HiveAlgBase { + +public: + + // Standard Algorithm Constructor: + + HiveAlgL3 (const std::string& name, ISvcLocator* pSvcLocator); + ~HiveAlgL3(); + + // Define the initialize, execute and finalize methods: + + StatusCode initialize(); + StatusCode execute(); + StatusCode finalize(); + +private: + + SG::UpdateHandleKey<HiveDataObj> m_udh1; + +}; +#endif diff --git a/Control/AthenaExamples/AthExHive/src/HiveAlgM.cxx b/Control/AthenaExamples/AthExHive/src/HiveAlgM.cxx new file mode 100644 index 0000000000000000000000000000000000000000..2a08c2056af26b6f6696f8fd006162291d185e11 --- /dev/null +++ b/Control/AthenaExamples/AthExHive/src/HiveAlgM.cxx @@ -0,0 +1,69 @@ +/* + Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration +*/ + +#include "HiveAlgM.h" +#include "CxxUtils/make_unique.h" +#include <thread> +#include <chrono> + +HiveAlgM::HiveAlgM( const std::string& name, + ISvcLocator* pSvcLocator ) : + ::HiveAlgBase( name, pSvcLocator ), + m_rdh1("a2"), + m_rdh2("l1") +{ + + declareProperty("Key_R1",m_rdh1); + declareProperty("Key_R2",m_rdh2); + declareProperty("Offset",m_off); + +} + +HiveAlgM::~HiveAlgM() {} + +StatusCode HiveAlgM::initialize() { + ATH_MSG_DEBUG("initialize " << name()); + + ATH_CHECK( m_rdh1.initialize() ); + ATH_CHECK( m_rdh2.initialize() ); + + return HiveAlgBase::initialize (); +} + +StatusCode HiveAlgM::finalize() { + ATH_MSG_DEBUG("finalize " << name()); + return StatusCode::SUCCESS; +} + +StatusCode HiveAlgM::execute() { + + ATH_MSG_DEBUG("execute " << name()); + + sleep(); + + SG::ReadHandle<HiveDataObj> rdh1( m_rdh1 ); + if (!rdh1.isValid()) { + ATH_MSG_ERROR ("Could not retrieve HiveDataObj with key " << rdh1.key()); + return StatusCode::FAILURE; + } + + SG::ReadHandle<HiveDataObj> rdh2( m_rdh2 ); + if (!rdh2.isValid()) { + ATH_MSG_ERROR ("Could not retrieve HiveDataObj with key " << rdh2.key()); + return StatusCode::FAILURE; + } + + ATH_MSG_INFO(" read: " << rdh1.key() << " = " << rdh1->val() ); + ATH_MSG_INFO(" read: " << rdh2.key() << " = " << rdh2->val() ); + + if ( rdh2->val() != (rdh1->val() + m_off) ) { + ATH_MSG_ERROR (rdh2.key() << " != " << rdh1.key() << " + " << m_off); + } else { + ATH_MSG_INFO( "loop is ok"); + } + + return StatusCode::SUCCESS; + +} + diff --git a/Control/AthenaExamples/AthExHive/src/HiveAlgM.h b/Control/AthenaExamples/AthExHive/src/HiveAlgM.h new file mode 100644 index 0000000000000000000000000000000000000000..969de54f3c51fbbefbfd156cd8a2bdf591ee6283 --- /dev/null +++ b/Control/AthenaExamples/AthExHive/src/HiveAlgM.h @@ -0,0 +1,37 @@ +/* + Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration +*/ + +#ifndef ATHEXHIVE_ALGM_H +#define ATHEXHIVE_ALGM_H 1 + +#include "HiveAlgBase.h" +#include "StoreGate/ReadHandleKey.h" +#include "AthExHive/HiveDataObj.h" +#include "rGen.h" + +#include <string> + +class HiveAlgM : public HiveAlgBase { + +public: + + // Standard Algorithm Constructor: + + HiveAlgM (const std::string& name, ISvcLocator* pSvcLocator); + ~HiveAlgM(); + + // Define the initialize, execute and finalize methods: + + StatusCode initialize(); + StatusCode execute(); + StatusCode finalize(); + +private: + + int m_off { 1 }; + SG::ReadHandleKey<HiveDataObj> m_rdh1; + SG::ReadHandleKey<HiveDataObj> m_rdh2; + +}; +#endif diff --git a/Control/AthenaExamples/AthExHive/src/HiveAlgR.cxx b/Control/AthenaExamples/AthExHive/src/HiveAlgR.cxx new file mode 100644 index 0000000000000000000000000000000000000000..2d58a3a24012a0c3f1ee6e303c8951a0bffb8a4a --- /dev/null +++ b/Control/AthenaExamples/AthExHive/src/HiveAlgR.cxx @@ -0,0 +1,69 @@ +/* + Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration +*/ + +#ifdef REENTRANT_GAUDI + +#include "HiveAlgR.h" +#include "CxxUtils/make_unique.h" +#include "GaudiKernel/ServiceHandle.h" +#include "EventInfo/EventInfo.h" +#include "EventInfo/EventID.h" + +#include <thread> +#include <chrono> +#include <ctime> + +DECLARE_COMPONENT(HiveAlgR) + +HiveAlgR::HiveAlgR( const std::string& name, + ISvcLocator* pSvcLocator ) : + ::AthReentrantAlgorithm( name, pSvcLocator ) + ,m_evt("McEventInfo") + ,m_wrh1("ar1") +{ + + declareProperty("Key_W1",m_wrh1); + declareProperty("EvtInfo",m_evt); + +} + +HiveAlgR::~HiveAlgR() {} + +StatusCode HiveAlgR::initialize() { + + info() << "initialize: " << index() << endmsg; + + ATH_CHECK( m_wrh1.initialize() ); + ATH_CHECK( m_evt.initialize() ); + + return StatusCode::SUCCESS; +} + +StatusCode HiveAlgR::finalize() { + info() << "finalize: " << index() << endmsg; + return StatusCode::SUCCESS; +} + +StatusCode HiveAlgR::execute_r(const EventContext& ctx) const { + + info() << "execute_R: " << index() << " on " << ctx << endmsg; + + + SG::ReadHandle<EventInfo> evt(m_evt); + ATH_MSG_INFO(" EventInfo: r: " << evt->event_ID()->run_number() + << " e: " << evt->event_ID()->event_number() ); + + + SG::WriteHandle<HiveDataObj> wh1(m_wrh1); + ATH_CHECK( wh1.record( CxxUtils::make_unique<HiveDataObj> + ( HiveDataObj(10000 + + evt->event_ID()->event_number()*100 ))) + ); + ATH_MSG_INFO(" write: " << wh1.key() << " = " << wh1->val() ); + + return StatusCode::SUCCESS; + +} + +#endif // REENTRANT_GAUDI diff --git a/Control/AthenaExamples/AthExHive/src/HiveAlgR.h b/Control/AthenaExamples/AthExHive/src/HiveAlgR.h new file mode 100644 index 0000000000000000000000000000000000000000..ed8ffb873817db1bd91f9c68dba50899463488d3 --- /dev/null +++ b/Control/AthenaExamples/AthExHive/src/HiveAlgR.h @@ -0,0 +1,37 @@ +/* + Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration +*/ + +#ifndef ATHEXHIVE_HIVEALGR_H +#define ATHEXHIVE_HIVEALGR_H 1 + +#include "AthenaBaseComps/AthReentrantAlgorithm.h" + +#include "StoreGate/WriteHandleKey.h" +#include "StoreGate/ReadHandleKey.h" +#include "AthExHive/HiveDataObj.h" +#include "EventInfo/EventInfo.h" + +class HiveAlgR : public AthReentrantAlgorithm { + +public: + + // Standard Algorithm Constructor: + + HiveAlgR (const std::string& name, ISvcLocator* pSvcLocator); + ~HiveAlgR (); + + // Define the initialize, execute and finalize methods: + + StatusCode initialize(); + StatusCode execute_r(const EventContext&) const; + StatusCode finalize(); + +private: + + SG::ReadHandleKey<EventInfo> m_evt; + + SG::WriteHandleKey<HiveDataObj> m_wrh1; + +}; +#endif diff --git a/Control/AthenaExamples/AthExHive/src/HiveAlgV.cxx b/Control/AthenaExamples/AthExHive/src/HiveAlgV.cxx new file mode 100644 index 0000000000000000000000000000000000000000..30ec5a6251c4aadaaf556ac4f4c9c2f5db689b01 --- /dev/null +++ b/Control/AthenaExamples/AthExHive/src/HiveAlgV.cxx @@ -0,0 +1,83 @@ +/* + Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration +*/ + +#include "HiveAlgV.h" +#include "CxxUtils/make_unique.h" +#include <thread> +#include <chrono> +#include <vector> + +HiveAlgV::HiveAlgV( const std::string& name, + ISvcLocator* pSvcLocator ) : + ::HiveAlgBase( name, pSvcLocator ) +{ + + declareProperty("Key_RV",m_rhv); + declareProperty("Key_WV",m_whv); + declareProperty("WriteBeforeRead",m_writeFirst=true); + +} + +HiveAlgV::~HiveAlgV() {} + +StatusCode HiveAlgV::initialize() { + ATH_MSG_DEBUG("initialize " << name()); + + ATH_CHECK( m_rhv.initialize() ); + ATH_CHECK( m_whv.initialize() ); + + ATH_MSG_INFO("ReadHandleKeyArray of size " << m_rhv.size()); + ATH_MSG_INFO("WriteHandleKeyArray of size " << m_whv.size()); + + return HiveAlgBase::initialize (); +} + +StatusCode HiveAlgV::finalize() { + ATH_MSG_DEBUG("finalize " << name()); + return StatusCode::SUCCESS; +} + +StatusCode HiveAlgV::execute() { + + ATH_MSG_DEBUG("execute " << name()); + + sleep(); + + StatusCode sc { StatusCode::SUCCESS }; + + if (m_writeFirst) { + write(); + sc = read(); + } else { + sc = read(); + write(); + } + + return sc; +} + +StatusCode +HiveAlgV::read() const { + StatusCode sc { StatusCode::SUCCESS }; + std::vector< SG::ReadHandle<HiveDataObj> > rhv = m_rhv.makeHandles(); + for (auto &hnd : rhv) { + if (!hnd.isValid()) { + ATH_MSG_ERROR ("Could not retrieve HiveDataObj with key " << hnd.key()); + sc = StatusCode::FAILURE; + } else { + ATH_MSG_INFO(" read: " << hnd.key() << " = " << hnd->val() ); + } + } + return sc; +} + +void +HiveAlgV::write() { + std::vector< SG::WriteHandle<HiveDataObj> > whv = m_whv.makeHandles(); + for (auto &hnd : whv) { + hnd = CxxUtils::make_unique<HiveDataObj> ( HiveDataObj( 10101 ) ); + ATH_MSG_INFO(" write: " << hnd.key() << " = " << hnd->val() ); + } +} + diff --git a/Control/AthenaExamples/AthExHive/src/HiveAlgV.h b/Control/AthenaExamples/AthExHive/src/HiveAlgV.h new file mode 100644 index 0000000000000000000000000000000000000000..e8f7990b90494d6aea610ea7b024f59b71b4aa1f --- /dev/null +++ b/Control/AthenaExamples/AthExHive/src/HiveAlgV.h @@ -0,0 +1,42 @@ +/* + Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration +*/ + +#ifndef ATHEXHIVE_ALGF_V +#define ATHEXHIVE_ALGF_V 1 + +#include "HiveAlgBase.h" +#include "StoreGate/ReadHandleKeyArray.h" +#include "StoreGate/WriteHandleKeyArray.h" +#include "AthExHive/HiveDataObj.h" +#include "rGen.h" + +#include <string> + +class HiveAlgV : public HiveAlgBase { + +public: + + // Standard Algorithm Constructor: + + HiveAlgV (const std::string& name, ISvcLocator* pSvcLocator); + ~HiveAlgV(); + + // Define the initialize, execute and finalize methods: + + StatusCode initialize(); + StatusCode execute(); + StatusCode finalize(); + +private: + + bool m_writeFirst { true }; + + SG::ReadHandleKeyArray<HiveDataObj> m_rhv; + SG::WriteHandleKeyArray<HiveDataObj> m_whv; + + StatusCode read() const; + void write(); + +}; +#endif diff --git a/Control/AthenaExamples/AthExHive/src/HiveExSvc.cxx b/Control/AthenaExamples/AthExHive/src/HiveExSvc.cxx new file mode 100644 index 0000000000000000000000000000000000000000..8e58617ce6cb19ab5423d728daaa90a9539cce46 --- /dev/null +++ b/Control/AthenaExamples/AthExHive/src/HiveExSvc.cxx @@ -0,0 +1,128 @@ +/* + Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration +*/ + +#include "HiveExSvc.h" + + +#include "GaudiKernel/SvcFactory.h" +#include "GaudiKernel/ISvcLocator.h" +#include "GaudiKernel/IJobOptionsSvc.h" + + + +/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ +DECLARE_SERVICE_FACTORY(HiveExSvc) + + +thread_local int s_i(0); + + +HiveExSvc::HiveExSvc(const std::string& name, ISvcLocator* svc) + : base_class( name, svc ) + ,m_di(0) + + { + + +} + +/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ + +HiveExSvc::~HiveExSvc() { + +} + +StatusCode +HiveExSvc::initialize() { + ATH_MSG_INFO("initialize"); + + return StatusCode::SUCCESS; +} + +StatusCode +HiveExSvc::finalize() { + ATH_MSG_INFO("finalize"); + + MsgStream log(msgSvc(),name()); + log << MSG::INFO << "listing all contents of m_di" << std::endl; + + m_di.for_all( [&log] (size_t s, const int i) + { log << " s: " << s << " v: " << i << std::endl; } ); + + log << "listing all contents of m_ci" << std::endl; + + m_ci.for_all( [&log] (size_t s, const int *i) + { log << " s: " << s << " v: " << *i << std::endl; } ); + + + log << "listing all contents of m_dq" << std::endl; + + m_dq.for_all([&log](size_t s, const std::vector<sDat> v) { + log << " s: " << s; + int st(0); + for (auto e : v) { + st += e.time; + log << " " << e.name << ":" << e.nEvt << "/" << e.nSlot + << "|" << e.time; + } + // this is not a real sum of the time, because slot != thread + log << " total time: " << st << " ms\n"; + } + ); + + log << endmsg; + + + + return StatusCode::SUCCESS; +} + +void +HiveExSvc::add(const std::string& n, const int& t) { + + EventContext::ContextID_t s = Gaudi::Hive::currentContextId(); + EventContext::ContextEvt_t e = Gaudi::Hive::currentContextEvt(); + + + std::vector<sDat> &v = m_dq; + v.push_back( sDat(s,e,t,n) ); + + // ((std::vector<sDat>)m_dq).push_back( sDat(s,e,n) ); + + +} + +void +HiveExSvc::set(const int& i) { + + m_di = i; + + // this is not thread safe! + if (! m_ci) { + m_ci = new int(i); + } else { + *m_ci = i; + } + +} + +void +HiveExSvc::setTL(const int& i) { + + s_i = i; + +} + +int +HiveExSvc::get() const { + // return *m_ci; + return m_di; +} + +int +HiveExSvc::getTL() const { + return s_i; +} + + diff --git a/Control/AthenaExamples/AthExHive/src/HiveExSvc.h b/Control/AthenaExamples/AthExHive/src/HiveExSvc.h new file mode 100644 index 0000000000000000000000000000000000000000..a162ca93533dd47111702060c23eb5d7cd631632 --- /dev/null +++ b/Control/AthenaExamples/AthExHive/src/HiveExSvc.h @@ -0,0 +1,75 @@ +/* + Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration +*/ + +#ifndef HIVEEXSVC_H +#define HIVEEXSVC_H 1 + +#include "GaudiKernel/Service.h" +#include "GaudiKernel/ClassID.h" +#include "GaudiKernel/StatusCode.h" +#include "GaudiKernel/ContextSpecificPtr.h" + +#include "AthExHive/IHiveExSvc.h" +#include "AthenaBaseComps/AthService.h" +#include "GaudiKernel/EventContext.h" +#include <string> +#include <vector> + +class HiveExSvc : public extends1<AthService,IHiveExSvc> { + +public: + HiveExSvc(const std::string& name, ISvcLocator* svc); + virtual ~HiveExSvc(); + +public: + virtual StatusCode initialize(); + virtual StatusCode finalize(); + +public: + + int get() const; + void set(const int&); + + void add(const std::string&, const int&); + + int getTL() const; + void setTL(const int&); + + +private: + + class CSPLog { + public: + CSPLog(MsgStream &log): m_log(log){}; + void operator()(int *n) { m_log << " val: " << *n << std::endl; } + void operator()(Gaudi::Hive::ContextIdType i, int *n) { + m_log << "s: " << i << " val: " << *n << std::endl; } + + private: + MsgStream &m_log; + } ; + + + Gaudi::Hive::ContextSpecificPtr<int> m_ci; + Gaudi::Hive::ContextSpecificData<int> m_di; + + struct sDat { + sDat() : nSlot(EventContext::INVALID_CONTEXT_ID), + nEvt(EventContext::INVALID_CONTEXT_EVT), time(0), name(""){}; + sDat(EventContext::ContextID_t s, EventContext::ContextEvt_t e, + const int& t, const std::string& n): nSlot(s), nEvt(e), time(t), + name(n) {}; + EventContext::ContextID_t nSlot; + EventContext::ContextEvt_t nEvt; + int time; + std::string name; + }; + + Gaudi::Hive::ContextSpecificData< std::vector< sDat > > m_dq; + + // thread_local int s_i; + +}; + +#endif diff --git a/Control/AthenaExamples/AthExHive/src/HiveTool.cxx b/Control/AthenaExamples/AthExHive/src/HiveTool.cxx new file mode 100644 index 0000000000000000000000000000000000000000..e0f4fe6dcbc09c8b929587c8fefaa7b0fd77966e --- /dev/null +++ b/Control/AthenaExamples/AthExHive/src/HiveTool.cxx @@ -0,0 +1,61 @@ +/* + Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration +*/ + +#include "HiveTool.h" + +#include "GaudiKernel/SvcFactory.h" +#include "StoreGate/ReadHandle.h" + + +/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ +//DECLARE_TOOL_FACTORY(HiveTool) + + +HiveTool::HiveTool(const std::string& type, const std::string& name, + const IInterface* parent) + : base_class( type, name, parent ), + m_rdh1("b1") +{ + + declareProperty("MyMessage", m_myMessage, "the default message"); + + declareProperty("Key_R1",m_rdh1); + +} + +/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ + +HiveTool::~HiveTool() { +} + +StatusCode +HiveTool::initialize() { + ATH_MSG_INFO("initialize"); + + ATH_CHECK( m_rdh1.initialize() ); + + return StatusCode::SUCCESS; +} + +StatusCode +HiveTool::finalize() { + ATH_MSG_INFO("finalize"); + + return StatusCode::SUCCESS; +} + +StatusCode HiveTool::saySomething() const { + ATH_MSG_INFO ("message: " << m_myMessage); + + SG::ReadHandle<HiveDataObj> rh( m_rdh1 ); + + // if (!m_rdh1.isValid()) { + // ATH_MSG_ERROR ("Could not retrieve HiveDataObj with key " << m_rdh1.key()); + // return StatusCode::FAILURE; + // } + + ATH_MSG_INFO(" read: " << rh.key() << " = " << rh->val() ); + + return StatusCode::SUCCESS; +} diff --git a/Control/AthenaExamples/AthExHive/src/HiveTool.h b/Control/AthenaExamples/AthExHive/src/HiveTool.h new file mode 100644 index 0000000000000000000000000000000000000000..92ba7c3e02a7fee0f8ba66b13560caab702d80da --- /dev/null +++ b/Control/AthenaExamples/AthExHive/src/HiveTool.h @@ -0,0 +1,35 @@ +/* + Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration +*/ + +#ifndef ATHEXHIVE_HIVETOOL_H +#define ATHEXHIVE_HIVETOOL_H + +#include "AthenaBaseComps/AthAlgTool.h" +#include "AthExHive/IHiveTool.h" +#include "StoreGate/ReadHandleKey.h" +#include "AthExHive/HiveDataObj.h" + +#include <string> + +class HiveTool : public extends1<AthAlgTool,IHiveTool> { +public: + HiveTool( const std::string&, const std::string&, const IInterface* ); + virtual ~HiveTool(); + + virtual StatusCode initialize(); + virtual StatusCode finalize(); + +// the magic method this tool provides + virtual StatusCode saySomething() const; + + virtual void ss() { ATH_MSG_INFO("...ssss..."); } + +private: + std::string m_myMessage; + + SG::ReadHandleKey<HiveDataObj> m_rdh1; + +}; + +#endif diff --git a/Control/AthenaExamples/AthExHive/src/ThreadInitTool.cxx b/Control/AthenaExamples/AthExHive/src/ThreadInitTool.cxx new file mode 100644 index 0000000000000000000000000000000000000000..4b264e75c21d5d8bada5c9ca04a501a8b8fc4dea --- /dev/null +++ b/Control/AthenaExamples/AthExHive/src/ThreadInitTool.cxx @@ -0,0 +1,49 @@ +/* + Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration +*/ + +#include "unistd.h" +#include "sys/syscall.h" + +#include "ThreadInitTool.h" + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * + +ThreadInitTool::ThreadInitTool( const std::string& type, const std::string& name, + const IInterface* parent ) + : base_class(type, name, parent), + m_nInitThreads(0) + +{ +} + + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * + +void +ThreadInitTool::initThread() +{ + ATH_MSG_INFO ("initThread in thread 0x" << std::hex << pthread_self() + << " at " << this << std::dec ); + + + // Thread Local initializations would go here. + + + m_nInitThreads++; +} + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * + +void +ThreadInitTool::terminateThread() +{ + ATH_MSG_INFO ("terminateThread in thread 0x" + << std::hex << pthread_self() << std::dec ); + + + m_nInitThreads--; + +} + + diff --git a/Control/AthenaExamples/AthExHive/src/ThreadInitTool.h b/Control/AthenaExamples/AthExHive/src/ThreadInitTool.h new file mode 100644 index 0000000000000000000000000000000000000000..cd4b692a6c9aecf62cab2c53bafe142b4a2f3c30 --- /dev/null +++ b/Control/AthenaExamples/AthExHive/src/ThreadInitTool.h @@ -0,0 +1,50 @@ +/* + Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration +*/ + +#ifndef ATHEXHIVE_THREADINITTOOL_H +#define ATHEXHIVE_THREADINITTOOL_H + +#include "AthenaBaseComps/AthAlgTool.h" +#include "GaudiKernel/IThreadInitTool.h" +//#include "GaudiKernel/ToolHandle.h" + +#include <string> +#include <atomic> + +//------------------------------------------------------------------------------- +// +// This is an example of a Tool that will get executed in every thread by the +// ThreadPoolSvc. +// +// At the beginning of the job, just after the ThreadPool has been created, +// the initThread() method of the Tool will be called in each thread. +// +// as a check, m_nInitThreads MUST be incremented at the end of the initThread() +// method. +// +// At the end of the job, the terminateThread() method will be called. +// +//------------------------------------------------------------------------------- + + +class ThreadInitTool: virtual public extends1<AthAlgTool, IThreadInitTool> { + +public: + ThreadInitTool( const std::string&, const std::string&, const IInterface* ); + + + virtual void initThread(); + virtual void terminateThread(); + + + virtual unsigned int nInit() const { return m_nInitThreads; } + + +private: + // Number of threads that have been initialized + std::atomic_uint m_nInitThreads; + +}; + +#endif diff --git a/Control/AthenaExamples/AthExHive/src/components/AthExHive_entries.cxx b/Control/AthenaExamples/AthExHive/src/components/AthExHive_entries.cxx new file mode 100644 index 0000000000000000000000000000000000000000..bd15e338c6f7e82980df70507ea3fa05d8879dc3 --- /dev/null +++ b/Control/AthenaExamples/AthExHive/src/components/AthExHive_entries.cxx @@ -0,0 +1,61 @@ +#include "../HiveAlgA.h" +#include "../HiveAlgB.h" +#include "../HiveAlgC.h" +#include "../HiveAlgD.h" +#include "../HiveAlgE.h" +#include "../HiveAlgF.h" +#include "../HiveAlgG.h" +#include "../HiveAlgL1.h" +#include "../HiveAlgL2.h" +#include "../HiveAlgL3.h" +#include "../HiveAlgM.h" +#include "../HiveAlgV.h" +#include "../HiveTool.h" +#include "../HiveExSvc.h" +#include "../ASCIICondDbSvc.h" + +#ifdef REENTRANT_GAUDI + #include "../HiveAlgR.h" +#endif + +#include "../AlgA.h" +#include "../AlgB.h" +#include "../AlgC.h" +#include "../AlgD.h" +#include "../CondAlgX.h" +#include "../CondAlgY.h" + +#include "../ThreadInitTool.h" + +#include "GaudiKernel/DeclareFactoryEntries.h" + +DECLARE_ALGORITHM_FACTORY( HiveAlgA ) +DECLARE_ALGORITHM_FACTORY( HiveAlgB ) +DECLARE_ALGORITHM_FACTORY( HiveAlgC ) +DECLARE_ALGORITHM_FACTORY( HiveAlgD ) +DECLARE_ALGORITHM_FACTORY( HiveAlgE ) +DECLARE_ALGORITHM_FACTORY( HiveAlgF ) +DECLARE_ALGORITHM_FACTORY( HiveAlgG ) +DECLARE_ALGORITHM_FACTORY( HiveAlgL1 ) +DECLARE_ALGORITHM_FACTORY( HiveAlgL2 ) +DECLARE_ALGORITHM_FACTORY( HiveAlgL3 ) +DECLARE_ALGORITHM_FACTORY( HiveAlgM ) +DECLARE_ALGORITHM_FACTORY( HiveAlgV ) + +#ifdef REENTRANT_GAUDI + DECLARE_ALGORITHM_FACTORY( HiveAlgR ) +#endif + +DECLARE_ALGORITHM_FACTORY( AlgA ) +DECLARE_ALGORITHM_FACTORY( AlgB ) +DECLARE_ALGORITHM_FACTORY( AlgC ) +DECLARE_ALGORITHM_FACTORY( AlgD ) +DECLARE_ALGORITHM_FACTORY( CondAlgX ) +DECLARE_ALGORITHM_FACTORY( CondAlgY ) + +DECLARE_TOOL_FACTORY( ThreadInitTool ) +DECLARE_TOOL_FACTORY( HiveTool ) + +DECLARE_SERVICE_FACTORY( HiveExSvc ) +DECLARE_SERVICE_FACTORY( ASCIICondDbSvc ) + diff --git a/Control/AthenaExamples/AthExHive/src/components/AthExHive_load.cxx b/Control/AthenaExamples/AthExHive/src/components/AthExHive_load.cxx new file mode 100644 index 0000000000000000000000000000000000000000..292e39aa2f8a76ae7ebfcf5d5a1520f93b785a62 --- /dev/null +++ b/Control/AthenaExamples/AthExHive/src/components/AthExHive_load.cxx @@ -0,0 +1,4 @@ +#include "GaudiKernel/LoadFactoryEntries.h" + +LOAD_FACTORY_ENTRIES(AthExHive) + diff --git a/Control/AthenaExamples/AthExHive/src/rGen.cxx b/Control/AthenaExamples/AthExHive/src/rGen.cxx new file mode 100644 index 0000000000000000000000000000000000000000..803c98ee79ebd2154150dbe54b65ef7e84470b66 --- /dev/null +++ b/Control/AthenaExamples/AthExHive/src/rGen.cxx @@ -0,0 +1,16 @@ +/* + Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration +*/ + +#include "rGen.h" +#include <iostream> + +std::once_flag rGen::m_f; +std::default_random_engine rGen::m_gen; +std::uniform_real_distribution<float> rGen::m_dst(0.5,2.0); + +void rGen::init() { + unsigned long seed = std::hash<std::thread::id>()(std::this_thread::get_id()); + // std::cout << "0----> rGen::init with seed " << seed << std::endl; + m_gen.seed(seed); +} diff --git a/Control/AthenaExamples/AthExHive/src/rGen.h b/Control/AthenaExamples/AthExHive/src/rGen.h new file mode 100644 index 0000000000000000000000000000000000000000..02532e15f6e3048e2932ecf733f6199c1b07ee50 --- /dev/null +++ b/Control/AthenaExamples/AthExHive/src/rGen.h @@ -0,0 +1,37 @@ +/* + Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration +*/ + +#ifndef RGEN_H +#define RGEN_H 1 + +#include <thread> +#include <random> +#include <mutex> + +class rGen { +public: + + rGen() { + std::call_once( m_f, &rGen::init, this ); + } + + float gen() { + return m_dst(m_gen); + } + + int igen(int t) { + return int( m_dst(m_gen) * float(t) ); + } + +private: + void init(); + static std::once_flag m_f; + + static std::default_random_engine m_gen; + static std::uniform_real_distribution<float> m_dst; + +}; + + +#endif