TOF preprocessor modified in order to use cosmic-ray calibration parameters (from...
[u/mrichter/AliRoot.git] / TOF / AliTOFPreprocessor.cxx
1 /**************************************************************************
2  * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
3  *                                                                        *
4  * Author: The ALICE Off-line Project.                                    *
5  * Contributors are mentioned in the code where appropriate.              *
6  *                                                                        *
7  * Permission to use, copy, modify and distribute this software and its   *
8  * documentation strictly for non-commercial purposes is hereby granted   *
9  * without fee, provided that the above copyright notice appears in all   *
10  * copies and that both the copyright notice and this permission notice   *
11  * appear in the supporting documentation. The authors make no claims     *
12  * about the suitability of this software for any purpose. It is          *
13  * provided "as is" without express or implied warranty.                  *
14  **************************************************************************/
15
16 /* $Id$ */
17
18 //#include <Riostream.h>
19 //#include <stdio.h>
20 //#include <stdlib.h>
21
22 #include <TFile.h>
23 #include <TH2S.h>
24 #include <TMath.h>
25 #include <TObjArray.h>
26 #include <TObjString.h>
27 #include <TTimeStamp.h>
28
29 #include "AliCDBMetaData.h"
30 #include "AliCDBEntry.h"
31 #include "AliLog.h"
32 #include "AliTOFChannelOnlineArray.h"
33 #include "AliTOFChannelOnlineStatusArray.h"
34 #include "AliTOFDataDCS.h"
35 #include "AliTOFGeometry.h"
36 #include "AliTOFPreprocessor.h"
37 #include "AliTOFFEEReader.h"
38 #include "AliTOFRawStream.h"
39 #include "AliTOFCableLengthMap.h"
40 #include "AliTOFcalibHisto.h"
41
42
43 // TOF preprocessor class.
44 // It takes data from DCS and passes them to the class AliTOFDataDCS, which
45 // processes them. The result is then written to the CDB.
46 // Analogously, it takes data form DAQ (both at Run level and inclusive - 
47 // of all the runs - level, processes them, and stores both Reference Data
48 // and Online Calibration files in the CDB. 
49 // Processing of Pulser/Noise Run data and of TOF FEE DCS map included also.
50
51 // return codes:
52 // return=0 : all ok
53 // return=1 : no DCS input data Map
54 // return=2 : no DCS input data processing
55 // return=3 : no DCS processed data was stored in Ref Data
56 // return=4 : no DAQ input for Ref Data
57 // return=5 : failed to store DAQ Ref Data
58 // return=6 : failed to retrieve DAQ data for calibration 
59 // return=7 : problems in processing histos in the input DAQ file 
60 // return=8 : failed to store Online Delays
61 // return=9 : failed to store Reference Data for Pulser
62 // return=10: failed to retrieve Pulser data 
63 // return=11: failed to store Pulser map in OCDB
64 // return=12: failed to store Reference Data for Noise
65 // return=13: failed to retrieve Noise data 
66 // return=14: failed to store Noise map in OCDB
67 // return=15: failed to retrieve FEE data from FXS
68 // return=16: failed to retrieve FEE data from OCDB
69 // return=17: failed to store FEE data in OCDB
70 // return=18: failed to store FEE reference data in OCDB
71 // return=20: failed in retrieving status variable
72
73 ClassImp(AliTOFPreprocessor)
74
75 const Int_t    AliTOFPreprocessor::fgkBinRangeAve = 13;    // number of bins where to calculate the mean 
76 const Double_t AliTOFPreprocessor::fgkIntegralThr = 100;   // min number of entries to perform computation of delay per channel 
77 const Double_t AliTOFPreprocessor::fgkThrPar      = 0.013; // parameter used to trigger the calculation of the delay
78
79 //_____________________________________________________________________________
80
81 AliTOFPreprocessor::AliTOFPreprocessor(AliShuttleInterface* shuttle) :
82   AliPreprocessor("TOF", shuttle),
83   fData(0),
84   fCal(0),
85   fNChannels(0),
86   fStoreRefData(kTRUE),
87   fFDRFlag(kFALSE),
88   fStatus(0),
89   fMatchingWindow(0)
90 {
91   // constructor
92   AddRunType("PHYSICS");
93   AddRunType("PULSER");
94   AddRunType("NOISE");
95
96 }
97
98 //_____________________________________________________________________________
99
100 AliTOFPreprocessor::~AliTOFPreprocessor()
101 {
102   // destructor
103 }
104
105 //______________________________________________________________________________
106 void AliTOFPreprocessor::Initialize(Int_t run, UInt_t startTime,
107         UInt_t endTime)
108 {
109   // Creates AliTOFDataDCS object
110
111   AliPreprocessor::Initialize(run, startTime, endTime);
112
113         AliInfo(Form("\n\tRun %d \n\tStartTime %s \n\tEndTime %s \n\tStartTime DCS Query %s \n\tEndTime DCS Query %s", run,
114                 TTimeStamp(startTime).AsString(),
115                 TTimeStamp(endTime).AsString(), ((TTimeStamp)GetStartTimeDCSQuery()).AsString(), ((TTimeStamp)GetEndTimeDCSQuery()).AsString()));
116
117         fData = new AliTOFDataDCS(fRun, fStartTime, fEndTime, GetStartTimeDCSQuery(), GetEndTimeDCSQuery());
118         fNChannels = AliTOFGeometry::NSectors()*(2*(AliTOFGeometry::NStripC()+AliTOFGeometry::NStripB())+AliTOFGeometry::NStripA())*AliTOFGeometry::NpadZ()*AliTOFGeometry::NpadX();
119 }
120 //_____________________________________________________________________________
121 Bool_t AliTOFPreprocessor::ProcessDCS(){
122
123   // check whether DCS should be processed or not...
124
125   TString runType = GetRunType();
126   Log(Form("RunType %s",runType.Data()));
127
128   if (runType != "PHYSICS"){
129     return kFALSE;
130   }
131
132   return kTRUE;
133 }
134 //_____________________________________________________________________________
135
136 UInt_t AliTOFPreprocessor::ProcessDCSDataPoints(TMap* dcsAliasMap)
137 {
138   // Fills data into a AliTOFDataDCS object
139
140
141   Log("Processing DCS DP");
142   TH1::AddDirectory(0);
143
144   Bool_t resultDCSMap=kFALSE;
145   Bool_t resultDCSStore=kFALSE;
146
147   // processing DCS
148
149   fData->SetFDRFlag(fFDRFlag);
150   
151   if (!dcsAliasMap){
152     Log("No DCS map found: TOF exiting from Shuttle");
153     if (fData){
154             delete fData;
155             fData = 0;
156     }
157     return 1;// return error Code for DCS input data not found 
158   }
159   else {
160
161   // The processing of the DCS input data is forwarded to AliTOFDataDCS
162     resultDCSMap=fData->ProcessData(*dcsAliasMap);
163     if(!resultDCSMap){
164       Log("Some problems occurred while processing DCS data, TOF exiting from Shuttle");
165       if (fData){
166               delete fData;
167               fData = 0;
168       }
169       return 2;// return error Code for processed DCS data not stored 
170     }
171     else{
172       AliCDBMetaData metaDataDCS;
173       metaDataDCS.SetBeamPeriod(0);
174       metaDataDCS.SetResponsible("Chiara Zampolli");
175       metaDataDCS.SetComment("This preprocessor fills an AliTOFDataDCS object.");
176       AliInfo("Storing DCS Data");
177       resultDCSStore = StoreReferenceData("Calib","DCSData",fData, &metaDataDCS);
178       if (!resultDCSStore){
179         Log("Some problems occurred while storing DCS data results in Reference Data, TOF exiting from Shuttle");
180         if (fData){
181                 delete fData;
182                 fData = 0;
183         }
184         return 3;// return error Code for processed DCS data not stored 
185                  // in reference data
186         
187       }
188     }
189   }
190   if (fData){
191           delete fData;
192           fData = 0;
193   }
194   
195   return 0;
196 }
197 //_____________________________________________________________________________
198
199 UInt_t AliTOFPreprocessor::ProcessOnlineDelays()
200 {
201   // Processing data from DAQ for online calibration 
202
203   Log("Processing DAQ delays");
204
205   // reading configuration map 
206   TString compDelays = "kFALSE";
207   Int_t deltaStartingRun = fRun;
208   Int_t startingRun = fRun-deltaStartingRun;
209   Int_t binRangeAve = fgkBinRangeAve;
210   Double_t integralThr = fgkIntegralThr;
211   Double_t thrPar = fgkThrPar;
212
213   AliCDBEntry *cdbEntry = GetFromOCDB("Calib","Config");
214   if (!cdbEntry) {
215           Log(Form("No Configuration entry found in CDB, using default values: ComputingDelays = %s, StartingRun = %i",compDelays.Data(), startingRun));
216   }
217   else {
218           TMap *configMap = (TMap*)cdbEntry->GetObject();
219           if (!configMap){
220                   Log(Form("No map found in Config entry in CDB, using default values: ComputingDelays = %s, StartingRun = %i",compDelays.Data(), startingRun));
221           }
222           else{
223                   TObjString *strDelays = (TObjString*)configMap->GetValue("ComputingDelays");
224                   if (strDelays) {
225                           compDelays = (TString) strDelays->GetString();
226                   }
227                   else {
228                           Log(Form("No ComputingDelays value found in Map from Config entry in CDB, using default value: ComputingDelays =  %s",compDelays.Data()));
229                   }
230                   TObjString *strRun = (TObjString*)configMap->GetValue("StartingRun");
231                   if (strRun) {
232                           TString tmpstr = strRun->GetString();
233                           startingRun = tmpstr.Atoi();
234                           deltaStartingRun = fRun - startingRun;
235                   }
236                   else {
237                           Log(Form("No StartingRun value found in Map from Config entry in CDB, using default value: StartingRun = %i",startingRun));
238                   }
239                   TObjString *strBinRangeAve = (TObjString*)configMap->GetValue("BinRangeAve");
240                   if (strBinRangeAve) {
241                           TString tmpstr = strBinRangeAve->GetString();
242                           binRangeAve = tmpstr.Atoi();
243                   }
244                   else {
245                           Log(Form("No BinRangeAve value found in Map from Config entry in CDB, using default value: BinRangeAve = %i",binRangeAve));
246                   }
247                   TObjString *strIntegralThr = (TObjString*)configMap->GetValue("IntegralThr");
248                   if (strIntegralThr) {
249                           TString tmpstr = strIntegralThr->GetString();
250                           integralThr = tmpstr.Atof();
251                   }
252                   else {
253                           Log(Form("No IntegralThr value found in Map from Config entry in CDB, using default value: IntegralThr = %i",integralThr));
254                   }
255                   TObjString *strThrPar = (TObjString*)configMap->GetValue("ThrPar");
256                   if (strThrPar) {
257                           TString tmpstr = strThrPar->GetString();
258                           thrPar = tmpstr.Atof();
259                   }
260                   else {
261                           Log(Form("No ThrPar value found in Map from Config entry in CDB, using default value: ThrPar = %i",thrPar));
262                   }
263           }
264   }
265   if (compDelays == "kTRUE") fFDRFlag = kFALSE;
266   else fFDRFlag = kTRUE;
267
268   delete cdbEntry;
269   cdbEntry = 0x0;
270
271   Log(Form("ComputingDelays = %s, StartingRun = %i",compDelays.Data(),startingRun));
272
273   fCal = new AliTOFChannelOnlineArray(fNChannels);
274
275   TH1::AddDirectory(0);
276
277   Bool_t resultDAQRef=kFALSE;
278   Bool_t resultTOFPP=kFALSE;
279   TH2S *h2 = 0x0;
280   // processing DAQ
281   
282   TFile * daqFile=0x0;
283   
284   if(fStoreRefData){
285     //retrieving data at Run level
286           TList* list = GetFileSources(kDAQ, "RUNLevel");
287           if (list !=0x0 && list->GetEntries()!=0)
288                   {
289                           AliInfo("The following sources produced files with the id RUNLevel");
290                           list->Print();
291                           for (Int_t jj=0;jj<list->GetEntries();jj++){
292                                   TObjString * str = dynamic_cast<TObjString*> (list->At(jj));
293                                   AliInfo(Form("found source %s", str->String().Data()));
294                                   // file to be stored run per run
295                                   TString fileNameRun = GetFile(kDAQ, "RUNLevel", str->GetName());
296                                   if (fileNameRun.Length()>0){
297                                           AliInfo(Form("Got the file %s, now we can store the Reference Data for the current Run.", fileNameRun.Data()));
298                                           daqFile = new TFile(fileNameRun.Data(),"READ");
299                                           h2 = (TH2S*) daqFile->Get("htof");
300                                           AliCDBMetaData metaDataHisto;
301                                           metaDataHisto.SetBeamPeriod(0);
302                                           metaDataHisto.SetResponsible("Chiara Zampolli");
303                                           metaDataHisto.SetComment("This preprocessor stores the array of histos object as Reference Data.");
304                                           AliInfo("Storing Reference Data");
305                                           resultDAQRef = StoreReferenceData("Calib","DAQData",h2, &metaDataHisto);
306                                           if (!resultDAQRef){
307                                                   Log("some problems occurred::No Reference Data stored, TOF exiting from Shuttle");
308                                                   delete h2;
309                                                   delete list;
310                                                   delete fCal;
311                                                   fCal=0x0;
312                                                   return 5;//return error code for failure in storing Ref Data 
313                                           }
314                                           daqFile->Close();
315                                           delete daqFile;
316                                   }
317                                   
318                                   else{
319                                           Log("The input data file from DAQ (run-level) was not found, TOF exiting from Shuttle "); 
320                                           delete list;
321                                           delete fCal;
322                                           fCal=0x0;
323                                           return 4;//return error code for failure in retrieving Ref Data 
324                                   }
325                           }
326                           delete list;
327                   }
328           else{
329                   Log("The input data file list from DAQ (run-level) was not found, TOF exiting from Shuttle "); 
330                   delete fCal;
331                   fCal=0x0;
332                   return 4;//return error code for failure in retrieving Ref Data 
333           }     
334   }
335
336
337   //Total files, with cumulative histos
338   
339   TList* listTot = GetFileSources(kDAQ, "DELAYS");
340   if (listTot !=0x0 && listTot->GetEntries()!=0)
341           {
342                   AliInfo("The following sources produced files with the id DELAYS");
343                   listTot->Print();
344                   for (Int_t jj=0;jj<listTot->GetEntries();jj++){
345                           TObjString * str = dynamic_cast<TObjString*> (listTot->At(jj));
346                           AliInfo(Form("found source %s", str->String().Data()));
347                           
348                           // file with summed histos, to extract calib params
349                           TString fileName = GetFile(kDAQ, "DELAYS", str->GetName());
350                           if (fileName.Length()>0){
351                                   AliInfo(Form("Got the file %s, now we can extract some values.", fileName.Data()));
352                                   
353                                   daqFile = new TFile(fileName.Data(),"READ");
354                                   if (h2) delete h2;
355                                   h2 = (TH2S*) daqFile->Get("htoftot");
356                                   if (!h2){
357                                           Log("some problems occurred:: No histo retrieved, TOF exiting from Shuttle");
358                                           delete listTot;
359                                           delete daqFile;
360                                           delete fCal;
361                                           fCal=0x0;
362                                           return 7; //return error code for histograms not existing/junky
363                                   }
364                                   else {
365                                           static const Int_t kSize=h2->GetNbinsX();
366                                           static const Int_t kNBins=h2->GetNbinsY();
367                                           static const Double_t kXBinmin=h2->GetYaxis()->GetBinLowEdge(1);
368                                           if (kSize != fNChannels){
369                                                   Log(" number of bins along x different from number of pads, found only a subset of the histograms, TOF exiting from Shuttle");
370                                                   delete listTot;
371                                                   delete h2;
372                                                   delete daqFile;
373                                                   delete fCal;
374                                                   fCal=0x0;
375                                                   return 7; //return error code for histograms not existing/junky
376                                           }
377                                           Int_t nNotStatistics = 0; // number of channel with not enough statistics
378
379                                           /* FDR flag set. do not compute delays, use nominal cable delays */
380                                           if (fFDRFlag) {
381
382                                             Log(" Not computing delays according to flag set in Config entry in OCDB!");
383                                             FillWithCosmicCalibration(fCal);
384                                             
385                                           }
386
387                                           else {  // computing delays if not in FDR runs
388                                                   for (Int_t ich=0;ich<kSize;ich++){
389                                                           /* check whether channel has been read out during current run.
390                                                            * if the status is bad it means it has not been read out.
391                                                            * in this case skip channel in order to not affect the mean */ 
392                                                           if (fStatus->GetHWStatus(ich) == AliTOFChannelOnlineStatusArray::kTOFHWBad){
393                                                                   AliDebug(2,Form(" Channel %i found bad according to FEEmap, (HW status = %i), skipping from delay computing",ich, (Int_t)fStatus->GetHWStatus(ich)));
394                                                                   continue;
395                                                           }
396                                                           AliDebug(2,Form(" Channel %i found ok according to FEEmap, starting delay computing",ich));
397                                                           TH1S *h1 = new TH1S("h1","h1",kNBins,kXBinmin-0.5,kNBins*1.+kXBinmin-0.5);
398                                                           for (Int_t ibin=0;ibin<kNBins;ibin++){
399                                                                   h1->SetBinContent(ibin+1,h2->GetBinContent(ich+1,ibin+1));
400                                                           }
401                                                           if(h1->Integral()<integralThr) {
402                                                                   nNotStatistics++;
403                                                                   Log(Form(" Not enough statistics for bin %i, skipping this channel",ich));  // printing message only if not in FDR runs
404                                                                   delete h1;
405                                                                   h1=0x0;
406                                                                   continue;
407                                                           }
408                                                           Bool_t found=kFALSE; 
409                                                           Float_t minContent=h1->Integral()*thrPar; 
410                                                           Int_t nbinsX = h1->GetNbinsX();
411                                                           Int_t startBin=1;
412                                                           for (Int_t j=1; j<=nbinsX; j++){
413                                                                   if ((
414                                                                        h1->GetBinContent(j) +     
415                                                                        h1->GetBinContent(j+1)+
416                                                                        h1->GetBinContent(j+2)+ 
417                                                                        h1->GetBinContent(j+3))>minContent){
418                                                                           found=kTRUE;
419                                                                           startBin=j;
420                                                                           break;
421                                                                   }
422                                                           }
423                                                           if(!found) AliInfo(Form("WARNING!!! no start of fit found for histo # %i",ich));
424                                                           // Now calculate the mean over the interval. 
425                                                           Double_t mean = 0;
426                                                           Double_t sumw2 = 0;
427                                                           Double_t nent = 0;
428                                                           for(Int_t k=0;k<binRangeAve;k++){
429                                                                   mean=mean+h1->GetBinCenter(startBin+k)*h1->GetBinContent(startBin+k);                 
430                                                                   nent=nent+h1->GetBinContent(startBin+k);                 
431                                                                   sumw2=sumw2+(h1->GetBinCenter(startBin+k))*(h1->GetBinCenter(startBin+k))*(h1->GetBinContent(startBin+k));
432                                                           }
433                                                           mean= mean/nent; //<x>
434                                                           sumw2=sumw2/nent; //<x^2>
435                                                           Double_t rmsmean= 0;
436                                                           rmsmean = TMath::Sqrt((sumw2-mean*mean)/nent);
437                                                           if (ich<fNChannels) {
438                                                                   Float_t delay = mean*AliTOFGeometry::TdcBinWidth()*1.E-3; // delay in ns
439                                                                   fCal->SetDelay(ich,delay);  // delay in ns
440                                                                   AliDebug(2,Form("Setting delay %f (ns) for channel %i",delay,ich));
441                                                           }
442                                                           delete h1;
443                                                           h1=0x0;
444                                                   }
445                                           }
446                                           if (nNotStatistics!=0) Log(Form("Too little statistics for %d channels!",nNotStatistics)); 
447                                   }
448                                   delete h2;
449                                   daqFile->Close();
450                                   delete daqFile;
451                           }
452                           else{
453                                   Log("The Cumulative data file from DAQ does not exist, TOF exiting from Shuttle"); 
454                                   delete listTot;
455                                   delete fCal;
456                                   fCal=0x0;
457                                   return 6;//return error code for problems in retrieving DAQ data 
458                           }
459                   }
460                   delete listTot;
461           }
462   else{
463     Log("Problem: no list for Cumulative data file from DAQ was found, TOF exiting from Shuttle");
464     delete fCal;
465     fCal=0x0;
466     return 6; //return error code for problems in retrieving DAQ data 
467   }
468
469   daqFile=0;
470   AliCDBMetaData metaData;
471   metaData.SetBeamPeriod(0);
472   metaData.SetResponsible("Chiara Zampolli");
473   metaData.SetComment("This preprocessor fills an AliTOFChannelOnlineArray object for online calibration - delays.");
474   AliInfo("Storing Calibration Data");
475   resultTOFPP = Store("Calib","ParOnlineDelay",fCal, &metaData,deltaStartingRun,kTRUE);
476   if(!resultTOFPP){
477     Log("Some problems occurred while storing online object resulting from DAQ data processing");
478     delete fCal;
479     fCal=0x0;
480     return 8;//return error code for problems in storing DAQ data 
481   }
482
483   if (fCal){
484     delete fCal;
485     fCal = 0;
486   }
487
488   return 0;
489 }
490 //_____________________________________________________________________________
491
492 UInt_t AliTOFPreprocessor::ProcessPulserData()
493 {
494   // Processing Pulser Run data for TOF channel status
495
496   Log("Processing Pulser");
497
498   if (fStatus==0x0){
499           AliError("No valid fStatus found, some errors must have occurred!!");
500           return 20;
501   }
502
503   TH1::AddDirectory(0);
504   
505   Bool_t resultPulserRef=kFALSE;
506   Bool_t resultPulser=kFALSE;
507   
508   static const Int_t kSize = AliTOFGeometry::NPadXSector()*AliTOFGeometry::NSectors();
509   TH1S * htofPulser = new TH1S("hTOFpulser","histo with signals on TOF during pulser", kSize,-0.5,kSize-0.5);
510   for (Int_t ibin =1;ibin<=kSize;ibin++){
511           htofPulser->SetBinContent(ibin,-1);
512   }
513   
514   // processing pulser
515   
516   TFile * daqFile=0x0;
517   TH1S *h1=0x0;
518   
519   //retrieving Pulser data 
520   TList* listPulser = GetFileSources(kDAQ, "PULSER");
521   if (listPulser !=0x0 && listPulser->GetEntries()!=0)
522           {
523                   AliInfo("The following sources produced files with the id PULSER");
524                   listPulser->Print();
525                   Int_t nPulser = 0;
526                   for (Int_t jj=0;jj<listPulser->GetEntries();jj++){
527                           Int_t nPulserSource = 0;
528                           TObjString * str = dynamic_cast<TObjString*> (listPulser->At(jj));
529                           AliInfo(Form("found source %s", str->String().Data()));
530                           // file to be stored run per run
531                           TString fileNamePulser = GetFile(kDAQ, "PULSER", str->GetName());
532                           if (fileNamePulser.Length()>0){
533                                   // storing refernce data
534                                   AliInfo(Form("Got the file %s, now we can process pulser data.", fileNamePulser.Data()));
535                                   daqFile = new TFile(fileNamePulser.Data(),"READ");
536                                   h1 = (TH1S*) daqFile->Get("hTOFpulser");
537                                   for (Int_t ibin=0;ibin<kSize;ibin++){
538                                           if ((h1->GetBinContent(ibin+1))!=-1){
539                                                   if ((htofPulser->GetBinContent(ibin+1))==-1){
540                                                           htofPulser->SetBinContent(ibin+1,h1->GetBinContent(ibin+1));
541                                                   }
542                                                   else {
543                                                           Log(Form("Something strange occurred during Pulser run, channel %i already read by another LDC, please check!",ibin));
544                                                   }
545                                           }
546                                   }
547                                   
548                                   // elaborating infos
549                                   Double_t mean =0;
550                                   Int_t nread=0;
551                                   Int_t nreadNotEmpty=0;
552                                   for (Int_t ientry=1;ientry<=h1->GetNbinsX();ientry++){
553                                           
554                                           AliDebug(3,Form(" channel %i pulser status before pulser = %i, with global status = %i",ientry,(Int_t)fStatus->GetPulserStatus(ientry),(Int_t)fStatus->GetStatus(ientry)));
555                                           /* check whether channel has been read out during current run.
556                                            * if the status is bad it means it has not been read out.
557                                            * in this case skip channel in order to not affect the mean */ 
558                                           if (fStatus->GetHWStatus(ientry-1) == AliTOFChannelOnlineStatusArray::kTOFHWBad)
559                                                   continue;
560                                           nPulser++;
561                                           nPulserSource++;
562                                           if (h1->GetBinContent(ientry)==-1) continue;
563                                           else {
564                                                   if (h1->GetBinContent(ientry)>0) {
565                                                           nreadNotEmpty++;
566                                                           AliDebug(2,Form(" channel %i is ok with entry = %f; so far %i channels added ",ientry-1,h1->GetBinContent(ientry),nreadNotEmpty));
567                                                   }
568                                                   mean+=h1->GetBinContent(ientry);
569                                                   nread++;
570                                           }
571                                   }
572                                   if (nread!=0) {
573                                           mean/=nread;
574                                           AliDebug(2,Form(" nread =  %i , nreadNotEmpty = %i, mean = %f",nread,nreadNotEmpty,mean));
575                                           for (Int_t ich =0;ich<fNChannels;ich++){
576                                                   if (h1->GetBinContent(ich+1)==-1) continue;
577                                                   AliDebug(3,Form(" channel %i pulser status before pulser = %i",ich,(Int_t)fStatus->GetPulserStatus(ich)));
578                                                   
579                                                   /* check whether channel has been read out during current run.
580                                                    * if the status is bad it means it has not been read out.
581                                                    * in this case skip channel in order to leave its status 
582                                                    * unchanged */
583                                                   if (fStatus->GetHWStatus(ich) == AliTOFChannelOnlineStatusArray::kTOFHWBad)
584                                                           continue;
585                                                   
586                                                   if (h1->GetBinContent(ich+1)<0.05*mean){
587                                                           fStatus->SetPulserStatus(ich,AliTOFChannelOnlineStatusArray::kTOFPulserBad);  // bad status for pulser
588                                                           AliDebug(2,Form( " channel %i pulser status after pulser = %i (bad, content = %f), with global status = %i",ich,(Int_t)fStatus->GetPulserStatus(ich),h1->GetBinContent(ich+1),(Int_t)fStatus->GetStatus(ich)));
589                                                   }
590                                                   else {
591                                                           fStatus->SetPulserStatus(ich,AliTOFChannelOnlineStatusArray::kTOFPulserOk);  // good status for pulser
592                                                           AliDebug(2,Form( " channel %i pulser status after pulser = %i (good), with global status = %i",ich,(Int_t)fStatus->GetPulserStatus(ich),(Int_t)fStatus->GetStatus(ich)));
593                                                   }
594                                           }
595                                   }
596                                   else {
597                                           Log("No channels read!! No action taken, keeping old status");
598                                   }
599                                   
600                                   daqFile->Close();
601                                   delete daqFile;
602                                   delete h1;
603                           }
604                           
605                           else{
606                                   Log("The input data file from DAQ (pulser) was not found, TOF exiting from Shuttle "); 
607                                   delete listPulser;
608                                   delete htofPulser;
609                                   htofPulser = 0x0;
610                                   if (fStatus){
611                                           delete fStatus;
612                                           fStatus = 0;
613                                   }
614                                   return 10;//return error code for failure in retrieving Ref Data 
615                           }
616                           AliDebug(2,Form(" Number of channels processed during pulser run from source %i = %i",jj, nPulserSource));             
617                   }
618                   AliDebug(2,Form(" Number of channels processed during pulser run = %i",nPulser));
619                   delete listPulser;
620           }
621   
622   else{
623           Log("The input data file list from DAQ (pulser) was not found, TOF exiting from Shuttle "); 
624           delete htofPulser;
625           htofPulser = 0x0;
626           if (fStatus){
627                   delete fStatus;
628                   fStatus = 0;
629           }
630           return 10;//return error code for failure in retrieving Ref Data 
631   }     
632   
633   //storing in OCDB  
634   
635   AliCDBMetaData metaData;
636   metaData.SetBeamPeriod(0);
637   metaData.SetResponsible("Chiara Zampolli");
638   metaData.SetComment("This preprocessor fills an AliTOFChannelOnlineStatusArray object after a Pulser run.");
639   AliInfo("Storing Calibration Data from Pulser Run");
640   resultPulser = Store("Calib","Status",fStatus, &metaData,0,kTRUE);
641   if(!resultPulser){
642     Log("Some problems occurred while storing online object resulting from Pulser data processing");
643     delete htofPulser;
644     htofPulser = 0x0;
645     if (fStatus){
646             delete fStatus;
647             fStatus = 0;
648     }
649     return 11;//return error code for problems in storing Pulser data 
650   }
651
652   if(fStoreRefData){
653     
654     AliCDBMetaData metaDataHisto;
655     metaDataHisto.SetBeamPeriod(0);
656     metaDataHisto.SetResponsible("Chiara Zampolli");
657     char comment[200];
658     sprintf(comment,"This preprocessor stores the Ref data from a pulser run.");
659     metaDataHisto.SetComment(comment);
660     AliInfo("Storing Reference Data");
661     resultPulserRef = StoreReferenceData("Calib","PulserData",htofPulser, &metaDataHisto);
662     if (!resultPulserRef){
663       Log("some problems occurred::No Reference Data for pulser stored, TOF exiting from Shuttle");
664       delete htofPulser;
665       htofPulser = 0x0;
666       if (fStatus){
667               delete fStatus;
668               fStatus = 0;
669       }
670       return 9;//return error code for failure in storing Ref Data 
671     }
672   }
673   
674   daqFile=0;
675
676   delete htofPulser;
677   htofPulser = 0x0;
678
679   if (fStatus){
680     delete fStatus;
681     fStatus = 0;
682   }
683
684   return 0;
685 }
686 //_____________________________________________________________________________
687
688 UInt_t AliTOFPreprocessor::ProcessNoiseData()
689 {
690
691   // Processing Noise Run data for TOF channel status
692
693   Log("Processing Noise");
694
695   if (fStatus==0x0){
696           AliError("No valid fStatus found, some errors must have occurred!!");
697           return 20;
698   }
699
700   Float_t noiseThr = 1;   // setting default threshold for noise to 1 Hz
701   // reading config map
702   AliCDBEntry *cdbEntry = GetFromOCDB("Calib","ConfigNoise");
703   if (!cdbEntry) {
704           Log(Form("No Configuration entry found in CDB, using default values: NoiseThr = %d",noiseThr));
705   }
706   else {
707           TMap *configMap = (TMap*)cdbEntry->GetObject();
708           if (!configMap){
709                   Log(Form("No map found in Config entry in CDB, using default values: NoiseThr = %d", noiseThr));
710           }
711           else{
712                   TObjString *strNoiseThr = (TObjString*)configMap->GetValue("NoiseThr");
713                   if (strNoiseThr) {
714                           TString tmpstr = strNoiseThr->GetString();
715                           noiseThr = tmpstr.Atoi();
716                   }
717                   else {
718                           Log(Form("No NoiseThr value found in Map from ConfigNoise entry in CDB, using default value: NoiseThr = %i",noiseThr));
719                   }
720           }
721   }
722
723   delete cdbEntry;
724   cdbEntry = 0x0;
725
726   TH1::AddDirectory(0);
727
728   Bool_t resultNoiseRef=kFALSE;
729   Bool_t resultNoise=kFALSE;
730
731   static const Int_t kSize = AliTOFGeometry::NPadXSector()*AliTOFGeometry::NSectors();
732   TH1F * htofNoise = new TH1F("hTOFnoise","histo with signals on TOF during noise", kSize,-0.5,kSize-0.5);
733   for (Int_t ibin =1;ibin<=kSize;ibin++){
734           htofNoise->SetBinContent(ibin,-1);
735   }
736   
737   // processing noise
738   
739   TFile * daqFile=0x0;
740   TH1F * h1=0x0;
741   
742   // useful counters
743   Int_t nNoise = 0;
744   Int_t nNoisyChannels = 0;
745   Int_t nNotNoisyChannels = 0;
746   Int_t nChannelsFromDA = 0;
747   Int_t nMatchingWindowNullNonZero = 0;
748   Int_t nMatchingWindowNullEqualZero = 0;
749
750   // retrieving Noise data 
751   TList* listNoise = GetFileSources(kDAQ, "NOISE");
752   if (listNoise !=0x0 && listNoise->GetEntries()!=0)
753           {
754                   AliInfo("The following sources produced files with the id NOISE");
755                   listNoise->Print();
756                   for (Int_t jj=0;jj<listNoise->GetEntries();jj++){
757                           Int_t nNoiseSource = 0;
758                           TObjString * str = dynamic_cast<TObjString*> (listNoise->At(jj));
759                           AliInfo(Form("found source %s", str->String().Data()));
760                           // file to be stored run per run
761                           TString fileNameNoise = GetFile(kDAQ, "NOISE", str->GetName());
762                           if (fileNameNoise.Length()>0){
763                                   // storing reference data
764                                   AliInfo(Form("Got the file %s, now we can process noise data.", fileNameNoise.Data()));
765                                   daqFile = new TFile(fileNameNoise.Data(),"READ");
766                                   h1 = (TH1F*) daqFile->Get("hTOFnoise");
767                                   for (Int_t ibin=0;ibin<kSize;ibin++){
768                                           if ((h1->GetBinContent(ibin+1))!=-1){
769                                                   nNoiseSource++;
770                                                   // checking the matching window for current channel
771                                                   if (fMatchingWindow[ibin] == 0){
772                                                           Log(Form("Matching window for channel %i null, but the channel was read by the LDC! skipping channel, BUT Please check!",ibin));
773                                                           if ((h1->GetBinContent(ibin+1))!=0) nMatchingWindowNullNonZero++;                                             
774                                                           if ((h1->GetBinContent(ibin+1))==0) nMatchingWindowNullEqualZero++;                                           
775                                                           continue;
776                                                   }
777                                                   if ((htofNoise->GetBinContent(ibin+1))==-1){
778                                                           htofNoise->SetBinContent(ibin+1,h1->GetBinContent(ibin+1)/(fMatchingWindow[ibin]*1.E-9));
779                                                           if ((h1->GetBinContent(ibin+1))!= 0) AliDebug(2,Form("Channel = %i, Matching window = %i, Content = %f", ibin, fMatchingWindow[ibin], htofNoise->GetBinContent(ibin+1)));
780                                                   }
781                                                   else {
782                                                           Log(Form("Something strange occurred during Noise run, channel %i already read by another LDC, please check!",ibin));
783                                                   }
784                                           }
785                                   }
786
787                                   Log(Form(" Number of channels processed during noise run from source %i = %i",jj, nNoiseSource));
788                                   daqFile->Close();
789                                   delete daqFile;
790                                   delete h1;
791                                   daqFile = 0x0;
792                                   h1 = 0x0;
793
794                           }
795                           else{
796                                   Log("The input data file from DAQ (noise) was not found, TOF exiting from Shuttle "); 
797                                   delete listNoise;
798                                   listNoise = 0x0;
799                                   delete htofNoise;
800                                   htofNoise = 0x0;
801                                   if (fStatus){
802                                           delete fStatus;
803                                           fStatus = 0;
804                                   }
805                                   if (fMatchingWindow){
806                                           delete [] fMatchingWindow;
807                                           fMatchingWindow = 0;
808                                   }
809                                   return 13;//return error code for failure in retrieving Ref Data 
810                           }
811                   }               
812           }
813                           
814   else{
815           Log("The input data file list from DAQ (noise) was not found, TOF exiting from Shuttle "); 
816           delete htofNoise;
817           htofNoise = 0x0;
818           if (fStatus){
819                   delete fStatus;
820                   fStatus = 0;
821           }
822           if (fMatchingWindow){
823                   delete [] fMatchingWindow;
824                   fMatchingWindow = 0;
825           }
826           return 13;//return error code for failure in retrieving Ref Data 
827   }     
828   
829   // elaborating infos to set NOISE status
830   for (Int_t ich =0;ich<fNChannels;ich++){
831           if (htofNoise->GetBinContent(ich+1)== -1) continue;
832
833           nChannelsFromDA++;
834
835           AliDebug(3,Form(" channel %i noise status before noise = %i, with global status = %i",ich,(Int_t)fStatus->GetNoiseStatus(ich),(Int_t)fStatus->GetStatus(ich)));
836           //AliDebug(2,Form( " channel %i status before noise = %i",ich,(Int_t)fStatus->GetNoiseStatus(ich)));
837           
838           /* check whether channel has been read out during current run.
839            * if the status is bad it means it has not been read out.
840            * in this case skip channel in order to leave its status 
841            * unchanged */
842
843           if ((fStatus->GetHWStatus(ich)) == AliTOFChannelOnlineStatusArray::kTOFHWBad)
844                   continue;
845           
846           nNoise++;
847           if (htofNoise->GetBinContent(ich+1) >= noiseThr){
848                   fStatus->SetNoiseStatus(ich,AliTOFChannelOnlineStatusArray::kTOFNoiseBad); // bad status for noise
849                   AliDebug(3,Form( " channel %i noise status after noise = %i, with global status = %i",ich,(Int_t)fStatus->GetNoiseStatus(ich),(Int_t)fStatus->GetStatus(ich)));
850                   nNoisyChannels++;
851           }
852           else {
853                   fStatus->SetNoiseStatus(ich,AliTOFChannelOnlineStatusArray::kTOFNoiseOk); // good status for noise
854                   AliDebug(3,Form(" channel %i noise status after noise = %i, with global status = %i",ich,(Int_t)fStatus->GetNoiseStatus(ich),(Int_t)fStatus->GetStatus(ich)));
855                   nNotNoisyChannels++;
856           }
857   }
858   
859   Log(Form(" Number of channels processed by DA during noise run, independetly from TOFFEE = %i",nChannelsFromDA));
860   Log(Form(" Number of channels processed during noise run (that were ON according to TOFFEE) = %i",nNoise));
861   Log(Form(" Number of noisy channels found during noise run = %i",nNoisyChannels));
862   Log(Form(" Number of not noisy channels found during noise run = %i",nNotNoisyChannels));
863   Log(Form(" Number of channels with matching window NULL (so skipped), but Non Zero content = %i",nMatchingWindowNullNonZero));
864   Log(Form(" Number of channels with matching window NULL (so skipped), and Zero content = %i",nMatchingWindowNullEqualZero));
865
866   delete listNoise;
867   
868   //daqFile=0;
869   
870   //storing in OCDB
871   
872   AliCDBMetaData metaData;
873   metaData.SetBeamPeriod(0);
874   metaData.SetResponsible("Chiara Zampolli");
875   metaData.SetComment("This preprocessor fills an AliTOFChannelOnlineStatusArray object after a Noise run.");
876   AliInfo("Storing Calibration Data from Noise Run");
877   resultNoise = Store("Calib","Status",fStatus, &metaData,0,kTRUE);
878   if(!resultNoise){
879     Log("Some problems occurred while storing online object resulting from Noise data processing");
880     delete htofNoise;
881     htofNoise = 0x0;
882     if (fStatus){
883             delete fStatus;
884             fStatus = 0;
885     }
886     if (fMatchingWindow){
887             delete [] fMatchingWindow;
888             fMatchingWindow = 0;
889     }
890     return 14;//return error code for problems in storing Noise data 
891   }
892
893   if(fStoreRefData){
894     
895     AliCDBMetaData metaDataHisto;
896     metaDataHisto.SetBeamPeriod(0);
897     metaDataHisto.SetResponsible("Chiara Zampolli");
898     char comment[200];
899     sprintf(comment,"This preprocessor stores the Ref data from a noise run. ");
900     metaDataHisto.SetComment(comment);
901     AliInfo("Storing Reference Data");
902     resultNoiseRef = StoreReferenceData("Calib","NoiseData",htofNoise, &metaDataHisto);
903     if (!resultNoiseRef){
904       Log("some problems occurred::No Reference Data for noise stored");
905       delete htofNoise;
906       htofNoise = 0x0;
907       if (fStatus){
908               delete fStatus;
909               fStatus = 0;
910       }
911       if (fMatchingWindow){
912               delete [] fMatchingWindow;
913               fMatchingWindow = 0;
914       }
915       return 12;//return error code for failure in storing Ref Data 
916     }
917   }
918
919   delete htofNoise;
920   htofNoise = 0x0;
921
922   if (fStatus){
923     delete fStatus;
924     fStatus = 0;
925   }
926
927   if (fMatchingWindow){
928           delete [] fMatchingWindow;
929           fMatchingWindow = 0;
930   }
931
932   return 0;
933 }
934 //_____________________________________________________________________________
935
936 UInt_t AliTOFPreprocessor::ProcessFEEData()
937 {
938   // Processing Pulser Run data for TOF channel status
939   // dummy for the time being
940
941   Log("Processing FEE");
942
943   Bool_t updateOCDB = kFALSE;
944   AliTOFFEEReader feeReader;
945
946   TH1C hCurrentFEE("hCurrentFEE","histo with current FEE channel status", fNChannels, 0, fNChannels);
947   
948   /* load current TOF FEE config from DCS FXS, parse, 
949    * fill current FEE histogram and set FEE status */
950   
951   const char * nameFile = GetFile(kDCS,"TofFeeMap",""); 
952   AliInfo(Form("nameFile = %s",nameFile));
953   if (nameFile == NULL) {
954           return 15;
955   } 
956   feeReader.LoadFEEConfig(nameFile);
957   Int_t parseFee = feeReader.ParseFEEConfig();
958   AliDebug(2,Form("%i enabled channels found in FEE configuration",parseFee));
959   /* load stored TOF FEE from OCDB and compare it with current FEE.
960    * if stored FEE is different from current FEE set update flag.
961    * if there is no stored FEE in OCDB set update flag */
962   
963   fMatchingWindow = new Int_t[fNChannels];
964
965   AliCDBEntry *cdbEntry = GetFromOCDB("Calib","Status");
966   if (!cdbEntry) {
967           /* no CDB entry found. set update flag */
968           Log("     ************ WARNING ************");
969           Log("No CDB Status entry found, creating a new one!");
970           Log("     *********************************");
971           fStatus = new AliTOFChannelOnlineStatusArray(fNChannels);
972           updateOCDB = kTRUE;
973   }
974   else {
975           if (cdbEntry) cdbEntry->SetOwner(kFALSE);
976           /* CDB entry OK. loop over channels */
977           fStatus = (AliTOFChannelOnlineStatusArray*) cdbEntry->GetObject();
978           delete cdbEntry;
979           cdbEntry = 0x0;
980   }
981   for (Int_t iChannel = 0; iChannel < fNChannels; iChannel++){
982           //AliDebug(2,Form("********** channel %i",iChannel));
983           /* compare current FEE channel status with stored one 
984            * if different set update flag and break loop */
985           //AliDebug(2,Form( " channel %i status before FEE = %i",iChannel,(Int_t)fStatus->GetHWStatus(iChannel)));
986           fMatchingWindow[iChannel] = feeReader.GetMatchingWindow(iChannel);
987           if (feeReader.IsChannelEnabled(iChannel)) {
988                   hCurrentFEE.SetBinContent(iChannel + 1, 1);
989                   if (fStatus->GetHWStatus(iChannel)!=AliTOFChannelOnlineStatusArray::kTOFHWOk){
990                           updateOCDB = kTRUE;
991                           fStatus->SetHWStatus(iChannel,AliTOFChannelOnlineStatusArray::kTOFHWOk);
992                           AliDebug(3,Form( " changed into enabled: channel %i status after FEE = %i",iChannel,(Int_t)fStatus->GetHWStatus(iChannel)));
993                   }
994           }
995           else {
996                   if (fStatus->GetHWStatus(iChannel)!=AliTOFChannelOnlineStatusArray::kTOFHWBad){
997                           updateOCDB = kTRUE;
998                           fStatus->SetHWStatus(iChannel,AliTOFChannelOnlineStatusArray::kTOFHWBad);
999                           AliDebug(3,Form( " changed into disabled: channel %i status after FEE = %i",iChannel,(Int_t)fStatus->GetHWStatus(iChannel)));
1000                   }
1001           }
1002   }
1003
1004
1005   /* check whether we don't have to store reference data.
1006    * in this case we return without errors. */
1007   if (fStoreRefData) {
1008           /* store reference data */
1009           AliCDBMetaData metaDataHisto;
1010           metaDataHisto.SetBeamPeriod(0);
1011           metaDataHisto.SetResponsible("Roberto Preghenella");
1012           metaDataHisto.SetComment("This preprocessor stores the FEE Ref data of the current run.");
1013           AliInfo("Storing FEE reference data");
1014           /* store FEE reference data */
1015           if (!StoreReferenceData("Calib", "FEEData", &hCurrentFEE, &metaDataHisto)) {
1016                   /* failed */
1017                   Log("problems while storing FEE reference data");
1018                   if (fStatus){
1019                           delete fStatus;
1020                           fStatus = 0;
1021                   }
1022                   return 18; /* error return code for problems while storing FEE reference data */
1023           }
1024   }
1025
1026   /* check whether we don't need to update OCDB.
1027    * in this case we can return without errors and
1028    * the current FEE is stored in the fStatus object. */
1029   if (!updateOCDB) {
1030     AliInfo("TOF FEE config has not changed. Do not overwrite stored file.");
1031     return 0; /* return ok */
1032   }
1033
1034   TString runType = GetRunType();
1035   if (runType != "PHYSICS") {
1036           AliInfo(Form("Run Type = %s, waiting to store status map",GetRunType()));
1037     return 0; /* return ok */
1038   }
1039
1040   /* update the OCDB with the current FEE since even 
1041    * a little difference has been detected. */
1042
1043   AliCDBMetaData metaData;
1044   metaData.SetBeamPeriod(0);
1045   metaData.SetResponsible("Roberto Preghenella");
1046   metaData.SetComment("This preprocessor fills an AliTOFChannelOnlineStatusArray object from FEE data.");
1047   AliInfo("Storing Status data from current run after FEE parsing");
1048   /* store FEE data */
1049   if (!Store("Calib", "Status", fStatus, &metaData, 0, kTRUE)) {
1050     /* failed */
1051     Log("problems while storing FEE data object");
1052     if (fStatus){
1053             delete fStatus;
1054             fStatus = 0;
1055     }
1056     return 17; /* return error code for problems  while storing FEE data */
1057   }
1058
1059   /* everything fine. return */
1060
1061   if (fStatus){
1062     delete fStatus;
1063     fStatus = 0;
1064   }
1065
1066   return 0;
1067
1068 }
1069
1070 //_____________________________________________________________________________
1071
1072 UInt_t AliTOFPreprocessor::Process(TMap* dcsAliasMap)
1073 {
1074   //
1075   //
1076   //
1077
1078   TString runType = GetRunType();
1079   Log(Form("RunType %s",runType.Data()));
1080   
1081   // processing 
1082
1083   /* always process FEE data */
1084   Int_t iresultFEE = ProcessFEEData();
1085   if (iresultFEE != 0)
1086     return iresultFEE;
1087
1088   if (runType == "PULSER") {
1089     Int_t iresultPulser = ProcessPulserData();
1090     return iresultPulser; 
1091   }
1092
1093   if (runType == "NOISE") { // for the time being associating noise runs with pedestal runs; proper run type to be defined 
1094     Int_t iresultNoise = ProcessNoiseData();
1095     return iresultNoise; 
1096   }
1097   
1098   if (runType == "PHYSICS") {
1099     Int_t iresultDAQ = ProcessOnlineDelays();
1100     if (iresultDAQ != 0) {
1101       return iresultDAQ;
1102     }
1103     else {
1104       Int_t iresultDCS = ProcessDCSDataPoints(dcsAliasMap);
1105       return iresultDCS;
1106     }
1107   }
1108
1109   // storing
1110   return 0;
1111 }
1112
1113
1114 //_____________________________________________________________________________
1115
1116 void
1117 AliTOFPreprocessor::FillWithCosmicCalibration(AliTOFChannelOnlineArray *cal)
1118 {
1119   /*
1120    * fill with cosmic calibration 
1121    */
1122
1123   Log(" Using cosmic-ray calibration.");
1124   
1125   AliTOFcalibHisto calibHisto;
1126     Log(Form(" loading calibration histograms from %s", calibHisto.GetCalibHistoFileName()));
1127   Log(Form(" loading calibration parameters from %s", calibHisto.GetCalibParFileName()));
1128   calibHisto.LoadCalibPar();
1129   
1130   /* loop over channel index */
1131   for (Int_t iIndex = 0; iIndex < fNChannels; iIndex++) {
1132     cal->SetDelay(iIndex, calibHisto.GetNominalCorrection(iIndex));
1133   }
1134   
1135 }
1136
1137
1138 //_____________________________________________________________________________
1139
1140 void
1141 AliTOFPreprocessor::FillWithCableLengthMap(AliTOFChannelOnlineArray *cal)
1142 {
1143   /*
1144    * fill with cosmic calibration 
1145    */
1146   
1147   Log(" Using cable-length map.");
1148   AliTOFRawStream tofrs;
1149   Int_t det[5], dummy, index;
1150   Float_t cableTimeShift;
1151   
1152   /* temporarly disable warnings */
1153   AliLog::EType_t logLevel = (AliLog::EType_t)AliLog::GetGlobalLogLevel();
1154   AliLog::SetGlobalLogLevel(AliLog::kError);
1155   
1156   /* loop over EO indeces */
1157   for (Int_t iddl = 0; iddl < 72; iddl++)
1158     for (Int_t islot = 3; islot <= 12; islot++)
1159       for (Int_t ichain = 0; ichain < 2; ichain++)
1160         for (Int_t itdc = 0; itdc < 15; itdc++)
1161           for (Int_t ichannel = 0; ichannel < 8; ichannel++) {
1162             
1163             /* get DO index */
1164             tofrs.EquipmentId2VolumeId(iddl, islot, ichain, itdc, ichannel, det);
1165             
1166             /* swap det[3] and det[4] indeces (needed to obtain correct channel index) */
1167             dummy = det[3];
1168             det[3] = det[4];
1169             det[4] = dummy;
1170             
1171             /* check DO index */
1172             if (det[0] < 0 || det[0] > 17 ||
1173                 det[1] < 0 || det[1] > 4 ||
1174                 det[2] < 0 || det[2] > 18 ||
1175                 det[3] < 0 || det[3] > 1 ||
1176                 det[4] < 0 || det[4] > 47)
1177               continue;
1178             
1179             /* get channel index */
1180             index = AliTOFGeometry::GetIndex(det);
1181             
1182             /* get cable time shift */
1183             cableTimeShift = AliTOFCableLengthMap::GetCableTimeShift(iddl, islot, ichain, itdc);
1184             
1185             /* set delay */
1186             if (index<fNChannels) {
1187               cal->SetDelay(index,cableTimeShift);  // delay in ns
1188               AliDebug(2,Form("Setting delay %f (ns) for channel %i",cableTimeShift,index));
1189             }
1190             
1191           } /* loop over EO indeces */
1192   
1193   /* re-enable warnings */
1194   AliLog::SetGlobalLogLevel(logLevel);
1195   
1196 }
1197
1198