Fixes for memory leaks (Chiara)
[u/mrichter/AliRoot.git] / T0 / AddTaskT0Calib.C
CommitLineData
dd162229 1
dd162229 2
4f0fdf74 3void readCDB (TObject *task1);
dd162229 4//_____________________________________________________________________________
5AliAnalysisTask *AddTaskT0Calib(Int_t runNumber)
6{
7 //
8 // add calibration task
9 //
10 AliAnalysisManager *mgr = AliAnalysisManager::GetAnalysisManager();
11 if (!mgr) {
12 ::Error("AddTaskT0Calib", "No analysis manager to connect to.");
13 return NULL;
14 }
15
16 // check the input handler
17 if (!mgr->GetInputEventHandler()) {
18 ::Error("AddTaskT0Calib", "This task requires an input event handler");
19 return NULL;
20 }
21
22 // set TPC OCDB parameters
23 //ConfigOCDB(runNumber);
24
25 // setup task
4f0fdf74 26 AliT0CalibOffsetChannelsTask *task1 = new AliT0CalibOffsetChannelsTask("CalibObjectsTrain1");
27 readCDB(task1, runNumber);
dd162229 28 mgr->AddTask(task1);
4f0fdf74 29
30 // AliT0AnalysisTaskQA * task2 = new AliT0AnalysisTaskQA("QA task");
31 // mgr->AddTask(task2);
dd162229 32
33 AliAnalysisDataContainer *cinput1 = mgr->GetCommonInputContainer();
34 if (!cinput1) cinput1 = mgr->CreateContainer("cchain",TChain::Class(),
35 AliAnalysisManager::kInputContainer);
36 AliAnalysisDataContainer *coutput1 = mgr->CreateContainer("T0Calib",TObjArray::Class(), AliAnalysisManager::kOutputContainer, "AliESDfriends_v1.root");
37
38 mgr->ConnectInput(task1,0,cinput1);
39 mgr->ConnectOutput(task1,1,coutput1);
40 return task1;
41}
4f0fdf74 42//_____________________________________________________________________________
43void readCDB (TObject *task1, Int_t runNumber) {
44
45 Float_t zero_timecdb[24]={0};
46 Float_t *timecdb = zero_timecdb;
47 Float_t cfdvalue[24][5];
ae923cb3 48 for(Int_t i=0; i<24; i++)
49 for (Int_t i0=0; i0<5; i0++)
50 cfdvalue[i][i0] = 0;
51
4f0fdf74 52 Float_t zero_shiftcdb[4]={0};
53 Float_t *shiftcdb = zero_shiftcdb;
54 AliT0CalibOffsetChannelsTask *mytask = (AliT0CalibOffsetChannelsTask*)task1;
55
56 AliCDBManager* man = AliCDBManager::Instance();
4f0fdf74 57 AliCDBEntry *entry = AliCDBManager::Instance()->Get("GRP/CTP/CTPtiming");
58 if (!entry) AliFatal("CTP timing parameters are not found in OCDB !");
59 AliCTPTimeParams *ctpParams = (AliCTPTimeParams*)entry->GetObject();
60 Float_t l1Delay = (Float_t)ctpParams->GetDelayL1L0()*25.0;
61
62 AliCDBEntry *entry1 = AliCDBManager::Instance()->Get("GRP/CTP/TimeAlign");
63 if (!entry1) AliFatal("CTP time-alignment is not found in OCDB !");
64 AliCTPTimeParams *ctpTimeAlign = (AliCTPTimeParams*)entry1->GetObject();
65 l1Delay += ((Float_t)ctpTimeAlign->GetDelayL1L0()*25.0);
66
67 AliCDBEntry *entry4 = AliCDBManager::Instance()->Get("GRP/Calib/LHCClockPhase");
68 if (!entry4) AliFatal("LHC clock-phase shift is not found in OCDB !");
69 AliLHCClockPhase *phase = (AliLHCClockPhase*)entry4->GetObject();
ae923cb3 70 Float_t fGRPdelays = l1Delay - phase->GetMeanPhase();
4f0fdf74 71
72 AliCDBEntry *entryCalib0 = man->Get("T0/Calib/Latency");
9743eabf 73 if(!entryCalib0) {
74 AliError::(Form("Cannot find any AliCDBEntry for [Calib, Latency]!"));
75 return;
76 }
77 AliT0CalibLatency *calibda=(AliT0CalibLatency*)entryCalib0->GetObject();
78 Float_t fLatencyL1 = calibda->GetLatencyL1();
79 Float_t fLatencyHPTDC = calibda->GetLatencyHPTDC();
4f0fdf74 80
81 AliCDBEntry *entryCalib1 = man->Get("T0/Calib/TimeDelay");
82 if(!entryCalib1) {
83 AliError::(Form("Cannot find any AliCDBEntry for [Calib, TimeDelay]!"));
84 return;
85 }
86 else
87 {
88 AliT0CalibTimeEq *clb = (AliT0CalibTimeEq*)entryCalib1->GetObject();
89 timecdb = clb->GetTimeEq();
90 for(Int_t i=0; i<24; i++)
91 for (Int_t i0=0; i0<5; i0++){
92 cfdvalue[i][i0] = clb->GetCFDvalue(i, i0);
4f0fdf74 93 }
94 }
95
96 for (Int_t i=0; i<24; i++) {
97 Float_t cfdmean = cfdvalue[i][0];
98 if( cfdvalue[i][0] < 500 || cfdvalue[i][0] > 50000) cfdmean = ( 1000.*fLatencyHPTDC - 1000.*fLatencyL1 + 1000.*fGRPdelays)/24.4;
ae923cb3 99 mytask->SetCFDvalue(i, cfdmean);
4f0fdf74 100 mytask->SetTimeEq(i, timecdb[i]);
101 }
102
103 AliCDBEntry *entryCalib2 = man->Get("T0/Calib/TimeAdjust");
104 if(!entryCalib2) {
105 AliError(Form("Cannot find any AliCDBEntry for [Calib, TimeAdjust]!"));
106 }
107 else
108 {
109 AliT0CalibSeasonTimeShift *clb1 = (AliT0CalibSeasonTimeShift*)entryCalib2->GetObject();
110 shiftcdb = clb1->GetT0Means();
111 }
112
113 for (Int_t i=0; i<4; i++) mytask->SetT0Means(i,shiftcdb[i]);
114}