|
11 | 11 | #include "Framework/runDataProcessing.h" |
12 | 12 | #include "Framework/AnalysisTask.h" |
13 | 13 | #include "Framework/AnalysisDataModel.h" |
| 14 | +#include "CCDB/BasicCCDBManager.h" |
| 15 | +#include "DataFormatsParameters/AggregatedRunInfo.h" |
14 | 16 | #include "ITStracking/Vertexer.h" |
15 | 17 | #include "PWGLF/DataModel/LFStrangenessTables.h" |
16 | 18 |
|
17 | 19 | using namespace o2; |
18 | 20 | using namespace o2::framework; |
| 21 | +using namespace o2::aod::evsel; |
| 22 | + |
| 23 | +static const int32_t nBCsPerOrbit = o2::constants::lhc::LHCMaxBunches; |
19 | 24 |
|
20 | 25 | // Converts Stra Event selections from 004 to 005 |
21 | 26 | struct straevselsconverter5 { |
22 | 27 | Produces<aod::StraEvSels_005> straEvSels_005; |
23 | 28 |
|
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 | + { |
| 42 | + if (run != lastRun) { |
| 43 | + lastRun = run; |
| 44 | + auto runInfo = o2::parameters::AggregatedRunInfo::buildAggregatedRunInfo(o2::ccdb::BasicCCDBManager::instance(), run); |
| 45 | + // first bc of the first orbit |
| 46 | + bcSOR = runInfo.orbitSOR * nBCsPerOrbit; |
| 47 | + // duration of TF in bcs |
| 48 | + nBCsPerTF = runInfo.orbitsPerTF * nBCsPerOrbit; |
| 49 | + // SOR and EOR timestamps |
| 50 | + sorTimestamp = runInfo.sor; |
| 51 | + eorTimestamp = runInfo.eor; |
| 52 | + // timestamp of the middle of the run used to access run-wise CCDB entries |
| 53 | + int64_t ts = runInfo.sor / 2 + runInfo.eor / 2; |
| 54 | + // QC info |
| 55 | + std::map<std::string, std::string> metadata; |
| 56 | + metadata["run"] = Form("%d", run); |
| 57 | + ccdb->setFatalWhenNull(0); |
| 58 | + mapRCT = ccdb->getSpecific<std::map<uint64_t, uint32_t>>("Users/j/jian/RCT", ts, metadata); |
| 59 | + ccdb->setFatalWhenNull(1); |
| 60 | + if (mapRCT == nullptr) { |
| 61 | + LOGP(info, "rct object missing... inserting dummy rct flags"); |
| 62 | + mapRCT = new std::map<uint64_t, uint32_t>; |
| 63 | + mapRCT->insert(std::pair<uint64_t, uint32_t>(sorTimestamp, 0)); |
| 64 | + } |
| 65 | + } |
| 66 | + |
| 67 | + // store rct flags |
| 68 | + uint32_t rct = lastRCT; |
| 69 | + int64_t thisTF = (globalBC - bcSOR) / nBCsPerTF; |
| 70 | + if (mapRCT != nullptr && thisTF != lastTF) { // skip for unanchored runs; do it once per TF |
| 71 | + auto itrct = mapRCT->upper_bound(timestamp); |
| 72 | + if (itrct != mapRCT->begin()) |
| 73 | + itrct--; |
| 74 | + rct = itrct->second; |
| 75 | + LOGP(debug, "sor={} eor={} ts={} rct={}", sorTimestamp, eorTimestamp, timestamp, rct); |
| 76 | + lastRCT = rct; |
| 77 | + lastTF = thisTF; |
| 78 | + } |
| 79 | + return rct; |
| 80 | + } |
| 81 | + |
| 82 | + void process(soa::Join<aod::StraEvSels_004, aod::StraStamps> const& straEvSels_004) |
25 | 83 | { |
26 | 84 | for (auto& values : straEvSels_004) { |
27 | 85 | straEvSels_005(values.sel8(), |
@@ -55,7 +113,7 @@ struct straevselsconverter5 { |
55 | 113 | values.energyCommonZNC(), |
56 | 114 | values.flags(), |
57 | 115 | 0 /*dummy Alias value*/, |
58 | | - 0 /*dummy Rct value*/); |
| 116 | + getRctRaw(values.runNumber(), values.timestamp(), values.globalBC()) /* Rct value*/); |
59 | 117 | } |
60 | 118 | } |
61 | 119 | }; |
|
0 commit comments