Skip to content

Commit c7de038

Browse files
committed
DPL: add ability to get CCDB blobs without deserialization
1 parent ae34547 commit c7de038

File tree

3 files changed

+40
-0
lines changed

3 files changed

+40
-0
lines changed

Framework/Core/include/Framework/DataRefUtils.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323

2424
#include <gsl/gsl>
2525

26+
#include <span>
2627
#include <type_traits>
2728
#include <typeinfo>
2829

@@ -184,6 +185,10 @@ struct DataRefUtils {
184185
// Decode a CCDB object using the CcdbApi.
185186
static void* decodeCCDB(DataRef const& ref, std::type_info const& info);
186187
static std::map<std::string, std::string> extractCCDBHeaders(DataRef const& ref);
188+
/// Return a span over the raw CCDB payload bytes, stripping the flattened HTTP
189+
/// headers footer that CCDBFetcherHelper appends. Use this when the CCDB entry is
190+
/// a binary blob rather than a ROOT-serialised object.
191+
static std::span<const char> getCCDBPayloadBlob(DataRef const& ref);
187192

188193
static o2::header::DataHeader::PayloadSizeType getPayloadSize(const DataRef& ref)
189194
{

Framework/Core/include/Framework/InputRecord.h

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
#include <memory>
3535
#include <type_traits>
3636
#include <concepts>
37+
#include <span>
3738

3839
#include <fairmq/FwdDecls.h>
3940

@@ -44,6 +45,12 @@ namespace o2::framework
4445
struct CCDBMetadataExtractor {
4546
};
4647

48+
/// Tag type to retrieve the raw binary payload of a CCDB entry without ROOT
49+
/// deserialization. The returned span is valid for the duration of the
50+
/// processing callback. Use as: inputs.get<CCDBBlob>("binding")
51+
struct CCDBBlob {
52+
};
53+
4754
struct InputSpec;
4855
class InputSpan;
4956
class CallbackService;
@@ -512,6 +519,18 @@ class InputRecord
512519
return cache.idToMetadata[id];
513520
}
514521

522+
template <typename T = DataRef, typename R>
523+
std::span<const char> get(R binding, int part = 0) const
524+
requires std::same_as<T, CCDBBlob>
525+
{
526+
auto ref = getRef(binding, part);
527+
auto header = DataRefUtils::getHeader<header::DataHeader*>(ref);
528+
if (header->payloadSerializationMethod != header::gSerializationMethodCCDB) {
529+
throw runtime_error("Attempt to extract CCDBBlob from a non-CCDB-serialized message");
530+
}
531+
return DataRefUtils::getCCDBPayloadBlob(ref);
532+
}
533+
515534
template <typename T>
516535
requires(std::same_as<T, DataRef>)
517536
decltype(auto) get(ConcreteDataMatcher matcher, int part = 0)

Framework/Core/src/DataRefUtils.cxx

Lines changed: 16 additions & 0 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

12+
#include <span>
1213
#include <typeinfo>
1314
#include <cstring>
1415
#include "Framework/DataRefUtils.h"
@@ -148,4 +149,19 @@ std::map<std::string, std::string> DataRefUtils::extractCCDBHeaders(DataRef cons
148149
return res;
149150
}
150151

152+
std::span<const char> DataRefUtils::getCCDBPayloadBlob(DataRef const& ref)
153+
{
154+
auto* dh = o2::header::get<o2::header::DataHeader*>(ref.header);
155+
const char* buff = ref.payload;
156+
size_t payloadSize = dh->payloadSize;
157+
constexpr char FlatHeaderAnnot[] = "$HEADER$";
158+
constexpr size_t Offset = sizeof(int) + sizeof(FlatHeaderAnnot);
159+
int headerSize = 0;
160+
if (payloadSize >= Offset &&
161+
!std::strncmp(buff + payloadSize - sizeof(FlatHeaderAnnot), FlatHeaderAnnot, sizeof(FlatHeaderAnnot))) {
162+
headerSize = *reinterpret_cast<const int*>(buff + payloadSize - Offset);
163+
}
164+
return {buff, payloadSize - headerSize};
165+
}
166+
151167
} // namespace o2::framework

0 commit comments

Comments
 (0)