Skip to content

Commit 2475cbc

Browse files
authored
DPL: allow configuring compression for the AOD writer (#13659)
1 parent fec521f commit 2475cbc

File tree

9 files changed

+103
-15
lines changed

9 files changed

+103
-15
lines changed

Framework/Core/include/Framework/DataOutputDirector.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ struct DataOutputDirector {
8484
std::vector<DataOutputDescriptor*> getDataOutputDescriptors(InputSpec spec);
8585

8686
// get the matching TFile
87-
FileAndFolder getFileFolder(DataOutputDescriptor* dodesc, uint64_t folderNumber, std::string parentFileName);
87+
FileAndFolder getFileFolder(DataOutputDescriptor* dodesc, uint64_t folderNumber, std::string parentFileName, int compression);
8888

8989
// check file sizes
9090
bool checkFileSizes();

Framework/Core/src/AnalysisSupportHelpers.cxx

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -318,10 +318,10 @@ DataProcessorSpec AnalysisSupportHelpers::getOutputObjHistSink(std::vector<Outpu
318318
// add sink for the AODs
319319
DataProcessorSpec
320320
AnalysisSupportHelpers::getGlobalAODSink(std::shared_ptr<DataOutputDirector> dod,
321-
std::vector<InputSpec> const& outputInputs)
321+
std::vector<InputSpec> const& outputInputs, int compressionLevel)
322322
{
323323

324-
auto writerFunction = [dod, outputInputs](InitContext& ic) -> std::function<void(ProcessingContext&)> {
324+
auto writerFunction = [dod, outputInputs, compressionLevel](InitContext& ic) -> std::function<void(ProcessingContext&)> {
325325
LOGP(debug, "======== getGlobalAODSink::Init ==========");
326326

327327
// find out if any table needs to be saved
@@ -363,7 +363,7 @@ DataProcessorSpec
363363
std::vector<TString> aodMetaDataVals;
364364

365365
// this functor is called once per time frame
366-
return [dod, tfNumbers, tfFilenames, aodMetaDataKeys, aodMetaDataVals](ProcessingContext& pc) mutable -> void {
366+
return [dod, tfNumbers, tfFilenames, aodMetaDataKeys, aodMetaDataVals, compressionLevel](ProcessingContext& pc) mutable -> void {
367367
LOGP(debug, "======== getGlobalAODSink::processing ==========");
368368
LOGP(debug, " processing data set with {} entries", pc.inputs().size());
369369

@@ -457,7 +457,7 @@ DataProcessorSpec
457457
// a table can be saved in multiple ways
458458
// e.g. different selections of columns to different files
459459
for (auto d : ds) {
460-
auto fileAndFolder = dod->getFileFolder(d, tfNumber, aodInputFile);
460+
auto fileAndFolder = dod->getFileFolder(d, tfNumber, aodInputFile, compressionLevel);
461461
auto treename = fileAndFolder.folderName + "/" + d->treename;
462462
TableToTree ta2tr(table,
463463
fileAndFolder.file,
@@ -495,11 +495,11 @@ DataProcessorSpec
495495
// the command line options relevant for the writer are global
496496
// see runDataProcessing.h
497497
DataProcessorSpec spec{
498-
"internal-dpl-aod-writer",
499-
outputInputs,
500-
Outputs{},
501-
AlgorithmSpec(writerFunction),
502-
{}};
498+
.name = "internal-dpl-aod-writer",
499+
.inputs = outputInputs,
500+
.outputs = {},
501+
.algorithm = AlgorithmSpec{writerFunction},
502+
};
503503

504504
return spec;
505505
}

Framework/Core/src/AnalysisSupportHelpers.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ struct AnalysisSupportHelpers {
7878
std::vector<OutputTaskInfo> const& tskmap);
7979
/// writes inputs of kind AOD to file
8080
static DataProcessorSpec getGlobalAODSink(std::shared_ptr<DataOutputDirector> dod,
81-
std::vector<InputSpec> const& outputInputs);
81+
std::vector<InputSpec> const& outputInputs, int compression);
8282
};
8383

8484
}; // namespace o2::framework

Framework/Core/src/ArrowSupport.cxx

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
#include "Headers/DataHeader.h"
3838
#include "Headers/DataHeaderHelpers.h"
3939

40+
#include <RtypesCore.h>
4041
#include <fairmq/ProgOptions.h>
4142

4243
#include <uv.h>
@@ -536,7 +537,11 @@ o2::framework::ServiceSpec ArrowSupport::arrowBackendSpec()
536537
// add TFNumber and TFFilename as input to the writer
537538
outputsInputsAOD.emplace_back("tfn", "TFN", "TFNumber");
538539
outputsInputsAOD.emplace_back("tff", "TFF", "TFFilename");
539-
workflow.push_back(AnalysisSupportHelpers::getGlobalAODSink(dod, outputsInputsAOD));
540+
int compression = 505;
541+
if (ctx.options().hasOption("aod-writer-compression")) {
542+
compression = ctx.options().get<int>("aod-writer-compression");
543+
}
544+
workflow.push_back(AnalysisSupportHelpers::getGlobalAODSink(dod, outputsInputsAOD, compression));
540545
}
541546
// Move the dummy sink at the end, if needed
542547
for (size_t i = 0; i < workflow.size(); ++i) {

Framework/Core/src/ConfigParamDiscovery.cxx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ std::vector<ConfigParamSpec> ConfigParamDiscovery::discover(ConfigParamRegistry&
2727
std::vector<char const*> capabilitiesSpecs = {
2828
"O2Framework:DiscoverMetadataInAODCapability",
2929
"O2Framework:DiscoverMetadataInCommandLineCapability",
30+
"O2Framework:DiscoverAODOptionsInCommandLineCapability",
3031
};
3132

3233
// Load all the requested plugins and discover what we can do.

Framework/Core/src/DataOutputDirector.cxx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -455,7 +455,7 @@ std::vector<DataOutputDescriptor*> DataOutputDirector::getDataOutputDescriptors(
455455
return result;
456456
}
457457

458-
FileAndFolder DataOutputDirector::getFileFolder(DataOutputDescriptor* dodesc, uint64_t folderNumber, std::string parentFileName)
458+
FileAndFolder DataOutputDirector::getFileFolder(DataOutputDescriptor* dodesc, uint64_t folderNumber, std::string parentFileName, int compression)
459459
{
460460
// initialisation
461461
FileAndFolder fileAndFolder;
@@ -488,7 +488,7 @@ FileAndFolder DataOutputDirector::getFileFolder(DataOutputDescriptor* dodesc, ui
488488
auto fn = resdirname + "/" + mfilenameBases[ind] + ".root";
489489
delete mfilePtrs[ind];
490490
mParentMaps[ind]->Clear();
491-
mfilePtrs[ind] = TFile::Open(fn.c_str(), mfileMode.c_str(), "", 505);
491+
mfilePtrs[ind] = TFile::Open(fn.c_str(), mfileMode.c_str(), "", compression);
492492
}
493493
fileAndFolder.file = mfilePtrs[ind];
494494

Framework/Core/src/Plugin.cxx

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
#include "Framework/Capability.h"
1616
#include "Framework/Signpost.h"
1717
#include "Framework/VariantJSONHelpers.h"
18+
#include <cstddef>
1819
#include <string_view>
1920

2021
O2_DECLARE_DYNAMIC_LOG(capabilities);
@@ -47,6 +48,19 @@ auto lookForCommandLineOptions = [](ConfigParamRegistry& registry, int argc, cha
4748
return false;
4849
};
4950

51+
auto lookForCommandLineAODOptions = [](ConfigParamRegistry& registry, int argc, char** argv) -> bool {
52+
O2_SIGNPOST_ID_GENERATE(sid, capabilities);
53+
// If one of the options for aod-writer is specified, we should allow configuring compression.
54+
for (size_t i = 0; i < argc; i++) {
55+
std::string_view arg = argv[i];
56+
if (arg.starts_with("--aod-writer-")) {
57+
O2_SIGNPOST_EVENT_EMIT(capabilities, sid, "DiscoverAODOptionsInCommandLineCapability", "AOD options found in arguments. Populating from them.");
58+
return true;
59+
}
60+
}
61+
return false;
62+
};
63+
5064
struct DiscoverMetadataInAODCapability : o2::framework::CapabilityPlugin {
5165
Capability* create() override
5266
{
@@ -68,6 +82,16 @@ struct DiscoverMetadataInCommandLineCapability : o2::framework::CapabilityPlugin
6882
}
6983
};
7084

85+
struct DiscoverAODOptionsInCommandLineCapability : o2::framework::CapabilityPlugin {
86+
Capability* create() override
87+
{
88+
return new Capability{
89+
.name = "DiscoverAODOptionsInCommandLineCapability",
90+
.checkIfNeeded = lookForCommandLineAODOptions,
91+
.requiredPlugin = "O2Framework:DiscoverAODOptionsInCommandLine"};
92+
}
93+
};
94+
7195
struct DiscoverMetadataInCommandLine : o2::framework::ConfigDiscoveryPlugin {
7296
ConfigDiscovery* create() override
7397
{
@@ -99,9 +123,46 @@ struct DiscoverMetadataInCommandLine : o2::framework::ConfigDiscoveryPlugin {
99123
}};
100124
}
101125
};
126+
127+
struct DiscoverAODOptionsInCommandLine : o2::framework::ConfigDiscoveryPlugin {
128+
ConfigDiscovery* create() override
129+
{
130+
return new ConfigDiscovery{
131+
.init = []() {},
132+
.discover = [](ConfigParamRegistry& registry, int argc, char** argv) -> std::vector<ConfigParamSpec> {
133+
O2_SIGNPOST_ID_GENERATE(sid, capabilities);
134+
O2_SIGNPOST_EVENT_EMIT(capabilities, sid, "DiscoverAODOptionsInCommandLine",
135+
"Discovering AOD handling related options in commandline arguments.");
136+
std::vector<ConfigParamSpec> results;
137+
bool injectOption = true;
138+
for (size_t i = 0; i < argc; i++) {
139+
std::string_view arg = argv[i];
140+
if (!arg.starts_with("--aod-writer-")) {
141+
continue;
142+
}
143+
std::string key = arg.data() + 2;
144+
std::string value = argv[i + 1];
145+
O2_SIGNPOST_EVENT_EMIT(capabilities, sid, "DiscoverAODOptionsInCommandLine",
146+
"Found %{public}s with value %{public}s.", key.c_str(), value.c_str());
147+
if (key == "aod-writer-compression") {
148+
int numericValue = std::stoi(value);
149+
results.push_back(ConfigParamSpec{"aod-writer-compression", VariantType::Int, numericValue, {"AOD Compression options"}});
150+
injectOption = false;
151+
}
152+
}
153+
if (injectOption) {
154+
results.push_back(ConfigParamSpec{"aod-writer-compression", VariantType::Int, 505, {"AOD Compression options"}});
155+
}
156+
return results;
157+
}};
158+
}
159+
};
160+
102161
DEFINE_DPL_PLUGINS_BEGIN
103162
DEFINE_DPL_PLUGIN_INSTANCE(DiscoverMetadataInAODCapability, Capability);
104163
DEFINE_DPL_PLUGIN_INSTANCE(DiscoverMetadataInCommandLineCapability, Capability);
164+
DEFINE_DPL_PLUGIN_INSTANCE(DiscoverAODOptionsInCommandLineCapability, Capability);
105165
DEFINE_DPL_PLUGIN_INSTANCE(DiscoverMetadataInCommandLine, ConfigDiscovery);
166+
DEFINE_DPL_PLUGIN_INSTANCE(DiscoverAODOptionsInCommandLine, ConfigDiscovery);
106167
DEFINE_DPL_PLUGINS_END
107168
} // namespace o2::framework

Framework/Core/src/WorkflowHelpers.cxx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -606,7 +606,11 @@ void WorkflowHelpers::injectServiceDevices(WorkflowSpec& workflow, ConfigContext
606606
// add TFNumber and TFFilename as input to the writer
607607
outputsInputsAOD.emplace_back(InputSpec{"tfn", "TFN", "TFNumber"});
608608
outputsInputsAOD.emplace_back(InputSpec{"tff", "TFF", "TFFilename"});
609-
auto fileSink = AnalysisSupportHelpers::getGlobalAODSink(dod, outputsInputsAOD);
609+
int compressionLevel = 505;
610+
if (ctx.options().hasOption("aod-writer-compression")) {
611+
compressionLevel = ctx.options().get<int>("aod-writer-compression");
612+
}
613+
auto fileSink = AnalysisSupportHelpers::getGlobalAODSink(dod, outputsInputsAOD, compressionLevel);
610614
extraSpecs.push_back(fileSink);
611615

612616
auto it = std::find_if(outputsInputs.begin(), outputsInputs.end(), [](InputSpec& spec) -> bool {

Framework/TestWorkflows/src/o2TestHistograms.cxx

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,26 +22,43 @@ using namespace o2;
2222
using namespace o2::framework;
2323
using namespace o2::framework::expressions;
2424

25+
namespace o2::aod
26+
{
27+
namespace skimmedExampleTrack
28+
{
29+
DECLARE_SOA_COLUMN(Pt, pt, float); //!
30+
DECLARE_SOA_COLUMN(Eta, eta, float); //!
31+
} // namespace skimmedExampleTrack
32+
33+
DECLARE_SOA_TABLE(SkimmedExampleTrack, "AOD", "SKIMEXTRK", //!
34+
skimmedExampleTrack::Pt,
35+
skimmedExampleTrack::Eta);
36+
} // namespace o2::aod
37+
2538
struct EtaAndClsHistogramsSimple {
2639
OutputObj<TH2F> etaClsH{TH2F("eta_vs_pt", "#eta vs pT", 102, -2.01, 2.01, 100, 0, 10)};
40+
Produces<o2::aod::SkimmedExampleTrack> skimEx;
2741

2842
void process(aod::Tracks const& tracks)
2943
{
3044
LOGP(info, "Invoking the simple one");
3145
for (auto& track : tracks) {
3246
etaClsH->Fill(track.eta(), track.pt(), 0);
47+
skimEx(track.pt(), track.eta());
3348
}
3449
}
3550
};
3651

3752
struct EtaAndClsHistogramsIUSimple {
3853
OutputObj<TH2F> etaClsH{TH2F("eta_vs_pt", "#eta vs pT", 102, -2.01, 2.01, 100, 0, 10)};
54+
Produces<o2::aod::SkimmedExampleTrack> skimEx;
3955

4056
void process(aod::TracksIU const& tracks)
4157
{
4258
LOGP(info, "Invoking the simple one");
4359
for (auto& track : tracks) {
4460
etaClsH->Fill(track.eta(), track.pt(), 0);
61+
skimEx(track.pt(), track.eta());
4562
}
4663
}
4764
};

0 commit comments

Comments
 (0)