Skip to content
Merged
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
4 changes: 2 additions & 2 deletions Framework/AnalysisSupport/src/AODJAlienReaderHelpers.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -133,12 +133,12 @@ AlgorithmSpec AODJAlienReaderHelpers::rootFileReaderCallback()
stats.updateStats({static_cast<short>(ProcessingStatsId::ARROW_MESSAGES_DESTROYED), DataProcessingStats::Op::Set, 0});
stats.updateStats({static_cast<short>(ProcessingStatsId::ARROW_BYTES_EXPIRED), DataProcessingStats::Op::Set, 0});

if (!options.isSet("aod-file")) {
if (!options.isSet("aod-file-private")) {
LOGP(fatal, "No input file defined!");
throw std::runtime_error("Processing is stopped!");
}

auto filename = options.get<std::string>("aod-file");
auto filename = options.get<std::string>("aod-file-private");

std::string parentFileReplacement;
if (options.isSet("aod-parent-base-path-replacement")) {
Expand Down
1 change: 1 addition & 0 deletions Framework/Core/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ o2_add_library(Framework
src/DefaultsHelpers.cxx
src/DomainInfoHeader.cxx
src/ProcessingPoliciesHelpers.cxx
src/ConfigParamDiscovery.cxx
src/ConfigParamStore.cxx
src/ConfigParamsHelper.cxx
src/ChannelParamSpec.cxx
Expand Down
34 changes: 34 additions & 0 deletions Framework/Core/include/Framework/ConfigParamDiscovery.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
// Copyright 2019-2020 CERN and copyright holders of ALICE O2.
// See https://alice-o2.web.cern.ch/copyright for details of the copyright holders.
// All rights not expressly granted are reserved.
//
// This software is distributed under the terms of the GNU General Public
// License v3 (GPL Version 3), copied verbatim in the file "COPYING".
//
// In applying this license CERN does not waive the privileges and immunities
// granted to it by virtue of its status as an Intergovernmental Organization
// or submit itself to any jurisdiction.

#ifndef O2_FRAMEWORK_CONFIGPARAMDISCOVERY_H_
#define O2_FRAMEWORK_CONFIGPARAMDISCOVERY_H_

#include "Framework/ConfigParamRegistry.h"

namespace o2::framework
{
struct ConfigParamDiscovery {
/// Given a ConfigParamRegistry, discovers all the extrac ConfigParam
/// which require an additional lookup starting from the ones already
/// present. E.g. you could use this to populate the registry with
/// ConfigParams defined in a file.
static void discover(ConfigParamRegistry& registry);
};

/// A plugin which is able to discover more option then the ones
/// provided on the command line.
struct ConfigDiscoveryPlugin {
virtual void discover(ConfigParamRegistry& registry) = 0;
};

} // namespace o2::framework
#endif // O2_FRAMEWORK_CONFIGPARAMDISCOVERY_H_
3 changes: 3 additions & 0 deletions Framework/Core/include/Framework/runDataProcessing.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
#include "Framework/Logger.h"
#include "Framework/CheckTypes.h"
#include "Framework/StructToTuple.h"
#include "Framework/ConfigParamDiscovery.h"

#include <vector>
#include <cstring>
Expand Down Expand Up @@ -203,6 +204,8 @@ int mainNoCatch(int argc, char** argv)
workflowOptionsStore->preload();
workflowOptionsStore->activate();
ConfigParamRegistry workflowOptionsRegistry(std::move(workflowOptionsStore));
ConfigParamDiscovery::discover(workflowOptionsRegistry);

ConfigContext configContext(workflowOptionsRegistry, argc, argv);
o2::framework::WorkflowSpec specs = defineDataProcessing(configContext);
overrideCloning(configContext, specs);
Expand Down
71 changes: 71 additions & 0 deletions Framework/Core/src/ConfigParamDiscovery.cxx
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
// Copyright 2019-2020 CERN and copyright holders of ALICE O2.
// See https://alice-o2.web.cern.ch/copyright for details of the copyright holders.
// All rights not expressly granted are reserved.
//
// This software is distributed under the terms of the GNU General Public
// License v3 (GPL Version 3), copied verbatim in the file "COPYING".
//
// In applying this license CERN does not waive the privileges and immunities
// granted to it by virtue of its status as an Intergovernmental Organization
// or submit itself to any jurisdiction.

#include "Framework/ConfigParamDiscovery.h"
#include "Framework/Plugins.h"
#include <TFile.h>
#include <TMap.h>
#include <TObjString.h>

namespace o2::framework
{

void ConfigParamDiscovery::discover(ConfigParamRegistry& registry)
{
// Keep track of the plugins
std::vector<PluginInfo> plugins;
if (registry.hasOption("aod-file") && registry.isSet("aod-file")) {
auto filename = registry.get<std::string>("aod-file");
if (filename.empty()) {
return;
}
TFile* currentFile = nullptr;
if (filename.at(0) == '@') {
filename.erase(0, 1);
// read the text file and set filename to the contents of the first line
std::ifstream file(filename);
if (!file.is_open()) {
LOGP(fatal, "Couldn't open file \"{}\"!", filename);
}
std::getline(file, filename);
file.close();
currentFile = TFile::Open(filename.c_str());
} else {
currentFile = TFile::Open(filename.c_str());
}
if (!currentFile) {
LOGP(fatal, "Couldn't open file \"{}\"!", filename);
}

// Get the metadata, if any
auto m = (TMap*)currentFile->Get("metaData");
if (!m) {
LOGP(warning, "No metadata found in file \"{}\"", filename);
return;
}
auto it = m->MakeIterator();

// Serialise metadata into a ; separated string with : separating key and value
bool first = true;
while (auto obj = it->Next()) {
if (first) {
LOGP(info, "Metadata for file \"{}\":", filename);
first = false;
}
auto objString = (TObjString*)m->GetValue(obj);
LOGP(info, "- {}: {}", obj->GetName(), objString->String());
std::string key = "aod-metadata-" + std::string(obj->GetName());
registry.override(key.c_str(), objString->String());
}
}
}

} // namespace o2::framework
4 changes: 4 additions & 0 deletions Framework/Core/src/WorkflowCustomizationHelpers.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,10 @@ std::vector<ConfigParamSpec> WorkflowCustomizationHelpers::requiredWorkflowOptio
// options for AOD rate limiting
{"aod-memory-rate-limit", VariantType::Int64, 0LL, {"Rate limit AOD processing based on memory"}},

// options for the AOD reader
// aod-file needs to be available as workflow option, because we
// can configure the workflow based on the contents of the first file.
{"aod-file", VariantType::String, "", {"Input AOD file"}},
// options for AOD writer
{"aod-writer-json", VariantType::String, "", {"Name of the json configuration file"}},
{"aod-writer-resdir", VariantType::String, "", {"Name of the output directory"}},
Expand Down
2 changes: 1 addition & 1 deletion Framework/Core/src/WorkflowHelpers.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,7 @@ void WorkflowHelpers::injectServiceDevices(WorkflowSpec& workflow, ConfigContext
static_cast<DataAllocator::SubSpecificationType>(compile_time_hash("internal-dpl-aod-reader")),
aodLifetime}},
.algorithm = AlgorithmSpec::dummyAlgorithm(),
.options = {ConfigParamSpec{"aod-file", VariantType::String, {"Input AOD file"}},
.options = {ConfigParamSpec{"aod-file-private", VariantType::String, ctx.options().get<std::string>("aod-file"), {"AOD file"}},
ConfigParamSpec{"aod-reader-json", VariantType::String, {"json configuration file"}},
ConfigParamSpec{"aod-parent-access-level", VariantType::String, {"Allow parent file access up to specified level. Default: no (0)"}},
ConfigParamSpec{"aod-parent-base-path-replacement", VariantType::String, {R"(Replace base path of parent files. Syntax: FROM;TO. E.g. "alien:///path/in/alien;/local/path". Enclose in "" on the command line.)"}},
Expand Down
13 changes: 10 additions & 3 deletions Framework/TestWorkflows/src/o2AnalysisWorkflow.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,14 @@ struct EtaAndClsHistograms {

WorkflowSpec defineDataProcessing(ConfigContext const& cfgc)
{
return WorkflowSpec{
adaptAnalysisTask<EtaAndClsHistograms>(cfgc),
};
// For the sake of running without an option, we do not throw an exception
// in case the option is not present.
if (cfgc.options().hasOption("aod-metadata-Run") == false ||
cfgc.options().get<std::string>("aod-metadata-Run") == "2") {
return WorkflowSpec{
adaptAnalysisTask<EtaAndClsHistograms>(cfgc),
};
} else {
throw std::runtime_error("Unsupported run type");
}
}