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 160 of file SGHiveMgrSvc.cxx.

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

◆ finalize()

StatusCode HiveMgrSvc::finalize ( )
overridevirtual

Definition at line 219 of file SGHiveMgrSvc.cxx.

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

◆ freeSlots()

size_t HiveMgrSvc::freeSlots ( )
overridevirtual

Get free slots number.

Definition at line 156 of file SGHiveMgrSvc.cxx.

156  {
157  return m_freeSlots;
158 }

◆ 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  for (size_t index=0; index<m_nSlots; ++index) {
151  if( m_slots[index].eventNumber == evtNumber) return index;
152  }
153  return std::string::npos;
154 }

◆ initialize()

StatusCode HiveMgrSvc::initialize ( )
overridevirtual

Definition at line 181 of file SGHiveMgrSvc.cxx.

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

◆ 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 233 of file SGHiveMgrSvc.cxx.

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

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
private

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:
grepfile.info
info
Definition: grepfile.py:38
SG::HiveEventSlot
Definition: SGHiveEventSlot.h:19
python.SystemOfUnits.s
int s
Definition: SystemOfUnits.py:131
StoreGateSvc::setSlot
static void setSlot(SG::HiveEventSlot *pSlot)
set the hive event slot pointer: used by the event loop mgrs
Definition: StoreGateSvc.cxx:62
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
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
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:221
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:364
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:297
dq_defect_virtual_defect_validation.d2
d2
Definition: dq_defect_virtual_defect_validation.py:81
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:26
StoreID::storeName
static const std::string & storeName(const StoreID::type &s)
Definition: StoreID.cxx:77
python.trfValidateRootFile.rc
rc
Definition: trfValidateRootFile.py:349
mapkey::key
key
Definition: TElectronEfficiencyCorrectionTool.cxx:37