-
Notifications
You must be signed in to change notification settings - Fork 651
Expand file tree
/
Copy pathtestMetadataHelper.C
More file actions
84 lines (74 loc) · 3.17 KB
/
testMetadataHelper.C
File metadata and controls
84 lines (74 loc) · 3.17 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
// 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.
/// \file testMetadataHelper.C
/// \author Nicolò Jacazio nicolo.jacazio@cern.ch
/// \brief Test the MetadataHelper functionality
#include "Common/Core/MetadataHelper.h"
#include <Framework/ConfigContext.h>
#include <Framework/ConfigParamRegistry.h>
#include <Framework/ConfigParamStore.h>
#include <Framework/ServiceRegistry.h>
#include <Framework/ServiceRegistryRef.h>
#include <TFile.h>
#include <TMap.h>
#include <TObjString.h>
#include <memory>
#include <string>
#include <utility>
#include <vector>
// Taken from O2/Framework/AnalysisSupport/src/Plugin.cxx
auto readMetadata(std::unique_ptr<TFile>& currentFile) -> std::vector<o2::framework::ConfigParamSpec>
{
// Get the metadata, if any
auto m = (TMap*)currentFile->Get("metaData");
if (!m) {
return {};
}
std::vector<o2::framework::ConfigParamSpec> results;
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 \"{}\":", currentFile->GetName());
first = false;
}
auto objString = (TObjString*)m->GetValue(obj);
std::string key = "aod-metadata-" + std::string(obj->GetName());
LOGP(info, "- {}: {} goes into key {}", obj->GetName(), objString->String().Data(), key);
char const* value = strdup(objString->String());
results.push_back(o2::framework::ConfigParamSpec{key, o2::framework::VariantType::String, value, {"Metadata in AOD"}});
}
return results;
}
void testMetadataHelper(std::string aod = "/tmp/AO2D.root")
{
TFile* file = TFile::Open(aod.c_str());
if (!file || file->IsZombie()) {
LOG(fatal) << "Could not open file " << aod;
}
std::unique_ptr<TFile> currentFile{file};
std::vector<o2::framework::ConfigParamSpec> specs = readMetadata(currentFile);
std::vector<std::unique_ptr<o2::framework::ParamRetriever>> retrievers;
auto paramStore = std::make_unique<o2::framework::ConfigParamStore>(specs, std::move(retrievers));
paramStore->preload();
paramStore->activate();
o2::framework::ConfigParamRegistry paramRegistry(std::move(paramStore));
o2::framework::ServiceRegistry serviceRegistry;
o2::framework::ServiceRegistryRef services(serviceRegistry);
o2::framework::ConfigContext aodCfg(paramRegistry, services, 0, nullptr);
LOG(info) << "Loaded " << aodCfg.options().specs().size() << " configuration entries from file " << aod;
aodCfg.options().get<std::string>("aod-metadata-DataType");
o2::common::core::MetadataHelper metadataInfo;
metadataInfo.initMetadata(aodCfg);
metadataInfo.print();
LOG(info) << "Metadata label: " << metadataInfo.makeMetadataLabel();
}