Change in comment
[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"
0d579f58 22#include "AliZDCMBCalib.h"
27d1ff1f 23#include "AliZDCTDCCalib.h"
64a7c78d 24
d5e687c2 25/////////////////////////////////////////////////////////////////////
26// //
73bc3a3f 27// Class implementing Shuttle ZDC pre-processor. //
28// It takes data from DCS and DAQ and writes calibration objects //
29// in the OCDB and reference values/histos in the ReferenceData. //
d5e687c2 30// //
31/////////////////////////////////////////////////////////////////////
64a7c78d 32
e83c8d88 33// ******************************************************************
34// RETURN CODES:
da2b6160 35// return 0 : everything OK
36// return 1 : no DCS input data Map
37// return 2 : error storing DCS data in RefData
38// return 3 : error storing alignment object in OCDB
39// return 4 : error in ZDCMapping.dat file retrieved from DAQ FXS (not existing|empty|corrupted)
40// return 5 : error storing mapping obj. in OCDB
41// return 6 : error storing energy calibration obj. in OCDB
42// return 7 : error storing tower inter-calibration obj. in OCDB
43// return 8 : error in ZDCEnergyCalib.dat file retrieved from DAQ FXS
44// return 9 : error in ZDCTowerCalib.dat file retrieved from DAQ FXS
45// return 10: error in ZDCPedestal.dat file retrieved from DAQ FXS
46// return 11: error storing pedestal calibration obj. in OCDB
47// return 12: error in ZDCPedHisto.root file retrieved from DAQ FXS
48// return 13: error storing pedestal histos in RefData
49// return 14: error in ZDCLaserCalib.dat file retrieved from DAQ FXS
50// return 15: error storing laser calibration obj. in OCDB
51// return 16: error in ZDCLaserHisto.root file retrieved from DAQ FXS
52// return 17: error storing laser histos in RefData
0d579f58 53// return 18: error in ZDCMBCalib.root file retrieved from DAQ FXS
54// return 19: error storing MB calibration obj. in OCDB
27d1ff1f 55// return 20: error in ZDCTDCCalib.root file retrieved from DAQ FXS
56// return 21: error in storing TDC calibration obj. in OCDB
57// return 22: error in ZDCTDCHisto.root file retrieved from DAQ FXS
58// Return 23: error storing TDC reference histos in RefData
e83c8d88 59// ******************************************************************
60
64a7c78d 61ClassImp(AliZDCPreprocessor)
62
63//______________________________________________________________________________________________
857ece97 64AliZDCPreprocessor::AliZDCPreprocessor(AliShuttleInterface* shuttle) :
65 AliPreprocessor("ZDC", shuttle),
64a7c78d 66 fData(0)
67{
68 // constructor
b8d194f5 69 // May 2009 - run types updated according to
70 // http://alice-ecs.web.cern.ch/alice-ecs/runtypes_3.36.html
cbf06263 71 AddRunType("STANDALONE_PEDESTAL");
1ee299a5 72 AddRunType("STANDALONE_LASER");
321fe3b8 73 AddRunType("STANDALONE_COSMIC");
b8d194f5 74 AddRunType("CALIBRATION_EMD");
75 AddRunType("CALIBRATION_MB");
76 AddRunType("CALIBRATION_CENTRAL");
77 AddRunType("CALIBRATION_SEMICENTRAL");
78 AddRunType("CALIBRATION_BC");
321fe3b8 79 AddRunType("PHYSICS");
64a7c78d 80}
81
cbf06263 82
64a7c78d 83//______________________________________________________________________________________________
84AliZDCPreprocessor::~AliZDCPreprocessor()
85{
86 // destructor
87}
88
7a78280f 89
64a7c78d 90//______________________________________________________________________________________________
da2b6160 91void AliZDCPreprocessor::Initialize(Int_t run, UInt_t startTime, UInt_t endTime)
64a7c78d 92{
93 // Creates AliZDCDataDCS object
94
95 AliPreprocessor::Initialize(run, startTime, endTime);
96
57c85e6e 97 AliDebug(2,Form("\n\tRun %d \n\tStartTime %s \n\tEndTime %s \n\tStartTime DCS Query %s \n\tEndTime DCS Query %s", run,
e83c8d88 98 TTimeStamp(startTime).AsString(),
99 TTimeStamp(endTime).AsString(), ((TTimeStamp)GetStartTimeDCSQuery()).AsString(), ((TTimeStamp)GetEndTimeDCSQuery()).AsString()));
64a7c78d 100
73bc3a3f 101 fRun = run;
102 fStartTime = startTime;
103 fEndTime = endTime;
79563ba1 104
e83c8d88 105 fData = new AliZDCDataDCS(fRun, fStartTime, fEndTime, GetStartTimeDCSQuery(), GetEndTimeDCSQuery());
106}
107
108//_____________________________________________________________________________
109Bool_t AliZDCPreprocessor::ProcessDCS(){
110
111 // tells whether DCS should be processed or not
112
113 TString runType = GetRunType();
114 Log(Form("RunType %s",runType.Data()));
115
116 if (runType=="STANDALONE_COSMIC" || runType=="STANDALONE_PEDESTAL"){
117 return kFALSE;
118 }
119
120 return kTRUE;
121}
122
123//______________________________________________________________________________________________
124UInt_t AliZDCPreprocessor::ProcessDCSData(TMap* dcsAliasMap)
125{
126
127 // Fills data into a AliZDCDataDCS object
bf867209 128 if(!dcsAliasMap){
129 Log(" No DCS map found: ZDC exiting from Shuttle");
57c85e6e 130 if(fData){
131 delete fData;
132 fData = 0;
133 }
bf867209 134 return 1;
135 }
136
e83c8d88 137 Log(Form("Processing data from DCS"));
bf867209 138
e83c8d88 139 // The processing of the DCS input data is forwarded to AliZDCDataDCS
e83c8d88 140 //dcsAliasMap->Print("");
bf867209 141 Bool_t resDCSProcess = fData->ProcessData(*dcsAliasMap);
142 if(resDCSProcess==kFALSE){
143 Log(" Problems in processing DCS DP");
144 return 1;
57c85e6e 145 }
e83c8d88 146
0d579f58 147 // ------------------------------------------------------
148 // Change introduced 26/9/09 in order NOT to process the
149 // HV DP since some of them are never found in amanda DB
150 // ------------------------------------------------------
57c85e6e 151 // Store DCS data as reference
aee13a2d 152 AliCDBMetaData metadata;
e83c8d88 153 metadata.SetResponsible("Chiara Oppedisano");
57c85e6e 154 metadata.SetComment("DCS DP TMap for ZDC");
e83c8d88 155 Bool_t resDCSRef = kTRUE;
57c85e6e 156 resDCSRef = StoreReferenceData("DCS","Data", dcsAliasMap, &metadata);
e83c8d88 157
158 if(resDCSRef==kFALSE) return 2;
aee13a2d 159
e83c8d88 160 // --- Writing ZDC table positions into alignment object
161 TClonesArray *array = new TClonesArray("AliAlignObjParams",10);
162 TClonesArray &alobj = *array;
163 AliAlignObjParams a;
164 Double_t dx=0., dz=0., dpsi=0., dtheta=0., dphi=0.;
165 // Vertical table position in mm from DCS
57c85e6e 166 Double_t dyZN1 = (Double_t) (fData->GetAlignData(0)/10.);
167 Double_t dyZP1 = (Double_t) (fData->GetAlignData(1)/10.);
168 Double_t dyZN2 = (Double_t) (fData->GetAlignData(2)/10.);
169 Double_t dyZP2 = (Double_t) (fData->GetAlignData(3)/10.);
e83c8d88 170 //
171 const char *n1ZDC="ZDC/NeutronZDC_C";
172 const char *p1ZDC="ZDC/ProtonZDC_C";
173 const char *n2ZDC="ZDC/NeutronZDC_A";
174 const char *p2ZDC="ZDC/ProtonZDC_A";
175 //
176 UShort_t iIndex=0;
177 AliGeomManager::ELayerID iLayer = AliGeomManager::kInvalidLayer;
178 UShort_t volid = AliGeomManager::LayerToVolUID(iLayer,iIndex);
179 //
180 new(alobj[0]) AliAlignObjParams(n1ZDC, volid, dx, dyZN1, dz, dpsi, dtheta, dphi, kTRUE);
181 new(alobj[1]) AliAlignObjParams(p1ZDC, volid, dx, dyZP1, dz, dpsi, dtheta, dphi, kTRUE);
182 new(alobj[2]) AliAlignObjParams(n2ZDC, volid, dx, dyZN2, dz, dpsi, dtheta, dphi, kTRUE);
183 new(alobj[3]) AliAlignObjParams(p2ZDC, volid, dx, dyZP2, dz, dpsi, dtheta, dphi, kTRUE);
184
185 // save in CDB storage
186 AliCDBMetaData mdDCS;
187 mdDCS.SetResponsible("Chiara Oppedisano");
188 mdDCS.SetComment("Alignment object for ZDC");
1a1c78d4 189 Bool_t resultAl = Store("Align","Data", array, &mdDCS, 0, kFALSE);
e83c8d88 190 if(resultAl==kFALSE) return 3;
191
192 return 0;
64a7c78d 193}
194
195//______________________________________________________________________________________________
da2b6160 196UInt_t AliZDCPreprocessor::ProcessChMap()
321fe3b8 197{
82dffa48 198 const int kNModules=10, kNch=48, kNScch=32, kNtdcch=32;
e83c8d88 199
3c159ed0 200 // Reading the file for mapping from FXS
da2b6160 201 TList* daqSource = GetFileSources(kDAQ, "MAPPING");
321fe3b8 202 if(!daqSource){
da2b6160 203 AliError(Form("No sources for file ZDCChMapping.dat in run %d ", fRun));
e83c8d88 204 return 4;
321fe3b8 205 }
da2b6160 206 if(daqSource->GetEntries()==0) return 4;
207 Log("\t List of DAQ sources for MAPPING id: "); daqSource->Print();
321fe3b8 208 //
209 TIter iter(daqSource);
210 TObjString* source = 0;
b8d194f5 211 Int_t isou = 0;
82dffa48 212 Int_t modMap[kNModules][3], adcMap[kNch][6], scMap[kNScch][6], tdcMap[kNtdcch][4];
3c159ed0 213 //
321fe3b8 214 while((source = dynamic_cast<TObjString*> (iter.Next()))){
92508ce2 215 TString fileName = GetFile(kDAQ, "MAPPING", source->GetName());
da2b6160 216 Log(Form("\t Getting file #%d: ZDCChMapping.dat from %s\n",++isou, source->GetName()));
321fe3b8 217
218 if(fileName.Length() <= 0){
219 Log(Form("No file from source %s!", source->GetName()));
e83c8d88 220 return 4;
321fe3b8 221 }
c00e895a 222 // --- Reading file with calibration data
223 //const char* fname = fileName.Data();
224 if(fileName){
321fe3b8 225 FILE *file;
c00e895a 226 if((file = fopen(fileName,"r")) == NULL){
227 printf("Cannot open file %s \n",fileName.Data());
e83c8d88 228 return 4;
321fe3b8 229 }
c00e895a 230 Log(Form("File %s connected to process data for ADC mapping", fileName.Data()));
321fe3b8 231 //
608444fb 232 for(Int_t j=0; j<kNch; j++){
233 for(Int_t k=0; k<6; k++){
234 int read = fscanf(file,"%d",&adcMap[j][k]);
198f612a 235 if(read == 0) AliDebug(3," Failing in reading data from mapping file");
236 }
237 }
608444fb 238 for(Int_t j=kNch; j<kNch+kNScch; j++){
198f612a 239 for(Int_t k=0; k<6; k++){
608444fb 240 int read = fscanf(file,"%d",&scMap[j-kNch][k]);
198f612a 241 if(read == 0) AliDebug(3," Failing in reading data from mapping file");
242 }
243 }
82dffa48 244 for(Int_t j=kNch+kNScch; j<kNch+kNScch+kNtdcch; j++){
245 for(Int_t k=0; k<4; k++){
246 int read = fscanf(file,"%d",&tdcMap[j-kNch-kNScch][k]);
247 if(read == 0) AliDebug(3," Failing in reading data from mapping file");
248 }
249 }
250 for(Int_t j=kNch+kNScch+kNtdcch; j<kNch+kNScch+kNtdcch+kNModules; j++){
608444fb 251 for(Int_t k=0; k<3; k++){
82dffa48 252 int read = fscanf(file,"%d",&modMap[j-kNch-kNScch-kNtdcch][k]);
e83c8d88 253 if(read == 0) AliDebug(3," Failing in reading data from mapping file");
321fe3b8 254 }
321fe3b8 255 }
256 fclose(file);
257 }
258 else{
c00e895a 259 Log(Form("File %s not found", fileName.Data()));
e83c8d88 260 return 4;
321fe3b8 261 }
3c159ed0 262 }
3c159ed0 263
264 // Store the currently read map ONLY IF it is different
265 // from the entry in the OCDB
82dffa48 266 Bool_t adcMapUpdated=kFALSE, scMapUpdated=kFALSE, tdcMapUpdated=kFALSE;
3c159ed0 267 Bool_t updateOCDB = kFALSE;
268
269 AliCDBEntry *cdbEntry = GetFromOCDB("Calib","ChMap");
270 if(!cdbEntry){
73bc3a3f 271 Log(" No existing CDB entry for ADC mapping");
3c159ed0 272 updateOCDB = kTRUE;
273 }
274 else{
275 AliZDCChMap *chMap = (AliZDCChMap*) cdbEntry->GetObject();
e83c8d88 276 for(Int_t i=0; i<kNch; i++){
ba3ffd74 277 if( (adcMap[i][1] != chMap->GetADCModule(i))
278 || (adcMap[i][2] != chMap->GetADCChannel(i))
216a94dd 279 || (adcMap[i][3] != chMap->GetADCSignalCode(i))
ba3ffd74 280 || (adcMap[i][4] != chMap->GetDetector(i))
281 || (adcMap[i][5] != chMap->GetSector(i)))
282 adcMapUpdated = kTRUE;
198f612a 283 }
284 for(Int_t i=0; i<kNScch; i++){
ba3ffd74 285 if( (scMap[i][2] != chMap->GetScChannel(i))
216a94dd 286 || (scMap[i][3] != chMap->GetScSignalCode(i)) )
ba3ffd74 287 scMapUpdated = kTRUE;
3c159ed0 288 }
82dffa48 289 for(Int_t i=0; i<kNtdcch; i++){
290 if( (tdcMap[i][2] != chMap->GetTDCChannel(i))
291 || (tdcMap[i][3] != chMap->GetTDCSignalCode(i)))
292 tdcMapUpdated = kTRUE;
293 }
3c159ed0 294 }
82dffa48 295 if(adcMapUpdated || scMapUpdated || tdcMapUpdated) updateOCDB = kTRUE;
0d579f58 296 //
e83c8d88 297 Bool_t resChMapStore = kTRUE;
3c159ed0 298 if(updateOCDB==kTRUE){
73bc3a3f 299 Log(" A new entry ZDC/Calib/ChMap will be created");
3c159ed0 300 //
301 // --- Initializing mapping calibration object
302 AliZDCChMap *mapCalib = new AliZDCChMap("ZDC");
303 // Writing channel map in the OCDB
198f612a 304 for(Int_t k=0; k<kNModules; k++){
305 mapCalib->SetModuleMap(k, modMap[k][0], modMap[k][1], modMap[k][2]);
306 }
e83c8d88 307 for(Int_t k=0; k<kNch; k++){
198f612a 308 mapCalib->SetADCModule(k,adcMap[k][1]);
309 mapCalib->SetADCChannel(k,adcMap[k][2]);
82dffa48 310 mapCalib->SetADCSignalCode(k,adcMap[k][3]);
198f612a 311 mapCalib->SetDetector(k,adcMap[k][4]);
312 mapCalib->SetSector(k,adcMap[k][5]);
313 }
314 for(Int_t k=0; k<kNScch; k++){
7d1d8256 315 mapCalib->SetScChannel(k, scMap[k][2]);
82dffa48 316 mapCalib->SetScSignalCode(k, scMap[k][3]);
7d1d8256 317 mapCalib->SetScDetector(k, scMap[k][4]);
318 mapCalib->SetScSector(k, scMap[k][5]);
3c159ed0 319 }
82dffa48 320 for(Int_t k=0; k<kNtdcch; k++){
321 mapCalib->SetTDCChannel(k, tdcMap[k][2]);
322 mapCalib->SetTDCSignalCode(k, tdcMap[k][3]);
323 }
198f612a 324 //
216a94dd 325 //mapCalib->Print("");
321fe3b8 326 //
327 AliCDBMetaData metaData;
328 metaData.SetBeamPeriod(0);
198f612a 329 metaData.SetResponsible("Chiara Oppedisano");
82dffa48 330 metaData.SetComment("AliZDCChMap object created by ZDC preprocessor");
321fe3b8 331 //
1a1c78d4 332 resChMapStore = Store("Calib","ChMap",mapCalib, &metaData, 0, kTRUE);
333 printf(" Mapping object stored in OCDB\n");
321fe3b8 334 }
3c159ed0 335 else{
73bc3a3f 336 Log(" ZDC/Calib/ChMap entry in OCDB is valid and won't be updated");
e83c8d88 337 resChMapStore = kTRUE;
3c159ed0 338 }
aee13a2d 339 delete daqSource; daqSource=0;
4fbf0a09 340
341 TString runType = GetRunType();
342 if(runType.CompareTo("PHYSICS")==0){
343 Log(Form("RunType %s -> producing TDC calibration data",runType.Data()));
344
345 // Reading the file for mapping from FXS
346 TList* daqSourcetdc = GetFileSources(kDAQ, "TDCDATA");
347 if(!daqSourcetdc){
348 AliError(Form("No sources for file ZDCChMappingTDCCalib.dat in run %d ", fRun));
349 return 20;
350 }
351 if(daqSourcetdc->GetEntries()==0) return 20;
352 Log("\t List of DAQ sources for TDCDATA id: "); daqSourcetdc->Print();
353 //
354 Bool_t resTDCcal = kTRUE;
355 TIter itertdc(daqSourcetdc);
356 TObjString* sourcetdc = 0;
357 Int_t isoutdc = 0;
358 //
359 while((sourcetdc = dynamic_cast<TObjString*> (itertdc.Next()))){
27d1ff1f 360 TString fileNametdc = GetFile(kDAQ, "TDCDATA", sourcetdc->GetName());
361 Log(Form("\t Getting file #%d: ZDCTDCdata.dat from %s\n",++isoutdc, sourcetdc->GetName()));
362
363 if(fileNametdc.Length() <= 0){
364 Log(Form("No file from source %s!", sourcetdc->GetName()));
365 return 20;
366 }
367 // --- Initializing TDC calibration object
368 AliZDCTDCCalib *tdcCalib = new AliZDCTDCCalib("ZDC");
369 // --- Reading file with calibration data
370 //const char* fname = fileName.Data();
371 if(fileNametdc){
372 FILE *filetdc;
373 if((filetdc = fopen(fileNametdc,"r")) == NULL){
374 printf("Cannot open file %s \n",fileNametdc.Data());
375 return 20;
376 }
377 Log(Form("File %s connected to process TDC data", fileNametdc.Data()));
378 //
379 Float_t tdcMean[6][2];
380 for(Int_t it=0; it<6; it++){
381 for(Int_t iu=0; iu<2; iu++) tdcMean[it][iu]=0.;
382 }
383 for(Int_t k=0; k<6; k++){
384 for(Int_t j=0; j<2; j++){
385 int leggi = fscanf(filetdc,"%f",&tdcMean[k][j]);
386 if(leggi==0) AliDebug(3," Failing reading data from tdc file");
387 tdcCalib->SetMeanTDC(k, tdcMean[k][0]);
388 tdcCalib->SetWidthTDC(k, tdcMean[k][1]);
389 }
390 }
391 fclose(filetdc);
392 }
393 else{
394 Log(Form("File %s not found", fileNametdc.Data()));
395 return 20;
396 }
397 //
398 AliCDBMetaData metaData;
399 metaData.SetBeamPeriod(0);
400 metaData.SetResponsible("Chiara Oppedisano");
401 metaData.SetComment("Filling AliZDCTDCCalib object");
402 //
403 resTDCcal = Store("Calib","TDCCalib",tdcCalib, &metaData, 0, kTRUE);
404 if(resTDCcal==kFALSE) return 21;
4fbf0a09 405 }
406 delete daqSourcetdc; daqSourcetdc = 0;
27d1ff1f 407
4fbf0a09 408 Bool_t restdcHist = kTRUE;
409 TList* daqSourceH = GetFileSources(kDAQ, "TDCHISTOS");
410 if(!daqSourceH){
411 Log(Form("No source for TDCHISTOS id run %d !", fRun));
412 return 22;
413 }
414 Log("\t List of DAQ sources for TDCHISTOS id: "); daqSourceH->Print();
415 //
416 TIter iterH(daqSourceH);
417 TObjString* sourceH = 0;
418 Int_t iH=0;
419 while((sourceH = dynamic_cast<TObjString*> (iterH.Next()))){
27d1ff1f 420 TString stringTDCFileName = GetFile(kDAQ, "TDCHISTOS", sourceH->GetName());
421 if(stringTDCFileName.Length() <= 0){
422 Log(Form("No TDCHISTOS file from source %s!", sourceH->GetName()));
423 return 22;
424 }
425 const char* tdcFileName = stringTDCFileName.Data();
426 Log(Form("\t Getting file #%d: %s from %s\n",++iH, tdcFileName, sourceH->GetName()));
427 restdcHist = StoreReferenceFile(tdcFileName, "tdcReference.root");
428 if(restdcHist==kFALSE) return 23;
4fbf0a09 429 }
430 delete daqSourceH; daqSourceH=0;
27d1ff1f 431 }
6f427255 432
4fbf0a09 433 if(resChMapStore==kFALSE) return 5;
434 else return 0;
321fe3b8 435
436}
437
438//______________________________________________________________________________________________
e83c8d88 439UInt_t AliZDCPreprocessor::ProcessppData()
64a7c78d 440{
e83c8d88 441 Bool_t resEnCal=kTRUE, resTowCal=kTRUE;
79563ba1 442
73bc3a3f 443 // *********** Energy calibration
3c159ed0 444 // --- Cheking if there is already the entry in the OCDB
5df9f417 445 AliCDBEntry *cdbEnEntry = GetFromOCDB("Calib", "EnergyCalib");
73bc3a3f 446 if(!cdbEnEntry){
dd98e862 447 Log(Form(" ZDC/Calib/EnergyCalib entry will be created"));
3c159ed0 448 // --- Initializing calibration object
73bc3a3f 449 AliCDBMetaData metaData;
450 metaData.SetBeamPeriod(0);
451 metaData.SetResponsible("Chiara Oppedisano");
3c159ed0 452 //
73bc3a3f 453 AliZDCEnCalib *eCalib = new AliZDCEnCalib("ZDC");
3c159ed0 454 for(Int_t j=0; j<6; j++) eCalib->SetEnCalib(j,1.);
73bc3a3f 455 metaData.SetComment("AliZDCEnCalib object");
456 //eCalib->Print("");
1a1c78d4 457 resEnCal = Store("Calib", "EnergyCalib", eCalib, &metaData, 0, kTRUE);
73bc3a3f 458 }
459 else{
460 // if entry exists it is still valid (=1 for all runs!)
dd98e862 461 Log(Form(" Valid ZDC/Calib/EnergyCalib object already existing in OCDB!!!"));
73bc3a3f 462 resEnCal = kTRUE;
463 }
e83c8d88 464
465 if(resEnCal==kFALSE) return 6;
466
73bc3a3f 467 //
468 // *********** Tower inter-calibration
469 // --- Cheking if there is already the entry in the OCDB
5df9f417 470 AliCDBEntry *cdbTowEntry = GetFromOCDB("Calib", "TowerCalib");
73bc3a3f 471 if(!cdbTowEntry){
472 AliZDCTowerCalib *towCalib = new AliZDCTowerCalib("ZDC");
3c159ed0 473 for(Int_t j=0; j<5; j++){
73bc3a3f 474 towCalib->SetZN1EqualCoeff(j, 1.);
475 towCalib->SetZP1EqualCoeff(j, 1.);
476 towCalib->SetZN2EqualCoeff(j, 1.);
477 towCalib->SetZP2EqualCoeff(j, 1.);
3c159ed0 478 }
73bc3a3f 479 //towCalib->Print("");
480 //
481 AliCDBMetaData metaData;
482 metaData.SetBeamPeriod(0);
483 metaData.SetResponsible("Chiara Oppedisano");
484 metaData.SetComment("AliZDCTowerCalib object");
485 //
1a1c78d4 486 resTowCal = Store("Calib", "TowerCalib", towCalib, &metaData, 0, kTRUE);
73bc3a3f 487 }
488 else{
489 // if entry exists it is still valid (=1 for all runs!)
dd98e862 490 Log(Form(" Valid ZDC/Calib/TowerCalib object already existing in OCDB!!!"));
73bc3a3f 491 resTowCal = kTRUE;
492 }
493
e83c8d88 494 if(resTowCal==kFALSE) return 7;
495
496 return 0;
497}
498
499//______________________________________________________________________________________________
2c62f191 500UInt_t AliZDCPreprocessor::ProcessCalibData(Float_t beamEnergy)
e83c8d88 501{
da2b6160 502 TList* daqSources = GetFileSources(kDAQ, "EMDENERGYCALIB");
e83c8d88 503 if(!daqSources){
504 AliError(Form("No sources for CALIBRATION_EMD run %d !", fRun));
da2b6160 505 return 8;
e83c8d88 506 }
da2b6160 507 Log("\t List of DAQ sources for EMDENERGYCALIB id: "); daqSources->Print();
e83c8d88 508 //
509 TIter iter2(daqSources);
510 TObjString* source = 0;
511 Int_t i=0;
da2b6160 512 Bool_t resEnCal=kTRUE, resTowCal=kTRUE;
513
e83c8d88 514 while((source = dynamic_cast<TObjString*> (iter2.Next()))){
da2b6160 515 TString stringEMDFileName = GetFile(kDAQ, "EMDENERGYCALIB", source->GetName());
e83c8d88 516 if(stringEMDFileName.Length() <= 0){
517 Log(Form("No file from source %s!", source->GetName()));
da2b6160 518 return 8;
e83c8d88 519 }
da2b6160 520 const char* emdFileName = stringEMDFileName.Data();
521 Log(Form("\t Getting file #%d: %s from %s\n",++i,emdFileName,source->GetName()));
522 //
e83c8d88 523 // --- Initializing energy calibration object
524 AliZDCEnCalib *eCalib = new AliZDCEnCalib("ZDC");
da2b6160 525 // --- Reading file with calibration data
e83c8d88 526 if(emdFileName){
527 FILE *file;
528 if((file = fopen(emdFileName,"r")) == NULL){
da2b6160 529 printf("Cannot open file %s \n",emdFileName);
530 return 8;
e83c8d88 531 }
532 Log(Form("File %s connected to process data from EM dissociation events", emdFileName));
533 //
534 Float_t fitValEMD[6];
535 for(Int_t j=0; j<6; j++){
da2b6160 536 if(j<6){
537 int iread = fscanf(file,"%f",&fitValEMD[j]);
c1ae51a3 538 if(iread==0) AliDebug(3," Failing reading data from EMD calibration data file");
539 if(fitValEMD[j]!=1.) eCalib->SetEnCalib(j, beamEnergy/fitValEMD[j]);
540 else eCalib->SetEnCalib(j, fitValEMD[j]);
da2b6160 541 }
e83c8d88 542 }
543 //
544 fclose(file);
545 }
546 else{
547 Log(Form("File %s not found", emdFileName));
da2b6160 548 return 8;
e83c8d88 549 }
550 //eCalib->Print("");
551 //
552 AliCDBMetaData metaData;
553 metaData.SetBeamPeriod(0);
554 metaData.SetResponsible("Chiara Oppedisano");
555 metaData.SetComment("Filling AliZDCEnCalib object");
556 //
1a1c78d4 557 resEnCal = Store("Calib","EnergyCalib",eCalib, &metaData, 0, kTRUE);
e83c8d88 558 if(resEnCal==kFALSE) return 6;
559 }
560 delete daqSources; daqSources = 0;
da2b6160 561
562 TList* daqSourcesH = GetFileSources(kDAQ, "EMDTOWERCALIB");
e83c8d88 563 if(!daqSourcesH){
564 AliError(Form("No sources for CALIBRATION_EMD run %d !", fRun));
da2b6160 565 return 9;
e83c8d88 566 }
da2b6160 567 Log("\t List of DAQ sources for EMDTOWERCALIB id: "); daqSourcesH->Print();
e83c8d88 568 //
569 TIter iter2H(daqSourcesH);
570 TObjString* sourceH = 0;
571 Int_t iH=0;
e83c8d88 572 while((sourceH = dynamic_cast<TObjString*> (iter2H.Next()))){
da2b6160 573 TString stringtowEMDFileName = GetFile(kDAQ, "EMDTOWERCALIB", sourceH->GetName());
574 if(stringtowEMDFileName.Length() <= 0){
e83c8d88 575 Log(Form("No file from source %s!", sourceH->GetName()));
da2b6160 576 return 9;
e83c8d88 577 }
da2b6160 578 const char * towEMDFileName = stringtowEMDFileName.Data();
579 Log(Form("\t Getting file #%d: %s from source %s\n",++iH,towEMDFileName,sourceH->GetName()));
e83c8d88 580 // --- Initializing energy calibration object
581 AliZDCTowerCalib *towCalib = new AliZDCTowerCalib("ZDC");
da2b6160 582 // --- Reading file with calibration data
583 if(towEMDFileName){
e83c8d88 584 FILE *file;
da2b6160 585 if((file = fopen(towEMDFileName,"r")) == NULL){
586 printf("Cannot open file %s \n",towEMDFileName);
587 return 9;
e83c8d88 588 }
e83c8d88 589 //
590 Float_t equalCoeff[4][5];
591 for(Int_t j=0; j<4; j++){
da2b6160 592 for(Int_t k=0; k<5; k++){
593 int leggi = fscanf(file,"%f",&equalCoeff[j][k]);
594 if(leggi==0) AliDebug(3," Failing reading data from EMD calibration file");
595 if(j==0) towCalib->SetZN1EqualCoeff(k, equalCoeff[j][k]);
596 else if(j==1) towCalib->SetZP1EqualCoeff(k, equalCoeff[j][k]);
597 else if(j==2) towCalib->SetZN2EqualCoeff(k, equalCoeff[j][k]);
598 else if(j==3) towCalib->SetZP2EqualCoeff(k, equalCoeff[j][k]);
599 }
e83c8d88 600 }
601 //
602 fclose(file);
603 }
604 else{
da2b6160 605 Log(Form("File %s not found", towEMDFileName));
606 return 9;
e83c8d88 607 }
608 //towCalib->Print("");
609 //
610 AliCDBMetaData metaData;
611 metaData.SetBeamPeriod(0);
612 metaData.SetResponsible("Chiara Oppedisano");
613 metaData.SetComment("Filling AliZDCTowerCalib object");
614 //
1a1c78d4 615 resTowCal = Store("Calib","TowerCalib",towCalib, &metaData, 0, kTRUE);
e83c8d88 616 if(resTowCal==kFALSE) return 7;
617 }
da2b6160 618 delete daqSourcesH; daqSourcesH = 0;
e83c8d88 619
da2b6160 620
e83c8d88 621 return 0;
622}
623
624//______________________________________________________________________________________________
625UInt_t AliZDCPreprocessor::ProcessPedestalData()
626{
73bc3a3f 627 TList* daqSources = GetFileSources(kDAQ, "PEDESTALDATA");
cb50c7c8 628 if(!daqSources){
78e8a1cc 629 Log(Form("No source for STANDALONE_PEDESTAL run %d !", fRun));
da2b6160 630 return 10;
79563ba1 631 }
da2b6160 632 if(daqSources->GetEntries()==0) return 10;
633 Log("\t List of DAQ sources for PEDESTALDATA id: "); daqSources->Print();
79563ba1 634 //
cb50c7c8 635 TIter iter(daqSources);
da2b6160 636 TObjString* source;
79563ba1 637 Int_t i=0;
da2b6160 638 Bool_t resPedCal=kTRUE, resPedHist=kTRUE;
639
cb50c7c8 640 while((source = dynamic_cast<TObjString*> (iter.Next()))){
73bc3a3f 641 TString stringPedFileName = GetFile(kDAQ, "PEDESTALDATA", source->GetName());
642 if(stringPedFileName.Length() <= 0){
da2b6160 643 Log(Form("No PEDESTALDATA file from source %s!", source->GetName()));
644 return 10;
73bc3a3f 645 }
da2b6160 646 const char* pedFileName = stringPedFileName.Data();
647 Log(Form("\t Getting file #%d: %s from %s\n",++i,pedFileName,source->GetName()));
648 //
e83c8d88 649 // --- Initializing pedestal calibration object
650 AliZDCPedestals *pedCalib = new AliZDCPedestals("ZDC");
651 // --- Reading file with pedestal calibration data
e83c8d88 652 // no. ADCch = (22 signal ch. + 2 reference PMs) * 2 gain chain = 48
653 const Int_t knZDCch = 48;
e83c8d88 654 FILE *file;
655 if((file = fopen(pedFileName,"r")) == NULL){
656 printf("Cannot open file %s \n",pedFileName);
da2b6160 657 return 10;
e83c8d88 658 }
659 Log(Form("File %s connected to process pedestal data", pedFileName));
796c8b58 660 Float_t pedVal[(3*knZDCch)][2];
93d32e24 661 for(Int_t k=0; k<(3*knZDCch); k++){
da2b6160 662 for(Int_t j=0; j<2; j++){
663 int aleggi = fscanf(file,"%f",&pedVal[k][j]);
664 if(aleggi==0) AliDebug(3," Failing reading data from pedestal file");
665 //if(j==1) printf("pedVal[%d] -> %f, %f \n",k,pedVal[k][0],pedVal[k][1]);
666 }
667 if(k<knZDCch){
668 pedCalib->SetMeanPed(k,pedVal[k][0]);
669 pedCalib->SetMeanPedWidth(k,pedVal[k][1]);
670 }
671 else if(k>=knZDCch && k<(2*knZDCch)){
672 pedCalib->SetOOTPed(k-knZDCch,pedVal[k][0]);
673 pedCalib->SetOOTPedWidth(k-knZDCch,pedVal[k][1]);
674 }
675 else if(k>=(2*knZDCch) && k<(3*knZDCch)){
676 pedCalib->SetPedCorrCoeff(k-(2*knZDCch),pedVal[k][0],pedVal[k][1]);
677 }
e83c8d88 678 }
679 fclose(file);
680 //pedCalib->Print("");
681 //
682 AliCDBMetaData metaData;
683 metaData.SetBeamPeriod(0);
684 metaData.SetResponsible("Chiara Oppedisano");
685 metaData.SetComment("Filling AliZDCPedestals object");
686 //
1a1c78d4 687 resPedCal = Store("Calib","Pedestals",pedCalib, &metaData, 0, kTRUE);
da2b6160 688 if(resPedCal==kFALSE) return 11;
64a7c78d 689 }
cb50c7c8 690 delete daqSources; daqSources = 0;
da2b6160 691
692 TList* daqSourceH = GetFileSources(kDAQ, "PEDESTALHISTOS");
73bc3a3f 693 if(!daqSourceH){
da2b6160 694 Log(Form("No source for PEDESTALHISTOS id run %d !", fRun));
695 return 12;
73bc3a3f 696 }
da2b6160 697 Log("\t List of DAQ sources for PEDESTALHISTOS id: "); daqSourceH->Print();
73bc3a3f 698 //
699 TIter iterH(daqSourceH);
700 TObjString* sourceH = 0;
701 Int_t iH=0;
702 while((sourceH = dynamic_cast<TObjString*> (iterH.Next()))){
da2b6160 703 TString stringPedFileName = GetFile(kDAQ, "PEDESTALHISTOS", sourceH->GetName());
73bc3a3f 704 if(stringPedFileName.Length() <= 0){
da2b6160 705 Log(Form("No PEDESTALHISTOS file from source %s!", sourceH->GetName()));
706 return 12;
73bc3a3f 707 }
da2b6160 708 const char* pedFileName = stringPedFileName.Data();
709 Log(Form("\t Getting file #%d: %s from %s\n",++iH, pedFileName, sourceH->GetName()));
710 resPedHist = StoreReferenceFile(pedFileName, "pedestalReference.root");
711 if(resPedHist==kFALSE) return 13;
73bc3a3f 712 }
da2b6160 713 delete daqSourceH; daqSourceH=0;
e83c8d88 714
715 return 0;
716}
717
718//______________________________________________________________________________________________
719UInt_t AliZDCPreprocessor::ProcessLaserData()
720{
73bc3a3f 721 TList* daqSources = GetFileSources(kDAQ, "LASERDATA");
1ee299a5 722 if(!daqSources){
723 AliError(Form("No sources for STANDALONE_LASER run %d !", fRun));
da2b6160 724 return 14;
1ee299a5 725 }
da2b6160 726 if(daqSources->GetEntries()==0) return 14;
727 Log("\t List of DAQ sources for LASERDATA id: "); daqSources->Print();
1ee299a5 728 //
729 TIter iter2(daqSources);
730 TObjString* source = 0;
731 Int_t i=0;
da2b6160 732 Bool_t resLaserCal=kTRUE, resLaserHist=kTRUE;
733
1ee299a5 734 while((source = dynamic_cast<TObjString*> (iter2.Next()))){
da2b6160 735 TString stringLaserFileName = GetFile(kDAQ, "LASERDATA", source->GetName());
736 if(stringLaserFileName.Length() <= 0){
73bc3a3f 737 Log(Form("No LASER file from source %s!", source->GetName()));
da2b6160 738 return 14;
73bc3a3f 739 }
da2b6160 740 const char* laserFileName = stringLaserFileName.Data();
741 Log(Form("\t Getting file #%d: %s from %s\n",++i,laserFileName,source->GetName()));
742 //
73bc3a3f 743 // --- Initializing pedestal calibration object
744 AliZDCLaserCalib *lCalib = new AliZDCLaserCalib("ZDC");
745 // --- Reading file with pedestal calibration data
73bc3a3f 746 if(laserFileName){
747 FILE *file;
748 if((file = fopen(laserFileName,"r")) == NULL){
749 printf("Cannot open file %s \n",laserFileName);
da2b6160 750 return 14;
1ee299a5 751 }
73bc3a3f 752 Log(Form("File %s connected to process data from LASER events", laserFileName));
1ee299a5 753 //
73bc3a3f 754 Float_t ivalRead[22][4];
755 for(Int_t j=0; j<22; j++){
da2b6160 756 for(Int_t k=0; k<4; k++){
757 int aleggi = fscanf(file,"%f",&ivalRead[j][k]);
758 if(aleggi==0) AliDebug(3," Failng reading data from laser file");
73bc3a3f 759 //printf(" %d %1.0f ",k, ivalRead[j][k]);
760 }
761 lCalib->SetDetector(j, (Int_t) ivalRead[j][0]);
762 lCalib->SetSector(j, (Int_t) ivalRead[j][1]);
763 lCalib->SetfPMValue(j, ivalRead[j][2]);
764 lCalib->SetfPMWidth(j, ivalRead[j][3]);
765 }
766 fclose(file);
767 }
768 else{
769 Log(Form("File %s not found", laserFileName));
da2b6160 770 return 14;
73bc3a3f 771 }
772 //lCalib->Print("");
773 //
774 AliCDBMetaData metaData;
775 metaData.SetBeamPeriod(0);
776 metaData.SetResponsible("Chiara Oppedisano");
777 metaData.SetComment("Filling AliZDCLaserCalib object");
778 //
1a1c78d4 779 resLaserCal = Store("Calib","LaserCalib",lCalib, &metaData, 0, kTRUE);
da2b6160 780 if(resLaserCal==kFALSE) return 15;
1ee299a5 781 }
73bc3a3f 782 delete daqSources; daqSources = 0;
da2b6160 783
73bc3a3f 784 TList* daqSourceH = GetFileSources(kDAQ, "LASERHISTOS");
785 if(!daqSourceH){
786 AliError(Form("No sources for STANDALONE_LASER run %d !", fRun));
da2b6160 787 return 16;
73bc3a3f 788 }
da2b6160 789 Log("\t List of DAQ sources for LASERHISTOS id: "); daqSourceH->Print();
73bc3a3f 790 //
791 TIter iter2H(daqSourceH);
792 TObjString* sourceH = 0;
793 Int_t iH=0;
794 while((sourceH = dynamic_cast<TObjString*> (iter2H.Next()))){
da2b6160 795 Log(Form("\t Getting file #%d\n",++iH));
796 TString stringLaserFileName = GetFile(kDAQ, "LASERHISTOS", sourceH->GetName());
797 if(stringLaserFileName.Length() <= 0){
73bc3a3f 798 Log(Form("No LASER file from source %s!", sourceH->GetName()));
da2b6160 799 return 16;
73bc3a3f 800 }
da2b6160 801 resLaserHist = StoreReferenceFile(stringLaserFileName.Data(), "laserReference.root");
e83c8d88 802 //
da2b6160 803 if(resLaserHist==kFALSE) return 17;
73bc3a3f 804 }
805 delete daqSourceH; daqSourceH = 0;
e83c8d88 806
807 return 0;
808}
809
0d579f58 810
811//______________________________________________________________________________________________
812UInt_t AliZDCPreprocessor::ProcessMBCalibData()
813{
814 TList* daqSources = GetFileSources(kDAQ, "MBCALIB");
815 if(!daqSources){
816 AliError(Form("No sources for CALIBRATION_MB run %d !", fRun));
817 return 18;
818 }
819 if(daqSources->GetEntries()==0) return 18;
820 Log("\t List of DAQ sources for MBCALIB id: "); daqSources->Print();
821 //
822 TIter iter2(daqSources);
823 TObjString* source = 0;
824 Int_t i=0;
825 Bool_t resMBCal=kTRUE;
826
827 while((source = dynamic_cast<TObjString*> (iter2.Next()))){
828 TString stringMBFileName = GetFile(kDAQ, "MBCALIB", source->GetName());
829 if(stringMBFileName.Length() <= 0){
830 Log(Form("No MBCALIB file from source %s!", source->GetName()));
831 return 18;
832 }
833 const char* mbFileName = stringMBFileName.Data();
834 Log(Form("\t Getting file #%d: %s from %s\n",++i,mbFileName,source->GetName()));
835 //
836 // --- Initializing calibration object
837 AliZDCMBCalib *mbCalib = new AliZDCMBCalib("ZDC");
838 // --- Reading file with calibration data
839 if(mbFileName){
840 TFile * fileHistos = TFile::Open(mbFileName);
841 Log(Form("File %s connected to process data from CALIBRATION_MB events", mbFileName));
842 //
843 fileHistos->cd();
844 TH2F *hZDCvsZEM = (TH2F*) fileHistos->Get("hZDCvsZEM");
845 TH2F *hZDCCvsZEM = (TH2F*) fileHistos->Get("hZDCCvsZEM");
846 TH2F *hZDCAvsZEM = (TH2F*) fileHistos->Get("hZDCAvsZEM");
847 //
848 mbCalib->SetZDCvsZEM(hZDCvsZEM);
849 mbCalib->SetZDCCvsZEM(hZDCCvsZEM);
850 mbCalib->SetZDCAvsZEM(hZDCAvsZEM);
851 //
852 //fileHistos->Close();
853 }
854 else{
855 Log(Form("File %s not found", mbFileName));
856 return 14;
857 }
858 //
859 AliCDBMetaData metaData;
860 metaData.SetBeamPeriod(0);
861 metaData.SetResponsible("Chiara Oppedisano");
862 metaData.SetComment("Filling AliZDCMBCalib object");
863 //
864 //mbCalib->Dump();
865 //
866 resMBCal = Store("Calib","MBCalib",mbCalib, &metaData, 0, kTRUE);
867 printf(" here 1000\n");
868 if(resMBCal==kFALSE) return 19;
869 }
870 delete daqSources; daqSources = 0;
871
872 return 0;
873}
874
e83c8d88 875//______________________________________________________________________________________________
876UInt_t AliZDCPreprocessor::Process(TMap* dcsAliasMap)
877{
878 UInt_t resDCS = 0;
879 UInt_t resChMap=0;
0d579f58 880 UInt_t resEnergyCalib=0, resPedestalCalib=0, resLaserCalib=0, resMBCalib=0;
e83c8d88 881
882 // ************************* Process DCS data ****************************
883 if(ProcessDCS()) resDCS = ProcessDCSData(dcsAliasMap);
884
885 // ********************************* From DAQ ************************************
886
887 const char* beamType = GetRunParameter("beamType");
888 TString runType = GetRunType();
2c62f191 889 Float_t beamEnergy = (Float_t)(((TString)GetRunParameter("beamEnergy")).Atof());
890 printf("\t **** AliZDCPreprocessor -> runType %s, beamType %s, beamEnergy %1.0f ****\n",
891 runType.Data(),beamType,beamEnergy);
e83c8d88 892
893 // ******************************************
0d579f58 894 // ADC channel mapping
e83c8d88 895 // ******************************************
da2b6160 896 resChMap = ProcessChMap();
e83c8d88 897
898 // ******************************************
0d579f58 899 // Calibration param. for p-p data (all = 1)
e83c8d88 900 // ******************************************
901 // NO ENERGY CALIBRATION -> coefficients set to 1.
902 // Temp -> also inter-calibration coefficients are set to 1.
f3ce44c3 903 if((strcmp(beamType,"p-p")==0) || (strcmp(beamType,"P-P")==0)
904 || (strcmp(beamType,"P-A")==0) || (strcmp(beamType,"A-P")==0))
905 resEnergyCalib = ProcessppData();
e83c8d88 906
b8d194f5 907 // *****************************************************
0d579f58 908 // CALIBRATION_EMD -> Energy calibration and equalization
b8d194f5 909 // *****************************************************
0d579f58 910 if((strcmp(beamType,"A-A")==0) && (runType.CompareTo("CALIBRATION_EMD")==0))
2c62f191 911 resEnergyCalib = ProcessCalibData(beamEnergy);
e83c8d88 912
913 // *****************************************************
914 // STANDALONE_PEDESTALS -> Pedestal subtraction
915 // *****************************************************
da2b6160 916 if(runType.CompareTo("STANDALONE_PEDESTAL")==0) resPedestalCalib = ProcessPedestalData();
e83c8d88 917
918 // *****************************************************
919 // STANDALONE_LASER -> Signal stability and ageing
920 // *****************************************************
0d579f58 921 else if(runType.CompareTo("STANDALONE_LASER")==0) resLaserCalib = ProcessLaserData();
922
923 // *****************************************************
924 // CALIBRATION_MB -> Signal stability and ageing
925 // *****************************************************
926 else if(runType.CompareTo("CALIBRATION_MB")==0) resMBCalib = ProcessMBCalibData();
e83c8d88 927
e83c8d88 928 if(resDCS!=0) return resDCS;
929 else if(resChMap!=0) return resChMap;
930 else if(resEnergyCalib!=0) return resEnergyCalib;
931 else if(resPedestalCalib!=0) return resPedestalCalib;
932 else if(resLaserCalib!=0) return resLaserCalib;
0d579f58 933 else if(resMBCalib!=0) return resMBCalib;
79563ba1 934
e83c8d88 935 return 0;
cb50c7c8 936
64a7c78d 937}