]> git.uio.no Git - u/mrichter/AliRoot.git/blob - TPC/AliTPCPreprocessor.cxx
(Jens Viechula)
[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), 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), 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
185 //______________________________________________________________________________________________
186 UInt_t AliTPCPreprocessor::Process(TMap* dcsAliasMap)
187 {
188   // Fills data into TPC calibrations objects
189
190   // Amanda servers provide information directly through dcsAliasMap
191
192   
193   if (!fConfigOK) return 9;
194   UInt_t result = 0;
195   TObjArray *resultArray = new TObjArray();
196   TString errorHandling = fConfEnv->GetValue("ErrorHandling","ON");
197   errorHandling.ToUpper();
198   TObject * status;
199
200   UInt_t dcsResult=0;
201   if (errorHandling == "OFF" ) {
202     if (!dcsAliasMap) dcsResult=1;
203     if (dcsAliasMap->GetEntries() == 0 ) dcsResult=1;  
204     status = new TParameter<int>("dcsResult",dcsResult);
205     resultArray->Add(status);
206   } else {
207     if (!dcsAliasMap) return 9;
208     if (dcsAliasMap->GetEntries() == 0 ) return 9;
209   }
210
211
212   
213
214   TString runType = GetRunType();
215
216   // Temperature sensors are processed by AliTPCCalTemp
217
218   TString tempConf = fConfEnv->GetValue("Temperature","ON");
219   tempConf.ToUpper();
220   if (tempConf != "OFF" ) {
221     UInt_t tempResult = MapTemperature(dcsAliasMap);
222     result=tempResult;
223     status = new TParameter<int>("tempResult",tempResult);
224     resultArray->Add(status);
225   }
226
227   // High Voltage recordings
228
229
230   TString hvConf = fConfEnv->GetValue("HighVoltage","ON");
231   hvConf.ToUpper();
232   if (hvConf != "OFF" ) { 
233    UInt_t hvResult = MapHighVoltage(dcsAliasMap);
234    result+=hvResult;
235    status = new TParameter<int>("hvResult",hvResult);
236    resultArray->Add(status);
237  }
238
239   // Other calibration information will be retrieved through FXS files
240   //  examples:
241   //    TList* fileSourcesDAQ = GetFile(AliShuttleInterface::kDAQ, "pedestals");
242   //    const char* fileNamePed = GetFile(AliShuttleInterface::kDAQ, "pedestals", "LDC1");
243   //
244   //    TList* fileSourcesHLT = GetFile(AliShuttleInterface::kHLT, "calib");
245   //    const char* fileNameHLT = GetFile(AliShuttleInterface::kHLT, "calib", "LDC1");
246
247   // pedestal entries
248
249   if(runType == kPedestalRunType) {
250     Int_t numSources = 1;
251     Int_t pedestalSource[2] = {AliShuttleInterface::kDAQ,AliShuttleInterface::kHLT} ;
252     TString source = fConfEnv->GetValue("Pedestal","DAQ");
253     source.ToUpper();
254     if (source != "OFF" ) { 
255      if ( source == "HLT") pedestalSource[0] = AliShuttleInterface::kHLT;
256      if (!GetHLTStatus()) pedestalSource[0] = AliShuttleInterface::kDAQ;
257      if (source == "HLTDAQ" ) {
258          numSources=2;
259          pedestalSource[0] = AliShuttleInterface::kHLT;
260          pedestalSource[1] = AliShuttleInterface::kDAQ;
261      }
262      if (source == "DAQHLT" ) numSources=2;
263      UInt_t pedestalResult=0;
264      for (Int_t i=0; i<numSources; i++ ) {      
265        pedestalResult = ExtractPedestals(pedestalSource[i]);
266        if ( pedestalResult == 0 ) break;
267      }
268      result += pedestalResult;
269      status = new TParameter<int>("pedestalResult",pedestalResult);
270      resultArray->Add(status);
271     }
272   }
273
274   // pulser trigger processing
275
276   if(runType == kPulserRunType) {
277     Int_t numSources = 1;
278     Int_t pulserSource[2] = {AliShuttleInterface::kDAQ,AliShuttleInterface::kHLT} ;
279     TString source = fConfEnv->GetValue("Pulser","DAQ");
280     source.ToUpper();
281     if ( source != "OFF") { 
282      if ( source == "HLT") pulserSource[0] = AliShuttleInterface::kHLT;
283      if (!GetHLTStatus()) pulserSource[0] = AliShuttleInterface::kDAQ;
284      if (source == "HLTDAQ" ) {
285          numSources=2;
286          pulserSource[0] = AliShuttleInterface::kHLT;
287          pulserSource[1] = AliShuttleInterface::kDAQ;
288      }
289      if (source == "DAQHLT" ) numSources=2;
290      UInt_t pulserResult=0;
291      for (Int_t i=0; i<numSources; i++ ) {      
292        pulserResult = ExtractPulser(pulserSource[i]);
293        if ( pulserResult == 0 ) break;
294      }
295      result += pulserResult;
296      status = new TParameter<int>("pulserResult",pulserResult);
297      resultArray->Add(status);
298     }
299   }
300
301
302
303   // Central Electrode processing
304
305   if( runType == kPhysicsRunType || runType == kStandAloneRunType || 
306       runType == kDaqRunType ) {    
307
308 //   if (true) {                 // do CE processing for all run types
309     Int_t numSources = 1;
310     Int_t ceSource[2] = {AliShuttleInterface::kDAQ,AliShuttleInterface::kHLT} ;
311     TString source = fConfEnv->GetValue("CE","DAQ");
312     source.ToUpper();
313     if ( source != "OFF" ) { 
314      if ( source == "HLT") ceSource[0] = AliShuttleInterface::kHLT;
315      if (!GetHLTStatus()) ceSource[0] = AliShuttleInterface::kDAQ;
316      if (source == "HLTDAQ" ) {
317         numSources=2;
318         ceSource[0] = AliShuttleInterface::kHLT;
319         ceSource[1] = AliShuttleInterface::kDAQ;
320      }
321      if (source == "DAQHLT" ) numSources=2;
322      UInt_t ceResult=0;
323      for (Int_t i=0; i<numSources; i++ ) {      
324        ceResult = ExtractCE(ceSource[i]);
325        if ( ceResult == 0 ) break;
326      }
327      result += ceResult;
328      status = new TParameter<int>("ceResult",ceResult);
329      resultArray->Add(status);
330
331     numSources = 1;
332     Int_t qaSource[2] = {AliShuttleInterface::kDAQ,AliShuttleInterface::kHLT} ;
333     TString source = fConfEnv->GetValue("QA","DAQ");
334     source.ToUpper();
335     if ( source != "OFF" ) { 
336      if ( source == "HLT") qaSource[0] = AliShuttleInterface::kHLT;
337      if (!GetHLTStatus()) qaSource[0] = AliShuttleInterface::kDAQ;
338      if (source == "HLTDAQ" ) {
339         numSources=2;
340         qaSource[0] = AliShuttleInterface::kHLT;
341         qaSource[1] = AliShuttleInterface::kDAQ;
342      }
343      if (source == "DAQHLT" ) numSources=2;
344      UInt_t qaResult=0;
345      for (Int_t i=0; i<numSources; i++ ) {      
346        qaResult = ExtractQA(qaSource[i]);
347        if ( qaResult == 0 ) break;
348      }
349 //     result += qaResult;
350      if ( qaResult !=0 ) Log ("ExtractQA failed, no QA entry available.");
351      status = new TParameter<int>("qaResult",qaResult);
352      resultArray->Add(status);
353     }
354    }
355   }
356   
357   if (errorHandling == "OFF" ) {
358     AliCDBMetaData metaData;
359     metaData.SetBeamPeriod(0);
360     metaData.SetResponsible("Haavard Helstrup");
361     metaData.SetComment("Preprocessor AliTPC status.");
362     Store("Calib", "PreprocStatus", resultArray, &metaData, 0, kFALSE);
363     resultArray->Delete();
364     return 0;
365   } else { 
366     return result;
367   }
368 }
369 //______________________________________________________________________________________________
370 UInt_t AliTPCPreprocessor::MapTemperature(TMap* dcsAliasMap)
371 {
372
373    // extract DCS temperature maps. Perform fits to save space
374
375   UInt_t result=0;
376   TMap *map = fTemp->ExtractDCS(dcsAliasMap);
377   if (map) {
378     fTemp->MakeSplineFit(map);
379     Double_t fitFraction = 1.0*fTemp->NumFits()/fTemp->NumSensors(); 
380     if (fitFraction > kFitFraction ) {
381       AliInfo(Form("Temperature values extracted, fits performed.\n"));
382     } else { 
383       Log ("Too few temperature maps fitted. \n");
384       result = 9;
385     }
386   } else {
387     Log("No temperature map extracted. \n");
388     result=9;
389   }
390   delete map;
391   // Now store the final CDB file
392
393   if ( result == 0 ) {
394         AliCDBMetaData metaData;
395         metaData.SetBeamPeriod(0);
396         metaData.SetResponsible("Haavard Helstrup");
397         metaData.SetComment("Preprocessor AliTPC data base entries.");
398
399         Bool_t storeOK = Store("Calib", "Temperature", fTemp, &metaData, 0, kFALSE);
400         if ( !storeOK )  result=1;
401
402    }
403
404    return result;
405
406 }
407
408 //______________________________________________________________________________________________
409 UInt_t AliTPCPreprocessor::MapHighVoltage(TMap* dcsAliasMap)
410 {
411
412    // extract DCS HV maps. Perform fits to save space
413
414   UInt_t result=0;
415   TMap *map = fHighVoltage->ExtractDCS(dcsAliasMap);
416   if (map) {
417     fHighVoltage->MakeSplineFit(map);
418     Double_t fitFraction = 1.0*fHighVoltage->NumFits()/fHighVoltage->NumSensors(); 
419     if (fitFraction > kFitFraction ) {
420       AliInfo(Form("High voltage recordings extracted, fits performed.\n"));
421     } else { 
422       Log ("Too few high voltage recordings fitted. \n");
423       result = 9;
424     }
425   } else {
426     Log("No high voltage recordings extracted. \n");
427     result=9;
428   }
429   delete map;
430
431   TString hvStatConf = fConfEnv->GetValue("HighVoltageStat","ON");
432   hvStatConf.ToUpper();
433   if (hvStatConf != "OFF" ) { 
434     TMap *map2 = fHighVoltageStat->ExtractDCS(dcsAliasMap);
435     if (map2) {
436       fHighVoltageStat->ClearFit();
437       fHighVoltageStat->SetGraph(map2);
438     } else {
439        Log("No high voltage status recordings extracted. \n");
440       result=9;
441     }
442     delete map2;
443
444     // add status maps to high voltage sensor array
445
446     fHighVoltage->AddSensors(fHighVoltageStat);
447    }
448   // Now store the final CDB file
449
450   if ( result == 0 ) {
451         AliCDBMetaData metaData;
452         metaData.SetBeamPeriod(0);
453         metaData.SetResponsible("Haavard Helstrup");
454         metaData.SetComment("Preprocessor AliTPC data base entries.");
455
456         Bool_t storeOK = Store("Calib", "HighVoltage", fHighVoltage, &metaData, 0, kFALSE);
457         if ( !storeOK )  result=1;
458
459    }
460
461    return result;
462
463 }
464
465
466 //______________________________________________________________________________________________
467
468 UInt_t AliTPCPreprocessor::ExtractPedestals(Int_t sourceFXS)
469 {
470  //
471  //  Read pedestal file from file exchage server
472  //  Keep original entry from OCDB in case no new pedestals are available
473  //
474  AliTPCCalPad *calPadPed=0;
475  AliCDBEntry* entry = GetFromOCDB("Calib", "Pedestals");
476  if (entry) calPadPed = (AliTPCCalPad*)entry->GetObject();
477  if ( calPadPed==NULL ) {
478      Log("AliTPCPreprocsessor: No previous TPC pedestal entry available.\n");
479      calPadPed = new AliTPCCalPad("PedestalsMean","PedestalsMean");
480  }
481
482  AliTPCCalPad *calPadRMS=0;
483  entry = GetFromOCDB("Calib", "PadNoise");
484  if (entry) calPadRMS = (AliTPCCalPad*)entry->GetObject();
485  if ( calPadRMS==NULL ) {
486      Log("AliTPCPreprocsessor: No previous TPC noise entry available.\n");
487      calPadRMS = new AliTPCCalPad("PedestalsRMS","PedestalsRMS");
488  }
489
490
491  UInt_t result=0;
492
493  Int_t nSectors = fROC->GetNSectors();
494  TList* list = GetFileSources(sourceFXS,"pedestals");
495  
496  if (list && list->GetEntries()>0) {
497
498 //  loop through all files from LDCs
499
500     Bool_t changed=false;
501     UInt_t index = 0;
502     while (list->At(index)!=NULL) {
503      TObjString* fileNameEntry = (TObjString*) list->At(index);
504      if (fileNameEntry!=NULL) {
505         TString fileName = GetFile(sourceFXS, "pedestals",
506                                          fileNameEntry->GetString().Data());
507         TFile *f = TFile::Open(fileName);
508         if (!f) {
509           Log ("Error opening pedestal file.");
510           result =2;
511           break;
512         }
513         AliTPCCalibPedestal *calPed;
514         f->GetObject("tpcCalibPedestal",calPed);
515         if ( !calPed ) {
516           Log ("No pedestal calibration object in file.");
517           result = 2;
518           break;
519         }
520
521         //  replace entries for the sectors available in the present file
522
523         changed=true;
524         for (Int_t sector=0; sector<nSectors; sector++) {
525            AliTPCCalROC *rocPed=calPed->GetCalRocPedestal(sector, kFALSE);
526            if ( rocPed )  calPadPed->SetCalROC(rocPed,sector);
527            AliTPCCalROC *rocRMS=calPed->GetCalRocRMS(sector, kFALSE);
528            if ( rocRMS )  calPadRMS->SetCalROC(rocRMS,sector);
529         }
530         delete calPed; 
531         f->Close();
532       }
533      ++index;
534     }  // while(list)
535 //
536 //  Store updated pedestal entry to OCDB
537 //
538     if (changed) {
539      AliCDBMetaData metaData;
540      metaData.SetBeamPeriod(0);
541      metaData.SetResponsible("Haavard Helstrup");
542      metaData.SetComment("Preprocessor AliTPC data base entries."); 
543  
544      Bool_t storeOK = Store("Calib", "Pedestals", calPadPed, &metaData, 0, kTRUE);
545      if ( !storeOK ) ++result;
546      storeOK = Store("Calib", "PadNoise", calPadRMS, &metaData, 0, kTRUE);
547      if ( !storeOK ) ++result;
548     }
549   } else {
550     Log ("Error: no entries in input file list!");
551     result = 1;
552   }
553
554   return result;
555 }
556
557 //______________________________________________________________________________________________
558
559
560 UInt_t AliTPCPreprocessor::ExtractPulser(Int_t sourceFXS)
561 {
562  //
563  //  Read pulser calibration file from file exchage server
564  //  Keep original entry from OCDB in case no new pulser calibration is available
565  //
566  TObjArray    *pulserObjects=0;
567  AliTPCCalPad *pulserTmean=0;
568  AliTPCCalPad *pulserTrms=0;
569  AliTPCCalPad *pulserQmean=0;
570  AliCDBEntry* entry = GetFromOCDB("Calib", "Pulser");
571  if (entry) pulserObjects = (TObjArray*)entry->GetObject();
572  if ( pulserObjects==NULL ) {
573      Log("AliTPCPreprocsessor: No previous TPC pulser entry available.\n");
574      pulserObjects = new TObjArray;    
575  }
576
577  pulserTmean = (AliTPCCalPad*)pulserObjects->FindObject("PulserTmean");
578  if ( !pulserTmean ) {
579     pulserTmean = new AliTPCCalPad("PulserTmean","PulserTmean");
580     pulserObjects->Add(pulserTmean);
581  }
582  pulserTrms = (AliTPCCalPad*)pulserObjects->FindObject("PulserTrms");
583  if ( !pulserTrms )  { 
584     pulserTrms = new AliTPCCalPad("PulserTrms","PulserTrms");
585     pulserObjects->Add(pulserTrms);
586  }
587  pulserQmean = (AliTPCCalPad*)pulserObjects->FindObject("PulserQmean");
588  if ( !pulserQmean )  { 
589     pulserQmean = new AliTPCCalPad("PulserQmean","PulserQmean");
590     pulserObjects->Add(pulserQmean);
591  }
592
593
594  UInt_t result=0;
595
596  Int_t nSectors = fROC->GetNSectors();
597  TList* list = GetFileSources(sourceFXS,"pulser");
598  
599  if (list && list->GetEntries()>0) {
600
601 //  loop through all files from LDCs
602
603     Bool_t changed=false;
604     UInt_t index = 0;
605     while (list->At(index)!=NULL) {
606      TObjString* fileNameEntry = (TObjString*) list->At(index);
607      if (fileNameEntry!=NULL) {
608         TString fileName = GetFile(sourceFXS, "pulser",
609                                          fileNameEntry->GetString().Data());
610         TFile *f = TFile::Open(fileName);
611         if (!f) {
612           Log ("Error opening pulser file.");
613           result =2;
614           break;
615         }
616         AliTPCCalibPulser *calPulser;
617         f->GetObject("tpcCalibPulser",calPulser);
618         if ( !calPulser ) {
619           Log ("No pulser calibration object in file.");
620           result = 2;
621           break;
622         }
623
624         //  replace entries for the sectors available in the present file
625
626         changed=true;
627         for (Int_t sector=0; sector<nSectors; sector++) {
628            AliTPCCalROC *rocTmean=calPulser->GetCalRocT0(sector);
629            if ( rocTmean )  pulserTmean->SetCalROC(rocTmean,sector);
630            AliTPCCalROC *rocTrms=calPulser->GetCalRocRMS(sector);
631            if ( rocTrms )  pulserTrms->SetCalROC(rocTrms,sector);
632            AliTPCCalROC *rocQmean=calPulser->GetCalRocQ(sector);
633            if ( rocQmean )  pulserQmean->SetCalROC(rocQmean,sector);
634         }
635        delete calPulser;
636        f->Close();
637       }
638      ++index;
639     }  // while(list)
640 //
641 //  Store updated pedestal entry to OCDB
642 //
643     if (changed) {
644      AliCDBMetaData metaData;
645      metaData.SetBeamPeriod(0);
646      metaData.SetResponsible("Haavard Helstrup");
647      metaData.SetComment("Preprocessor AliTPC data base entries.");
648
649      Bool_t storeOK = Store("Calib", "Pulser", pulserObjects, &metaData, 0, kTRUE);
650      if ( !storeOK ) ++result;
651     }  
652   } else {
653     Log ("Error: no entries in input file list!");
654     result = 1;
655   }
656
657   return result;
658 }
659
660 UInt_t AliTPCPreprocessor::ExtractCE(Int_t sourceFXS)
661 {
662  //
663  //  Read Central Electrode file from file exchage server
664  //  Keep original entry from OCDB in case no new CE calibration is available
665  //
666  TObjArray    *ceObjects=0;
667  AliTPCCalPad *ceTmean=0;
668  AliTPCCalPad *ceTrms=0;
669  AliTPCCalPad *ceQmean=0;
670  TObjArray    *rocTtime=0;  
671  TObjArray    *rocQtime=0;  
672
673  AliCDBEntry* entry = GetFromOCDB("Calib", "CE");
674  if (entry) ceObjects = (TObjArray*)entry->GetObject();
675  if ( ceObjects==NULL ) {
676      Log("AliTPCPreprocsessor: No previous TPC central electrode entry available.\n");
677      ceObjects = new TObjArray;    
678  }
679
680  Int_t nSectors = fROC->GetNSectors();
681
682  ceTmean = (AliTPCCalPad*)ceObjects->FindObject("CETmean");
683  if ( !ceTmean ) {
684     ceTmean = new AliTPCCalPad("CETmean","CETmean");
685     ceObjects->Add(ceTmean);
686  }
687  ceTrms = (AliTPCCalPad*)ceObjects->FindObject("CETrms");
688  if ( !ceTrms )  { 
689     ceTrms = new AliTPCCalPad("CETrms","CETrms");
690     ceObjects->Add(ceTrms);
691  }
692  ceQmean = (AliTPCCalPad*)ceObjects->FindObject("CEQmean");
693  if ( !ceQmean )  { 
694     ceQmean = new AliTPCCalPad("CEQmean","CEQmean");
695     ceObjects->Add(ceQmean);
696  }
697  //!new from here please have a look!!!
698  rocTtime = (TObjArray*)ceObjects->FindObject("rocTtime");
699  if ( !rocTtime ) {
700      rocTtime = new TObjArray(nSectors);
701      rocTtime->SetName("rocTtime");
702      ceObjects->Add(rocTtime);
703  }
704  
705  rocQtime = (TObjArray*)ceObjects->FindObject("rocQtime");
706  if ( !rocQtime ) {
707      rocQtime = new TObjArray(nSectors);
708      rocQtime->SetName("rocQtime");
709      ceObjects->Add(rocQtime);
710  }
711
712
713  UInt_t result=0;
714
715  TList* list = GetFileSources(sourceFXS,"CE");
716  
717  if (list && list->GetEntries()>0) {
718
719 //  loop through all files from LDCs
720
721     UInt_t index = 0;
722     while (list->At(index)!=NULL) {
723      TObjString* fileNameEntry = (TObjString*) list->At(index);
724      if (fileNameEntry!=NULL) {
725         TString fileName = GetFile(sourceFXS, "CE",
726                                          fileNameEntry->GetString().Data());
727         TFile *f = TFile::Open(fileName);
728         if (!f) {
729           Log ("Error opening central electrode file.");
730           result =2;
731           break;
732         }
733         AliTPCCalibCE *calCE;
734         f->GetObject("tpcCalibCE",calCE);
735
736         //  replace entries for the sectors available in the present file
737
738         for (Int_t sector=0; sector<nSectors; sector++) {
739            AliTPCCalROC *rocTmean=calCE->GetCalRocT0(sector);
740            if ( rocTmean )  ceTmean->SetCalROC(rocTmean,sector);
741            AliTPCCalROC *rocTrms=calCE->GetCalRocRMS(sector);
742            if ( rocTrms )  ceTrms->SetCalROC(rocTrms,sector);
743            AliTPCCalROC *rocQmean=calCE->GetCalRocQ(sector);
744            if ( rocQmean )  ceQmean->SetCalROC(rocQmean,sector);
745            TGraph *grT=calCE->MakeGraphTimeCE(sector,0,2); // T time graph
746            if ( grT ) rocTtime->AddAt(grT,sector);         
747            TGraph *grQ=calCE->MakeGraphTimeCE(sector,0,3); // Q time graph
748            if ( grQ ) rocTtime->AddAt(grQ,sector);         
749         }
750        delete calCE;
751        f->Close();
752       }
753      ++index;
754     }  // while(list)
755 //
756 //  Store updated pedestal entry to OCDB
757 //
758     AliCDBMetaData metaData;
759     metaData.SetBeamPeriod(0);
760     metaData.SetResponsible("Haavard Helstrup");
761     metaData.SetComment("Preprocessor AliTPC data base entries.");
762
763     Bool_t storeOK = Store("Calib", "CE", ceObjects, &metaData, 0, kTRUE);
764     if ( !storeOK ) ++result;
765     
766   } else {
767     Log ("Error: no entries!");
768     result = 1;
769   }
770
771   return result;
772 }
773 //______________________________________________________________________________________________
774
775 UInt_t AliTPCPreprocessor::ExtractQA(Int_t sourceFXS)
776 {
777  //
778  //  Read Quality Assurance file from file exchage server
779  //
780  
781  UInt_t result=0;
782
783  TList* list = GetFileSources(sourceFXS,"QA");
784  
785  if (list && list->GetEntries()>0) {
786
787 //  only one QA objetc should be available!
788
789     AliTPCdataQA *calQA;
790
791     UInt_t nentries = list->GetEntries();  
792     UInt_t index=0;
793     if ( nentries > 1) Log ( "More than one QA entry. First one processed");      
794     TObjString* fileNameEntry = (TObjString*) list->At(index);
795     if (fileNameEntry!=NULL) {
796         TString fileName = GetFile(sourceFXS, "QA",
797                                          fileNameEntry->GetString().Data());
798         TFile *f = TFile::Open(fileName);
799         if (!f) {
800           Log ("Error opening QA file.");
801           result =2;          
802         } else {
803           f->GetObject("tpcCalibQA",calQA);
804       
805 //
806 //  Store updated pedestal entry to OCDB
807 //
808          AliCDBMetaData metaData;
809          metaData.SetBeamPeriod(0);
810          metaData.SetResponsible("Haavard Helstrup");
811          metaData.SetComment("Preprocessor AliTPC data base entries.");
812
813          Bool_t storeOK = Store("Calib", "QA", calQA, &metaData, 0, kTRUE);
814          if ( !storeOK ) ++result;
815         }
816     } else {
817     Log ("Error: no QA files on FXS!");
818     result = 2;
819     }
820   } else {
821     Log ("Error: no QA entries in FXS list!");
822     result = 1;
823   }
824   return result;
825 }
826