]> git.uio.no Git - u/mrichter/AliRoot.git/blob - TPC/AliTPCPreprocessor.cxx
Updated flags for low flux case (A. Dainese)
[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 "AliTPCdataQA.h"
31 #include "TFile.h"
32 #include "TTree.h"
33 #include "TGraph.h" 
34 #include "TEnv.h"
35 #include "TParameter.h"
36
37 #include <TTimeStamp.h>
38
39 const Int_t kValCutTemp = 100;               // discard temperatures > 100 degrees
40 const Int_t kDiffCutTemp = 5;                // discard temperature differences > 5 degrees
41 const TString kPedestalRunType = "PEDESTAL";  // pedestal run identifier
42 const TString kPulserRunType = "CALIBRATION_PULSER";   // pulser run identifier
43 const TString kPhysicsRunType = "PHYSICS";   // physics run identifier
44 const TString kStandAloneRunType = "STANDALONE"; // standalone run identifier
45 const TString kStandAlonePulserRunType = "STANDALONE_PULSER"; // standalone run identifier
46 const TString kCosmicRunType = "COSMIC"; // cosmic run identifier
47 const TString kLaserRunType = "LASER";   // laser run identifier
48 const TString kDaqRunType = "DAQ"; // DAQ run identifier
49 const TString kAmandaTemp = "TPC_PT_%d_TEMPERATURE"; // Amanda string for temperature entries
50 //const Double_t kFitFraction = 0.7;                 // Fraction of DCS sensor fits required              
51 const Double_t kFitFraction = -1.0;          // Don't require minimum number of fits in commissioning run 
52
53 //
54 // This class is the SHUTTLE preprocessor for the TPC detector.
55 //
56
57 ClassImp(AliTPCPreprocessor)
58
59 //______________________________________________________________________________________________
60 AliTPCPreprocessor::AliTPCPreprocessor(AliShuttleInterface* shuttle) :
61   AliPreprocessor("TPC",shuttle),
62   fConfEnv(0), fTemp(0), fHighVoltage(0), fHighVoltageStat(0), fGoofie(0), fConfigOK(kTRUE), fROC(0)
63 {
64   // constructor
65   fROC = AliTPCROC::Instance();
66
67   // define run types to be processed
68   
69   AddRunType(kPedestalRunType);
70   AddRunType(kPulserRunType);
71   AddRunType(kPhysicsRunType);
72   AddRunType(kStandAloneRunType);
73   AddRunType(kStandAlonePulserRunType);
74   AddRunType(kCosmicRunType);
75   AddRunType(kLaserRunType);
76   AddRunType(kDaqRunType);
77   
78 }
79 //______________________________________________________________________________________________
80  AliTPCPreprocessor::AliTPCPreprocessor(const AliTPCPreprocessor&  ) :
81    AliPreprocessor("TPC",0),
82    fConfEnv(0), fTemp(0), fHighVoltage(0), fHighVoltageStat(0), fGoofie(0), fConfigOK(kTRUE), fROC(0)
83  {
84
85    Fatal("AliTPCPreprocessor", "copy constructor not implemented");
86 //
87 // //  fTemp = new AliTPCSensorTempArray(*(org.fTemp));
88  }
89
90 //______________________________________________________________________________________________
91 AliTPCPreprocessor::~AliTPCPreprocessor()
92 {
93   // destructor
94
95   delete fTemp;
96   delete fHighVoltage;
97 }
98 //______________________________________________________________________________________________
99 AliTPCPreprocessor& AliTPCPreprocessor::operator = (const AliTPCPreprocessor& )
100 {
101   Fatal("operator =", "assignment operator not implemented");
102   return *this;
103 }
104
105
106 //______________________________________________________________________________________________
107 void AliTPCPreprocessor::Initialize(Int_t run, UInt_t startTime,
108         UInt_t endTime)
109 {
110   // Creates AliTestDataDCS object -- start maps half an hour beforre actual run start
111
112   UInt_t startTimeLocal = startTime-3600;
113   UInt_t endTimeLocal = endTime+1800;
114
115   AliPreprocessor::Initialize(run, startTimeLocal, endTimeLocal);
116
117         AliInfo(Form("\n\tRun %d \n\tStartTime %s \n\tEndTime %s", run,
118                 TTimeStamp((time_t)startTime,0).AsString(),
119                 TTimeStamp((time_t)endTime,0).AsString()));
120
121   // Preprocessor configuration
122
123         AliCDBEntry* entry = GetFromOCDB("Config", "Preprocessor");
124         if (entry) fConfEnv = (TEnv*) entry->GetObject();
125         if ( fConfEnv==0 ) {
126            Log("AliTPCPreprocsessor: Preprocessor Config OCDB entry missing.\n");
127            fConfigOK = kFALSE;
128            return;
129         }
130
131   // Temperature sensors
132
133        TTree *confTree = 0;
134
135        TString tempConf = fConfEnv->GetValue("Temperature","ON");
136        tempConf.ToUpper();
137        if (tempConf != "OFF" ) {
138         entry = GetFromOCDB("Config", "Temperature");
139         if (entry) confTree = (TTree*) entry->GetObject();
140         if ( confTree==0 ) {
141            Log("AliTPCPreprocsessor: Temperature Config OCDB entry missing.\n");
142            fConfigOK = kFALSE;
143            return;
144         }
145         fTemp = new AliTPCSensorTempArray(startTimeLocal, endTimeLocal, confTree, kAmandaTemp);
146         fTemp->SetValCut(kValCutTemp);
147         fTemp->SetDiffCut(kDiffCutTemp);
148        }
149
150   // High voltage measurements
151
152       TString hvConf = fConfEnv->GetValue("HighVoltage","ON");
153       hvConf.ToUpper();
154       if (hvConf != "OFF" ) { 
155         confTree=0;
156         entry=0;
157         entry = GetFromOCDB("Config", "HighVoltage");
158         if (entry) confTree = (TTree*) entry->GetObject();
159         if ( confTree==0 ) {
160            Log("AliTPCPreprocsessor: High Voltage Config OCDB entry missing.\n");
161            fConfigOK = kFALSE;
162            return;
163         }
164         fHighVoltage = new AliDCSSensorArray(startTimeLocal, endTimeLocal, confTree);
165       }
166
167    // High voltage status values
168      
169       TString hvStatConf = fConfEnv->GetValue("HighVoltageStat","ON");
170       hvStatConf.ToUpper();
171       if (hvStatConf != "OFF" ) { 
172         confTree=0;
173         entry=0;
174         entry = GetFromOCDB("Config", "HighVoltageStat");
175         if (entry) confTree = (TTree*) entry->GetObject();
176         if ( confTree==0 ) {
177            Log("AliTPCPreprocsessor: High Voltage Status Config OCDB entry missing.\n");
178            fConfigOK = kFALSE;
179            return;
180         }
181         fHighVoltageStat = new AliDCSSensorArray(startTimeLocal, endTimeLocal, confTree);
182       }
183
184    // Goofie values
185      
186       TString goofieConf = fConfEnv->GetValue("Goofie","ON");
187       goofieConf.ToUpper();
188       if (goofieConf != "OFF" ) { 
189         confTree=0;
190         entry=0;
191         entry = GetFromOCDB("Config", "Goofie");
192         if (entry) confTree = (TTree*) entry->GetObject();
193         if ( confTree==0 ) {
194            Log("AliTPCPreprocsessor: Goofie Config OCDB entry missing.\n");
195            fConfigOK = kFALSE;
196            return;
197         }
198         fGoofie = new AliDCSSensorArray(startTimeLocal, endTimeLocal, confTree);
199       }
200
201
202 }
203
204 //______________________________________________________________________________________________
205 UInt_t AliTPCPreprocessor::Process(TMap* dcsAliasMap)
206 {
207   // Fills data into TPC calibrations objects
208
209   // Amanda servers provide information directly through dcsAliasMap
210
211   
212   if (!fConfigOK) return 9;
213   UInt_t result = 0;
214   TObjArray *resultArray = new TObjArray();
215   TString errorHandling = fConfEnv->GetValue("ErrorHandling","ON");
216   errorHandling.ToUpper();
217   TObject * status;
218
219   UInt_t dcsResult=0;
220   if (errorHandling == "OFF" ) {
221     if (!dcsAliasMap) dcsResult=1;
222     if (dcsAliasMap->GetEntries() == 0 ) dcsResult=1;  
223     status = new TParameter<int>("dcsResult",dcsResult);
224     resultArray->Add(status);
225   } else {
226     if (!dcsAliasMap) return 9;
227     if (dcsAliasMap->GetEntries() == 0 ) return 9;
228   }
229
230
231   
232
233   TString runType = GetRunType();
234
235   // Temperature sensors are processed by AliTPCCalTemp
236
237   TString tempConf = fConfEnv->GetValue("Temperature","ON");
238   tempConf.ToUpper();
239   if (tempConf != "OFF" ) {
240     UInt_t tempResult = MapTemperature(dcsAliasMap);
241     result=tempResult;
242     status = new TParameter<int>("tempResult",tempResult);
243     resultArray->Add(status);
244   }
245
246   // High Voltage recordings
247
248
249   TString hvConf = fConfEnv->GetValue("HighVoltage","ON");
250   hvConf.ToUpper();
251   if (hvConf != "OFF" ) { 
252    UInt_t hvResult = MapHighVoltage(dcsAliasMap);
253    result+=hvResult;
254    status = new TParameter<int>("hvResult",hvResult);
255    resultArray->Add(status);
256  }
257
258   // Goofie values
259
260
261   TString goofieConf = fConfEnv->GetValue("Goofie","ON");
262   goofieConf.ToUpper();
263   if (goofieConf != "OFF" ) { 
264    UInt_t goofieResult = MapGoofie(dcsAliasMap);
265    result+=goofieResult;
266    status = new TParameter<int>("goofieResult",goofieResult);
267    resultArray->Add(status);
268  }
269
270   // Other calibration information will be retrieved through FXS files
271   //  examples:
272   //    TList* fileSourcesDAQ = GetFile(AliShuttleInterface::kDAQ, "pedestals");
273   //    const char* fileNamePed = GetFile(AliShuttleInterface::kDAQ, "pedestals", "LDC1");
274   //
275   //    TList* fileSourcesHLT = GetFile(AliShuttleInterface::kHLT, "calib");
276   //    const char* fileNameHLT = GetFile(AliShuttleInterface::kHLT, "calib", "LDC1");
277
278   // pedestal entries
279
280   if(runType == kPedestalRunType) {
281     Int_t numSources = 1;
282     Int_t pedestalSource[2] = {AliShuttleInterface::kDAQ,AliShuttleInterface::kHLT} ;
283     TString source = fConfEnv->GetValue("Pedestal","DAQ");
284     source.ToUpper();
285     if (source != "OFF" ) { 
286      if ( source == "HLT") pedestalSource[0] = AliShuttleInterface::kHLT;
287      if (!GetHLTStatus()) pedestalSource[0] = AliShuttleInterface::kDAQ;
288      if (source == "HLTDAQ" ) {
289          numSources=2;
290          pedestalSource[0] = AliShuttleInterface::kHLT;
291          pedestalSource[1] = AliShuttleInterface::kDAQ;
292      }
293      if (source == "DAQHLT" ) numSources=2;
294      UInt_t pedestalResult=0;
295      for (Int_t i=0; i<numSources; i++ ) {      
296        pedestalResult = ExtractPedestals(pedestalSource[i]);
297        if ( pedestalResult == 0 ) break;
298      }
299      result += pedestalResult;
300      status = new TParameter<int>("pedestalResult",pedestalResult);
301      resultArray->Add(status);
302     }
303   }
304
305   // pulser trigger processing
306
307   if(runType == kPulserRunType) {
308     Int_t numSources = 1;
309     Int_t pulserSource[2] = {AliShuttleInterface::kDAQ,AliShuttleInterface::kHLT} ;
310     TString source = fConfEnv->GetValue("Pulser","DAQ");
311     source.ToUpper();
312     if ( source != "OFF") { 
313      if ( source == "HLT") pulserSource[0] = AliShuttleInterface::kHLT;
314      if (!GetHLTStatus()) pulserSource[0] = AliShuttleInterface::kDAQ;
315      if (source == "HLTDAQ" ) {
316          numSources=2;
317          pulserSource[0] = AliShuttleInterface::kHLT;
318          pulserSource[1] = AliShuttleInterface::kDAQ;
319      }
320      if (source == "DAQHLT" ) numSources=2;
321      UInt_t pulserResult=0;
322      for (Int_t i=0; i<numSources; i++ ) {      
323        pulserResult = ExtractPulser(pulserSource[i]);
324        if ( pulserResult == 0 ) break;
325      }
326      result += pulserResult;
327      status = new TParameter<int>("pulserResult",pulserResult);
328      resultArray->Add(status);
329     }
330   }
331
332
333
334   // Central Electrode processing
335
336   if( runType == kPhysicsRunType || runType == kStandAloneRunType || 
337       runType == kDaqRunType ) {    
338
339 //   if (true) {                 // do CE processing for all run types
340     Int_t numSources = 1;
341     Int_t ceSource[2] = {AliShuttleInterface::kDAQ,AliShuttleInterface::kHLT} ;
342     TString source = fConfEnv->GetValue("CE","DAQ");
343     source.ToUpper();
344     if ( source != "OFF" ) { 
345      if ( source == "HLT") ceSource[0] = AliShuttleInterface::kHLT;
346      if (!GetHLTStatus()) ceSource[0] = AliShuttleInterface::kDAQ;
347      if (source == "HLTDAQ" ) {
348         numSources=2;
349         ceSource[0] = AliShuttleInterface::kHLT;
350         ceSource[1] = AliShuttleInterface::kDAQ;
351      }
352      if (source == "DAQHLT" ) numSources=2;
353      UInt_t ceResult=0;
354      for (Int_t i=0; i<numSources; i++ ) {      
355        ceResult = ExtractCE(ceSource[i]);
356        if ( ceResult == 0 ) break;
357      }
358      result += ceResult;
359      status = new TParameter<int>("ceResult",ceResult);
360      resultArray->Add(status);
361
362     numSources = 1;
363     Int_t qaSource[2] = {AliShuttleInterface::kDAQ,AliShuttleInterface::kHLT} ;
364     source = fConfEnv->GetValue("QA","DAQ");
365     source.ToUpper();
366     if ( source != "OFF" ) { 
367      if ( source == "HLT") qaSource[0] = AliShuttleInterface::kHLT;
368      if (!GetHLTStatus()) qaSource[0] = AliShuttleInterface::kDAQ;
369      if (source == "HLTDAQ" ) {
370         numSources=2;
371         qaSource[0] = AliShuttleInterface::kHLT;
372         qaSource[1] = AliShuttleInterface::kDAQ;
373      }
374      if (source == "DAQHLT" ) numSources=2;
375      UInt_t qaResult=0;
376      for (Int_t i=0; i<numSources; i++ ) {      
377        qaResult = ExtractQA(qaSource[i]);
378        if ( qaResult == 0 ) break;
379      }
380 //     result += qaResult;
381      if ( qaResult !=0 ) Log ("ExtractQA failed, no QA entry available.");
382      status = new TParameter<int>("qaResult",qaResult);
383      resultArray->Add(status);
384     }
385    }
386   }
387   
388   if (errorHandling == "OFF" ) {
389     AliCDBMetaData metaData;
390     metaData.SetBeamPeriod(0);
391     metaData.SetResponsible("Haavard Helstrup");
392     metaData.SetComment("Preprocessor AliTPC status.");
393     Store("Calib", "PreprocStatus", resultArray, &metaData, 0, kFALSE);
394     resultArray->Delete();
395     return 0;
396   } else { 
397     return result;
398   }
399 }
400 //______________________________________________________________________________________________
401 UInt_t AliTPCPreprocessor::MapTemperature(TMap* dcsAliasMap)
402 {
403
404    // extract DCS temperature maps. Perform fits to save space
405
406   UInt_t result=0;
407   TMap *map = fTemp->ExtractDCS(dcsAliasMap);
408   if (map) {
409     fTemp->MakeSplineFit(map);
410     Double_t fitFraction = 1.0*fTemp->NumFits()/fTemp->NumSensors(); 
411     if (fitFraction > kFitFraction ) {
412       AliInfo(Form("Temperature values extracted, fits performed.\n"));
413     } else { 
414       Log ("Too few temperature maps fitted. \n");
415       result = 9;
416     }
417   } else {
418     Log("No temperature map extracted. \n");
419     result=9;
420   }
421   delete map;
422   // Now store the final CDB file
423
424   if ( result == 0 ) {
425         AliCDBMetaData metaData;
426         metaData.SetBeamPeriod(0);
427         metaData.SetResponsible("Haavard Helstrup");
428         metaData.SetComment("Preprocessor AliTPC data base entries.");
429
430         Bool_t storeOK = Store("Calib", "Temperature", fTemp, &metaData, 0, kFALSE);
431         if ( !storeOK )  result=1;
432
433    }
434
435    return result;
436
437 }
438
439 //______________________________________________________________________________________________
440 UInt_t AliTPCPreprocessor::MapHighVoltage(TMap* dcsAliasMap)
441 {
442
443    // extract DCS HV maps. Perform fits to save space
444
445   UInt_t result=0;
446   TMap *map = fHighVoltage->ExtractDCS(dcsAliasMap);
447   if (map) {
448     fHighVoltage->MakeSplineFit(map);
449     Double_t fitFraction = 1.0*fHighVoltage->NumFits()/fHighVoltage->NumSensors(); 
450     if (fitFraction > kFitFraction ) {
451       AliInfo(Form("High voltage recordings extracted, fits performed.\n"));
452     } else { 
453       Log ("Too few high voltage recordings fitted. \n");
454       result = 9;
455     }
456   } else {
457     Log("No high voltage recordings extracted. \n");
458     result=9;
459   }
460   delete map;
461
462   TString hvStatConf = fConfEnv->GetValue("HighVoltageStat","ON");
463   hvStatConf.ToUpper();
464   if (hvStatConf != "OFF" ) { 
465     TMap *map2 = fHighVoltageStat->ExtractDCS(dcsAliasMap);
466     if (map2) {
467       fHighVoltageStat->ClearFit();
468       fHighVoltageStat->SetGraph(map2);
469     } else {
470        Log("No high voltage status recordings extracted. \n");
471       result=9;
472     }
473     delete map2;
474
475     // add status maps to high voltage sensor array
476
477     fHighVoltage->AddSensors(fHighVoltageStat);
478    }
479   // Now store the final CDB file
480
481   if ( result == 0 ) {
482         AliCDBMetaData metaData;
483         metaData.SetBeamPeriod(0);
484         metaData.SetResponsible("Haavard Helstrup");
485         metaData.SetComment("Preprocessor AliTPC data base entries.");
486
487         Bool_t storeOK = Store("Calib", "HighVoltage", fHighVoltage, &metaData, 0, kFALSE);
488         if ( !storeOK )  result=1;
489
490    }
491
492    return result;
493
494 }
495
496 //______________________________________________________________________________________________
497 UInt_t AliTPCPreprocessor::MapGoofie(TMap* dcsAliasMap)
498 {
499
500    // extract DCS Goofie maps. Do not perform fits (low update rate)
501
502   UInt_t result=0;
503
504   TMap *map = fGoofie->ExtractDCS(dcsAliasMap);
505   if (map) {
506     fGoofie->ClearFit();
507     fGoofie->SetGraph(map);
508   } else {
509     Log("No Goofie recordings extracted. \n");
510     result=9;
511   }
512   delete map;
513
514   // Now store the final CDB file
515
516   if ( result == 0 ) {
517         AliCDBMetaData metaData;
518         metaData.SetBeamPeriod(0);
519         metaData.SetResponsible("Haavard Helstrup");
520         metaData.SetComment("Preprocessor AliTPC data base entries.");
521
522         Bool_t storeOK = Store("Calib", "Goofie", fGoofie, &metaData, 0, kFALSE);
523         if ( !storeOK )  result=1;
524
525    }
526
527    return result;
528
529 }
530
531
532 //______________________________________________________________________________________________
533
534 UInt_t AliTPCPreprocessor::ExtractPedestals(Int_t sourceFXS)
535 {
536  //
537  //  Read pedestal file from file exchage server
538  //  Keep original entry from OCDB in case no new pedestals are available
539  //
540  AliTPCCalPad *calPadPed=0;
541  AliCDBEntry* entry = GetFromOCDB("Calib", "Pedestals");
542  if (entry) calPadPed = (AliTPCCalPad*)entry->GetObject();
543  if ( calPadPed==NULL ) {
544      Log("AliTPCPreprocsessor: No previous TPC pedestal entry available.\n");
545      calPadPed = new AliTPCCalPad("PedestalsMean","PedestalsMean");
546  }
547
548  AliTPCCalPad *calPadRMS=0;
549  entry = GetFromOCDB("Calib", "PadNoise");
550  if (entry) calPadRMS = (AliTPCCalPad*)entry->GetObject();
551  if ( calPadRMS==NULL ) {
552      Log("AliTPCPreprocsessor: No previous TPC noise entry available.\n");
553      calPadRMS = new AliTPCCalPad("PedestalsRMS","PedestalsRMS");
554  }
555
556
557  UInt_t result=0;
558
559  Int_t nSectors = fROC->GetNSectors();
560  TList* list = GetFileSources(sourceFXS,"pedestals");
561  
562  if (list && list->GetEntries()>0) {
563
564 //  loop through all files from LDCs
565
566     Bool_t changed=false;
567     UInt_t index = 0;
568     while (list->At(index)!=NULL) {
569      TObjString* fileNameEntry = (TObjString*) list->At(index);
570      if (fileNameEntry!=NULL) {
571         TString fileName = GetFile(sourceFXS, "pedestals",
572                                          fileNameEntry->GetString().Data());
573         TFile *f = TFile::Open(fileName);
574         if (!f) {
575           Log ("Error opening pedestal file.");
576           result =2;
577           break;
578         }
579         AliTPCCalibPedestal *calPed;
580         f->GetObject("tpcCalibPedestal",calPed);
581         if ( !calPed ) {
582           Log ("No pedestal calibration object in file.");
583           result = 2;
584           break;
585         }
586
587         //  replace entries for the sectors available in the present file
588
589         changed=true;
590         for (Int_t sector=0; sector<nSectors; sector++) {
591            AliTPCCalROC *rocPed=calPed->GetCalRocPedestal(sector, kFALSE);
592            if ( rocPed )  calPadPed->SetCalROC(rocPed,sector);
593            AliTPCCalROC *rocRMS=calPed->GetCalRocRMS(sector, kFALSE);
594            if ( rocRMS )  calPadRMS->SetCalROC(rocRMS,sector);
595         }
596         delete calPed; 
597         f->Close();
598       }
599      ++index;
600     }  // while(list)
601 //
602 //  Store updated pedestal entry to OCDB
603 //
604     if (changed) {
605      AliCDBMetaData metaData;
606      metaData.SetBeamPeriod(0);
607      metaData.SetResponsible("Haavard Helstrup");
608      metaData.SetComment("Preprocessor AliTPC data base entries."); 
609  
610      Bool_t storeOK = Store("Calib", "Pedestals", calPadPed, &metaData, 0, kTRUE);
611      if ( !storeOK ) ++result;
612      storeOK = Store("Calib", "PadNoise", calPadRMS, &metaData, 0, kTRUE);
613      if ( !storeOK ) ++result;
614     }
615   } else {
616     Log ("Error: no entries in input file list!");
617     result = 1;
618   }
619
620   return result;
621 }
622
623 //______________________________________________________________________________________________
624
625
626 UInt_t AliTPCPreprocessor::ExtractPulser(Int_t sourceFXS)
627 {
628  //
629  //  Read pulser calibration file from file exchage server
630  //  Keep original entry from OCDB in case no new pulser calibration is available
631  //
632  TObjArray    *pulserObjects=0;
633  AliTPCCalPad *pulserTmean=0;
634  AliTPCCalPad *pulserTrms=0;
635  AliTPCCalPad *pulserQmean=0;
636  AliCDBEntry* entry = GetFromOCDB("Calib", "Pulser");
637  if (entry) pulserObjects = (TObjArray*)entry->GetObject();
638  if ( pulserObjects==NULL ) {
639      Log("AliTPCPreprocsessor: No previous TPC pulser entry available.\n");
640      pulserObjects = new TObjArray;    
641  }
642
643  pulserTmean = (AliTPCCalPad*)pulserObjects->FindObject("PulserTmean");
644  if ( !pulserTmean ) {
645     pulserTmean = new AliTPCCalPad("PulserTmean","PulserTmean");
646     pulserObjects->Add(pulserTmean);
647  }
648  pulserTrms = (AliTPCCalPad*)pulserObjects->FindObject("PulserTrms");
649  if ( !pulserTrms )  { 
650     pulserTrms = new AliTPCCalPad("PulserTrms","PulserTrms");
651     pulserObjects->Add(pulserTrms);
652  }
653  pulserQmean = (AliTPCCalPad*)pulserObjects->FindObject("PulserQmean");
654  if ( !pulserQmean )  { 
655     pulserQmean = new AliTPCCalPad("PulserQmean","PulserQmean");
656     pulserObjects->Add(pulserQmean);
657  }
658
659
660  UInt_t result=0;
661
662  Int_t nSectors = fROC->GetNSectors();
663  TList* list = GetFileSources(sourceFXS,"pulser");
664  
665  if (list && list->GetEntries()>0) {
666
667 //  loop through all files from LDCs
668
669     Bool_t changed=false;
670     UInt_t index = 0;
671     while (list->At(index)!=NULL) {
672      TObjString* fileNameEntry = (TObjString*) list->At(index);
673      if (fileNameEntry!=NULL) {
674         TString fileName = GetFile(sourceFXS, "pulser",
675                                          fileNameEntry->GetString().Data());
676         TFile *f = TFile::Open(fileName);
677         if (!f) {
678           Log ("Error opening pulser file.");
679           result =2;
680           break;
681         }
682         AliTPCCalibPulser *calPulser;
683         f->GetObject("tpcCalibPulser",calPulser);
684         if ( !calPulser ) {
685           Log ("No pulser calibration object in file.");
686           result = 2;
687           break;
688         }
689
690         //  replace entries for the sectors available in the present file
691
692         changed=true;
693         for (Int_t sector=0; sector<nSectors; sector++) {
694            AliTPCCalROC *rocTmean=calPulser->GetCalRocT0(sector);
695            if ( rocTmean )  pulserTmean->SetCalROC(rocTmean,sector);
696            AliTPCCalROC *rocTrms=calPulser->GetCalRocRMS(sector);
697            if ( rocTrms )  pulserTrms->SetCalROC(rocTrms,sector);
698            AliTPCCalROC *rocQmean=calPulser->GetCalRocQ(sector);
699            if ( rocQmean )  pulserQmean->SetCalROC(rocQmean,sector);
700         }
701        delete calPulser;
702        f->Close();
703       }
704      ++index;
705     }  // while(list)
706 //
707 //  Store updated pedestal entry to OCDB
708 //
709     if (changed) {
710      AliCDBMetaData metaData;
711      metaData.SetBeamPeriod(0);
712      metaData.SetResponsible("Haavard Helstrup");
713      metaData.SetComment("Preprocessor AliTPC data base entries.");
714
715      Bool_t storeOK = Store("Calib", "Pulser", pulserObjects, &metaData, 0, kTRUE);
716      if ( !storeOK ) ++result;
717     }  
718   } else {
719     Log ("Error: no entries in input file list!");
720     result = 1;
721   }
722
723   return result;
724 }
725
726 UInt_t AliTPCPreprocessor::ExtractCE(Int_t sourceFXS)
727 {
728  //
729  //  Read Central Electrode file from file exchage server
730  //  Keep original entry from OCDB in case no new CE calibration is available
731  //
732  TObjArray    *ceObjects=0;
733  AliTPCCalPad *ceTmean=0;
734  AliTPCCalPad *ceTrms=0;
735  AliTPCCalPad *ceQmean=0;
736  TObjArray    *rocTtime=0;  
737  TObjArray    *rocQtime=0;  
738
739  AliCDBEntry* entry = GetFromOCDB("Calib", "CE");
740  if (entry) ceObjects = (TObjArray*)entry->GetObject();
741  if ( ceObjects==NULL ) {
742      Log("AliTPCPreprocsessor: No previous TPC central electrode entry available.\n");
743      ceObjects = new TObjArray;    
744  }
745
746  Int_t nSectors = fROC->GetNSectors();
747
748  ceTmean = (AliTPCCalPad*)ceObjects->FindObject("CETmean");
749  if ( !ceTmean ) {
750     ceTmean = new AliTPCCalPad("CETmean","CETmean");
751     ceObjects->Add(ceTmean);
752  }
753  ceTrms = (AliTPCCalPad*)ceObjects->FindObject("CETrms");
754  if ( !ceTrms )  { 
755     ceTrms = new AliTPCCalPad("CETrms","CETrms");
756     ceObjects->Add(ceTrms);
757  }
758  ceQmean = (AliTPCCalPad*)ceObjects->FindObject("CEQmean");
759  if ( !ceQmean )  { 
760     ceQmean = new AliTPCCalPad("CEQmean","CEQmean");
761     ceObjects->Add(ceQmean);
762  }
763  //!new from here please have a look!!!
764  rocTtime = (TObjArray*)ceObjects->FindObject("rocTtime");
765  if ( !rocTtime ) {
766      rocTtime = new TObjArray(nSectors);
767      rocTtime->SetName("rocTtime");
768      ceObjects->Add(rocTtime);
769  }
770  
771  rocQtime = (TObjArray*)ceObjects->FindObject("rocQtime");
772  if ( !rocQtime ) {
773      rocQtime = new TObjArray(nSectors);
774      rocQtime->SetName("rocQtime");
775      ceObjects->Add(rocQtime);
776  }
777
778
779  UInt_t result=0;
780
781  TList* list = GetFileSources(sourceFXS,"CE");
782  
783  if (list && list->GetEntries()>0) {
784
785 //  loop through all files from LDCs
786
787     UInt_t index = 0;
788     while (list->At(index)!=NULL) {
789      TObjString* fileNameEntry = (TObjString*) list->At(index);
790      if (fileNameEntry!=NULL) {
791         TString fileName = GetFile(sourceFXS, "CE",
792                                          fileNameEntry->GetString().Data());
793         TFile *f = TFile::Open(fileName);
794         if (!f) {
795           Log ("Error opening central electrode file.");
796           result =2;
797           break;
798         }
799         AliTPCCalibCE *calCE;
800         f->GetObject("tpcCalibCE",calCE);
801
802         if (!calCE) {
803           Log ("No valid calibCE object.");
804           result=2;
805           break;
806         }
807         //  replace entries for the sectors available in the present file
808
809         for (Int_t sector=0; sector<nSectors; sector++) {
810            AliTPCCalROC *rocTmean=calCE->GetCalRocT0(sector);
811            if ( rocTmean )  ceTmean->SetCalROC(rocTmean,sector);
812            AliTPCCalROC *rocTrms=calCE->GetCalRocRMS(sector);
813            if ( rocTrms )  ceTrms->SetCalROC(rocTrms,sector);
814            AliTPCCalROC *rocQmean=calCE->GetCalRocQ(sector);
815            if ( rocQmean )  ceQmean->SetCalROC(rocQmean,sector);
816            TGraph *grT=calCE->MakeGraphTimeCE(sector,0,2); // T time graph
817            if ( grT ) rocTtime->AddAt(grT,sector);         
818            TGraph *grQ=calCE->MakeGraphTimeCE(sector,0,3); // Q time graph
819            if ( grQ ) rocTtime->AddAt(grQ,sector);         
820         }
821        delete calCE;
822        f->Close();
823       }
824      ++index;
825     }  // while(list)
826 //
827 //  Store updated pedestal entry to OCDB
828 //
829     AliCDBMetaData metaData;
830     metaData.SetBeamPeriod(0);
831     metaData.SetResponsible("Haavard Helstrup");
832     metaData.SetComment("Preprocessor AliTPC data base entries.");
833
834     Bool_t storeOK = Store("Calib", "CE", ceObjects, &metaData, 0, kTRUE);
835     if ( !storeOK ) ++result;
836     
837   } else {
838     Log ("Error: no entries!");
839     result = 1;
840   }
841
842   return result;
843 }
844 //______________________________________________________________________________________________
845
846 UInt_t AliTPCPreprocessor::ExtractQA(Int_t sourceFXS)
847 {
848  //
849  //  Read Quality Assurance file from file exchage server
850  //
851  
852  UInt_t result=0;
853
854  TList* list = GetFileSources(sourceFXS,"QA");
855  
856  if (list && list->GetEntries()>0) {
857
858 //  only one QA objetc should be available!
859
860     AliTPCdataQA *calQA;
861
862     UInt_t nentries = list->GetEntries();  
863     UInt_t index=0;
864     if ( nentries > 1) Log ( "More than one QA entry. First one processed");      
865     TObjString* fileNameEntry = (TObjString*) list->At(index);
866     if (fileNameEntry!=NULL) {
867         TString fileName = GetFile(sourceFXS, "QA",
868                                          fileNameEntry->GetString().Data());
869         TFile *f = TFile::Open(fileName);
870         if (!f) {
871           Log ("Error opening QA file.");
872           result =2;          
873         } else {
874           f->GetObject("tpcCalibQA",calQA);
875           if ( calQA ) {      
876 //
877 //  Store updated pedestal entry to OCDB
878 //
879            AliCDBMetaData metaData;
880            metaData.SetBeamPeriod(0);
881            metaData.SetResponsible("Haavard Helstrup");
882            metaData.SetComment("Preprocessor AliTPC data base entries.");
883
884            Bool_t storeOK = Store("Calib", "QA", calQA, &metaData, 0, kTRUE);
885            if ( !storeOK ) ++result;
886           }
887         }
888     } else {
889     Log ("Error: no QA files on FXS!");
890     result = 2;
891     }
892   } else {
893     Log ("Error: no QA entries in FXS list!");
894     result = 1;
895   }
896   return result;
897 }
898