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