Skip to content

Commit 81cfc23

Browse files
ddobrigkalibuild
andauthored
[Common] Fuse new evsel with timestamp (#11827)
Co-authored-by: ALICE Builder <alibuild@users.noreply.github.com>
1 parent acaaf05 commit 81cfc23

File tree

5 files changed

+277
-35
lines changed

5 files changed

+277
-35
lines changed

Common/TableProducer/CMakeLists.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,11 @@ o2physics_add_dpl_workflow(timestamp
5959
PUBLIC_LINK_LIBRARIES O2Physics::AnalysisCore
6060
COMPONENT_NAME Analysis)
6161

62+
o2physics_add_dpl_workflow(timestamptester
63+
SOURCES timestampTester.cxx
64+
PUBLIC_LINK_LIBRARIES O2Physics::AnalysisCore
65+
COMPONENT_NAME Analysis)
66+
6267
o2physics_add_dpl_workflow(weak-decay-indices
6368
SOURCES weakDecayIndices.cxx
6469
PUBLIC_LINK_LIBRARIES O2Physics::AnalysisCore

Common/TableProducer/eventSelectionService.cxx

Lines changed: 24 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
#include "Common/Core/trackUtilities.h"
2525
#include "Common/DataModel/TrackSelectionTables.h"
2626
#include "Common/Tools/EventSelectionTools.h"
27+
#include "Common/Tools/timestampModule.h"
2728

2829
#include "CCDB/BasicCCDBManager.h"
2930
#include "CCDB/CcdbApi.h"
@@ -45,18 +46,22 @@ using namespace o2::framework;
4546

4647
MetadataHelper metadataInfo; // Metadata helper
4748

48-
using BCsWithRun2InfosTimestampsAndMatches = soa::Join<aod::BCs, aod::Run2BCInfos, aod::Timestamps, aod::Run2MatchedToBCSparse>;
49-
using BCsWithRun3Matchings = soa::Join<aod::BCs, aod::Timestamps, aod::Run3MatchedToBCSparse>;
49+
using BCsWithRun2InfosAndMatches = soa::Join<aod::BCs, aod::Run2BCInfos, aod::Run2MatchedToBCSparse>;
50+
using BCsWithRun3Matchings = soa::Join<aod::BCs, aod::Run3MatchedToBCSparse>;
5051
using FullTracks = soa::Join<aod::Tracks, aod::TracksExtra>;
5152
using FullTracksIU = soa::Join<aod::TracksIU, aod::TracksExtra>;
5253

5354
struct eventselectionRun2 {
55+
o2::common::timestamp::timestampConfigurables timestampConfigurables;
56+
o2::common::timestamp::TimestampModule timestampMod;
57+
5458
o2::common::eventselection::bcselConfigurables bcselOpts;
5559
o2::common::eventselection::BcSelectionModule bcselmodule;
5660

5761
o2::common::eventselection::evselConfigurables evselOpts;
5862
o2::common::eventselection::EventSelectionModule evselmodule;
5963

64+
Produces<aod::Timestamps> timestampTable; /// Table with SOR timestamps produced by the task
6065
Produces<aod::BcSels> bcsel;
6166
Produces<aod::EvSels> evsel;
6267

@@ -69,8 +74,8 @@ struct eventselectionRun2 {
6974

7075
HistogramRegistry histos{"Histos", {}, OutputObjHandlingPolicy::AnalysisObject};
7176

72-
// the best: have readable cursors
73-
// this: a stopgap solution to avoid spawning yet another device
77+
// buffering intermediate results for passing
78+
std::vector<uint64_t> timestamps;
7479
std::vector<o2::common::eventselection::bcselEntry> bcselsbuffer;
7580

7681
// auxiliary
@@ -85,11 +90,12 @@ struct eventselectionRun2 {
8590
ccdb->setURL(ccdburl.value);
8691

8792
// task-specific
93+
timestampMod.init(timestampConfigurables, metadataInfo);
8894
bcselmodule.init(context, bcselOpts, histos);
8995
evselmodule.init(context, evselOpts, histos, metadataInfo);
9096
}
9197

92-
void process(BCsWithRun2InfosTimestampsAndMatches const& bcs,
98+
void process(BCsWithRun2InfosAndMatches const& bcs,
9399
aod::Collisions const& collisions,
94100
aod::Zdcs const&,
95101
aod::FV0As const&,
@@ -98,12 +104,16 @@ struct eventselectionRun2 {
98104
aod::FDDs const&,
99105
FullTracks const&)
100106
{
101-
bcselmodule.processRun2(ccdb, bcs, bcselsbuffer, bcsel);
102-
evselmodule.processRun2(ccdb, histos, collisions, tracklets, cache, bcselsbuffer, evsel);
107+
timestampMod.process(bcs, ccdb, timestamps, timestampTable);
108+
bcselmodule.processRun2(ccdb, bcs, timestamps, bcselsbuffer, bcsel);
109+
evselmodule.processRun2(ccdb, histos, collisions, tracklets, cache, timestamps, bcselsbuffer, evsel);
103110
}
104111
};
105112

106113
struct eventselectionRun3 {
114+
o2::common::timestamp::timestampConfigurables timestampConfigurables;
115+
o2::common::timestamp::TimestampModule timestampMod;
116+
107117
o2::common::eventselection::bcselConfigurables bcselOpts;
108118
o2::common::eventselection::BcSelectionModule bcselmodule;
109119

@@ -113,6 +123,7 @@ struct eventselectionRun3 {
113123
o2::common::eventselection::lumiConfigurables lumiOpts;
114124
o2::common::eventselection::LumiModule lumimodule;
115125

126+
Produces<aod::Timestamps> timestampTable; /// Table with SOR timestamps produced by the task
116127
Produces<aod::BcSels> bcsel;
117128
Produces<aod::EvSels> evsel;
118129

@@ -127,6 +138,7 @@ struct eventselectionRun3 {
127138

128139
// the best: have readable cursors
129140
// this: a stopgap solution to avoid spawning yet another device
141+
std::vector<uint64_t> timestamps;
130142
std::vector<o2::common::eventselection::bcselEntry> bcselsbuffer;
131143

132144
// auxiliary
@@ -141,6 +153,7 @@ struct eventselectionRun3 {
141153
ccdb->setURL(ccdburl.value);
142154

143155
// task-specific
156+
timestampMod.init(timestampConfigurables, metadataInfo);
144157
bcselmodule.init(context, bcselOpts, histos);
145158
evselmodule.init(context, evselOpts, histos, metadataInfo);
146159
lumimodule.init(context, lumiOpts, histos);
@@ -154,9 +167,10 @@ struct eventselectionRun3 {
154167
aod::FDDs const&,
155168
FullTracksIU const&)
156169
{
157-
bcselmodule.processRun3(ccdb, histos, bcs, bcselsbuffer, bcsel);
158-
evselmodule.processRun3(ccdb, histos, bcs, collisions, pvTracks, ft0s, cache, bcselsbuffer, evsel);
159-
lumimodule.process(ccdb, histos, bcs, bcselsbuffer);
170+
timestampMod.process(bcs, ccdb, timestamps, timestampTable);
171+
bcselmodule.processRun3(ccdb, histos, bcs, timestamps, bcselsbuffer, bcsel);
172+
evselmodule.processRun3(ccdb, histos, bcs, collisions, pvTracks, ft0s, cache, timestamps, bcselsbuffer, evsel);
173+
lumimodule.process(ccdb, histos, bcs, timestamps, bcselsbuffer);
160174
}
161175
};
162176

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
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+
///
13+
/// \file timestamp.cxx
14+
/// \author Nicolò Jacazio
15+
/// \since 2020-06-22
16+
/// \brief A task to fill the timestamp table from run number.
17+
/// Uses headers from CCDB
18+
///
19+
#include "MetadataHelper.h"
20+
21+
#include "Common/Tools/timestampModule.h"
22+
23+
#include "CCDB/BasicCCDBManager.h"
24+
#include "CommonDataFormat/InteractionRecord.h"
25+
#include "DetectorsRaw/HBFUtils.h"
26+
#include "Framework/AnalysisTask.h"
27+
#include "Framework/runDataProcessing.h"
28+
29+
#include <map>
30+
#include <vector>
31+
32+
using namespace o2::framework;
33+
using namespace o2::header;
34+
using namespace o2;
35+
36+
MetadataHelper metadataInfo; // Metadata helper
37+
38+
struct TimestampTask {
39+
Produces<aod::Timestamps> timestampTable; /// Table with SOR timestamps produced by the task
40+
Service<o2::ccdb::BasicCCDBManager> ccdb; /// CCDB manager to access orbit-reset timestamp
41+
o2::ccdb::CcdbApi ccdb_api; /// API to access CCDB headers
42+
43+
Configurable<std::string> ccdb_url{"ccdb-url", "http://alice-ccdb.cern.ch", "URL of the CCDB database"};
44+
45+
o2::common::timestamp::timestampConfigurables timestampConfigurables;
46+
o2::common::timestamp::TimestampModule timestampMod;
47+
48+
std::vector<int64_t> timestampBuffer;
49+
50+
void init(o2::framework::InitContext&)
51+
{
52+
// CCDB initialization
53+
ccdb->setURL(ccdb_url.value);
54+
ccdb_api.init(ccdb_url.value);
55+
56+
// timestamp configuration + init
57+
timestampMod.init(timestampConfigurables, metadataInfo);
58+
}
59+
60+
void process(aod::BCs const& bcs)
61+
{
62+
timestampMod.process(bcs, ccdb, timestampBuffer, timestampTable);
63+
}
64+
};
65+
66+
WorkflowSpec defineDataProcessing(ConfigContext const& cfgc)
67+
{
68+
// Parse the metadata
69+
metadataInfo.initMetadata(cfgc);
70+
71+
return WorkflowSpec{adaptAnalysisTask<TimestampTask>(cfgc)};
72+
}

Common/Tools/EventSelectionTools.h

Lines changed: 29 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -264,17 +264,18 @@ class BcSelectionModule
264264
}
265265

266266
//__________________________________________________
267-
template <typename TCCDB, typename TBCs, typename TBcSelBuffer, typename TBcSelCursor>
268-
void processRun2(TCCDB const& ccdb, TBCs const& bcs, TBcSelBuffer& bcselbuffer, TBcSelCursor& bcsel)
267+
template <typename TCCDB, typename TBCs, typename TTimestamps, typename TBcSelBuffer, typename TBcSelCursor>
268+
void processRun2(TCCDB const& ccdb, TBCs const& bcs, TTimestamps const& timestamps, TBcSelBuffer& bcselbuffer, TBcSelCursor& bcsel)
269269
{
270270
if (bcselOpts.amIneeded.value == 0) {
271271
bcselbuffer.clear();
272272
return;
273273
}
274274
bcselbuffer.clear();
275275
for (const auto& bc : bcs) {
276-
par = ccdb->template getForTimeStamp<EventSelectionParams>("EventSelection/EventSelectionParams", bc.timestamp());
277-
aliases = ccdb->template getForTimeStamp<TriggerAliases>("EventSelection/TriggerAliases", bc.timestamp());
276+
uint64_t timestamp = timestamps[bc.globalIndex()];
277+
par = ccdb->template getForTimeStamp<EventSelectionParams>("EventSelection/EventSelectionParams", timestamp);
278+
aliases = ccdb->template getForTimeStamp<TriggerAliases>("EventSelection/TriggerAliases", timestamp);
278279
// fill fired aliases
279280
uint32_t alias{0};
280281
uint64_t triggerMask = bc.triggerMask();
@@ -401,8 +402,8 @@ class BcSelectionModule
401402
} // end processRun2
402403

403404
//__________________________________________________
404-
template <typename TCCDB, typename THistoRegistry, typename TBCs, typename TBcSelBuffer, typename TBcSelCursor>
405-
void processRun3(TCCDB const& ccdb, THistoRegistry& histos, TBCs const& bcs, TBcSelBuffer& bcselbuffer, TBcSelCursor& bcsel)
405+
template <typename TCCDB, typename THistoRegistry, typename TBCs, typename TTimestamps, typename TBcSelBuffer, typename TBcSelCursor>
406+
void processRun3(TCCDB const& ccdb, THistoRegistry& histos, TBCs const& bcs, TTimestamps const& timestamps, TBcSelBuffer& bcselbuffer, TBcSelCursor& bcsel)
406407
{
407408
if (bcselOpts.amIneeded.value == 0) {
408409
bcselbuffer.clear();
@@ -426,15 +427,16 @@ class BcSelectionModule
426427

427428
// bc loop
428429
for (auto bc : bcs) { // o2-linter: disable=const-ref-in-for-loop (use bc as nonconst iterator)
430+
uint64_t timestamp = timestamps[bc.globalIndex()];
429431
// store rct flags
430432
uint32_t rct = lastRCT;
431433
int64_t thisTF = (bc.globalBC() - bcSOR) / nBCsPerTF;
432434
if (mapRCT != nullptr && thisTF != lastTF) { // skip for unanchored runs; do it once per TF
433-
auto itrct = mapRCT->upper_bound(bc.timestamp());
435+
auto itrct = mapRCT->upper_bound(timestamp);
434436
if (itrct != mapRCT->begin())
435437
itrct--;
436438
rct = itrct->second;
437-
LOGP(debug, "sor={} eor={} ts={} rct={}", sorTimestamp, eorTimestamp, bc.timestamp(), rct);
439+
LOGP(debug, "sor={} eor={} ts={} rct={}", sorTimestamp, eorTimestamp, timestamp, rct);
438440
lastRCT = rct;
439441
lastTF = thisTF;
440442
}
@@ -560,10 +562,10 @@ class BcSelectionModule
560562
LOGP(debug, "foundFT0={}", foundFT0);
561563

562564
const char* srun = Form("%d", run);
563-
if (bc.timestamp() < sorTimestamp || bc.timestamp() > eorTimestamp) {
565+
if (timestamp < sorTimestamp || timestamp > eorTimestamp) {
564566
histos.template get<TH1>(HIST("bcselection/hCounterInvalidBCTimestamp"))->Fill(srun, 1);
565567
if (bcselOpts.confCheckRunDurationLimits.value) {
566-
LOGF(warn, "Invalid BC timestamp: %d, run: %d, sor: %d, eor: %d", bc.timestamp(), run, sorTimestamp, eorTimestamp);
568+
LOGF(warn, "Invalid BC timestamp: %d, run: %d, sor: %d, eor: %d", timestamp, run, sorTimestamp, eorTimestamp);
567569
alias = 0u;
568570
selection = 0u;
569571
}
@@ -692,8 +694,8 @@ class EventSelectionModule
692694
}
693695

694696
//__________________________________________________
695-
template <typename TCCDB, typename TBCs>
696-
bool configure(TCCDB& ccdb, TBCs const& bcs)
697+
template <typename TCCDB, typename TTimestamps, typename TBCs>
698+
bool configure(TCCDB& ccdb, TTimestamps const& timestamps, TBCs const& bcs)
697699
{
698700
int run = bcs.iteratorAt(0).runNumber();
699701
// extract bc pattern from CCDB for data or anchored MC only
@@ -705,7 +707,8 @@ class EventSelectionModule
705707
// duration of TF in bcs
706708
nBCsPerTF = evselOpts.confNumberOfOrbitsPerTF < 0 ? runInfo.orbitsPerTF * nBCsPerOrbit : evselOpts.confNumberOfOrbitsPerTF * nBCsPerOrbit;
707709
// colliding bc pattern
708-
int64_t ts = bcs.iteratorAt(0).timestamp();
710+
int64_t ts = timestamps[0];
711+
709712
// getForTimeStamp replaced with getSpecific to set metadata to zero
710713
// avoids crash related to specific run number
711714
auto grplhcif = ccdb->template getSpecific<o2::parameters::GRPLHCIFData>("GLO/Config/GRPLHCIF", ts);
@@ -721,15 +724,16 @@ class EventSelectionModule
721724
}
722725

723726
//__________________________________________________
724-
template <typename TCCDB, typename THistoRegistry, typename TCollisions, typename TTracklets, typename TSlicecache, typename TBcSelBuffer, typename TEvselCursor>
725-
void processRun2(TCCDB const& ccdb, THistoRegistry& histos, TCollisions const& collisions, TTracklets const& tracklets, TSlicecache& cache, TBcSelBuffer const& bcselbuffer, TEvselCursor& evsel)
727+
template <typename TCCDB, typename THistoRegistry, typename TCollisions, typename TTracklets, typename TSlicecache, typename TTimestamps, typename TBcSelBuffer, typename TEvselCursor>
728+
void processRun2(TCCDB const& ccdb, THistoRegistry& histos, TCollisions const& collisions, TTracklets const& tracklets, TSlicecache& cache, TTimestamps const& timestamps, TBcSelBuffer const& bcselbuffer, TEvselCursor& evsel)
726729
{
727730
if (evselOpts.amIneeded.value == 0) {
728731
return; // dummy process
729732
}
730733
for (const auto& col : collisions) {
731734
auto bc = col.template bc_as<soa::Join<aod::BCs, aod::Run2BCInfos, aod::Timestamps, aod::Run2MatchedToBCSparse>>();
732-
EventSelectionParams* par = ccdb->template getForTimeStamp<EventSelectionParams>("EventSelection/EventSelectionParams", bc.timestamp());
735+
uint64_t timestamp = timestamps[bc.globalIndex()];
736+
EventSelectionParams* par = ccdb->template getForTimeStamp<EventSelectionParams>("EventSelection/EventSelectionParams", timestamp);
733737
bool* applySelection = par->getSelection(evselOpts.muonSelection);
734738
if (evselOpts.isMC == 1) {
735739
applySelection[aod::evsel::kIsBBZAC] = 0;
@@ -802,13 +806,13 @@ class EventSelectionModule
802806
} // end processRun2
803807

804808
//__________________________________________________
805-
template <typename TCCDB, typename THistoRegistry, typename TBCs, typename TCollisions, typename TPVTracks, typename TFT0s, typename TSlicecache, typename TBcSelBuffer, typename TEvselCursor>
806-
void processRun3(TCCDB const& ccdb, THistoRegistry& histos, TBCs const& bcs, TCollisions const& cols, TPVTracks const& pvTracks, TFT0s const& ft0s, TSlicecache& cache, TBcSelBuffer const& bcselbuffer, TEvselCursor& evsel)
809+
template <typename TCCDB, typename THistoRegistry, typename TBCs, typename TCollisions, typename TPVTracks, typename TFT0s, typename TSlicecache, typename TTimestamps, typename TBcSelBuffer, typename TEvselCursor>
810+
void processRun3(TCCDB const& ccdb, THistoRegistry& histos, TBCs const& bcs, TCollisions const& cols, TPVTracks const& pvTracks, TFT0s const& ft0s, TSlicecache& cache, TTimestamps const& timestamps, TBcSelBuffer const& bcselbuffer, TEvselCursor& evsel)
807811
{
808812
if (evselOpts.amIneeded.value == 0) {
809813
return; // dummy process
810814
}
811-
if (!configure(ccdb, bcs))
815+
if (!configure(ccdb, timestamps, bcs))
812816
return; // don't do anything in case configuration reported not ok
813817

814818
int run = bcs.iteratorAt(0).runNumber();
@@ -1372,8 +1376,8 @@ class LumiModule
13721376
}
13731377
}
13741378

1375-
template <typename TCCDB, typename TBCs>
1376-
bool configure(TCCDB& ccdb, TBCs const& bcs)
1379+
template <typename TCCDB, typename TTimestamps, typename TBCs>
1380+
bool configure(TCCDB& ccdb, TTimestamps const& timestamps, TBCs const& bcs)
13771381
{
13781382
if (bcs.size() == 0)
13791383
return false;
@@ -1382,7 +1386,7 @@ class LumiModule
13821386
return false;
13831387
if (run != lastRun && run >= 520259) { // o2-linter: disable=magic-number (scalers available for runs above 520120)
13841388
lastRun = run;
1385-
int64_t ts = bcs.iteratorAt(0).timestamp();
1389+
int64_t ts = timestamps[0];
13861390

13871391
// getting GRP LHCIF object to extract colliding system, energy and colliding bc pattern
13881392
auto grplhcif = ccdb->template getForTimeStamp<parameters::GRPLHCIFData>("GLO/Config/GRPLHCIF", ts);
@@ -1511,14 +1515,14 @@ class LumiModule
15111515
}
15121516

15131517
//__________________________________________________
1514-
template <typename TCCDB, typename THistoRegistry, typename TBCs, typename TBcSelBuffer>
1515-
void process(TCCDB& ccdb, THistoRegistry& histos, TBCs const& bcs, TBcSelBuffer const& bcselBuffer)
1518+
template <typename TCCDB, typename THistoRegistry, typename TBCs, typename TTimestamps, typename TBcSelBuffer>
1519+
void process(TCCDB& ccdb, THistoRegistry& histos, TBCs const& bcs, TTimestamps const& timestamps, TBcSelBuffer const& bcselBuffer)
15161520
{
15171521
if (lumiOpts.amIneeded.value == 0) {
15181522
return;
15191523
}
15201524

1521-
if (!configure(ccdb, bcs))
1525+
if (!configure(ccdb, timestamps, bcs))
15221526
return; // don't do anything in case configuration reported not ok
15231527

15241528
int run = bcs.iteratorAt(0).runNumber();

0 commit comments

Comments
 (0)