ATLAS Offline Software
Public Member Functions | Static Private Member Functions | Private Attributes | Friends | List of all members
SG::HiveMgrSvc Class Reference

#include <SGHiveMgrSvc.h>

Inheritance diagram for SG::HiveMgrSvc:
Collaboration diagram for SG::HiveMgrSvc:

Public Member Functions

virtual StatusCode selectStore (size_t slotIndex) override
 Activate an given 'slot' for all subsequent calls within the same thread id. More...
 
virtual StatusCode clearStore (size_t slotIndex) override
 Clear a given 'slot'. More...
 
virtual StatusCode setNumberOfStores (size_t slots) override
 Set the number of 'slots'. More...
 
virtual size_t getNumberOfStores () const override
 Get the number of 'slots'. More...
 
virtual bool exists (const DataObjID &) override
 Check if a data object exists in store. More...
 
virtual size_t allocateStore (int evtnumber) override
 Allocate a store slot for new event. More...
 
virtual StatusCode freeStore (size_t slotIndex) override
 Free a store slot. More...
 
virtual size_t getPartitionNumber (int eventnumber) const override
 Get the slot number corresponding to a given event. More...
 
virtual size_t freeSlots () override
 Get free slots number. More...
 
virtual StatusCode initialize () override
 
virtual StatusCode finalize () override
 
virtual StatusCode start () override
 
 HiveMgrSvc (const std::string &name, ISvcLocator *svc)
 Standard Service Constructor. sets active store to default event store. More...
 
virtual ~HiveMgrSvc ()
 

Static Private Member Functions

static void setNumProcs (size_t numProcs)
 Set number of concurrent processes. More...
 

Private Attributes

ServiceHandle< StoreGateSvcm_hiveStore
 
size_t m_nSlots
 
std::vector< SG::HiveEventSlotm_slots
 
std::mutex m_mutex
 
std::atomic< size_t > m_freeSlots {0}
 

Friends

class TestSGHiveMgrSvc
 
class ::HltEventLoopMgr
 

Detailed Description

Definition at line 30 of file SGHiveMgrSvc.h.

Constructor & Destructor Documentation

◆ HiveMgrSvc()

HiveMgrSvc::HiveMgrSvc ( const std::string &  name,
ISvcLocator *  svc 
)

Standard Service Constructor. sets active store to default event store.

Definition at line 17 of file SGHiveMgrSvc.cxx.

18  : base_class(name, svc),
20  m_nSlots(1)
21 {
22  declareProperty("HiveStoreSvc", m_hiveStore);
23  declareProperty("NSlots", m_nSlots, "number of event slots");
24 }

◆ ~HiveMgrSvc()

virtual SG::HiveMgrSvc::~HiveMgrSvc ( )
inlinevirtual

Definition at line 106 of file SGHiveMgrSvc.h.

106 {}

Member Function Documentation

◆ allocateStore()

size_t HiveMgrSvc::allocateStore ( int  evtNumber)
overridevirtual

Allocate a store slot for new event.

Parameters
evtnumber[IN] Event number
slot[OUT] Returned slot or slot number
Returns
Slot number (npos to indicate an error).

Definition at line 98 of file SGHiveMgrSvc.cxx.

98  {
99  if (m_freeSlots == 0) {
100  error() << "No slots available for event number " << evtNumber << endmsg;
101  return std::string::npos;
102  }
103  std::scoped_lock lock{m_mutex};
104  for (size_t index=0; index<m_nSlots; ++index) {
105  if( m_slots[index].eventNumber == evtNumber) {
106  error() << "Attempt to allocate an event slot for an event that is still active: event number " << evtNumber << endmsg;
107  return std::string::npos;
108  } else if (m_slots[index].eventNumber == -1) {
109  m_slots[index].eventNumber = evtNumber;
110  debug() << "Slot " << index
111  << " allocated to event number "<< evtNumber << endmsg;
112  m_freeSlots--;
113  return index;
114  }
115  }
116  error() << "No slots available for event number " << evtNumber << endmsg;
117  return std::string::npos;
118 }

◆ clearStore()

StatusCode HiveMgrSvc::clearStore ( size_t  slotIndex)
overridevirtual

Clear a given 'slot'.

Parameters
slot[IN] Slot number (event slot) *
Returns
Status code indicating failure or success.

Definition at line 57 of file SGHiveMgrSvc.cxx.

57  {
58  StatusCode rc(StatusCode::FAILURE);
59  if (slotIndex < m_nSlots) {
60  rc=m_slots[slotIndex].pEvtStore->clearStore();
61  if (rc.isSuccess()) debug() << "cleared store " << slotIndex << endmsg;
62  }
63  if (!rc.isSuccess()) error() << "could not clear store " << slotIndex << endmsg;
64  return rc;
65 }

◆ exists()

bool HiveMgrSvc::exists ( const DataObjID &  id)
overridevirtual

Check if a data object exists in store.

TODO: remove the method ASA a cross-experiment event data store interface emerges

Returns
boolean

Definition at line 161 of file SGHiveMgrSvc.cxx.

161  {
162  // this should only get called in error situations, so we
163  // don't care if it's slow
164  std::string key = id.key();
165  key.erase(0,key.find('+')+1);
166 
167  if (id.clid() == 0) {
168  // this is an ugly hack in case the DataObjID gets munged
169  // upstream, and we have to re-separate it into (class,key)
170  // from "class/key"
171  std::string cl = id.fullKey();
172  cl.erase(cl.find('/'),cl.length());
173 
174  DataObjID d2(std::move(cl),key);
175  return m_hiveStore->transientContains(d2.clid(), key);
176  } else {
177  return m_hiveStore->transientContains(id.clid(), key);
178  }
179 
180 }

◆ finalize()

StatusCode HiveMgrSvc::finalize ( )
overridevirtual

Definition at line 220 of file SGHiveMgrSvc.cxx.

220  {
221  info() << "Finalizing " << name() << endmsg;
222 
223  for (SG::HiveEventSlot& s : m_slots) {
224  // The impl services are not set to active, so ServiceManager
225  // won't finalize them.
226  CHECK( s.pEvtStore->finalize() );
227  s.pEvtStore->release();
228  }
229 
230  return StatusCode::SUCCESS;
231 }

◆ freeSlots()

size_t HiveMgrSvc::freeSlots ( )
overridevirtual

Get free slots number.

Definition at line 157 of file SGHiveMgrSvc.cxx.

157  {
158  return m_freeSlots;
159 }

◆ freeStore()

StatusCode HiveMgrSvc::freeStore ( size_t  slotIndex)
overridevirtual

Free a store slot.

Parameters
slot[IN] Slot number
Returns
Status code indicating failure or success.

Definition at line 125 of file SGHiveMgrSvc.cxx.

125  {
126  if (slotIndex < m_nSlots) {
127  std::scoped_lock lock{m_mutex};
128  if (m_slots[slotIndex].eventNumber == -1) {
129  debug() << "Slot " << slotIndex << " is already free" << endmsg;
130  }
131  else {
132  m_slots[slotIndex].eventNumber = -1;
133  m_freeSlots++;
134  debug() << "Freed slot " << slotIndex << endmsg;
135  }
136  return StatusCode::SUCCESS;
137  } else {
138  error() << "no slot at " << slotIndex << endmsg;
139  return StatusCode::FAILURE;
140  }
141 }

◆ getNumberOfStores()

size_t HiveMgrSvc::getNumberOfStores ( ) const
overridevirtual

Get the number of 'slots'.

Returns
Number of event stores allocated in the whiteboard

Definition at line 86 of file SGHiveMgrSvc.cxx.

86  {
87  return m_nSlots;
88 }

◆ getPartitionNumber()

size_t HiveMgrSvc::getPartitionNumber ( int  evtNumber) const
overridevirtual

Get the slot number corresponding to a given event.

Parameters
evtnumber[IN] Event number
Returns
slot number (npos to indicate an error).
Parameters
evtNumber[IN] Event number
Returns
slot number (npos to indicate an error).

Definition at line 149 of file SGHiveMgrSvc.cxx.

149  {
150  std::scoped_lock lock{m_mutex};
151  for (size_t index=0; index<m_nSlots; ++index) {
152  if( m_slots[index].eventNumber == evtNumber) return index;
153  }
154  return std::string::npos;
155 }

◆ initialize()

StatusCode HiveMgrSvc::initialize ( )
overridevirtual

Definition at line 182 of file SGHiveMgrSvc.cxx.

182  {
183  verbose() << "Initializing " << name() << endmsg;
184 
185  if ( !(Service::initialize().isSuccess()) ) {
186  fatal() << "Unable to initialize base class" << endmsg;
187  return StatusCode::FAILURE;
188  }
189  //this sets the hiveStore pointer to StoreGateSvc.defaultStore
190  if (!(m_hiveStore.retrieve()).isSuccess()) {
191  fatal() << "Unable to get hive event store" << endmsg;
192  return StatusCode::FAILURE;
193  }
194 
195  //use hiveStore default impl store as prototype
196  Service* child(0);
197  SGImplSvc* pSG(0);
198 
199  for( size_t i = 0; i< m_nSlots; ++i) {
200  std::ostringstream oss;
201  oss << i << '_' << m_hiveStore->currentStore()->name();
202  if (CloneService::clone(m_hiveStore->currentStore(), oss.str(), child).isSuccess() &&
203  child->initialize().isSuccess() &&
204  0 != (pSG = dynamic_cast<SGImplSvc*>(child)) )
205  {
206  pSG->setSlotNumber (i, m_nSlots);
207  m_slots.push_back(SG::HiveEventSlot(pSG));
208  } else {
209  fatal() << "Unable to clone event store " << oss.str() << endmsg;
210  return StatusCode::FAILURE;
211  }
212  }
213 
214  m_freeSlots.store( m_nSlots );
215  Gaudi::Concurrency::ConcurrencyFlags::setNumConcEvents( m_nSlots );
216 
217  return selectStore(0);
218 }

◆ selectStore()

StatusCode HiveMgrSvc::selectStore ( size_t  slotIndex)
overridevirtual

Activate an given 'slot' for all subsequent calls within the same thread id.

Parameters
slot[IN] Slot number (event slot) *
Returns
Status code indicating failure or success.

Definition at line 46 of file SGHiveMgrSvc.cxx.

46  {
47  s_current = &m_slots[slotIndex];
49  return StatusCode::SUCCESS;
50 }

◆ setNumberOfStores()

StatusCode HiveMgrSvc::setNumberOfStores ( size_t  slots)
overridevirtual

Set the number of 'slots'.

Parameters
slot[IN] Slot number (event slot) *
Returns
Status code indicating failure or success.

Definition at line 72 of file SGHiveMgrSvc.cxx.

72  {
73  //FIXME what if running?
74  if(FSMState() == Gaudi::StateMachine::INITIALIZED) {
75  fatal() << "Too late to change the number of slots!" << endmsg;
76  return StatusCode::FAILURE;
77  } else {
78  m_slots.resize(slots);
79  m_nSlots = slots;
80  m_freeSlots.store(slots);
81  Gaudi::Concurrency::ConcurrencyFlags::setNumConcEvents( slots );
82  return StatusCode::SUCCESS;
83  }
84 }

◆ setNumProcs()

void HiveMgrSvc::setNumProcs ( size_t  numProcs)
staticprivate

Set number of concurrent processes.

This can only be called by "friends" of this class. Its sole purpose is to have a common entry point within ATLAS to call the private methods of Gaudi::ConcurrencyFlags.

Parameters
numProcs[IN] Number of concurrent processes

Definition at line 35 of file SGHiveMgrSvc.cxx.

36 {
37  Gaudi::Concurrency::ConcurrencyFlags::setNumProcs(numProcs);
38 }

◆ start()

StatusCode HiveMgrSvc::start ( )
overridevirtual

Definition at line 234 of file SGHiveMgrSvc.cxx.

235 {
236  // On a start transition, merge the string pool from the default store
237  // into that of each store, so that they will know about any explicit
238  // registrations that were done during initialize().
239  // See ATEAM-846.
240  for (SG::HiveEventSlot& slot : m_slots) {
241  slot.pEvtStore->mergeStringPool (*m_hiveStore->currentStore());
242  }
243  return StatusCode::SUCCESS;
244 }

Friends And Related Function Documentation

◆ ::HltEventLoopMgr

friend class ::HltEventLoopMgr
friend

Definition at line 32 of file SGHiveMgrSvc.h.

◆ TestSGHiveMgrSvc

friend class TestSGHiveMgrSvc
friend

Definition at line 31 of file SGHiveMgrSvc.h.

Member Data Documentation

◆ m_freeSlots

std::atomic<size_t> SG::HiveMgrSvc::m_freeSlots {0}
private

Definition at line 123 of file SGHiveMgrSvc.h.

◆ m_hiveStore

ServiceHandle<StoreGateSvc> SG::HiveMgrSvc::m_hiveStore
private

Definition at line 119 of file SGHiveMgrSvc.h.

◆ m_mutex

std::mutex SG::HiveMgrSvc::m_mutex
mutableprivate

Definition at line 122 of file SGHiveMgrSvc.h.

◆ m_nSlots

size_t SG::HiveMgrSvc::m_nSlots
private

Definition at line 120 of file SGHiveMgrSvc.h.

◆ m_slots

std::vector<SG::HiveEventSlot> SG::HiveMgrSvc::m_slots
private

Definition at line 121 of file SGHiveMgrSvc.h.


The documentation for this class was generated from the following files:
SG::HiveEventSlot
Definition: SGHiveEventSlot.h:19
StoreGateSvc::setSlot
static void setSlot(SG::HiveEventSlot *pSlot)
set the hive event slot pointer: used by the event loop mgrs
Definition: StoreGateSvc.cxx:44
SG::HiveMgrSvc::m_hiveStore
ServiceHandle< StoreGateSvc > m_hiveStore
Definition: SGHiveMgrSvc.h:119
index
Definition: index.py:1
initialize
void initialize()
Definition: run_EoverP.cxx:894
SG::HiveMgrSvc::m_slots
std::vector< SG::HiveEventSlot > m_slots
Definition: SGHiveMgrSvc.h:121
python.RatesEmulationExample.lock
lock
Definition: RatesEmulationExample.py:148
SG::HiveMgrSvc::m_freeSlots
std::atomic< size_t > m_freeSlots
Definition: SGHiveMgrSvc.h:123
lumiFormat.i
int i
Definition: lumiFormat.py:85
endmsg
#define endmsg
Definition: AnalysisConfig_Ntuple.cxx:63
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
SGImplSvc
The Athena Transient Store API.
Definition: SGImplSvc.h:109
CHECK
#define CHECK(...)
Evaluate an expression and check for errors.
Definition: Control/AthenaKernel/AthenaKernel/errorcheck.h:422
xAOD::eventNumber
eventNumber
Definition: EventInfo_v1.cxx:124
Handler::svc
AthROOTErrorHandlerSvc * svc
Definition: AthROOTErrorHandlerSvc.cxx:10
SG::HiveMgrSvc::selectStore
virtual StatusCode selectStore(size_t slotIndex) override
Activate an given 'slot' for all subsequent calls within the same thread id.
Definition: SGHiveMgrSvc.cxx:46
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:240
debug
const bool debug
Definition: MakeUncertaintyPlots.cxx:53
SG::HiveMgrSvc::m_nSlots
size_t m_nSlots
Definition: SGHiveMgrSvc.h:120
DeMoScan.index
string index
Definition: DeMoScan.py:362
CloneService::clone
StatusCode clone(const IService *parent, const std::string &childName, Service *&child)
given a reference to a parent svc sets a reference to a cloned child
Definition: CloneService.cxx:21
SG::HiveMgrSvc::m_mutex
std::mutex m_mutex
Definition: SGHiveMgrSvc.h:122
python.TriggerHandler.verbose
verbose
Definition: TriggerHandler.py:296
dq_defect_virtual_defect_validation.d2
d2
Definition: dq_defect_virtual_defect_validation.py:81
python.SystemOfUnits.s
float s
Definition: SystemOfUnits.py:147
s_current
__thread HiveEventSlot * s_current(0)
StoreID::EVENT_STORE
@ EVENT_STORE
Definition: StoreID.h:26
get_generator_info.error
error
Definition: get_generator_info.py:40
dq_make_web_display.cl
cl
print [x.__class__ for x in toList(dqregion.getSubRegions()) ]
Definition: dq_make_web_display.py:25
python.ParticleTypeUtil.info
def info
Definition: ParticleTypeUtil.py:87
StoreID::storeName
static const std::string & storeName(const StoreID::type &s)
Definition: StoreID.cxx:77
python.trfValidateRootFile.rc
rc
Definition: trfValidateRootFile.py:375
mapkey::key
key
Definition: TElectronEfficiencyCorrectionTool.cxx:37