]> git.uio.no Git - u/mrichter/AliRoot.git/blob - TPC/AliTPCPreprocessor.cxx
Adding QA makers for digits (Marian)
[u/mrichter/AliRoot.git] / TPC / AliTPCPreprocessor.cxx
1 /**************************************************************************
2  * Copyright(c) 2007, ALICE Experiment at CERN, All rights reserved.      *
3  *                                                                        *
4  * Author: The ALICE Off-line Project.                                    *
5  * Contributors are mentioned in the code where appropriate.              *
6  *                                                                        *
7  * Permission to use, copy, modify and distribute this software and its   *
8  * documentation strictly for non-commercial purposes is hereby granted   *
9  * without fee, provided that the above copyright notice appears in all   *
10  * copies and that both the copyright notice and this permission notice   *
11  * appear in the supporting documentation. The authors make no claims     *
12  * about the suitability of this software for any purpose. It is          *
13  * provided "as is" without express or implied warranty.                  *
14  **************************************************************************/
15
16
17 #include "AliTPCPreprocessor.h"
18 #include "AliShuttleInterface.h"
19
20 #include "AliCDBMetaData.h"
21 #include "AliDCSValue.h"
22 #include "AliLog.h"
23 #include "AliTPCSensorTempArray.h"
24 #include "AliTPCROC.h"
25 #include "AliTPCCalROC.h"
26 #include "AliTPCCalPad.h"
27 #include "AliTPCCalibPedestal.h"
28 #include "AliTPCCalibPulser.h"
29 #include "AliTPCCalibCE.h"
30 #include "TFile.h"
31 #include "TTree.h"
32 #include "TEnv.h"
33
34 #include <TTimeStamp.h>
35
36 const Int_t kValCutTemp = 100;               // discard temperatures > 100 degrees
37 const Int_t kDiffCutTemp = 5;                // discard temperature differences > 5 degrees
38 const TString kPedestalRunType = "PEDESTAL_RUN";  // pedestal run identifier
39 const TString kPulserRunType = "PULSER_RUN";   // pulser run identifier
40 const TString kPhysicsRunType = "PHYSICS";   // physics run identifier
41 const TString kStandAloneRunType = "STANDALONE"; // standalone run identifier
42 const TString kDaqRunType = "DAQ"; // DAQ run identifier
43 const TString kAmandaTemp = "tpc_PT_%d.Temperature"; // Amanda string for temperature entries
44 //const Double_t kFitFraction = 0.7;                 // Fraction of DCS sensor fits required              
45 const Double_t kFitFraction = -1.0;          // Don't require minimum number of fits in commissioning run 
46
47 //
48 // This class is the SHUTTLE preprocessor for the TPC detector.
49 //
50
51 ClassImp(AliTPCPreprocessor)
52
53 //______________________________________________________________________________________________
54 AliTPCPreprocessor::AliTPCPreprocessor(AliShuttleInterface* shuttle) :
55   AliPreprocessor("TPC",shuttle),
56   fConfEnv(0), fTemp(0), fHighVoltage(0), fConfigOK(kTRUE), fROC(0)
57 {
58   // constructor
59   fROC = AliTPCROC::Instance();
60 }
61 //______________________________________________________________________________________________
62 // AliTPCPreprocessor::AliTPCPreprocessor(const AliTPCPreprocessor& org) :
63 //   AliPreprocessor(org),
64 //   fConfEnv(0), fTemp(0), fHighVoltage(0), fConfigOK(kTRUE)
65 // {
66 //   // copy constructor not implemented
67 //   //   -- missing underlying copy constructor in AliPreprocessor
68 //
69 //   Fatal("AliTPCPreprocessor", "copy constructor not implemented");
70 //
71 // //  fTemp = new AliTPCSensorTempArray(*(org.fTemp));
72 // }
73
74 //______________________________________________________________________________________________
75 AliTPCPreprocessor::~AliTPCPreprocessor()
76 {
77   // destructor
78
79   delete fTemp;
80   delete fHighVoltage;
81 }
82 //______________________________________________________________________________________________
83 AliTPCPreprocessor& AliTPCPreprocessor::operator = (const AliTPCPreprocessor& )
84 {
85   Fatal("operator =", "assignment operator not implemented");
86   return *this;
87 }
88
89
90 //______________________________________________________________________________________________
91 void AliTPCPreprocessor::Initialize(Int_t run, UInt_t startTime,
92         UInt_t endTime)
93 {
94   // Creates AliTestDataDCS object
95
96   AliPreprocessor::Initialize(run, startTime, endTime);
97
98         AliInfo(Form("\n\tRun %d \n\tStartTime %s \n\tEndTime %s", run,
99                 TTimeStamp(startTime).AsString(),
100                 TTimeStamp(endTime).AsString()));
101
102   // Preprocessor configuration
103
104         AliCDBEntry* entry = GetFromOCDB("Config", "Preprocessor");
105         if (entry) fConfEnv = (TEnv*) entry->GetObject();
106         if ( fConfEnv==0 ) {
107            Log("AliTPCPreprocsessor: Preprocessor Config OCDB entry missing.\n");
108            fConfigOK = kFALSE;
109            return;
110         }
111
112   // Temperature sensors
113
114         TTree *confTree = 0;
115         entry = GetFromOCDB("Config", "Temperature");
116         if (entry) confTree = (TTree*) entry->GetObject();
117         if ( confTree==0 ) {
118            Log("AliTPCPreprocsessor: Temperature Config OCDB entry missing.\n");
119            fConfigOK = kFALSE;
120            return;
121         }
122         fTemp = new AliTPCSensorTempArray(fStartTime, fEndTime, confTree, kAmandaTemp);
123         fTemp->SetValCut(kValCutTemp);
124         fTemp->SetDiffCut(kDiffCutTemp);
125
126
127   // High voltage measurements
128
129       if (false) {    // high voltage maps not yet implemented...
130         confTree=0;
131         entry=0;
132         entry = GetFromOCDB("Config", "HighVoltage");
133         if (entry) confTree = (TTree*) entry->GetObject();
134         if ( confTree==0 ) {
135            Log("AliTPCPreprocsessor: High Voltage Config OCDB entry missing.\n");
136            fConfigOK = kFALSE;
137            return;
138         }
139         fHighVoltage = new AliDCSSensorArray(fStartTime, fEndTime, confTree);
140       }
141 }
142
143 //______________________________________________________________________________________________
144 UInt_t AliTPCPreprocessor::Process(TMap* dcsAliasMap)
145 {
146   // Fills data into TPC calibrations objects
147
148   // Amanda servers provide information directly through dcsAliasMap
149
150   if (!dcsAliasMap) return 9;
151   if (dcsAliasMap->GetEntries() == 0 ) return 9;
152   if (!fConfigOK) return 9;
153
154   TString runType = GetRunType();
155
156   // Temperature sensors are processed by AliTPCCalTemp
157
158
159   UInt_t tempResult = MapTemperature(dcsAliasMap);
160   UInt_t result=tempResult;
161
162   // High Voltage recordings
163
164
165  if (false) {   // High Voltage maps not yet implemented..
166  
167   UInt_t hvResult = MapHighVoltage(dcsAliasMap);
168   result+=hvResult;
169
170  }
171
172   // Other calibration information will be retrieved through FXS files
173   //  examples:
174   //    TList* fileSourcesDAQ = GetFile(AliShuttleInterface::kDAQ, "pedestals");
175   //    const char* fileNamePed = GetFile(AliShuttleInterface::kDAQ, "pedestals", "LDC1");
176   //
177   //    TList* fileSourcesHLT = GetFile(AliShuttleInterface::kHLT, "calib");
178   //    const char* fileNameHLT = GetFile(AliShuttleInterface::kHLT, "calib", "LDC1");
179
180   // pedestal entries
181
182   if(runType == kPedestalRunType) {
183     Int_t numSources = 1;
184     Int_t pedestalSource[2] = {AliShuttleInterface::kDAQ,AliShuttleInterface::kHLT} ;
185     TString source = fConfEnv->GetValue("Pedestal","DAQ");
186     source.ToUpper();
187     if ( source == "HLT") pedestalSource[0] = AliShuttleInterface::kHLT;
188     if (!GetHLTStatus()) pedestalSource[0] = AliShuttleInterface::kDAQ;
189     if (source == "HLTDAQ" ) {
190         numSources=2;
191         pedestalSource[0] = AliShuttleInterface::kHLT;
192         pedestalSource[1] = AliShuttleInterface::kDAQ;
193     }
194     if (source == "DAQHLT" ) numSources=2;
195     UInt_t pedestalResult=0;
196     for (Int_t i=0; i<numSources; i++ ) {       
197       UInt_t pedestalResult = ExtractPedestals(pedestalSource[i]);
198       if ( pedestalResult == 0 ) break;
199     }
200     result += pedestalResult;
201
202   }
203
204   // pulser trigger processing
205
206   if(runType == kPulserRunType) {
207     Int_t numSources = 1;
208     Int_t pulserSource[2] = {AliShuttleInterface::kDAQ,AliShuttleInterface::kHLT} ;
209     TString source = fConfEnv->GetValue("Pulser","DAQ");
210     source.ToUpper();
211     if ( source == "HLT") pulserSource[0] = AliShuttleInterface::kHLT;
212     if (!GetHLTStatus()) pulserSource[0] = AliShuttleInterface::kDAQ;
213     if (source == "HLTDAQ" ) {
214         numSources=2;
215         pulserSource[0] = AliShuttleInterface::kHLT;
216         pulserSource[1] = AliShuttleInterface::kDAQ;
217     }
218     if (source == "DAQHLT" ) numSources=2;
219     UInt_t pulserResult=0;
220     for (Int_t i=0; i<numSources; i++ ) {       
221       pulserResult = ExtractPulser(pulserSource[i]);
222       if ( pulserResult == 0 ) break;
223     }
224     result += pulserResult;
225
226   }
227
228
229
230   // Central Electrode processing
231
232   if( runType == kPhysicsRunType || runType == kStandAloneRunType || 
233       runType == kDaqRunType ) {    
234
235     Int_t numSources = 1;
236     Int_t ceSource[2] = {AliShuttleInterface::kDAQ,AliShuttleInterface::kHLT} ;
237     TString source = fConfEnv->GetValue("CE","DAQ");
238     source.ToUpper();
239     if ( source == "HLT") ceSource[0] = AliShuttleInterface::kHLT;
240     if (!GetHLTStatus()) ceSource[0] = AliShuttleInterface::kDAQ;
241     if (source == "HLTDAQ" ) {
242         numSources=2;
243         ceSource[0] = AliShuttleInterface::kHLT;
244         ceSource[1] = AliShuttleInterface::kDAQ;
245     }
246     if (source == "DAQHLT" ) numSources=2;
247     UInt_t ceResult=0;
248     for (Int_t i=0; i<numSources; i++ ) {       
249       ceResult = ExtractCE(ceSource[i]);
250       if ( ceResult == 0 ) break;
251     }
252     result += ceResult;
253
254   }
255
256   return result;
257 }
258 //______________________________________________________________________________________________
259 UInt_t AliTPCPreprocessor::MapTemperature(TMap* dcsAliasMap)
260 {
261
262    // extract DCS temperature maps. Perform fits to save space
263
264   UInt_t result=0;
265   TMap *map = fTemp->ExtractDCS(dcsAliasMap);
266   if (map) {
267     fTemp->MakeSplineFit(map);
268     Double_t fitFraction = 1.0*fTemp->NumFits()/fTemp->NumSensors(); 
269     if (fitFraction > kFitFraction ) {
270       AliInfo(Form("Temperature values extracted, fits performed.\n"));
271     } else { 
272       Log ("Too few temperature maps fitted. \n");
273       result = 9;
274     }
275   } else {
276     Log("No temperature map extracted. \n");
277     result=9;
278   }
279   delete map;
280   // Now store the final CDB file
281
282   if ( result == 0 ) {
283         AliCDBMetaData metaData;
284         metaData.SetBeamPeriod(0);
285         metaData.SetResponsible("Haavard Helstrup");
286         metaData.SetComment("Preprocessor AliTPC data base entries.");
287
288         Bool_t storeOK = Store("Calib", "Temperature", fTemp, &metaData, 0, kFALSE);
289         if ( !storeOK )  result=1;
290
291    }
292
293    return result;
294
295 }
296
297 //______________________________________________________________________________________________
298 UInt_t AliTPCPreprocessor::MapHighVoltage(TMap* dcsAliasMap)
299 {
300
301    // extract DCS HV maps. Perform fits to save space
302
303   UInt_t result=0;
304   TMap *map = fHighVoltage->ExtractDCS(dcsAliasMap);
305   if (map) {
306     fHighVoltage->MakeSplineFit(map);
307     Double_t fitFraction = 1.0*fHighVoltage->NumFits()/fHighVoltage->NumSensors(); 
308     if (fitFraction > kFitFraction ) {
309       AliInfo(Form("High volatge recordings extracted, fits performed.\n"));
310     } else { 
311       Log ("Too few high voltage recordings fitted. \n");
312       result = 9;
313     }
314   } else {
315     Log("No high voltage recordings extracted. \n");
316     result=9;
317   }
318   delete map;
319   // Now store the final CDB file
320
321   if ( result == 0 ) {
322         AliCDBMetaData metaData;
323         metaData.SetBeamPeriod(0);
324         metaData.SetResponsible("Haavard Helstrup");
325         metaData.SetComment("Preprocessor AliTPC data base entries.");
326
327         Bool_t storeOK = Store("Calib", "HighVoltage", fHighVoltage, &metaData, 0, kFALSE);
328         if ( !storeOK )  result=1;
329
330    }
331
332    return result;
333
334 }
335
336
337 //______________________________________________________________________________________________
338
339 UInt_t AliTPCPreprocessor::ExtractPedestals(Int_t sourceFXS)
340 {
341  //
342  //  Read pedestal file from file exchage server
343  //  Keep original entry from OCDB in case no new pedestals are available
344  //
345  AliTPCCalPad *calPadPed=0;
346  AliCDBEntry* entry = GetFromOCDB("Calib", "Pedestals");
347  if (entry) calPadPed = (AliTPCCalPad*)entry->GetObject();
348  if ( calPadPed==NULL ) {
349      Log("AliTPCPreprocsessor: No previous TPC pedestal entry available.\n");
350      calPadPed = new AliTPCCalPad("PedestalsMean","PedestalsMean");
351  }
352
353  AliTPCCalPad *calPadRMS=0;
354  entry = GetFromOCDB("Calib", "Noise");
355  if (entry) calPadRMS = (AliTPCCalPad*)entry->GetObject();
356  if ( calPadRMS==NULL ) {
357      Log("AliTPCPreprocsessor: No previous TPC noise entry available.\n");
358      calPadRMS = new AliTPCCalPad("PedestalsRMS","PedestalsRMS");
359  }
360
361
362  UInt_t result=0;
363
364  Int_t nSectors = fROC->GetNSectors();
365  TList* list = GetFileSources(sourceFXS,"pedestals");
366  
367  if (list && list->GetEntries()>0) {
368
369 //  loop through all files from LDCs
370
371     Bool_t changed=false;
372     UInt_t index = 0;
373     while (list->At(index)!=NULL) {
374      TObjString* fileNameEntry = (TObjString*) list->At(index);
375      if (fileNameEntry!=NULL) {
376         TString fileName = GetFile(sourceFXS, "pedestals",
377                                          fileNameEntry->GetString().Data());
378         TFile *f = TFile::Open(fileName);
379         if (!f) {
380           Log ("Error opening pedestal file.");
381           result =2;
382           break;
383         }
384         AliTPCCalibPedestal *calPed;
385         f->GetObject("AliTPCCalibPedestal",calPed);
386         if ( !calPed ) {
387           Log ("No pedestal calibration object in file.");
388           result = 2;
389           break;
390         }
391
392         //  replace entries for the sectors available in the present file
393
394         changed=true;
395         for (Int_t sector=0; sector<nSectors; sector++) {
396            AliTPCCalROC *rocPed=calPed->GetCalRocPedestal(sector, kFALSE);
397            if ( rocPed )  calPadPed->SetCalROC(rocPed,sector);
398            AliTPCCalROC *rocRMS=calPed->GetCalRocRMS(sector, kFALSE);
399            if ( rocRMS )  calPadRMS->SetCalROC(rocRMS,sector);
400         }
401       }
402      ++index;
403     }  // while(list)
404 //
405 //  Store updated pedestal entry to OCDB
406 //
407     if (changed) {
408      AliCDBMetaData metaData;
409      metaData.SetBeamPeriod(0);
410      metaData.SetResponsible("Haavard Helstrup");
411      metaData.SetComment("Preprocessor AliTPC data base entries."); 
412  
413      Bool_t storeOK = Store("Calib", "Pedestals", calPadPed, &metaData, 0, kTRUE);
414      if ( !storeOK ) ++result;
415      storeOK = Store("Calib", "PadNoise", calPadRMS, &metaData, 0, kTRUE);
416      if ( !storeOK ) ++result;
417     }
418   } else {
419     Log ("Error: no entries in input file list!");
420     result = 1;
421   }
422
423   return result;
424 }
425
426 //______________________________________________________________________________________________
427
428
429 UInt_t AliTPCPreprocessor::ExtractPulser(Int_t sourceFXS)
430 {
431  //
432  //  Read pulser calibration file from file exchage server
433  //  Keep original entry from OCDB in case no new pulser calibration is available
434  //
435  TObjArray    *pulserObjects=0;
436  AliTPCCalPad *pulserTmean=0;
437  AliTPCCalPad *pulserTrms=0;
438  AliTPCCalPad *pulserQmean=0;
439  AliCDBEntry* entry = GetFromOCDB("Calib", "Pulser");
440  if (entry) pulserObjects = (TObjArray*)entry->GetObject();
441  if ( pulserObjects==NULL ) {
442      Log("AliTPCPreprocsessor: No previous TPC pulser entry available.\n");
443      pulserObjects = new TObjArray;    
444  }
445
446  pulserTmean = (AliTPCCalPad*)pulserObjects->FindObject("PulserTmean");
447  if ( !pulserTmean ) {
448     pulserTmean = new AliTPCCalPad("PulserTmean","PulserTmean");
449     pulserObjects->Add(pulserTmean);
450  }
451  pulserTrms = (AliTPCCalPad*)pulserObjects->FindObject("PulserTrms");
452  if ( !pulserTrms )  { 
453     pulserTrms = new AliTPCCalPad("PulserTrms","PulserTrms");
454     pulserObjects->Add(pulserTrms);
455  }
456  pulserQmean = (AliTPCCalPad*)pulserObjects->FindObject("PulserQmean");
457  if ( !pulserQmean )  { 
458     pulserQmean = new AliTPCCalPad("PulserQmean","PulserQmean");
459     pulserObjects->Add(pulserQmean);
460  }
461
462
463  UInt_t result=0;
464
465  Int_t nSectors = fROC->GetNSectors();
466  TList* list = GetFileSources(sourceFXS,"pulser");
467  
468  if (list && list->GetEntries()>0) {
469
470 //  loop through all files from LDCs
471
472     Bool_t changed=false;
473     UInt_t index = 0;
474     while (list->At(index)!=NULL) {
475      TObjString* fileNameEntry = (TObjString*) list->At(index);
476      if (fileNameEntry!=NULL) {
477         TString fileName = GetFile(sourceFXS, "pulser",
478                                          fileNameEntry->GetString().Data());
479         TFile *f = TFile::Open(fileName);
480         if (!f) {
481           Log ("Error opening pulser file.");
482           result =2;
483           break;
484         }
485         AliTPCCalibPulser *calPulser;
486         f->GetObject("AliTPCCalibPulser",calPulser);
487         if ( !calPulser ) {
488           Log ("No pulser calibration object in file.");
489           result = 2;
490           break;
491         }
492
493         //  replace entries for the sectors available in the present file
494
495         changed=true;
496         for (Int_t sector=0; sector<nSectors; sector++) {
497            AliTPCCalROC *rocTmean=calPulser->GetCalRocT0(sector);
498            if ( rocTmean )  pulserTmean->SetCalROC(rocTmean,sector);
499            AliTPCCalROC *rocTrms=calPulser->GetCalRocRMS(sector);
500            if ( rocTrms )  pulserTrms->SetCalROC(rocTrms,sector);
501            AliTPCCalROC *rocQmean=calPulser->GetCalRocQ(sector);
502            if ( rocQmean )  pulserQmean->SetCalROC(rocQmean,sector);
503         }
504       }
505      ++index;
506     }  // while(list)
507 //
508 //  Store updated pedestal entry to OCDB
509 //
510     if (changed) {
511      AliCDBMetaData metaData;
512      metaData.SetBeamPeriod(0);
513      metaData.SetResponsible("Haavard Helstrup");
514      metaData.SetComment("Preprocessor AliTPC data base entries.");
515
516      Bool_t storeOK = Store("Calib", "Pulser", pulserObjects, &metaData, 0, kTRUE);
517      if ( !storeOK ) ++result;
518     }  
519   } else {
520     Log ("Error: no entries in input file list!");
521     result = 1;
522   }
523
524   return result;
525 }
526
527 UInt_t AliTPCPreprocessor::ExtractCE(Int_t sourceFXS)
528 {
529  //
530  //  Read Central Electrode file from file exchage server
531  //  Keep original entry from OCDB in case no new CE calibration is available
532  //
533  TObjArray    *ceObjects=0;
534  AliTPCCalPad *ceTmean=0;
535  AliTPCCalPad *ceTrms=0;
536  AliTPCCalPad *ceQmean=0;
537  AliCDBEntry* entry = GetFromOCDB("Calib", "CE");
538  if (entry) ceObjects = (TObjArray*)entry->GetObject();
539  if ( ceObjects==NULL ) {
540      Log("AliTPCPreprocsessor: No previous TPC central electrode entry available.\n");
541      ceObjects = new TObjArray;    
542  }
543
544  ceTmean = (AliTPCCalPad*)ceObjects->FindObject("CETmean");
545  if ( !ceTmean ) {
546     ceTmean = new AliTPCCalPad("CETmean","CETmean");
547     ceObjects->Add(ceTmean);
548  }
549  ceTrms = (AliTPCCalPad*)ceObjects->FindObject("CETrms");
550  if ( !ceTrms )  { 
551     ceTrms = new AliTPCCalPad("CETrms","CETrms");
552     ceObjects->Add(ceTrms);
553  }
554  ceQmean = (AliTPCCalPad*)ceObjects->FindObject("CEQmean");
555  if ( !ceQmean )  { 
556     ceQmean = new AliTPCCalPad("CEQmean","CEQmean");
557     ceObjects->Add(ceQmean);
558  }
559
560
561  UInt_t result=0;
562
563  Int_t nSectors = fROC->GetNSectors();
564  TList* list = GetFileSources(sourceFXS,"CE");
565  
566  if (list && list->GetEntries()>0) {
567
568 //  loop through all files from LDCs
569
570     UInt_t index = 0;
571     while (list->At(index)!=NULL) {
572      TObjString* fileNameEntry = (TObjString*) list->At(index);
573      if (fileNameEntry!=NULL) {
574         TString fileName = GetFile(sourceFXS, "CE",
575                                          fileNameEntry->GetString().Data());
576         TFile *f = TFile::Open(fileName);
577         if (!f) {
578           Log ("Error opening central electrode file.");
579           result =2;
580           break;
581         }
582         AliTPCCalibCE *calCE;
583         f->GetObject("AliTPCCalibCE",calCE);
584
585         //  replace entries for the sectors available in the present file
586
587         for (Int_t sector=0; sector<nSectors; sector++) {
588            AliTPCCalROC *rocTmean=calCE->GetCalRocT0(sector);
589            if ( rocTmean )  ceTmean->SetCalROC(rocTmean,sector);
590            AliTPCCalROC *rocTrms=calCE->GetCalRocRMS(sector);
591            if ( rocTrms )  ceTrms->SetCalROC(rocTrms,sector);
592            AliTPCCalROC *rocQmean=calCE->GetCalRocQ(sector);
593            if ( rocQmean )  ceQmean->SetCalROC(rocQmean,sector);
594         }
595       }
596      ++index;
597     }  // while(list)
598 //
599 //  Store updated pedestal entry to OCDB
600 //
601     AliCDBMetaData metaData;
602     metaData.SetBeamPeriod(0);
603     metaData.SetResponsible("Haavard Helstrup");
604     metaData.SetComment("Preprocessor AliTPC data base entries.");
605
606     Bool_t storeOK = Store("Calib", "CE", ceObjects, &metaData, 0, kTRUE);
607     if ( !storeOK ) ++result;
608     
609   } else {
610     Log ("Error: no entries!");
611     result = 1;
612   }
613
614   return result;
615 }