Skip to content

Commit c2d8b5e

Browse files
Add RCT info in straevselsconverter5
1 parent ff2a5fc commit c2d8b5e

File tree

1 file changed

+59
-2
lines changed

1 file changed

+59
-2
lines changed

PWGLF/TableProducer/Strangeness/Converters/straevselsconverter5.cxx

Lines changed: 59 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,17 +11,74 @@
1111
#include "Framework/runDataProcessing.h"
1212
#include "Framework/AnalysisTask.h"
1313
#include "Framework/AnalysisDataModel.h"
14+
#include "CCDB/BasicCCDBManager.h"
15+
#include "DataFormatsParameters/AggregatedRunInfo.h"
1416
#include "ITStracking/Vertexer.h"
1517
#include "PWGLF/DataModel/LFStrangenessTables.h"
1618

1719
using namespace o2;
1820
using namespace o2::framework;
21+
using namespace o2::aod::evsel;
22+
23+
static const int32_t nBCsPerOrbit = o2::constants::lhc::LHCMaxBunches;
1924

2025
// Converts Stra Event selections from 004 to 005
2126
struct straevselsconverter5 {
2227
Produces<aod::StraEvSels_005> straEvSels_005;
2328

24-
void process(aod::StraEvSels_004 const& straEvSels_004)
29+
Service<o2::ccdb::BasicCCDBManager> ccdb;
30+
31+
int lastRun = -1;
32+
int64_t lastTF = -1;
33+
uint32_t lastRCT = 0;
34+
uint64_t sorTimestamp = 0; // default SOR timestamp
35+
uint64_t eorTimestamp = 1; // default EOR timestamp
36+
int64_t bcSOR = -1; // global bc of the start of run
37+
int64_t nBCsPerTF = -1; // duration of TF in bcs, should be 128*3564 or 3
38+
std::map<uint64_t, uint32_t>* mapRCT = nullptr;
39+
40+
uint32_t getRctRaw(int run, uint64_t timestamp, uint64_t globalBC) {
41+
if (run != lastRun) {
42+
lastRun = run;
43+
auto runInfo = o2::parameters::AggregatedRunInfo::buildAggregatedRunInfo(o2::ccdb::BasicCCDBManager::instance(), run);
44+
// first bc of the first orbit
45+
bcSOR = runInfo.orbitSOR * nBCsPerOrbit;
46+
// duration of TF in bcs
47+
nBCsPerTF = runInfo.orbitsPerTF * nBCsPerOrbit;
48+
// SOR and EOR timestamps
49+
sorTimestamp = runInfo.sor;
50+
eorTimestamp = runInfo.eor;
51+
// timestamp of the middle of the run used to access run-wise CCDB entries
52+
int64_t ts = runInfo.sor / 2 + runInfo.eor / 2;
53+
// QC info
54+
std::map<std::string, std::string> metadata;
55+
metadata["run"] = Form("%d", run);
56+
ccdb->setFatalWhenNull(0);
57+
mapRCT = ccdb->getSpecific<std::map<uint64_t, uint32_t>>("Users/j/jian/RCT", ts, metadata);
58+
ccdb->setFatalWhenNull(1);
59+
if (mapRCT == nullptr) {
60+
LOGP(info, "rct object missing... inserting dummy rct flags");
61+
mapRCT = new std::map<uint64_t, uint32_t>;
62+
mapRCT->insert(std::pair<uint64_t, uint32_t>(sorTimestamp, 0));
63+
}
64+
}
65+
66+
// store rct flags
67+
uint32_t rct = lastRCT;
68+
int64_t thisTF = (globalBC - bcSOR) / nBCsPerTF;
69+
if (mapRCT != nullptr && thisTF != lastTF) { // skip for unanchored runs; do it once per TF
70+
auto itrct = mapRCT->upper_bound(timestamp);
71+
if (itrct != mapRCT->begin())
72+
itrct--;
73+
rct = itrct->second;
74+
LOGP(debug, "sor={} eor={} ts={} rct={}", sorTimestamp, eorTimestamp, timestamp, rct);
75+
lastRCT = rct;
76+
lastTF = thisTF;
77+
}
78+
return rct;
79+
}
80+
81+
void process(soa::Join<aod::StraEvSels_004, aod::StraStamps> const& straEvSels_004)
2582
{
2683
for (auto& values : straEvSels_004) {
2784
straEvSels_005(values.sel8(),
@@ -55,7 +112,7 @@ struct straevselsconverter5 {
55112
values.energyCommonZNC(),
56113
values.flags(),
57114
0 /*dummy Alias value*/,
58-
0 /*dummy Rct value*/);
115+
getRctRaw(values.runNumber(), values.timestamp(), values.globalBC()) /* Rct value*/);
59116
}
60117
}
61118
};

0 commit comments

Comments
 (0)