forked from AliceO2Group/AliceO2
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrun_calib_tof.C
More file actions
138 lines (118 loc) · 4.11 KB
/
Copy pathrun_calib_tof.C
File metadata and controls
138 lines (118 loc) · 4.11 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
#if !defined(__CLING__) || defined(__ROOTCLING__)
#include <TFile.h>
#include <TChain.h>
#include <TTree.h>
#include <TGeoGlobalMagField.h>
#include <TParameter.h>
#include <string>
#include <FairLogger.h>
#include <TStopwatch.h>
#include "Field/MagneticField.h"
#include "DataFormatsParameters/GRPObject.h"
#include "DetectorsBase/GeometryManager.h"
#include "DetectorsBase/Propagator.h"
#include "GlobalTracking/CalibTOF.h"
#endif
#include <string>
#include <iostream>
#include <sys/types.h>
#include <sys/wait.h>
#include <unistd.h>
#include "err.h"
void run_calib_tof(std::string path = "./", std::string outputfile = "o2calparams_tof.root",
std::string inputfileCalib = "o2calibration_tof.root")
{
bool onlymerge = false; // set to true if you have already the outputs from forked processes and you want only merge
TString namefile(outputfile);
namefile.ReplaceAll(".root", "");
const int ninstance = 4;
o2::globaltracking::CalibTOF calib;
calib.setDebugMode(1);
if (path.back() != '/') {
path += '/';
}
//>>>---------- attach input data --------------->>>
TChain tofCalibInfo("calibrationTOF");
tofCalibInfo.AddFile((path + inputfileCalib).data());
TFile* fin = TFile::Open((path + inputfileCalib).data());
TParameter<int>* minTimestamp = (TParameter<int>*)fin->Get("minTimestamp");
TParameter<int>* maxTimestamp = (TParameter<int>*)fin->Get("maxTimestamp");
calib.setInputTreeTOFCollectedCalibInfo(&tofCalibInfo);
calib.setMinTimestamp(minTimestamp->GetVal());
calib.setMaxTimestamp(maxTimestamp->GetVal());
fin->Close();
//<<<---------- attach input data ---------------<<<
//-------------------- settings -----------//
//calib.run(o2::globaltracking::CalibTOF::kLHCphase);
//calib.run(o2::globaltracking::CalibTOF::kChannelOffset);
//calib.run(o2::globaltracking::CalibTOF::kChannelTimeSlewing); // all sectors
// to be generalized for more than 2 forks
int counter = 0;
pid_t pids[ninstance];
int n = ninstance;
/* Start children. */
TStopwatch timerTot;
timerTot.Start();
if (!onlymerge) {
for (int i = 0; i < n; ++i) {
if ((pids[i] = fork()) < 0) {
perror("fork");
abort();
} else if (pids[i] == 0) {
cout << "child " << i << endl;
TFile outFile((path + namefile.Data() + Form("_fork%i.root", i)).data(), "recreate");
TTree outTree("calibrationTOF", "Calibration TOF params");
calib.setOutputTree(&outTree);
calib.init();
cout << i << ") Child process: My process id = " << getpid() << endl;
cout << "Child process: Value returned by fork() = " << pids[i] << endl;
// only for the first child
if (i == 0)
calib.run(o2::globaltracking::CalibTOF::kLHCphase);
for (int sect = i; sect < 18; sect += ninstance)
//calib.run(o2::globaltracking::CalibTOF::kChannelTimeSlewing, sect);
calib.run(o2::globaltracking::CalibTOF::kChannelOffset, sect);
calib.fillOutput();
outFile.cd();
outTree.Write();
if (i == 0)
calib.getLHCphaseHisto()->Write();
calib.getChTimeSlewingHistoAll()->Write();
outFile.Close();
exit(0);
}
}
int status;
pid_t pid;
while (n > 0) {
pid = wait(&status);
printf("Child with PID %ld exited with status 0x%x.\n", (long)pid, status);
--n; // TODO(pts): Remove pid from the pids array.
}
}
timerTot.Stop();
Printf("Time to run the calibration was:");
timerTot.Print();
printf("merge outputs\n");
TFile outFile((path + outputfile).data(), "recreate");
TTree outTree("calibrationTOF", "Calibration TOF params");
calib.setOutputTree(&outTree);
calib.init();
timerTot.Start(1);
for (int i = 0; i < ninstance; ++i) {
calib.merge((path + namefile.Data() + Form("_fork%i.root", i)).data());
}
timerTot.Stop();
Printf("Time to run the merging was:");
timerTot.Print();
// flag problematics
timerTot.Start(1);
calib.flagProblematics();
timerTot.Stop();
Printf("Time to run for problematics:");
timerTot.Print();
outFile.cd();
calib.fillOutput();
outTree.Write();
outFile.Close();
}