Skip to content

Commit ec560d1

Browse files
committed
DPL Analysis: fix multiple HistogramRegistry instances per task
In particular when one of them needs to have its own folder.
1 parent 24d15d0 commit ec560d1

File tree

4 files changed

+30
-2
lines changed

4 files changed

+30
-2
lines changed

Framework/AnalysisSupport/src/AODWriterHelpers.cxx

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -339,7 +339,9 @@ AlgorithmSpec AODWriterHelpers::getOutputObjHistWriter(ConfigContext const& ctx)
339339
O2_SIGNPOST_END(histogram_registry, did, "deserialization", "Done deserialization.");
340340
// If we have a folder, we assume the first element of the path
341341
// to be the name of the registry.
342+
bool folderForContainer = false;
342343
if (sourceType == HistogramRegistrySource) {
344+
folderForContainer = objh->createContainer != 0;
343345
obj.container = objh->containerName;
344346
} else {
345347
obj.container = obj.name;
@@ -423,6 +425,16 @@ AlgorithmSpec AODWriterHelpers::getOutputObjHistWriter(ConfigContext const& ctx)
423425
// FIXME: handle folders
424426
f[route.policy]->cd("/");
425427
auto* currentDir = f[route.policy]->GetDirectory(currentDirectory.c_str());
428+
429+
// In case we need a folder for the registry, let's create it.
430+
if (folderForContainer) {
431+
auto* histogramRegistryFolder = currentDir->GetDirectory(obj.container.data());
432+
if (!histogramRegistryFolder) {
433+
histogramRegistryFolder = currentDir->mkdir(obj.container.c_str(), "", kTRUE);
434+
}
435+
currentDir = histogramRegistryFolder;
436+
}
437+
426438
// The name contains a path...
427439
int objSize = 0;
428440
if (sourceType == HistogramRegistrySource) {

Framework/Core/include/Framework/OutputObjHeader.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ enum OutputObjSourceType : unsigned int {
3737
/// @brief O2 header for OutputObj metadata
3838
struct OutputObjHeader : public BaseHeader {
3939
constexpr static const uint32_t sVersion = 1;
40+
constexpr static const uint32_t MAX_REGISTRY_NAME_SIZE = 128;
4041
constexpr static const o2::header::HeaderType sHeaderType = "OutObjMD";
4142
constexpr static const o2::header::SerializationMethod sSerializationMethod = o2::header::gSerializationMethodNone;
4243
OutputObjHandlingPolicy mPolicy;
@@ -45,7 +46,9 @@ struct OutputObjHeader : public BaseHeader {
4546
uint16_t mPipelineIndex = 0;
4647
uint16_t mPipelineSize = 1;
4748
// Name of the actual container for the object, e.g. the HistogramRegistry name
48-
char containerName[64] = {0};
49+
char containerName[MAX_REGISTRY_NAME_SIZE] = {0};
50+
// Wether or not the container should have a name
51+
char createContainer = false;
4952

5053
constexpr OutputObjHeader()
5154
: BaseHeader(sizeof(OutputObjHeader), sHeaderType, sSerializationMethod, sVersion),

Framework/Core/src/HistogramRegistry.cxx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,8 @@ OutputRef HistogramRegistry::ref(uint16_t pipelineIndex, uint16_t pipelineSize)
5555
{
5656
OutputObjHeader header{mPolicy, OutputObjSourceType::HistogramRegistrySource, mTaskHash, pipelineIndex, pipelineSize};
5757
// Copy the name of the registry to the haeder.
58-
strncpy(header.containerName, mName.data(), 64);
58+
strncpy(header.containerName, mName.data(), OutputObjHeader::MAX_REGISTRY_NAME_SIZE);
59+
header.createContainer = mCreateRegistryDir ? 1 : 0;
5960
return OutputRef{std::string{mName}, 0, o2::header::Stack{header}};
6061
}
6162

Framework/TestWorkflows/src/o2TestHistograms.cxx

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,18 @@ struct EtaAndClsHistogramsSimple {
5353
} //
5454
};
5555

56+
HistogramRegistry registry2{
57+
"registry2",
58+
{
59+
{"a/foo/b/eta", "#Eta", {HistType::kTH1F, {{100, -2.0, 2.0}}}}, //
60+
{"fii/c/hpt", "p_{T}", {HistType::kTH1D, {{1002, -0.01, 50.1}}}}, //
61+
{"a/foobar/phi", "#Phi", {HistType::kTH1D, {{102, 0, 2 * M_PI}}}}, //
62+
{"fifi/ptToPt", "#ptToPt", {HistType::kTH2F, {{100, -0.01, 10.01}, {100, -0.01, 10.01}}}} //
63+
},
64+
OutputObjHandlingPolicy::AnalysisObject,
65+
false,
66+
true};
67+
5668
void init(InitContext&)
5769
{
5870
if (!trackFilterString->empty()) {

0 commit comments

Comments
 (0)