@@ -422,37 +422,35 @@ class InputRecord
422422 auto id = ObjectCache::Id::fromRef (ref);
423423 ConcreteDataMatcher matcher{header->dataOrigin , header->dataDescription , header->subSpecification };
424424 // If the matcher does not have an entry in the cache, deserialise it
425- // and cache the deserialised object at the given id .
425+ // and cache the deserialised object alongside its id, keyed by path .
426426 auto path = fmt::format (" {}" , DataSpecUtils::describe (matcher));
427427 LOGP (debug, " {}" , path);
428428 auto & cache = mRegistry .get <ObjectCache>();
429429 auto & callbacks = mRegistry .get <CallbackService>();
430- auto cacheEntry = cache.matcherToId .find (path);
431- if (cacheEntry == cache.matcherToId .end ()) {
432- cache.matcherToId .insert (std::make_pair (path, id));
430+ auto cacheEntry = cache.matcherToEntry .find (path);
431+ if (cacheEntry == cache.matcherToEntry .end ()) {
433432 std::unique_ptr<ValueT const , Deleter<ValueT const >> result (DataRefUtils::as<CCDBSerialized<ValueT>>(ref).release (), false );
434433 void * obj = (void *)result.get ();
435434 callbacks.call <CallbackService::Id::CCDBDeserialised>((ConcreteDataMatcher&)matcher, (void *)obj);
436- cache.idToObject [id] = obj;
435+ cache.matcherToEntry . emplace (path, ObjectCache::Entry{id, obj}) ;
437436 LOGP (info, " Caching in {} ptr to {} ({})" , id.value , path, obj);
438437 return result;
439438 }
440- auto & oldId = cacheEntry->second ;
439+ auto & entry = cacheEntry->second ;
441440 // The id in the cache is the same, let's simply return it.
442- if (oldId .value == id.value ) {
443- std::unique_ptr<ValueT const , Deleter<ValueT const >> result ((ValueT const *)cache. idToObject [id] , false );
441+ if (entry. id .value == id.value ) {
442+ std::unique_ptr<ValueT const , Deleter<ValueT const >> result ((ValueT const *)entry. obj , false );
444443 LOGP (debug, " Returning cached entry {} for {} ({})" , id.value , path, (void *)result.get ());
445444 return result;
446445 }
447- // The id in the cache is different. Let's destroy the old cached entry
448- // and create a new one.
449- delete reinterpret_cast <ValueT*>(cache.idToObject [oldId]);
446+ // The id in the cache is different. Destroy this path's previously cached object and replace it.
447+ delete reinterpret_cast <ValueT*>(entry.obj );
450448 std::unique_ptr<ValueT const , Deleter<ValueT const >> result (DataRefUtils::as<CCDBSerialized<ValueT>>(ref).release (), false );
451449 void * obj = (void *)result.get ();
452450 callbacks.call <CallbackService::Id::CCDBDeserialised>((ConcreteDataMatcher&)matcher, (void *)obj);
453- cache. idToObject [id] = obj;
454- LOGP (info, " Replacing cached entry {} with {} for {} ({}) " , oldId. value , id. value , path, obj) ;
455- oldId. value = id. value ;
451+ LOGP (info, " Replacing cached entry {} with {} for {} ({}) " , entry. id . value , id. value , path, obj) ;
452+ entry. id = id ;
453+ entry. obj = obj ;
456454 return result;
457455 } else {
458456 throw runtime_error (" Attempt to extract object from message with unsupported serialization type" );
@@ -503,30 +501,28 @@ class InputRecord
503501 // it's updated.
504502 auto id = ObjectCache::Id::fromRef (ref);
505503 ConcreteDataMatcher matcher{header->dataOrigin , header->dataDescription , header->subSpecification };
506- // If the matcher does not have an entry in the cache, deserialise it
507- // and cache the deserialised object at the given id.
504+ // If the matcher does not have an entry in the cache, deserialise it and cache it per path.
508505 auto path = fmt::format (" {}" , DataSpecUtils::describe (matcher));
509506 LOGP (debug, " {}" , path);
510507 auto & cache = mRegistry .get <ObjectCache>();
511- auto cacheEntry = cache.matcherToMetadataId .find (path);
512- if (cacheEntry == cache.matcherToMetadataId .end ()) {
513- cache.matcherToMetadataId . insert ( std::make_pair (path, id));
514- cache. idToMetadata [id] = DataRefUtils::extractCCDBHeaders (ref);
508+ auto cacheEntry = cache.matcherToMetadata .find (path);
509+ if (cacheEntry == cache.matcherToMetadata .end ()) {
510+ auto [it, inserted] = cache.matcherToMetadata . emplace (
511+ path, ObjectCache::MetadataEntry{id, DataRefUtils::extractCCDBHeaders (ref)} );
515512 LOGP (info, " Caching CCDB metadata {}: {}" , id.value , path);
516- return cache. idToMetadata [id] ;
513+ return it-> second . metadata ;
517514 }
518- auto & oldId = cacheEntry->second ;
515+ auto & entry = cacheEntry->second ;
519516 // The id in the cache is the same, let's simply return it.
520- if (oldId .value == id.value ) {
517+ if (entry. id .value == id.value ) {
521518 LOGP (debug, " Returning cached CCDB metatada {}: {}" , id.value , path);
522- return cache. idToMetadata [id] ;
519+ return entry. metadata ;
523520 }
524- // The id in the cache is different. Let's destroy the old cached entry
525- // and create a new one.
526- LOGP (info, " Replacing cached entry {} with {} for {}" , oldId.value , id.value , path);
527- cache.idToMetadata [id] = DataRefUtils::extractCCDBHeaders (ref);
528- oldId.value = id.value ;
529- return cache.idToMetadata [id];
521+ // The id in the cache is different. Replace this path's metadata.
522+ LOGP (info, " Replacing cached entry {} with {} for {}" , entry.id .value , id.value , path);
523+ entry.id = id;
524+ entry.metadata = DataRefUtils::extractCCDBHeaders (ref);
525+ return entry.metadata ;
530526 }
531527
532528 template <typename T = DataRef, typename R>
0 commit comments