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