Skip to content

Commit dd213aa

Browse files
committed
[Common] Test new CCDB table
1 parent 0a316ee commit dd213aa

File tree

2 files changed

+215
-0
lines changed

2 files changed

+215
-0
lines changed

Common/TableProducer/CMakeLists.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,12 @@ o2physics_add_dpl_workflow(event-selection-service
2828
O2::DataFormatsITSMFT
2929
COMPONENT_NAME Analysis)
3030

31+
o2physics_add_dpl_workflow(event-selection-service-test-ccdb
32+
SOURCES eventSelectionServiceTestCCDB.cxx
33+
PUBLIC_LINK_LIBRARIES O2Physics::AnalysisCCDB
34+
O2::DataFormatsITSMFT
35+
COMPONENT_NAME Analysis)
36+
3137
o2physics_add_dpl_workflow(event-selection-service-run2
3238
SOURCES eventSelectionServiceRun2.cxx
3339
PUBLIC_LINK_LIBRARIES O2Physics::AnalysisCCDB
Lines changed: 209 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,209 @@
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 "Common/Core/MetadataHelper.h"
23+
#include "Common/DataModel/EventSelection.h"
24+
#include "Common/Tools/EventSelectionModule.h"
25+
#include "Common/Tools/timestampModule.h"
26+
27+
#include <CCDB/BasicCCDBManager.h>
28+
#include <Framework/AnalysisDataModel.h>
29+
#include <Framework/AnalysisHelpers.h>
30+
#include <Framework/AnalysisTask.h>
31+
#include <Framework/Configurable.h>
32+
#include <Framework/DataTypes.h>
33+
#include <Framework/HistogramRegistry.h>
34+
#include <Framework/InitContext.h>
35+
#include <Framework/OutputObjHeader.h>
36+
#include <Framework/runDataProcessing.h>
37+
38+
#include <cstdint>
39+
#include <stdexcept>
40+
#include <string>
41+
#include <vector>
42+
43+
using namespace o2;
44+
using namespace o2::framework;
45+
46+
o2::common::core::MetadataHelper metadataInfo; // Metadata helper
47+
48+
using BCsWithRun2InfosAndMatches = soa::Join<aod::BCs, aod::Run2BCInfos, aod::Run2MatchedToBCSparse>;
49+
using BCsWithRun3Matchings = soa::Join<aod::BCs, aod::Run3MatchedToBCSparse>;
50+
using FullTracks = soa::Join<aod::Tracks, aod::TracksExtra>;
51+
using FullTracksIU = soa::Join<aod::TracksIU, aod::TracksExtra>;
52+
53+
struct eventselectionRun2TestCCDB {
54+
o2::common::timestamp::timestampConfigurables timestampConfigurables;
55+
o2::common::timestamp::TimestampModule timestampMod;
56+
57+
o2::common::eventselection::bcselConfigurables bcselOpts;
58+
o2::common::eventselection::BcSelectionModule bcselmodule;
59+
60+
o2::common::eventselection::evselConfigurables evselOpts;
61+
o2::common::eventselection::EventSelectionModule evselmodule;
62+
63+
Produces<aod::Timestamps> timestampTable; /// Table with SOR timestamps produced by the task
64+
Produces<aod::BcSels> bcsel;
65+
Produces<aod::EvSels> evsel;
66+
67+
// for slicing
68+
SliceCache cache;
69+
70+
// CCDB boilerplate declarations
71+
o2::framework::Configurable<std::string> ccdburl{"ccdburl", "http://alice-ccdb.cern.ch", "url of the ccdb repository"};
72+
Service<o2::ccdb::BasicCCDBManager> ccdb;
73+
74+
HistogramRegistry histos{"Histos", {}, OutputObjHandlingPolicy::AnalysisObject};
75+
76+
// buffering intermediate results for passing
77+
std::vector<uint64_t> timestamps;
78+
std::vector<o2::common::eventselection::bcselEntry> bcselsbuffer;
79+
80+
// auxiliary
81+
Partition<FullTracks> tracklets = (aod::track::trackType == static_cast<uint8_t>(o2::aod::track::TrackTypeEnum::Run2Tracklet));
82+
Preslice<FullTracks> perCollision = aod::track::collisionId;
83+
84+
void init(o2::framework::InitContext& context)
85+
{
86+
// CCDB boilerplate init
87+
ccdb->setCaching(true);
88+
ccdb->setLocalObjectValidityChecking();
89+
ccdb->setURL(ccdburl.value);
90+
91+
// task-specific
92+
timestampMod.init(timestampConfigurables, metadataInfo);
93+
bcselmodule.init(context, bcselOpts, histos, metadataInfo);
94+
evselmodule.init(context, evselOpts, histos, metadataInfo);
95+
}
96+
97+
void process(BCsWithRun2InfosAndMatches const& bcs,
98+
aod::Collisions const& collisions,
99+
aod::Zdcs const&,
100+
aod::FV0As const&,
101+
aod::FV0Cs const&,
102+
aod::FT0s const&,
103+
aod::FDDs const&,
104+
FullTracks const&)
105+
{
106+
timestampMod.process(bcs, ccdb, timestamps, timestampTable);
107+
bcselmodule.processRun2(ccdb, bcs, timestamps, bcselsbuffer, bcsel);
108+
evselmodule.processRun2(ccdb, histos, collisions, tracklets, cache, timestamps, bcselsbuffer, evsel);
109+
}
110+
};
111+
112+
struct eventselectionRun3TestCCDB {
113+
o2::common::timestamp::timestampConfigurables timestampConfigurables;
114+
o2::common::timestamp::TimestampModule timestampMod;
115+
116+
o2::common::eventselection::bcselConfigurables bcselOpts;
117+
o2::common::eventselection::BcSelectionModule bcselmodule;
118+
119+
o2::common::eventselection::evselConfigurables evselOpts;
120+
o2::common::eventselection::EventSelectionModule evselmodule;
121+
122+
o2::common::eventselection::lumiConfigurables lumiOpts;
123+
o2::common::eventselection::LumiModule lumimodule;
124+
125+
Produces<aod::Timestamps> timestampTable; /// Table with SOR timestamps produced by the task
126+
Produces<aod::BcSels> bcsel;
127+
Produces<aod::EvSels> evsel;
128+
129+
// for slicing
130+
SliceCache cache;
131+
132+
// CCDB boilerplate declarations
133+
o2::framework::Configurable<std::string> ccdburl{"ccdburl", "http://alice-ccdb.cern.ch", "url of the ccdb repository"};
134+
Service<o2::ccdb::BasicCCDBManager> ccdb;
135+
136+
HistogramRegistry histos{"Histos", {}, OutputObjHandlingPolicy::AnalysisObject};
137+
138+
// the best: have readable cursors
139+
// this: a stopgap solution to avoid spawning yet another device
140+
std::vector<uint64_t> timestamps;
141+
std::vector<o2::common::eventselection::bcselEntry> bcselsbuffer;
142+
143+
// auxiliary
144+
Partition<FullTracksIU> pvTracks = ((aod::track::flags & static_cast<uint32_t>(o2::aod::track::PVContributor)) == static_cast<uint32_t>(o2::aod::track::PVContributor));
145+
Preslice<FullTracksIU> perCollisionIU = aod::track::collisionId;
146+
147+
void init(o2::framework::InitContext& context)
148+
{
149+
// CCDB boilerplate init
150+
ccdb->setCaching(true);
151+
ccdb->setLocalObjectValidityChecking();
152+
ccdb->setURL(ccdburl.value);
153+
154+
// task-specific
155+
timestampMod.init(timestampConfigurables, metadataInfo);
156+
bcselmodule.init(context, bcselOpts, histos, metadataInfo);
157+
evselmodule.init(context, evselOpts, histos, metadataInfo);
158+
lumimodule.init(context, lumiOpts, histos);
159+
}
160+
161+
void process(aod::Collisions const& collisions,
162+
BCsWithRun3Matchings const& bcs,
163+
aod::Zdcs const&,
164+
aod::FV0As const&,
165+
aod::FT0s const& ft0s, // to resolve iterator
166+
aod::FDDs const&,
167+
FullTracksIU const&)
168+
{
169+
timestampMod.process(bcs, ccdb, timestamps, timestampTable);
170+
bcselmodule.processRun3(ccdb, histos, bcs, timestamps, bcselsbuffer, bcsel);
171+
evselmodule.processRun3(ccdb, histos, bcs, collisions, pvTracks, ft0s, cache, timestamps, bcselsbuffer, evsel);
172+
lumimodule.process(ccdb, histos, bcs, timestamps, bcselsbuffer);
173+
}
174+
};
175+
176+
WorkflowSpec defineDataProcessing(ConfigContext const& cfgc)
177+
{
178+
// Parse the metadata for later too
179+
metadataInfo.initMetadata(cfgc);
180+
181+
bool isRun3 = true, hasRunInfo = false;
182+
if (cfgc.options().hasOption("aod-metadata-Run") == true) {
183+
hasRunInfo = true;
184+
if (cfgc.options().get<std::string>("aod-metadata-Run") == "2") {
185+
isRun3 = false;
186+
}
187+
}
188+
189+
LOGF(info, "Event selection autoconfiguring from metadata. Availability of info for Run 2/3 is %i", hasRunInfo);
190+
if (!hasRunInfo) {
191+
LOGF(warn, "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.");
192+
LOGF(warn, "Initializing with Run 3 data as default. Please note you will not be able to change settings manually.");
193+
LOGF(warn, "You should instead make sure the metadata is read in correctly.");
194+
return WorkflowSpec{adaptAnalysisTask<eventselectionRun3TestCCDB>(cfgc)};
195+
} else {
196+
LOGF(info, "Metadata successfully read in. Is this Run 3? %i - will self-configure.", isRun3);
197+
if (isRun3) {
198+
return WorkflowSpec{adaptAnalysisTask<eventselectionRun3TestCCDB>(cfgc)};
199+
} else {
200+
LOGF(warn, "******************************************************************");
201+
LOGF(warn, " Event selection service self-configuring for Run 2.");
202+
LOGF(warn, " WARNING: THIS HAS NOT BEEN VALIDATED YET, USE WITH CAUTION");
203+
LOGF(warn, " If this fails, please use event-selection-service-run2 instead.");
204+
LOGF(warn, "******************************************************************");
205+
return WorkflowSpec{adaptAnalysisTask<eventselectionRun2TestCCDB>(cfgc)};
206+
}
207+
}
208+
throw std::runtime_error("Unsupported run type / problem when configuring event selection!");
209+
}

0 commit comments

Comments
 (0)