The Gaudi Framework  v33r0 (d5ea422b)
EvtStoreSvc.cpp
Go to the documentation of this file.
1 /***********************************************************************************\
2 * (c) Copyright 1998-2019 CERN for the benefit of the LHCb and ATLAS collaborations *
3 * *
4 * This software is distributed under the terms of the Apache version 2 licence, *
5 * copied verbatim in the file "LICENSE". *
6 * *
7 * In applying this licence, CERN does not waive the privileges and immunities *
8 * granted to it by virtue of its status as an Intergovernmental Organization *
9 * or submit itself to any jurisdiction. *
10 \***********************************************************************************/
17 #include "GaudiKernel/IRegistry.h"
18 #include "GaudiKernel/Service.h"
19 #include "GaudiKernel/System.h"
20 
21 #include "ThreadLocalStorage.h"
22 
23 #include "boost/algorithm/string/predicate.hpp"
24 
25 #include "tbb/concurrent_queue.h"
26 #include "tbb/tbb_stddef.h"
27 #if TBB_INTERFACE_VERSION_MAJOR < 12
28 # include "tbb/recursive_mutex.h"
29 #endif // TBB_INTERFACE_VERSION_MAJOR < 12
30 
31 #include <algorithm>
32 #include <iomanip>
33 #include <iterator>
34 #include <map>
35 #include <mutex>
36 #include <stdexcept>
37 #include <type_traits>
38 #include <unordered_map>
39 #include <utility>
40 #include <vector>
41 
42 namespace {
43 
44  class Entry final : public IRegistry {
47  std::string m_identifier;
48  static IDataProviderSvc* s_svc;
49 
50  public:
51  static void setDataProviderSvc( IDataProviderSvc* p ) { s_svc = p; }
52 
53  Entry( std::string id, std::unique_ptr<DataObject> data, std::unique_ptr<IOpaqueAddress> addr = {} ) noexcept
54  : m_data{std::move( data )}, m_addr{std::move( addr )}, m_identifier{std::move( id )} {
55  if ( m_data ) m_data->setRegistry( this );
56  if ( m_addr ) m_addr->setRegistry( this );
57  }
58  Entry( const Entry& ) = delete;
59  Entry& operator=( const Entry& rhs ) = delete;
60  Entry( Entry&& rhs ) = delete;
61  Entry& operator=( Entry&& rhs ) = delete;
62 
63  // required by IRegistry...
64  unsigned long addRef() override { return -1; }
65  unsigned long release() override { return -1; }
66  const name_type& name() const override { return m_identifier; } // should really be from last '/' onward...
67  const id_type& identifier() const override { return m_identifier; }
68  IDataProviderSvc* dataSvc() const override { return s_svc; }
69  DataObject* object() const override { return const_cast<DataObject*>( m_data.get() ); }
70  IOpaqueAddress* address() const override { return m_addr.get(); }
71  void setAddress( IOpaqueAddress* iAddr ) override {
72  m_addr.reset( iAddr );
73  if ( m_addr ) m_addr->setRegistry( this );
74  }
75  };
76  IDataProviderSvc* Entry::s_svc = nullptr;
77 
79  using OrderedMap = std::map<std::string_view, Entry>;
80 
81  template <typename Map = UnorderedMap>
82  class Store {
83  Map m_store;
84  static_assert( std::is_same_v<typename Map::key_type, std::string_view> );
85 
86  const auto& emplace( std::string_view k, std::unique_ptr<DataObject> d, std::unique_ptr<IOpaqueAddress> a = {} ) {
87  // tricky way to insert a string_view key which points to the
88  // string contained in the mapped type...
89  auto [i, b] = m_store.try_emplace( k, std::string{k}, std::move( d ), std::move( a ) );
90  if ( !b ) throw std::runtime_error( "failed to insert " + std::string{k} );
91  auto nh = m_store.extract( i );
92  nh.key() = nh.mapped().identifier(); // "re-point" key to the string contained in the Entry
93  auto r = m_store.insert( std::move( nh ) );
94  if ( !r.inserted ) throw std::runtime_error( "failed to insert " + std::string{k} );
95  return r.position->second;
96  }
97 
98  public:
99  const DataObject* put( std::string_view k, std::unique_ptr<DataObject> data,
100  std::unique_ptr<IOpaqueAddress> addr = {} ) {
101  return emplace( k, std::move( data ), std::move( addr ) ).object();
102  }
103  const DataObject* get( std::string_view k ) const noexcept {
104  const Entry* d = find( k );
105  return d ? d->object() : nullptr;
106  }
107  const Entry* find( std::string_view k ) const noexcept {
108  auto i = m_store.find( k );
109  return i != m_store.end() ? &( i->second ) : nullptr;
110  }
111 
112  auto begin() const noexcept { return m_store.begin(); }
113  auto end() const noexcept { return m_store.end(); }
114  void clear() noexcept { m_store.clear(); }
115  auto erase( std::string_view k ) { return m_store.erase( k ); }
116  template <typename Predicate>
117  void erase_if( Predicate p ) {
118  auto i = m_store.begin();
119  auto end = m_store.end();
120  while ( i != end ) {
121  if ( std::invoke( p, std::as_const( *i ) ) )
122  i = m_store.erase( i );
123  else
124  ++i;
125  }
126  }
127  };
128 
129  StatusCode dummy( std::string s ) {
130  std::string trace;
131  System::backTrace( trace, 6, 2 );
132  throw std::logic_error{"Unsupported Function Called: " + s + "\n" + trace};
133  return StatusCode::FAILURE;
134  }
135 
136  std::string_view normalize_path( std::string_view path, std::string_view prefix ) {
137  if ( path.size() >= prefix.size() && std::equal( prefix.begin(), prefix.end(), path.begin() ) )
138  path.remove_prefix( prefix.size() );
139  if ( !path.empty() && path.front() == '/' ) path.remove_prefix( 1 );
140  return path;
141  }
142 
144  DataObject* pObject = nullptr;
145  auto status = cnv.createObj( &addr, pObject ); // Call data loader
146  auto object = std::unique_ptr<DataObject>( pObject );
147  if ( status.isFailure() ) object.reset();
148  return object;
149  }
150 
151  // HiveWhiteBoard helpers
152  struct Partition final {
153  Store<> store;
154  int eventNumber = -1;
155  };
156 
157 #if TBB_INTERFACE_VERSION_MAJOR < 12
158  template <typename T, typename Mutex = tbb::recursive_mutex, typename ReadLock = typename Mutex::scoped_lock,
159 
160 #else
161  template <typename T, typename Mutex = std::recursive_mutex,
162  typename ReadLock = std::lock_guard<std::recursive_mutex>,
163 #endif // TBB_INTERFACE_VERSION_MAJOR < 12
164  typename WriteLock = ReadLock>
165  class Synced {
166  T m_obj;
167  mutable Mutex m_mtx;
168 
169  public:
170  template <typename F>
171  decltype( auto ) with_lock( F&& f ) {
172  WriteLock lock{m_mtx};
173  return f( m_obj );
174  }
175  template <typename F>
176  decltype( auto ) with_lock( F&& f ) const {
177  ReadLock lock{m_mtx};
178  return f( m_obj );
179  }
180  };
181  // transform an f(T) into an f(Synced<T>)
182  template <typename Fun>
183  auto with_lock( Fun&& f ) {
184  return [f = std::forward<Fun>( f )]( auto& p ) -> decltype( auto ) { return p.with_lock( f ); };
185  }
186 
187  TTHREAD_TLS( Synced<Partition>* ) s_current = nullptr;
188 
189  template <typename Fun>
190  StatusCode fwd( Fun&& f ) {
191  return s_current ? s_current->with_lock( std::forward<Fun>( f ) )
193  }
194 
195 } // namespace
196 
207 class GAUDI_API EvtStoreSvc : public extends<Service, IDataProviderSvc, IDataManagerSvc, IHiveWhiteBoard> {
208  Gaudi::Property<CLID> m_rootCLID{this, "RootCLID", 110 /*CLID_Event*/, "CLID of root entry"};
209  Gaudi::Property<std::string> m_rootName{this, "RootName", "/Event", "name of root entry"};
210  Gaudi::Property<bool> m_forceLeaves{this, "ForceLeaves", false, "force creation of default leaves on registerObject"};
211  Gaudi::Property<std::string> m_loader{this, "DataLoader", "EventPersistencySvc"};
212  Gaudi::Property<size_t> m_slots{this, "EventSlots", 1, "number of event slots"};
213 
215 
218 
221 
222  tbb::concurrent_queue<size_t> m_freeSlots;
223 
224 public:
225  using extends::extends;
226 
227  CLID rootCLID() const override;
228  const std::string& rootName() const override;
229  StatusCode setDataLoader( IConversionSvc* svc, IDataProviderSvc* dpsvc ) override;
230 
231  size_t allocateStore( int evtnumber ) override;
232  StatusCode freeStore( size_t partition ) override;
233  size_t freeSlots() override { return m_freeSlots.unsafe_size(); }
234  StatusCode selectStore( size_t partition ) override;
235  StatusCode clearStore() override;
236  StatusCode clearStore( size_t partition ) override;
237  StatusCode setNumberOfStores( size_t slots ) override;
238  size_t getNumberOfStores() const override { return m_slots; }
239  size_t getPartitionNumber( int eventnumber ) const override;
240  bool exists( const DataObjID& id ) override {
241  DataObject* pObject{nullptr};
242  return findObject( id.fullKey(), pObject ).isSuccess();
243  }
244 
245  StatusCode objectParent( const DataObject*, IRegistry*& ) override { return dummy( __FUNCTION__ ); }
246  StatusCode objectParent( const IRegistry*, IRegistry*& ) override { return dummy( __FUNCTION__ ); }
247  StatusCode objectLeaves( const DataObject*, std::vector<IRegistry*>& ) override { return dummy( __FUNCTION__ ); }
248  StatusCode objectLeaves( const IRegistry*, std::vector<IRegistry*>& ) override { return dummy( __FUNCTION__ ); }
249 
250  StatusCode clearSubTree( std::string_view ) override;
251  StatusCode clearSubTree( DataObject* obj ) override {
252  return obj && obj->registry() ? clearSubTree( obj->registry()->identifier() ) : StatusCode::FAILURE;
253  }
254 
255  StatusCode traverseSubTree( std::string_view, IDataStoreAgent* ) override;
257  return ( obj && obj->registry() ) ? traverseSubTree( obj->registry()->identifier(), pAgent ) : StatusCode::FAILURE;
258  }
259  StatusCode traverseTree( IDataStoreAgent* pAgent ) override { return traverseSubTree( std::string_view{}, pAgent ); }
260 
261  StatusCode setRoot( std::string root_name, DataObject* pObject ) override;
262  StatusCode setRoot( std::string root_path, IOpaqueAddress* pRootAddr ) override;
263 
264  StatusCode unregisterAddress( std::string_view ) override { return dummy( __FUNCTION__ ); };
265  StatusCode unregisterAddress( IRegistry*, std::string_view ) override { return dummy( __FUNCTION__ ); };
266 
267  StatusCode registerAddress( std::string_view fullPath, IOpaqueAddress* pAddress ) override;
268  StatusCode registerAddress( IRegistry* parentObj, std::string_view objectPath, IOpaqueAddress* pAddress ) override;
269  StatusCode registerObject( std::string_view parentPath, std::string_view objectPath, DataObject* pObject ) override;
270  StatusCode registerObject( DataObject* parentObj, std::string_view objectPath, DataObject* pObject ) override;
271 
272  StatusCode unregisterObject( std::string_view ) override;
274  return ( obj && obj->registry() ) ? unregisterObject( obj->registry()->identifier() ) : StatusCode::FAILURE;
275  }
276  StatusCode unregisterObject( DataObject* obj, std::string_view sr ) override {
277  return !obj ? unregisterObject( sr )
278  : obj->registry() ? unregisterObject( ( obj->registry()->identifier() + '/' ).append( sr ) )
280  };
281 
282  StatusCode retrieveObject( IRegistry* pDirectory, std::string_view path, DataObject*& pObject ) override;
283 
284  StatusCode findObject( IRegistry* pDirectory, std::string_view path, DataObject*& pObject ) override;
285  StatusCode findObject( std::string_view fullPath, DataObject*& pObject ) override;
286 
287  StatusCode updateObject( IRegistry* ) override { return dummy( __FUNCTION__ ); }
288  StatusCode updateObject( DataObject* ) override { return dummy( __FUNCTION__ ); }
289 
290  StatusCode addPreLoadItem( const DataStoreItem& ) override;
291  StatusCode removePreLoadItem( const DataStoreItem& ) override;
293  m_preLoads.clear();
294  return StatusCode::SUCCESS;
295  }
296  StatusCode preLoad() override;
297 
298  StatusCode linkObject( IRegistry*, std::string_view, DataObject* ) override { return dummy( __FUNCTION__ ); }
299  StatusCode linkObject( std::string_view, DataObject* ) override { return dummy( __FUNCTION__ ); }
300  StatusCode unlinkObject( IRegistry*, std::string_view ) override { return dummy( __FUNCTION__ ); }
301  StatusCode unlinkObject( DataObject*, std::string_view ) override { return dummy( __FUNCTION__ ); }
302  StatusCode unlinkObject( std::string_view ) override { return dummy( __FUNCTION__ ); }
303 
304  StatusCode initialize() override {
305  Entry::setDataProviderSvc( this );
306  extends::initialize().ignore();
307  if ( !setNumberOfStores( m_slots ).isSuccess() ) {
308  error() << "Cannot set number of slots" << endmsg;
309  return StatusCode::FAILURE;
310  }
311  m_partitions = std::vector<Synced<Partition>>( m_slots );
312  for ( size_t i = 0; i < m_slots; i++ ) { m_freeSlots.push( i ); }
313  selectStore( 0 ).ignore();
314 
315  auto loader = serviceLocator()->service( m_loader ).as<IConversionSvc>().get();
316  if ( !loader ) {
317  error() << "Cannot get IConversionSvc " << m_loader.value() << endmsg;
318  return StatusCode::FAILURE;
319  }
320  return setDataLoader( loader, nullptr );
321  }
322  StatusCode finalize() override {
323  setDataLoader( nullptr, nullptr ).ignore(); // release
324  return extends::finalize();
325  }
326 };
327 
328 // Instantiation of a static factory class used by clients to create
329 // instances of this service
331 
332 CLID EvtStoreSvc::rootCLID() const { return m_rootCLID; }
333 const std::string& EvtStoreSvc::rootName() const { return m_rootName; }
335  m_dataLoader = pDataLoader;
336  if ( m_dataLoader ) m_dataLoader->setDataProvider( dpsvc ? dpsvc : this ).ignore();
337  return StatusCode::SUCCESS;
338 }
340 size_t EvtStoreSvc::allocateStore( int evtnumber ) {
341  // take next free slot in the list
342  size_t slot = std::string::npos;
343  if ( m_freeSlots.try_pop( slot ) ) {
344  assert( slot != std::string::npos );
345  assert( slot < m_partitions.size() );
346  [[maybe_unused]] auto prev = m_partitions[slot].with_lock(
347  [evtnumber]( Partition& p ) { return std::exchange( p.eventNumber, evtnumber ); } );
348  assert( prev == -1 ); // or whatever value represents 'free'
349  }
350  return slot;
351 }
354  if ( slots < size_t{1} ) {
355  error() << "Invalid number of slots (" << slots << ")" << endmsg;
356  return StatusCode::FAILURE;
357  }
359  error() << "Too late to change the number of slots!" << endmsg;
360  return StatusCode::FAILURE;
361  }
362  m_slots = slots;
364  return StatusCode::SUCCESS;
365 }
367 size_t EvtStoreSvc::getPartitionNumber( int eventnumber ) const {
369  with_lock( [eventnumber]( const Partition& p ) { return p.eventNumber == eventnumber; } ) );
370  return i != end( m_partitions ) ? std::distance( begin( m_partitions ), i ) : std::string::npos;
371 }
374  s_current = &m_partitions[partition];
375  return StatusCode::SUCCESS;
376 }
378 StatusCode EvtStoreSvc::freeStore( size_t partition ) {
379  assert( partition < m_partitions.size() );
380  auto prev = m_partitions[partition].with_lock( []( Partition& p ) { return std::exchange( p.eventNumber, -1 ); } );
381  if ( UNLIKELY( prev == -1 ) ) return StatusCode::FAILURE; // double free -- should never happen!
382  m_freeSlots.push( partition );
383  return StatusCode::SUCCESS;
384 }
386 StatusCode EvtStoreSvc::clearStore( size_t partition ) {
387  return m_partitions[partition].with_lock( []( Partition& p ) {
388  p.store.clear();
389  return StatusCode::SUCCESS;
390  } );
391 }
392 StatusCode EvtStoreSvc::clearSubTree( std::string_view top ) {
393  top = normalize_path( top, rootName() );
394  return fwd( [&]( Partition& p ) {
395  p.store.erase_if( [top]( const auto& value ) { return boost::algorithm::starts_with( value.first, top ); } );
396  return StatusCode::SUCCESS;
397  } );
398 }
400  return fwd( []( Partition& p ) {
401  p.store.clear();
402  return StatusCode::SUCCESS;
403  } );
404 }
405 StatusCode EvtStoreSvc::traverseSubTree( std::string_view top, IDataStoreAgent* pAgent ) {
406  return fwd( [&]( Partition& p ) {
407  top = normalize_path( top, rootName() );
408  auto cmp = []( const Entry* lhs, const Entry* rhs ) { return lhs->identifier() < rhs->identifier(); };
409  std::set<const Entry*, decltype( cmp )> keys{std::move( cmp )};
410  for ( const auto& v : p.store ) {
411  if ( boost::algorithm::starts_with( v.second.identifier(), top ) ) keys.insert( &v.second );
412  }
413  auto k = keys.begin();
414  while ( k != keys.end() ) {
415  const auto& id = ( *k )->identifier();
416  int level = std::count( id.begin(), id.end(), '/' );
417  bool accept = pAgent->analyse( const_cast<Entry*>( *( k++ ) ), level );
418  if ( !accept ) {
419  k = std::find_if_not( k, keys.end(),
420  [&id]( const auto& e ) { return boost::algorithm::starts_with( e->identifier(), id ); } );
421  }
422  }
423  return StatusCode::SUCCESS;
424  } );
425 }
427  if ( msgLevel( MSG::DEBUG ) ) {
428  debug() << "setRoot( " << root_path << ", (DataObject*)" << (void*)pObject << " )" << endmsg;
429  }
430  clearStore().ignore();
431  return registerObject( nullptr, root_path, pObject );
432 }
434  auto rootAddr = std::unique_ptr<IOpaqueAddress>( pRootAddr );
435  if ( msgLevel( MSG::DEBUG ) ) {
436  debug() << "setRoot( " << root_path << ", (IOpaqueAddress*)" << (void*)rootAddr.get() << " )" << endmsg;
437  }
438  clearStore().ignore();
439  if ( !rootAddr ) return Status::INVALID_OBJ_ADDR; // Precondition: Address must be valid
440  if ( msgLevel( MSG::DEBUG ) ) {
441  const std::string* par = rootAddr->par();
442  debug() << "par[0]=" << par[0] << endmsg;
443  debug() << "par[1]=" << par[1] << endmsg;
444  }
445  auto object = createObj( *m_dataLoader, *rootAddr ); // Call data loader
446  if ( !object ) return Status::INVALID_OBJECT;
447  if ( msgLevel( MSG::DEBUG ) ) { debug() << "Root Object " << root_path << " created " << endmsg; }
448  auto dummy = Entry{root_path, {}, {}};
449  object->setRegistry( &dummy );
450  rootAddr->setRegistry( &dummy );
451  auto status = m_dataLoader->fillObjRefs( rootAddr.get(), object.get() );
452  if ( status.isSuccess() ) {
453  auto pObject = object.get();
454  status = registerObject( nullptr, root_path, object.release() );
455  if ( status.isSuccess() ) pObject->registry()->setAddress( rootAddr.release() );
456  }
457  return status;
458 }
460  return registerAddress( nullptr, path, pAddr );
461 }
463  auto addr = std::unique_ptr<IOpaqueAddress>( pAddr );
464  if ( msgLevel( MSG::DEBUG ) ) {
465  debug() << "registerAddress( (IRegistry*)" << (void*)pReg << ", " << path << ", (IOpaqueAddress*)" << addr.get()
466  << "[ " << addr->par()[0] << ", " << addr->par()[1] << " ]"
467  << " )" << endmsg;
468  }
469  if ( !addr ) return Status::INVALID_OBJ_ADDR; // Precondition: Address must be valid
470  if ( path.empty() || path[0] != '/' ) return StatusCode::FAILURE;
471  auto object = createObj( *m_dataLoader, *addr ); // Call data loader
472  if ( !object ) return Status::INVALID_OBJECT;
473  auto fullpath = ( pReg ? pReg->identifier() : m_rootName.value() ) + std::string{path};
474  // the data loader expects the path _including_ the root
475  auto dummy = Entry{fullpath, {}, {}};
476  object->setRegistry( &dummy );
477  addr->setRegistry( &dummy );
478  auto status = m_dataLoader->fillObjRefs( addr.get(), object.get() );
479  if ( !status.isSuccess() ) return status;
480  // note: put will overwrite the registry in pObject to point at the
481  // one actually used -- so we do not dangle, pointing at dummy beyond its
482  // lifetime
483  if ( msgLevel( MSG::DEBUG ) ) {
484  auto ptr = object.get();
485  debug() << "registerAddress: " << std::quoted( normalize_path( fullpath, rootName() ) ) << " (DataObject*)"
486  << static_cast<void*>( ptr ) << ( ptr ? " -> " + System::typeinfoName( typeid( *ptr ) ) : std::string{} )
487  << endmsg;
488  }
489  fwd( [&]( Partition& p ) {
490  p.store.put( normalize_path( fullpath, rootName() ), std::move( object ), std::move( addr ) );
491  return StatusCode::SUCCESS;
492  } ).ignore();
493  return status;
494 }
495 StatusCode EvtStoreSvc::registerObject( std::string_view parentPath, std::string_view objectPath,
496  DataObject* pObject ) {
497  return parentPath.empty()
498  ? registerObject( nullptr, objectPath, pObject )
499  : registerObject( nullptr, std::string{parentPath}.append( "/" ).append( objectPath ), pObject );
500 }
501 StatusCode EvtStoreSvc::registerObject( DataObject* parentObj, std::string_view path, DataObject* pObject ) {
502  if ( parentObj ) return StatusCode::FAILURE;
503  return fwd( [&, object = std::unique_ptr<DataObject>( pObject ),
504  path = normalize_path( path, rootName() )]( Partition& p ) mutable {
505  if ( m_forceLeaves ) {
506  auto dir = path;
507  for ( auto i = dir.rfind( '/' ); i != std::string_view::npos; i = dir.rfind( '/' ) ) {
508  dir = dir.substr( 0, i );
509  if ( !p.store.find( dir ) ) {
510  if ( msgLevel( MSG::DEBUG ) ) {
511  debug() << "registerObject: adding directory " << std::quoted( dir ) << endmsg;
512  }
513  p.store.put( dir, std::unique_ptr<DataObject>{} );
514  }
515  }
516  }
517  if ( msgLevel( MSG::DEBUG ) ) {
518  auto ptr = object.get();
519  debug() << "registerObject: " << std::quoted( path ) << " (DataObject*)" << static_cast<void*>( ptr )
520  << ( ptr ? " -> " + System::typeinfoName( typeid( *ptr ) ) : std::string{} ) << endmsg;
521  }
522  p.store.put( path, std::move( object ) );
523  return StatusCode::SUCCESS;
524  } );
525 }
526 StatusCode EvtStoreSvc::retrieveObject( IRegistry* pDirectory, std::string_view path, DataObject*& pObject ) {
527  if ( pDirectory ) return StatusCode::FAILURE;
528  return fwd( [&]( Partition& p ) {
529  path = normalize_path( path, rootName() );
530  pObject = const_cast<DataObject*>( p.store.get( path ) );
531  if ( msgLevel( MSG::DEBUG ) ) {
532  debug() << "retrieveObject: " << std::quoted( path ) << " (DataObject*)" << (void*)pObject
533  << ( pObject ? " -> " + System::typeinfoName( typeid( *pObject ) ) : std::string{} ) << endmsg;
534  }
535  return pObject ? StatusCode::SUCCESS : StatusCode::FAILURE;
536  } );
537 }
538 StatusCode EvtStoreSvc::findObject( IRegistry* pDirectory, std::string_view path, DataObject*& pObject ) {
539  return retrieveObject( pDirectory, path, pObject );
540 }
541 StatusCode EvtStoreSvc::findObject( std::string_view fullPath, DataObject*& pObject ) {
542  return retrieveObject( nullptr, fullPath, pObject );
543 }
545  return fwd( [&]( Partition& p ) { return p.store.erase( sr ) != 0 ? StatusCode::SUCCESS : StatusCode::FAILURE; } );
546 }
548  auto i = std::find( m_preLoads.begin(), m_preLoads.begin(), item );
549  if ( i == m_preLoads.end() ) m_preLoads.push_back( item );
550  return StatusCode::SUCCESS;
551 }
553  auto i = std::remove( m_preLoads.begin(), m_preLoads.begin(), item );
554  m_preLoads.erase( i, m_preLoads.end() );
555  return StatusCode::SUCCESS;
556 }
558  for ( const auto& i : m_preLoads ) {
559  DataObject* pObj;
560  if ( msgLevel( MSG::DEBUG ) ) debug() << "Preloading " << i.path() << endmsg;
561  retrieveObject( nullptr, i.path(), pObj ).ignore();
562  }
563  return StatusCode::SUCCESS;
564 }
virtual const std::string * par() const =0
Retrieve String parameters.
#define UNLIKELY(x)
Definition: Kernel.h:106
Out1 * put(const DataObjectHandle< Out1 > &out_handle, Out2 &&out)
constexpr double sr
StatusCode setNumberOfStores(size_t slots) override
Set the number of event slots (copies of DataSvc objects).
T distance(T... args)
StatusCode setDataLoader(IConversionSvc *svc, IDataProviderSvc *dpsvc) override
IRegistry * registry() const
Get pointer to Registry.
Definition: DataObject.h:82
virtual StatusCode createObj(IOpaqueAddress *pAddress, DataObject *&refpObject)=0
Create the transient representation of an object.
Implementation of property with value of concrete type.
Definition: Property.h:370
Gaudi::StateMachine::State FSMState() const override
Definition: Service.h:62
GAUDI_API const std::string typeinfoName(const std::type_info &)
Get platform independent information about the class type.
Definition: System.cpp:308
virtual bool analyse(IRegistry *pObject, int level)=0
Analyse the data object.
StatusCode resetPreLoad() override
StatusCode updateObject(IRegistry *) override
StatusCode initialize() override
SmartIF< IConversionSvc > m_dataLoader
virtual StatusCode setDataProvider(IDataProviderSvc *pService)=0
Set Data provider service.
constexpr static const auto SUCCESS
Definition: StatusCode.h:96
std::vector< DataStoreItem > m_preLoads
Items to be pre-loaded.
Gaudi::Property< std::string > m_rootName
virtual const name_type & name() const =0
Name of the directory (or key)
StatusCode clearSubTree(DataObject *obj) override
tbb::concurrent_queue< size_t > m_freeSlots
T end(T... args)
StatusCode removePreLoadItem(const DataStoreItem &) override
StatusCode traverseSubTree(std::string_view, IDataStoreAgent *) override
StatusCode retrieveObject(IRegistry *pDirectory, std::string_view path, DataObject *&pObject) override
auto get(const Handle &handle, const Algo &, const EventContext &) -> decltype(details::deref(handle.get()))
StatusCode traverseTree(IDataStoreAgent *pAgent) override
Data provider interface definition.
T remove(T... args)
Description of the DataStoreItem class.
Definition: DataStoreItem.h:27
STL class.
Gaudi::Property< size_t > m_slots
GAUDI_API int backTrace(void **addresses, const int depth)
size_t freeSlots() override
bool exists(const DataObjID &id) override
StatusCode objectParent(const DataObject *, IRegistry *&) override
MSG::Level msgLevel() const
get the cached level (originally extracted from the embedded MsgStream)
Invalid root path object cannot be retrieved or stored.
STL class.
StatusCode linkObject(std::string_view, DataObject *) override
#define DECLARE_COMPONENT(type)
Gaudi::Property< bool > m_forceLeaves
T push_back(T... args)
MsgStream & error() const
shortcut for the method msgStream(MSG::ERROR)
StatusCode preLoad() override
std::vector< Synced< Partition > > m_partitions
The actual store(s)
StatusCode clearSubTree(std::string_view) override
This class is used for returning status codes from appropriate routines.
Definition: StatusCode.h:61
StatusCode updateObject(DataObject *) override
T append(T... args)
StatusCode finalize() override
virtual unsigned long addRef()=0
Add reference to object.
T erase(T... args)
size_t allocateStore(int evtnumber) override
Allocate a store partition for a given event number.
T lock(T... args)
The IRegistry represents the entry door to the environment any data object residing in a transient da...
Definition: IRegistry.h:32
string prefix
Definition: gaudirun.py:343
size_t getNumberOfStores() const override
MsgStream & debug() const
shortcut for the method msgStream(MSG::DEBUG)
T reset(T... args)
def end
Definition: IOTest.py:123
unsigned int CLID
Class ID definition.
Definition: ClassID.h:18
StatusCode unlinkObject(DataObject *, std::string_view) override
T clear(T... args)
StatusCode unregisterObject(std::string_view) override
virtual IOpaqueAddress * address() const =0
Retrieve opaque storage address.
T move(T... args)
virtual DataObject * object() const =0
Retrieve object behind the link.
StatusCode objectParent(const IRegistry *, IRegistry *&) override
T count(T... args)
TTHREAD_TLS(Synced< Partition > *) s_current
StatusCode unregisterAddress(IRegistry *, std::string_view) override
StatusCode objectLeaves(const IRegistry *, std::vector< IRegistry * > &) override
StatusCode unregisterObject(DataObject *obj, std::string_view sr) override
T get(T... args)
StatusCode unregisterObject(DataObject *obj) override
StatusCode linkObject(IRegistry *, std::string_view, DataObject *) override
StatusCode clearStore() override
T find(T... args)
T size(T... args)
const StatusCode & ignore() const
Ignore/check StatusCode.
Definition: StatusCode.h:164
STL class.
virtual StatusCode fillObjRefs(IOpaqueAddress *pAddress, DataObject *pObject)=0
Resolve the references of the created transient object.
StatusCode selectStore(size_t partition) override
Activate a partition object. The identifies the partition uniquely.
STL class.
Generic data agent interface.
size_t getPartitionNumber(int eventnumber) const override
Get the partition number corresponding to a given event.
Base class used to extend a class implementing other interfaces.
Definition: extends.h:20
T begin(T... args)
virtual unsigned long release()=0
release reference to object
virtual void setAddress(IOpaqueAddress *pAddress)=0
Set/Update Opaque storage address.
StatusCode freeStore(size_t partition) override
Free a store partition.
StatusCode registerAddress(std::string_view fullPath, IOpaqueAddress *pAddress) override
StatusCode objectLeaves(const DataObject *, std::vector< IRegistry * > &) override
StatusCode unlinkObject(IRegistry *, std::string_view) override
string s
Definition: gaudirun.py:328
StatusCode setRoot(std::string root_name, DataObject *pObject) override
constexpr static const auto FAILURE
Definition: StatusCode.h:97
virtual IDataProviderSvc * dataSvc() const =0
Retrieve pointer to Transient Store.
StatusCode unregisterAddress(std::string_view) override
virtual const id_type & identifier() const =0
Full identifier (or key)
AttribStringParser::Iterator begin(const AttribStringParser &parser)
virtual void setRegistry(IRegistry *r)=0
Update directory pointer.
Opaque address interface definition.
StatusCode registerObject(std::string_view parentPath, std::string_view objectPath, DataObject *pObject) override
#define GAUDI_API
Definition: Kernel.h:81
A DataObject is the base class of any identifiable object on any data store.
Definition: DataObject.h:40
T equal(T... args)
KeyedObjectManager< map > Map
Forward declaration of specialized std::map-like object manager.
Use a minimal event store implementation, and adds everything required to satisfy the IDataProviderSv...
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:202
StatusCode addPreLoadItem(const DataStoreItem &) override
StatusCode findObject(IRegistry *pDirectory, std::string_view path, DataObject *&pObject) override
static GAUDI_API void setNumConcEvents(const std::size_t &nE)
const std::string & rootName() const override
StatusCode traverseSubTree(DataObject *obj, IDataStoreAgent *pAgent) override
StatusCode unlinkObject(std::string_view) override