The Gaudi Framework  v41r0 (bdbe7744)
Loading...
Searching...
No Matches
EvtStoreSvc.cpp
Go to the documentation of this file.
1/***********************************************************************************\
2* (c) Copyright 1998-2026 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\***********************************************************************************/
11#include <Gaudi/Accumulators.h>
21#include <GaudiKernel/Service.h>
22#include <GaudiKernel/System.h>
23#include <tbb/concurrent_queue.h>
24
25#include <ThreadLocalStorage.h>
26
27#include <algorithm>
28#include <iomanip>
29#include <iterator>
30#include <map>
31#include <mutex>
32#include <stdexcept>
33#include <type_traits>
34#include <unordered_map>
35#include <utility>
36#include <vector>
37
38namespace {
39 using LocalArena = Gaudi::Arena::Monotonic<>;
40
41 template <typename T>
42 using LocalAlloc = Gaudi::Allocator::MonotonicArena<T>;
43
44 using pool_string = std::basic_string<char, std::char_traits<char>, LocalAlloc<char>>;
45
46 class Entry final : public IRegistry {
47 std::unique_ptr<DataObject> m_data;
48 std::unique_ptr<IOpaqueAddress> m_addr;
49 pool_string m_identifierStorage;
50 mutable std::optional<std::string> m_identifier;
51 static IDataProviderSvc* s_svc;
52
53 public:
54 using allocator_type = LocalAlloc<char>;
55 static void setDataProviderSvc( IDataProviderSvc* p ) { s_svc = p; }
56
57 Entry( std::string_view id, std::unique_ptr<DataObject> data, std::unique_ptr<IOpaqueAddress> addr,
58 allocator_type alloc ) noexcept
59 : m_data{ std::move( data ) }, m_addr{ std::move( addr ) }, m_identifierStorage{ id, alloc } {
60 if ( m_data ) m_data->setRegistry( this );
61 if ( m_addr ) m_addr->setRegistry( this );
62 }
63 Entry( const Entry& ) = delete;
64 Entry& operator=( const Entry& rhs ) = delete;
65 Entry( Entry&& rhs ) = delete;
66 Entry& operator=( Entry&& rhs ) = delete;
67
68 // required by IRegistry...
69 unsigned long addRef() override { return -1; }
70 unsigned long release() override { return -1; }
71 const name_type& name() const override {
72 // should really be from last '/' onward...
73 if ( !m_identifier ) m_identifier.emplace( m_identifierStorage );
74 return *m_identifier;
75 }
76 const id_type& identifier() const override {
77 if ( !m_identifier ) m_identifier.emplace( m_identifierStorage );
78 return *m_identifier;
79 }
80 std::string_view identifierView() const { return m_identifierStorage; }
81 IDataProviderSvc* dataSvc() const override { return s_svc; }
82 DataObject* object() const override { return const_cast<DataObject*>( m_data.get() ); }
83 IOpaqueAddress* address() const override { return m_addr.get(); }
84 void setAddress( IOpaqueAddress* iAddr ) override {
85 m_addr.reset( iAddr );
86 if ( m_addr ) m_addr->setRegistry( this );
87 }
88 };
89 IDataProviderSvc* Entry::s_svc = nullptr;
90
91 using UnorderedMap =
92 std::unordered_map<std::string_view, Entry, std::hash<std::string_view>, std::equal_to<std::string_view>,
93 LocalAlloc<std::pair<const std::string_view, Entry>>>;
94 using OrderedMap = std::map<std::string_view, Entry>;
95
96 template <typename Map = UnorderedMap>
97 class Store {
98 LocalArena m_resource;
99 std::size_t m_est_size;
100 // Optional purely to make [re]construction simpler, should "always" be valid
101 std::optional<Map> m_store{ std::in_place, &m_resource };
102 static_assert( std::is_same_v<typename Map::key_type, std::string_view> );
103
104 const auto& emplace( std::string_view k, std::unique_ptr<DataObject> d, std::unique_ptr<IOpaqueAddress> a = {} ) {
105 // tricky way to insert a string_view key which points to the
106 // string contained in the mapped type...
107 auto [i, b] = m_store->try_emplace( k, k, std::move( d ), std::move( a ), &m_resource );
108 if ( !b ) throw std::runtime_error( "failed to insert " + std::string{ k } );
109 auto nh = m_store->extract( i );
110 nh.key() = nh.mapped().identifierView(); // "re-point" key to the string contained in the Entry
111 auto r = m_store->insert( std::move( nh ) );
112 if ( !r.inserted ) throw std::runtime_error( "failed to insert " + std::string{ k } );
113 return r.position->second;
114 }
115
116 public:
117 Store( std::size_t est_size, std::size_t pool_size ) : m_resource{ pool_size }, m_est_size{ est_size } {}
118 [[nodiscard]] bool empty() const { return m_store->empty(); }
119 [[nodiscard]] std::size_t size() const { return m_store->size(); }
120 [[nodiscard]] std::size_t used_bytes() const noexcept { return m_resource.size(); }
121 [[nodiscard]] std::size_t used_blocks() const noexcept { return m_resource.num_blocks(); }
122 [[nodiscard]] std::size_t used_buckets() const { return m_store->bucket_count(); }
123 [[nodiscard]] std::size_t num_allocations() const noexcept { return m_resource.num_allocations(); }
124
125 void reset() {
126 m_store.reset(); // kill the old map
127 m_resource.reset(); // tell the memory pool it can start re-using its resources
128 m_store.emplace( m_est_size, &m_resource ); // initialise the new map with a sane number of buckets
129 }
130
131 const DataObject* put( std::string_view k, std::unique_ptr<DataObject> data,
132 std::unique_ptr<IOpaqueAddress> addr = {} ) {
133 return emplace( k, std::move( data ), std::move( addr ) ).object();
134 }
135 const DataObject* get( std::string_view k ) const noexcept {
136 const Entry* d = find( k );
137 return d ? d->object() : nullptr;
138 }
139 const Entry* find( std::string_view k ) const noexcept {
140 auto i = m_store->find( k );
141 return i != m_store->end() ? &( i->second ) : nullptr;
142 }
143
144 [[nodiscard]] auto begin() const noexcept { return m_store->begin(); }
145 [[nodiscard]] auto end() const noexcept { return m_store->end(); }
146 void clear() noexcept { m_store->clear(); }
147 auto erase( std::string_view k ) { return m_store->erase( k ); }
148 template <typename Predicate>
149 void erase_if( Predicate p ) {
150 auto i = m_store->begin();
151 auto end = m_store->end();
152 while ( i != end ) {
153 if ( std::invoke( p, std::as_const( *i ) ) )
154 i = m_store->erase( i );
155 else
156 ++i;
157 }
158 }
159 };
160
161 StatusCode dummy( const std::string& s ) {
162 std::string trace;
163 System::backTrace( trace, 6, 2 );
164 throw std::logic_error{ "Unsupported Function Called: " + s + "\n" + trace };
165 return StatusCode::FAILURE;
166 }
167
168 std::string_view normalize_path( std::string_view path, std::string_view prefix ) {
169 if ( path.size() >= prefix.size() && std::equal( prefix.begin(), prefix.end(), path.begin() ) )
170 path.remove_prefix( prefix.size() );
171 if ( !path.empty() && path.front() == '/' ) path.remove_prefix( 1 );
172 return path;
173 }
174
175 std::unique_ptr<DataObject> createObj( IConversionSvc& cnv, IOpaqueAddress& addr ) {
176 DataObject* pObject = nullptr;
177 auto status = cnv.createObj( &addr, pObject ); // Call data loader
178 auto object = std::unique_ptr<DataObject>( pObject );
179 if ( status.isFailure() ) object.reset();
180 return object;
181 }
182
183 // HiveWhiteBoard helpers
184 struct Partition final {
185 // Use optional to allow re-constructing in-place without an ugly
186 // exception-unsafe placement-new conconction, and also to make it easier
187 // to pass constructor arguments to Store<>.
188 std::optional<Store<>> store;
189 int eventNumber = -1;
190 std::string_view onlyThisID{};
191 };
193
194 TTHREAD_TLS( SynchronizedPartition* ) s_current = nullptr;
195
196 template <typename Fun>
197 StatusCode fwd( Fun&& f ) {
198 return s_current ? s_current->with_lock( std::forward<Fun>( f ) )
200 }
201
202} // namespace
203
214class GAUDI_API EvtStoreSvc : public extends<Service, IDataProviderSvc, IDataManagerSvc, IHiveWhiteBoard,
215 Gaudi::Concurrency::ConcurrencyManager> {
216 Gaudi::Property<CLID> m_rootCLID{ this, "RootCLID", 110 /*CLID_Event*/, "CLID of root entry" };
217 Gaudi::Property<std::string> m_rootName{ this, "RootName", "/Event", "name of root entry" };
218 Gaudi::Property<bool> m_forceLeaves{ this, "ForceLeaves", false,
219 "force creation of default leaves on registerObject" };
220 Gaudi::Property<std::string> m_loader{ this, "DataLoader", "EventPersistencySvc" };
221 Gaudi::Property<size_t> m_slots{ this, "EventSlots", 1, "number of event slots" };
222 Gaudi::Property<bool> m_printPoolStats{ this, "PrintPoolStats", false, "Print memory pool statistics" };
223 Gaudi::Property<std::size_t> m_poolSize{ this, "PoolSize", 1024, "Initial per-event memory pool size [KiB]" };
225 "Estimated number of buckets in the store" };
228
229 // Convert to bytes
230 std::size_t poolSize() const { return m_poolSize * 1024; }
231
232 void fillStats( Partition& p ) const {
233 if ( !m_printPoolStats ) return;
234 auto n_allocs = p.store->num_allocations();
235 if ( n_allocs ) {
236 m_storeEntries += p.store->size();
237 m_usedPoolSize += p.store->used_bytes();
238 m_storeBuckets += p.store->used_buckets();
239 m_usedPoolAllocations += p.store->used_blocks();
240 m_servedPoolAllocations += n_allocs;
241 }
242 }
243
244 void initStore( Partition& p ) const {
245 if ( p.store ) {
246 // re-use the existing memory pool
247 p.store->reset();
248 } else {
249 p.store.emplace( m_estStoreBuckets, poolSize() );
250 }
251 }
252
254
256 std::vector<DataStoreItem> m_preLoads;
257
259 std::vector<SynchronizedPartition> m_partitions;
260
261 tbb::concurrent_queue<size_t> m_freeSlots;
262
264 this,
265 "InhibitedPathPrefixes",
266 {},
267 "Prefixes of TES locations that will not be loaded by the persistency service " };
269 this, "FollowLinksToAncestors", true,
270 "Load objects which reside in files other than the one corresponding to the root of the event store" };
271
272public:
273 using extends::extends;
274
275 CLID rootCLID() const override;
276 const std::string& rootName() const override;
277 StatusCode setDataLoader( IConversionSvc* svc, IDataProviderSvc* dpsvc ) override;
278
279 size_t allocateStore( int evtnumber ) override;
280 StatusCode freeStore( size_t partition ) override;
281 size_t freeSlots() override { return m_freeSlots.unsafe_size(); }
282 StatusCode selectStore( size_t partition ) override;
283 StatusCode clearStore() override;
284 StatusCode clearStore( size_t partition ) override;
285 StatusCode setNumberOfStores( size_t slots ) override;
286 size_t getNumberOfStores() const override { return m_slots; }
287 size_t getPartitionNumber( int eventnumber ) const override;
288 bool exists( const DataObjID& id ) override {
289 DataObject* pObject{ nullptr };
290 return findObject( id.fullKey(), pObject ).isSuccess();
291 }
292
293 StatusCode objectParent( const DataObject*, IRegistry*& ) override { return dummy( __FUNCTION__ ); }
294 StatusCode objectParent( const IRegistry*, IRegistry*& ) override { return dummy( __FUNCTION__ ); }
295 // Objects have no leaves, so just return success
296 StatusCode objectLeaves( const DataObject*, std::vector<IRegistry*>& ) override { return StatusCode::SUCCESS; }
297 StatusCode objectLeaves( const IRegistry*, std::vector<IRegistry*>& ) override { return StatusCode::SUCCESS; }
298
299 StatusCode clearSubTree( std::string_view ) override;
301 return obj && obj->registry() ? clearSubTree( obj->registry()->identifier() ) : StatusCode::FAILURE;
302 }
303
304 StatusCode traverseSubTree( std::string_view, IDataStoreAgent* ) override;
306 return ( obj && obj->registry() ) ? traverseSubTree( obj->registry()->identifier(), pAgent ) : StatusCode::FAILURE;
307 }
308 StatusCode traverseTree( IDataStoreAgent* pAgent ) override { return traverseSubTree( std::string_view{}, pAgent ); }
309
310 StatusCode setRoot( std::string root_name, DataObject* pObject ) override;
311 StatusCode setRoot( std::string root_path, IOpaqueAddress* pRootAddr ) override;
312
313 StatusCode unregisterAddress( std::string_view ) override { return dummy( __FUNCTION__ ); };
314 StatusCode unregisterAddress( IRegistry*, std::string_view ) override { return dummy( __FUNCTION__ ); };
315
316 StatusCode registerAddress( std::string_view fullPath, IOpaqueAddress* pAddress ) override;
317 StatusCode registerAddress( IRegistry* parentObj, std::string_view objectPath, IOpaqueAddress* pAddress ) override;
318 StatusCode registerObject( std::string_view parentPath, std::string_view objectPath, DataObject* pObject ) override;
319 StatusCode registerObject( DataObject* parentObj, std::string_view objectPath, DataObject* pObject ) override;
320
321 StatusCode unregisterObject( std::string_view ) override;
323 return ( obj && obj->registry() ) ? unregisterObject( obj->registry()->identifier() ) : StatusCode::FAILURE;
324 }
325 StatusCode unregisterObject( DataObject* obj, std::string_view sr ) override {
326 return !obj ? unregisterObject( sr )
327 : obj->registry() ? unregisterObject( ( obj->registry()->identifier() + '/' ).append( sr ) )
329 };
330
331 StatusCode retrieveObject( IRegistry* pDirectory, std::string_view path, DataObject*& pObject ) override;
332
333 StatusCode findObject( IRegistry* pDirectory, std::string_view path, DataObject*& pObject ) override;
334 StatusCode findObject( std::string_view fullPath, DataObject*& pObject ) override;
335
336 StatusCode updateObject( IRegistry* ) override { return dummy( __FUNCTION__ ); }
337 StatusCode updateObject( DataObject* ) override { return dummy( __FUNCTION__ ); }
338
339 StatusCode addPreLoadItem( const DataStoreItem& ) override;
340 StatusCode removePreLoadItem( const DataStoreItem& ) override;
342 m_preLoads.clear();
343 return StatusCode::SUCCESS;
344 }
345 StatusCode preLoad() override;
346
347 StatusCode linkObject( IRegistry*, std::string_view, DataObject* ) override { return dummy( __FUNCTION__ ); }
348 StatusCode linkObject( std::string_view, DataObject* ) override { return dummy( __FUNCTION__ ); }
349 StatusCode unlinkObject( IRegistry*, std::string_view ) override { return dummy( __FUNCTION__ ); }
350 StatusCode unlinkObject( DataObject*, std::string_view ) override { return dummy( __FUNCTION__ ); }
351 StatusCode unlinkObject( std::string_view ) override { return dummy( __FUNCTION__ ); }
352
354 Entry::setDataProviderSvc( this );
355 extends::initialize().ignore();
356 if ( !setNumberOfStores( m_slots ).isSuccess() ) {
357 error() << "Cannot set number of slots" << endmsg;
358 return StatusCode::FAILURE;
359 }
360 m_partitions = std::vector<SynchronizedPartition>( m_slots );
361 // m_partitions is now full of empty std::optionals, fill them now.
362 for ( auto& synced_p : m_partitions ) {
363 synced_p.with_lock( [this]( Partition& p ) { initStore( p ); } );
364 }
365 for ( size_t i = 0; i < m_slots; i++ ) { m_freeSlots.push( i ); }
366 selectStore( 0 ).ignore();
367
368 auto loader = serviceLocator()->service( m_loader ).as<IConversionSvc>().get();
369 if ( !loader ) {
370 error() << "Cannot get IConversionSvc " << m_loader.value() << endmsg;
371 return StatusCode::FAILURE;
372 }
373 return setDataLoader( loader, nullptr );
374 }
375 StatusCode finalize() override {
376 if ( m_printPoolStats ) {
377 info() << "Mean memory pool usage: " << float( 1e-3f * float( m_usedPoolSize.mean() ) ) << " KiB serving "
378 << float( m_servedPoolAllocations.mean() ) << " allocations from " << float( m_usedPoolAllocations.mean() )
379 << " to produce " << float( m_storeEntries.mean() ) << " entries in " << float( m_storeBuckets.mean() )
380 << " buckets" << endmsg;
381 }
382 setDataLoader( nullptr, nullptr ).ignore(); // release
383 return extends::finalize();
384 }
385};
386
387// Instantiation of a static factory class used by clients to create
388// instances of this service
390
392const std::string& EvtStoreSvc::rootName() const { return m_rootName; }
394 m_dataLoader = pDataLoader;
395 if ( m_dataLoader ) m_dataLoader->setDataProvider( dpsvc ? dpsvc : this ).ignore();
396 return StatusCode::SUCCESS;
397}
398
399size_t EvtStoreSvc::allocateStore( int evtnumber ) {
400 // take next free slot in the list
401 size_t slot = std::string::npos;
402 if ( m_freeSlots.try_pop( slot ) ) {
403 assert( slot != std::string::npos );
404 assert( slot < m_partitions.size() );
405 [[maybe_unused]] auto prev = m_partitions[slot].with_lock(
406 [evtnumber]( Partition& p ) { return std::exchange( p.eventNumber, evtnumber ); } );
407 assert( prev == -1 ); // or whatever value represents 'free'
408 }
409 return slot;
410}
411
413 if ( slots < size_t{ 1 } ) {
414 error() << "Invalid number of slots (" << slots << ")" << endmsg;
415 return StatusCode::FAILURE;
416 }
418 error() << "Too late to change the number of slots!" << endmsg;
419 return StatusCode::FAILURE;
420 }
421 m_slots = slots;
423 return StatusCode::SUCCESS;
424}
425
426size_t EvtStoreSvc::getPartitionNumber( int eventnumber ) const {
427 auto i = std::find_if(
428 begin( m_partitions ), end( m_partitions ),
429 Gaudi::cxx::with_lock( [eventnumber]( const Partition& p ) { return p.eventNumber == eventnumber; } ) );
430 return i != end( m_partitions ) ? std::distance( begin( m_partitions ), i ) : std::string::npos;
431}
432
434 s_current = &m_partitions[partition];
435 return StatusCode::SUCCESS;
436}
437
439 assert( partition < m_partitions.size() );
440 auto prev = m_partitions[partition].with_lock( []( Partition& p ) { return std::exchange( p.eventNumber, -1 ); } );
441 if ( prev == -1 ) return StatusCode::FAILURE; // double free -- should never happen!
442 m_freeSlots.push( partition );
443 return StatusCode::SUCCESS;
444}
445
447 return m_partitions[partition].with_lock( [this]( Partition& p ) {
448 p.onlyThisID = {};
449 fillStats( p );
450 initStore( p ); // replace with a clean store
451 return StatusCode::SUCCESS;
452 } );
453}
454StatusCode EvtStoreSvc::clearSubTree( std::string_view top ) {
455 top = normalize_path( top, rootName() );
456 return fwd( [&]( Partition& p ) {
457 p.store->erase_if( [top]( const auto& value ) { return value.first.starts_with( top ); } );
458 return StatusCode::SUCCESS;
459 } );
460}
462 return fwd( [this]( Partition& p ) {
463 p.onlyThisID = {};
464 fillStats( p );
465 initStore( p ); // replace with a clean store
466 return StatusCode::SUCCESS;
467 } );
468}
470 return fwd( [&]( Partition& p ) {
471 top = normalize_path( top, rootName() );
472 unsigned int nbSlashesInRootName = std::count( rootName().begin(), rootName().end(), '/' );
473 auto cmp = []( const Entry* lhs, const Entry* rhs ) { return lhs->identifier() < rhs->identifier(); };
474 std::set<const Entry*, decltype( cmp )> keys{ std::move( cmp ) };
475 for ( const auto& v : *p.store ) {
476 if ( v.second.identifier().starts_with( top ) ) keys.insert( &v.second );
477 }
478 auto k = keys.begin();
479 while ( k != keys.end() ) {
480 const auto& id = ( *k )->identifier();
481 int level = std::count( id.begin(), id.end(), '/' ) + nbSlashesInRootName;
482 bool accept = pAgent->analyse( const_cast<Entry*>( *( k++ ) ), level );
483 if ( !accept ) {
484 k = std::find_if_not( k, keys.end(), [&id]( const auto& e ) { return e->identifier().starts_with( id ); } );
485 }
486 }
487 return StatusCode::SUCCESS;
488 } );
489}
490StatusCode EvtStoreSvc::setRoot( std::string root_path, DataObject* pObject ) {
491 if ( msgLevel( MSG::DEBUG ) ) {
492 debug() << "setRoot( " << root_path << ", (DataObject*)" << (void*)pObject << " )" << endmsg;
493 }
494 if ( !fwd( []( Partition& p ) {
495 return p.store->empty() ? StatusCode::SUCCESS : StatusCode::FAILURE;
496 } ).isSuccess() ) {
497 throw GaudiException{ "setRoot called with non-empty store", "EvtStoreSvc", StatusCode::FAILURE };
498 }
499 return registerObject( nullptr, root_path, pObject );
500}
501StatusCode EvtStoreSvc::setRoot( std::string root_path, IOpaqueAddress* pRootAddr ) {
502 auto rootAddr = std::unique_ptr<IOpaqueAddress>( pRootAddr );
503 if ( msgLevel( MSG::DEBUG ) ) {
504 debug() << "setRoot( " << root_path << ", (IOpaqueAddress*)" << rootAddr.get();
505 if ( rootAddr ) debug() << "[ " << rootAddr->par()[0] << ", " << rootAddr->par()[1] << " ]";
506 debug() << " )" << endmsg;
507 }
508 if ( !fwd( []( Partition& p ) {
509 return p.store->empty() ? StatusCode::SUCCESS : StatusCode::FAILURE;
510 } ).isSuccess() ) {
511 throw GaudiException{ "setRoot called with non-empty store", "EvtStoreSvc", StatusCode::FAILURE };
512 }
513 if ( !rootAddr ) return Status::INVALID_OBJ_ADDR; // Precondition: Address must be valid
515 fwd( [&]( Partition& p ) {
516 p.onlyThisID = rootAddr->par()[0];
517 return StatusCode::SUCCESS;
518 } ).ignore();
519 }
520 auto object = createObj( *m_dataLoader, *rootAddr ); // Call data loader
521 if ( !object ) return Status::INVALID_OBJECT;
522 if ( msgLevel( MSG::DEBUG ) ) { debug() << "Root Object " << root_path << " created " << endmsg; }
523 LocalArena dummy_arena{ root_path.size() + 1 };
524 auto dummy = Entry{ root_path, {}, {}, &dummy_arena };
525 object->setRegistry( &dummy );
526 rootAddr->setRegistry( &dummy );
527 auto status = m_dataLoader->fillObjRefs( rootAddr.get(), object.get() );
528 if ( status.isSuccess() ) {
529 auto pObject = object.get();
530 status = registerObject( nullptr, root_path, object.release() );
531 if ( status.isSuccess() ) pObject->registry()->setAddress( rootAddr.release() );
532 }
533 return status;
534}
536 return registerAddress( nullptr, path, pAddr );
537}
538StatusCode EvtStoreSvc::registerAddress( IRegistry* pReg, std::string_view path, IOpaqueAddress* pAddr ) {
539 auto addr = std::unique_ptr<IOpaqueAddress>( pAddr );
540 if ( !addr ) return Status::INVALID_OBJ_ADDR; // Precondition: Address must be valid
541 if ( msgLevel( MSG::DEBUG ) ) {
542 debug() << "registerAddress( (IRegistry*)" << (void*)pReg << ", " << path << ", (IOpaqueAddress*)" << addr.get()
543 << "[ " << addr->par()[0] << ", " << addr->par()[1] << " ]"
544 << " )" << endmsg;
545 }
546 if ( path.empty() || path[0] != '/' ) return StatusCode::FAILURE;
547 const auto onlyThisID =
548 s_current ? s_current->with_lock( []( const Partition& p ) { return p.onlyThisID; } ) : std::string_view{};
549 if ( !onlyThisID.empty() && addr->par()[0] != onlyThisID ) {
550 if ( msgLevel( MSG::DEBUG ) )
551 debug() << "Attempt to load " << addr->par()[1] << " from file " << addr->par()[0] << " blocked -- different file"
552 << endmsg;
553 return StatusCode::SUCCESS;
554 }
555 if ( std::any_of(
557 [addrPath = addr->par()[1]]( std::string_view prefix ) { return addrPath.starts_with( prefix ); } ) ) {
558 if ( msgLevel( MSG::DEBUG ) )
559 debug() << "Attempt to load " << addr->par()[1] << " from file " << addr->par()[0] << " blocked -- path inhibited"
560 << endmsg;
561 return StatusCode::SUCCESS;
562 }
563
564 auto object = createObj( *m_dataLoader, *addr ); // Call data loader
565 if ( !object ) return Status::INVALID_OBJECT;
566 auto fullpath = ( pReg ? pReg->identifier() : m_rootName.value() ) + std::string{ path };
567 // the data loader expects the path _including_ the root
568 LocalArena dummy_arena{ fullpath.size() + 1 };
569 auto dummy = Entry{ fullpath, {}, {}, &dummy_arena };
570 object->setRegistry( &dummy );
571 addr->setRegistry( &dummy );
572 auto status = m_dataLoader->fillObjRefs( addr.get(), object.get() );
573 if ( !status.isSuccess() ) return status;
574 // note: put will overwrite the registry in pObject to point at the
575 // one actually used -- so we do not dangle, pointing at dummy beyond its
576 // lifetime
577 if ( msgLevel( MSG::DEBUG ) ) {
578 auto ptr = object.get();
579 debug() << "registerAddress: " << std::quoted( normalize_path( fullpath, rootName() ) ) << " (DataObject*)"
580 << static_cast<void*>( ptr ) << ( ptr ? " -> " + System::typeinfoName( typeid( *ptr ) ) : std::string{} )
581 << endmsg;
582 }
583 fwd( [&]( Partition& p ) {
584 p.store->put( normalize_path( fullpath, rootName() ), std::move( object ), std::move( addr ) );
585 return StatusCode::SUCCESS;
586 } ).ignore();
587 return status;
588}
589StatusCode EvtStoreSvc::registerObject( std::string_view parentPath, std::string_view objectPath,
590 DataObject* pObject ) {
591 return parentPath.empty()
592 ? registerObject( nullptr, objectPath, pObject )
593 : registerObject( nullptr, std::string{ parentPath }.append( "/" ).append( objectPath ), pObject );
594}
595StatusCode EvtStoreSvc::registerObject( DataObject* parentObj, std::string_view path, DataObject* pObject ) {
596 if ( parentObj ) return StatusCode::FAILURE;
597 return fwd( [&, object = std::unique_ptr<DataObject>( pObject ),
598 path = normalize_path( path, rootName() )]( Partition& p ) mutable {
599 if ( m_forceLeaves ) {
600 auto dir = path;
601 for ( auto i = dir.rfind( '/' ); i != std::string_view::npos; i = dir.rfind( '/' ) ) {
602 dir = dir.substr( 0, i );
603 if ( !p.store->find( dir ) ) {
604 if ( msgLevel( MSG::DEBUG ) ) {
605 debug() << "registerObject: adding directory " << std::quoted( dir ) << endmsg;
606 }
607 p.store->put( dir, std::unique_ptr<DataObject>{} );
608 }
609 }
610 }
611 if ( msgLevel( MSG::DEBUG ) ) {
612 auto ptr = object.get();
613 debug() << "registerObject: " << std::quoted( path ) << " (DataObject*)" << static_cast<void*>( ptr )
614 << ( ptr ? " -> " + System::typeinfoName( typeid( *ptr ) ) : std::string{} ) << endmsg;
615 }
616 p.store->put( path, std::move( object ) );
617 return StatusCode::SUCCESS;
618 } );
619}
620StatusCode EvtStoreSvc::retrieveObject( IRegistry* pDirectory, std::string_view path, DataObject*& pObject ) {
621 if ( pDirectory ) return StatusCode::FAILURE;
622 return fwd( [&]( Partition& p ) {
623 path = normalize_path( path, rootName() );
624 pObject = const_cast<DataObject*>( p.store->get( path ) );
625 if ( msgLevel( MSG::DEBUG ) ) {
626 debug() << "retrieveObject: " << std::quoted( path ) << " (DataObject*)" << (void*)pObject
627 << ( pObject ? " -> " + System::typeinfoName( typeid( *pObject ) ) : std::string{} ) << endmsg;
628 }
629 return pObject ? StatusCode::SUCCESS : StatusCode::FAILURE;
630 } );
631}
632StatusCode EvtStoreSvc::findObject( IRegistry* pDirectory, std::string_view path, DataObject*& pObject ) {
633 return retrieveObject( pDirectory, path, pObject );
634}
635StatusCode EvtStoreSvc::findObject( std::string_view fullPath, DataObject*& pObject ) {
636 return retrieveObject( nullptr, fullPath, pObject );
637}
639 sr = normalize_path( sr, rootName() );
640 return fwd( [&]( Partition& p ) { return p.store->erase( sr ) != 0 ? StatusCode::SUCCESS : StatusCode::FAILURE; } );
641}
643 auto i = std::find( m_preLoads.begin(), m_preLoads.end(), item );
644 if ( i == m_preLoads.end() ) m_preLoads.push_back( item );
645 return StatusCode::SUCCESS;
646}
648 auto i = std::remove( m_preLoads.begin(), m_preLoads.begin(), item );
649 m_preLoads.erase( i, m_preLoads.end() );
650 return StatusCode::SUCCESS;
651}
653 for ( const auto& i : m_preLoads ) {
654 DataObject* pObj;
655 if ( msgLevel( MSG::DEBUG ) ) debug() << "Preloading " << i.path() << endmsg;
656 retrieveObject( nullptr, i.path(), pObj ).ignore();
657 }
658 return StatusCode::SUCCESS;
659}
unsigned int CLID
Class ID definition.
Definition ClassID.h:16
TTHREAD_TLS(SynchronizedPartition *) s_current
#define GAUDI_API
Definition Kernel.h:49
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition MsgStream.h:198
#define DECLARE_COMPONENT(type)
MsgStream & error() const
shortcut for the method msgStream(MSG::ERROR)
MsgStream & debug() const
shortcut for the method msgStream(MSG::DEBUG)
MsgStream & info() const
shortcut for the method msgStream(MSG::INFO)
MSG::Level msgLevel() const
get the cached level (originally extracted from the embedded MsgStream)
A DataObject is the base class of any identifiable object on any data store.
Definition DataObject.h:37
IRegistry * registry() const
Get pointer to Registry.
Definition DataObject.h:79
Description of the DataStoreItem class.
Use a minimal event store implementation, and adds everything required to satisfy the IDataProviderSv...
Gaudi::Property< std::size_t > m_poolSize
Gaudi::Accumulators::AveragingCounter< std::size_t > m_usedPoolAllocations
StatusCode updateObject(IRegistry *) override
bool exists(const DataObjID &id) override
StatusCode unlinkObject(IRegistry *, std::string_view) override
Gaudi::Property< std::vector< std::string > > m_inhibitPrefixes
StatusCode objectLeaves(const IRegistry *, std::vector< IRegistry * > &) override
StatusCode setDataLoader(IConversionSvc *svc, IDataProviderSvc *dpsvc) override
StatusCode finalize() override
SmartIF< IConversionSvc > m_dataLoader
StatusCode traverseSubTree(std::string_view, IDataStoreAgent *) override
StatusCode preLoad() override
StatusCode addPreLoadItem(const DataStoreItem &) override
StatusCode retrieveObject(IRegistry *pDirectory, std::string_view path, DataObject *&pObject) override
std::size_t poolSize() const
StatusCode unregisterAddress(IRegistry *, std::string_view) override
Gaudi::Property< bool > m_followLinksToAncestors
StatusCode updateObject(DataObject *) override
Gaudi::Accumulators::AveragingCounter< std::size_t > m_storeBuckets
StatusCode findObject(IRegistry *pDirectory, std::string_view path, DataObject *&pObject) override
StatusCode removePreLoadItem(const DataStoreItem &) override
StatusCode unregisterObject(DataObject *obj) override
size_t freeSlots() override
StatusCode clearSubTree(std::string_view) override
Gaudi::Property< size_t > m_slots
StatusCode traverseTree(IDataStoreAgent *pAgent) override
StatusCode selectStore(size_t partition) override
Activate a partition object. The identifies the partition uniquely.
Gaudi::Property< CLID > m_rootCLID
StatusCode initialize() override
StatusCode unregisterAddress(std::string_view) override
StatusCode traverseSubTree(DataObject *obj, IDataStoreAgent *pAgent) override
StatusCode registerAddress(std::string_view fullPath, IOpaqueAddress *pAddress) override
Gaudi::Property< std::string > m_loader
Gaudi::Accumulators::AveragingCounter< std::size_t > m_servedPoolAllocations
StatusCode unregisterObject(std::string_view) override
Gaudi::Property< bool > m_printPoolStats
void fillStats(Partition &p) const
StatusCode setNumberOfStores(size_t slots) override
Set the number of event slots (copies of DataSvc objects).
std::vector< SynchronizedPartition > m_partitions
The actual store(s).
StatusCode objectParent(const IRegistry *, IRegistry *&) override
StatusCode objectParent(const DataObject *, IRegistry *&) override
StatusCode unregisterObject(DataObject *obj, std::string_view sr) override
void initStore(Partition &p) const
size_t getPartitionNumber(int eventnumber) const override
Get the partition number corresponding to a given event.
StatusCode setRoot(std::string root_name, DataObject *pObject) override
StatusCode clearSubTree(DataObject *obj) override
size_t getNumberOfStores() const override
StatusCode registerObject(std::string_view parentPath, std::string_view objectPath, DataObject *pObject) override
Gaudi::Accumulators::AveragingCounter< std::size_t > m_usedPoolSize
StatusCode resetPreLoad() override
tbb::concurrent_queue< size_t > m_freeSlots
StatusCode linkObject(IRegistry *, std::string_view, DataObject *) override
Gaudi::Property< bool > m_forceLeaves
Gaudi::Accumulators::AveragingCounter< std::size_t > m_storeEntries
StatusCode freeStore(size_t partition) override
Free a store partition.
size_t allocateStore(int evtnumber) override
Allocate a store partition for a given event number.
const std::string & rootName() const override
Gaudi::Property< std::size_t > m_estStoreBuckets
Gaudi::Property< std::string > m_rootName
CLID rootCLID() const override
StatusCode objectLeaves(const DataObject *, std::vector< IRegistry * > &) override
StatusCode linkObject(std::string_view, DataObject *) override
StatusCode clearStore() override
StatusCode unlinkObject(std::string_view) override
StatusCode unlinkObject(DataObject *, std::string_view) override
std::vector< DataStoreItem > m_preLoads
Items to be pre-loaded.
A fast memory arena that does not track deallocations.
Definition Monotonic.h:46
static void setNumConcEvents(const std::size_t &nE)
Set the number of concurrent events (for MT).
Implementation of property with value of concrete type.
Definition Property.h:35
Define general base for Gaudi exception.
virtual StatusCode createObj(IOpaqueAddress *pAddress, DataObject *&refpObject)=0
Create the transient representation of an object.
Data provider interface definition.
@ INVALID_ROOT
Invalid root path object cannot be retrieved or stored.
Generic data agent interface.
virtual bool analyse(IRegistry *pObject, int level)=0
Analyse the data object.
Opaque address interface definition.
virtual void setRegistry(IRegistry *r)=0
Update directory pointer.
virtual const std::string * par() const =0
Retrieve String parameters.
The IRegistry represents the entry door to the environment any data object residing in a transient da...
Definition IRegistry.h:29
virtual const id_type & identifier() const =0
Full identifier (or key).
virtual void setAddress(IOpaqueAddress *pAddress)=0
Set/Update Opaque storage address.
Gaudi::StateMachine::State FSMState() const override
Definition Service.h:55
SmartIF< ISvcLocator > & serviceLocator() const override
Retrieve pointer to service locator.
Definition Service.cpp:336
Small smart pointer class with automatic reference counting for IInterface.
Definition SmartIF.h:28
This class is used for returning status codes from appropriate routines.
Definition StatusCode.h:64
void ignore() const
Allow discarding a StatusCode without warning.
Definition StatusCode.h:128
constexpr static const auto SUCCESS
Definition StatusCode.h:99
constexpr static const auto FAILURE
Definition StatusCode.h:100
Base class used to extend a class implementing other interfaces.
Definition extends.h:19
::Gaudi::Allocator::Arena<::Gaudi::Arena::Monotonic< Alignment, UpstreamAllocator >, T, DefaultResource > MonotonicArena
Definition Monotonic.h:170
auto put(const DataObjectHandle< Out1 > &out_handle, Out2 &&out)
Definition details.h:100
GAUDI_API std::string path(const AIDA::IBaseHistogram *aida)
get the path in THS for AIDA histogram
AttribStringParser::Iterator begin(const AttribStringParser &parser)
auto with_lock(Fun &&f)
get
decorate the vector of properties
Definition decorators.py:94
@ DEBUG
Definition IMessageSvc.h:22
GAUDI_API int backTrace(void **addresses, const int depth)
Definition System.cpp:357
GAUDI_API const std::string typeinfoName(const std::type_info &)
Get platform independent information about the class type.
Definition System.cpp:254
str release
Definition conf.py:27
constexpr auto size(const T &, Args &&...) noexcept
str prefix
Definition gaudirun.py:361
A counter aiming at computing sum and average.