]> git.uio.no Git - u/mrichter/AliRoot.git/blob - TPC/Base/AliTPCPreprocessor.cxx
ATO-119 - solving merge conflict
[u/mrichter/AliRoot.git] / TPC / Base / 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 "AliTPCCalibRaw.h"
31 #include "AliTPCdataQA.h"
32 #include "ARVersion.h"
33 #include "TFile.h"
34 #include "TTree.h"
35 #include "TGraph.h" 
36 #include "TEnv.h"
37 #include "TParameter.h"
38
39 #include <TTimeStamp.h>
40
41 const Int_t kValCutTemp = 100;               // discard temperatures > 100 degrees
42 const Int_t kDiffCutTemp = 5;                // discard temperature differences > 5 degrees
43 const Double_t kHighVoltageDifference = 1e-4; // don't record High Voltage points 
44                                              // differing by less than 1e-4 from
45                                              // previous point.
46 const Double_t kGasCompositionDifference = 1e-3; // don't record Gas Composition points 
47                                              // differing by less than 1e-3 from
48                                              // previous point
49 const TString kPedestalRunType = "PEDESTAL";  // pedestal run identifier
50 const TString kPulserRunType = "PULSER";     // pulser run identifier
51 const TString kPhysicsRunType = "PHYSICS";   // physics run identifier
52 const TString kCosmicRunType = "COSMIC";     // cosmic run identifier
53 const TString kLaserRunType = "LASER";       // laser run identifier
54 const TString kDaqRunType = "DAQ"; // DAQ run identifier
55 const TString kAmandaTemp = "TPC_PT_%d_TEMPERATURE"; // Amanda string for temperature entries
56 const TString kAmandaDDL = "DDL%d";   // Amanda string for list of active DDLs
57 const Int_t  kNumDDL = 216;           // number of TPC DDLs
58 const Int_t  kFirstDDL = 768;         // identifier of first DDL
59 //const Double_t kFitFraction = 0.7;                 // Fraction of DCS sensor fits required              
60 const Double_t kFitFraction = -1.0;          // Don't require minimum number of fits in commissioning run 
61 const Int_t   kNumPressureSensors = 3;    // number of pressure sensors
62 const char* kPressureSensorNames[kNumPressureSensors] = {
63                    "CavernAtmosPressure",
64                    "CavernAtmosPressure2",
65                    "SurfaceAtmosPressure" };
66 const Int_t  kMinCESectors = 32;      // minimum number of sectors (per side)
67                                       // to accept CE calibration
68       
69
70 //
71 // This class is the SHUTTLE preprocessor for the TPC detector.
72 //
73
74 ClassImp(AliTPCPreprocessor)
75
76 //______________________________________________________________________________________________
77 AliTPCPreprocessor::AliTPCPreprocessor(AliShuttleInterface* shuttle) :
78   AliPreprocessor("TPC",shuttle),
79   fConfEnv(0), fTemp(0), fHighVoltage(0), fHighVoltageStat(0), fGoofie(0),
80   fPressure(0), fGasComposition(0), fConfigOK(kTRUE), fROC(0)
81 {
82   // constructor
83   fROC = AliTPCROC::Instance();
84
85   // define run types to be processed
86   
87   AddRunType(kPedestalRunType);
88   AddRunType(kPulserRunType);
89   AddRunType(kPhysicsRunType);
90   AddRunType(kCosmicRunType);
91   AddRunType(kLaserRunType);
92   AddRunType(kDaqRunType);
93   
94 }
95 //______________________________________________________________________________________________
96  AliTPCPreprocessor::AliTPCPreprocessor(const AliTPCPreprocessor&  ) :
97    AliPreprocessor("TPC",0),
98    fConfEnv(0), fTemp(0), fHighVoltage(0), fHighVoltageStat(0), fGoofie(0),
99    fPressure(0), fGasComposition(0), fConfigOK(kTRUE), fROC(0)
100  {
101
102    Fatal("AliTPCPreprocessor", "copy constructor not implemented");
103 //
104 // //  fTemp = new AliTPCSensorTempArray(*(org.fTemp));
105  }
106
107 //______________________________________________________________________________________________
108 AliTPCPreprocessor::~AliTPCPreprocessor()
109 {
110   // destructor
111
112   delete fTemp;
113   delete fHighVoltage;
114   delete fHighVoltageStat;
115   delete fGoofie;
116   delete fGasComposition;
117   delete fPressure;
118 }
119 //______________________________________________________________________________________________
120 AliTPCPreprocessor& AliTPCPreprocessor::operator = (const AliTPCPreprocessor& )
121 {
122   Fatal("operator =", "assignment operator not implemented");
123   return *this;
124 }
125
126
127 //______________________________________________________________________________________________
128 void AliTPCPreprocessor::Initialize(Int_t run, UInt_t startTime,
129         UInt_t endTime)
130 {
131
132   AliPreprocessor::Initialize(run, startTime, endTime);
133
134         AliInfo(Form("\n\tRun %d \n\tStartTime %s \n\tEndTime %s", run,
135                 TTimeStamp((time_t)startTime,0).AsString(),
136                 TTimeStamp((time_t)endTime,0).AsString()));
137
138   // Preprocessor configuration
139
140         AliCDBEntry* entry = GetFromOCDB("Config", "Preprocessor");
141         if (entry) fConfEnv = (TEnv*) entry->GetObject();
142         if ( fConfEnv==0 ) {
143            Log("AliTPCPreprocsessor: Preprocessor Config OCDB entry missing.\n");
144            fConfigOK = kFALSE;
145            return;
146         }
147
148   // Temperature sensors
149
150        TTree *confTree = 0;
151
152        TString tempConf = fConfEnv->GetValue("Temperature","ON");
153        tempConf.ToUpper();
154        if (tempConf != "OFF" ) {
155         entry = GetFromOCDB("Config", "Temperature");
156         if (entry) confTree = (TTree*) entry->GetObject();
157         if ( confTree==0 ) {
158            Log("AliTPCPreprocsessor: Temperature Config OCDB entry missing.\n");
159            fConfigOK = kFALSE;
160            return;
161         }
162         fTemp = new AliTPCSensorTempArray(startTime, endTime, confTree, kAmandaTemp);
163         fTemp->SetValCut(kValCutTemp);
164         fTemp->SetDiffCut(kDiffCutTemp);
165        }
166
167   // High voltage measurements
168
169       TString hvConf = fConfEnv->GetValue("HighVoltage","ON");
170       hvConf.ToUpper();
171       if (hvConf != "OFF" ) { 
172         confTree=0;
173         entry=0;
174         entry = GetFromOCDB("Config", "HighVoltage");
175         if (entry) confTree = (TTree*) entry->GetObject();
176         if ( confTree==0 ) {
177            Log("AliTPCPreprocsessor: High Voltage Config OCDB entry missing.\n");
178            fConfigOK = kFALSE;
179            return;
180         }
181         time_t timeStart = (time_t)(((TString)GetRunParameter("DAQ_time_start")).Atoi());
182         time_t timeEnd = (time_t)(((TString)GetRunParameter("DAQ_time_end")).Atoi());
183         fHighVoltage = new AliDCSSensorArray (UInt_t(timeStart), 
184                                             UInt_t(timeEnd), confTree);
185       }
186
187    // High voltage status values
188      
189       TString hvStatConf = fConfEnv->GetValue("HighVoltageStat","ON");
190       hvStatConf.ToUpper();
191       if (hvStatConf != "OFF" ) { 
192         confTree=0;
193         entry=0;
194         entry = GetFromOCDB("Config", "HighVoltageStat");
195         if (entry) confTree = (TTree*) entry->GetObject();
196         if ( confTree==0 ) {
197            Log("AliTPCPreprocsessor: High Voltage Status Config OCDB entry missing.\n");
198            fConfigOK = kFALSE;
199            return;
200         }
201         fHighVoltageStat = new AliDCSSensorArray(startTime, endTime, confTree);
202       }
203
204    // Goofie values
205      
206       TString goofieConf = fConfEnv->GetValue("Goofie","ON");
207       goofieConf.ToUpper();
208       if (goofieConf != "OFF" ) { 
209         confTree=0;
210         entry=0;
211         entry = GetFromOCDB("Config", "Goofie");
212         if (entry) confTree = (TTree*) entry->GetObject();
213         if ( confTree==0 ) {
214            Log("AliTPCPreprocsessor: Goofie Config OCDB entry missing.\n");
215            fConfigOK = kFALSE;
216            return;
217         }
218         fGoofie = new AliDCSSensorArray(startTime, endTime, confTree);
219       }
220
221
222   // Gas composition measurements
223
224       TString gasConf = fConfEnv->GetValue("GasComposition","OFF");
225       gasConf.ToUpper();
226       if (gasConf != "OFF" ) { 
227         confTree=0;
228         entry=0;
229         entry = GetFromOCDB("Config", "GasComposition");
230         if (entry) confTree = (TTree*) entry->GetObject();
231         if ( confTree==0 ) {
232            Log("AliTPCPreprocsessor: Gas Composition Config OCDB entry missing.\n");
233            fConfigOK = kFALSE;
234            return;
235         }
236         time_t timeStart = (time_t)(((TString)GetRunParameter("DAQ_time_start")).Atoi());
237         time_t timeEnd = (time_t)(((TString)GetRunParameter("DAQ_time_end")).Atoi());
238         fGasComposition = new AliDCSSensorArray (UInt_t(timeStart), 
239                                             UInt_t(timeEnd), confTree);
240       }
241    // Pressure values
242      
243        TString runType = GetRunType();
244
245        if( runType == kPhysicsRunType || 
246         runType == kLaserRunType ) {    
247        TString pressureConf = fConfEnv->GetValue("Pressure","ON");
248        pressureConf.ToUpper();
249        if (pressureConf != "OFF" ) { 
250          TClonesArray * array = new TClonesArray("AliDCSSensor",kNumPressureSensors); 
251          for(Int_t j = 0; j < kNumPressureSensors; j++) {
252            AliDCSSensor * sens = new ((*array)[j])AliDCSSensor;
253            sens->SetStringID(kPressureSensorNames[j]);
254          }
255          fPressure = new AliDCSSensorArray(startTime, endTime, array);
256        }
257      }
258 }
259
260 //______________________________________________________________________________________________
261 UInt_t AliTPCPreprocessor::Process(TMap* dcsAliasMap)
262 {
263   // Fills data into TPC calibrations objects
264
265   // Amanda servers provide information directly through dcsAliasMap
266
267   
268   if (!fConfigOK) return 9;
269   UInt_t result = 0;
270   TObjArray *resultArray = new TObjArray();
271   TString errorHandling = fConfEnv->GetValue("ErrorHandling","ON");
272   errorHandling.ToUpper();
273   TObject * status;
274
275   UInt_t dcsResult=0;
276   if (!dcsAliasMap) { 
277      dcsResult=1;
278   } else {
279      if (dcsAliasMap->GetEntries() == 0 ) dcsResult=1;
280   }  
281   status = new TParameter<int>("dcsResult",dcsResult);
282   resultArray->Add(status);
283
284
285   TString runType = GetRunType();
286
287   if ( dcsResult == 0 ) {
288
289   // Temperature sensors are processed by AliTPCCalTemp
290
291     TString tempConf = fConfEnv->GetValue("Temperature","ON");
292     tempConf.ToUpper();
293     if (tempConf != "OFF" ) {
294       UInt_t tempResult = MapTemperature(dcsAliasMap);
295       if ( tempConf != "TRY") result+=tempResult;
296       status = new TParameter<int>("tempResult",tempResult);
297       resultArray->Add(status);
298     }
299
300   // High Voltage recordings
301
302
303     TString hvConf = fConfEnv->GetValue("HighVoltage","ON");
304     hvConf.ToUpper();
305     if (hvConf != "OFF" ) { 
306      UInt_t hvResult = MapHighVoltage(dcsAliasMap);
307      if (hvConf != "TRY") result+=hvResult;
308      status = new TParameter<int>("hvResult",hvResult);
309      resultArray->Add(status);
310     }
311
312     // Goofie values
313
314
315     TString goofieConf = fConfEnv->GetValue("Goofie","ON");
316     goofieConf.ToUpper();
317     if (goofieConf != "OFF" ) { 
318      UInt_t goofieResult = MapGoofie(dcsAliasMap);
319      if (goofieConf != "TRY") result+=goofieResult;
320      status = new TParameter<int>("goofieResult",goofieResult);
321      resultArray->Add(status);
322     }
323
324
325     // Gas composition recordings
326
327
328     TString gasConf = fConfEnv->GetValue("GasComposition","OFF");
329     gasConf.ToUpper();
330     if (gasConf != "OFF" ) { 
331      UInt_t gasResult = MapGasComposition(dcsAliasMap);
332      if (gasConf != "TRY") result+=gasResult;
333      status = new TParameter<int>("gasResult",gasResult);
334      resultArray->Add(status);
335     }
336
337     // Pressure values
338
339     if( runType == kPhysicsRunType || 
340       runType == kLaserRunType ) {    
341
342       TString pressureConf = fConfEnv->GetValue("Pressure","ON");
343       pressureConf.ToUpper();
344       if (pressureConf != "OFF" ) { 
345        UInt_t pressureResult = MapPressure(dcsAliasMap);
346        status = new TParameter<int>("pressureResult",pressureResult);
347        resultArray->Add(status);
348       }
349     }
350   }
351   // Other calibration information will be retrieved through FXS files
352   //  examples:
353   //    TList* fileSourcesDAQ = GetFile(AliShuttleInterface::kDAQ, "pedestals");
354   //    const char* fileNamePed = GetFile(AliShuttleInterface::kDAQ, "pedestals", "LDC1");
355   //
356   //    TList* fileSourcesHLT = GetFile(AliShuttleInterface::kHLT, "calib");
357   //    const char* fileNameHLT = GetFile(AliShuttleInterface::kHLT, "calib", "LDC1");
358
359   // pedestal entries
360
361   if(runType == kPedestalRunType) {
362     Int_t numSources = 1;
363     Int_t pedestalSource[2] = {AliShuttleInterface::kDAQ,AliShuttleInterface::kHLT} ;
364     TString source = fConfEnv->GetValue("Pedestal","DAQ");
365     source.ToUpper();
366     if (source != "OFF" ) { 
367      if ( source == "HLT") pedestalSource[0] = AliShuttleInterface::kHLT;
368      if (!GetHLTStatus()) pedestalSource[0] = AliShuttleInterface::kDAQ;
369      if (source == "HLTDAQ" ) {
370          numSources=2;
371          pedestalSource[0] = AliShuttleInterface::kHLT;
372          pedestalSource[1] = AliShuttleInterface::kDAQ;
373      }
374      if (source == "DAQHLT" ) numSources=2;
375      UInt_t pedestalResult=0;
376      for (Int_t i=0; i<numSources; i++ ) {      
377        pedestalResult = ExtractPedestals(pedestalSource[i]);
378        if ( pedestalResult == 0 ) break;
379      }
380      result += pedestalResult;
381      status = new TParameter<int>("pedestalResult",pedestalResult);
382      resultArray->Add(status);
383     }
384   }
385
386   // pulser trigger processing
387
388   if(runType == kPulserRunType) {
389     Int_t numSources = 1;
390     Int_t pulserSource[2] = {AliShuttleInterface::kDAQ,AliShuttleInterface::kHLT} ;
391     TString source = fConfEnv->GetValue("Pulser","DAQ");
392     source.ToUpper();
393     if ( source != "OFF") { 
394      if ( source == "HLT") pulserSource[0] = AliShuttleInterface::kHLT;
395      if (!GetHLTStatus()) pulserSource[0] = AliShuttleInterface::kDAQ;
396      if (source == "HLTDAQ" ) {
397          numSources=2;
398          pulserSource[0] = AliShuttleInterface::kHLT;
399          pulserSource[1] = AliShuttleInterface::kDAQ;
400      }
401      if (source == "DAQHLT" ) numSources=2;
402      if (source == "TRY" ) numSources=2;
403      UInt_t pulserResult=0;
404      for (Int_t i=0; i<numSources; i++ ) {      
405        pulserResult = ExtractPulser(pulserSource[i]);
406        if ( pulserResult == 0 ) break;
407      }
408      if (source != "TRY") result += pulserResult;
409      status = new TParameter<int>("pulserResult",pulserResult);
410      resultArray->Add(status);
411     }
412   }
413
414
415 // raw calibration processing
416
417   if(runType == kPhysicsRunType) {
418     Int_t numSources = 1;
419     Int_t rawSource[2] = {AliShuttleInterface::kDAQ,AliShuttleInterface::kHLT} ;
420     TString source = fConfEnv->GetValue("Raw","DAQ");
421     source.ToUpper();
422     if ( source != "OFF") { 
423      if ( source == "HLT") rawSource[0] = AliShuttleInterface::kHLT;
424      if (!GetHLTStatus()) rawSource[0] = AliShuttleInterface::kDAQ;
425      if (source == "HLTDAQ" ) {
426          numSources=2;
427          rawSource[0] = AliShuttleInterface::kHLT;
428          rawSource[1] = AliShuttleInterface::kDAQ;
429      }
430      if (source == "DAQHLT" ) numSources=2;
431      if (source == "TRY" ) numSources=2;
432      UInt_t rawResult=0;
433      for (Int_t i=0; i<numSources; i++ ) {      
434        rawResult = ExtractRaw(rawSource[i]);
435        if ( rawResult == 0 ) break;
436      }
437      if (source != "TRY" )result += rawResult;
438      status = new TParameter<int>("rawResult",rawResult);
439      resultArray->Add(status);
440     }
441   }
442
443
444   // Altro configuration
445
446
447   TString altroConf = fConfEnv->GetValue("AltroConf","ON");
448   altroConf.ToUpper();
449   if (altroConf != "OFF" ) { 
450    UInt_t altroResult = ExtractAltro(AliShuttleInterface::kDCS,dcsAliasMap);
451    if (altroConf != "TRY" ) result+=altroResult;
452    status = new TParameter<int>("altroResult",altroResult);
453    resultArray->Add(status);
454  }
455
456
457   // Central Electrode processing
458
459   if( runType == kPhysicsRunType || 
460       runType == kLaserRunType ) {    
461
462     Int_t numSources = 1;
463     Int_t ceSource[2] = {AliShuttleInterface::kDAQ,AliShuttleInterface::kHLT} ;
464     TString source = fConfEnv->GetValue("CE","DAQ");
465     source.ToUpper();
466     if ( source != "OFF" ) { 
467      if ( source == "HLT") ceSource[0] = AliShuttleInterface::kHLT;
468      if (!GetHLTStatus()) ceSource[0] = AliShuttleInterface::kDAQ;
469      if (source == "HLTDAQ" ) {
470         numSources=2;
471         ceSource[0] = AliShuttleInterface::kHLT;
472         ceSource[1] = AliShuttleInterface::kDAQ;
473      }
474      if (source == "DAQHLT" ) numSources=2;
475      if (source == "TRY" ) numSources=2;
476      UInt_t ceResult=0;
477      for (Int_t i=0; i<numSources; i++ ) {      
478        ceResult = ExtractCE(ceSource[i]);
479        if ( ceResult == 0 ) break;
480      }
481
482    // only flag error if CE result is missing from LASER runs
483    //    -- for PHYSICS run do CE processing if data available
484    
485      if ( runType == kLaserRunType && source != "TRY"  && ceResult<10 ) result += ceResult;
486      status = new TParameter<int>("ceResult",ceResult);
487      resultArray->Add(status);
488
489     numSources = 1;
490     Int_t qaSource[2] = {AliShuttleInterface::kDAQ,AliShuttleInterface::kHLT} ;
491     source = fConfEnv->GetValue("QA","DAQ");
492     source.ToUpper();
493     if ( source != "OFF" ) { 
494      if ( source == "HLT") qaSource[0] = AliShuttleInterface::kHLT;
495      if (!GetHLTStatus()) qaSource[0] = AliShuttleInterface::kDAQ;
496      if (source == "HLTDAQ" ) {
497         numSources=2;
498         qaSource[0] = AliShuttleInterface::kHLT;
499         qaSource[1] = AliShuttleInterface::kDAQ;
500      }
501      if (source == "DAQHLT" ) numSources=2;
502      if (source == "TRY" ) numSources=2;
503      UInt_t qaResult=0;
504      for (Int_t i=0; i<numSources; i++ ) {      
505        qaResult = ExtractQA(qaSource[i]);
506        if ( qaResult == 0 ) break;
507      }
508 //     result += qaResult;
509      if ( qaResult !=0 ) Log ("ExtractQA failed, no QA entry available.");
510      status = new TParameter<int>("qaResult",qaResult);
511      resultArray->Add(status);
512     }
513    }
514   }
515   
516 // Store component status to OCDB
517
518   AliCDBMetaData metaData;
519   metaData.SetBeamPeriod(0);
520   metaData.SetResponsible("Haavard Helstrup");
521   metaData.SetAliRootVersion(ALIROOT_BRANCH);
522   metaData.SetComment("Preprocessor AliTPC status.");
523   Bool_t storeOK = Store("Calib", "PreprocStatus", resultArray, &metaData, 0,  kFALSE);
524   if (!storeOK) Log ("Unable to store preprocessor status entry");
525  
526   resultArray->Delete();
527   delete resultArray;
528
529   if (errorHandling == "OFF" ) return 0;
530   return result;
531   
532 }
533 //______________________________________________________________________________________________
534 UInt_t AliTPCPreprocessor::MapTemperature(TMap* dcsAliasMap)
535 {
536
537    // extract DCS temperature maps. Perform fits to save space
538
539   UInt_t result=0;
540   TMap *map = fTemp->ExtractDCS(dcsAliasMap);
541   if (map) {
542     fTemp->MakeSplineFit(map);
543     Double_t fitFraction = 1.0*fTemp->NumFits()/fTemp->NumSensors(); 
544     if (fitFraction > kFitFraction ) {
545       AliInfo(Form("Temperature values extracted, fits performed.\n"));
546     } else { 
547       Log ("Too few temperature maps fitted. \n");
548       result = 9;
549     }
550   } else {
551     Log("No temperature map extracted. \n");
552     result=9;
553   }
554   delete map;
555   // Now store the final CDB file
556
557   if ( result == 0 ) {
558         AliCDBMetaData metaData;
559         metaData.SetBeamPeriod(0);
560         metaData.SetResponsible("Haavard Helstrup");
561         metaData.SetAliRootVersion(ALIROOT_BRANCH);
562         metaData.SetComment("Preprocessor AliTPC data base entries.");
563
564         Bool_t storeOK = Store("Calib", "Temperature", fTemp, &metaData, 0, kFALSE);
565         if ( !storeOK )  result=1;
566
567    }
568
569    return result;
570
571 }
572 //______________________________________________________________________________________________
573 UInt_t AliTPCPreprocessor::MapPressure(TMap* dcsAliasMap)
574 {
575
576    // extract DCS pressure maps. Perform fits to save space
577
578   UInt_t result=0;
579   TMap *map = fPressure->ExtractDCS(dcsAliasMap);
580   if (map) {
581     fPressure->MakeSplineFit(map);
582     Double_t fitFraction = 1.0*fPressure->NumFits()/fPressure->NumSensors(); 
583     if (fitFraction > kFitFraction ) {
584       AliInfo(Form("Pressure values extracted, fits performed.\n"));
585     } else { 
586       Log ("Too few pressure maps fitted. \n");
587       result = 9;
588     }
589   } else {
590     Log("No pressure map extracted. \n");
591     result=9;
592   }
593   delete map;
594   return result;
595 }
596
597 //______________________________________________________________________________________________
598 UInt_t AliTPCPreprocessor::MapHighVoltage(TMap* dcsAliasMap)
599 {
600
601    // extract DCS HV maps. Perform fits to save space
602
603   UInt_t result=0;
604   TMap *map = fHighVoltage->ExtractDCS(dcsAliasMap);
605   if (map) {
606     fHighVoltage->ClearFit();
607     fHighVoltage->RemoveGraphDuplicates(kHighVoltageDifference);
608                // don't keep new point if too similar to previous one
609     fHighVoltage->SetGraph(map);
610   } else {
611     Log("No high voltage recordings extracted. \n");
612     result=9;
613   }
614   delete map;
615
616   TString hvStatConf = fConfEnv->GetValue("HighVoltageStat","ON");
617   hvStatConf.ToUpper();
618   if (hvStatConf != "OFF" ) { 
619     TMap *map2 = fHighVoltageStat->ExtractDCS(dcsAliasMap);
620     if (map2) {
621       fHighVoltageStat->ClearFit();
622       fHighVoltageStat->SetGraph(map2);
623     } else {
624        Log("No high voltage status recordings extracted. \n");
625       result=9;
626     }
627     delete map2;
628
629     // add status maps to high voltage sensor array
630
631     fHighVoltage->AddSensors(fHighVoltageStat);
632    }
633   // Now store the final CDB file
634
635   if ( result == 0 ) {
636         AliCDBMetaData metaData;
637         metaData.SetBeamPeriod(0);
638         metaData.SetResponsible("Haavard Helstrup");
639         metaData.SetAliRootVersion(ALIROOT_BRANCH);
640         metaData.SetComment("Preprocessor AliTPC data base entries.");
641
642         Bool_t storeOK = Store("Calib", "HighVoltage", fHighVoltage, &metaData, 0, kFALSE);
643         if ( !storeOK )  result=1;
644
645    }
646
647    return result;
648
649 }
650
651 //______________________________________________________________________________________________
652 UInt_t AliTPCPreprocessor::MapGoofie(TMap* dcsAliasMap)
653 {
654
655    // extract DCS Goofie maps. Do not perform fits (low update rate)
656
657   UInt_t result=0;
658
659   TMap *map = fGoofie->ExtractDCS(dcsAliasMap);
660   if (map) {
661     fGoofie->ClearFit();
662     fGoofie->SetGraph(map);
663   } else {
664     Log("No Goofie recordings extracted. \n");
665     result=9;
666   }
667   delete map;
668
669   // Now store the final CDB file
670
671   if ( result == 0 ) {
672         AliCDBMetaData metaData;
673         metaData.SetBeamPeriod(0);
674         metaData.SetResponsible("Haavard Helstrup");
675         metaData.SetAliRootVersion(ALIROOT_BRANCH);
676         metaData.SetComment("Preprocessor AliTPC data base entries.");
677
678         Bool_t storeOK = Store("Calib", "Goofie", fGoofie, &metaData, 0, kFALSE);
679         if ( !storeOK )  result=1;
680
681    }
682
683    return result;
684
685 }
686
687 //______________________________________________________________________________________________
688 UInt_t AliTPCPreprocessor::MapGasComposition(TMap* dcsAliasMap)
689 {
690
691    // extract DCS HV maps. Perform fits to save space
692
693   UInt_t result=0;
694   TMap *map = fGasComposition->ExtractDCS(dcsAliasMap);
695   if (map) {
696     fGasComposition->ClearFit();
697     fGasComposition->RemoveGraphDuplicates(kGasCompositionDifference);
698                // don't keep new point if too similar to previous one
699     fGasComposition->SetGraph(map);
700   } else {
701     Log("No gas composition recordings extracted. \n");
702     result=9;
703   }
704   delete map;
705
706   // Now store the final CDB file
707
708   if ( result == 0 ) {
709         AliCDBMetaData metaData;
710         metaData.SetBeamPeriod(0);
711         metaData.SetResponsible("Haavard Helstrup");
712         metaData.SetAliRootVersion(ALIROOT_BRANCH);
713         metaData.SetComment("Preprocessor AliTPC data base entries.");
714
715         Bool_t storeOK = Store("Calib", "GasComposition", fGasComposition, &metaData, 0, kFALSE);
716         if ( !storeOK )  result=1;
717
718    }
719
720    return result;
721
722 }
723
724
725 //______________________________________________________________________________________________
726
727 UInt_t AliTPCPreprocessor::ExtractPedestals(Int_t sourceFXS)
728 {
729  //
730  //  Read pedestal file from file exchage server
731  //  Keep original entry from OCDB in case no new pedestals are available
732  //
733  AliTPCCalPad *calPadPedOCDB=0;
734  AliCDBEntry* entry = GetFromOCDB("Calib", "Pedestals");
735  if (entry) calPadPedOCDB = (AliTPCCalPad*)entry->GetObject();
736  if ( calPadPedOCDB==NULL ) {
737      Log("AliTPCPreprocsessor: No previous TPC pedestal entry available.\n");
738  }
739
740  AliTPCCalPad *calPadRMSOCDB=0;
741  entry = GetFromOCDB("Calib", "PadNoise");
742  if (entry) calPadRMSOCDB = (AliTPCCalPad*)entry->GetObject();
743  if ( calPadRMSOCDB==NULL ) {
744      Log("AliTPCPreprocsessor: No previous TPC noise entry available.\n");
745  }
746
747   AliTPCCalPad* calPadPed = new AliTPCCalPad("PedestalsMean","PedestalsMean");
748   AliTPCCalPad* calPadRMS = new AliTPCCalPad("PedestalsRMS","PedestalsRMS");
749
750
751  UInt_t result=0;
752
753  Int_t nSectors = fROC->GetNSectors();
754  TVectorD foundSectorsPed(nSectors);
755  foundSectorsPed=0;
756  TVectorD foundSectorsRMS(nSectors);
757  foundSectorsRMS=0;
758
759  TList* list = GetFileSources(sourceFXS,"pedestals");
760  
761  if (list && list->GetEntries()>0) {
762
763 //  loop through all files from LDCs
764
765     Bool_t changed=false;
766     UInt_t index = 0;
767     while (list->At(index)!=NULL) {
768      TObjString* fileNameEntry = (TObjString*) list->At(index);
769      if (fileNameEntry!=NULL) {
770         TString fileName = GetFile(sourceFXS, "pedestals",
771                                          fileNameEntry->GetString().Data());
772         TFile *f = TFile::Open(fileName);
773         if (!f) {
774           Log ("Error opening pedestal file.");
775           result =2;
776           break;
777         }
778         AliTPCCalibPedestal *calPed;
779         f->GetObject("tpcCalibPedestal",calPed);
780         if ( !calPed ) {
781           Log ("No pedestal calibration object in file.");
782           result = 2;
783           break;
784         }
785
786         //  replace entries for the sectors available in the present file
787
788         changed=true;
789         for (Int_t sector=0; sector<nSectors; sector++) {
790            AliTPCCalROC *rocPed=calPed->GetCalRocPedestal(sector, kFALSE);
791            if ( rocPed ) {
792                AliTPCCalROC* roc=calPadPed->GetCalROC(sector);
793                roc->Add(rocPed,1);
794                foundSectorsPed[sector]++;
795            }
796            AliTPCCalROC *rocRMS=calPed->GetCalRocRMS(sector, kFALSE);
797            if ( rocRMS )  {
798                AliTPCCalROC* roc=calPadRMS->GetCalROC(sector);
799                roc->Add(rocRMS,1);
800                foundSectorsRMS[sector]++;
801            } 
802         }
803         delete calPed; 
804         f->Close();
805       }
806      ++index;
807     }  // while(list)
808
809 //
810 //  Check if calibration is complete -- otherwise take from old OCDB entry
811
812 // inner sectors
813     for (Int_t sector=0; sector<nSectors/2; sector++) {
814        if (foundSectorsPed[sector] < 1 ) {
815           if (calPadPedOCDB) {
816             AliTPCCalROC *rocOCDB=calPadPedOCDB->GetCalROC(sector);
817             calPadPed->SetCalROC(rocOCDB,sector);
818           } else {
819             const int mess_length=100;
820             char message[mess_length];
821             snprintf(message,mess_length,"Missing pedestals for sector %d - also not available from previous OCDB entry.\n",
822                      sector);
823             Log (message);
824             result = 2;
825           }
826        }
827        if (foundSectorsRMS[sector] < 1 ) {
828           if (calPadRMSOCDB) {
829             AliTPCCalROC *rocOCDB=calPadRMSOCDB->GetCalROC(sector);
830             calPadRMS->SetCalROC(rocOCDB,sector);
831           } else {
832             const int mess_length=100;
833             char message[mess_length];
834             snprintf(message,mess_length,"Missing pedestal RMS for sector %d - also not available from previous OCDB entry.\n",
835                      sector);
836             Log (message);
837             result = 2;
838           }       
839        }
840     }
841
842 // outer sectors -- two updates needed
843
844     for (Int_t sector=nSectors/2; sector<nSectors; sector++) {
845        if (foundSectorsPed[sector] < 2 ) {
846           if (calPadPedOCDB) {
847             AliTPCCalROC *rocOCDB=calPadPedOCDB->GetCalROC(sector);
848             calPadPed->SetCalROC(rocOCDB,sector);
849           } else {
850             const int mess_length=100;
851             char message[mess_length];
852             snprintf(message,mess_length,"Missing pedestals for sector %d - also not available from previous OCDB entry.\n",
853                      sector);
854             Log (message);
855             result = 2;
856           }
857
858        }
859        if (foundSectorsRMS[sector] < 2 ) {
860           if (calPadRMSOCDB) {
861             AliTPCCalROC *rocOCDB=calPadRMSOCDB->GetCalROC(sector);
862             calPadRMS->SetCalROC(rocOCDB,sector);
863           } else {
864             const int mess_length=100;
865             char message[mess_length];
866             snprintf(message,mess_length,"Missing pedestal RMS for sector %d - also not available from previous OCDB entry.\n",
867                      sector);
868             Log (message);
869             result = 2;
870           }       
871
872        }       
873     }
874
875     
876 //
877 //  Store updated pedestal entry to OCDB
878 //
879     if (changed) {
880      AliCDBMetaData metaData;
881      metaData.SetBeamPeriod(0);
882      metaData.SetResponsible("Haavard Helstrup");
883      metaData.SetAliRootVersion(ALIROOT_BRANCH);
884      metaData.SetComment("Preprocessor AliTPC data base entries."); 
885  
886      Bool_t storeOK = Store("Calib", "Pedestals", calPadPed, &metaData, 0, kTRUE);
887      if ( !storeOK ) ++result;
888      storeOK = Store("Calib", "PadNoise", calPadRMS, &metaData, 0, kTRUE);
889      if ( !storeOK ) ++result;
890     }
891   } else {
892     Log ("Error: no entries in pedestal file list!");
893     result = 1;
894   }
895
896   delete calPadPed;
897   delete calPadRMS;
898   delete calPadPedOCDB;
899   delete calPadRMSOCDB;
900
901   return result;
902 }
903
904 //______________________________________________________________________________________________
905
906
907 UInt_t AliTPCPreprocessor::ExtractPulser(Int_t sourceFXS)
908 {
909  //
910  //  Read pulser calibration file from file exchage server
911  //  Keep original entry from OCDB in case no new pulser calibration is available
912  //
913  
914  TObjArray *pulserObjects = new TObjArray;
915  TObjArray *pulserObjectsOCDB=0;   
916   
917  AliCDBEntry* entry = GetFromOCDB("Calib", "Pulser");
918  if (entry) pulserObjectsOCDB = (TObjArray*)entry->GetObject();
919  if ( pulserObjectsOCDB==NULL ) {
920      Log("AliTPCPreprocsessor: No previous TPC pulser entry available.\n");
921  }
922
923  AliTPCCalPad *pulserTmean = new AliTPCCalPad("PulserTmean","PulserTmean");
924  pulserObjects->Add(pulserTmean);
925  
926  AliTPCCalPad *pulserTrms = new AliTPCCalPad("PulserTrms","PulserTrms");
927  pulserObjects->Add(pulserTrms);
928  
929  AliTPCCalPad *pulserQmean = new AliTPCCalPad("PulserQmean","PulserQmean");
930  pulserObjects->Add(pulserQmean);
931  
932
933
934  UInt_t result=0;
935
936  Int_t nSectors = fROC->GetNSectors();
937  TVectorD foundTmean(nSectors);
938  foundTmean=0;
939  TVectorD foundTrms(nSectors);
940  foundTrms=0;
941  TVectorD foundQmean(nSectors);
942  foundQmean=0;
943
944
945  TList* list = GetFileSources(sourceFXS,"pulser");
946  
947  if (list && list->GetEntries()>0) {
948
949 //  loop through all files from LDCs
950
951     Bool_t changed=false;
952     UInt_t index = 0;
953     while (list->At(index)!=NULL) {
954      TObjString* fileNameEntry = (TObjString*) list->At(index);
955      if (fileNameEntry!=NULL) {
956         TString fileName = GetFile(sourceFXS, "pulser",
957                                          fileNameEntry->GetString().Data());
958         TFile *f = TFile::Open(fileName);
959         if (!f) {
960           Log ("Error opening pulser file.");
961           result =2;
962           break;
963         }
964         AliTPCCalibPulser *calPulser;
965         f->GetObject("tpcCalibPulser",calPulser);
966         if ( !calPulser ) {
967           Log ("No pulser calibration object in file.");
968           result = 2;
969           break;
970         }
971
972         //  replace entries for the sectors available in the present file
973
974         changed=true;
975         for (Int_t sector=0; sector<nSectors; sector++) {
976            AliTPCCalROC *rocTmean=calPulser->GetCalRocT0(sector);
977            if ( rocTmean ) {
978                AliTPCCalROC* roc=pulserTmean->GetCalROC(sector);
979                roc->Add(rocTmean,1);
980                foundTmean[sector]++;
981            }
982            AliTPCCalROC *rocTrms=calPulser->GetCalRocRMS(sector);
983            if ( rocTrms ) {
984                AliTPCCalROC* roc=pulserTrms->GetCalROC(sector);
985                roc->Add(rocTrms,1);
986                foundTrms[sector]++;
987            }
988            AliTPCCalROC *rocQmean=calPulser->GetCalRocQ(sector);
989            if ( rocQmean ) {
990                AliTPCCalROC* roc=pulserQmean->GetCalROC(sector);
991                roc->Add(rocQmean,1);
992                foundQmean[sector]++;
993            }
994         }
995        delete calPulser;
996        f->Close();
997       }
998      ++index;
999     }  // while(list)
1000
1001
1002
1003
1004 if (pulserObjectsOCDB) {
1005   AliTPCCalPad* pulserTmeanOCDB = (AliTPCCalPad*)pulserObjectsOCDB->FindObject("PulserTmean");
1006   AliTPCCalPad* pulserTrmsOCDB  = (AliTPCCalPad*)pulserObjectsOCDB->FindObject("PulserTrms");
1007   AliTPCCalPad* pulserQmeanOCDB = (AliTPCCalPad*)pulserObjectsOCDB->FindObject("PulserQmean");
1008  
1009 //
1010 //  Check if calibration is complete -- otherwise take from old OCDB entry
1011
1012 // inner sectors
1013     for (Int_t sector=0; sector<nSectors/2; sector++) {
1014        if (foundTmean[sector] < 1 ) {
1015          if (pulserTmeanOCDB) {
1016           AliTPCCalROC* rocOCDB = pulserTmeanOCDB->GetCalROC(sector);
1017           if ( rocOCDB ) pulserTmean->SetCalROC(rocOCDB,sector);
1018          }
1019        }
1020        if (foundTrms[sector] < 1 ) {
1021          if (pulserTrmsOCDB) {
1022           AliTPCCalROC* rocOCDB = pulserTrmsOCDB->GetCalROC(sector);
1023           if ( rocOCDB ) pulserTrms->SetCalROC(rocOCDB,sector);
1024          }
1025        }
1026        if (foundQmean[sector] < 1 ) {
1027          if (pulserQmeanOCDB) {
1028           AliTPCCalROC* rocOCDB = pulserQmeanOCDB->GetCalROC(sector);
1029           if ( rocOCDB ) pulserQmean->SetCalROC(rocOCDB,sector);
1030          }
1031        }
1032     }
1033   
1034 // outer sectors -- two updates needed
1035
1036     for (Int_t sector=0; sector<nSectors/2; sector++) {
1037        if (foundTmean[sector] < 2 ) {
1038          if (pulserTmeanOCDB) {
1039           AliTPCCalROC* rocOCDB = pulserTmeanOCDB->GetCalROC(sector);
1040           if ( rocOCDB ) pulserTmean->SetCalROC(rocOCDB,sector);
1041          }
1042        }
1043        if (foundTrms[sector] < 2 ) {
1044          if (pulserTrmsOCDB) {
1045           AliTPCCalROC* rocOCDB = pulserTrmsOCDB->GetCalROC(sector);
1046           if ( rocOCDB ) pulserTrms->SetCalROC(rocOCDB,sector);
1047          }
1048        }
1049        if (foundQmean[sector] < 2 ) {
1050          if (pulserQmeanOCDB) {
1051           AliTPCCalROC* rocOCDB = pulserQmeanOCDB->GetCalROC(sector);
1052           if ( rocOCDB ) pulserQmean->SetCalROC(rocOCDB,sector);
1053          }
1054        }
1055
1056     }
1057 }
1058
1059 //
1060 //  Store updated pedestal entry to OCDB
1061 //
1062     if (changed) {
1063      AliCDBMetaData metaData;
1064      metaData.SetBeamPeriod(0);
1065      metaData.SetResponsible("Haavard Helstrup");
1066      metaData.SetAliRootVersion(ALIROOT_BRANCH);
1067      metaData.SetComment("Preprocessor AliTPC data base entries.");
1068
1069      Bool_t storeOK = Store("Calib", "Pulser", pulserObjects, &metaData, 0, kTRUE);
1070      if ( !storeOK ) ++result;
1071     }  
1072   } else {
1073     Log ("Error: no entries in pulser file list!");
1074     result = 1;
1075   }
1076   pulserObjects->Delete();
1077   delete pulserObjects;
1078   if (pulserObjectsOCDB) pulserObjectsOCDB->Delete();
1079   delete pulserObjectsOCDB;
1080
1081   return result;
1082 }
1083
1084 //______________________________________________________________________________________________
1085
1086
1087 UInt_t AliTPCPreprocessor::ExtractRaw(Int_t sourceFXS)
1088 {
1089  //
1090  //  Read Raw calibration file from file exchage server
1091  //
1092  
1093  UInt_t result=0;
1094  TObjArray* rawArray = new TObjArray;
1095
1096  TList* list = GetFileSources(sourceFXS,"tpcCalibRaw");
1097  
1098  if (list && list->GetEntries()>0) {
1099
1100 //  loop through all files
1101
1102     UInt_t index = 0;
1103     while (list->At(index)!=NULL) {
1104      TObjString* fileNameEntry = (TObjString*) list->At(index);
1105      if (fileNameEntry!=NULL) {
1106         TString fileName = GetFile(sourceFXS, "tpcCalibRaw",
1107                                          fileNameEntry->GetString().Data());
1108         TFile *f = TFile::Open(fileName);
1109         if (!f) {
1110           Log ("Error opening raw file.");
1111           result =2;
1112           break;
1113         }
1114         AliTPCCalibRaw *calRaw;
1115         f->GetObject("tpcCalibRaw",calRaw);
1116         if ( !calRaw ) {
1117           Log ("No raw calibration object in file.");
1118           result = 2;
1119           break;
1120         }
1121        rawArray->Add(calRaw);
1122        f->Close();
1123       }
1124      ++index;
1125     }  // while(list)
1126 //
1127 //  Store updated pedestal entry to OCDB
1128 //
1129      AliCDBMetaData metaData;
1130      metaData.SetBeamPeriod(0);
1131      metaData.SetResponsible("Haavard Helstrup");
1132      metaData.SetAliRootVersion(ALIROOT_BRANCH);
1133      metaData.SetComment("Preprocessor AliTPC data base entries.");
1134
1135      Bool_t storeOK = Store("Calib", "Raw", rawArray, &metaData, 0, kTRUE);
1136      if ( !storeOK ) ++result;
1137   } else {
1138     Log ("Error: no entries in raw file list!");
1139     result = 1;
1140   }
1141   
1142   rawArray->Delete();
1143   delete rawArray;
1144
1145   return result;
1146 }
1147 //______________________________________________________________________________________________
1148
1149 UInt_t AliTPCPreprocessor::ExtractCE(Int_t sourceFXS)
1150 {
1151  //
1152  //  Read Central Electrode file from file exchage server
1153  //
1154  //
1155   AliTPCCalPad *ceTmean=0;
1156   AliTPCCalPad *ceTrms=0;
1157   AliTPCCalPad *ceQmean=0;
1158   TObjArray    *rocTtime=0;
1159   TObjArray    *rocQtime=0;
1160   
1161   TObjArray    *ceObjects= new TObjArray;
1162   
1163   
1164   Int_t nSectors = fROC->GetNSectors();
1165   
1166   ceTmean = new AliTPCCalPad("CETmean","CETmean");
1167   ceObjects->Add(ceTmean);
1168   
1169   ceTrms = new AliTPCCalPad("CETrms","CETrms");
1170   ceObjects->Add(ceTrms);
1171   
1172   ceQmean = new AliTPCCalPad("CEQmean","CEQmean");
1173   ceObjects->Add(ceQmean);
1174   
1175   rocTtime = new TObjArray(nSectors+2);   // also make room for A and C side average
1176   rocTtime->SetName("rocTtime");
1177   ceObjects->Add(rocTtime);
1178   
1179   rocQtime = new TObjArray(nSectors);
1180   rocQtime->SetName("rocQtime");
1181   ceObjects->Add(rocQtime);
1182
1183   //=== new part
1184   TObjArray *arrFitGraphs=new TObjArray;
1185   arrFitGraphs->SetName("ceFitsDrift");
1186   ceObjects->Add(arrFitGraphs);
1187   
1188 // Temperature maps 
1189   
1190   if (fTemp) {
1191     AliTPCSensorTempArray *tempMap = new AliTPCSensorTempArray(*fTemp);
1192     tempMap->SetNameTitle("TempMap","TempMap");
1193     ceObjects->Add(tempMap);
1194   }
1195   
1196 // Pressure maps
1197   
1198   if (fPressure) {
1199     AliDCSSensor *sensor=0, *sensorCopy=0;
1200     for (Int_t isensor=0; isensor<kNumPressureSensors; ++isensor ) {
1201       sensor = fPressure->GetSensor(kPressureSensorNames[isensor]);
1202       if (sensor) {
1203         sensorCopy = new AliDCSSensor(*sensor);
1204         sensorCopy->SetNameTitle(kPressureSensorNames[isensor],kPressureSensorNames[isensor]);
1205         ceObjects->Add(sensorCopy);
1206       }
1207     }
1208   }
1209   
1210   UInt_t result=0;
1211   
1212   TList* list = GetFileSources(sourceFXS,"CE");
1213   
1214   if (list && list->GetEntries()>0) {
1215     
1216 //  loop through all files from LDCs
1217     
1218     UInt_t index = 0;
1219     while (list->At(index)!=NULL) {
1220       TObjString* fileNameEntry = (TObjString*) list->At(index);
1221       if (fileNameEntry!=NULL) {
1222         TString fileName = GetFile(sourceFXS, "CE",
1223                                    fileNameEntry->GetString().Data());
1224         AliTPCCalibCE *calCE=AliTPCCalibCE::ReadFromFile(fileName.Data());        
1225         
1226         if (!calCE) {
1227           Log ("No valid calibCE object.");
1228           result=2;
1229           break;
1230         }
1231         //  replace entries for the sectors available in the present file
1232         
1233         for (Int_t sector=0; sector<nSectors; sector++) {
1234           AliTPCCalROC *rocTmean=calCE->GetCalRocT0(sector);
1235           if ( rocTmean )  ceTmean->SetCalROC(rocTmean,sector);
1236           AliTPCCalROC *rocTrms=calCE->GetCalRocRMS(sector);
1237           if ( rocTrms )  ceTrms->SetCalROC(rocTrms,sector);
1238           AliTPCCalROC *rocQmean=calCE->GetCalRocQ(sector);
1239           if ( rocQmean )  ceQmean->SetCalROC(rocQmean,sector);
1240           TGraph *grT=calCE->MakeGraphTimeCE(sector,0,2); // T time graph
1241           if ( grT ) rocTtime->AddAt(grT,sector);
1242           TGraph *grQ=calCE->MakeGraphTimeCE(sector,0,3); // Q time graph
1243           if ( grQ ) rocQtime->AddAt(grQ,sector);
1244         }
1245         
1246         TGraph *grT=calCE->MakeGraphTimeCE(-1,0,2); // A side average
1247         if ( grT ) {
1248           rocTtime->AddAt(grT,nSectors);
1249         } else {
1250           result=10;
1251         }
1252         grT=calCE->MakeGraphTimeCE(-2,0,2); // C side average
1253         if ( grT ) {
1254           rocTtime->AddAt(grT,nSectors+1);
1255         } else {
1256           result=10;
1257         }
1258
1259         delete calCE;
1260       }
1261       ++index;
1262     }  // while(list)
1263 //
1264 //   Check number of calibrated sectors per side
1265 // 
1266     Int_t aside=0, cside=0;
1267     for (Int_t ind=0; ind<nSectors/4; ind++ ) {
1268         TGraph *grT=(TGraph*)rocTtime->At(ind);
1269         if (grT) aside++;
1270         grT=(TGraph*)rocTtime->At(ind+nSectors/2);
1271         if (grT) aside++;
1272         grT=(TGraph*)rocTtime->At(ind+nSectors/4);
1273         if (grT) cside++;
1274         grT=(TGraph*)rocTtime->At(ind+3*nSectors/4);
1275         if (grT) cside++;
1276      }
1277      if ( (aside<kMinCESectors) && (cside<kMinCESectors) ) {
1278         Log (Form("ExtractCE: Too few fitted sectors: Aside =%d, Cside=%d\n",
1279              aside, cside)) ;
1280         result=10;
1281      }
1282
1283     //
1284     //=== New CE part
1285     //    if it is validated this part needs to be modified again
1286     //    currently its only processed if there is a valid standard CE object
1287     //
1288     list = GetFileSources(sourceFXS,"CEnew");
1289     
1290     if (result==0 && list && list->GetEntries()>0) {
1291       
1292 //  loop through all files from LDCs
1293       
1294       UInt_t index2 = 0;
1295       while (list->At(index2)!=NULL) {
1296         TObjString* fileNameEntry = (TObjString*) list->At(index2);
1297         if (fileNameEntry!=NULL) {
1298           TString fileName = GetFile(sourceFXS, "CEnew",
1299                                      fileNameEntry->GetString().Data());
1300           AliTPCCalibCE *calCE=AliTPCCalibCE::ReadFromFile(fileName.Data());        
1301           
1302           if (!calCE) {
1303             Log ("No valid new calibCE object.");
1304 //             result=2;
1305             break;
1306           }
1307
1308           TIter nextObj(calCE->GetArrFitGraphs());
1309           TObject *obj=0x0;
1310           while ( (obj=nextObj()) ){
1311             arrFitGraphs->Add(obj->Clone());
1312           }
1313           delete calCE;
1314         }
1315         ++index2;
1316       }
1317     }
1318     
1319 //
1320 //  Store updated pedestal entry to OCDB
1321 //
1322     AliCDBMetaData metaData;
1323     metaData.SetBeamPeriod(0);
1324     metaData.SetResponsible("Haavard Helstrup");
1325     metaData.SetAliRootVersion(ALIROOT_BRANCH);
1326     metaData.SetComment("Preprocessor AliTPC data base entries.");
1327     
1328     if ( result == 0 ) {
1329       Bool_t storeOK = Store("Calib", "CE", ceObjects, &metaData, 0, kTRUE);
1330       if ( !storeOK ) ++result;
1331     } else {
1332       Log ("Warning: Average time graphs not available - no OCDB entry written");
1333     }
1334   } else {
1335     Log ("Error: no CE entries available from FXS!");
1336     result = 1;
1337   }
1338   
1339   ceObjects->Delete();
1340   delete ceObjects;
1341   
1342   return result;
1343 }
1344 //______________________________________________________________________________________________
1345
1346 UInt_t AliTPCPreprocessor::ExtractQA(Int_t sourceFXS)
1347 {
1348  //
1349  //  Read Quality Assurance file from file exchage server
1350  //
1351  
1352  UInt_t result=0;
1353
1354  TList* list = GetFileSources(sourceFXS,"QA");
1355  
1356  if (list && list->GetEntries()>0) {
1357
1358 //  only one QA object should be available!
1359
1360     AliTPCdataQA *calQA;
1361
1362     UInt_t nentries = list->GetEntries();  
1363     UInt_t index=0;
1364     if ( nentries > 1) Log ( "More than one QA entry. First one processed");      
1365     TObjString* fileNameEntry = (TObjString*) list->At(index);
1366     if (fileNameEntry!=NULL) {
1367         TString fileName = GetFile(sourceFXS, "QA",
1368                                          fileNameEntry->GetString().Data());
1369         TFile *f = TFile::Open(fileName);
1370         if (!f) {
1371           Log ("Error opening QA file.");
1372           result =2;          
1373         } else {
1374           f->GetObject("tpcCalibQA",calQA);
1375           if ( calQA ) {      
1376 //
1377 //  Store updated pedestal entry to OCDB
1378 //
1379            AliCDBMetaData metaData;
1380            metaData.SetBeamPeriod(0);
1381            metaData.SetResponsible("Haavard Helstrup");
1382            metaData.SetAliRootVersion(ALIROOT_BRANCH);
1383            metaData.SetComment("Preprocessor AliTPC data base entries.");
1384
1385            Bool_t storeOK = Store("Calib", "QA", calQA, &metaData, 0, kFALSE);
1386            if ( !storeOK ) ++result;
1387
1388            delete calQA;
1389           }
1390         }
1391     } else {
1392     Log ("Error: no QA files on FXS!");
1393     result = 2;
1394     }
1395   } else {
1396     Log ("Error: no QA entries in FXS list!");
1397     result = 1;
1398   }
1399   return result;
1400 }
1401
1402 //______________________________________________________________________________________________
1403
1404
1405 UInt_t AliTPCPreprocessor::ExtractAltro(Int_t sourceFXS, TMap* dcsMap)
1406 {
1407  //
1408  //  Read Altro configuration file from file exchage server
1409  //  Keep original entry from OCDB in case no new pulser calibration is available
1410  //
1411  TObjArray    *altroObjects=0;
1412  AliTPCCalPad *acqStart=0;
1413  AliTPCCalPad *zsThr=0;
1414  AliTPCCalPad *acqStop=0;
1415  AliTPCCalPad *FPED=0;
1416  AliTPCCalPad *masked=0;
1417  AliTPCCalPad *k1=0, *k2=0, *k3=0;
1418  AliTPCCalPad *l1=0, *l2=0, *l3=0;
1419  TMap *mapRCUconfig=0;
1420
1421  AliCDBEntry* entry = GetFromOCDB("Calib", "AltroConfig");
1422  if (entry) altroObjects = (TObjArray*)entry->GetObject();
1423  if ( altroObjects==NULL ) {
1424      Log("AliTPCPreprocsessor: No previous TPC altro calibration entry available.\n");
1425      altroObjects = new TObjArray;    
1426  }
1427
1428  acqStart = (AliTPCCalPad*)altroObjects->FindObject("AcqStart");
1429  if ( !acqStart ) {
1430     acqStart = new AliTPCCalPad("AcqStart","AcqStart");
1431     altroObjects->Add(acqStart);
1432  }
1433  zsThr = (AliTPCCalPad*)altroObjects->FindObject("ZsThr");
1434  if ( !zsThr )  { 
1435     zsThr = new AliTPCCalPad("ZsThr","ZsThr");
1436     altroObjects->Add(zsThr);
1437  }
1438  FPED = (AliTPCCalPad*)altroObjects->FindObject("FPED");
1439  if ( !FPED )  { 
1440     FPED = new AliTPCCalPad("FPED","FPED");
1441     altroObjects->Add(FPED);
1442  }
1443  acqStop = (AliTPCCalPad*)altroObjects->FindObject("AcqStop");
1444  if ( !acqStop ) {
1445     acqStop = new AliTPCCalPad("AcqStop","AcqStop");
1446     altroObjects->Add(acqStop);
1447  }
1448  masked = (AliTPCCalPad*)altroObjects->FindObject("Masked");
1449  if ( !masked )  { 
1450     masked = new AliTPCCalPad("Masked","Masked");
1451     altroObjects->Add(masked);
1452  }
1453  k1 = (AliTPCCalPad*)altroObjects->FindObject("K1");
1454  if ( !k1 )  { 
1455     k1 = new AliTPCCalPad("K1","K1");
1456     altroObjects->Add(k1);
1457  }
1458  k2 = (AliTPCCalPad*)altroObjects->FindObject("K2");
1459  if ( !k2 )  { 
1460     k2 = new AliTPCCalPad("K2","K2");
1461     altroObjects->Add(k2);
1462  }
1463  k3 = (AliTPCCalPad*)altroObjects->FindObject("K3");
1464  if ( !k3 )  { 
1465     k3 = new AliTPCCalPad("K3","K3");
1466     altroObjects->Add(k3);
1467  }
1468  l1 = (AliTPCCalPad*)altroObjects->FindObject("L1");
1469  if ( !l1 )  { 
1470     l1 = new AliTPCCalPad("L1","L1");
1471     altroObjects->Add(l1);
1472  }
1473  l2 = (AliTPCCalPad*)altroObjects->FindObject("L2");
1474  if ( !l2 )  { 
1475     l2 = new AliTPCCalPad("L2","L2");
1476     altroObjects->Add(l2);
1477  }
1478  l3 = (AliTPCCalPad*)altroObjects->FindObject("L3");
1479  if ( !l3 )  { 
1480     l3 = new AliTPCCalPad("L3","L3");
1481     altroObjects->Add(l3);
1482  }
1483  mapRCUconfig = (TMap*)altroObjects->FindObject("RCUconfig");
1484  if (!mapRCUconfig) {
1485     mapRCUconfig = new TMap();
1486     mapRCUconfig->SetName("RCUconfig");
1487     altroObjects->Add(mapRCUconfig);
1488  }
1489
1490
1491  UInt_t result=0;
1492  TString idFXS[2]={"AltroConfigA","AltroConfigC"};
1493
1494  Int_t nSectors = fROC->GetNSectors();
1495  Bool_t changed=false;
1496  if (altroObjects == 0 ) altroObjects = new TObjArray;
1497
1498 // extract list of active DDLs
1499
1500  if (dcsMap) {
1501   Bool_t found; 
1502   TString arrDDL(kNumDDL);
1503   arrDDL.Append('x',kNumDDL);
1504   for ( Int_t iDDL = 0; iDDL<kNumDDL; iDDL++ ) {
1505     TString stringID = Form (kAmandaDDL.Data(),iDDL+kFirstDDL);
1506     TPair *pair = (TPair*)dcsMap->FindObject(stringID.Data());
1507     found = false;
1508     if ( pair ) {
1509         TObjArray *valueSet=(TObjArray*)pair->Value();
1510         if ( valueSet) { 
1511           AliDCSValue *val = (AliDCSValue*)valueSet->At(0);
1512           if (val) { 
1513               found = val->GetBool();
1514               if (found){
1515                arrDDL[iDDL] = '1';
1516               } else { 
1517                arrDDL[iDDL] = '0';
1518               }
1519           }    
1520         }
1521     } 
1522   }
1523   TObjString *ddlArray = new TObjString;
1524   ddlArray->SetString(arrDDL);
1525   TMap *activeDDL = new TMap;
1526   activeDDL->SetName("DDLArray");
1527   TObjString *key = new TObjString("DDLArray");
1528   activeDDL->Add(key,ddlArray);
1529   altroObjects->Add(activeDDL);
1530   changed=true;
1531  } else {
1532    Log ("ExtractAltro: No DCS map available. Active DDL list cannot be obtained.");
1533    result = 3;
1534  }        
1535
1536 // extract Altro configuration files
1537
1538  for ( Int_t id=0; id<2; id++) {
1539    TList* list = GetFileSources(sourceFXS,idFXS[id].Data());
1540  
1541    if (list && list->GetEntries()>0) {
1542
1543 //  loop through all files from LDCs
1544
1545     UInt_t index = 0;
1546     while (list->At(index)!=NULL) {
1547      TObjString* fileNameEntry = (TObjString*) list->At(index);
1548      if (fileNameEntry!=NULL) {
1549         TString fileName = GetFile(sourceFXS, idFXS[id].Data(),
1550                                          fileNameEntry->GetString().Data());
1551         TFile *f = TFile::Open(fileName);
1552         if (!f) {
1553           const int mess_length=40;
1554           char message[mess_length];
1555           snprintf(message,mess_length,"Error opening Altro configuration file, id = %d",id);
1556           Log (message);
1557           result =2;
1558           break;
1559         }
1560         TObjArray *altroFXS;
1561         f->GetObject("AltroConfig",altroFXS);
1562         if ( !altroFXS ) {
1563           Log ("No Altro configuration object in file.");
1564           result = 2;
1565           break;
1566         }
1567
1568         //  replace entries for the sectors available in the present file
1569         AliTPCCalPad *acqStartFXS=(AliTPCCalPad*)altroFXS->FindObject("AcqStart");
1570         AliTPCCalPad *zsThrFXS=(AliTPCCalPad*)altroFXS->FindObject("ZsThr");
1571         AliTPCCalPad *acqStopFXS=(AliTPCCalPad*)altroFXS->FindObject("AcqStop");
1572         AliTPCCalPad *FPEDFXS=(AliTPCCalPad*)altroFXS->FindObject("FPED");
1573         AliTPCCalPad *maskedFXS=(AliTPCCalPad*)altroFXS->FindObject("Masked");
1574         AliTPCCalPad *k1FXS=(AliTPCCalPad*)altroFXS->FindObject("K1");
1575         AliTPCCalPad *k2FXS=(AliTPCCalPad*)altroFXS->FindObject("K2");
1576         AliTPCCalPad *k3FXS=(AliTPCCalPad*)altroFXS->FindObject("K3");
1577         AliTPCCalPad *l1FXS=(AliTPCCalPad*)altroFXS->FindObject("L1");
1578         AliTPCCalPad *l2FXS=(AliTPCCalPad*)altroFXS->FindObject("L2");
1579         AliTPCCalPad *l3FXS=(AliTPCCalPad*)altroFXS->FindObject("L3");
1580         TMap *mapRCUconfigFXS = (TMap*)altroFXS->FindObject("RCUconfig");
1581         TIterator *mapFXSiter = mapRCUconfigFXS->MakeIterator();
1582         
1583         changed=true;
1584         for (Int_t sector=0; sector<nSectors; sector++) {
1585             
1586            if (acqStartFXS) {
1587               AliTPCCalROC *rocAcqStart=acqStartFXS->GetCalROC(sector);
1588               if ( rocAcqStart )  acqStart->SetCalROC(rocAcqStart,sector);
1589            }
1590            if (zsThrFXS ) {
1591               AliTPCCalROC *rocZsThr=zsThrFXS->GetCalROC(sector);
1592               if ( rocZsThr )  zsThr->SetCalROC(rocZsThr,sector);
1593            }
1594            if (acqStopFXS) {
1595               AliTPCCalROC *rocAcqStop=acqStopFXS->GetCalROC(sector);
1596               if ( rocAcqStop )  acqStop->SetCalROC(rocAcqStop,sector);
1597            }
1598            if (FPEDFXS ) {
1599               AliTPCCalROC *rocFPED=FPEDFXS->GetCalROC(sector);
1600               if ( rocFPED )  FPED->SetCalROC(rocFPED,sector);
1601            }
1602            if (maskedFXS) {
1603               AliTPCCalROC *rocMasked=maskedFXS->GetCalROC(sector);
1604               if ( rocMasked )  masked->SetCalROC(rocMasked,sector);
1605            }
1606            if (k1FXS) {
1607               AliTPCCalROC *rocK1=k1FXS->GetCalROC(sector);
1608               if ( rocK1 )  k1->SetCalROC(rocK1,sector);
1609            }
1610            if (k2FXS) {
1611               AliTPCCalROC *rocK2=k2FXS->GetCalROC(sector);
1612               if ( rocK2 )  k2->SetCalROC(rocK2,sector);
1613            }
1614            if (k3FXS) {
1615               AliTPCCalROC *rocK3=k3FXS->GetCalROC(sector);
1616               if ( rocK3 )  k3->SetCalROC(rocK3,sector);
1617            }
1618            if (l1FXS) {
1619               AliTPCCalROC *rocL1=l1FXS->GetCalROC(sector);
1620               if ( rocL1 )  l1->SetCalROC(rocL1,sector);
1621            }
1622            if (l2FXS) {
1623               AliTPCCalROC *rocL2=l2FXS->GetCalROC(sector);
1624               if ( rocL2 )  l2->SetCalROC(rocL2,sector);
1625            }
1626            if (l3FXS) {
1627               AliTPCCalROC *rocL3=l3FXS->GetCalROC(sector);
1628               if ( rocL3 )  l3->SetCalROC(rocL3,sector);
1629            }
1630          }
1631          if (mapRCUconfigFXS) {
1632           Int_t mapEntries = mapRCUconfigFXS->GetEntries();
1633           TObjString* keyFXS;
1634           TVectorF* vecFXS;
1635           TVectorF* vec;              // nSectors = 72  (total number of inner/outer sectors)
1636           for (Int_t i=0; i<mapEntries; ++i) {
1637             keyFXS=(TObjString*)mapFXSiter->Next();
1638             vecFXS=(TVectorF*)mapRCUconfigFXS->GetValue(keyFXS);
1639             vec=(TVectorF*)mapRCUconfig->GetValue(keyFXS);
1640             if (!vec) {
1641               vec = new TVectorF(3*nSectors);
1642               *vec = -1;
1643               mapRCUconfig->Add(keyFXS,vec);
1644             }
1645             if (vec->GetNoElements() != 3*nSectors ) {
1646               vec->ResizeTo(3*nSectors);
1647             }
1648             if (id==0) {                        // A side
1649               vec->SetSub(0,vecFXS->GetSub(0,nSectors/2-1));
1650               vec->SetSub(nSectors,vecFXS->GetSub(nSectors,2*nSectors-1));
1651             } else {                             // C side
1652               vec->SetSub(nSectors/2,vecFXS->GetSub(nSectors/2,nSectors-1));
1653               vec->SetSub(2*nSectors,vecFXS->GetSub(2*nSectors,3*nSectors-1));
1654             }
1655           }
1656         }
1657        delete altroFXS;
1658        f->Close();
1659       }
1660      ++index;
1661      }  // while(list)
1662     } else {
1663       Log ("Error: no entries in AltroConfig file list!");
1664       result = 1;
1665     }
1666
1667    }   // for - id
1668 //
1669 //  Store updated pedestal entry to OCDB
1670 //
1671     if (changed) {
1672      AliCDBMetaData metaData;
1673      metaData.SetBeamPeriod(0);
1674      metaData.SetResponsible("Haavard Helstrup");
1675      metaData.SetAliRootVersion(ALIROOT_BRANCH);
1676      metaData.SetComment("Preprocessor AliTPC data base entries.");
1677
1678      Bool_t storeOK = Store("Calib", "AltroConfig", altroObjects, &metaData, 0, kFALSE);
1679      if ( !storeOK ) ++result;
1680     }  
1681
1682   altroObjects->Delete();
1683   delete altroObjects;
1684   
1685   return result;
1686 }