]> git.uio.no Git - u/mrichter/AliRoot.git/blob - TPC/AliTPCPreprocessor.cxx
update train to use TPC performance task
[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 "AliTPCdataQA.h"
31 #include "TFile.h"
32 #include "TTree.h"
33 #include "TGraph.h" 
34 #include "TEnv.h"
35 #include "TParameter.h"
36
37 #include <TTimeStamp.h>
38
39 const Int_t kValCutTemp = 100;               // discard temperatures > 100 degrees
40 const Int_t kDiffCutTemp = 5;                // discard temperature differences > 5 degrees
41 const TString kPedestalRunType = "PEDESTAL";  // pedestal run identifier
42 const TString kPulserRunType = "PULSER";     // pulser run identifier
43 const TString kPhysicsRunType = "PHYSICS";   // physics run identifier
44 const TString kCosmicRunType = "COSMIC";     // cosmic run identifier
45 const TString kLaserRunType = "LASER";       // laser run identifier
46 const TString kDaqRunType = "DAQ"; // DAQ run identifier
47 const TString kAmandaTemp = "TPC_PT_%d_TEMPERATURE"; // Amanda string for temperature entries
48 //const Double_t kFitFraction = 0.7;                 // Fraction of DCS sensor fits required              
49 const Double_t kFitFraction = -1.0;          // Don't require minimum number of fits in commissioning run 
50
51 //
52 // This class is the SHUTTLE preprocessor for the TPC detector.
53 //
54
55 ClassImp(AliTPCPreprocessor)
56
57 //______________________________________________________________________________________________
58 AliTPCPreprocessor::AliTPCPreprocessor(AliShuttleInterface* shuttle) :
59   AliPreprocessor("TPC",shuttle),
60   fConfEnv(0), fTemp(0), fHighVoltage(0), fHighVoltageStat(0), fGoofie(0), fConfigOK(kTRUE), fROC(0)
61 {
62   // constructor
63   fROC = AliTPCROC::Instance();
64
65   // define run types to be processed
66   
67   AddRunType(kPedestalRunType);
68   AddRunType(kPulserRunType);
69   AddRunType(kPhysicsRunType);
70   AddRunType(kCosmicRunType);
71   AddRunType(kLaserRunType);
72   AddRunType(kDaqRunType);
73   
74 }
75 //______________________________________________________________________________________________
76  AliTPCPreprocessor::AliTPCPreprocessor(const AliTPCPreprocessor&  ) :
77    AliPreprocessor("TPC",0),
78    fConfEnv(0), fTemp(0), fHighVoltage(0), fHighVoltageStat(0), fGoofie(0), fConfigOK(kTRUE), fROC(0)
79  {
80
81    Fatal("AliTPCPreprocessor", "copy constructor not implemented");
82 //
83 // //  fTemp = new AliTPCSensorTempArray(*(org.fTemp));
84  }
85
86 //______________________________________________________________________________________________
87 AliTPCPreprocessor::~AliTPCPreprocessor()
88 {
89   // destructor
90
91   delete fTemp;
92   delete fHighVoltage;
93 }
94 //______________________________________________________________________________________________
95 AliTPCPreprocessor& AliTPCPreprocessor::operator = (const AliTPCPreprocessor& )
96 {
97   Fatal("operator =", "assignment operator not implemented");
98   return *this;
99 }
100
101
102 //______________________________________________________________________________________________
103 void AliTPCPreprocessor::Initialize(Int_t run, UInt_t startTime,
104         UInt_t endTime)
105 {
106   // Creates AliTestDataDCS object -- start maps half an hour beforre actual run start
107
108   UInt_t startTimeLocal = startTime-3600;
109   UInt_t endTimeLocal = endTime+1800;
110
111   AliPreprocessor::Initialize(run, startTimeLocal, endTimeLocal);
112
113         AliInfo(Form("\n\tRun %d \n\tStartTime %s \n\tEndTime %s", run,
114                 TTimeStamp((time_t)startTime,0).AsString(),
115                 TTimeStamp((time_t)endTime,0).AsString()));
116
117   // Preprocessor configuration
118
119         AliCDBEntry* entry = GetFromOCDB("Config", "Preprocessor");
120         if (entry) fConfEnv = (TEnv*) entry->GetObject();
121         if ( fConfEnv==0 ) {
122            Log("AliTPCPreprocsessor: Preprocessor Config OCDB entry missing.\n");
123            fConfigOK = kFALSE;
124            return;
125         }
126
127   // Temperature sensors
128
129        TTree *confTree = 0;
130
131        TString tempConf = fConfEnv->GetValue("Temperature","ON");
132        tempConf.ToUpper();
133        if (tempConf != "OFF" ) {
134         entry = GetFromOCDB("Config", "Temperature");
135         if (entry) confTree = (TTree*) entry->GetObject();
136         if ( confTree==0 ) {
137            Log("AliTPCPreprocsessor: Temperature Config OCDB entry missing.\n");
138            fConfigOK = kFALSE;
139            return;
140         }
141         fTemp = new AliTPCSensorTempArray(startTimeLocal, endTimeLocal, confTree, kAmandaTemp);
142         fTemp->SetValCut(kValCutTemp);
143         fTemp->SetDiffCut(kDiffCutTemp);
144        }
145
146   // High voltage measurements
147
148       TString hvConf = fConfEnv->GetValue("HighVoltage","ON");
149       hvConf.ToUpper();
150       if (hvConf != "OFF" ) { 
151         confTree=0;
152         entry=0;
153         entry = GetFromOCDB("Config", "HighVoltage");
154         if (entry) confTree = (TTree*) entry->GetObject();
155         if ( confTree==0 ) {
156            Log("AliTPCPreprocsessor: High Voltage Config OCDB entry missing.\n");
157            fConfigOK = kFALSE;
158            return;
159         }
160         fHighVoltage = new AliDCSSensorArray(startTimeLocal, endTimeLocal, confTree);
161       }
162
163    // High voltage status values
164      
165       TString hvStatConf = fConfEnv->GetValue("HighVoltageStat","ON");
166       hvStatConf.ToUpper();
167       if (hvStatConf != "OFF" ) { 
168         confTree=0;
169         entry=0;
170         entry = GetFromOCDB("Config", "HighVoltageStat");
171         if (entry) confTree = (TTree*) entry->GetObject();
172         if ( confTree==0 ) {
173            Log("AliTPCPreprocsessor: High Voltage Status Config OCDB entry missing.\n");
174            fConfigOK = kFALSE;
175            return;
176         }
177         fHighVoltageStat = new AliDCSSensorArray(startTimeLocal, endTimeLocal, confTree);
178       }
179
180    // Goofie values
181      
182       TString goofieConf = fConfEnv->GetValue("Goofie","ON");
183       goofieConf.ToUpper();
184       if (goofieConf != "OFF" ) { 
185         confTree=0;
186         entry=0;
187         entry = GetFromOCDB("Config", "Goofie");
188         if (entry) confTree = (TTree*) entry->GetObject();
189         if ( confTree==0 ) {
190            Log("AliTPCPreprocsessor: Goofie Config OCDB entry missing.\n");
191            fConfigOK = kFALSE;
192            return;
193         }
194         fGoofie = new AliDCSSensorArray(startTimeLocal, endTimeLocal, confTree);
195       }
196
197
198 }
199
200 //______________________________________________________________________________________________
201 UInt_t AliTPCPreprocessor::Process(TMap* dcsAliasMap)
202 {
203   // Fills data into TPC calibrations objects
204
205   // Amanda servers provide information directly through dcsAliasMap
206
207   
208   if (!fConfigOK) return 9;
209   UInt_t result = 0;
210   TObjArray *resultArray = new TObjArray();
211   TString errorHandling = fConfEnv->GetValue("ErrorHandling","ON");
212   errorHandling.ToUpper();
213   TObject * status;
214
215   UInt_t dcsResult=0;
216   if (errorHandling == "OFF" ) {
217     if (!dcsAliasMap) dcsResult=1;
218     if (dcsAliasMap->GetEntries() == 0 ) dcsResult=1;  
219     status = new TParameter<int>("dcsResult",dcsResult);
220     resultArray->Add(status);
221   } else {
222     if (!dcsAliasMap) return 9;
223     if (dcsAliasMap->GetEntries() == 0 ) return 9;
224   }
225
226
227   
228
229   TString runType = GetRunType();
230
231   // Temperature sensors are processed by AliTPCCalTemp
232
233   TString tempConf = fConfEnv->GetValue("Temperature","ON");
234   tempConf.ToUpper();
235   if (tempConf != "OFF" ) {
236     UInt_t tempResult = MapTemperature(dcsAliasMap);
237     result=tempResult;
238     status = new TParameter<int>("tempResult",tempResult);
239     resultArray->Add(status);
240   }
241
242   // High Voltage recordings
243
244
245   TString hvConf = fConfEnv->GetValue("HighVoltage","ON");
246   hvConf.ToUpper();
247   if (hvConf != "OFF" ) { 
248    UInt_t hvResult = MapHighVoltage(dcsAliasMap);
249    result+=hvResult;
250    status = new TParameter<int>("hvResult",hvResult);
251    resultArray->Add(status);
252  }
253
254   // Goofie values
255
256
257   TString goofieConf = fConfEnv->GetValue("Goofie","ON");
258   goofieConf.ToUpper();
259   if (goofieConf != "OFF" ) { 
260    UInt_t goofieResult = MapGoofie(dcsAliasMap);
261    result+=goofieResult;
262    status = new TParameter<int>("goofieResult",goofieResult);
263    resultArray->Add(status);
264  }
265
266   // Other calibration information will be retrieved through FXS files
267   //  examples:
268   //    TList* fileSourcesDAQ = GetFile(AliShuttleInterface::kDAQ, "pedestals");
269   //    const char* fileNamePed = GetFile(AliShuttleInterface::kDAQ, "pedestals", "LDC1");
270   //
271   //    TList* fileSourcesHLT = GetFile(AliShuttleInterface::kHLT, "calib");
272   //    const char* fileNameHLT = GetFile(AliShuttleInterface::kHLT, "calib", "LDC1");
273
274   // pedestal entries
275
276   if(runType == kPedestalRunType) {
277     Int_t numSources = 1;
278     Int_t pedestalSource[2] = {AliShuttleInterface::kDAQ,AliShuttleInterface::kHLT} ;
279     TString source = fConfEnv->GetValue("Pedestal","DAQ");
280     source.ToUpper();
281     if (source != "OFF" ) { 
282      if ( source == "HLT") pedestalSource[0] = AliShuttleInterface::kHLT;
283      if (!GetHLTStatus()) pedestalSource[0] = AliShuttleInterface::kDAQ;
284      if (source == "HLTDAQ" ) {
285          numSources=2;
286          pedestalSource[0] = AliShuttleInterface::kHLT;
287          pedestalSource[1] = AliShuttleInterface::kDAQ;
288      }
289      if (source == "DAQHLT" ) numSources=2;
290      UInt_t pedestalResult=0;
291      for (Int_t i=0; i<numSources; i++ ) {      
292        pedestalResult = ExtractPedestals(pedestalSource[i]);
293        if ( pedestalResult == 0 ) break;
294      }
295      result += pedestalResult;
296      status = new TParameter<int>("pedestalResult",pedestalResult);
297      resultArray->Add(status);
298     }
299   }
300
301   // pulser trigger processing
302
303   if(runType == kPulserRunType) {
304     Int_t numSources = 1;
305     Int_t pulserSource[2] = {AliShuttleInterface::kDAQ,AliShuttleInterface::kHLT} ;
306     TString source = fConfEnv->GetValue("Pulser","DAQ");
307     source.ToUpper();
308     if ( source != "OFF") { 
309      if ( source == "HLT") pulserSource[0] = AliShuttleInterface::kHLT;
310      if (!GetHLTStatus()) pulserSource[0] = AliShuttleInterface::kDAQ;
311      if (source == "HLTDAQ" ) {
312          numSources=2;
313          pulserSource[0] = AliShuttleInterface::kHLT;
314          pulserSource[1] = AliShuttleInterface::kDAQ;
315      }
316      if (source == "DAQHLT" ) numSources=2;
317      UInt_t pulserResult=0;
318      for (Int_t i=0; i<numSources; i++ ) {      
319        pulserResult = ExtractPulser(pulserSource[i]);
320        if ( pulserResult == 0 ) break;
321      }
322      result += pulserResult;
323      status = new TParameter<int>("pulserResult",pulserResult);
324      resultArray->Add(status);
325     }
326   }
327
328   // Altro configuration
329
330
331   TString altroConf = fConfEnv->GetValue("AltroConf","ON");
332   goofieConf.ToUpper();
333   if (altroConf != "OFF" ) { 
334    UInt_t altroResult = ExtractAltro(AliShuttleInterface::kDCS);
335    result+=altroResult;
336    status = new TParameter<int>("altroResult",altroResult);
337    resultArray->Add(status);
338  }
339
340
341   // Central Electrode processing
342
343   if( runType == kPhysicsRunType || 
344       runType == kLaserRunType ) {    
345
346     Int_t numSources = 1;
347     Int_t ceSource[2] = {AliShuttleInterface::kDAQ,AliShuttleInterface::kHLT} ;
348     TString source = fConfEnv->GetValue("CE","DAQ");
349     source.ToUpper();
350     if ( source != "OFF" ) { 
351      if ( source == "HLT") ceSource[0] = AliShuttleInterface::kHLT;
352      if (!GetHLTStatus()) ceSource[0] = AliShuttleInterface::kDAQ;
353      if (source == "HLTDAQ" ) {
354         numSources=2;
355         ceSource[0] = AliShuttleInterface::kHLT;
356         ceSource[1] = AliShuttleInterface::kDAQ;
357      }
358      if (source == "DAQHLT" ) numSources=2;
359      UInt_t ceResult=0;
360      for (Int_t i=0; i<numSources; i++ ) {      
361        ceResult = ExtractCE(ceSource[i]);
362        if ( ceResult == 0 ) break;
363      }
364
365    // only flag error if CE result is missing from LASER runs
366    //    -- for PHYSICS run do CE processing if data available
367    
368      if ( runType == kLaserRunType ) result += ceResult;
369      status = new TParameter<int>("ceResult",ceResult);
370      resultArray->Add(status);
371
372     numSources = 1;
373     Int_t qaSource[2] = {AliShuttleInterface::kDAQ,AliShuttleInterface::kHLT} ;
374     source = fConfEnv->GetValue("QA","DAQ");
375     source.ToUpper();
376     if ( source != "OFF" ) { 
377      if ( source == "HLT") qaSource[0] = AliShuttleInterface::kHLT;
378      if (!GetHLTStatus()) qaSource[0] = AliShuttleInterface::kDAQ;
379      if (source == "HLTDAQ" ) {
380         numSources=2;
381         qaSource[0] = AliShuttleInterface::kHLT;
382         qaSource[1] = AliShuttleInterface::kDAQ;
383      }
384      if (source == "DAQHLT" ) numSources=2;
385      UInt_t qaResult=0;
386      for (Int_t i=0; i<numSources; i++ ) {      
387        qaResult = ExtractQA(qaSource[i]);
388        if ( qaResult == 0 ) break;
389      }
390 //     result += qaResult;
391      if ( qaResult !=0 ) Log ("ExtractQA failed, no QA entry available.");
392      status = new TParameter<int>("qaResult",qaResult);
393      resultArray->Add(status);
394     }
395    }
396   }
397   
398   if (errorHandling == "OFF" ) {
399     AliCDBMetaData metaData;
400     metaData.SetBeamPeriod(0);
401     metaData.SetResponsible("Haavard Helstrup");
402     metaData.SetComment("Preprocessor AliTPC status.");
403     Store("Calib", "PreprocStatus", resultArray, &metaData, 0, kFALSE);
404     resultArray->Delete();
405     return 0;
406   } else { 
407     return result;
408   }
409 }
410 //______________________________________________________________________________________________
411 UInt_t AliTPCPreprocessor::MapTemperature(TMap* dcsAliasMap)
412 {
413
414    // extract DCS temperature maps. Perform fits to save space
415
416   UInt_t result=0;
417   TMap *map = fTemp->ExtractDCS(dcsAliasMap);
418   if (map) {
419     fTemp->MakeSplineFit(map);
420     Double_t fitFraction = 1.0*fTemp->NumFits()/fTemp->NumSensors(); 
421     if (fitFraction > kFitFraction ) {
422       AliInfo(Form("Temperature values extracted, fits performed.\n"));
423     } else { 
424       Log ("Too few temperature maps fitted. \n");
425       result = 9;
426     }
427   } else {
428     Log("No temperature map extracted. \n");
429     result=9;
430   }
431   delete map;
432   // Now store the final CDB file
433
434   if ( result == 0 ) {
435         AliCDBMetaData metaData;
436         metaData.SetBeamPeriod(0);
437         metaData.SetResponsible("Haavard Helstrup");
438         metaData.SetComment("Preprocessor AliTPC data base entries.");
439
440         Bool_t storeOK = Store("Calib", "Temperature", fTemp, &metaData, 0, kFALSE);
441         if ( !storeOK )  result=1;
442
443    }
444
445    return result;
446
447 }
448
449 //______________________________________________________________________________________________
450 UInt_t AliTPCPreprocessor::MapHighVoltage(TMap* dcsAliasMap)
451 {
452
453    // extract DCS HV maps. Perform fits to save space
454
455   UInt_t result=0;
456   TMap *map = fHighVoltage->ExtractDCS(dcsAliasMap);
457   if (map) {
458     fHighVoltage->MakeSplineFit(map);
459     Double_t fitFraction = 1.0*fHighVoltage->NumFits()/fHighVoltage->NumSensors(); 
460     if (fitFraction > kFitFraction ) {
461       AliInfo(Form("High voltage recordings extracted, fits performed.\n"));
462     } else { 
463       Log ("Too few high voltage recordings fitted. \n");
464       result = 9;
465     }
466   } else {
467     Log("No high voltage recordings extracted. \n");
468     result=9;
469   }
470   delete map;
471
472   TString hvStatConf = fConfEnv->GetValue("HighVoltageStat","ON");
473   hvStatConf.ToUpper();
474   if (hvStatConf != "OFF" ) { 
475     TMap *map2 = fHighVoltageStat->ExtractDCS(dcsAliasMap);
476     if (map2) {
477       fHighVoltageStat->ClearFit();
478       fHighVoltageStat->SetGraph(map2);
479     } else {
480        Log("No high voltage status recordings extracted. \n");
481       result=9;
482     }
483     delete map2;
484
485     // add status maps to high voltage sensor array
486
487     fHighVoltage->AddSensors(fHighVoltageStat);
488    }
489   // Now store the final CDB file
490
491   if ( result == 0 ) {
492         AliCDBMetaData metaData;
493         metaData.SetBeamPeriod(0);
494         metaData.SetResponsible("Haavard Helstrup");
495         metaData.SetComment("Preprocessor AliTPC data base entries.");
496
497         Bool_t storeOK = Store("Calib", "HighVoltage", fHighVoltage, &metaData, 0, kFALSE);
498         if ( !storeOK )  result=1;
499
500    }
501
502    return result;
503
504 }
505
506 //______________________________________________________________________________________________
507 UInt_t AliTPCPreprocessor::MapGoofie(TMap* dcsAliasMap)
508 {
509
510    // extract DCS Goofie maps. Do not perform fits (low update rate)
511
512   UInt_t result=0;
513
514   TMap *map = fGoofie->ExtractDCS(dcsAliasMap);
515   if (map) {
516     fGoofie->ClearFit();
517     fGoofie->SetGraph(map);
518   } else {
519     Log("No Goofie recordings extracted. \n");
520     result=9;
521   }
522   delete map;
523
524   // Now store the final CDB file
525
526   if ( result == 0 ) {
527         AliCDBMetaData metaData;
528         metaData.SetBeamPeriod(0);
529         metaData.SetResponsible("Haavard Helstrup");
530         metaData.SetComment("Preprocessor AliTPC data base entries.");
531
532         Bool_t storeOK = Store("Calib", "Goofie", fGoofie, &metaData, 0, kFALSE);
533         if ( !storeOK )  result=1;
534
535    }
536
537    return result;
538
539 }
540
541
542 //______________________________________________________________________________________________
543
544 UInt_t AliTPCPreprocessor::ExtractPedestals(Int_t sourceFXS)
545 {
546  //
547  //  Read pedestal file from file exchage server
548  //  Keep original entry from OCDB in case no new pedestals are available
549  //
550  AliTPCCalPad *calPadPed=0;
551  AliCDBEntry* entry = GetFromOCDB("Calib", "Pedestals");
552  if (entry) calPadPed = (AliTPCCalPad*)entry->GetObject();
553  if ( calPadPed==NULL ) {
554      Log("AliTPCPreprocsessor: No previous TPC pedestal entry available.\n");
555      calPadPed = new AliTPCCalPad("PedestalsMean","PedestalsMean");
556  }
557
558  AliTPCCalPad *calPadRMS=0;
559  entry = GetFromOCDB("Calib", "PadNoise");
560  if (entry) calPadRMS = (AliTPCCalPad*)entry->GetObject();
561  if ( calPadRMS==NULL ) {
562      Log("AliTPCPreprocsessor: No previous TPC noise entry available.\n");
563      calPadRMS = new AliTPCCalPad("PedestalsRMS","PedestalsRMS");
564  }
565
566
567  UInt_t result=0;
568
569  Int_t nSectors = fROC->GetNSectors();
570  TList* list = GetFileSources(sourceFXS,"pedestals");
571  
572  if (list && list->GetEntries()>0) {
573
574 //  loop through all files from LDCs
575
576     Bool_t changed=false;
577     UInt_t index = 0;
578     while (list->At(index)!=NULL) {
579      TObjString* fileNameEntry = (TObjString*) list->At(index);
580      if (fileNameEntry!=NULL) {
581         TString fileName = GetFile(sourceFXS, "pedestals",
582                                          fileNameEntry->GetString().Data());
583         TFile *f = TFile::Open(fileName);
584         if (!f) {
585           Log ("Error opening pedestal file.");
586           result =2;
587           break;
588         }
589         AliTPCCalibPedestal *calPed;
590         f->GetObject("tpcCalibPedestal",calPed);
591         if ( !calPed ) {
592           Log ("No pedestal calibration object in file.");
593           result = 2;
594           break;
595         }
596
597         //  replace entries for the sectors available in the present file
598
599         changed=true;
600         for (Int_t sector=0; sector<nSectors; sector++) {
601            AliTPCCalROC *rocPed=calPed->GetCalRocPedestal(sector, kFALSE);
602            if ( rocPed )  calPadPed->SetCalROC(rocPed,sector);
603            AliTPCCalROC *rocRMS=calPed->GetCalRocRMS(sector, kFALSE);
604            if ( rocRMS )  calPadRMS->SetCalROC(rocRMS,sector);
605         }
606         delete calPed; 
607         f->Close();
608       }
609      ++index;
610     }  // while(list)
611 //
612 //  Store updated pedestal entry to OCDB
613 //
614     if (changed) {
615      AliCDBMetaData metaData;
616      metaData.SetBeamPeriod(0);
617      metaData.SetResponsible("Haavard Helstrup");
618      metaData.SetComment("Preprocessor AliTPC data base entries."); 
619  
620      Bool_t storeOK = Store("Calib", "Pedestals", calPadPed, &metaData, 0, kTRUE);
621      if ( !storeOK ) ++result;
622      storeOK = Store("Calib", "PadNoise", calPadRMS, &metaData, 0, kTRUE);
623      if ( !storeOK ) ++result;
624     }
625   } else {
626     Log ("Error: no entries in input file list!");
627     result = 1;
628   }
629
630   return result;
631 }
632
633 //______________________________________________________________________________________________
634
635
636 UInt_t AliTPCPreprocessor::ExtractPulser(Int_t sourceFXS)
637 {
638  //
639  //  Read pulser calibration file from file exchage server
640  //  Keep original entry from OCDB in case no new pulser calibration is available
641  //
642  TObjArray    *pulserObjects=0;
643  AliTPCCalPad *pulserTmean=0;
644  AliTPCCalPad *pulserTrms=0;
645  AliTPCCalPad *pulserQmean=0;
646  AliCDBEntry* entry = GetFromOCDB("Calib", "Pulser");
647  if (entry) pulserObjects = (TObjArray*)entry->GetObject();
648  if ( pulserObjects==NULL ) {
649      Log("AliTPCPreprocsessor: No previous TPC pulser entry available.\n");
650      pulserObjects = new TObjArray;    
651  }
652
653  pulserTmean = (AliTPCCalPad*)pulserObjects->FindObject("PulserTmean");
654  if ( !pulserTmean ) {
655     pulserTmean = new AliTPCCalPad("PulserTmean","PulserTmean");
656     pulserObjects->Add(pulserTmean);
657  }
658  pulserTrms = (AliTPCCalPad*)pulserObjects->FindObject("PulserTrms");
659  if ( !pulserTrms )  { 
660     pulserTrms = new AliTPCCalPad("PulserTrms","PulserTrms");
661     pulserObjects->Add(pulserTrms);
662  }
663  pulserQmean = (AliTPCCalPad*)pulserObjects->FindObject("PulserQmean");
664  if ( !pulserQmean )  { 
665     pulserQmean = new AliTPCCalPad("PulserQmean","PulserQmean");
666     pulserObjects->Add(pulserQmean);
667  }
668
669
670  UInt_t result=0;
671
672  Int_t nSectors = fROC->GetNSectors();
673  TList* list = GetFileSources(sourceFXS,"pulser");
674  
675  if (list && list->GetEntries()>0) {
676
677 //  loop through all files from LDCs
678
679     Bool_t changed=false;
680     UInt_t index = 0;
681     while (list->At(index)!=NULL) {
682      TObjString* fileNameEntry = (TObjString*) list->At(index);
683      if (fileNameEntry!=NULL) {
684         TString fileName = GetFile(sourceFXS, "pulser",
685                                          fileNameEntry->GetString().Data());
686         TFile *f = TFile::Open(fileName);
687         if (!f) {
688           Log ("Error opening pulser file.");
689           result =2;
690           break;
691         }
692         AliTPCCalibPulser *calPulser;
693         f->GetObject("tpcCalibPulser",calPulser);
694         if ( !calPulser ) {
695           Log ("No pulser calibration object in file.");
696           result = 2;
697           break;
698         }
699
700         //  replace entries for the sectors available in the present file
701
702         changed=true;
703         for (Int_t sector=0; sector<nSectors; sector++) {
704            AliTPCCalROC *rocTmean=calPulser->GetCalRocT0(sector);
705            if ( rocTmean )  pulserTmean->SetCalROC(rocTmean,sector);
706            AliTPCCalROC *rocTrms=calPulser->GetCalRocRMS(sector);
707            if ( rocTrms )  pulserTrms->SetCalROC(rocTrms,sector);
708            AliTPCCalROC *rocQmean=calPulser->GetCalRocQ(sector);
709            if ( rocQmean )  pulserQmean->SetCalROC(rocQmean,sector);
710         }
711        delete calPulser;
712        f->Close();
713       }
714      ++index;
715     }  // while(list)
716 //
717 //  Store updated pedestal entry to OCDB
718 //
719     if (changed) {
720      AliCDBMetaData metaData;
721      metaData.SetBeamPeriod(0);
722      metaData.SetResponsible("Haavard Helstrup");
723      metaData.SetComment("Preprocessor AliTPC data base entries.");
724
725      Bool_t storeOK = Store("Calib", "Pulser", pulserObjects, &metaData, 0, kTRUE);
726      if ( !storeOK ) ++result;
727     }  
728   } else {
729     Log ("Error: no entries in input file list!");
730     result = 1;
731   }
732
733   return result;
734 }
735
736 UInt_t AliTPCPreprocessor::ExtractCE(Int_t sourceFXS)
737 {
738  //
739  //  Read Central Electrode file from file exchage server
740  //  Keep original entry from OCDB in case no new CE calibration is available
741  //
742  TObjArray    *ceObjects=0;
743  AliTPCCalPad *ceTmean=0;
744  AliTPCCalPad *ceTrms=0;
745  AliTPCCalPad *ceQmean=0;
746  TObjArray    *rocTtime=0;  
747  TObjArray    *rocQtime=0;  
748
749  AliCDBEntry* entry = GetFromOCDB("Calib", "CE");
750  if (entry) ceObjects = (TObjArray*)entry->GetObject();
751  if ( ceObjects==NULL ) {
752      Log("AliTPCPreprocsessor: No previous TPC central electrode entry available.\n");
753      ceObjects = new TObjArray;    
754  }
755
756  Int_t nSectors = fROC->GetNSectors();
757
758  ceTmean = (AliTPCCalPad*)ceObjects->FindObject("CETmean");
759  if ( !ceTmean ) {
760     ceTmean = new AliTPCCalPad("CETmean","CETmean");
761     ceObjects->Add(ceTmean);
762  }
763  ceTrms = (AliTPCCalPad*)ceObjects->FindObject("CETrms");
764  if ( !ceTrms )  { 
765     ceTrms = new AliTPCCalPad("CETrms","CETrms");
766     ceObjects->Add(ceTrms);
767  }
768  ceQmean = (AliTPCCalPad*)ceObjects->FindObject("CEQmean");
769  if ( !ceQmean )  { 
770     ceQmean = new AliTPCCalPad("CEQmean","CEQmean");
771     ceObjects->Add(ceQmean);
772  }
773  //!new from here please have a look!!!
774  rocTtime = (TObjArray*)ceObjects->FindObject("rocTtime");
775  if ( !rocTtime ) {
776      rocTtime = new TObjArray(nSectors);
777      rocTtime->SetName("rocTtime");
778      ceObjects->Add(rocTtime);
779  }
780  
781  rocQtime = (TObjArray*)ceObjects->FindObject("rocQtime");
782  if ( !rocQtime ) {
783      rocQtime = new TObjArray(nSectors);
784      rocQtime->SetName("rocQtime");
785      ceObjects->Add(rocQtime);
786  }
787
788
789  UInt_t result=0;
790
791  TList* list = GetFileSources(sourceFXS,"CE");
792  
793  if (list && list->GetEntries()>0) {
794
795 //  loop through all files from LDCs
796
797     UInt_t index = 0;
798     while (list->At(index)!=NULL) {
799      TObjString* fileNameEntry = (TObjString*) list->At(index);
800      if (fileNameEntry!=NULL) {
801         TString fileName = GetFile(sourceFXS, "CE",
802                                          fileNameEntry->GetString().Data());
803         TFile *f = TFile::Open(fileName);
804         if (!f) {
805           Log ("Error opening central electrode file.");
806           result =2;
807           break;
808         }
809         AliTPCCalibCE *calCE;
810         f->GetObject("tpcCalibCE",calCE);
811
812         if (!calCE) {
813           Log ("No valid calibCE object.");
814           result=2;
815           break;
816         }
817         //  replace entries for the sectors available in the present file
818
819         for (Int_t sector=0; sector<nSectors; sector++) {
820            AliTPCCalROC *rocTmean=calCE->GetCalRocT0(sector);
821            if ( rocTmean )  ceTmean->SetCalROC(rocTmean,sector);
822            AliTPCCalROC *rocTrms=calCE->GetCalRocRMS(sector);
823            if ( rocTrms )  ceTrms->SetCalROC(rocTrms,sector);
824            AliTPCCalROC *rocQmean=calCE->GetCalRocQ(sector);
825            if ( rocQmean )  ceQmean->SetCalROC(rocQmean,sector);
826            TGraph *grT=calCE->MakeGraphTimeCE(sector,0,2); // T time graph
827            if ( grT ) rocTtime->AddAt(grT,sector);         
828            TGraph *grQ=calCE->MakeGraphTimeCE(sector,0,3); // Q time graph
829            if ( grQ ) rocTtime->AddAt(grQ,sector);         
830         }
831        delete calCE;
832        f->Close();
833       }
834      ++index;
835     }  // while(list)
836 //
837 //  Store updated pedestal entry to OCDB
838 //
839     AliCDBMetaData metaData;
840     metaData.SetBeamPeriod(0);
841     metaData.SetResponsible("Haavard Helstrup");
842     metaData.SetComment("Preprocessor AliTPC data base entries.");
843
844     Bool_t storeOK = Store("Calib", "CE", ceObjects, &metaData, 0, kTRUE);
845     if ( !storeOK ) ++result;
846     
847   } else {
848     Log ("Error: no entries!");
849     result = 1;
850   }
851
852   return result;
853 }
854 //______________________________________________________________________________________________
855
856 UInt_t AliTPCPreprocessor::ExtractQA(Int_t sourceFXS)
857 {
858  //
859  //  Read Quality Assurance file from file exchage server
860  //
861  
862  UInt_t result=0;
863
864  TList* list = GetFileSources(sourceFXS,"QA");
865  
866  if (list && list->GetEntries()>0) {
867
868 //  only one QA objetc should be available!
869
870     AliTPCdataQA *calQA;
871
872     UInt_t nentries = list->GetEntries();  
873     UInt_t index=0;
874     if ( nentries > 1) Log ( "More than one QA entry. First one processed");      
875     TObjString* fileNameEntry = (TObjString*) list->At(index);
876     if (fileNameEntry!=NULL) {
877         TString fileName = GetFile(sourceFXS, "QA",
878                                          fileNameEntry->GetString().Data());
879         TFile *f = TFile::Open(fileName);
880         if (!f) {
881           Log ("Error opening QA file.");
882           result =2;          
883         } else {
884           f->GetObject("tpcCalibQA",calQA);
885           if ( calQA ) {      
886 //
887 //  Store updated pedestal entry to OCDB
888 //
889            AliCDBMetaData metaData;
890            metaData.SetBeamPeriod(0);
891            metaData.SetResponsible("Haavard Helstrup");
892            metaData.SetComment("Preprocessor AliTPC data base entries.");
893
894            Bool_t storeOK = Store("Calib", "QA", calQA, &metaData, 0, kTRUE);
895            if ( !storeOK ) ++result;
896           }
897         }
898     } else {
899     Log ("Error: no QA files on FXS!");
900     result = 2;
901     }
902   } else {
903     Log ("Error: no QA entries in FXS list!");
904     result = 1;
905   }
906   return result;
907 }
908
909 //______________________________________________________________________________________________
910
911
912 UInt_t AliTPCPreprocessor::ExtractAltro(Int_t sourceFXS)
913 {
914  //
915  //  Read pulser calibration file from file exchage server
916  //  Keep original entry from OCDB in case no new pulser calibration is available
917  //
918  TObjArray    *altroObjects=0;
919  AliTPCCalPad *acqStart=0;
920  AliTPCCalPad *zsThr=0;
921  AliTPCCalPad *acqStop=0;
922  AliTPCCalPad *FPED=0;
923  AliTPCCalPad *masked=0;
924
925  AliCDBEntry* entry = GetFromOCDB("Calib", "Altro");
926  if (entry) altroObjects = (TObjArray*)entry->GetObject();
927  if ( altroObjects==NULL ) {
928      Log("AliTPCPreprocsessor: No previous TPC altro calibration entry available.\n");
929      altroObjects = new TObjArray;    
930  }
931
932  acqStart = (AliTPCCalPad*)altroObjects->FindObject("AcqStart");
933  if ( !acqStart ) {
934     acqStart = new AliTPCCalPad("AcqStart","AcqStart");
935     altroObjects->Add(acqStart);
936  }
937  zsThr = (AliTPCCalPad*)altroObjects->FindObject("ZsThr");
938  if ( !zsThr )  { 
939     zsThr = new AliTPCCalPad("ZsThr","ZsThr");
940     altroObjects->Add(zsThr);
941  }
942  FPED = (AliTPCCalPad*)altroObjects->FindObject("FPED");
943  if ( !FPED )  { 
944     FPED = new AliTPCCalPad("FPED","FPED");
945     altroObjects->Add(FPED);
946  }
947  acqStop = (AliTPCCalPad*)altroObjects->FindObject("AcqStop");
948  if ( !acqStop ) {
949     acqStop = new AliTPCCalPad("AcqStop","AcqStop");
950     altroObjects->Add(acqStop);
951  }
952  masked = (AliTPCCalPad*)altroObjects->FindObject("Masked");
953  if ( !masked )  { 
954     masked = new AliTPCCalPad("Masked","Masked");
955     altroObjects->Add(masked);
956  }
957
958
959
960  UInt_t result=0;
961  TString idFXS[2]={"AltroConfigA","AltroConfigC"};
962
963  Int_t nSectors = fROC->GetNSectors();
964  Bool_t changed=false;
965  for ( Int_t id=0; id<2; id++) {
966    TList* list = GetFileSources(sourceFXS,idFXS[id].Data());
967  
968    if (list && list->GetEntries()>0) {
969       if (altroObjects == 0 ) altroObjects = new TObjArray;
970
971 //  loop through all files from LDCs
972
973     UInt_t index = 0;
974     while (list->At(index)!=NULL) {
975      TObjString* fileNameEntry = (TObjString*) list->At(index);
976      if (fileNameEntry!=NULL) {
977         TString fileName = GetFile(sourceFXS, idFXS[id].Data(),
978                                          fileNameEntry->GetString().Data());
979         TFile *f = TFile::Open(fileName);
980         if (!f) {
981           char message[40];
982           sprintf(message,"Error opening Altro configuration file, id = %d",id);
983           Log (message);
984           result =2;
985           break;
986         }
987         TObjArray *altroFXS;
988         f->GetObject("AltroConfig",altroFXS);
989         if ( !altroFXS ) {
990           Log ("No Altro configuration object in file.");
991           result = 2;
992           break;
993         }
994
995         //  replace entries for the sectors available in the present file
996         AliTPCCalPad *acqStartFXS=(AliTPCCalPad*)altroFXS->FindObject("AcqStart");
997         AliTPCCalPad *zsThrFXS=(AliTPCCalPad*)altroFXS->FindObject("ZsThr");
998         AliTPCCalPad *acqStopFXS=(AliTPCCalPad*)altroFXS->FindObject("AcqStop");
999         AliTPCCalPad *FPEDFXS=(AliTPCCalPad*)altroFXS->FindObject("FPED");
1000         AliTPCCalPad *maskedFXS=(AliTPCCalPad*)altroFXS->FindObject("Masked");
1001
1002         changed=true;
1003         for (Int_t sector=0; sector<nSectors; sector++) {
1004             
1005            if (acqStartFXS) {
1006               AliTPCCalROC *rocAcqStart=acqStartFXS->GetCalROC(sector);
1007               if ( rocAcqStart )  acqStart->SetCalROC(rocAcqStart,sector);
1008            }
1009            if (zsThrFXS ) {
1010               AliTPCCalROC *rocZsThr=zsThrFXS->GetCalROC(sector);
1011               if ( rocZsThr )  zsThr->SetCalROC(rocZsThr,sector);
1012            }
1013            if (acqStopFXS) {
1014               AliTPCCalROC *rocAcqStop=acqStopFXS->GetCalROC(sector);
1015               if ( rocAcqStop )  acqStop->SetCalROC(rocAcqStop,sector);
1016            }
1017            if (FPEDFXS ) {
1018               AliTPCCalROC *rocFPED=FPEDFXS->GetCalROC(sector);
1019               if ( rocFPED )  FPED->SetCalROC(rocFPED,sector);
1020            }
1021            if (maskedFXS) {
1022               AliTPCCalROC *rocMasked=maskedFXS->GetCalROC(sector);
1023               if ( rocMasked )  masked->SetCalROC(rocMasked,sector);
1024            }
1025         }
1026        delete altroFXS;
1027        f->Close();
1028       }
1029      ++index;
1030      }  // while(list)
1031     } else {
1032       Log ("Error: no entries in input file list!");
1033       result = 1;
1034     }
1035
1036    }   // for - id
1037 //
1038 //  Store updated pedestal entry to OCDB
1039 //
1040     if (changed) {
1041      AliCDBMetaData metaData;
1042      metaData.SetBeamPeriod(0);
1043      metaData.SetResponsible("Haavard Helstrup");
1044      metaData.SetComment("Preprocessor AliTPC data base entries.");
1045
1046      Bool_t storeOK = Store("Calib", "AltroConfig", altroObjects, &metaData, 0, kTRUE);
1047      if ( !storeOK ) ++result;
1048     }  
1049
1050   return result;
1051 }