Skip to content

Commit 3cc5dd6

Browse files
authored
Support upload of the chunked Zorro objects (AliceO2Group#8001)
1 parent 4eb8aa5 commit 3cc5dd6

File tree

1 file changed

+51
-6
lines changed

1 file changed

+51
-6
lines changed

EventFiltering/macros/uploadOTSobjects.C

Lines changed: 51 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
#include <string>
1717
#include <map>
1818
#include <array>
19+
#include <cmath>
1920

2021
#include "TFile.h"
2122
#include "TGrid.h"
@@ -26,16 +27,23 @@
2627

2728
#include "CCDB/BasicCCDBManager.h"
2829
#include "EventFiltering/ZorroHelper.h"
30+
#include "CommonConstants/LHCConstants.h"
2931

30-
void uploadOTSobjects(std::string inputList, std::string passName, bool useAlien)
32+
constexpr uint32_t chunkSize = 1000000;
33+
34+
void uploadOTSobjects(std::string inputList, std::string passName, bool useAlien, bool chunkedProcessing)
3135
{
3236
const std::string kBaseCCDBPath = "Users/m/mpuccio/EventFiltering/OTS/";
3337
std::string baseCCDBpath = passName.empty() ? kBaseCCDBPath : kBaseCCDBPath + passName + "/";
38+
if (chunkedProcessing) {
39+
baseCCDBpath += "Chunked/";
40+
}
3441
if (useAlien) {
3542
TGrid::Connect("alien://");
3643
}
3744
o2::ccdb::CcdbApi api;
3845
api.init("http://alice-ccdb.cern.ch");
46+
auto& ccdb = o2::ccdb::BasicCCDBManager::instance();
3947

4048
std::ifstream file(inputList.data());
4149
std::string path;
@@ -47,9 +55,11 @@ void uploadOTSobjects(std::string inputList, std::string passName, bool useAlien
4755
const int runNumber = std::stoi(runString);
4856
metadata["runNumber"] = runString;
4957
std::pair<int64_t, int64_t> duration = o2::ccdb::BasicCCDBManager::getRunDuration(api, runNumber);
50-
duration.first -= 10000; // subtract 3 minutes from the run start
51-
duration.second += 180000; // add 3 minutes to the run duration
58+
duration.first -= 60000; // subtract 1 minutes from the run start
59+
duration.second += 60000; // add 1 minutes to the run duration
5260
std::cout << ">>> Begin - end timestamps for the upload: " << duration.first << " - " << duration.second << std::endl;
61+
auto ctp = ccdb.getForTimeStamp<std::vector<Long64_t>>("CTP/Calib/OrbitReset", duration.first / 2 + duration.second / 2);
62+
auto orbitResetTimestamp = (*ctp)[0];
5363
path = useAlien ? "alien://" + path : path;
5464
std::unique_ptr<TFile> scalersFile{TFile::Open((path + "/AnalysisResults_fullrun.root").data(), "READ")};
5565
TH1* scalers = static_cast<TH1*>(scalersFile->Get("central-event-filter-task/scalers/mScalers"));
@@ -85,13 +95,48 @@ void uploadOTSobjects(std::string inputList, std::string passName, bool useAlien
8595
}
8696
}
8797
}
88-
api.storeAsTFileAny(&zorroHelpers, baseCCDBpath + "ZorroHelpers", metadata, duration.first, duration.second);
98+
std::sort(zorroHelpers.begin(), zorroHelpers.end(), [](const ZorroHelper& a, const ZorroHelper& b) {
99+
return a.bcAOD < b.bcAOD;
100+
});
101+
if (!chunkedProcessing) {
102+
api.storeAsTFileAny(&zorroHelpers, baseCCDBpath + "ZorroHelpers", metadata, duration.first, duration.second);
103+
std::cout << std::endl;
104+
} else {
105+
uint32_t helperIndex{0};
106+
auto startTS = duration.first;
107+
int64_t endTS = 0;
108+
while (helperIndex < zorroHelpers.size()) {
109+
std::vector<ZorroHelper> chunk;
110+
uint32_t endIndex = helperIndex + chunkSize;
111+
while (true) {
112+
if (endIndex >= zorroHelpers.size() - 2) {
113+
endTS = duration.second;
114+
chunk.insert(chunk.begin(), zorroHelpers.begin() + helperIndex, zorroHelpers.end());
115+
break;
116+
}
117+
auto bcEnd{zorroHelpers[endIndex].bcAOD > zorroHelpers[endIndex].bcEvSel ? zorroHelpers[endIndex].bcAOD : zorroHelpers[endIndex].bcEvSel};
118+
const auto& nextHelper = zorroHelpers[endIndex + 1];
119+
auto bcNext{nextHelper.bcAOD < nextHelper.bcEvSel ? nextHelper.bcAOD : nextHelper.bcEvSel};
120+
if (bcNext - bcEnd > 2001 / o2::constants::lhc::LHCBunchSpacingMUS) { /// ensure a gap of 2ms between chunks
121+
chunk.insert(chunk.begin(), zorroHelpers.begin() + helperIndex, zorroHelpers.begin() + endIndex + 1);
122+
endTS = (orbitResetTimestamp + int64_t(bcEnd * o2::constants::lhc::LHCBunchSpacingNS * 1e-3)) / 1000 + 1;
123+
break;
124+
}
125+
bcEnd = nextHelper.bcAOD > nextHelper.bcEvSel ? nextHelper.bcAOD : nextHelper.bcEvSel;
126+
endIndex++;
127+
}
128+
std::cout << ">>> Chunk " << helperIndex << " - " << helperIndex + chunk.size() << " : " << startTS << " - " << endTS << " \t" << (endTS - startTS) * 1.e-3 << std::endl;
129+
api.storeAsTFileAny(&zorroHelpers, baseCCDBpath + "ZorroHelpers", metadata, startTS, endTS);
130+
startTS = endTS + 1;
131+
helperIndex += chunk.size();
132+
}
133+
}
89134
}
90135
}
91136

92-
void uploadOTSobjects(std::string periodName)
137+
void uploadOTSobjects(std::string periodName, bool chunkedProcessing)
93138
{
94139
int year = 2000 + std::stoi(periodName.substr(3, 2));
95140
gSystem->Exec(Form("alien_find /alice/data/%i/%s/ ctf_skim_full/AnalysisResults_fullrun.root | sed 's:/AnalysisResults_fullrun\\.root::' > list_%s.txt", year, periodName.data(), periodName.data()));
96-
uploadOTSobjects(Form("list_%s.txt", periodName.data()), "", true);
141+
uploadOTSobjects(Form("list_%s.txt", periodName.data()), "", true, chunkedProcessing);
97142
}

0 commit comments

Comments
 (0)