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