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