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