Skip to content

Commit d6bb77b

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

3 files changed

Lines changed: 40 additions & 0 deletions

File tree

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
@@ -35,6 +35,7 @@
3535
#include <memory>
3636
#include <type_traits>
3737
#include <concepts>
38+
#include <span>
3839

3940
#include <fairmq/FwdDecls.h>
4041

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

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

532+
template <typename T = DataRef, typename R>
533+
std::span<const char> get(R binding, int part = 0) const
534+
requires std::same_as<T, CCDBBlob>
535+
{
536+
auto ref = getRef(binding, part);
537+
auto header = DataRefUtils::getHeader<header::DataHeader*>(ref);
538+
if (header->payloadSerializationMethod != header::gSerializationMethodCCDB) {
539+
throw runtime_error("Attempt to extract CCDBBlob from a non-CCDB-serialized message");
540+
}
541+
return DataRefUtils::getCCDBPayloadBlob(ref);
542+
}
543+
525544
template <typename T>
526545
requires(std::same_as<T, DataRef>)
527546
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)