minor coverity defect: adding self-assignment protection
[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();
57 man->SetDefaultStorage("raw://");
58 man->SetRun(runNumber);
59 AliCDBEntry *entry = AliCDBManager::Instance()->Get("GRP/CTP/CTPtiming");
60 if (!entry) AliFatal("CTP timing parameters are not found in OCDB !");
61 AliCTPTimeParams *ctpParams = (AliCTPTimeParams*)entry->GetObject();
62 Float_t l1Delay = (Float_t)ctpParams->GetDelayL1L0()*25.0;
63
64 AliCDBEntry *entry1 = AliCDBManager::Instance()->Get("GRP/CTP/TimeAlign");
65 if (!entry1) AliFatal("CTP time-alignment is not found in OCDB !");
66 AliCTPTimeParams *ctpTimeAlign = (AliCTPTimeParams*)entry1->GetObject();
67 l1Delay += ((Float_t)ctpTimeAlign->GetDelayL1L0()*25.0);
68
69 AliCDBEntry *entry4 = AliCDBManager::Instance()->Get("GRP/Calib/LHCClockPhase");
70 if (!entry4) AliFatal("LHC clock-phase shift is not found in OCDB !");
71 AliLHCClockPhase *phase = (AliLHCClockPhase*)entry4->GetObject();
ae923cb3 72 Float_t fGRPdelays = l1Delay - phase->GetMeanPhase();
4f0fdf74 73
74 AliCDBEntry *entryCalib0 = man->Get("T0/Calib/Latency");
9743eabf 75 if(!entryCalib0) {
76 AliError::(Form("Cannot find any AliCDBEntry for [Calib, Latency]!"));
77 return;
78 }
79 AliT0CalibLatency *calibda=(AliT0CalibLatency*)entryCalib0->GetObject();
80 Float_t fLatencyL1 = calibda->GetLatencyL1();
81 Float_t fLatencyHPTDC = calibda->GetLatencyHPTDC();
4f0fdf74 82
83 AliCDBEntry *entryCalib1 = man->Get("T0/Calib/TimeDelay");
84 if(!entryCalib1) {
85 AliError::(Form("Cannot find any AliCDBEntry for [Calib, TimeDelay]!"));
86 return;
87 }
88 else
89 {
90 AliT0CalibTimeEq *clb = (AliT0CalibTimeEq*)entryCalib1->GetObject();
91 timecdb = clb->GetTimeEq();
92 for(Int_t i=0; i<24; i++)
93 for (Int_t i0=0; i0<5; i0++){
94 cfdvalue[i][i0] = clb->GetCFDvalue(i, i0);
4f0fdf74 95 }
96 }
97
98 for (Int_t i=0; i<24; i++) {
99 Float_t cfdmean = cfdvalue[i][0];
100 if( cfdvalue[i][0] < 500 || cfdvalue[i][0] > 50000) cfdmean = ( 1000.*fLatencyHPTDC - 1000.*fLatencyL1 + 1000.*fGRPdelays)/24.4;
ae923cb3 101 mytask->SetCFDvalue(i, cfdmean);
4f0fdf74 102 mytask->SetTimeEq(i, timecdb[i]);
103 }
104
105 AliCDBEntry *entryCalib2 = man->Get("T0/Calib/TimeAdjust");
106 if(!entryCalib2) {
107 AliError(Form("Cannot find any AliCDBEntry for [Calib, TimeAdjust]!"));
108 }
109 else
110 {
111 AliT0CalibSeasonTimeShift *clb1 = (AliT0CalibSeasonTimeShift*)entryCalib2->GetObject();
112 shiftcdb = clb1->GetT0Means();
113 }
114
115 for (Int_t i=0; i<4; i++) mytask->SetT0Means(i,shiftcdb[i]);
116}