summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMarco Clemencic <marco.clemencic@cern.ch>2013-10-29 13:02:06 +0100
committerMarco Clemencic <marco.clemencic@cern.ch>2013-10-29 13:02:06 +0100
commitfaeb564dcd4de9697cc4d9fdc7ddc868c92c0545 (patch)
treeb9cf3b3a8c7ac061da005d2014d25dd4ff58b33e
parent564231a0c7bc1039b1f2b9dcf2c86e0ecc5802cb (diff)
modified ContextEventCounter to demonstrate ContextSpecificDatatest/context-specific-ptr
-rw-r--r--GaudiHive/options/ForwardSchedulerSimpleTest.py9
-rw-r--r--GaudiHive/src/ContextEventCounter.cpp83
-rw-r--r--GaudiHive/src/ContextEventCounter.h21
3 files changed, 93 insertions, 20 deletions
diff --git a/GaudiHive/options/ForwardSchedulerSimpleTest.py b/GaudiHive/options/ForwardSchedulerSimpleTest.py
index ae5c869..f2374a2 100644
--- a/GaudiHive/options/ForwardSchedulerSimpleTest.py
+++ b/GaudiHive/options/ForwardSchedulerSimpleTest.py
@@ -29,7 +29,9 @@ entity to test it. It's an algorithm that simply wastes cpu.
from Gaudi.Configuration import *
from Configurables import (HiveWhiteBoard, HiveSlimEventLoopMgr,
ForwardSchedulerSvc, AlgResourcePool,
- CPUCruncher, ContextEventCounter)
+ CPUCruncher,
+ ContextEventCounterPtr,
+ ContextEventCounterData)
# metaconfig -------------------------------------------------------------------
# It's confortable to collect the relevant parameters at the top of the optionfile
@@ -94,7 +96,8 @@ for algo in [a1, a2, a3, a4]:
algo.varRuntime=.3
algo.avgRuntime=.5
-ctr = ContextEventCounter("CNT", Cardinality=0, OutputLevel=INFO)
+ctrp = ContextEventCounterPtr("CNT*", Cardinality=0, OutputLevel=INFO)
+ctrd = ContextEventCounterData("CNT&", Cardinality=0, OutputLevel=INFO)
# Application Manager ----------------------------------------------------------
# We put everything together and change the type of message service
@@ -103,7 +106,7 @@ ApplicationMgr( EvtMax = evtMax,
EvtSel = 'NONE',
ExtSvc =[whiteboard],
EventLoop = slimeventloopmgr,
- TopAlg = [a1, a2, a3, a4, ctr],
+ TopAlg = [a1, a2, a3, a4, ctrp, ctrd],
MessageSvcType="InertMessageSvc")
#------------------------------------------------------------------------------- \ No newline at end of file
diff --git a/GaudiHive/src/ContextEventCounter.cpp b/GaudiHive/src/ContextEventCounter.cpp
index c5e8dc6..e644b1c 100644
--- a/GaudiHive/src/ContextEventCounter.cpp
+++ b/GaudiHive/src/ContextEventCounter.cpp
@@ -6,45 +6,44 @@
#include "ContextEventCounter.h"
// ----------------------------------------------------------------------------
-// Implementation file for class: ContextEventCounter
+// Implementation file for class: ContextEventCounterPtr
//
// 27/10/2013: Marco Clemencic
// ----------------------------------------------------------------------------
-DECLARE_ALGORITHM_FACTORY(ContextEventCounter)
+DECLARE_ALGORITHM_FACTORY(ContextEventCounterPtr)
+DECLARE_ALGORITHM_FACTORY(ContextEventCounterData)
// ============================================================================
// Standard constructor, initializes variables
// ============================================================================
-ContextEventCounter::ContextEventCounter(const std::string& name, ISvcLocator* pSvcLocator)
+ContextEventCounterPtr::ContextEventCounterPtr(const std::string& name, ISvcLocator* pSvcLocator)
: GaudiAlgorithm(name, pSvcLocator)
{
-
}
// ============================================================================
// Destructor
// ============================================================================
-ContextEventCounter::~ContextEventCounter() {}
+ContextEventCounterPtr::~ContextEventCounterPtr() {}
// ============================================================================
// Initialization
// ============================================================================
-StatusCode ContextEventCounter::initialize() {
+StatusCode ContextEventCounterPtr::initialize() {
StatusCode sc = GaudiAlgorithm::initialize(); // must be executed first
if ( sc.isFailure() ) return sc; // error printed already by GaudiAlgorithm
-// TODO initialization procedure
-
if ( msgLevel(MSG::DEBUG) ) debug() << "==> Initialize" << endmsg;
+
return StatusCode::SUCCESS;
}
// ============================================================================
// Main execution
// ============================================================================
-StatusCode ContextEventCounter::execute() {
+StatusCode ContextEventCounterPtr::execute() {
if ( msgLevel(MSG::DEBUG) ) debug() << "==> Execute" << endmsg;
-
+
if (!m_ctxtSpecCounter) {
m_ctxtSpecCounter = new int(1);
} else {
@@ -52,23 +51,23 @@ StatusCode ContextEventCounter::execute() {
}
debug() << "Context " << Gaudi::Hive::currentContextId() << " "
<< m_ctxtSpecCounter.get() << " -> " << *m_ctxtSpecCounter << endmsg;
-
+
return StatusCode::SUCCESS;
}
// ============================================================================
// Finalize
// ============================================================================
-StatusCode ContextEventCounter::finalize() {
+StatusCode ContextEventCounterPtr::finalize() {
if ( msgLevel(MSG::DEBUG) ) debug() << "==> Finalize" << endmsg;
- info() << "Partial counts:" << endmsg;
+ debug() << "Partial counts:" << endmsg;
info() << "Total count of events: " << m_ctxtSpecCounter.accumulate(
[this] (const int* p) -> int {
const int r = (p) ? *p : 0;
// print partial counts
- this->info() << " " << r << endmsg;
+ this->debug() << " " << p << " -> " << r << endmsg;
return r;
}
, 0) << endmsg;
@@ -79,3 +78,59 @@ StatusCode ContextEventCounter::finalize() {
}
// ============================================================================
+// Standard constructor, initializes variables
+// ============================================================================
+ContextEventCounterData::ContextEventCounterData(const std::string& name, ISvcLocator* pSvcLocator)
+ : GaudiAlgorithm(name, pSvcLocator)
+{
+}
+
+// ============================================================================
+// Destructor
+// ============================================================================
+ContextEventCounterData::~ContextEventCounterData() {}
+
+// ============================================================================
+// Initialization
+// ============================================================================
+StatusCode ContextEventCounterData::initialize() {
+ StatusCode sc = GaudiAlgorithm::initialize(); // must be executed first
+ if ( sc.isFailure() ) return sc; // error printed already by GaudiAlgorithm
+
+ if ( msgLevel(MSG::DEBUG) ) debug() << "==> Initialize" << endmsg;
+
+ return StatusCode::SUCCESS;
+}
+
+// ============================================================================
+// Main execution
+// ============================================================================
+StatusCode ContextEventCounterData::execute() {
+ if ( msgLevel(MSG::DEBUG) ) debug() << "==> Execute" << endmsg;
+
+ ++m_ctxtSpecCounter;
+ debug() << "Context " << Gaudi::Hive::currentContextId() << " "
+ << m_ctxtSpecCounter << endmsg;
+
+ return StatusCode::SUCCESS;
+}
+
+// ============================================================================
+// Finalize
+// ============================================================================
+StatusCode ContextEventCounterData::finalize() {
+ if ( msgLevel(MSG::DEBUG) ) debug() << "==> Finalize" << endmsg;
+
+ if ( msgLevel(MSG::DEBUG) ) {
+ debug() << "Partial counts:" << endmsg;
+ m_ctxtSpecCounter.for_each([this] (const int i) {
+ this->debug() << " " << i << endmsg;
+ });
+ }
+
+ info() << "Total count of events: " << m_ctxtSpecCounter.accumulate(0) << endmsg;
+
+ return GaudiAlgorithm::finalize(); // must be called after all other actions
+}
+
+// ============================================================================
diff --git a/GaudiHive/src/ContextEventCounter.h b/GaudiHive/src/ContextEventCounter.h
index c3edc7d..aba1cb6 100644
--- a/GaudiHive/src/ContextEventCounter.h
+++ b/GaudiHive/src/ContextEventCounter.h
@@ -12,11 +12,11 @@
* @author Marco Clemencic
* @date 27/10/2013
*/
-class ContextEventCounter: public GaudiAlgorithm {
+class ContextEventCounterPtr: public GaudiAlgorithm {
public:
/// Standard constructor
- ContextEventCounter(const std::string& name, ISvcLocator* pSvcLocator);
- virtual ~ContextEventCounter(); ///< Destructor
+ ContextEventCounterPtr(const std::string& name, ISvcLocator* pSvcLocator);
+ virtual ~ContextEventCounterPtr(); ///< Destructor
virtual StatusCode initialize(); ///< Algorithm initialization
virtual StatusCode execute (); ///< Algorithm execution
@@ -27,4 +27,19 @@ private:
Gaudi::Hive::ContextSpecificPtr<int> m_ctxtSpecCounter;
};
+class ContextEventCounterData: public GaudiAlgorithm {
+public:
+ /// Standard constructor
+ ContextEventCounterData(const std::string& name, ISvcLocator* pSvcLocator);
+ virtual ~ContextEventCounterData(); ///< Destructor
+
+ virtual StatusCode initialize(); ///< Algorithm initialization
+ virtual StatusCode execute (); ///< Algorithm execution
+ virtual StatusCode finalize (); ///< Algorithm finalization
+protected:
+private:
+
+ Gaudi::Hive::ContextSpecificData<int> m_ctxtSpecCounter;
+};
+
#endif // SRC_CONTEXTEVENTCOUNTER_H