Skip to content

Commit 3124b96

Browse files
committed
DPL: make sure caching strategy is provided explicitly
1 parent 4548e88 commit 3124b96

2 files changed

Lines changed: 18 additions & 13 deletions

File tree

Framework/CCDBSupport/src/CCDBHelpers.cxx

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,7 @@ auto populateCacheWith(std::shared_ptr<CCDBFetcherHelper> const& helper,
229229
helper->mapURL2UUID[path].cacheMiss++;
230230
helper->mapURL2UUID[path].minSize = std::min(v.size(), helper->mapURL2UUID[path].minSize);
231231
helper->mapURL2UUID[path].maxSize = std::max(v.size(), helper->mapURL2UUID[path].maxSize);
232-
auto cacheId = allocator.adoptContainer(output, std::move(v), true, header::gSerializationMethodCCDB);
232+
auto cacheId = allocator.adoptContainer(output, std::move(v), DataAllocator::CacheStrategy::Always, header::gSerializationMethodCCDB);
233233
helper->mapURL2DPLCache[path] = cacheId;
234234
LOGP(debug, "Caching {} for {} (DPL id {})", path, headers["ETag"], cacheId.value);
235235
continue;
@@ -240,11 +240,11 @@ auto populateCacheWith(std::shared_ptr<CCDBFetcherHelper> const& helper,
240240
helper->mapURL2UUID[path].cacheMiss++;
241241
helper->mapURL2UUID[path].minSize = std::min(v.size(), helper->mapURL2UUID[path].minSize);
242242
helper->mapURL2UUID[path].maxSize = std::max(v.size(), helper->mapURL2UUID[path].maxSize);
243-
auto cacheId = allocator.adoptContainer(output, std::move(v), true, header::gSerializationMethodCCDB);
243+
auto cacheId = allocator.adoptContainer(output, std::move(v), DataAllocator::CacheStrategy::Always, header::gSerializationMethodCCDB);
244244
helper->mapURL2DPLCache[path] = cacheId;
245245
LOGP(debug, "Caching {} for {} (DPL id {})", path, headers["ETag"], cacheId.value);
246246
// one could modify the adoptContainer to take optional old cacheID to clean:
247-
// mapURL2DPLCache[URL] = ctx.outputs().adoptContainer(output, std::move(outputBuffer), true, mapURL2DPLCache[URL]);
247+
// mapURL2DPLCache[URL] = ctx.outputs().adoptContainer(output, std::move(outputBuffer), DataAllocator::CacheStrategy::Always, mapURL2DPLCache[URL]);
248248
continue;
249249
}
250250
}
@@ -352,7 +352,7 @@ AlgorithmSpec CCDBHelpers::fetchFromCCDB()
352352
helper->mapURL2UUID[path].minSize = std::min(v.size(), helper->mapURL2UUID[path].minSize);
353353
helper->mapURL2UUID[path].maxSize = std::max(v.size(), helper->mapURL2UUID[path].maxSize);
354354
newOrbitResetTime = getOrbitResetTime(v);
355-
auto cacheId = allocator.adoptContainer(output, std::move(v), true, header::gSerializationMethodNone);
355+
auto cacheId = allocator.adoptContainer(output, std::move(v), DataAllocator::CacheStrategy::Always, header::gSerializationMethodNone);
356356
helper->mapURL2DPLCache[path] = cacheId;
357357
LOGP(debug, "Caching {} for {} (DPL id {})", path, headers["ETag"], cacheId.value);
358358
} else if (v.size()) { // but should be overridden by fresh object
@@ -362,11 +362,11 @@ AlgorithmSpec CCDBHelpers::fetchFromCCDB()
362362
helper->mapURL2UUID[path].minSize = std::min(v.size(), helper->mapURL2UUID[path].minSize);
363363
helper->mapURL2UUID[path].maxSize = std::max(v.size(), helper->mapURL2UUID[path].maxSize);
364364
newOrbitResetTime = getOrbitResetTime(v);
365-
auto cacheId = allocator.adoptContainer(output, std::move(v), true, header::gSerializationMethodNone);
365+
auto cacheId = allocator.adoptContainer(output, std::move(v), DataAllocator::CacheStrategy::Always, header::gSerializationMethodNone);
366366
helper->mapURL2DPLCache[path] = cacheId;
367367
LOGP(debug, "Caching {} for {} (DPL id {})", path, headers["ETag"], cacheId.value);
368368
// one could modify the adoptContainer to take optional old cacheID to clean:
369-
// mapURL2DPLCache[URL] = ctx.outputs().adoptContainer(output, std::move(outputBuffer), true, mapURL2DPLCache[URL]);
369+
// mapURL2DPLCache[URL] = ctx.outputs().adoptContainer(output, std::move(outputBuffer), DataAllocator::CacheStrategy::Always, mapURL2DPLCache[URL]);
370370
}
371371
// cached object is fine
372372
}

Framework/Core/include/Framework/DataAllocator.h

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@
88
// In applying this license CERN does not waive the privileges and immunities
99
// granted to it by virtue of its status as an Intergovernmental Organization
1010
// or submit itself to any jurisdiction.
11-
#ifndef FRAMEWORK_DATAALLOCATOR_H
12-
#define FRAMEWORK_DATAALLOCATOR_H
11+
#ifndef O2_FRAMEWORK_DATAALLOCATOR_H_
12+
#define O2_FRAMEWORK_DATAALLOCATOR_H_
1313

1414
#include "Framework/MessageContext.h"
1515
#include "Framework/RootMessageContext.h"
@@ -390,8 +390,13 @@ class DataAllocator
390390
int64_t value;
391391
};
392392

393+
enum struct CacheStrategy : int {
394+
Never = 0,
395+
Always = 1
396+
};
397+
393398
template <typename ContainerT>
394-
CacheId adoptContainer(const Output& /*spec*/, ContainerT& /*container*/, bool /* cache = false */, o2::header::SerializationMethod /* method = header::gSerializationMethodNone*/)
399+
CacheId adoptContainer(const Output& /*spec*/, ContainerT& /*container*/, CacheStrategy /* cache = false */, o2::header::SerializationMethod /* method = header::gSerializationMethodNone*/)
395400
{
396401
static_assert(always_static_assert_v<ContainerT>, "Container cannot be moved. Please make sure it is backed by a o2::pmr::FairMQMemoryResource");
397402
return {0};
@@ -407,7 +412,7 @@ class DataAllocator
407412
/// @return a unique id of the adopted message which can be used to resend the
408413
/// message or can be pruned via the DataAllocator::prune() method.
409414
template <typename ContainerT>
410-
CacheId adoptContainer(const Output& spec, ContainerT&& container, bool cache = false, o2::header::SerializationMethod method = header::gSerializationMethodNone);
415+
CacheId adoptContainer(const Output& spec, ContainerT&& container, CacheStrategy cache = CacheStrategy::Never, o2::header::SerializationMethod method = header::gSerializationMethodNone);
411416

412417
/// Adopt an already cached message, using an already provided CacheId.
413418
void adoptFromCache(Output const& spec, CacheId id, header::SerializationMethod method = header::gSerializationMethodNone);
@@ -467,7 +472,7 @@ class DataAllocator
467472
};
468473

469474
template <typename ContainerT>
470-
DataAllocator::CacheId DataAllocator::adoptContainer(const Output& spec, ContainerT&& container, bool cache, header::SerializationMethod method)
475+
DataAllocator::CacheId DataAllocator::adoptContainer(const Output& spec, ContainerT&& container, CacheStrategy cache, header::SerializationMethod method)
471476
{
472477
// Find a matching channel, extract the message for it form the container
473478
// and put it in the queue to be sent at the end of the processing
@@ -483,7 +488,7 @@ DataAllocator::CacheId DataAllocator::adoptContainer(const Output& spec, Contain
483488
);
484489

485490
CacheId cacheId{0}; //
486-
if (cache) {
491+
if (cache == CacheStrategy::Always) {
487492
// The message will be shallow cloned in the cache. Since the
488493
// clone is indistinguishable from the original, we can keep sending
489494
// the original.
@@ -496,4 +501,4 @@ DataAllocator::CacheId DataAllocator::adoptContainer(const Output& spec, Contain
496501

497502
} // namespace o2::framework
498503

499-
#endif //FRAMEWORK_DATAALLOCATOR_H
504+
#endif // O2_FRAMEWORK_DATAALLOCATOR_H_

0 commit comments

Comments
 (0)