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