Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions Framework/Core/include/Framework/DataRefUtils.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@

#include <gsl/gsl>

#include <span>
#include <type_traits>
#include <typeinfo>

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

static o2::header::DataHeader::PayloadSizeType getPayloadSize(const DataRef& ref)
{
Expand Down
19 changes: 19 additions & 0 deletions Framework/Core/include/Framework/InputRecord.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
#include <memory>
#include <type_traits>
#include <concepts>
#include <span>

#include <fairmq/FwdDecls.h>

Expand All @@ -44,6 +45,12 @@ namespace o2::framework
struct CCDBMetadataExtractor {
};

/// Tag type to retrieve the raw binary payload of a CCDB entry without ROOT
/// deserialization. The returned span is valid for the duration of the
/// processing callback. Use as: inputs.get<CCDBBlob>("binding")
struct CCDBBlob {
};

struct InputSpec;
class InputSpan;
class CallbackService;
Expand Down Expand Up @@ -512,6 +519,18 @@ class InputRecord
return cache.idToMetadata[id];
}

template <typename T = DataRef, typename R>
std::span<const char> get(R binding, int part = 0) const
requires std::same_as<T, CCDBBlob>
{
auto ref = getRef(binding, part);
auto header = DataRefUtils::getHeader<header::DataHeader*>(ref);
if (header->payloadSerializationMethod != header::gSerializationMethodCCDB) {
throw runtime_error("Attempt to extract CCDBBlob from a non-CCDB-serialized message");
}
return DataRefUtils::getCCDBPayloadBlob(ref);
}

template <typename T>
requires(std::same_as<T, DataRef>)
decltype(auto) get(ConcreteDataMatcher matcher, int part = 0)
Expand Down
16 changes: 16 additions & 0 deletions Framework/Core/src/DataRefUtils.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
// granted to it by virtue of its status as an Intergovernmental Organization
// or submit itself to any jurisdiction.

#include <span>
#include <typeinfo>
#include <cstring>
#include "Framework/DataRefUtils.h"
Expand Down Expand Up @@ -148,4 +149,19 @@ std::map<std::string, std::string> DataRefUtils::extractCCDBHeaders(DataRef cons
return res;
}

std::span<const char> DataRefUtils::getCCDBPayloadBlob(DataRef const& ref)
{
auto* dh = o2::header::get<o2::header::DataHeader*>(ref.header);
const char* buff = ref.payload;
size_t payloadSize = dh->payloadSize;
constexpr char FlatHeaderAnnot[] = "$HEADER$";
constexpr size_t Offset = sizeof(int) + sizeof(FlatHeaderAnnot);
int headerSize = 0;
if (payloadSize >= Offset &&
!std::strncmp(buff + payloadSize - sizeof(FlatHeaderAnnot), FlatHeaderAnnot, sizeof(FlatHeaderAnnot))) {
headerSize = *reinterpret_cast<const int*>(buff + payloadSize - Offset);
}
return {buff, payloadSize - headerSize};
}

} // namespace o2::framework