]> git.uio.no Git - u/mrichter/AliRoot.git/blob - ZDC/AliZDCPreprocessor.cxx
Fix
[u/mrichter/AliRoot.git] / ZDC / AliZDCPreprocessor.cxx
1 // --- ROOT system
2 #include <TFile.h>
3 #include <TClonesArray.h>
4 #include <TList.h>
5 #include <TObjString.h>
6 #include <TTimeStamp.h>
7
8 #include "AliZDCPreprocessor.h"
9 #include "AliCDBManager.h"
10 #include "AliCDBEntry.h"
11 #include "AliCDBMetaData.h"
12 #include "AliDCSValue.h"
13 #include "AliAlignObj.h"
14 #include "AliAlignObjParams.h"
15 #include "AliLog.h"
16 #include "AliZDCDataDCS.h"
17 #include "AliZDCChMap.h"
18 #include "AliZDCPedestals.h"
19 #include "AliZDCLaserCalib.h"
20 #include "AliZDCEnCalib.h"
21 #include "AliZDCTowerCalib.h"
22
23 /////////////////////////////////////////////////////////////////////
24 //                                                                 //
25 // Class implementing Shuttle ZDC pre-processor.                   //
26 // It takes data from DCS and DAQ and writes calibration objects   //
27 // in the OCDB and reference values/histos in the ReferenceData.   //
28 //                                                                 //
29 /////////////////////////////////////////////////////////////////////
30
31 // ******************************************************************
32 //    RETURN CODES:
33 // return 0 : everything OK
34 // return 1 : no DCS input data Map
35 // return 2 : error storing DCS data in RefData 
36 // return 3 : error storing alignment object in OCDB
37 // return 4 : error in ZDCMapping.dat file retrieved from DAQ FXS (not existing|empty|corrupted)
38 // return 5 : error storing mapping obj. in OCDB
39 // return 6 : error storing energy calibration obj. in OCDB
40 // return 7 : error storing tower inter-calibration obj. in OCDB
41 // return 8 : error in ZDCEnergyCalib.dat file retrieved from DAQ FXS 
42 // return 9 : error in ZDCTowerCalib.dat file retrieved from DAQ FXS 
43 // return 10: error in ZDCPedestal.dat file retrieved from DAQ FXS 
44 // return 11: error storing pedestal calibration obj. in OCDB
45 // return 12: error in ZDCPedHisto.root file retrieved from DAQ FXS 
46 // return 13: error storing pedestal histos in RefData 
47 // return 14: error in ZDCLaserCalib.dat file retrieved from DAQ FXS 
48 // return 15: error storing laser calibration obj. in OCDB
49 // return 16: error in ZDCLaserHisto.root file retrieved from DAQ FXS 
50 // return 17: error storing laser histos in RefData 
51 // ******************************************************************
52
53 ClassImp(AliZDCPreprocessor)
54
55 //______________________________________________________________________________________________
56 AliZDCPreprocessor::AliZDCPreprocessor(AliShuttleInterface* shuttle) :
57   AliPreprocessor("ZDC", shuttle),
58   fData(0)
59 {
60   // constructor
61   // May 2009 - run types updated according to
62   // http://alice-ecs.web.cern.ch/alice-ecs/runtypes_3.36.html
63   AddRunType("STANDALONE_PEDESTAL");
64   AddRunType("STANDALONE_LASER");
65   AddRunType("STANDALONE_COSMIC");
66   AddRunType("CALIBRATION_EMD");
67   AddRunType("CALIBRATION_MB");
68   AddRunType("CALIBRATION_CENTRAL");
69   AddRunType("CALIBRATION_SEMICENTRAL");
70   AddRunType("CALIBRATION_BC");
71   AddRunType("PHYSICS");
72 }
73
74
75 //______________________________________________________________________________________________
76 AliZDCPreprocessor::~AliZDCPreprocessor()
77 {
78   // destructor
79 }
80
81
82 //______________________________________________________________________________________________
83 void AliZDCPreprocessor::Initialize(Int_t run, UInt_t startTime, UInt_t endTime)
84 {
85   // Creates AliZDCDataDCS object
86
87   AliPreprocessor::Initialize(run, startTime, endTime);
88
89   AliDebug(2,Form("\n\tRun %d \n\tStartTime %s \n\tEndTime %s \n\tStartTime DCS Query %s \n\tEndTime DCS Query %s", run,
90                 TTimeStamp(startTime).AsString(),
91                 TTimeStamp(endTime).AsString(), ((TTimeStamp)GetStartTimeDCSQuery()).AsString(), ((TTimeStamp)GetEndTimeDCSQuery()).AsString()));
92
93   fRun = run;
94   fStartTime = startTime;
95   fEndTime = endTime;
96
97   fData = new AliZDCDataDCS(fRun, fStartTime, fEndTime, GetStartTimeDCSQuery(), GetEndTimeDCSQuery());
98 }
99
100 //_____________________________________________________________________________
101 Bool_t AliZDCPreprocessor::ProcessDCS(){
102
103   // tells whether DCS should be processed or not
104
105   TString runType = GetRunType();
106   Log(Form("RunType %s",runType.Data()));
107
108   if (runType=="STANDALONE_COSMIC" || runType=="STANDALONE_PEDESTAL"){
109     return kFALSE;
110   }
111
112   return kTRUE;
113 }
114
115 //______________________________________________________________________________________________
116 UInt_t AliZDCPreprocessor::ProcessDCSData(TMap* dcsAliasMap)
117 {
118   
119   // Fills data into a AliZDCDataDCS object
120   if(!dcsAliasMap){
121     Log(" No DCS map found: ZDC exiting from Shuttle");
122     if(fData){
123       delete fData;
124       fData = 0;
125     }
126     return 1;
127   }
128
129   Log(Form("Processing data from DCS"));
130    
131   // The processing of the DCS input data is forwarded to AliZDCDataDCS
132   //dcsAliasMap->Print(""); 
133   Bool_t resDCSProcess = fData->ProcessData(*dcsAliasMap);
134   if(resDCSProcess==kFALSE){
135     Log(" Problems in processing DCS DP");
136     return 1;
137   }  
138   
139   // Store DCS data as reference
140   AliCDBMetaData metadata;
141   metadata.SetResponsible("Chiara Oppedisano");
142   metadata.SetComment("DCS DP TMap for ZDC");
143   Bool_t resDCSRef = kTRUE;
144   resDCSRef = StoreReferenceData("DCS","Data", dcsAliasMap, &metadata);
145   
146   if(resDCSRef==kFALSE) return 2;
147
148   // --- Writing ZDC table positions into alignment object
149   TClonesArray *array = new TClonesArray("AliAlignObjParams",10);
150   TClonesArray &alobj = *array;
151   AliAlignObjParams a;
152   Double_t dx=0., dz=0., dpsi=0., dtheta=0., dphi=0.;
153   // Vertical table position in mm from DCS
154   Double_t dyZN1 = (Double_t) (fData->GetAlignData(0)/10.);
155   Double_t dyZP1 = (Double_t) (fData->GetAlignData(1)/10.);
156   Double_t dyZN2 = (Double_t) (fData->GetAlignData(2)/10.);
157   Double_t dyZP2 = (Double_t) (fData->GetAlignData(3)/10.);
158   //
159   const char *n1ZDC="ZDC/NeutronZDC_C";  
160   const char *p1ZDC="ZDC/ProtonZDC_C";
161   const char *n2ZDC="ZDC/NeutronZDC_A";
162   const char *p2ZDC="ZDC/ProtonZDC_A";
163   //
164   UShort_t iIndex=0;
165   AliGeomManager::ELayerID iLayer = AliGeomManager::kInvalidLayer;
166   UShort_t volid = AliGeomManager::LayerToVolUID(iLayer,iIndex);
167   //
168   new(alobj[0]) AliAlignObjParams(n1ZDC, volid, dx, dyZN1, dz, dpsi, dtheta, dphi, kTRUE);
169   new(alobj[1]) AliAlignObjParams(p1ZDC, volid, dx, dyZP1, dz, dpsi, dtheta, dphi, kTRUE);
170   new(alobj[2]) AliAlignObjParams(n2ZDC, volid, dx, dyZN2, dz, dpsi, dtheta, dphi, kTRUE);
171   new(alobj[3]) AliAlignObjParams(p2ZDC, volid, dx, dyZP2, dz, dpsi, dtheta, dphi, kTRUE);
172  
173   // save in CDB storage
174   AliCDBMetaData mdDCS;
175   mdDCS.SetResponsible("Chiara Oppedisano");
176   mdDCS.SetComment("Alignment object for ZDC");
177   Bool_t resultAl = Store("Align","Data", array, &mdDCS, 0, 0);
178   if(resultAl==kFALSE)  return 3;
179   
180   return 0;
181 }
182
183 //______________________________________________________________________________________________
184 UInt_t AliZDCPreprocessor::ProcessChMap()
185
186   const int kNch = 48;
187   
188   // Reading the file for mapping from FXS
189   TList* daqSource = GetFileSources(kDAQ, "MAPPING");
190   if(!daqSource){
191     AliError(Form("No sources for file ZDCChMapping.dat in run %d ", fRun));
192     return 4;
193   }
194   if(daqSource->GetEntries()==0) return 4;
195   Log("\t List of DAQ sources for MAPPING id: "); daqSource->Print();
196   //
197   TIter iter(daqSource);
198   TObjString* source = 0;
199   Int_t isou = 0;
200   Int_t readMap[kNch][6]; 
201   //
202   while((source = dynamic_cast<TObjString*> (iter.Next()))){
203      TString fileName = GetFile(kDAQ, "MAPPING", source->GetName());
204      Log(Form("\t Getting file #%d: ZDCChMapping.dat from %s\n",++isou, source->GetName()));
205
206      if(fileName.Length() <= 0){
207        Log(Form("No file from source %s!", source->GetName()));
208        return 4;
209      }
210      // --- Reading file with calibration data
211      //const char* fname = fileName.Data();
212      if(fileName){
213        FILE *file;
214        if((file = fopen(fileName,"r")) == NULL){
215          printf("Cannot open file %s \n",fileName.Data());
216          return 4;
217        }
218        Log(Form("File %s connected to process data for ADC mapping", fileName.Data()));
219        //
220        for(Int_t j=0; j<kNch; j++){       
221            for(Int_t k=0; k<6; k++){
222              int read = fscanf(file,"%d",&readMap[j][k]);
223              if(read == 0) AliDebug(3," Failing in reading data from mapping file");
224            }
225        }
226        fclose(file);
227      }
228      else{
229        Log(Form("File %s not found", fileName.Data()));
230        return 4;
231      }
232   }
233   delete daqSource; daqSource=0;
234   
235   // Store the currently read map ONLY IF it is different
236   // from the entry in the OCDB
237   Bool_t updateOCDB = kFALSE;
238   
239   AliCDBEntry *cdbEntry = GetFromOCDB("Calib","ChMap");
240   if(!cdbEntry){
241     Log(" No existing CDB entry for ADC mapping");
242     updateOCDB = kTRUE;
243   }
244   else{
245     AliZDCChMap *chMap = (AliZDCChMap*) cdbEntry->GetObject();
246     for(Int_t i=0; i<kNch; i++){
247       if(  (readMap[i][1] == chMap->GetADCModule(i)) 
248         && (readMap[i][2] == chMap->GetADCChannel(i)) 
249         && (readMap[i][4] == chMap->GetDetector(i)) 
250         && (readMap[i][5] == chMap->GetSector(i))){
251          updateOCDB = kFALSE;
252       }
253       else updateOCDB = kTRUE;
254     }
255   }
256   //
257   Bool_t resChMapStore = kTRUE;
258   if(updateOCDB==kTRUE){
259     Log(" A new entry ZDC/Calib/ChMap will be created");
260     //
261     // --- Initializing mapping calibration object
262     AliZDCChMap *mapCalib = new AliZDCChMap("ZDC");
263     // Writing channel map in the OCDB
264     for(Int_t k=0; k<kNch; k++){
265       mapCalib->SetADCModule(k,readMap[k][1]);
266       mapCalib->SetADCChannel(k,readMap[k][2]);
267       mapCalib->SetDetector(k,readMap[k][4]);
268       mapCalib->SetSector(k,readMap[k][5]);
269     }
270     //mapCalib->Print("");
271     // 
272     AliCDBMetaData metaData;
273     metaData.SetBeamPeriod(0);
274     metaData.SetResponsible("Chiara Oppedisano");
275     metaData.SetComment("Filling AliZDCChMap object");  
276     //
277     resChMapStore = Store("Calib","ChMap",mapCalib, &metaData, 0, 1);
278   }
279   else{
280     Log(" ZDC/Calib/ChMap entry in OCDB is valid and won't be updated");
281     resChMapStore = kTRUE;
282   }
283   
284   if(resChMapStore==kFALSE) return 5;
285   
286   return 0;
287
288 }
289
290 //______________________________________________________________________________________________
291 UInt_t AliZDCPreprocessor::ProcessppData()
292 {
293    Bool_t resEnCal=kTRUE, resTowCal=kTRUE;
294   
295    // *********** Energy calibration
296    // --- Cheking if there is already the entry in the OCDB
297    AliCDBEntry *cdbEnEntry = GetFromOCDB("Calib", "EnergyCalib");
298    if(!cdbEnEntry){   
299      Log(Form(" ZDC/Calib/EnergyCalib entry will be created"));
300      // --- Initializing calibration object
301      AliCDBMetaData metaData;
302      metaData.SetBeamPeriod(0);
303      metaData.SetResponsible("Chiara Oppedisano");
304      //
305      AliZDCEnCalib *eCalib = new AliZDCEnCalib("ZDC");
306      for(Int_t j=0; j<6; j++) eCalib->SetEnCalib(j,1.);
307      metaData.SetComment("AliZDCEnCalib object");  
308      //eCalib->Print("");
309      resEnCal = Store("Calib", "EnergyCalib", eCalib, &metaData, 0, 1);
310    }
311    else{ 
312      // if entry exists it is still valid (=1 for all runs!)
313      Log(Form(" Valid ZDC/Calib/EnergyCalib object already existing in OCDB!!!"));
314      resEnCal = kTRUE;
315    }
316    
317    if(resEnCal==kFALSE) return 6;
318
319    //
320    // *********** Tower inter-calibration
321    // --- Cheking if there is already the entry in the OCDB
322    AliCDBEntry *cdbTowEntry = GetFromOCDB("Calib", "TowerCalib");
323    if(!cdbTowEntry){   
324      AliZDCTowerCalib *towCalib = new AliZDCTowerCalib("ZDC");
325      for(Int_t j=0; j<5; j++){  
326         towCalib->SetZN1EqualCoeff(j, 1.);
327         towCalib->SetZP1EqualCoeff(j, 1.);
328         towCalib->SetZN2EqualCoeff(j, 1.);
329         towCalib->SetZP2EqualCoeff(j, 1.);  
330      }
331      //towCalib->Print("");
332      // 
333      AliCDBMetaData metaData;
334      metaData.SetBeamPeriod(0);
335      metaData.SetResponsible("Chiara Oppedisano");
336      metaData.SetComment("AliZDCTowerCalib object");  
337      //
338      resTowCal = Store("Calib", "TowerCalib", towCalib, &metaData, 0, 1);
339    }
340    else{ 
341      // if entry exists it is still valid (=1 for all runs!)
342      Log(Form(" Valid ZDC/Calib/TowerCalib object already existing in OCDB!!!"));
343      resTowCal = kTRUE;
344    }
345    
346    if(resTowCal==kFALSE) return 7;
347    
348    return 0;
349 }
350
351 //______________________________________________________________________________________________
352 UInt_t AliZDCPreprocessor::ProcessCalibData()
353 {
354   TList* daqSources = GetFileSources(kDAQ, "EMDENERGYCALIB");
355   if(!daqSources){
356     AliError(Form("No sources for CALIBRATION_EMD run %d !", fRun));
357     return 8;
358   }
359   Log("\t List of DAQ sources for EMDENERGYCALIB id: "); daqSources->Print();
360   //
361   TIter iter2(daqSources);
362   TObjString* source = 0;
363   Int_t i=0;
364   Bool_t resEnCal=kTRUE, resTowCal=kTRUE;
365   
366   while((source = dynamic_cast<TObjString*> (iter2.Next()))){
367     TString stringEMDFileName = GetFile(kDAQ, "EMDENERGYCALIB", source->GetName());
368     if(stringEMDFileName.Length() <= 0){
369       Log(Form("No file from source %s!", source->GetName()));
370       return 8;
371     }
372     const char* emdFileName = stringEMDFileName.Data();
373     Log(Form("\t Getting file #%d: %s from %s\n",++i,emdFileName,source->GetName()));
374     //
375     // --- Initializing energy calibration object
376     AliZDCEnCalib *eCalib = new AliZDCEnCalib("ZDC");
377     // --- Reading file with calibration data
378     if(emdFileName){
379       FILE *file;
380       if((file = fopen(emdFileName,"r")) == NULL){
381         printf("Cannot open file %s \n",emdFileName);
382         return 8;
383       }
384       Log(Form("File %s connected to process data from EM dissociation events", emdFileName));
385       //
386       Float_t fitValEMD[6];
387       for(Int_t j=0; j<6; j++){        
388         if(j<6){
389           int iread = fscanf(file,"%f",&fitValEMD[j]);
390           if(iread==0) AliDebug(3," Failing reading daa from EMD calibration data file");
391           eCalib->SetEnCalib(j,fitValEMD[j]);
392         }
393       }
394       //
395       fclose(file);
396     }
397     else{
398       Log(Form("File %s not found", emdFileName));
399       return 8;
400     }
401     //eCalib->Print("");
402     // 
403     AliCDBMetaData metaData;
404     metaData.SetBeamPeriod(0);
405     metaData.SetResponsible("Chiara Oppedisano");
406     metaData.SetComment("Filling AliZDCEnCalib object");  
407     //
408     resEnCal = Store("Calib","EnergyCalib",eCalib, &metaData, 0, 1);
409     if(resEnCal==kFALSE) return 6;
410   }
411   delete daqSources; daqSources = 0;
412   
413   TList* daqSourcesH = GetFileSources(kDAQ, "EMDTOWERCALIB");
414   if(!daqSourcesH){
415     AliError(Form("No sources for CALIBRATION_EMD run %d !", fRun));
416     return 9;
417   }
418   Log("\t List of DAQ sources for EMDTOWERCALIB id: "); daqSourcesH->Print();
419   //
420   TIter iter2H(daqSourcesH);
421   TObjString* sourceH = 0;
422   Int_t iH=0;
423   while((sourceH = dynamic_cast<TObjString*> (iter2H.Next()))){
424     TString stringtowEMDFileName = GetFile(kDAQ, "EMDTOWERCALIB", sourceH->GetName());
425     if(stringtowEMDFileName.Length() <= 0){
426       Log(Form("No file from source %s!", sourceH->GetName()));
427       return 9;
428     }
429     const char * towEMDFileName = stringtowEMDFileName.Data();
430     Log(Form("\t Getting file #%d: %s from source %s\n",++iH,towEMDFileName,sourceH->GetName()));
431     // --- Initializing energy calibration object
432     AliZDCTowerCalib *towCalib = new AliZDCTowerCalib("ZDC");
433     // --- Reading file with calibration data
434     if(towEMDFileName){
435       FILE *file;
436       if((file = fopen(towEMDFileName,"r")) == NULL){
437         printf("Cannot open file %s \n",towEMDFileName);
438         return 9;
439       }
440       //
441       Float_t equalCoeff[4][5];
442       for(Int_t j=0; j<4; j++){        
443          for(Int_t k=0; k<5; k++){
444            int leggi = fscanf(file,"%f",&equalCoeff[j][k]);
445            if(leggi==0) AliDebug(3," Failing reading data from EMD calibration file");
446            if(j==0)      towCalib->SetZN1EqualCoeff(k, equalCoeff[j][k]);
447            else if(j==1) towCalib->SetZP1EqualCoeff(k, equalCoeff[j][k]);
448            else if(j==2) towCalib->SetZN2EqualCoeff(k, equalCoeff[j][k]);
449            else if(j==3) towCalib->SetZP2EqualCoeff(k, equalCoeff[j][k]);  
450          }
451       }
452       //
453       fclose(file);
454     }
455     else{
456       Log(Form("File %s not found", towEMDFileName));
457       return 9;
458     }
459     //towCalib->Print("");
460     // 
461     AliCDBMetaData metaData;
462     metaData.SetBeamPeriod(0);
463     metaData.SetResponsible("Chiara Oppedisano");
464     metaData.SetComment("Filling AliZDCTowerCalib object");  
465     //
466     resTowCal = Store("Calib","TowerCalib",towCalib, &metaData, 0, 1);
467     if(resTowCal==kFALSE) return 7;
468   }
469   delete daqSourcesH; daqSourcesH = 0;
470   
471      
472   return 0;
473 }
474
475 //______________________________________________________________________________________________
476 UInt_t AliZDCPreprocessor::ProcessPedestalData()
477 {
478   TList* daqSources = GetFileSources(kDAQ, "PEDESTALDATA");
479   if(!daqSources){
480     Log(Form("No source for STANDALONE_PEDESTAL run %d !", fRun));
481     return 10;
482   }
483   if(daqSources->GetEntries()==0) return 10;
484   Log("\t List of DAQ sources for PEDESTALDATA id: "); daqSources->Print();
485   //
486   TIter iter(daqSources);
487   TObjString* source;
488   Int_t i=0;
489   Bool_t resPedCal=kTRUE, resPedHist=kTRUE;
490   
491   while((source = dynamic_cast<TObjString*> (iter.Next()))){
492      TString stringPedFileName = GetFile(kDAQ, "PEDESTALDATA", source->GetName());
493      if(stringPedFileName.Length() <= 0){
494         Log(Form("No PEDESTALDATA file from source %s!", source->GetName()));
495         return 10;
496      }
497      const char* pedFileName = stringPedFileName.Data();
498      Log(Form("\t Getting file #%d: %s from %s\n",++i,pedFileName,source->GetName()));
499      //
500      // --- Initializing pedestal calibration object
501      AliZDCPedestals *pedCalib = new AliZDCPedestals("ZDC");
502      // --- Reading file with pedestal calibration data
503      // no. ADCch = (22 signal ch. + 2 reference PMs) * 2 gain chain = 48
504      const Int_t knZDCch = 48;
505      FILE *file;
506      if((file = fopen(pedFileName,"r")) == NULL){
507        printf("Cannot open file %s \n",pedFileName);
508        return 10;
509      }
510      Log(Form("File %s connected to process pedestal data", pedFileName));
511      Float_t pedVal[(2*knZDCch)][2];
512      for(Int_t k=0; k<(2*knZDCch); k++){
513         for(Int_t j=0; j<2; j++){
514            int aleggi = fscanf(file,"%f",&pedVal[k][j]);
515            if(aleggi==0) AliDebug(3," Failing reading data from pedestal file");
516            //if(j==1) printf("pedVal[%d] -> %f, %f \n",k,pedVal[k][0],pedVal[k][1]);
517         }
518         if(k<knZDCch){
519           pedCalib->SetMeanPed(k,pedVal[k][0]);
520           pedCalib->SetMeanPedWidth(k,pedVal[k][1]);
521         }
522         else if(k>=knZDCch && k<(2*knZDCch)){
523           pedCalib->SetOOTPed(k-knZDCch,pedVal[k][0]);
524           pedCalib->SetOOTPedWidth(k-knZDCch,pedVal[k][1]);
525         }
526         else if(k>=(2*knZDCch) && k<(3*knZDCch)){
527           pedCalib->SetPedCorrCoeff(k-(2*knZDCch),pedVal[k][0],pedVal[k][1]);
528         }
529      }
530      fclose(file);
531      //pedCalib->Print("");
532      // 
533      AliCDBMetaData metaData;
534      metaData.SetBeamPeriod(0);
535      metaData.SetResponsible("Chiara Oppedisano");
536      metaData.SetComment("Filling AliZDCPedestals object");  
537      //
538      resPedCal = Store("Calib","Pedestals",pedCalib, &metaData, 0, 1);
539      if(resPedCal==kFALSE) return 11;
540   }
541   delete daqSources; daqSources = 0;
542   
543   TList* daqSourceH = GetFileSources(kDAQ, "PEDESTALHISTOS");
544   if(!daqSourceH){
545     Log(Form("No source for PEDESTALHISTOS id run %d !", fRun));
546     return 12;
547   }
548   Log("\t List of DAQ sources for PEDESTALHISTOS id: "); daqSourceH->Print();
549   //
550   TIter iterH(daqSourceH);
551   TObjString* sourceH = 0;
552   Int_t iH=0;
553   while((sourceH = dynamic_cast<TObjString*> (iterH.Next()))){
554      TString stringPedFileName = GetFile(kDAQ, "PEDESTALHISTOS", sourceH->GetName());
555      if(stringPedFileName.Length() <= 0){
556         Log(Form("No PEDESTALHISTOS file from source %s!", sourceH->GetName()));
557         return 12;
558      }
559      const char* pedFileName = stringPedFileName.Data();
560      Log(Form("\t Getting file #%d: %s from %s\n",++iH, pedFileName, sourceH->GetName()));
561      resPedHist = StoreReferenceFile(pedFileName, "pedestalReference.root");
562      if(resPedHist==kFALSE) return 13;
563   }
564   delete daqSourceH; daqSourceH=0;
565   
566   return 0;
567 }
568
569 //______________________________________________________________________________________________
570 UInt_t AliZDCPreprocessor::ProcessLaserData()
571 {
572   TList* daqSources = GetFileSources(kDAQ, "LASERDATA");
573   if(!daqSources){
574     AliError(Form("No sources for STANDALONE_LASER run %d !", fRun));
575     return 14;
576   }
577   if(daqSources->GetEntries()==0) return 14;
578   Log("\t List of DAQ sources for LASERDATA id: "); daqSources->Print();
579   //
580   TIter iter2(daqSources);
581   TObjString* source = 0;
582   Int_t i=0;
583   Bool_t resLaserCal=kTRUE, resLaserHist=kTRUE;
584   
585   while((source = dynamic_cast<TObjString*> (iter2.Next()))){
586      TString stringLaserFileName = GetFile(kDAQ, "LASERDATA", source->GetName());
587      if(stringLaserFileName.Length() <= 0){
588        Log(Form("No LASER file from source %s!", source->GetName()));
589        return 14;
590      }
591      const char* laserFileName = stringLaserFileName.Data();
592      Log(Form("\t Getting file #%d: %s from %s\n",++i,laserFileName,source->GetName()));
593      //
594      // --- Initializing pedestal calibration object
595      AliZDCLaserCalib *lCalib = new AliZDCLaserCalib("ZDC");
596      // --- Reading file with pedestal calibration data
597      if(laserFileName){
598        FILE *file;
599        if((file = fopen(laserFileName,"r")) == NULL){
600          printf("Cannot open file %s \n",laserFileName);
601          return 14;
602        }
603        Log(Form("File %s connected to process data from LASER events", laserFileName));
604        //
605        Float_t ivalRead[22][4]; 
606        for(Int_t j=0; j<22; j++){
607           for(Int_t k=0; k<4; k++){
608             int aleggi = fscanf(file,"%f",&ivalRead[j][k]);
609             if(aleggi==0) AliDebug(3," Failng reading data from laser file");
610             //printf(" %d %1.0f  ",k, ivalRead[j][k]);
611           }
612           lCalib->SetDetector(j, (Int_t) ivalRead[j][0]);
613           lCalib->SetSector(j, (Int_t) ivalRead[j][1]);
614           lCalib->SetfPMValue(j, ivalRead[j][2]);
615           lCalib->SetfPMWidth(j, ivalRead[j][3]);
616        }
617        fclose(file);
618      }
619      else{
620        Log(Form("File %s not found", laserFileName));
621        return 14;
622      }
623      //lCalib->Print("");
624      // 
625      AliCDBMetaData metaData;
626      metaData.SetBeamPeriod(0);
627      metaData.SetResponsible("Chiara Oppedisano");
628      metaData.SetComment("Filling AliZDCLaserCalib object");  
629      //
630      resLaserCal = Store("Calib","LaserCalib",lCalib, &metaData, 0, 1);
631      if(resLaserCal==kFALSE) return 15;
632   }
633   delete daqSources; daqSources = 0;
634
635   TList* daqSourceH = GetFileSources(kDAQ, "LASERHISTOS");
636   if(!daqSourceH){
637     AliError(Form("No sources for STANDALONE_LASER run %d !", fRun));
638     return 16;
639   }
640   Log("\t List of DAQ sources for LASERHISTOS id: "); daqSourceH->Print();
641   //
642   TIter iter2H(daqSourceH);
643   TObjString* sourceH = 0;
644   Int_t iH=0;
645   while((sourceH = dynamic_cast<TObjString*> (iter2H.Next()))){
646      Log(Form("\t Getting file #%d\n",++iH));
647      TString stringLaserFileName = GetFile(kDAQ, "LASERHISTOS", sourceH->GetName());
648      if(stringLaserFileName.Length() <= 0){
649        Log(Form("No LASER file from source %s!", sourceH->GetName()));
650        return 16;
651      }
652      resLaserHist = StoreReferenceFile(stringLaserFileName.Data(), "laserReference.root");
653      //
654      if(resLaserHist==kFALSE) return 17;
655   }
656   delete daqSourceH; daqSourceH = 0;
657   
658   return 0;
659 }
660
661 //______________________________________________________________________________________________
662 UInt_t AliZDCPreprocessor::Process(TMap* dcsAliasMap)
663 {
664  UInt_t resDCS = 0;
665  UInt_t resChMap=0;
666  UInt_t resEnergyCalib=0, resPedestalCalib=0, resLaserCalib=0;
667
668  // ************************* Process DCS data ****************************
669  if(ProcessDCS()) resDCS = ProcessDCSData(dcsAliasMap);
670   
671  // ********************************* From DAQ ************************************
672
673  const char* beamType = GetRunParameter("beamType");
674  TString runType = GetRunType();
675  printf("\t **** AliZDCPreprocessor -> beamType %s, runType %s ****\n",beamType,runType.Data());
676
677  // ******************************************
678  //   ADC channel mapping
679  // ******************************************
680  resChMap = ProcessChMap();
681  
682  // ******************************************
683  //   Calibration param. for p-p data (all = 1)
684  // ******************************************
685  // NO ENERGY CALIBRATION -> coefficients set to 1.
686  // Temp -> also inter-calibration coefficients are set to 1.
687  if((strcmp(beamType,"p-p")==0) || (strcmp(beamType,"P-P")==0)) resEnergyCalib = ProcessppData();
688  
689  // *****************************************************
690  //  EMD EVENTS -> Energy calibration and equalization
691  // *****************************************************
692  else if((strcmp(beamType,"A-A")==0) && (runType.CompareTo("CALIBRATION_EMD")==0)) 
693    resEnergyCalib =  ProcessCalibData();
694  
695  // *****************************************************
696  // STANDALONE_PEDESTALS -> Pedestal subtraction 
697  // *****************************************************
698  if(runType.CompareTo("STANDALONE_PEDESTAL")==0) resPedestalCalib = ProcessPedestalData();
699  
700  // *****************************************************
701  // STANDALONE_LASER -> Signal stability and ageing 
702  // *****************************************************
703  if(runType.CompareTo("STANDALONE_LASER")==0) resLaserCalib = ProcessLaserData();
704  
705
706  if(resDCS!=0)                return resDCS;
707  else if(resChMap!=0)         return resChMap;
708  else if(resEnergyCalib!=0)   return resEnergyCalib;
709  else if(resPedestalCalib!=0) return resPedestalCalib;
710  else if(resLaserCalib!=0)    return resLaserCalib;
711  
712  return 0;
713   
714 }