Skip to content

Commit 80a1cdb

Browse files
chiarazampollisawenzel
authored andcommitted
Writing TOF calibration to CCDB
1 parent c7d403f commit 80a1cdb

File tree

3 files changed

+42
-14
lines changed

3 files changed

+42
-14
lines changed

Detectors/GlobalTracking/include/GlobalTracking/CalibTOF.h

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ class CalibTOF
6060

6161
///< calibrate using the provided input
6262
void run(int flag, int sector = -1);
63-
void fillOutput();
63+
void fillOutput(int flag);
6464

6565
///< perform all initializations
6666
void init();
@@ -102,6 +102,12 @@ class CalibTOF
102102
float getNsigmaFractionProblematicCut() const { return mNsigmaFractionProblematicCut; }
103103
float getNsigmaSigmaProblematicCut() const { return mNsigmaSigmaProblematicCut; }
104104

105+
void setFillCCDB(bool flag) { mFillCCDB = flag; }
106+
bool getFillCCDB() const { return mFillCCDB; }
107+
108+
void setCCDBpath(std::string path) { mCCDBpath = path; }
109+
std::string getCCDBpath() const { return mCCDBpath; }
110+
105111
private:
106112
Int_t mDebugMode = 0; ///< >0= time slewing extra plot, >1= problematic fits stored
107113

@@ -129,7 +135,9 @@ class CalibTOF
129135
// Data members
130136

131137
bool mInitDone = false; ///< flag init already done
132-
138+
bool mFillCCDB = false; ///< flag init already doneto decide whether to fill or not the CCDB
139+
std::string mCCDBpath = "http://ccdb-test.cern.ch:8080"; ///< path to CCDB
140+
133141
///========== Parameters to be set externally, e.g. from CCDB ====================
134142

135143
// to be done later

Detectors/GlobalTracking/src/CalibTOF.cxx

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
#include <TFile.h>
1717
#include "DataFormatsParameters/GRPObject.h"
1818
#include "ReconstructionDataFormats/PID.h"
19+
#include "CCDB/CcdbApi.h"
1920

2021
#include "GlobalTracking/CalibTOF.h"
2122

@@ -25,6 +26,7 @@
2526
#include "TRandom.h"
2627

2728
using namespace o2::globaltracking;
29+
using CcdbApi = o2::ccdb::CcdbApi;
2830

2931
ClassImp(CalibTOF);
3032

@@ -259,9 +261,23 @@ void CalibTOF::run(int flag, int sector)
259261
}
260262

261263
//______________________________________________
262-
void CalibTOF::fillOutput()
264+
void CalibTOF::fillOutput(int flag)
263265
{
264266
mOutputTree->Fill();
267+
268+
if (mFillCCDB) {
269+
CcdbApi api;
270+
api.init(mCCDBpath.c_str()); // or http://localhost:8080 for a local installation
271+
272+
if (flag & kLHCphase) {
273+
std::map<std::string, std::string> metadataLHCphase; // can be empty
274+
api.storeAsTFileAny(mLHCphaseObj, "TOF/LHCphase", metadataLHCphase, (ulong)mMinTimestamp*1000, (ulong)mMaxTimestamp*1000); // we use as validity the timestamps that we got from the input for the calibration; but we need to convert to ms for the CCDB (at least for now that we use an integer for the timestamp)
275+
}
276+
if (flag & kChannelOffset || flag & kChannelTimeSlewing) {
277+
std::map<std::string, std::string> metadataChannelCalib; // can be empty
278+
api.storeAsTFileAny(mTimeSlewingObj, "TOF/ChannelCalib", metadataChannelCalib, (ulong)mMinTimestamp*1000); // contains both offset and time slewing; we use as validity the START ONLY timestamp that we got from the input for the calibration; but we need to convert to ms for the CCDB (at least for now that we use an integer for the timestamp), END is default
279+
}
280+
}
265281
}
266282

267283
//______________________________________________

macro/run_calib_tof.C

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -34,14 +34,15 @@
3434
#include "err.h"
3535

3636
void run_calib_tof(std::string path = "./", std::string outputfile = "o2calparams_tof.root",
37-
std::string inputfileCalib = "o2calibration_tof.root")
37+
std::string inputfileCalib = "o2calibration_tof.root", int calibType = o2::globaltracking::CalibTOF::kLHCphase)
3838
{
3939
bool onlymerge = false; // set to true if you have already the outputs from forked processes and you want only merge
4040

4141
TString namefile(outputfile);
4242
namefile.ReplaceAll(".root", "");
4343

44-
const int ninstance = 4;
44+
int ninstance = 4;
45+
if (calibType == o2::globaltracking::CalibTOF::kLHCphase) ninstance = 1;
4546
o2::globaltracking::CalibTOF calib;
4647
calib.setDebugMode(1);
4748

@@ -71,7 +72,7 @@ void run_calib_tof(std::string path = "./", std::string outputfile = "o2calparam
7172
// to be generalized for more than 2 forks
7273
int counter = 0;
7374

74-
pid_t pids[ninstance];
75+
pid_t* pids = new pid_t[ninstance];
7576
int n = ninstance;
7677
/* Start children. */
7778
TStopwatch timerTot;
@@ -91,14 +92,15 @@ void run_calib_tof(std::string path = "./", std::string outputfile = "o2calparam
9192
cout << "Child process: Value returned by fork() = " << pids[i] << endl;
9293

9394
// only for the first child
94-
if (i == 0)
95+
if (i == 0 && calibType & o2::globaltracking::CalibTOF::kLHCphase)
9596
calib.run(o2::globaltracking::CalibTOF::kLHCphase);
96-
for (int sect = i; sect < 18; sect += ninstance)
97-
//calib.run(o2::globaltracking::CalibTOF::kChannelTimeSlewing, sect);
98-
calib.run(o2::globaltracking::CalibTOF::kChannelOffset, sect);
99-
calib.fillOutput();
100-
outFile.cd();
101-
outTree.Write();
97+
if (calibType > o2::globaltracking::CalibTOF::kLHCphase) { // we do more than only the LHCphase
98+
for (int sect = i; sect < 18; sect += ninstance)
99+
calib.run((~o2::globaltracking::CalibTOF::kLHCphase) & calibType, sect); // we switch off the LHCphase, if it was enabled in the calibType
100+
}
101+
calib.fillOutput();
102+
outFile.cd();
103+
outTree.Write();
102104
if (i == 0)
103105
calib.getLHCphaseHisto()->Write();
104106
calib.getChTimeSlewingHistoAll()->Write();
@@ -117,6 +119,8 @@ void run_calib_tof(std::string path = "./", std::string outputfile = "o2calparam
117119
}
118120
}
119121

122+
delete [] pids;
123+
120124
timerTot.Stop();
121125
Printf("Time to run the calibration was:");
122126
timerTot.Print();
@@ -142,7 +146,7 @@ void run_calib_tof(std::string path = "./", std::string outputfile = "o2calparam
142146
timerTot.Print();
143147

144148
outFile.cd();
145-
calib.fillOutput();
149+
calib.fillOutput(calibType);
146150
outTree.Write();
147151
outFile.Close();
148152
}

0 commit comments

Comments
 (0)