]> git.uio.no Git - u/mrichter/AliRoot.git/blob - TRD/Macros/DumpOCDBtoTree.C
If not needed do not create the histograms in the neutral meson selection task
[u/mrichter/AliRoot.git] / TRD / Macros / DumpOCDBtoTree.C
1 ////////////////////////////////////////////
2 // Author: Ionut Cristian Arsene          //          
3 // email:  iarsene@mail.cern.ch           //
4 ////////////////////////////////////////////
5 // Use this macro to create ROOT trees with time dependent information from the TRD OCDB
6 //
7 // Usage:
8 //
9 //DumpOCDBtoTree(const Char_t* runListFilename, const Char_t* outFilename,
10 //               Int_t firstRun = -1, Int_t lastRun = -1,
11 //               Bool_t getMonitoringInfo = kTRUE,
12 //               Bool_t getCalibrationInfo = kTRUE,
13 //               Bool_t getGoofieInfo = kTRUE,
14 //               Bool_t getDCSInfo = kFALSE,
15 //               const Char_t* storage = "local:///lustre/alice/alien/alice/data/2010/OCDB/")
16 //
17 //    * runListFilename   - name of an ascii file containing run numbers
18 //    * outFilename       - name of the root file where the TRD OCDB information tree to be stored
19 //    * firstRun, lastRun - lowest and highest run numbers (from the ascii file) to be dumped
20 //                          if these numbers are not specified (-1) all run numbers in the input ascii file will
21 //                          be used. If the run list file is not specified then all runs in this interval
22 //                          will be queried
23 //    * getMonitoringInfo - flag to switch on/off monitoring information (HV, temperatures, gas pressure,
24 //                          gas composition, ADC clock phase, chamber status)
25 //    * getCalibrationInfo- flag to switch on/off calibration information (gain, pedestal, T0, vdrift, pad status)
26 //    * getGoofieInfo     - flag to switch on/off goofie information (gain, HV, pressure, temperature, drift velocity,
27 //                          gas composition)
28 //    * getDCSInfo        - flag to switch on/off DCS information ()
29 //    * storage           - path of the OCDB database (if it is on alien, be sure to have a valid/active token)
30
31
32 #include <iostream>
33 #include <fstream>
34 #include <string>
35 #include <exception>
36 #include "TVectorD.h"
37 #include "TTreeStream.h"
38 #include "TObjString.h"
39 #include "TTimeStamp.h"
40 #include "TH1.h"
41 #include "TMath.h"
42 #include "TObjArray.h"
43 #include "TFile.h"
44 #include "TSystem.h"
45 #include "TGrid.h"
46 #include "AliCDBManager.h"
47 #include "AliCDBEntry.h"
48 #include "AliTRDcalibDB.h"
49 #include "AliGRPObject.h"
50 #include "AliDCSSensor.h"
51 #include "AliTRDSensorArray.h"
52 #include "AliTRDCalDet.h"
53 #include "AliTRDCalPad.h"
54 #include "AliTRDCalROC.h"
55 #include "AliTRDCalPadStatus.h"
56 #include "AliTRDCalChamberStatus.h"
57 #include "AliTRDCalSingleChamberStatus.h"
58 #include "AliTRDCalDCS.h"
59 #include "AliTRDCalDCSFEE.h"
60 using namespace std;
61
62 // global variables
63 // histograms used for extracting the mean and RMS of calibration parameters
64 TH1F *gRunWiseHisto;
65 TH1F *gSuperModuleWiseHisto;
66 TH1F *gChamberWiseHisto;
67
68 // global constants
69 const Int_t gkSuperModuleStatus[18] = {1, 1, 0, 0, 0, 0, 0, 1, 1,   // (1-installed)
70                                        1, 1, 0, 0, 0, 0, 0, 0, 1};  
71
72 void MakeRunListFromOCDB(const Char_t* directory, const Char_t* outfile, Bool_t fromAlien=kFALSE);
73 void ProcessTRDSensorArray(AliTRDSensorArray*, TTimeStamp, TVectorD&);
74 void ProcessTRDCalibArray(AliTRDCalDet*, AliTRDCalPad*, TString, Double_t&, Double_t&,
75                           TVectorD&, TVectorD&, TVectorD&, TVectorD&);
76 void ProcessTRDstatus(AliTRDCalChamberStatus*, AliTRDCalPadStatus*, Float_t&, TVectorD&, TVectorD&);
77 void ProcessTRDCalDCSFEE(AliTRDCalDCS*, AliTRDCalDCS*, Int_t&, Int_t&, Int_t&, Int_t&, Int_t&, Int_t&, Bool_t&, 
78                          TVectorD&, TVectorD&);
79
80 //__________________________________________________________________________________________
81 void DumpOCDBtoTree(const Char_t* runListFilename,
82                     const Char_t* outFilename,
83                     Int_t firstRun = -1, Int_t lastRun = -1,
84                     Bool_t getMonitoringInfo = kTRUE,
85                     Bool_t getCalibrationInfo = kTRUE,
86                     Bool_t getGoofieInfo = kTRUE,
87                     Bool_t getDCSInfo = kFALSE,
88                     const Char_t* storage = "alien://folder=/alice/data/2010/OCDB/") {
89   //
90   // Main function to steer the extraction of TRD OCDB information
91   //
92
93
94   TTimeStamp jobStartTime;
95   // if the storage is on alien than we need to do some extra stuff
96   TString storageString(storage);
97   if(storageString.Contains("alien://")) {
98     TGrid::Connect("alien://");
99   }
100   // initialize the OCDB manager
101   AliCDBManager *manager = AliCDBManager::Instance();
102   manager->SetDefaultStorage(storage);
103     
104   // initialize the tree
105   TTreeSRedirector *treeStreamer = new TTreeSRedirector(outFilename);
106   
107   // initialize the histograms used for extracting the mean and RMS
108   gRunWiseHisto = new TH1F("runHisto", "runHisto", 200, -10.0, 10.0);
109   gSuperModuleWiseHisto = new TH1F("smHisto", "smHisto", 200, -10.0, 10.0);
110   gChamberWiseHisto = new TH1F("chamberHisto", "chamberHisto", 200, -10.0, 10.0);
111
112   // open the ascii file with run numbers
113   ifstream in;
114   if(runListFilename[0]!='\0')
115     in.open(runListFilename);
116
117   // if a run list file was not specified then use the run range
118   Int_t currRun;
119   if(runListFilename[0]=='\0' && firstRun!=-1 && lastRun!=-1)
120     currRun = firstRun-1;  
121
122   TVectorD runs;
123   TVectorD rejectedRuns;
124   TTimeStamp loopStartTime;
125
126   // loop over runs
127   while(1) {
128     // check if we still have run numbers in the file or provided range
129     if(runListFilename[0]=='\0' && firstRun!=-1 && lastRun!=-1) {
130       currRun++;
131       if(currRun>lastRun) break;
132     }
133     if(runListFilename[0]!='\0') {
134       if(in.eof()) break;
135       if(!(in>>currRun)) continue;
136       if(currRun < (firstRun==-1 ? 0 : firstRun) ||
137          currRun > (lastRun==-1 ? 999999999 : lastRun))
138         continue;
139     }
140
141     cout << "run = " << currRun << endl;
142     // check if the run was processed already
143     Bool_t runProcessed = kFALSE;
144     for(Int_t iRun=0; iRun<runs.GetNoElements(); iRun++) {
145       if(runs[iRun]==currRun) runProcessed = kTRUE;
146     }
147     if(runProcessed) {
148       cout << "Run processed already" << endl;
149       continue;
150     }
151
152     manager->SetRun(currRun);
153
154     // Get the GRP data. Only runs with a corresponding GRP entry in the OCDB 
155     // will be processed.
156     time_t startTime = 0;
157     time_t endTime = 0;
158     TObjString runType("UNKNOWN");
159     AliDCSSensor *cavern_pressure;
160     AliDCSSensor *surface_pressure;
161     UInt_t detectorMask = 0;
162     AliCDBEntry *entry = manager->Get("GRP/GRP/Data");
163     if(entry) {
164       entry->SetOwner(kFALSE);
165     }
166     AliGRPObject* grpObject = 0;
167     if(entry) 
168       grpObject = dynamic_cast<AliGRPObject*>(entry->GetObject());
169     else {
170       // add the run number to the list of rejected runs
171       rejectedRuns.ResizeTo(rejectedRuns.GetNoElements()+1);
172       rejectedRuns[rejectedRuns.GetNoElements()-1] = currRun;
173       continue;
174     }
175     if(grpObject) {
176       startTime = grpObject->GetTimeStart();
177       endTime = grpObject->GetTimeEnd();
178       runType = grpObject->GetRunType().Data();
179       cavern_pressure = grpObject->GetCavernAtmosPressure();
180       surface_pressure = grpObject->GetSurfaceAtmosPressure();
181       detectorMask = grpObject->GetDetectorMask();
182       TTimeStamp start(grpObject->GetTimeStart());
183       TTimeStamp end(grpObject->GetTimeEnd());
184       cout << "Start time: " << start.GetDate()/10000 << "/" 
185            << (start.GetDate()/100)-(start.GetDate()/10000)*100 << "/" 
186            << start.GetDate()%100 << "   "
187            << start.GetTime()/10000 << ":"
188            << (start.GetTime()/100)-(start.GetTime()/10000)*100 << ":" 
189            << start.GetTime()%100 << endl;
190       cout << "End time: " << end.GetDate()/10000 << "/" 
191            << (end.GetDate()/100)-(end.GetDate()/10000)*100 << "/" 
192            << end.GetDate()%100 << "   "
193            << end.GetTime()/10000 << ":"
194            << (end.GetTime()/100)-(end.GetTime()/10000)*100 << ":"
195            << end.GetTime()%100 << endl;
196       cout << "Run type = " << grpObject->GetRunType().Data() << endl;
197     }
198     else {
199       // add the run number to the list of rejected runs
200       rejectedRuns.ResizeTo(rejectedRuns.GetNoElements()+1);
201       rejectedRuns[rejectedRuns.GetNoElements()-1] = currRun;
202       continue;
203     }
204
205     // remove runs with zero time duration
206     if(startTime==endTime) {
207       if(grpObject) delete grpObject;
208       // add the run number to the list of rejected runs
209       rejectedRuns.ResizeTo(rejectedRuns.GetNoElements()+1);
210       rejectedRuns[rejectedRuns.GetNoElements()-1] = currRun;
211       continue;
212     }
213
214     // time step for time dependent information (change this if you need something else)
215     UInt_t dTime = TMath::Max((endTime-startTime)/20, Long_t(5*60));
216
217     // get monitoring information
218     AliTRDSensorArray *anodeISensors = 0;
219     AliTRDSensorArray *anodeUSensors = 0;
220     AliTRDSensorArray *driftISensors = 0;
221     AliTRDSensorArray *driftUSensors = 0;
222     AliTRDSensorArray *temperatureSensors = 0;
223     AliTRDSensorArray *chamberStatusSensors = 0;
224     AliTRDSensorArray *overpressureSensors = 0;
225     AliTRDSensorArray *gasCO2Sensors = 0;
226     AliTRDSensorArray *gasH2OSensors = 0;
227     AliTRDSensorArray *gasO2Sensors = 0;
228   //  AliTRDSensorArray *adcClkPhaseSensors = 0;
229
230     if(getMonitoringInfo) {
231       // anode hv currents (per chamber)
232       entry = manager->Get("TRD/Calib/trd_hvAnodeImon");
233       if(entry) {
234         entry->SetOwner(kTRUE);
235         anodeISensors = (AliTRDSensorArray*)entry->GetObject();
236       }
237
238       // anode hv voltages (per chamber)
239       entry = manager->Get("TRD/Calib/trd_hvAnodeUmon");
240       if(entry) {
241         entry->SetOwner(kTRUE);
242         anodeUSensors = (AliTRDSensorArray*)entry->GetObject();
243       }
244
245       // drift hv currents (per chamber)
246       entry = manager->Get("TRD/Calib/trd_hvDriftImon");
247       if(entry) {
248         entry->SetOwner(kTRUE);
249         driftISensors = (AliTRDSensorArray*)entry->GetObject();
250       }
251     
252       // drift hv voltages (per chamber)
253       entry = manager->Get("TRD/Calib/trd_hvDriftUmon");
254       if(entry) {
255         entry->SetOwner(kTRUE);
256         driftUSensors = (AliTRDSensorArray*)entry->GetObject();
257       }
258     
259       // temperatures from chamber sensors (per chamber)
260       entry = manager->Get("TRD/Calib/trd_envTemp");
261       if(entry) {
262         entry->SetOwner(kTRUE);
263         temperatureSensors = (AliTRDSensorArray*)entry->GetObject();
264       }
265     
266       // chamber status (from sensors)
267       entry = manager->Get("TRD/Calib/trd_chamberStatus");
268       if(entry) {
269         entry->SetOwner(kTRUE);
270         chamberStatusSensors = (AliTRDSensorArray*)entry->GetObject();
271       }
272     
273       // gas overpressure (per whole TRD)
274       entry = manager->Get("TRD/Calib/trd_gasOverpressure");
275       if(entry) {
276         entry->SetOwner(kTRUE);
277         overpressureSensors = (AliTRDSensorArray*)entry->GetObject();
278       }
279     
280       // gas CO2 fraction (whole TRD)
281       entry = manager->Get("TRD/Calib/trd_gasCO2");
282       if(entry) {
283         entry->SetOwner(kTRUE);
284         gasCO2Sensors = (AliTRDSensorArray*)entry->GetObject();
285       }
286     
287       // gas H2O fraction (whole TRD)
288       entry = manager->Get("TRD/Calib/trd_gasH2O");
289       if(entry) {
290         entry->SetOwner(kTRUE);
291         gasH2OSensors = (AliTRDSensorArray*)entry->GetObject();
292       }
293       
294       // gas O2 fraction (whole TRD)
295       entry = manager->Get("TRD/Calib/trd_gasO2");
296       if(entry) {
297         entry->SetOwner(kTRUE);
298         gasO2Sensors = (AliTRDSensorArray*)entry->GetObject();
299       }
300     
301       // ADC Clk phase (whole TRD)
302 /*
303       entry = manager->Get("TRD/Calib/trd_adcClkPhase");
304       if(entry) {
305         entry->SetOwner(kTRUE);
306         adcClkPhaseSensors = (AliTRDSensorArray*)entry->GetObject();
307       }
308 */
309     }  // end if getMonitoringInfo
310
311
312     // get calibration information
313     // process gains
314     AliTRDCalDet *chamberGainFactor = 0;
315     AliTRDCalPad *padGainFactor = 0;
316     Double_t runMeanGain=0.0, runRMSGain=0.0;
317     TVectorD chamberMeanGain(AliTRDcalibDB::kNdet);
318     TVectorD chamberRMSGain(AliTRDcalibDB::kNdet);
319     TVectorD smMeanGain(AliTRDcalibDB::kNsector);
320     TVectorD smRMSGain(AliTRDcalibDB::kNsector);
321     TString parName("Gain");
322     if(getCalibrationInfo) {
323       entry = manager->Get("TRD/Calib/ChamberGainFactor");
324       if(entry) {
325         entry->SetOwner(kFALSE);
326         chamberGainFactor = (AliTRDCalDet*)entry->GetObject();
327       }
328       entry = manager->Get("TRD/Calib/LocalGainFactor");
329       if(entry) {
330         entry->SetOwner(kFALSE);
331         padGainFactor = (AliTRDCalPad*)entry->GetObject();
332       }
333       ProcessTRDCalibArray(chamberGainFactor, padGainFactor, 
334                            parName,
335                            runMeanGain, runRMSGain,
336                            chamberMeanGain, chamberRMSGain,
337                            smMeanGain, smRMSGain);
338     }
339
340     // process pedestals
341     AliTRDCalDet *chamberNoise = 0;
342     AliTRDCalPad *padNoise = 0;
343     Double_t runMeanNoise=0.0, runRMSNoise=0.0;
344     TVectorD chamberMeanNoise(AliTRDcalibDB::kNdet);
345     TVectorD chamberRMSNoise(AliTRDcalibDB::kNdet);
346     TVectorD smMeanNoise(AliTRDcalibDB::kNsector);
347     TVectorD smRMSNoise(AliTRDcalibDB::kNsector);
348     parName = "Noise";
349     if(getCalibrationInfo) {
350       entry = manager->Get("TRD/Calib/DetNoise");
351       if(entry) {
352         entry->SetOwner(kFALSE);
353         chamberNoise = (AliTRDCalDet*)entry->GetObject();
354       }
355       entry = manager->Get("TRD/Calib/PadNoise");
356       if(entry) {
357         entry->SetOwner(kFALSE);
358         padNoise = (AliTRDCalPad*)entry->GetObject();
359       }
360       ProcessTRDCalibArray(chamberNoise, padNoise, 
361                            parName,
362                            runMeanNoise, runRMSNoise,
363                            chamberMeanNoise, chamberRMSNoise,
364                            smMeanNoise, smRMSNoise);
365     }
366
367     // process drift velocity
368     AliTRDCalDet *chamberVdrift = 0;
369     AliTRDCalPad *padVdrift = 0;
370     Double_t runMeanVdrift=0.0, runRMSVdrift=0.0;
371     TVectorD chamberMeanVdrift(AliTRDcalibDB::kNdet);
372     TVectorD chamberRMSVdrift(AliTRDcalibDB::kNdet);
373     TVectorD smMeanVdrift(AliTRDcalibDB::kNsector);
374     TVectorD smRMSVdrift(AliTRDcalibDB::kNsector);
375     parName = "Vdrift";
376     if(getCalibrationInfo) {
377       entry = manager->Get("TRD/Calib/ChamberVdrift");
378       if(entry) {
379         entry->SetOwner(kFALSE);
380         chamberVdrift = (AliTRDCalDet*)entry->GetObject();
381       }
382       entry = manager->Get("TRD/Calib/LocalVdrift");
383       if(entry) {
384         entry->SetOwner(kFALSE);
385         padVdrift = (AliTRDCalPad*)entry->GetObject();
386       }
387       ProcessTRDCalibArray(chamberVdrift, padVdrift, 
388                            parName,
389                            runMeanVdrift, runRMSVdrift,
390                            chamberMeanVdrift, chamberRMSVdrift,
391                            smMeanVdrift, smRMSVdrift);
392     }
393     
394     // process T0
395     AliTRDCalDet *chamberT0 = 0;
396     AliTRDCalPad *padT0 = 0;
397     Double_t runMeanT0=0.0, runRMST0=0.0;
398     TVectorD chamberMeanT0(AliTRDcalibDB::kNdet);
399     TVectorD chamberRMST0(AliTRDcalibDB::kNdet);
400     TVectorD smMeanT0(AliTRDcalibDB::kNsector);
401     TVectorD smRMST0(AliTRDcalibDB::kNsector);
402     parName = "T0";
403     if(getCalibrationInfo) {
404       entry = manager->Get("TRD/Calib/ChamberT0");
405       if(entry) {
406         entry->SetOwner(kFALSE);
407         chamberT0 = (AliTRDCalDet*)entry->GetObject();
408       }
409       entry = manager->Get("TRD/Calib/LocalT0");
410       if(entry) {
411         entry->SetOwner(kFALSE);
412         padT0 = (AliTRDCalPad*)entry->GetObject();
413       }
414       ProcessTRDCalibArray(chamberT0, padT0, 
415                            parName,
416                            runMeanT0, runRMST0,
417                            chamberMeanT0, chamberRMST0,
418                            smMeanT0, smRMST0);
419     }    
420
421     // process pad and chamber status
422     AliTRDCalChamberStatus* chamberStatus = 0;
423     AliTRDCalPadStatus *padStatus = 0;
424     Float_t runBadPadFraction=0.0;
425     TVectorD chamberBadPadFraction(AliTRDcalibDB::kNdet);
426     TVectorD chamberStatusValues(AliTRDcalibDB::kNdet);
427     if(getCalibrationInfo) {
428       entry = manager->Get("TRD/Calib/ChamberStatus");
429       if(entry) {
430         entry->SetOwner(kFALSE);
431         chamberStatus = (AliTRDCalChamberStatus*)entry->GetObject();
432       }
433       entry = manager->Get("TRD/Calib/PadStatus");
434       if(entry) {
435         entry->SetOwner(kFALSE);
436         padStatus = (AliTRDCalPadStatus*)entry->GetObject();
437       }
438       ProcessTRDstatus(chamberStatus, padStatus, 
439                        runBadPadFraction, chamberBadPadFraction,
440                        chamberStatusValues);
441     }
442
443     // get Goofie information
444     AliTRDSensorArray *goofieGainSensors = 0x0;
445     AliTRDSensorArray *goofieHvSensors = 0x0;
446     AliTRDSensorArray *goofiePressureSensors = 0x0;
447     AliTRDSensorArray *goofieTempSensors = 0x0;
448     AliTRDSensorArray *goofieVelocitySensors = 0x0;
449     AliTRDSensorArray *goofieCO2Sensors = 0x0;
450     AliTRDSensorArray *goofieN2Sensors = 0x0;
451
452     if(getGoofieInfo) {
453       // goofie gain
454       entry = manager->Get("TRD/Calib/trd_goofieGain");
455       if(entry) {
456         entry->SetOwner(kTRUE);
457         goofieGainSensors = (AliTRDSensorArray*)entry->GetObject();
458       }
459       // goofie HV
460       entry = manager->Get("TRD/Calib/trd_goofieHv");
461       if(entry) {
462         entry->SetOwner(kTRUE);
463         goofieHvSensors = (AliTRDSensorArray*)entry->GetObject();
464       }
465       // goofie pressure
466       entry = manager->Get("TRD/Calib/trd_goofiePressure");
467       if(entry) {
468         entry->SetOwner(kTRUE);
469         goofiePressureSensors = (AliTRDSensorArray*)entry->GetObject();
470       }
471       // goofie temperature
472       entry = manager->Get("TRD/Calib/trd_goofieTemp");
473       if(entry) {
474         entry->SetOwner(kTRUE);
475         goofieTempSensors = (AliTRDSensorArray*)entry->GetObject();
476       }
477       // goofie drift velocity
478       entry = manager->Get("TRD/Calib/trd_goofieVelocity");
479       if(entry) {
480         entry->SetOwner(kTRUE);
481         goofieVelocitySensors = (AliTRDSensorArray*)entry->GetObject();
482       }
483       // goofie CO2
484       entry = manager->Get("TRD/Calib/trd_goofieCO2");
485       if(entry) {
486         entry->SetOwner(kTRUE);
487         goofieCO2Sensors = (AliTRDSensorArray*)entry->GetObject();
488       }
489       // goofie N2
490       entry = manager->Get("TRD/Calib/trd_goofieN2");
491       if(entry) {
492         entry->SetOwner(kTRUE);
493         goofieN2Sensors = (AliTRDSensorArray*)entry->GetObject();
494       }
495     }   // end if getGoofieInfo
496
497     // process the DCS FEE arrays
498     Int_t nSB1 = 0; Int_t nSB2 = 0; Int_t nSB3 = 0; Int_t nSB4 = 0; Int_t nSB5 = 0; 
499     Int_t nChanged = 0;
500     Bool_t sorAndEor = kFALSE;
501     TVectorD statusArraySOR(AliTRDcalibDB::kNdet);
502     TVectorD statusArrayEOR(AliTRDcalibDB::kNdet);
503     Int_t dcsFeeGlobalNTimeBins = -1;
504     Int_t dcsFeeGlobalConfigTag = -1;
505     Int_t dcsFeeGlobalSingleHitThres = -1;
506     Int_t dcsFeeGlobalThreePadClustThres = -1;
507     Int_t dcsFeeGlobalSelectiveNoSZ = -1;
508     Int_t dcsFeeGlobalTCFilterWeight = -1;
509     Int_t dcsFeeGlobalTCFilterShortDecPar = -1;
510     Int_t dcsFeeGlobalTCFilterLongDecPar = -1;
511     Int_t dcsFeeGlobalModeFastStatNoise = -1;
512     TObjString dcsFeeGlobalConfigVersion("");
513     TObjString dcsFeeGlobalConfigName("");
514     TObjString dcsFeeGlobalFilterType("");
515     TObjString dcsFeeGlobalReadoutParam("");
516     TObjString dcsFeeGlobalTestPattern("");
517     TObjString dcsFeeGlobalTrackletMode("");
518     TObjString dcsFeeGlobalTrackletDef("");
519     TObjString dcsFeeGlobalTriggerSetup("");
520     TObjString dcsFeeGlobalAddOptions("");
521     if(getDCSInfo) {
522       TObjArray *objArrayCDB = 0;
523       AliTRDCalDCS* calDCSsor = 0x0;
524       AliTRDCalDCS* calDCSeor = 0x0;
525       entry = manager->Get("TRD/Calib/DCS");
526       if(entry) {
527         entry->SetOwner(kTRUE);
528         objArrayCDB = (TObjArray*)entry->GetObject();
529         if(objArrayCDB) {
530           objArrayCDB->SetOwner(kTRUE);
531           calDCSsor = (AliTRDCalDCS*)objArrayCDB->At(0);
532           calDCSeor = (AliTRDCalDCS*)objArrayCDB->At(1);
533         }
534       }
535       ProcessTRDCalDCSFEE(calDCSsor, calDCSeor, 
536                           nSB1, nSB2, nSB3, nSB4, nSB5, 
537                           nChanged, sorAndEor, statusArraySOR, statusArrayEOR);
538       
539       if(calDCSsor || calDCSeor) {
540         AliTRDCalDCS *caldcs = 0;
541         if(calDCSsor) caldcs = calDCSsor;
542         else caldcs = calDCSeor;
543         dcsFeeGlobalNTimeBins = caldcs->GetGlobalNumberOfTimeBins();
544         dcsFeeGlobalConfigTag = caldcs->GetGlobalConfigTag();
545         dcsFeeGlobalSingleHitThres = caldcs->GetGlobalSingleHitThres();
546         dcsFeeGlobalThreePadClustThres = caldcs->GetGlobalThreePadClustThres();
547         dcsFeeGlobalSelectiveNoSZ = caldcs->GetGlobalSelectiveNoZS();
548         dcsFeeGlobalTCFilterWeight = caldcs->GetGlobalTCFilterWeight();
549         dcsFeeGlobalTCFilterShortDecPar = caldcs->GetGlobalTCFilterShortDecPar();
550         dcsFeeGlobalTCFilterLongDecPar = caldcs->GetGlobalTCFilterLongDecPar();
551         dcsFeeGlobalModeFastStatNoise = caldcs->GetGlobalModeFastStatNoise();
552         dcsFeeGlobalConfigVersion = caldcs->GetGlobalConfigVersion().Data();
553         dcsFeeGlobalConfigName = caldcs->GetGlobalConfigName().Data();
554         dcsFeeGlobalFilterType = caldcs->GetGlobalFilterType().Data();
555         dcsFeeGlobalReadoutParam = caldcs->GetGlobalReadoutParam().Data();
556         dcsFeeGlobalTestPattern = caldcs->GetGlobalTestPattern().Data();
557         dcsFeeGlobalTrackletMode = caldcs->GetGlobalTrackletMode().Data();
558         dcsFeeGlobalTrackletDef = caldcs->GetGlobalTrackletDef().Data();
559         dcsFeeGlobalTriggerSetup = caldcs->GetGlobalTriggerSetup().Data();
560         dcsFeeGlobalAddOptions = caldcs->GetGlobalAddOptions().Data();
561       }
562       if(objArrayCDB) objArrayCDB->RemoveAll();
563     }   // end if(getDCSInfo)
564        
565
566     // loop over time steps
567     for(UInt_t iTime = startTime; iTime<=endTime; iTime += dTime) {
568       // time stamp
569       TTimeStamp iStamp(iTime);
570       cout << "time step  " << iStamp.GetDate()/10000 << "/" 
571            << (iStamp.GetDate()/100)-(iStamp.GetDate()/10000)*100 << "/" 
572            << iStamp.GetDate()%100 << "   "
573            << iStamp.GetTime()/10000 << ":"
574            << (iStamp.GetTime()/100)-(iStamp.GetTime()/10000)*100 << ":" 
575            << iStamp.GetTime()%100 << endl;
576       
577       // cavern pressure
578       Float_t pressure = -99.;
579       if(cavern_pressure) 
580         pressure = cavern_pressure->Eval(iStamp);
581             
582       // surface pressure
583       Float_t surfacePressure = -99.;
584       if(surface_pressure) 
585         surfacePressure = surface_pressure->Eval(iStamp);
586             
587       // anode I sensors
588       TVectorD anodeIValues(AliTRDcalibDB::kNdet);
589       if(anodeISensors) 
590         ProcessTRDSensorArray(anodeISensors, iStamp, anodeIValues);
591             
592       // anode U sensors
593       TVectorD anodeUValues(AliTRDcalibDB::kNdet);
594       if(anodeUSensors) 
595         ProcessTRDSensorArray(anodeUSensors, iStamp, anodeUValues);
596             
597       // drift I sensors
598       TVectorD driftIValues(AliTRDcalibDB::kNdet);
599       if(driftISensors) 
600         ProcessTRDSensorArray(driftISensors, iStamp, driftIValues);
601       
602       // drift U sensors
603       TVectorD driftUValues(AliTRDcalibDB::kNdet);
604       if(driftUSensors) 
605         ProcessTRDSensorArray(driftUSensors, iStamp, driftUValues);
606       
607       // chamber temperatures
608       TVectorD envTempValues(AliTRDcalibDB::kNdet);
609       if(temperatureSensors) 
610         ProcessTRDSensorArray(temperatureSensors, iStamp, envTempValues);
611
612       // chamber status sensors
613       TVectorD statusValues(AliTRDcalibDB::kNdet);
614       if(chamberStatusSensors)
615         ProcessTRDSensorArray(chamberStatusSensors, iStamp, statusValues);
616
617       // gas overpressure
618       TVectorD overpressureValues(overpressureSensors ? overpressureSensors->NumSensors() : 0);
619       if(overpressureSensors)
620         ProcessTRDSensorArray(overpressureSensors, iStamp, overpressureValues);
621       
622       // gas CO2
623       TVectorD gasCO2Values(gasCO2Sensors ? gasCO2Sensors->NumSensors() : 0);
624       if(gasCO2Sensors)
625         ProcessTRDSensorArray(gasCO2Sensors, iStamp, gasCO2Values);
626       
627       // gas H2O
628       TVectorD gasH2OValues(gasH2OSensors ? gasH2OSensors->NumSensors() : 0);
629       if(gasH2OSensors)
630         ProcessTRDSensorArray(gasH2OSensors, iStamp, gasH2OValues);
631       
632       // gas O2
633       TVectorD gasO2Values(gasO2Sensors ? gasO2Sensors->NumSensors() : 0);
634       if(gasO2Sensors)
635         ProcessTRDSensorArray(gasO2Sensors, iStamp, gasO2Values);
636       
637       // ADC Clk phase
638       //TVectorD adcClkPhaseValues(adcClkPhaseSensors ? adcClkPhaseSensors->NumSensors() : 0);
639       //if(adcClkPhaseSensors)
640 //      ProcessTRDSensorArray(adcClkPhaseSensors, iStamp, adcClkPhaseValues);
641
642       // goofie gain
643       TVectorD goofieGainValues(goofieGainSensors ? goofieGainSensors->NumSensors() : 0);
644       if(goofieGainSensors)
645         ProcessTRDSensorArray(goofieGainSensors, iStamp, goofieGainValues);
646
647       // goofie HV
648       TVectorD goofieHvValues(goofieHvSensors ? goofieHvSensors->NumSensors() : 0);
649       if(goofieHvSensors)
650         ProcessTRDSensorArray(goofieHvSensors, iStamp, goofieHvValues);
651
652       // goofie pressure
653       TVectorD goofiePressureValues(goofiePressureSensors ? goofiePressureSensors->NumSensors() : 0);
654       if(goofiePressureSensors)
655         ProcessTRDSensorArray(goofiePressureSensors, iStamp, goofiePressureValues);
656       
657       // goofie temperature
658       TVectorD goofieTempValues(goofieTempSensors ? goofieTempSensors->NumSensors() : 0);
659       if(goofieTempSensors) 
660         ProcessTRDSensorArray(goofieTempSensors, iStamp, goofieTempValues);
661       
662       // goofie drift velocity
663       TVectorD goofieVelocityValues(goofieVelocitySensors ? goofieVelocitySensors->NumSensors() : 0);
664       if(goofieVelocitySensors) 
665         ProcessTRDSensorArray(goofieVelocitySensors, iStamp, goofieVelocityValues);
666       
667       // goofie CO2
668       TVectorD goofieCO2Values(goofieCO2Sensors ? goofieCO2Sensors->NumSensors() : 0);
669       if(goofieCO2Sensors) 
670         ProcessTRDSensorArray(goofieCO2Sensors, iStamp, goofieCO2Values);
671       
672       // goofie N2
673       TVectorD goofieN2Values(goofieN2Sensors ? goofieN2Sensors->NumSensors() : 0);
674       if(goofieN2Sensors) 
675         ProcessTRDSensorArray(goofieN2Sensors, iStamp, goofieN2Values);
676       
677             
678       // fill the tree
679       (*treeStreamer)<< "trdTree"
680                      << "run=" << currRun
681                      << "time=" << iTime
682                      << "startTimeGRP=" << startTime
683                      << "endTimeGRP=" << endTime
684                      << "runType.=" << &runType
685                      << "cavernPressure=" << pressure
686                      << "surfacePressure=" << surfacePressure
687                      << "detectorMask=" << detectorMask;
688       if(getMonitoringInfo) {
689         (*treeStreamer)<< "trdTree"
690                        << "hvAnodeI.=" << &anodeIValues
691                        << "hvAnodeU.=" << &anodeUValues
692                        << "hvDriftI.=" << &driftIValues
693                        << "hvDriftU.=" << &driftUValues
694                        << "envTemp.=" << &envTempValues
695                        << "sensorStatusValues.=" << &statusValues
696                        << "gasOverPressure.=" << &overpressureValues
697                        << "gasCO2.=" << &gasCO2Values
698                        << "gasH2O.=" << &gasH2OValues
699                        << "gasO2.=" << &gasO2Values;
700                        //<< "adcClkPhase.=" << &adcClkPhaseValues;
701       }
702       if(getGoofieInfo) {
703         (*treeStreamer)<< "trdTree"
704                        << "goofieGain.=" << &goofieGainValues
705                        << "goofieHV.=" << &goofieHvValues
706                        << "goofiePressure.=" << &goofiePressureValues
707                        << "goofieTemp.=" << &goofieTempValues
708                        << "goofieVelocity.=" << &goofieVelocityValues
709                        << "goofieCO2.=" << &goofieCO2Values
710                        << "goofieN2.=" << &goofieN2Values;
711       }
712       if(getCalibrationInfo) {
713         (*treeStreamer)<< "trdTree"
714                        << "runMeanGain=" << runMeanGain
715                        << "runRMSGain=" << runRMSGain
716                        << "smMeanGain.=" << &smMeanGain
717                        << "smRMSGain.=" << &smRMSGain
718                        << "chamberMeanGain.=" << &chamberMeanGain
719                        << "chamberRMSGain.=" << &chamberRMSGain
720                        << "runMeanNoise=" << runMeanNoise
721                        << "runRMSNoise=" << runRMSNoise
722                        << "smMeanNoise.=" << &smMeanNoise
723                        << "smRMSNoise.=" << &smRMSNoise
724                        << "chamberMeanNoise.=" << &chamberMeanNoise
725                        << "chamberRMSNoise.=" << &chamberRMSNoise
726                        << "runMeanVdrift=" << runMeanVdrift
727                        << "runRMSVdrift=" << runRMSVdrift
728                        << "smMeanVdrift.=" << &smMeanVdrift
729                        << "smRMSVdrift.=" << &smRMSVdrift
730                        << "chamberMeanVdrift.=" << &chamberMeanVdrift
731                        << "chamberRMSVdrift.=" << &chamberRMSVdrift
732                        << "runMeanT0=" << runMeanT0
733                        << "runRMST0=" << runRMST0
734                        << "smMeanT0.=" << &smMeanT0
735                        << "smRMST0.=" << &smRMST0
736                        << "chamberMeanT0.=" << &chamberMeanT0
737                        << "chamberRMST0.=" << &chamberRMST0
738                        << "runBadPadFraction=" << runBadPadFraction
739                        << "chamberBadPadFraction.=" << &chamberBadPadFraction
740                        << "chamberStatusValues.=" << &chamberStatusValues;
741       }
742       if(getDCSInfo) {
743         (*treeStreamer)<< "trdTree" 
744                        << "dcsFeeGlobalNTimeBins=" << dcsFeeGlobalNTimeBins
745                        << "dcsFeeGlobalConfigTag=" << dcsFeeGlobalConfigTag
746                        << "dcsFeeGlobalSingleHitThres=" << dcsFeeGlobalSingleHitThres
747                        << "dcsFeeGlobalThreePadClustThres=" << dcsFeeGlobalThreePadClustThres
748                        << "dcsFeeGlobalSelectiveNoSZ=" << dcsFeeGlobalSelectiveNoSZ
749                        << "dcsFeeGlobalTCFilterWeight=" << dcsFeeGlobalTCFilterWeight
750                        << "dcsFeeGlobalTCFilterShortDecPar=" << dcsFeeGlobalTCFilterShortDecPar
751                        << "dcsFeeGlobalTCFilterLongDecPar=" << dcsFeeGlobalTCFilterLongDecPar
752                        << "dcsFeeGlobalModeFastStatNoise=" << dcsFeeGlobalModeFastStatNoise
753           //                 << "dcsFeeGlobalConfigVersion.=" << &dcsFeeGlobalConfigVersion
754           //                 << "dcsFeeGlobalConfigName.=" << &dcsFeeGlobalConfigName
755           //                 << "dcsFeeGlobalFilterType.=" << &dcsFeeGlobalFilterType
756           //                 << "dcsFeeGlobalReadoutParam.=" << &dcsFeeGlobalReadoutParam
757           //                 << "dcsFeeGlobalTestPattern.=" << &dcsFeeGlobalTestPattern
758           //                 << "dcsFeeGlobalTrackletMode.=" << &dcsFeeGlobalTrackletMode
759           //                 << "dcsFeeGlobalTrackletDef.=" << &dcsFeeGlobalTrackletDef
760           //                 << "dcsFeeGlobalTriggerSetup.=" << &dcsFeeGlobalTriggerSetup
761           //                 << "dcsFeeGlobalAddOptions.=" << &dcsFeeGlobalAddOptions
762                        << "statusDCSFEESOR.=" << &statusArraySOR
763                        << "statusDCSFEEEOR.=" << &statusArrayEOR
764                        << "SORandEOR=" << sorAndEor
765                        << "nChanged=" << nChanged
766                        << "nSB1=" << nSB1
767                        << "nSB2=" << nSB2
768                        << "nSB3=" << nSB3
769                        << "nSB4=" << nSB4
770                        << "nSB5=" << nSB5;
771       }
772       (*treeStreamer)<< "trdTree"
773                      << "\n";
774     }  // end loop over time steps
775
776     // add the run number to the list of runs
777     runs.ResizeTo(runs.GetNoElements()+1);
778     runs[runs.GetNoElements()-1] = currRun;
779
780     // do some cleaning
781     if(grpObject) delete grpObject;
782     if(anodeISensors) anodeISensors->Clear();
783     if(anodeUSensors) anodeUSensors->Clear();
784     if(driftISensors) driftISensors->Clear();
785     if(driftUSensors) driftUSensors->Clear();
786     if(temperatureSensors) temperatureSensors->Clear();
787     if(overpressureSensors) overpressureSensors->Clear();
788     if(gasCO2Sensors) gasCO2Sensors->Clear();
789     if(gasH2OSensors) gasH2OSensors->Clear();
790     if(gasO2Sensors) gasO2Sensors->Clear();
791     //if(adcClkPhaseSensors) adcClkPhaseSensors->Clear();
792     if(goofieGainSensors) goofieGainSensors->Clear();
793     if(goofieHvSensors) goofieHvSensors->Clear();
794     if(goofiePressureSensors) goofiePressureSensors->Clear();
795     if(goofieTempSensors) goofieTempSensors->Clear();
796     if(goofieVelocitySensors) goofieVelocitySensors->Clear();
797     if(goofieCO2Sensors) goofieCO2Sensors->Clear();
798     if(goofieN2Sensors) goofieN2Sensors->Clear();
799     if(chamberGainFactor) delete chamberGainFactor;
800     if(padGainFactor) delete padGainFactor;
801     if(chamberNoise) delete chamberNoise;
802     if(padNoise) delete padNoise;
803     if(chamberVdrift) delete chamberVdrift;
804     if(padVdrift) delete padVdrift;
805     if(chamberT0) delete chamberT0;
806     if(padT0) delete padT0;
807     if(chamberStatus) delete chamberStatus;
808     if(padStatus) delete padStatus;
809   } // end while (loop over runs)
810   TTimeStamp loopEndTime;
811
812   treeStreamer->GetFile()->cd();
813   runs.Write("runs");
814   delete treeStreamer;
815
816   // output some job informations
817   TTimeStamp jobEndTime;
818   cout << "=============================================" << endl;
819   cout << "Job launched at          :  " << jobStartTime.AsString() << endl;
820   cout << "Loop over runs started at:  " << loopStartTime.AsString() << endl;
821   cout << "Loop over runs ended at  :  " << loopEndTime.AsString() << endl;
822   cout << "Job ended at             :  " << jobEndTime.AsString() << endl;
823   cout << "Initialization duration  :  " 
824        << loopStartTime.GetSec() - jobStartTime.GetSec() << " seconds" << endl;
825   cout << "Loop over runs duration  :  " 
826        << loopEndTime.GetSec() - loopStartTime.GetSec() << " seconds" << endl;
827   cout << "Post loop                :  "
828        << jobEndTime.GetSec() - loopEndTime.GetSec() << " seconds" << endl;
829   cout << "Running time per processed run:  "
830        << (loopEndTime.GetSec()-loopStartTime.GetSec())/(runs.GetNoElements()>0 ? Double_t(runs.GetNoElements()) : 1.0)
831        << " sec./run" << endl;
832   cout << "Running time per input run:  "
833        << (loopEndTime.GetSec()-loopStartTime.GetSec())/((rejectedRuns.GetNoElements()+runs.GetNoElements())>0 ? Double_t(runs.GetNoElements()+rejectedRuns.GetNoElements()) : 1.0)
834        << " sec./run" << endl;
835
836   // print the runs that had problems
837   cout << "number of rejected runs: " << rejectedRuns.GetNoElements() << endl;
838   cout << "rejected run numbers" << endl;
839   cout << "********************" << endl;
840   for(Int_t iRun=0; iRun<rejectedRuns.GetNoElements(); iRun++) {
841     cout << rejectedRuns[iRun] << "    ";
842     if(iRun%10==0) cout << endl;
843   }
844   cout << "=============================================" << endl;
845   return;
846 }
847
848 //__________________________________________________________________________________________
849 void ProcessTRDSensorArray(AliTRDSensorArray *sensorArray, TTimeStamp timeStamp, TVectorD &values) {
850   // Fill a vector with sensor values for a given time stamp
851   // The sensor->Eval() method makes interpolation inside the covered time interval
852   // and returns the value at the closest time limit (start or end) outside the covered time range
853   AliDCSSensor *sensor;
854   for(Int_t i=0; i<sensorArray->NumSensors(); i++) {
855     sensor = sensorArray->GetSensorNum(i);
856     if(sensor && sensor->GetGraph()) 
857       values[i] = sensor->Eval(timeStamp);
858     else
859       values[i] = -99.;
860   }
861   return;
862 }
863
864 //__________________________________________________________________________________________
865 void ProcessTRDCalibArray(AliTRDCalDet* chamberCalib, AliTRDCalPad *padCalib,
866                           TString parName,
867                           Double_t &runValue, Double_t &runRMS,
868                           TVectorD &chamberValues, TVectorD &chamberValuesRMS,
869                           TVectorD &superModuleValues, TVectorD &superModuleValuesRMS) {
870   // Process the calibrations for a given run.
871   // Calculates the run and chamber wise averages
872   //
873
874   // check if the calibration parameter is multiplicative or additive
875   Bool_t multiplicative = kTRUE;
876   if(!parName.CompareTo("T0")) multiplicative = kFALSE;
877
878   // first iteration (calculate all averages and RMS without discrimination on the SM average)
879   gRunWiseHisto->Reset();
880   for(Int_t iSM = 0; iSM<AliTRDcalibDB::kNsector; iSM++) {   // loop over supermodules
881     // reset the super module histogram
882     gSuperModuleWiseHisto->Reset();
883     // check if SM is installed
884     if(!gkSuperModuleStatus[iSM]) continue;
885     for(Int_t iChamber=iSM*AliTRDcalibDB::kNstack*AliTRDcalibDB::kNlayer; 
886         iChamber < (iSM+1)*AliTRDcalibDB::kNstack*AliTRDcalibDB::kNlayer; 
887         iChamber++) {  // loop over chambers in this supermodule
888       // get the chamber value
889       Float_t chamberValue = chamberCalib->GetValue(iChamber);
890       // get the ROC object
891       AliTRDCalROC *chamberROC = padCalib->GetCalROC(iChamber);
892       if(!chamberROC) 
893         continue;
894       gChamberWiseHisto->Reset();
895       for(Int_t iChannel = 0; iChannel < chamberROC->GetNchannels(); iChannel++){ // loop over channels
896         // calculate the calibration parameter for this pad
897         Float_t padValue;
898         if(multiplicative)
899           padValue = chamberValue * chamberROC->GetValue(iChannel);
900         else
901           padValue = chamberValue + chamberROC->GetValue(iChannel);
902         // fill the run, SM and chamber wise histograms
903         gChamberWiseHisto->Fill(padValue);
904         // if the parameter is Noise then check if the pad value is not a default one
905         // Default value is now 1.2!!!! Check with Raphaelle for more informations
906         if(parName.Contains("Noise") &&
907            TMath::Abs(padValue-1.2)<0.00001) continue;
908         gSuperModuleWiseHisto->Fill(padValue);
909         gRunWiseHisto->Fill(padValue);
910       }  // end loop over channels
911       // get the chamber wise mean and RMS
912       chamberValues[iChamber] = gChamberWiseHisto->GetMean();
913       chamberValuesRMS[iChamber] = gChamberWiseHisto->GetRMS();
914     }  // end loop over chambers
915     // SM wise mean and RMS
916     superModuleValues[iSM] = gSuperModuleWiseHisto->GetMean();
917     superModuleValuesRMS[iSM] = gSuperModuleWiseHisto->GetRMS();
918   }  // end loop over supermodules
919   // run wise mean and RMS
920   runValue = gRunWiseHisto->GetMean();
921   runRMS = gRunWiseHisto->GetRMS();
922
923   // Noise and Gain are finished processing
924   if(parName.Contains("Noise") || parName.Contains("Gain"))
925     return;
926   // second iteration (calculate SM and run wise averages and RMS for Vdrift and T0)
927   // The pads with calib parameter equal to the SM average are discarded (default value)
928   gRunWiseHisto->Reset();
929   for(Int_t iSM = 0; iSM<AliTRDcalibDB::kNsector; iSM++) {   // loop over supermodules
930     gSuperModuleWiseHisto->Reset();
931     // eliminate the uninstalled super modules
932     if(!gkSuperModuleStatus[iSM]) continue;
933     for(Int_t iChamber=iSM*AliTRDcalibDB::kNstack*AliTRDcalibDB::kNlayer; 
934         iChamber < (iSM+1)*AliTRDcalibDB::kNstack*AliTRDcalibDB::kNlayer; 
935         iChamber++) {  // loop over chambers
936       // the chamber value
937       Float_t chamberValue = chamberCalib->GetValue(iChamber);
938       AliTRDCalROC *chamberROC = padCalib->GetCalROC(iChamber);
939       if(!chamberROC) 
940         continue;
941       
942       for(Int_t iChannel = 0; iChannel < chamberROC->GetNchannels(); iChannel++){ // loop over channels in a chamber
943         // get the pad value
944         Float_t padValue;
945         if(multiplicative)
946           padValue = chamberValue * chamberROC->GetValue(iChannel);
947         else
948           padValue = chamberValue + chamberROC->GetValue(iChannel);
949         // eliminate from the average and RMS calculation all pads which
950         // have the calib parameter equal with the SM average
951         if((parName.Contains("Vdrift") || parName.Contains("T0")) && 
952            TMath::Abs(padValue-superModuleValues[iSM])<0.00001) continue;
953         gSuperModuleWiseHisto->Fill(padValue);
954         gRunWiseHisto->Fill(padValue);
955       }   // end loop over channels
956     }   // end loop over chambers 
957     superModuleValues[iSM] = gSuperModuleWiseHisto->GetMean();
958     superModuleValuesRMS[iSM] = gSuperModuleWiseHisto->GetRMS();
959   }   // end loop over super modules
960   runValue = gRunWiseHisto->GetMean();
961   runRMS = gRunWiseHisto->GetRMS();
962   return;
963 }
964
965 //__________________________________________________________________________________________
966 void ProcessTRDstatus(AliTRDCalChamberStatus* chamberStatus, AliTRDCalPadStatus* padStatus,
967                       Float_t &runBadPadFraction, TVectorD &chamberBadPadFraction,
968                       TVectorD &chamberStatusValues) {
969   // Process the pad status. Calculates the fraction of pads with non 0 status
970   // run and chamber wise
971   //
972   Int_t runPadStatusNot0 = 0;
973   Int_t runPadStatusAll = 0;
974
975   Int_t superModuleStatus[18] = {1, 1, 0, 0, 0, 0, 0, 1, 1,
976                                  1, 1, 0, 0, 0, 0, 0, 0, 1};  
977
978   // loop over chambers
979   for(Int_t iChamber=0; iChamber < AliTRDcalibDB::kNdet; iChamber++) {
980     // check if the chamber is in an installed sector;
981     Int_t sm = AliTRDgeometry::GetSector(iChamber);
982     if(!superModuleStatus[sm]) continue;
983
984     chamberStatusValues[iChamber] = chamberStatus->GetStatus(iChamber);
985     AliTRDCalSingleChamberStatus *singleChamberStatus = padStatus->GetCalROC(iChamber);
986     if(!singleChamberStatus)
987       continue;
988     Int_t chamberPadStatusNot0 = 0;
989     Int_t chamberPadStatusAll = 0;
990     // loop over channels in a chamber
991     for(Int_t iChannel = 0; iChannel < singleChamberStatus->GetNchannels(); iChannel++) {
992       if(singleChamberStatus->GetStatus(iChannel) > 0) {
993         chamberPadStatusNot0++;
994         runPadStatusNot0++;
995       }
996       chamberPadStatusAll++;
997       runPadStatusAll++;
998     }
999     chamberBadPadFraction[iChamber] = (chamberPadStatusAll>0 ? 
1000                                        Float_t(chamberPadStatusNot0)/Float_t(chamberPadStatusAll) : -99.);
1001   }
1002   runBadPadFraction = (runPadStatusAll>0 ? Float_t(runPadStatusNot0)/Float_t(runPadStatusAll) : -99.);
1003   return;
1004 }
1005
1006 //__________________________________________________________________________________________
1007 void ProcessTRDCalDCSFEE(AliTRDCalDCS *caldcsSOR, AliTRDCalDCS *caldcsEOR, 
1008                          Int_t &nsb1, Int_t &nsb2, Int_t &nsb3, Int_t &nsb4, Int_t &nsb5,
1009                          Int_t &nChanged, Bool_t &sorAndEor, 
1010                          TVectorD &statusArraySOR, TVectorD &statusArrayEOR) {
1011   //
1012   // Process the DCS information
1013   //
1014   sorAndEor = kTRUE;
1015   if(!caldcsSOR && !caldcsEOR) {
1016     sorAndEor = kFALSE;
1017     return;
1018   }
1019   else if(caldcsSOR && !caldcsEOR) {
1020     sorAndEor = kFALSE;
1021   }
1022   else if(!caldcsSOR && caldcsEOR) {
1023     caldcsSOR = caldcsEOR;
1024     sorAndEor = kFALSE;
1025   }
1026
1027   nsb1 = 0; nsb2 = 0; nsb3 = 0; nsb4 = 0; nsb5 = 0; nChanged = 0;
1028   for(Int_t iROC=0; iROC<AliTRDcalibDB::kNdet && iROC<caldcsSOR->GetFEEArr()->GetSize(); iROC++) {
1029     AliTRDCalDCSFEE *dcsSorFee = caldcsSOR->GetCalDCSFEEObj(iROC);
1030     AliTRDCalDCSFEE *dcsEorFee = caldcsEOR->GetCalDCSFEEObj(iROC);
1031     if(dcsSorFee) {
1032       statusArraySOR[iROC] = dcsSorFee->GetStatusBit();
1033       if(statusArraySOR[iROC] == 1) nsb1++;
1034       if(statusArraySOR[iROC] == 2) nsb2++;
1035       if(statusArraySOR[iROC] == 3) nsb3++;
1036       if(statusArraySOR[iROC] == 4) nsb4++;
1037       if(statusArraySOR[iROC] == 5) nsb5++;
1038     }
1039     if(dcsEorFee) {
1040       statusArrayEOR[iROC] = dcsEorFee->GetStatusBit();
1041     }
1042     if(sorAndEor) {
1043       if((statusArraySOR[iROC]-statusArrayEOR[iROC]) != 0) nChanged++;
1044     } 
1045   }
1046   return;
1047 }
1048
1049 //__________________________________________________________________________________________
1050 void MakeRunListFromOCDB(const Char_t* directory, const Char_t* outfile, Bool_t fromAlien) {
1051   //
1052   // For a given OCDB path dump the list of available run numbers
1053   //
1054   if(fromAlien)
1055     gSystem->Exec(Form("alien_ls %s > temp.txt", directory));
1056   else
1057     gSystem->Exec(Form("ls %s > temp.txt", directory));
1058
1059   ifstream inBuffer("temp.txt");
1060   if(!inBuffer.is_open()) {
1061     cout << "File temp.txt not opened! Exiting" << endl;
1062     return;
1063   }
1064   ofstream outBuffer(outfile);
1065   if(!outBuffer.is_open()) {
1066     cout << "File runList.txt cannot be opened! Exiting" << endl;
1067     return;
1068   }
1069
1070   while(!inBuffer.eof()) {
1071     char inputLine[128];
1072     inBuffer.getline(inputLine, 128, '\n');
1073     int runLow, runHigh;
1074     const char* tempLine = inputLine;
1075     sscanf(tempLine, "Run%d_%d_v1_s0.root", &runLow, &runHigh);
1076     outBuffer << runLow << endl;
1077   }
1078
1079   inBuffer.close();
1080   outBuffer.close();
1081   gSystem->Exec("rm temp.txt");
1082   return;
1083 }