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