]> git.uio.no Git - u/mrichter/AliRoot.git/blob - TPC/AliTPCPreprocessor.cxx
Added code in preprocessor to handle output from new laser drift velocity DA
[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   //=== new part
945   TObjArray *arrFitGraphs=new TObjArray;
946   arrFitGraphs->SetName("ceFitsDrift");
947   ceObjects->Add(arrFitGraphs);
948   
949 // Temperature maps 
950   
951   if (fTemp) {
952     AliTPCSensorTempArray *tempMap = new AliTPCSensorTempArray(*fTemp);
953     tempMap->SetNameTitle("TempMap","TempMap");
954     ceObjects->Add(tempMap);
955   }
956   
957 // Pressure maps
958   
959   if (fPressure) {
960     AliDCSSensor *sensor=0, *sensorCopy=0;
961     for (Int_t isensor=0; isensor<kNumPressureSensors; ++isensor ) {
962       sensor = fPressure->GetSensor(kPressureSensorNames[isensor]);
963       if (sensor) {
964         sensorCopy = new AliDCSSensor(*sensor);
965         sensorCopy->SetNameTitle(kPressureSensorNames[isensor],kPressureSensorNames[isensor]);
966         ceObjects->Add(sensorCopy);
967       }
968     }
969   }
970   
971   UInt_t result=0;
972   
973   TList* list = GetFileSources(sourceFXS,"CE");
974   
975   if (list && list->GetEntries()>0) {
976     
977 //  loop through all files from LDCs
978     
979     UInt_t index = 0;
980     while (list->At(index)!=NULL) {
981       TObjString* fileNameEntry = (TObjString*) list->At(index);
982       if (fileNameEntry!=NULL) {
983         TString fileName = GetFile(sourceFXS, "CE",
984                                    fileNameEntry->GetString().Data());
985         TFile *f = TFile::Open(fileName);
986         if (!f) {
987           Log ("Error opening central electrode file.");
988           result =2;
989           break;
990         }
991         AliTPCCalibCE *calCE;
992         f->GetObject("tpcCalibCE",calCE);
993         
994         if (!calCE) {
995           Log ("No valid calibCE object.");
996           result=2;
997           break;
998         }
999         //  replace entries for the sectors available in the present file
1000         
1001         for (Int_t sector=0; sector<nSectors; sector++) {
1002           AliTPCCalROC *rocTmean=calCE->GetCalRocT0(sector);
1003           if ( rocTmean )  ceTmean->SetCalROC(rocTmean,sector);
1004           AliTPCCalROC *rocTrms=calCE->GetCalRocRMS(sector);
1005           if ( rocTrms )  ceTrms->SetCalROC(rocTrms,sector);
1006           AliTPCCalROC *rocQmean=calCE->GetCalRocQ(sector);
1007           if ( rocQmean )  ceQmean->SetCalROC(rocQmean,sector);
1008           TGraph *grT=calCE->MakeGraphTimeCE(sector,0,2); // T time graph
1009           if ( grT ) rocTtime->AddAt(grT,sector);
1010           TGraph *grQ=calCE->MakeGraphTimeCE(sector,0,3); // Q time graph
1011           if ( grQ ) rocQtime->AddAt(grQ,sector);
1012         }
1013         
1014         TGraph *grT=calCE->MakeGraphTimeCE(-1,0,2); // A side average
1015         if ( grT ) {
1016           rocTtime->AddAt(grT,nSectors);
1017         } else {
1018           result=10;
1019         }
1020         grT=calCE->MakeGraphTimeCE(-2,0,2); // C side average
1021         if ( grT ) {
1022           rocTtime->AddAt(grT,nSectors+1);
1023         } else {
1024           result=10;
1025         }
1026         delete calCE;
1027         f->Close();
1028       }
1029       ++index;
1030     }  // while(list)
1031
1032     //
1033     //=== New CE part
1034     //    if it is validated this part needs to be modified again
1035     //    currently its only processed if there is a valid standard CE object
1036     //
1037     list = GetFileSources(sourceFXS,"CEnew");
1038     
1039     if (result==0 && list && list->GetEntries()>0) {
1040       
1041 //  loop through all files from LDCs
1042       
1043       UInt_t index2 = 0;
1044       while (list->At(index2)!=NULL) {
1045         TObjString* fileNameEntry = (TObjString*) list->At(index2);
1046         if (fileNameEntry!=NULL) {
1047           TString fileName = GetFile(sourceFXS, "CEnew",
1048                                      fileNameEntry->GetString().Data());
1049           TFile *f = TFile::Open(fileName);
1050           if (!f) {
1051             Log ("Error opening new central electrode file.");
1052 //             result =2;
1053             break;
1054           }
1055           AliTPCCalibCE *calCE;
1056           f->GetObject("tpcCalibCE",calCE);
1057           
1058           if (!calCE) {
1059             Log ("No valid new calibCE object.");
1060 //             result=2;
1061             break;
1062           }
1063
1064           TIter nextObj(calCE->GetArrFitGraphs());
1065           TObject *obj=0x0;
1066           while ( (obj=nextObj()) ){
1067             arrFitGraphs->Add(obj->Clone());
1068           }
1069           delete calCE;
1070           f->Close();          
1071         }
1072         ++index2;
1073       }
1074     }
1075     
1076 //
1077 //  Store updated pedestal entry to OCDB
1078 //
1079     AliCDBMetaData metaData;
1080     metaData.SetBeamPeriod(0);
1081     metaData.SetResponsible("Haavard Helstrup");
1082     metaData.SetAliRootVersion(ALIROOT_SVN_BRANCH);
1083     metaData.SetComment("Preprocessor AliTPC data base entries.");
1084     
1085     if ( result == 0 ) {
1086       Bool_t storeOK = Store("Calib", "CE", ceObjects, &metaData, 0, kTRUE);
1087       if ( !storeOK ) ++result;
1088     } else {
1089       Log ("Warning: Average time graphs not available - no OCDB entry written");
1090     }
1091   } else {
1092     Log ("Error: no CE entries available from FXS!");
1093     result = 1;
1094   }
1095   
1096   ceObjects->Delete();
1097   delete ceObjects;
1098   
1099   return result;
1100 }
1101 //______________________________________________________________________________________________
1102
1103 UInt_t AliTPCPreprocessor::ExtractQA(Int_t sourceFXS)
1104 {
1105  //
1106  //  Read Quality Assurance file from file exchage server
1107  //
1108  
1109  UInt_t result=0;
1110
1111  TList* list = GetFileSources(sourceFXS,"QA");
1112  
1113  if (list && list->GetEntries()>0) {
1114
1115 //  only one QA objetc should be available!
1116
1117     AliTPCdataQA *calQA;
1118
1119     UInt_t nentries = list->GetEntries();  
1120     UInt_t index=0;
1121     if ( nentries > 1) Log ( "More than one QA entry. First one processed");      
1122     TObjString* fileNameEntry = (TObjString*) list->At(index);
1123     if (fileNameEntry!=NULL) {
1124         TString fileName = GetFile(sourceFXS, "QA",
1125                                          fileNameEntry->GetString().Data());
1126         TFile *f = TFile::Open(fileName);
1127         if (!f) {
1128           Log ("Error opening QA file.");
1129           result =2;          
1130         } else {
1131           f->GetObject("tpcCalibQA",calQA);
1132           if ( calQA ) {      
1133 //
1134 //  Store updated pedestal entry to OCDB
1135 //
1136            AliCDBMetaData metaData;
1137            metaData.SetBeamPeriod(0);
1138            metaData.SetResponsible("Haavard Helstrup");
1139            metaData.SetAliRootVersion(ALIROOT_SVN_BRANCH);
1140            metaData.SetComment("Preprocessor AliTPC data base entries.");
1141
1142            Bool_t storeOK = Store("Calib", "QA", calQA, &metaData, 0, kFALSE);
1143            if ( !storeOK ) ++result;
1144
1145            delete calQA;
1146           }
1147         }
1148     } else {
1149     Log ("Error: no QA files on FXS!");
1150     result = 2;
1151     }
1152   } else {
1153     Log ("Error: no QA entries in FXS list!");
1154     result = 1;
1155   }
1156   return result;
1157 }
1158
1159 //______________________________________________________________________________________________
1160
1161
1162 UInt_t AliTPCPreprocessor::ExtractAltro(Int_t sourceFXS, TMap* dcsMap)
1163 {
1164  //
1165  //  Read Altro configuration file from file exchage server
1166  //  Keep original entry from OCDB in case no new pulser calibration is available
1167  //
1168  TObjArray    *altroObjects=0;
1169  AliTPCCalPad *acqStart=0;
1170  AliTPCCalPad *zsThr=0;
1171  AliTPCCalPad *acqStop=0;
1172  AliTPCCalPad *FPED=0;
1173  AliTPCCalPad *masked=0;
1174  AliTPCCalPad *k1=0, *k2=0, *k3=0;
1175  AliTPCCalPad *l1=0, *l2=0, *l3=0;
1176  TMap *mapRCUconfig=0;
1177
1178  AliCDBEntry* entry = GetFromOCDB("Calib", "AltroConfig");
1179  if (entry) altroObjects = (TObjArray*)entry->GetObject();
1180  if ( altroObjects==NULL ) {
1181      Log("AliTPCPreprocsessor: No previous TPC altro calibration entry available.\n");
1182      altroObjects = new TObjArray;    
1183  }
1184
1185  acqStart = (AliTPCCalPad*)altroObjects->FindObject("AcqStart");
1186  if ( !acqStart ) {
1187     acqStart = new AliTPCCalPad("AcqStart","AcqStart");
1188     altroObjects->Add(acqStart);
1189  }
1190  zsThr = (AliTPCCalPad*)altroObjects->FindObject("ZsThr");
1191  if ( !zsThr )  { 
1192     zsThr = new AliTPCCalPad("ZsThr","ZsThr");
1193     altroObjects->Add(zsThr);
1194  }
1195  FPED = (AliTPCCalPad*)altroObjects->FindObject("FPED");
1196  if ( !FPED )  { 
1197     FPED = new AliTPCCalPad("FPED","FPED");
1198     altroObjects->Add(FPED);
1199  }
1200  acqStop = (AliTPCCalPad*)altroObjects->FindObject("AcqStop");
1201  if ( !acqStop ) {
1202     acqStop = new AliTPCCalPad("AcqStop","AcqStop");
1203     altroObjects->Add(acqStop);
1204  }
1205  masked = (AliTPCCalPad*)altroObjects->FindObject("Masked");
1206  if ( !masked )  { 
1207     masked = new AliTPCCalPad("Masked","Masked");
1208     altroObjects->Add(masked);
1209  }
1210  k1 = (AliTPCCalPad*)altroObjects->FindObject("K1");
1211  if ( !k1 )  { 
1212     k1 = new AliTPCCalPad("K1","K1");
1213     altroObjects->Add(k1);
1214  }
1215  k2 = (AliTPCCalPad*)altroObjects->FindObject("K2");
1216  if ( !k2 )  { 
1217     k2 = new AliTPCCalPad("K2","K2");
1218     altroObjects->Add(k2);
1219  }
1220  k3 = (AliTPCCalPad*)altroObjects->FindObject("K3");
1221  if ( !k3 )  { 
1222     k3 = new AliTPCCalPad("K3","K3");
1223     altroObjects->Add(k3);
1224  }
1225  l1 = (AliTPCCalPad*)altroObjects->FindObject("L1");
1226  if ( !l1 )  { 
1227     l1 = new AliTPCCalPad("L1","L1");
1228     altroObjects->Add(l1);
1229  }
1230  l2 = (AliTPCCalPad*)altroObjects->FindObject("L2");
1231  if ( !l2 )  { 
1232     l2 = new AliTPCCalPad("L2","L2");
1233     altroObjects->Add(l2);
1234  }
1235  l3 = (AliTPCCalPad*)altroObjects->FindObject("L3");
1236  if ( !l3 )  { 
1237     l3 = new AliTPCCalPad("L3","L3");
1238     altroObjects->Add(l3);
1239  }
1240  mapRCUconfig = (TMap*)altroObjects->FindObject("RCUconfig");
1241  if (!mapRCUconfig) {
1242     mapRCUconfig = new TMap();
1243     mapRCUconfig->SetName("RCUconfig");
1244     altroObjects->Add(mapRCUconfig);
1245  }
1246
1247
1248  UInt_t result=0;
1249  TString idFXS[2]={"AltroConfigA","AltroConfigC"};
1250
1251  Int_t nSectors = fROC->GetNSectors();
1252  Bool_t changed=false;
1253  if (altroObjects == 0 ) altroObjects = new TObjArray;
1254
1255 // extract list of active DDLs
1256
1257   Bool_t found; 
1258   TString arrDDL(kNumDDL);
1259   arrDDL.Append('x',kNumDDL);
1260   for ( Int_t iDDL = 0; iDDL<kNumDDL; iDDL++ ) {
1261     TString stringID = Form (kAmandaDDL.Data(),iDDL+kFirstDDL);
1262     TPair *pair = (TPair*)dcsMap->FindObject(stringID.Data());
1263     found = false;
1264     if ( pair ) {
1265         TObjArray *valueSet=(TObjArray*)pair->Value();
1266         if ( valueSet) { 
1267           AliDCSValue *val = (AliDCSValue*)valueSet->At(0);
1268           if (val) { 
1269               found = val->GetBool();
1270               if (found){
1271                arrDDL[iDDL] = '1';
1272               } else { 
1273                arrDDL[iDDL] = '0';
1274               }
1275           }    
1276         }
1277     } 
1278   }
1279   TObjString *ddlArray = new TObjString;
1280   ddlArray->SetString(arrDDL);
1281   TMap *activeDDL = new TMap;
1282   activeDDL->SetName("DDLArray");
1283   TObjString *key = new TObjString("DDLArray");
1284   activeDDL->Add(key,ddlArray);
1285   altroObjects->Add(activeDDL);
1286   changed=true;
1287   
1288
1289 // extract Altro configuration files
1290
1291  for ( Int_t id=0; id<2; id++) {
1292    TList* list = GetFileSources(sourceFXS,idFXS[id].Data());
1293  
1294    if (list && list->GetEntries()>0) {
1295
1296 //  loop through all files from LDCs
1297
1298     UInt_t index = 0;
1299     while (list->At(index)!=NULL) {
1300      TObjString* fileNameEntry = (TObjString*) list->At(index);
1301      if (fileNameEntry!=NULL) {
1302         TString fileName = GetFile(sourceFXS, idFXS[id].Data(),
1303                                          fileNameEntry->GetString().Data());
1304         TFile *f = TFile::Open(fileName);
1305         if (!f) {
1306           char message[40];
1307           sprintf(message,"Error opening Altro configuration file, id = %d",id);
1308           Log (message);
1309           result =2;
1310           break;
1311         }
1312         TObjArray *altroFXS;
1313         f->GetObject("AltroConfig",altroFXS);
1314         if ( !altroFXS ) {
1315           Log ("No Altro configuration object in file.");
1316           result = 2;
1317           break;
1318         }
1319
1320         //  replace entries for the sectors available in the present file
1321         AliTPCCalPad *acqStartFXS=(AliTPCCalPad*)altroFXS->FindObject("AcqStart");
1322         AliTPCCalPad *zsThrFXS=(AliTPCCalPad*)altroFXS->FindObject("ZsThr");
1323         AliTPCCalPad *acqStopFXS=(AliTPCCalPad*)altroFXS->FindObject("AcqStop");
1324         AliTPCCalPad *FPEDFXS=(AliTPCCalPad*)altroFXS->FindObject("FPED");
1325         AliTPCCalPad *maskedFXS=(AliTPCCalPad*)altroFXS->FindObject("Masked");
1326         AliTPCCalPad *k1FXS=(AliTPCCalPad*)altroFXS->FindObject("K1");
1327         AliTPCCalPad *k2FXS=(AliTPCCalPad*)altroFXS->FindObject("K2");
1328         AliTPCCalPad *k3FXS=(AliTPCCalPad*)altroFXS->FindObject("K3");
1329         AliTPCCalPad *l1FXS=(AliTPCCalPad*)altroFXS->FindObject("L1");
1330         AliTPCCalPad *l2FXS=(AliTPCCalPad*)altroFXS->FindObject("L2");
1331         AliTPCCalPad *l3FXS=(AliTPCCalPad*)altroFXS->FindObject("L3");
1332         TMap *mapRCUconfigFXS = (TMap*)altroFXS->FindObject("RCUconfig");
1333         TIterator *mapFXSiter = mapRCUconfigFXS->MakeIterator();
1334         
1335         changed=true;
1336         for (Int_t sector=0; sector<nSectors; sector++) {
1337             
1338            if (acqStartFXS) {
1339               AliTPCCalROC *rocAcqStart=acqStartFXS->GetCalROC(sector);
1340               if ( rocAcqStart )  acqStart->SetCalROC(rocAcqStart,sector);
1341            }
1342            if (zsThrFXS ) {
1343               AliTPCCalROC *rocZsThr=zsThrFXS->GetCalROC(sector);
1344               if ( rocZsThr )  zsThr->SetCalROC(rocZsThr,sector);
1345            }
1346            if (acqStopFXS) {
1347               AliTPCCalROC *rocAcqStop=acqStopFXS->GetCalROC(sector);
1348               if ( rocAcqStop )  acqStop->SetCalROC(rocAcqStop,sector);
1349            }
1350            if (FPEDFXS ) {
1351               AliTPCCalROC *rocFPED=FPEDFXS->GetCalROC(sector);
1352               if ( rocFPED )  FPED->SetCalROC(rocFPED,sector);
1353            }
1354            if (maskedFXS) {
1355               AliTPCCalROC *rocMasked=maskedFXS->GetCalROC(sector);
1356               if ( rocMasked )  masked->SetCalROC(rocMasked,sector);
1357            }
1358            if (k1FXS) {
1359               AliTPCCalROC *rocK1=k1FXS->GetCalROC(sector);
1360               if ( rocK1 )  k1->SetCalROC(rocK1,sector);
1361            }
1362            if (k2FXS) {
1363               AliTPCCalROC *rocK2=k2FXS->GetCalROC(sector);
1364               if ( rocK2 )  k2->SetCalROC(rocK2,sector);
1365            }
1366            if (k3FXS) {
1367               AliTPCCalROC *rocK3=k3FXS->GetCalROC(sector);
1368               if ( rocK3 )  k3->SetCalROC(rocK3,sector);
1369            }
1370            if (l1FXS) {
1371               AliTPCCalROC *rocL1=l1FXS->GetCalROC(sector);
1372               if ( rocL1 )  l1->SetCalROC(rocL1,sector);
1373            }
1374            if (l2FXS) {
1375               AliTPCCalROC *rocL2=l2FXS->GetCalROC(sector);
1376               if ( rocL2 )  l2->SetCalROC(rocL2,sector);
1377            }
1378            if (l3FXS) {
1379               AliTPCCalROC *rocL3=l3FXS->GetCalROC(sector);
1380               if ( rocL3 )  l3->SetCalROC(rocL3,sector);
1381            }
1382          }
1383          if (mapRCUconfigFXS) {
1384           Int_t mapEntries = mapRCUconfigFXS->GetEntries();
1385           TObjString* keyFXS;
1386           TVectorF* vecFXS;
1387           TVectorF* vec;              // nSectors = 72  (total number of inner/outer sectors)
1388           for (Int_t i=0; i<mapEntries; ++i) {
1389             keyFXS=(TObjString*)mapFXSiter->Next();
1390             vecFXS=(TVectorF*)mapRCUconfigFXS->GetValue(keyFXS);
1391             vec=(TVectorF*)mapRCUconfig->GetValue(keyFXS);
1392             if (!vec) {
1393               vec = new TVectorF(3*nSectors);
1394               *vec = -1;
1395               mapRCUconfig->Add(keyFXS,vec);
1396             }
1397             if (vec->GetNoElements() != 3*nSectors ) {
1398               vec->ResizeTo(3*nSectors);
1399             }
1400             if (id==0) {                        // A side
1401               vec->SetSub(0,vecFXS->GetSub(0,nSectors/2-1));
1402               vec->SetSub(nSectors,vecFXS->GetSub(nSectors,2*nSectors-1));
1403             } else {                             // C side
1404               vec->SetSub(nSectors/2,vecFXS->GetSub(nSectors/2,nSectors-1));
1405               vec->SetSub(2*nSectors,vecFXS->GetSub(2*nSectors,3*nSectors-1));
1406             }
1407           }
1408         }
1409        delete altroFXS;
1410        f->Close();
1411       }
1412      ++index;
1413      }  // while(list)
1414     } else {
1415       Log ("Error: no entries in AltroConfig file list!");
1416       result = 1;
1417     }
1418
1419    }   // for - id
1420 //
1421 //  Store updated pedestal entry to OCDB
1422 //
1423     if (changed) {
1424      AliCDBMetaData metaData;
1425      metaData.SetBeamPeriod(0);
1426      metaData.SetResponsible("Haavard Helstrup");
1427      metaData.SetAliRootVersion(ALIROOT_SVN_BRANCH);
1428      metaData.SetComment("Preprocessor AliTPC data base entries.");
1429
1430      Bool_t storeOK = Store("Calib", "AltroConfig", altroObjects, &metaData, 0, kFALSE);
1431      if ( !storeOK ) ++result;
1432     }  
1433
1434   altroObjects->Delete();
1435   delete altroObjects;
1436   
1437   return result;
1438 }