Skip to content

Commit 6eee837

Browse files
authored
Merge c0d252c into sapling-pr-archive-ktf
2 parents e9751c7 + c0d252c commit 6eee837

11 files changed

Lines changed: 174 additions & 60 deletions

File tree

Common/Constants/include/CommonConstants/PhysicsConstants.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,8 @@ enum Pdg {
9797
kHyperHelium4Sigma = 1110020040,
9898
kLambda1520_Py = 102134,
9999
kK1_1270_0 = 10313,
100-
kK1_1270Plus = 10323
100+
kK1_1270Plus = 10323,
101+
kCDeuteron = 2010010020
101102
};
102103

103104
/// \brief Declarations of masses for additional particles
@@ -168,6 +169,7 @@ constexpr double MassHyperHelium4Sigma = 3.995;
168169
constexpr double MassLambda1520_Py = 1.5195;
169170
constexpr double MassK1_1270_0 = 1.253;
170171
constexpr double MassK1_1270Plus = 1.272;
172+
constexpr double MassCDeuteron = 3.226;
171173

172174
/// \brief Declarations of masses for particles in ROOT PDG_t
173175
constexpr double MassDown = 0.00467;

Common/Constants/include/CommonConstants/make_pdg_header.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,7 @@ class Pdg(Enum):
156156
kLambda1520_Py = 102134 # PYTHIA code different from PDG
157157
kK1_1270_0 = 10313
158158
kK1_1270Plus = 10323
159+
kCDeuteron = 2010010020
159160

160161

161162
dbPdg = o2.O2DatabasePDG

DataFormats/simulation/include/SimulationDataFormat/O2DatabasePDG.h

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -732,6 +732,21 @@ inline void O2DatabasePDG::addALICEParticles(TDatabasePDG* db)
732732
db->AddParticle("Xi_c_0_3080", "Xi_c_0_3080", 3.0799, false, 0.0056, 0, "Resonance", ionCode);
733733
}
734734
db->AddAntiParticle("Anti-Xi_c_0_3080", -ionCode);
735+
ionCode = 24124;
736+
if (!db->GetParticle(ionCode)) {
737+
db->AddParticle("Lambda_c_Plus_2860", "Lambda_c_Plus_2860", 2.8561, false, 0.0680, 0, "Resonance", ionCode);
738+
}
739+
db->AddAntiParticle("Anti-Lambda_c_Minus_2860", -ionCode);
740+
ionCode = 24126;
741+
if (!db->GetParticle(ionCode)) {
742+
db->AddParticle("Lambda_c_Plus_2880", "Lambda_c_Plus_2880", 2.8816, false, 0.0056, 0, "Resonance", ionCode);
743+
}
744+
db->AddAntiParticle("Anti-Lambda_c_Minus_2880", -ionCode);
745+
ionCode = 4125;
746+
if (!db->GetParticle(ionCode)) {
747+
db->AddParticle("Lambda_c_Plus_2940", "Lambda_c_Plus_2940", 2.9396, false, 0.0200, 0, "Resonance", ionCode);
748+
}
749+
db->AddAntiParticle("Anti-Lambda_c_Minus_2940", -ionCode);
735750

736751
// d*(2380) - dibaryon resonance
737752

Framework/CCDBSupport/src/CCDBFetcherHelper.cxx

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
// granted to it by virtue of its status as an Intergovernmental Organization
1010
// or submit itself to any jurisdiction.
1111
#include "CCDBFetcherHelper.h"
12+
#include "CCDBHelpers.h"
1213
#include "Framework/DataTakingContext.h"
1314
#include "Framework/Signpost.h"
1415
#include "Framework/DataSpecUtils.h"
@@ -257,14 +258,13 @@ auto CCDBFetcherHelper::populateCacheWith(std::shared_ptr<CCDBFetcherHelper> con
257258
helper->totalFetchedBytes += size;
258259
helper->totalRequestedBytes += size;
259260
api.appendFlatHeader(v, headers);
260-
auto cacheId = allocator.adoptContainer(output, std::move(v), DataAllocator::CacheStrategy::Always, header::gSerializationMethodCCDB);
261+
auto cacheId = CCDBHelpers::adoptAndReplaceCachedMessage(allocator, helper->mapURL2DPLCache, path, output, std::move(v), header::gSerializationMethodCCDB);
261262
helper->mapURL2DPLCache[path] = cacheId;
262263
responses.emplace_back(Response{.id = cacheId, .size = size, .request = nullptr});
263264
O2_SIGNPOST_EVENT_EMIT(ccdb, sid, "populateCacheWith", "Caching %{public}s for %{public}s (DPL id %" PRIu64 ", size %zu)", path.data(), headers["ETag"].data(), cacheId.value, size);
264265
continue;
265266
}
266-
if (v.size()) { // but should be overridden by fresh object
267-
// somewhere here pruneFromCache should be called
267+
if (v.size()) { // but should be overridden by fresh object
268268
helper->mapURL2UUID[path].etag = headers["ETag"]; // update uuid
269269
helper->mapURL2UUID[path].cachePopulatedAt = timestampToUse;
270270
helper->mapURL2UUID[path].cacheValidUntil = headers["Cache-Valid-Until"].empty() ? 0 : std::stoul(headers["Cache-Valid-Until"]);
@@ -276,12 +276,10 @@ auto CCDBFetcherHelper::populateCacheWith(std::shared_ptr<CCDBFetcherHelper> con
276276
helper->totalFetchedBytes += size;
277277
helper->totalRequestedBytes += size;
278278
api.appendFlatHeader(v, headers);
279-
auto cacheId = allocator.adoptContainer(output, std::move(v), DataAllocator::CacheStrategy::Always, header::gSerializationMethodCCDB);
279+
auto cacheId = CCDBHelpers::adoptAndReplaceCachedMessage(allocator, helper->mapURL2DPLCache, path, output, std::move(v), header::gSerializationMethodCCDB);
280280
helper->mapURL2DPLCache[path] = cacheId;
281281
responses.emplace_back(Response{.id = cacheId, .size = size, .request = nullptr});
282282
O2_SIGNPOST_EVENT_EMIT(ccdb, sid, "populateCacheWith", "Caching %{public}s for %{public}s (DPL id %" PRIu64 ")", path.data(), headers["ETag"].data(), cacheId.value);
283-
// one could modify the adoptContainer to take optional old cacheID to clean:
284-
// mapURL2DPLCache[URL] = ctx.outputs().adoptContainer(output, std::move(outputBuffer), DataAllocator::CacheStrategy::Always, mapURL2DPLCache[URL]);
285283
continue;
286284
} else {
287285
// Only once the etag is actually used, we get the information on how long the object is valid

Framework/CCDBSupport/src/CCDBHelpers.cxx

Lines changed: 22 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -249,6 +249,22 @@ bool isOnlineRun(DataTakingContext const& dtc)
249249
return dtc.deploymentMode == DeploymentMode::OnlineAUX || dtc.deploymentMode == DeploymentMode::OnlineDDS || dtc.deploymentMode == DeploymentMode::OnlineECS;
250250
}
251251

252+
DataAllocator::CacheId CCDBHelpers::adoptAndReplaceCachedMessage(
253+
DataAllocator& allocator,
254+
std::unordered_map<std::string, DataAllocator::CacheId> const& cache,
255+
std::string const& path,
256+
Output const& output,
257+
o2::pmr::vector<char>&& v,
258+
o2::header::SerializationMethod method)
259+
{
260+
auto oldIt = cache.find(path);
261+
auto cacheId = allocator.adoptContainer(output, std::move(v), DataAllocator::CacheStrategy::Always, method);
262+
if (oldIt != cache.end()) {
263+
allocator.pruneFromCache(oldIt->second);
264+
}
265+
return cacheId;
266+
}
267+
252268
auto populateCacheWith(std::shared_ptr<CCDBFetcherHelper> const& helper,
253269
int64_t timestamp,
254270
TimingInfo& timingInfo,
@@ -347,13 +363,12 @@ auto populateCacheWith(std::shared_ptr<CCDBFetcherHelper> const& helper,
347363
helper->totalFetchedBytes += v.size();
348364
helper->totalRequestedBytes += v.size();
349365
api.appendFlatHeader(v, headers);
350-
auto cacheId = allocator.adoptContainer(output, std::move(v), DataAllocator::CacheStrategy::Always, header::gSerializationMethodCCDB);
366+
auto cacheId = CCDBHelpers::adoptAndReplaceCachedMessage(allocator, helper->mapURL2DPLCache, path, output, std::move(v), header::gSerializationMethodCCDB);
351367
helper->mapURL2DPLCache[path] = cacheId;
352368
O2_SIGNPOST_EVENT_EMIT(ccdb, sid, "populateCacheWith", "Caching %{public}s for %{public}s (DPL id %" PRIu64 ")", path.data(), headers["ETag"].data(), cacheId.value);
353369
continue;
354370
}
355-
if (v.size()) { // but should be overridden by fresh object
356-
// somewhere here pruneFromCache should be called
371+
if (v.size()) { // but should be overridden by fresh object
357372
helper->mapURL2UUID[path].etag = headers["ETag"]; // update uuid
358373
helper->mapURL2UUID[path].cachePopulatedAt = timestampToUse;
359374
helper->mapURL2UUID[path].cacheValidUntil = headers["Cache-Valid-Until"].empty() ? 0 : std::stoul(headers["Cache-Valid-Until"]);
@@ -364,11 +379,9 @@ auto populateCacheWith(std::shared_ptr<CCDBFetcherHelper> const& helper,
364379
helper->totalFetchedBytes += v.size();
365380
helper->totalRequestedBytes += v.size();
366381
api.appendFlatHeader(v, headers);
367-
auto cacheId = allocator.adoptContainer(output, std::move(v), DataAllocator::CacheStrategy::Always, header::gSerializationMethodCCDB);
382+
auto cacheId = CCDBHelpers::adoptAndReplaceCachedMessage(allocator, helper->mapURL2DPLCache, path, output, std::move(v), header::gSerializationMethodCCDB);
368383
helper->mapURL2DPLCache[path] = cacheId;
369384
O2_SIGNPOST_EVENT_EMIT(ccdb, sid, "populateCacheWith", "Caching %{public}s for %{public}s (DPL id %" PRIu64 ")", path.data(), headers["ETag"].data(), cacheId.value);
370-
// one could modify the adoptContainer to take optional old cacheID to clean:
371-
// mapURL2DPLCache[URL] = ctx.outputs().adoptContainer(output, std::move(outputBuffer), DataAllocator::CacheStrategy::Always, mapURL2DPLCache[URL]);
372385
continue;
373386
} else {
374387
// Only once the etag is actually used, we get the information on how long the object is valid
@@ -448,11 +461,10 @@ AlgorithmSpec CCDBHelpers::fetchFromCCDB()
448461
helper->totalRequestedBytes += v.size();
449462
newOrbitResetTime = getOrbitResetTime(v);
450463
api.appendFlatHeader(v, headers);
451-
auto cacheId = allocator.adoptContainer(output, std::move(v), DataAllocator::CacheStrategy::Always, header::gSerializationMethodNone);
464+
auto cacheId = CCDBHelpers::adoptAndReplaceCachedMessage(allocator, helper->mapURL2DPLCache, path, output, std::move(v), header::gSerializationMethodNone);
452465
helper->mapURL2DPLCache[path] = cacheId;
453466
O2_SIGNPOST_EVENT_EMIT(ccdb, sid, "fetchFromCCDB", "Caching %{public}s for %{public}s (DPL id %" PRIu64 ")", path.data(), headers["ETag"].data(), cacheId.value);
454-
} else if (v.size()) { // but should be overridden by fresh object
455-
// somewhere here pruneFromCache should be called
467+
} else if (v.size()) { // but should be overridden by fresh object
456468
helper->mapURL2UUID[path].etag = headers["ETag"]; // update uuid
457469
helper->mapURL2UUID[path].cacheMiss++;
458470
helper->mapURL2UUID[path].size = v.size();
@@ -462,11 +474,9 @@ AlgorithmSpec CCDBHelpers::fetchFromCCDB()
462474
helper->totalRequestedBytes += v.size();
463475
newOrbitResetTime = getOrbitResetTime(v);
464476
api.appendFlatHeader(v, headers);
465-
auto cacheId = allocator.adoptContainer(output, std::move(v), DataAllocator::CacheStrategy::Always, header::gSerializationMethodNone);
477+
auto cacheId = CCDBHelpers::adoptAndReplaceCachedMessage(allocator, helper->mapURL2DPLCache, path, output, std::move(v), header::gSerializationMethodNone);
466478
helper->mapURL2DPLCache[path] = cacheId;
467479
O2_SIGNPOST_EVENT_EMIT(ccdb, sid, "fetchFromCCDB", "Caching %{public}s for %{public}s (DPL id %" PRIu64 ")", path.data(), headers["ETag"].data(), cacheId.value);
468-
// one could modify the adoptContainer to take optional old cacheID to clean:
469-
// mapURL2DPLCache[URL] = ctx.outputs().adoptContainer(output, std::move(outputBuffer), DataAllocator::CacheStrategy::Always, mapURL2DPLCache[URL]);
470480
}
471481
// cached object is fine
472482
}

Framework/CCDBSupport/src/CCDBHelpers.h

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,10 @@
1212
#define O2_FRAMEWORK_CCDBHELPERS_H_
1313

1414
#include "Framework/AlgorithmSpec.h"
15+
#include "Framework/DataAllocator.h"
16+
#include "Framework/Output.h"
17+
#include "Headers/DataHeader.h"
18+
#include "MemoryResources/MemoryResources.h"
1519
#include <unordered_map>
1620
#include <string>
1721

@@ -25,6 +29,24 @@ struct CCDBHelpers {
2529
};
2630
static AlgorithmSpec fetchFromCCDB();
2731
static ParserResult parseRemappings(char const*);
32+
33+
/// Adopt a freshly-fetched CCDB payload as a new SHM message and prune
34+
/// the previously cached one for this path. The new SHM message is
35+
/// adopted BEFORE the old cached one is pruned
36+
/// @a allocator producer-device DPL DataAllocator
37+
/// @a cache read-only view of the producer-local path -> CacheId map;
38+
/// @a path CCDB path
39+
/// @a output DPL Output matcher
40+
/// @a v freshly-fetched CCDB payload; consumed by the call, leaving @a v empty
41+
/// @a method serialization-method tag written into the message header
42+
/// @return the new CacheId; the caller must record it in its map
43+
static DataAllocator::CacheId adoptAndReplaceCachedMessage(
44+
DataAllocator& allocator,
45+
std::unordered_map<std::string, DataAllocator::CacheId> const& cache,
46+
std::string const& path,
47+
Output const& output,
48+
o2::pmr::vector<char>&& v,
49+
o2::header::SerializationMethod method);
2850
};
2951

3052
} // namespace o2::framework

Framework/Core/include/Framework/DataAllocator.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -525,6 +525,10 @@ class DataAllocator
525525
/// Adopt an already cached message, using an already provided CacheId.
526526
void adoptFromCache(Output const& spec, CacheId id, header::SerializationMethod method = header::gSerializationMethodNone);
527527

528+
/// Prune a previously cached message identified by @a id from the message cache.
529+
/// Calling this with an unknown id is a no-op.
530+
void pruneFromCache(CacheId id);
531+
528532
/// snapshot object and route to output specified by OutputRef
529533
/// Framework makes a (serialized) copy of object content.
530534
///

Framework/Core/include/Framework/InputRecord.h

Lines changed: 26 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -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>

Framework/Core/include/Framework/ObjectCache.h

Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,14 @@
1414
#include "Framework/DataRef.h"
1515
#include <unordered_map>
1616
#include <map>
17+
#include <string>
1718

1819
namespace o2::framework
1920
{
2021

2122
/// A cache for CCDB objects or objects in general
2223
/// which have more than one timeframe of lifetime.
24+
/// The cache is keyed *per path* rather than by a global id-derived hash.
2325
struct ObjectCache {
2426
struct Id {
2527
int64_t value;
@@ -39,20 +41,28 @@ struct ObjectCache {
3941
}
4042
};
4143
};
42-
/// A cache for deserialised objects.
44+
45+
/// Per-path cache entry for a deserialised CCDB object.
46+
struct Entry {
47+
Id id{0};
48+
void* obj{nullptr};
49+
};
50+
51+
/// Per-path cache entry for the CCDB metadata map.
52+
struct MetadataEntry {
53+
Id id{0};
54+
std::map<std::string, std::string> metadata;
55+
};
56+
57+
/// A per-path cache for deserialised objects.
4358
/// This keeps a mapping so that we can tell if a given
44-
/// path was already received and it's blob stored in
45-
/// .second.
46-
std::unordered_map<std::string, Id> matcherToId;
47-
/// A map from a CacheId (which is the void* ptr of the previous map).
48-
/// to an actual (type erased) pointer to the deserialised object.
49-
std::unordered_map<Id, void*, Id::hash_fn> idToObject;
50-
51-
/// A cache to the deserialised metadata
59+
/// path was already received and it's blob stored in .second.obj
60+
std::unordered_map<std::string, Entry> matcherToEntry;
61+
62+
/// A per-path cache to the deserialised metadata
5263
/// We keep it separate because we want to avoid that looking up
5364
/// the metadata also pollutes the object cache.
54-
std::unordered_map<std::string, Id> matcherToMetadataId;
55-
std::unordered_map<Id, std::map<std::string, std::string>, Id::hash_fn> idToMetadata;
65+
std::unordered_map<std::string, MetadataEntry> matcherToMetadata;
5666
};
5767

5868
} // namespace o2::framework

0 commit comments

Comments
 (0)