Skip to content

Commit 299e429

Browse files
authored
Merge branch 'AliceO2Group:master' into master
2 parents a762576 + 4bc7f94 commit 299e429

25 files changed

+891
-577
lines changed

Common/Core/MetadataHelper.cxx

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,3 +124,19 @@ bool MetadataHelper::isInitialized() const
124124
}
125125
return mIsInitialized;
126126
}
127+
128+
std::string MetadataHelper::makeMetadataLabel() const
129+
{
130+
if (!mIsInitialized) {
131+
LOG(fatal) << "Metadata not initialized";
132+
}
133+
std::string label = get("DataType");
134+
label += "_" + get("LPMProductionTag");
135+
if (isMC()) {
136+
label += "_" + get("AnchorPassName");
137+
label += "_" + get("AnchorProduction");
138+
} else {
139+
label += "_" + get("RecoPassName");
140+
}
141+
return label;
142+
}

Common/Core/MetadataHelper.h

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,10 @@
88
// In applying this license CERN does not waive the privileges and immunities
99
// granted to it by virtue of its status as an Intergovernmental Organization
1010
// or submit itself to any jurisdiction.
11-
/// \file TableHelper.h
11+
12+
/// \file MetadataHelper.h
13+
/// \brief Utility to handle the metadata from the AOD
1214
/// \author Nicolò Jacazio nicolo.jacazio@cern.ch
13-
/// \brief Utility to handle the metadata from the AOD
14-
///
1515

1616
#ifndef COMMON_CORE_METADATAHELPER_H_
1717
#define COMMON_CORE_METADATAHELPER_H_
@@ -61,6 +61,9 @@ struct MetadataHelper {
6161
/// @return true if the key is defined, false otherwise. Throws an exception if the key is not found
6262
bool isKeyDefined(const std::string& key) const;
6363

64+
/// @brief Function to create a label with the metadata information, useful e.g. for histogram naming
65+
std::string makeMetadataLabel() const;
66+
6467
private:
6568
std::map<std::string, std::string> mMetadata; /// < The metadata map
6669
bool mIsInitialized = false; /// < Flag to check if the metadata has been initialized
Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
// Copyright 2019-2020 CERN and copyright holders of ALICE O2.
2+
// See https://alice-o2.web.cern.ch/copyright for details of the copyright holders.
3+
// All rights not expressly granted are reserved.
4+
//
5+
// This software is distributed under the terms of the GNU General Public
6+
// License v3 (GPL Version 3), copied verbatim in the file "COPYING".
7+
//
8+
// In applying this license CERN does not waive the privileges and immunities
9+
// granted to it by virtue of its status as an Intergovernmental Organization
10+
// or submit itself to any jurisdiction.
11+
12+
/// \file testMetadataHelper.C
13+
/// \author Nicolò Jacazio nicolo.jacazio@cern.ch
14+
/// \brief Test the MetadataHelper functionality
15+
16+
#include "Common/Core/MetadataHelper.h"
17+
18+
#include <Framework/ConfigContext.h>
19+
#include <Framework/ConfigParamRegistry.h>
20+
#include <Framework/ConfigParamStore.h>
21+
#include <Framework/ServiceRegistry.h>
22+
#include <Framework/ServiceRegistryRef.h>
23+
24+
#include <TFile.h>
25+
#include <TMap.h>
26+
#include <TObjString.h>
27+
28+
#include <memory>
29+
#include <string>
30+
#include <utility>
31+
#include <vector>
32+
33+
// Taken from O2/Framework/AnalysisSupport/src/Plugin.cxx
34+
auto readMetadata(std::unique_ptr<TFile>& currentFile) -> std::vector<o2::framework::ConfigParamSpec>
35+
{
36+
// Get the metadata, if any
37+
auto m = (TMap*)currentFile->Get("metaData");
38+
if (!m) {
39+
return {};
40+
}
41+
std::vector<o2::framework::ConfigParamSpec> results;
42+
auto it = m->MakeIterator();
43+
44+
// Serialise metadata into a ; separated string with : separating key and value
45+
bool first = true;
46+
while (auto obj = it->Next()) {
47+
if (first) {
48+
LOGP(info, "Metadata for file \"{}\":", currentFile->GetName());
49+
first = false;
50+
}
51+
auto objString = (TObjString*)m->GetValue(obj);
52+
std::string key = "aod-metadata-" + std::string(obj->GetName());
53+
LOGP(info, "- {}: {} goes into key {}", obj->GetName(), objString->String().Data(), key);
54+
char const* value = strdup(objString->String());
55+
results.push_back(o2::framework::ConfigParamSpec{key, o2::framework::VariantType::String, value, {"Metadata in AOD"}});
56+
}
57+
return results;
58+
}
59+
60+
void testMetadataHelper(std::string aod = "/tmp/AO2D.root")
61+
{
62+
63+
TFile* file = TFile::Open(aod.c_str());
64+
if (!file || file->IsZombie()) {
65+
LOG(fatal) << "Could not open file " << aod;
66+
}
67+
std::unique_ptr<TFile> currentFile{file};
68+
std::vector<o2::framework::ConfigParamSpec> specs = readMetadata(currentFile);
69+
70+
std::vector<std::unique_ptr<o2::framework::ParamRetriever>> retrievers;
71+
auto paramStore = std::make_unique<o2::framework::ConfigParamStore>(specs, std::move(retrievers));
72+
paramStore->preload();
73+
paramStore->activate();
74+
o2::framework::ConfigParamRegistry paramRegistry(std::move(paramStore));
75+
o2::framework::ServiceRegistry serviceRegistry;
76+
o2::framework::ServiceRegistryRef services(serviceRegistry);
77+
o2::framework::ConfigContext aodCfg(paramRegistry, services, 0, nullptr);
78+
LOG(info) << "Loaded " << aodCfg.options().specs().size() << " configuration entries from file " << aod;
79+
aodCfg.options().get<std::string>("aod-metadata-DataType");
80+
o2::common::core::MetadataHelper metadataInfo;
81+
metadataInfo.initMetadata(aodCfg);
82+
metadataInfo.print();
83+
LOG(info) << "Metadata label: " << metadataInfo.makeMetadataLabel();
84+
}

PWGCF/Femto/Core/baseSelection.h

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,17 +110,48 @@ class BaseSelection
110110
mSelectionContainers.at(observableIndex) = SelectionContainer<T, BitmaskType>(baseName, lowerLimit, upperLimit, selectionValues, limitType, skipMostPermissiveBit, isMinimalCut);
111111
}
112112

113+
/// \brief Add a boolean based selection for a specific observable.
114+
/// \param mode Whether the selection is not applied, minimal or optional cut
115+
/// \param observableIndex Index of the observable.
116+
void addSelection(int mode, int observableIndex)
117+
{
118+
if (static_cast<size_t>(observableIndex) >= NumObservables) {
119+
LOG(fatal) << "Observable is not valid. Observable (index) has to be smaller than " << NumObservables;
120+
}
121+
switch (mode) {
122+
case -1: // cut is optional and we store bit for the cut
123+
mNSelections += 1;
124+
mHasOptionalSelection = true;
125+
mSelectionContainers.at(observableIndex) = SelectionContainer<T, BitmaskType>(std::vector<T>{1}, limits::LimitType::kEqual, false, false);
126+
break;
127+
case 0: // cut is not applied, initalize with empty vector, so we bail out later
128+
mSelectionContainers.at(observableIndex) = SelectionContainer<T, BitmaskType>(std::vector<T>{}, limits::LimitType::kEqual, false, false);
129+
break;
130+
case 1: // cut is added as mininal selection (since it is only one value, not extra bit is stored)
131+
mSelectionContainers.at(observableIndex) = SelectionContainer<T, BitmaskType>(std::vector<T>{1}, limits::LimitType::kEqual, true, true);
132+
break;
133+
default:
134+
LOG(fatal) << "Invalid switch for boolean selection";
135+
}
136+
if (mNSelections >= sizeof(BitmaskType) * CHAR_BIT) {
137+
LOG(fatal) << "Too many selections. At most " << sizeof(BitmaskType) * CHAR_BIT << " are supported";
138+
}
139+
}
140+
113141
/// \brief Update the limits of a function-based selection for a specific observable.
114142
/// \param observable Index of the observable.
115143
/// \param value Value at which to evaluate the selection functions.
116-
void updateLimits(int observable, T value) { mSelectionContainers.at(observable).updateLimits(value); }
144+
void updateLimits(int observable, T value)
145+
{
146+
mSelectionContainers.at(observable).updateLimits(value);
147+
}
117148

118149
/// \brief Reset the internal bitmask and evaluation flags before evaluating a new event.
119150
void reset()
120151
{
121152
mFinalBitmask.reset();
122153
mPassesMinimalSelections = true;
123-
// will be true if no optional cut as been defined and
154+
// will be true if no optional cut has been defined and
124155
// will be set to false if we have optional cuts (but will be set to true in the case at least one optional cut succeeds)
125156
mPassesOptionalSelections = !mHasOptionalSelection;
126157
}

PWGCF/Femto/Core/cascadeBuilder.h

Lines changed: 27 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -337,23 +337,23 @@ class CascadeBuilder
337337
template <typename T1, typename T2, typename T3, typename T4>
338338
void init(T1& config, T2& filter, T3& table, T4& initContext)
339339
{
340-
cascadeSelection.configure(config, filter);
340+
mCascadeSelection.configure(config, filter);
341341
if constexpr (modes::isEqual(cascadeType, modes::Cascade::kXi)) {
342342
LOG(info) << "Initialize femto Xi builder...";
343-
produceXis = utils::enableTable("FXis_001", table.produceXis.value, initContext);
344-
produceXiMasks = utils::enableTable("FXiMasks_001", table.produceXiMasks.value, initContext);
345-
produceXiExtras = utils::enableTable("FXiExtras_001", table.produceXiExtras.value, initContext);
343+
mProduceXis = utils::enableTable("FXis_001", table.produceXis.value, initContext);
344+
mProduceXiMasks = utils::enableTable("FXiMasks_001", table.produceXiMasks.value, initContext);
345+
mProduceXiExtras = utils::enableTable("FXiExtras_001", table.produceXiExtras.value, initContext);
346346
}
347347
if constexpr (modes::isEqual(cascadeType, modes::Cascade::kOmega)) {
348348
LOG(info) << "Initialize femto Omega builder...";
349-
produceOmegas = utils::enableTable("FOmegas_001", table.produceOmegas.value, initContext);
350-
produceOmegaMasks = utils::enableTable("FOmegaMasks_001", table.produceOmegaMasks.value, initContext);
351-
produceOmegaExtras = utils::enableTable("FOmegaExtras_001", table.produceOmegaExtras.value, initContext);
349+
mProduceOmegas = utils::enableTable("FOmegas_001", table.produceOmegas.value, initContext);
350+
mProduceOmegaMasks = utils::enableTable("FOmegaMasks_001", table.produceOmegaMasks.value, initContext);
351+
mProduceOmegaExtras = utils::enableTable("FOmegaExtras_001", table.produceOmegaExtras.value, initContext);
352352
}
353353

354-
if (produceXis || produceXiExtras || produceXiMasks || produceOmegas || produceOmegaMasks || produceOmegaExtras) {
354+
if (mProduceXis || mProduceXiExtras || mProduceXiMasks || mProduceOmegas || mProduceOmegaMasks || mProduceOmegaExtras) {
355355
mFillAnyTable = true;
356-
cascadeSelection.printSelections(cascadeSelsName, cascadeSelsToString);
356+
mCascadeSelection.printSelections(cascadeSelsName, cascadeSelsToString);
357357
} else {
358358
LOG(info) << "No tables configured";
359359
}
@@ -371,11 +371,11 @@ class CascadeBuilder
371371
int64_t posDaughterIndex = 0;
372372
int64_t negDaughterIndex = 0;
373373
for (const auto& cascade : fullCascades) {
374-
if (!cascadeSelection.checkFilters(cascade)) {
374+
if (!mCascadeSelection.checkFilters(cascade)) {
375375
continue;
376376
}
377-
cascadeSelection.applySelections(cascade, fullTracks, col);
378-
if (cascadeSelection.passesAllRequiredSelections() && cascadeSelection.checkHypothesis(cascade)) {
377+
mCascadeSelection.applySelections(cascade, fullTracks, col);
378+
if (mCascadeSelection.passesAllRequiredSelections() && mCascadeSelection.checkHypothesis(cascade)) {
379379

380380
auto bachelor = cascade.template bachelor_as<T5>();
381381
auto posDaughter = cascade.template posTrack_as<T5>();
@@ -394,7 +394,7 @@ class CascadeBuilder
394394
void fillCascade(T1& collisionProducts, T2& cascadeProducts, T3 const& cascade, T4 const& col, int bachelorIndex, int posDaughterIndex, int negDaughterIndex)
395395
{
396396
if constexpr (modes::isEqual(cascadeType, modes::Cascade::kXi)) {
397-
if (produceXis) {
397+
if (mProduceXis) {
398398
cascadeProducts.producedXis(collisionProducts.producedCollision.lastIndex(),
399399
cascade.sign() * cascade.pt(),
400400
cascade.eta(),
@@ -404,10 +404,10 @@ class CascadeBuilder
404404
posDaughterIndex,
405405
negDaughterIndex);
406406
}
407-
if (produceXiMasks) {
408-
cascadeProducts.producedXiMasks(cascadeSelection.getBitmask());
407+
if (mProduceXiMasks) {
408+
cascadeProducts.producedXiMasks(mCascadeSelection.getBitmask());
409409
}
410-
if (produceXiExtras) {
410+
if (mProduceXiExtras) {
411411
cascadeProducts.producedXiExtras(
412412
cascade.mOmega(),
413413
cascade.casccosPA(col.posX(), col.posY(), col.posZ()),
@@ -420,7 +420,7 @@ class CascadeBuilder
420420
}
421421
}
422422
if constexpr (modes::isEqual(cascadeType, modes::Cascade::kOmega)) {
423-
if (produceOmegas) {
423+
if (mProduceOmegas) {
424424
cascadeProducts.producedOmegas(collisionProducts.producedCollision.lastIndex(),
425425
cascade.sign() * cascade.pt(),
426426
cascade.eta(),
@@ -430,10 +430,10 @@ class CascadeBuilder
430430
posDaughterIndex,
431431
negDaughterIndex);
432432
}
433-
if (produceOmegaMasks) {
434-
cascadeProducts.producedOmegaMasks(cascadeSelection.getBitmask());
433+
if (mProduceOmegaMasks) {
434+
cascadeProducts.producedOmegaMasks(mCascadeSelection.getBitmask());
435435
}
436-
if (produceOmegaExtras) {
436+
if (mProduceOmegaExtras) {
437437
cascadeProducts.producedOmegaExtras(
438438
cascade.mXi(),
439439
cascade.casccosPA(col.posX(), col.posY(), col.posZ()),
@@ -450,14 +450,14 @@ class CascadeBuilder
450450
bool fillAnyTable() { return mFillAnyTable; }
451451

452452
private:
453-
CascadeSelection<cascadeType> cascadeSelection;
453+
CascadeSelection<cascadeType> mCascadeSelection;
454454
bool mFillAnyTable = false;
455-
bool produceXis = false;
456-
bool produceXiMasks = false;
457-
bool produceXiExtras = false;
458-
bool produceOmegas = false;
459-
bool produceOmegaMasks = false;
460-
bool produceOmegaExtras = false;
455+
bool mProduceXis = false;
456+
bool mProduceXiMasks = false;
457+
bool mProduceXiExtras = false;
458+
bool mProduceOmegas = false;
459+
bool mProduceOmegaMasks = false;
460+
bool mProduceOmegaExtras = false;
461461
};
462462

463463
} // namespace cascadebuilder

0 commit comments

Comments
 (0)