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