20#include <TBufferFile.h>
21#include <TDirectory.h>
22#include <TDirectoryFile.h>
24#include <arrow/dataset/file_base.h>
25#include <arrow/filesystem/filesystem.h>
33auto lookForAodFile = [](ConfigParamRegistry& registry,
int argc,
char** argv) ->
bool {
35 if (registry.hasOption(
"aod-file") && registry.isSet(
"aod-file")) {
36 for (
size_t i = 0;
i < argc;
i++) {
37 std::string_view arg = argv[
i];
38 if (arg.starts_with(
"--aod-metadata-")) {
42 O2_SIGNPOST_EVENT_EMIT(capabilities, sid,
"DiscoverMetadataInAODCapability",
"Metadata not found in arguments. Checking in AOD file.");
48auto lookForCommandLineOptions = [](ConfigParamRegistry& registry,
int argc,
char** argv) ->
bool {
50 for (
size_t i = 0;
i < argc;
i++) {
51 std::string_view arg = argv[
i];
52 if (arg.starts_with(
"--aod-metadata-")) {
53 O2_SIGNPOST_EVENT_EMIT(capabilities, sid,
"DiscoverMetadataInCommandLineCapability",
"Metadata found in arguments. Populating from them.");
60auto lookForCommandLineAODOptions = [](ConfigParamRegistry& registry,
int argc,
char** argv) ->
bool {
63 for (
size_t i = 0;
i < argc;
i++) {
64 std::string_view arg = argv[
i];
65 if (arg.starts_with(
"--aod-writer-")) {
66 O2_SIGNPOST_EVENT_EMIT(capabilities, sid,
"DiscoverAODOptionsInCommandLineCapability",
"AOD options found in arguments. Populating from them.");
69 if (arg.starts_with(
"--aod-parent-")) {
70 O2_SIGNPOST_EVENT_EMIT(capabilities, sid,
"DiscoverAODOptionsInCommandLineCapability",
"AOD options found in arguments. Populating from them.");
81 .name =
"DiscoverMetadataInAODCapability",
82 .checkIfNeeded = lookForAodFile,
83 .requiredPlugin =
"O2FrameworkAnalysisSupport:DiscoverMetadataInAOD"};
92 .name =
"DiscoverMetadataInCommandLineCapability",
93 .checkIfNeeded = lookForCommandLineOptions,
94 .requiredPlugin =
"O2Framework:DiscoverMetadataInCommandLine"};
102 .name =
"DiscoverAODOptionsInCommandLineCapability",
103 .checkIfNeeded = lookForCommandLineAODOptions,
104 .requiredPlugin =
"O2Framework:DiscoverAODOptionsInCommandLine"};
113 .discover = [](ConfigParamRegistry& registry,
int argc,
char** argv) -> std::vector<ConfigParamSpec> {
116 "Discovering metadata for analysis from well known environment variables.");
117 std::vector<ConfigParamSpec> results;
118 for (
size_t i = 0;
i < argc;
i++) {
119 std::string_view arg = argv[
i];
120 if (!arg.starts_with(
"--aod-metadata")) {
123 std::string
key = arg.data() + 2;
124 std::string
value = argv[
i + 1];
126 "Found %{public}s with value %{public}s.",
key.c_str(),
value.c_str());
127 if (
key ==
"aod-metadata-tables") {
128 std::stringstream is(
value);
129 auto arrayValue = VariantJSONHelpers::read<VariantType::ArrayString>(is);
130 results.push_back(ConfigParamSpec{
key, VariantType::ArrayString, arrayValue, {
"Metadata in command line"}});
132 results.push_back(ConfigParamSpec{
key, VariantType::String,
value, {
"Metadata in command line"}});
145 .discover = [](ConfigParamRegistry& registry,
int argc,
char** argv) -> std::vector<ConfigParamSpec> {
148 "Discovering AOD handling related options in commandline arguments.");
149 std::vector<ConfigParamSpec> results;
150 bool injectOption =
true;
151 for (
size_t i = 0;
i < argc;
i++) {
152 std::string_view arg = argv[
i];
153 if (!arg.starts_with(
"--aod-writer-") && !arg.starts_with(
"--aod-parent-")) {
156 std::string
key = arg.data() + 2;
157 std::string
value = argv[
i + 1];
159 "Found %{public}s with value %{public}s.",
key.c_str(),
value.c_str());
160 if (
key ==
"aod-writer-compression") {
161 int numericValue = std::stoi(
value);
162 results.push_back(ConfigParamSpec{
"aod-writer-compression", VariantType::Int, numericValue, {
"AOD Compression options"}});
163 injectOption =
false;
165 if (
key ==
"aod-parent-base-path-replacement") {
166 results.push_back(ConfigParamSpec{
"aod-parent-base-path-replacement", VariantType::String,
value, {R
"(Replace base path of parent files. Syntax: FROM;TO. E.g. "alien:///path/in/alien;/local/path". Enclose in "" on the command line.)"}});
168 if (
key ==
"aod-parent-access-level") {
169 results.push_back(ConfigParamSpec{
"aod-parent-access-level", VariantType::String,
value, {
"Allow parent file access up to specified level. Default: no (0)"}});
173 results.push_back(ConfigParamSpec{
"aod-writer-compression", VariantType::Int, 505, {
"AOD Compression options"}});
180struct ImplementationContext {
181 std::vector<RootArrowFactory> implementations;
184std::function<
void*(std::shared_ptr<arrow::fs::FileSystem>, std::string
const&)> getHandleByClass(
char const* classname)
186 return [
c = TClass::GetClass(classname)](std::shared_ptr<arrow::fs::FileSystem> fs, std::string
const&
path) ->
void* {
187 if (
auto tfileFS = std::dynamic_pointer_cast<TFileFileSystem>(fs)) {
188 return tfileFS->GetFile()->GetObjectChecked(
path.c_str(),
c);
189 }
else if (
auto tbufferFS = std::dynamic_pointer_cast<TBufferFileFS>(fs)) {
190 tbufferFS->GetBuffer()->Reset();
191 return tbufferFS->GetBuffer()->ReadObjectAny(
c);
197std::function<
bool(
char const*)> matchClassByName(std::string_view classname)
199 return [
c = classname](
char const* attempt) ->
bool {
204void lazyLoadFactory(std::vector<RootArrowFactory>& implementations,
char const* specs)
207 if (implementations.empty()) {
208 std::vector<LoadablePlugin> plugins;
210 for (
auto& extra : morePlugins) {
211 plugins.push_back(extra);
213 PluginManager::loadFromPlugin<RootArrowFactory, RootArrowFactoryPlugin>(plugins, implementations);
214 if (implementations.empty()) {
223 auto context =
new ImplementationContext;
227 .lfn2objectPath = [](std::string
s) {
228 std::replace(
s.begin()+1,
s.end(),
'/',
'-');
229 if (
s.starts_with(
"/")) {
234 .getHandle = getHandleByClass(
"ROOT::Experimental::RNTuple"),
235 .checkSupport = matchClassByName(
"ROOT::Experimental::RNTuple"),
236 .factory = [context]() -> RootArrowFactory& {
237 lazyLoadFactory(context->implementations,
"O2FrameworkAnalysisRNTupleSupport:RNTupleObjectReadingImplementation");
238 return context->implementations.back();
246 auto context =
new ImplementationContext;
250 .lfn2objectPath = [](std::string
s) {
return s; },
251 .getHandle = getHandleByClass(
"TTree"),
252 .checkSupport = matchClassByName(
"TTree"),
253 .factory = [context]() -> RootArrowFactory& {
254 lazyLoadFactory(context->implementations,
"O2FrameworkAnalysisTTreeSupport:TTreeObjectReadingImplementation");
255 return context->implementations.back();
#define DEFINE_DPL_PLUGIN_INSTANCE(NAME, KIND)
#define DEFINE_DPL_PLUGINS_END
#define DEFINE_DPL_PLUGINS_BEGIN
#define O2_DECLARE_DYNAMIC_LOG(name)
#define O2_SIGNPOST_ID_GENERATE(name, log)
#define O2_SIGNPOST_EVENT_EMIT(log, id, name, format,...)
GLsizei const GLfloat * value
GLsizei const GLchar *const * path
ConcreteParserVariants< PageSize, BOUNDS_CHECKS > create(T const *buffer, size_t size)
create a raw parser depending on version of RAWDataHeader found at beginning of data
Defining PrimaryVertex explicitly as messageable.
@ RootObjectReadingCapability
static std::vector< LoadablePlugin > parsePluginSpecString(char const *str)
Parse a comma separated list of <library>:<plugin-name> plugin declarations.