Skip to content

Commit 22b0532

Browse files
updated macro for TPC vdrift + typo
1 parent 9853977 commit 22b0532

File tree

2 files changed

+49
-88
lines changed

2 files changed

+49
-88
lines changed
Lines changed: 47 additions & 86 deletions
Original file line numberDiff line numberDiff line change
@@ -1,97 +1,58 @@
1-
#include <map>
2-
#include "TPCBase/ParameterGas.h"
1+
#include <cmath>
2+
#include <fmt/format.h>
3+
#include <string_view>
4+
5+
#include "TSystem.h"
6+
37
#include "CCDB/CcdbApi.h"
48
#include "DataFormatsTPC/LtrCalibData.h"
9+
#include "TPCBase/ParameterGas.h"
510

6-
float getTPCvdrift(int run, bool useCCDB) {
7-
11+
float getTPCvdrift(int run, std::string_view ltrUrl = "http://ccdb-test.cern.ch:8080")
12+
{
813
o2::ccdb::CcdbApi c;
914
c.init("http://alice-ccdb.cern.ch");
10-
long sor = 0;
11-
12-
std::map<int, uint64_t> laserTimeStamp;
13-
laserTimeStamp[517035] = 1653640509000;
14-
laserTimeStamp[517037] = 1653641691000;
15-
laserTimeStamp[517039] = 1653643160000;
16-
laserTimeStamp[517040] = 1653644143000;
17-
laserTimeStamp[517041] = 1653646640000;
18-
laserTimeStamp[517043] = 1653649528000;
19-
laserTimeStamp[517044] = 1653650947000;
20-
laserTimeStamp[517120] = 1653726400000;
21-
laserTimeStamp[517124] = 1653728126000;
22-
laserTimeStamp[517132] = 1653730328000;
23-
laserTimeStamp[517136] = 1653732051000;
24-
laserTimeStamp[517141] = 1653735268000;
25-
laserTimeStamp[517144] = 1653738882000;
26-
laserTimeStamp[517205] = 1653808408000;
27-
laserTimeStamp[517214] = 1653811673000;
28-
laserTimeStamp[517216] = 1653812811000;
29-
laserTimeStamp[517218] = 1653815109000;
30-
laserTimeStamp[517219] = 1653815730000;
31-
laserTimeStamp[517220] = 1653816476000;
32-
laserTimeStamp[517222] = 1653817433000;
33-
laserTimeStamp[517224] = 1653822183000;
34-
laserTimeStamp[517616] = 1654242788000;
35-
laserTimeStamp[517618] = 1654244395000;
36-
laserTimeStamp[517619] = 1654245241000;
37-
laserTimeStamp[517620] = 1654246805000;
38-
laserTimeStamp[517622] = 1654252675000;
39-
laserTimeStamp[517623] = 1654253383000;
40-
//laserTimeStamp[517676] = ; // bad run anyway
41-
laserTimeStamp[517677] = 1654305282000;
42-
laserTimeStamp[517678] = 1654307618000;
43-
laserTimeStamp[517679] = 1654310481000;
44-
laserTimeStamp[517684] = 1654314428000;
45-
laserTimeStamp[517685] = 1654315256000;
46-
laserTimeStamp[517689] = 1654324732000;
47-
laserTimeStamp[517690] = 1654325594000;
48-
laserTimeStamp[517692] = 1654332609000;
49-
laserTimeStamp[517693] = 1654333304000;
50-
laserTimeStamp[517735] = 1654409869000;
51-
laserTimeStamp[517736] = 1654410373000;
52-
laserTimeStamp[517737] = 1654410885000;
53-
laserTimeStamp[517748] = 1654415651000;
54-
laserTimeStamp[517750] = 1654420434000;
55-
laserTimeStamp[517751] = 1654421682000;
56-
laserTimeStamp[517753] = 1654426894000;
57-
laserTimeStamp[517758] = 1654432984000;
58-
laserTimeStamp[517767] = 1654441645000;
59-
laserTimeStamp[518541] = 1655115072000;
60-
laserTimeStamp[518542] = 1655116790000;
61-
laserTimeStamp[518543] = 1655117484000;
62-
laserTimeStamp[518546] = 1655119611000;
63-
laserTimeStamp[518547] = 1655122585000;
64-
65-
std::map<std::string, std::string> headers, metadataRCT, metadata;
66-
if (useCCDB) {
67-
headers = c.retrieveHeaders(Form("RCT/Info/RunInformation/%i", run), metadataRCT, -1);
68-
printf("\nLooking for vdrift for run %d\n", run);
69-
sor = stol(headers["SOR"].c_str());
70-
}
71-
else {
72-
const auto& sorEl = laserTimeStamp.find(run);
73-
if (sorEl == laserTimeStamp.end()) {
74-
std::cout << "Run not found in map to determine laser timestamp!" << "\n";
75-
return -999999999; // should be crazy enough to result in issues in reco output
15+
std::map<std::string, std::string> headers, metadataRCT, metadata, mm;
16+
headers = c.retrieveHeaders(fmt::format("RCT/Info/RunInformation/{}", run), metadataRCT, -1);
17+
printf("\nLooking for vdrift for run %d\n", run);
18+
const auto sor = std::stol(headers["SOR"].data());
19+
20+
const auto defaultDriftV = o2::tpc::ParameterGas::Instance().DriftV;
21+
22+
std::string_view calibType = "TPC/Calib/LaserTracks";
23+
//
24+
// query present run up to +-3days
25+
const auto queryInterval = 3l * 24l * 60l * 60l * 1000l;
26+
const auto queryString = fmt::format("curl -H \"If-Not-Before: {}\" -H \"If-Not-After: {}\" -H \"Accept: application/json\" {}/browse/{}", sor - queryInterval, sor + queryInterval, ltrUrl.data(), calibType.data());
27+
fmt::print("Query: {}\n", queryString);
28+
const auto queryResultTString = gSystem->GetFromPipe(queryString.data());
29+
std::string queryResult(queryResultTString);
30+
31+
// find closest entry in time
32+
long minDist = 9999999999999;
33+
long minTime = sor;
34+
size_t pos = 0;
35+
const std::string_view searchString("validFrom");
36+
while ((pos = queryResult.find(searchString.data(), pos)) < queryResult.size()) {
37+
const auto startPosTime = queryResult.find(":", pos) + 1;
38+
const auto endPosTime = queryResult.find(",", pos);
39+
const auto startValidity = std::atol(queryResult.substr(startPosTime, endPosTime - startPosTime).data());
40+
fmt::print("add object {}\n", startValidity);
41+
if (std::abs(startValidity - sor) < minDist) {
42+
minTime = startValidity;
43+
minDist = std::abs(startValidity - sor);
7644
}
77-
sor = sorEl->second;
45+
pos = endPosTime;
7846
}
79-
80-
o2::ccdb::CcdbApi ctest;
81-
ctest.init("http://ccdb-test.cern.ch:8080");
82-
o2::tpc::LtrCalibData* ltrCalib = ctest.retrieveFromTFileAny<o2::tpc::LtrCalibData>("TPC/Calib/LaserTracks", metadata, sor); /// timestamp in the run of interest
83-
auto corr = ltrCalib->getDriftVCorrection();
84-
float vcorr = o2::tpc::ParameterGas::Instance().DriftV / corr;
47+
fmt::print("{} closest to {} is at {}\n", calibType, sor, minTime);
48+
49+
//
50+
// Get object closest to present run and return the drfit veloctiy calibration factor
51+
c.init(ltrUrl.data());
52+
const auto ltrCalib = c.retrieveFromTFileAny<o2::tpc::LtrCalibData>(calibType.data(), metadata, minTime); /// timestamp in the run of interest
53+
const auto corr = ltrCalib->getDriftVCorrection();
54+
const float vcorr = defaultDriftV / corr;
8555
printf("vdrift = %f\n", vcorr);
86-
const char* vcorrStr = std::to_string(vcorr).c_str();
8756

88-
ofstream vdriftFile;
89-
vdriftFile.open("vdrift.txt");
90-
vdriftFile << vcorr;
91-
vdriftFile.close();
92-
9357
return vcorr;
94-
9558
}
96-
97-

DATA/production/configurations/2022/MayJunePilotBeam/apass1/setenv_extra.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ if [[ $remappingITS == 1 ]] || [[ $remappingMFT == 1 ]]; then
3131
if [[ $remappingMFT == 1 ]]; then
3232
REMAPPING=$REMAPPING"MFT/Calib/ClusterDictionary"
3333
fi
34-
RAMAPPING=$REMAPPING\"
34+
REMAPPING=$REMAPPING\"
3535
fi
3636

3737
echo remapping = $REMAPPING
@@ -49,7 +49,7 @@ else
4949
fi
5050

5151
# TPC vdrift
52-
root -b -q "$O2DPG_ROOT/DATA/production/configurations/$ALIEN_JDL_LPMANCHORYEAR/$O2DPGPATH/$ALIEN_JDL_LPMPASSNAME/getTPCvdrift.C+($RUNNUMBER, false)"
52+
root -b -q "$O2DPG_ROOT/DATA/production/configurations/$ALIEN_JDL_LPMANCHORYEAR/$O2DPGPATH/$ALIEN_JDL_LPMPASSNAME/getTPCvdrift.C+($RUNNUMBER)"
5353
export VDRIFT=`cat vdrift.txt`
5454

5555
# remove monitoring-backend

0 commit comments

Comments
 (0)