Skip to content

Commit 3385eae

Browse files
author
David Dobrigkeit Chinellato
committed
[Common] Self-configuring, single-device event selection
1 parent bd793a5 commit 3385eae

File tree

3 files changed

+1736
-0
lines changed

3 files changed

+1736
-0
lines changed

Common/TableProducer/CMakeLists.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,11 @@ o2physics_add_dpl_workflow(event-selection
2727
PUBLIC_LINK_LIBRARIES O2Physics::AnalysisCCDB
2828
COMPONENT_NAME Analysis)
2929

30+
o2physics_add_dpl_workflow(event-selection-service
31+
SOURCES eventSelectionService.cxx
32+
PUBLIC_LINK_LIBRARIES O2Physics::AnalysisCCDB
33+
COMPONENT_NAME Analysis)
34+
3035
o2physics_add_dpl_workflow(multiplicity-table
3136
SOURCES multiplicityTable.cxx
3237
PUBLIC_LINK_LIBRARIES O2Physics::AnalysisCore
Lines changed: 188 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,188 @@
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 eventSelectionTester.cxx
13+
/// \brief unified, self-configuring event selection task
14+
/// \author ALICE
15+
16+
//===============================================================
17+
//
18+
// Unified, self-configuring event selection task
19+
//
20+
//===============================================================
21+
22+
#include "Framework/AnalysisDataModel.h"
23+
#include "Framework/AnalysisTask.h"
24+
#include "Framework/runDataProcessing.h"
25+
#include "Framework/RunningWorkflowInfo.h"
26+
#include "Common/DataModel/TrackSelectionTables.h"
27+
#include "Common/Core/trackUtilities.h"
28+
#include "ReconstructionDataFormats/DCA.h"
29+
#include "DetectorsBase/Propagator.h"
30+
#include "DetectorsBase/GeometryManager.h"
31+
#include "CommonUtils/NameConf.h"
32+
#include "CCDB/CcdbApi.h"
33+
#include "DataFormatsParameters/GRPMagField.h"
34+
#include "CCDB/BasicCCDBManager.h"
35+
#include "Framework/HistogramRegistry.h"
36+
#include "DataFormatsCalibration/MeanVertexObject.h"
37+
#include "CommonConstants/GeomConstants.h"
38+
#include "Common/Tools/EventSelectionTools.h"
39+
#include "MetadataHelper.h"
40+
41+
using namespace o2;
42+
using namespace o2::framework;
43+
44+
MetadataHelper metadataInfo; // Metadata helper
45+
46+
using BCsWithRun2InfosTimestampsAndMatches = soa::Join<aod::BCs, aod::Run2BCInfos, aod::Timestamps, aod::Run2MatchedToBCSparse>;
47+
using BCsWithRun3Matchings = soa::Join<aod::BCs, aod::Timestamps, aod::Run3MatchedToBCSparse>;
48+
using FullTracks = soa::Join<aod::Tracks, aod::TracksExtra>;
49+
using FullTracksIU = soa::Join<aod::TracksIU, aod::TracksExtra>;
50+
51+
struct eventselectionRun2 {
52+
o2::common::eventselection::bcselConfigurables bcselOpts;
53+
o2::common::eventselection::BcSelectionModule bcselmodule;
54+
55+
o2::common::eventselection::evselConfigurables evselOpts;
56+
o2::common::eventselection::EventSelectionModule evselmodule;
57+
58+
Produces<aod::BcSels> bcsel;
59+
Produces<aod::EvSels> evsel;
60+
61+
// for slicing
62+
SliceCache cache;
63+
64+
// CCDB boilerplate declarations
65+
o2::framework::Configurable<std::string> ccdburl{"ccdburl", "http://alice-ccdb.cern.ch", "url of the ccdb repository"};
66+
Service<o2::ccdb::BasicCCDBManager> ccdb;
67+
68+
HistogramRegistry histos{"Histos", {}, OutputObjHandlingPolicy::AnalysisObject};
69+
70+
// the best: have readable cursors
71+
// this: a stopgap solution to avoid spawning yet another device
72+
std::vector<o2::common::eventselection::bcselEntry> bcselsbuffer;
73+
74+
// auxiliary
75+
Partition<FullTracks> tracklets = (aod::track::trackType == static_cast<uint8_t>(o2::aod::track::TrackTypeEnum::Run2Tracklet));
76+
Preslice<FullTracks> perCollision = aod::track::collisionId;
77+
78+
void init(o2::framework::InitContext&)
79+
{
80+
// CCDB boilerplate init
81+
ccdb->setCaching(true);
82+
ccdb->setLocalObjectValidityChecking();
83+
ccdb->setURL(ccdburl.value);
84+
85+
// task-specific
86+
bcselmodule.init(bcselOpts, histos);
87+
evselmodule.init(evselOpts, histos, metadataInfo);
88+
}
89+
90+
void process(BCsWithRun2InfosTimestampsAndMatches const& bcs,
91+
aod::Collisions const& collisions,
92+
aod::Zdcs const&,
93+
aod::FV0As const&,
94+
aod::FV0Cs const&,
95+
aod::FT0s const&,
96+
aod::FDDs const&,
97+
FullTracks const&)
98+
{
99+
auto bcselbuffer = bcselmodule.processRun2(ccdb, bcs, bcsel);
100+
evselmodule.processRun2(ccdb, histos, collisions, tracklets, cache, bcselbuffer, evsel);
101+
}
102+
};
103+
104+
struct eventselectionRun3 {
105+
o2::common::eventselection::bcselConfigurables bcselOpts;
106+
o2::common::eventselection::BcSelectionModule bcselmodule;
107+
108+
o2::common::eventselection::evselConfigurables evselOpts;
109+
o2::common::eventselection::EventSelectionModule evselmodule;
110+
111+
o2::common::eventselection::LumiModule lumimodule;
112+
113+
Produces<aod::BcSels> bcsel;
114+
Produces<aod::EvSels> evsel;
115+
116+
// for slicing
117+
SliceCache cache;
118+
119+
// CCDB boilerplate declarations
120+
o2::framework::Configurable<std::string> ccdburl{"ccdburl", "http://alice-ccdb.cern.ch", "url of the ccdb repository"};
121+
Service<o2::ccdb::BasicCCDBManager> ccdb;
122+
123+
HistogramRegistry histos{"Histos", {}, OutputObjHandlingPolicy::AnalysisObject};
124+
125+
// the best: have readable cursors
126+
// this: a stopgap solution to avoid spawning yet another device
127+
std::vector<o2::common::eventselection::bcselEntry> bcselsbuffer;
128+
129+
// auxiliary
130+
Partition<FullTracksIU> pvTracks = ((aod::track::flags & static_cast<uint32_t>(o2::aod::track::PVContributor)) == static_cast<uint32_t>(o2::aod::track::PVContributor));
131+
Preslice<FullTracksIU> perCollisionIU = aod::track::collisionId;
132+
133+
void init(o2::framework::InitContext&)
134+
{
135+
// CCDB boilerplate init
136+
ccdb->setCaching(true);
137+
ccdb->setLocalObjectValidityChecking();
138+
ccdb->setURL(ccdburl.value);
139+
140+
// task-specific
141+
bcselmodule.init(bcselOpts, histos);
142+
evselmodule.init(evselOpts, histos, metadataInfo);
143+
lumimodule.init(histos);
144+
}
145+
146+
void process(aod::Collisions const& collisions,
147+
BCsWithRun3Matchings const& bcs,
148+
aod::Zdcs const&,
149+
aod::FV0As const&,
150+
aod::FT0s const& ft0s, // to resolve iterator
151+
aod::FDDs const&,
152+
FullTracksIU const&)
153+
{
154+
auto bcselbuffer = bcselmodule.processRun3(ccdb, histos, bcs, bcsel);
155+
evselmodule.processRun3(ccdb, histos, bcs, collisions, pvTracks, ft0s, cache, bcselbuffer, evsel);
156+
lumimodule.process(ccdb, histos, bcs, bcselbuffer);
157+
}
158+
};
159+
160+
WorkflowSpec defineDataProcessing(ConfigContext const& cfgc)
161+
{
162+
// Parse the metadata for later too
163+
metadataInfo.initMetadata(cfgc);
164+
165+
bool isRun3 = true, hasRunInfo = false;
166+
if (cfgc.options().hasOption("aod-metadata-Run") == true) {
167+
hasRunInfo = true;
168+
if (cfgc.options().get<std::string>("aod-metadata-Run") == "2") {
169+
isRun3 = false;
170+
}
171+
}
172+
173+
LOGF(info, "Event selection autoconfiguring from metadata. Availability of info for Run 2/3 is %i", hasRunInfo);
174+
if(!hasRunInfo){
175+
LOGF(info, "Metadata info missing or incomplete. Make sure --aod-file is provided at the end of the last workflow and that the AO2D has metadata stored.");
176+
LOGF(info, "Initializing with Run 3 data as default. Please note you will not be able to change settings manually.");
177+
LOGF(info, "You should instead make sure the metadata is read in correctly.");
178+
return WorkflowSpec{adaptAnalysisTask<eventselectionRun3>(cfgc)};
179+
}else{
180+
LOGF(info, "Metadata successfully read in. Is this Run 3? %i - will self-configure.", isRun3);
181+
if(isRun3){
182+
return WorkflowSpec{adaptAnalysisTask<eventselectionRun3>(cfgc)};
183+
}else{
184+
return WorkflowSpec{adaptAnalysisTask<eventselectionRun2>(cfgc)};
185+
}
186+
}
187+
throw std::runtime_error("Unsupported run type / problem when configuring event selection!");
188+
}

0 commit comments

Comments
 (0)