]> git.uio.no Git - u/mrichter/AliRoot.git/blob - TRD/AliTRDPreprocessor.cxx
Speed up AliTRDseedV1::AttachClusyters() and add HLT data containers as friend classe...
[u/mrichter/AliRoot.git] / TRD / AliTRDPreprocessor.cxx
1 /**************************************************************************
2  * Copyright(c) 1998-1999, 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 /* $Id$ */
17
18 ////////////////////////////////////////////////////////////////////////////
19 //                                                                        //
20 // This class is a first implementation for the TRD.                      //
21 // It takes data from HLT and computes the parameters                     //
22 // and stores both reference data and online calibration                  //
23 // parameters in the CDB                                                  //
24 // It alsotakes DCS data, does spline fits                                //
25 // and stores both reference data and spline fits results                 //
26 // in the CDB                                                             //
27 //                                                                        //
28 // Authors:                                                               //
29 //   R. Bailhache (R.Bailhache@gsi.de)                                    //
30 //   W. Monange   (w.monange@gsi.de)                                      //
31 //   F. Kramer    (kramer@ikf.uni-frankfurt.de)                           //
32 //                                                                        //
33 ////////////////////////////////////////////////////////////////////////////
34
35 #include <fstream>
36
37 #include <TFile.h>
38 #include <TProfile2D.h>
39 #include <TObjString.h>
40 #include <TString.h>
41 #include <TList.h>
42 #include <TSAXParser.h>
43
44 #include "AliCDBMetaData.h"
45 #include "AliLog.h"
46
47 #include "AliTRDPreprocessor.h"
48 #include "AliTRDSensorArray.h"
49 #include "AliTRDCalibraFit.h"
50 #include "AliTRDCalibraMode.h"
51 #include "AliTRDCalibPadStatus.h"
52 #include "AliTRDSaxHandler.h"
53 #include "AliTRDgeometry.h"
54 #include "Cal/AliTRDCalPad.h"
55 #include "Cal/AliTRDCalPadStatus.h"
56 #include "Cal/AliTRDCalDCS.h"
57 #include "Cal/AliTRDCalSingleChamberStatus.h"
58 #include "Cal/AliTRDCalROC.h"
59
60 ClassImp(AliTRDPreprocessor)
61
62 //______________________________________________________________________________________________
63 AliTRDPreprocessor::AliTRDPreprocessor(AliShuttleInterface *shuttle)
64   :AliPreprocessor("TRD", shuttle)
65   ,fVdriftHLT(0)
66 {
67   //
68   // Constructor
69   //
70
71   AddRunType("PHYSICS");
72   AddRunType("STANDALONE");
73   AddRunType("PEDESTAL");
74   AddRunType("DAQ");
75   
76 }
77
78 //______________________________________________________________________________________________
79 AliTRDPreprocessor::~AliTRDPreprocessor()
80 {
81   //
82   // Destructor
83   //
84
85 }
86
87 //______________________________________________________________________________________________
88 void AliTRDPreprocessor::Initialize(Int_t run, UInt_t startTime, UInt_t endTime)
89 {
90   //
91   // Initialization routine for the TRD preprocessor
92   //
93
94   AliPreprocessor::Initialize(run,startTime,endTime);
95
96 }
97
98 //______________________________________________________________________________________________
99 UInt_t AliTRDPreprocessor::Process(TMap* dcsAliasMap)
100 {
101   //
102   // Process DCS and calibration part for HLT
103   //
104
105   TString runType = GetRunType();
106   Log(Form("runtype %s\n",runType.Data()));
107   
108   // always process the configuration data
109  if(ProcessDCSConfigData()) return 1; 
110   
111   if (runType=="PEDESTAL"){
112     if(ExtractPedestals()) return 1;
113     return 0;
114   } 
115
116   if ((runType=="PHYSICS") || (runType=="STANDALONE") || (runType=="DAQ")){
117     // DCS
118     if(ProcessDCS(dcsAliasMap)) return 1; 
119     if(runType=="PHYSICS"){
120       // HLT if On
121       //TString runPar = GetRunParameter("HLTStatus");
122       //if(runPar=="1") {
123       if(GetHLTStatus()) {
124         if(ExtractHLT()) return 1; // for testing!
125       } 
126       // DAQ if HLT failed
127       if(!fVdriftHLT) {
128         if(ExtractDriftVelocityDAQ()) return 1; // for testing!
129       }
130     }
131   }
132   
133   return 0;  
134   
135 }
136 //______________________________________________________________________________
137 Bool_t AliTRDPreprocessor::ProcessDCS()
138 {
139   //
140   // Default process DCS method
141   //
142
143   TString runType = GetRunType();
144   if ((runType == "PHYSICS") || (runType == "STANDALONE")) {
145     return kTRUE;
146   }
147   return kFALSE;
148
149 }
150
151 //______________________________________________________________________________
152 Bool_t AliTRDPreprocessor::ProcessDCS(TMap *dcsAliasMap)
153 {
154   //
155   // Process DCS method
156   //
157
158   Bool_t error = kFALSE;
159
160   AliCDBMetaData metaData;
161   metaData.SetBeamPeriod(0);
162   metaData.SetResponsible("Wilfried Monange/Raphaelle Bailhache");
163   metaData.SetComment("TRD calib test");
164
165   Log("****** DCS ******\n");
166         
167   TObjArray * list=AliTRDSensorArray::GetList ();
168         
169   if (list == 0x0) {
170     Log ("Error during AliTRDSensorArray::GetList");
171     Log ("DCS will not be processing");
172     return kTRUE;
173   }
174
175   Int_t nEntries = list->GetEntries ();
176   Log (Form ("%d alias loaded", nEntries));
177                 
178   Bool_t * results=new Bool_t [nEntries];
179   Int_t  * nGraph=new Int_t [nEntries];
180                 
181   for (Int_t iAlias = 0; iAlias < nEntries; iAlias++) {
182                         
183     AliTRDSensorArray * oneTRDDCS = (AliTRDSensorArray *)list->At (iAlias);
184                         
185     oneTRDDCS->SetStartTime (TTimeStamp (fStartTime));
186     oneTRDDCS->SetEndTime (TTimeStamp (fEndTime));
187                         
188     Log(Form("Processing DCS : \"%s\"", oneTRDDCS->GetStoreName ().Data ()));
189                         
190     TMap * map;
191
192     map=oneTRDDCS->ExtractDCS (dcsAliasMap);
193                 
194     nGraph [iAlias] = map->GetEntries ();
195                 
196     if (nGraph [iAlias] == 0) {
197       Log("No TGraph for this dcsDatapointAlias : not stored");
198       results [iAlias] = kFALSE;
199       error  = kTRUE;
200       continue;
201     }
202                 
203     oneTRDDCS->SetGraph(map);
204     results[iAlias]=Store("Calib", oneTRDDCS->GetStoreName().Data(), oneTRDDCS, &metaData, 0, kTRUE); 
205     delete map;         
206
207     //results [iAlias] = StoreReferenceData("Calib", oneTRDDCS->GetStoreName ().Data (), oneTRDDCS, &metaData); 
208
209     if (!results[iAlias]) {
210       AliError("Problem during StoreRef DCS");
211       error=kTRUE;
212     }
213
214     //BEGIN TEST (should not be removed ...)
215     /*
216     oneTRDDCS->ClearGraph();
217     oneTRDDCS->ClearFit();
218     oneTRDDCS->SetDiffCut2 (0.1);
219     map=oneTRDDCS->ExtractDCS (dcsAliasMap);
220     oneTRDDCS->SetGraph (map);
221     Store("Calib", ("cut_"+oneTRDDCS->GetStoreName()).Data(), oneTRDDCS, &metaData, 0, kTRUE); 
222     delete map;
223
224
225     if(iAlias==1 || iAlias==19) continue;
226     
227     oneTRDDCS->ClearGraph();
228     oneTRDDCS->ClearFit();
229     oneTRDDCS->SetDiffCut2(0);
230     map=oneTRDDCS->ExtractDCS(dcsAliasMap);
231     oneTRDDCS->MakeSplineFit(map);
232     Store("Calib", ("fit_"+oneTRDDCS->GetStoreName()).Data() , oneTRDDCS, &metaData, 0, kTRUE); 
233     delete map;
234
235      
236     oneTRDDCS->ClearGraph(); 
237     oneTRDDCS->ClearFit();
238     oneTRDDCS->SetDiffCut2 (0.1);
239     map=oneTRDDCS->ExtractDCS (dcsAliasMap);
240     oneTRDDCS->MakeSplineFit(map);
241     Store("Calib", ("cutfit_"+oneTRDDCS->GetStoreName()).Data() , oneTRDDCS, &metaData, 0, kTRUE); 
242     delete map;
243     */    
244     //END TEST
245
246   }
247                 
248   Log ("         Summury of DCS :\n");
249   Log (Form("%30s %10s %10s", "dcsDatapointAlias", "Stored ?", "# graph"));
250   for (Int_t iAlias = 0; iAlias < nEntries; iAlias++) {
251     AliTRDSensorArray * oneTRDDCS = (AliTRDSensorArray *)list->At (iAlias);
252     Log (Form ("%30s %10s %4d", 
253                oneTRDDCS->GetStoreName ().Data (),
254                results[iAlias] ? "ok" : "X",
255                nGraph [iAlias]));
256   }
257   Log ("*********** End of DCS **********");
258   
259   delete results;
260   delete nGraph;
261
262   return error;
263
264 }
265
266 //______________________________________________________________________________________________
267 Bool_t AliTRDPreprocessor::ExtractPedestals()
268 {
269   //
270   // Pedestal running on LDCs at the DAQ
271   //
272
273   //
274   // The reference data are stored in:
275   // PadStatus1 for sm-00-01-02-09-10-11
276   // PadStatus2 for sm-03-04-05-12-13-14
277   // PadStatus3 for sm-06-07-08-15-16-17
278   // PadStatus0 if nothing found..means problems
279   //
280
281   Bool_t error = kFALSE;
282
283   // Init a AliTRDCalibPadStatus
284   AliTRDCalibPadStatus calPedSum = AliTRDCalibPadStatus();
285
286   AliCDBMetaData metaData;
287   metaData.SetBeamPeriod(0);
288   metaData.SetResponsible("Raphaelle Bailhache");
289   metaData.SetComment("TRD calib test");
290   
291   // Sum the contributions of the LDCs
292   TList * listpad = GetFileSources(kDAQ,"PADSTATUS");
293   if (!listpad) {
294     Log("No list found for the PEDESTRAL Run");
295     return kTRUE;
296   }
297   
298   // loop through all files from LDCs  
299   UInt_t index = 0;
300   while (listpad->At(index)!=NULL) {
301     TObjString* fileNameEntry = (TObjString*) listpad->At(index);
302     if (fileNameEntry != NULL)
303       {
304         TString fileName = GetFile(kDAQ, "PADSTATUS",
305                                    fileNameEntry->GetString().Data());
306         if(fileName.Length() ==0){
307           Log(Form("Error by retrieving the file %d for the pedestal",(Int_t)index));
308           delete listpad;
309           return kTRUE;
310         }
311         
312         TFile *f = TFile::Open(fileName);
313         AliTRDCalibPadStatus *calPed;
314         f->GetObject("calibpadstatus",calPed);
315         
316         if(calPed){
317           
318           Int_t ldc = 0; 
319
320           // analyse
321           //calPed->AnalyseHisto();
322                   
323           // Add to the calPedSum
324           for (Int_t idet=0; idet<540; idet++) {
325             AliTRDCalROC *rocMean  = calPed->GetCalRocMean(idet, kFALSE);
326             if ( rocMean )  {
327               calPedSum.SetCalRocMean(rocMean,idet);
328               ldc = (Int_t) (idet / 30);
329             }
330             AliTRDCalROC *rocRMS = calPed->GetCalRocRMS(idet, kFALSE);
331             if ( rocRMS )  {
332               calPedSum.SetCalRocRMS(rocRMS,idet);
333             }
334             AliTRDCalROC *rocMeand  = calPed->GetCalRocMeand(idet, kFALSE);
335             if ( rocMeand )  {
336               calPedSum.SetCalRocMeand(rocMeand,idet);
337             }
338             AliTRDCalROC *rocRMSd = calPed->GetCalRocRMSd(idet, kFALSE);
339             if ( rocRMSd )  {
340               calPedSum.SetCalRocRMSd(rocRMSd,idet);
341             }
342           }// det loop
343
344           if((ldc==0) || (ldc==1) || (ldc==2)) ldc = 1;
345           if((ldc==3) || (ldc==4) || (ldc==5)) ldc = 2;
346           if((ldc==6) || (ldc==7) || (ldc==8)) ldc = 3;
347           if((ldc==9) || (ldc==10) || (ldc==11)) ldc = 4;
348           if((ldc==12) || (ldc==13) || (ldc==14)) ldc = 5;
349           if((ldc==15) || (ldc==16) || (ldc==17)) ldc = 6;
350         
351           // store as reference data
352           TString name("PadStatus");
353           name += ldc;
354           if(!StoreReferenceData("DAQData",(const char *)name,(TObject *) calPed,&metaData)){
355             Log(Form("Error storing AliTRDCalibPadStatus object %d as reference data",(Int_t)index));
356             error = kTRUE;
357           }
358
359         } // calPed
360       } // fileNameEntry
361     ++index;
362   }// while (list)
363
364   Log(Form("%d elements found in the list for the pedestal",(Int_t)index));
365   if(index==0){
366     delete listpad;
367     return kTRUE;
368   }
369
370   //
371   // Create pedestal 
372   //
373     
374   // Create Pad Status
375   AliTRDCalPadStatus *calPadStatus = calPedSum.CreateCalPadStatus();
376   // Create Noise 
377   //Make the AliTRDCalPad
378   AliTRDCalPad *calPad2 = calPedSum.CreateCalPad();
379   //Make the AliTRDCalDet correspondant
380   AliTRDCalDet *calDet = calPedSum.CreateCalDet();
381  
382   //
383   // Take the noise and Pad status from the previous OCDB
384   //
385
386   AliTRDCalPad *calPadPrevious=0;
387   AliCDBEntry* entry = GetFromOCDB("Calib", "PadNoise");
388   if (entry) calPadPrevious = (AliTRDCalPad*)entry->GetObject();
389   if ( calPadPrevious==NULL ) {
390      Log("AliTRDPreprocsessor: No previous TRD pad noise entry available.\n");
391      calPadPrevious = new AliTRDCalPad("PadNoise", "PadNoise");
392   }
393
394   AliTRDCalPadStatus *calPadStatusPrevious=0;
395   entry = GetFromOCDB("Calib", "PadStatus");
396   if (entry) calPadStatusPrevious = (AliTRDCalPadStatus*)entry->GetObject();
397   if ( calPadStatusPrevious==NULL ) {
398     Log("AliTRDPreprocsessor: No previous TRD pad status entry available.\n");
399     calPadStatusPrevious = new AliTRDCalPadStatus("padstatus", "padstatus");
400     for (Int_t idet=0; idet<540; ++idet)
401       {
402         AliTRDCalSingleChamberStatus *calROC = calPadStatusPrevious->GetCalROC(idet);
403         for(Int_t k = 0; k < calROC->GetNchannels(); k++){
404           calROC->SetStatus(k,AliTRDCalPadStatus::kMasked);
405         }
406       }
407   }
408
409   
410   // Loop over detectors for check
411   for (Int_t det=0; det<AliTRDgeometry::kNdet; ++det)  {
412     
413     // noise
414     AliTRDCalROC *calROCPreviousNoise = calPadPrevious->GetCalROC(det);
415     AliTRDCalROC *calROCNoise         = calPad2->GetCalROC(det);
416
417     // padstatus
418     AliTRDCalSingleChamberStatus *calROCPreviousStatus = calPadStatusPrevious->GetCalROC(det);
419     AliTRDCalSingleChamberStatus *calROCStatus         = calPadStatus->GetCalROC(det);
420     
421     
422     // loop over first half and second half chamber
423     for(Int_t half = 0; half < 2; half++){
424
425       Bool_t data         = AreThereDataPedestal(calROCStatus,(Bool_t)half);
426       //printf("There are data for the detector %d the half %d: %d\n",det,half,data);
427       if(!data){
428         // look if data in the OCDB
429         Bool_t dataPrevious = AreThereDataPedestal(calROCPreviousStatus,(Bool_t)half);
430         // if no data at all, set to default value
431         if(!dataPrevious){
432           SetDefaultStatus(*calROCStatus,(Bool_t)half);
433           SetDefaultNoise(*calROCNoise,(Bool_t)half);
434         }
435         else{
436           // if data, set to previous value
437           SetStatus(*calROCStatus,calROCPreviousStatus,(Bool_t)half);
438           SetNoise(*calROCNoise,calROCPreviousNoise,(Bool_t)half);
439         }
440       }
441     }
442   }
443   
444   //
445   // Store  
446   //  
447
448   AliCDBMetaData md3; 
449   md3.SetObjectClassName("AliTRDCalPadStatus");
450   md3.SetResponsible("Raphaelle Bailhache");
451   md3.SetBeamPeriod(1);
452   md3.SetComment("TRD calib test");
453   if(!Store("Calib","PadStatus"    ,(TObject *)calPadStatus, &md3, 0, kTRUE)){
454     Log("Error storing the pedestal");
455     delete listpad;
456     return kTRUE;
457   }
458
459   AliCDBMetaData md4; 
460   md4.SetObjectClassName("AliTRDCalPad");
461   md4.SetResponsible("Raphaelle Bailhache");
462   md4.SetBeamPeriod(1);
463   md4.SetComment("TRD calib test");
464   if(!Store("Calib","PadNoise"    ,(TObject *)calPad2, &md4, 0, kTRUE)){
465     Log("Error storing the pedestal");
466     delete listpad;
467     return kTRUE;
468   }
469   
470   AliCDBMetaData md5; 
471   md5.SetObjectClassName("AliTRDCalDet");
472   md5.SetResponsible("Raphaelle Bailhache");
473   md5.SetBeamPeriod(1);
474   md5.SetComment("TRD calib test");
475   if(!Store("Calib","DetNoise"    ,(TObject *)calDet, &md5, 0, kTRUE)){
476     Log("Error storing the pedestal");
477     delete listpad;
478     return kTRUE;
479   }  
480
481   delete listpad;
482   return error; 
483   
484 }
485
486 //__________________________________________________________________
487 Bool_t AliTRDPreprocessor::AreThereDataPedestal(AliTRDCalSingleChamberStatus * const calROCStatus
488                                               , Bool_t second)
489 {
490
491   //
492   // Data for this half chamber
493   //
494
495   Bool_t data         = kFALSE;
496   Int_t nCols         = calROCStatus->GetNcols();
497   Int_t nCol0         = 0;
498   Int_t nColE         = (Int_t) nCols/2 - 2;
499   if(second) {
500     nCol0 = nColE + 4;
501     nColE = nCols;
502   }
503
504   Int_t totalnumberofpads = 0;
505   Int_t totalnumberofdata = 0; 
506
507   for(Int_t col = nCol0; col < nColE; col++){
508     for(Int_t row = 0; row < calROCStatus->GetNrows(); row++){
509       totalnumberofpads++;
510       //printf("ismasked %d\n",(Int_t)calROCStatus->IsMasked(col,row));
511       if(!calROCStatus->GetStatus(col,row)) {
512         data = kTRUE;
513         totalnumberofdata++;
514       }
515     }
516   }
517   if(totalnumberofdata < (Int_t)(totalnumberofpads/2)) data = kFALSE;
518
519   return data;
520   
521 }
522 //__________________________________________________________________
523 void AliTRDPreprocessor::SetDefaultStatus(AliTRDCalSingleChamberStatus &calROCStatus, Bool_t second){
524
525   //
526   // default status for this half chamber
527   //
528
529   Int_t nCols         = calROCStatus.GetNcols();
530   Int_t nCol0         = 0;
531   Int_t nColE         = (Int_t) nCols/2;
532   if(second) {
533     nCol0 = nColE;
534     nColE = nCols;
535   }
536   for(Int_t col = nCol0; col < nColE; col++){
537     for(Int_t row = 0; row < calROCStatus.GetNrows(); row++){
538       calROCStatus.SetStatus(col,row,0);
539     }
540   }
541 }
542 //__________________________________________________________________
543 void AliTRDPreprocessor::SetStatus(AliTRDCalSingleChamberStatus &calROCStatus, AliTRDCalSingleChamberStatus *calROCStatusPrevious,Bool_t second){
544
545   //
546   // previous status for this half chamber
547   //
548
549   Int_t nCols         = calROCStatus.GetNcols();
550   Int_t nCol0         = 0;
551   Int_t nColE         = (Int_t) nCols/2;
552   if(second) {
553     nCol0 = nColE;
554     nColE = nCols;
555   }
556   for(Int_t col = nCol0; col < nColE; col++){
557     for(Int_t row = 0; row < calROCStatus.GetNrows(); row++){
558       calROCStatus.SetStatus(col,row,calROCStatusPrevious->GetStatus(col,row));
559     }
560   }
561 }
562 //__________________________________________________________________
563 void AliTRDPreprocessor::SetDefaultNoise(AliTRDCalROC &calROCNoise, Bool_t second){
564
565   //
566   // default noise for this half chamber
567   //
568
569   Int_t nCols         = calROCNoise.GetNcols();
570   Int_t nCol0         = 0;
571   Int_t nColE         = (Int_t) nCols/2;
572   if(second) {
573     nCol0 = nColE;
574     nColE = nCols;
575   }
576   for(Int_t col = nCol0; col < nColE; col++){
577     for(Int_t row = 0; row < calROCNoise.GetNrows(); row++){
578       calROCNoise.SetValue(col,row,0.12);
579     }
580   }
581 }
582 //__________________________________________________________________
583 void AliTRDPreprocessor::SetNoise(AliTRDCalROC &calROCNoise, AliTRDCalROC *calROCNoisePrevious, Bool_t second){
584
585   //
586   // previous noise for this half chamber
587   //
588
589   Int_t nCols         = calROCNoise.GetNcols();
590   Int_t nCol0         = 0;
591   Int_t nColE         = (Int_t) nCols/2;
592   if(second) {
593     nCol0 = nColE;
594     nColE = nCols;
595   }
596   for(Int_t col = nCol0; col < nColE; col++){
597     for(Int_t row = 0; row < calROCNoise.GetNrows(); row++){
598       calROCNoise.SetValue(col,row,calROCNoisePrevious->GetValue(col,row));
599     }
600   }
601 }
602 //______________________________________________________________________________________________
603 Bool_t AliTRDPreprocessor::ExtractDriftVelocityDAQ()
604 {
605   //
606   // Drift velocity DA running on monitoring servers at the DAQ
607   //
608
609   Bool_t error = kFALSE; 
610
611   // Objects for HLT and DAQ zusammen
612   AliTRDCalibraFit *calibra = AliTRDCalibraFit::Instance();
613   AliCDBMetaData metaData;
614   metaData.SetBeamPeriod(0);
615   metaData.SetResponsible("Raphaelle Bailhache");
616   metaData.SetComment("TRD calib test");
617   // Store the infos for the detector
618   AliCDBMetaData md1; 
619   md1.SetObjectClassName("AliTRDCalDet");
620   md1.SetResponsible("Raphaelle Bailhache");
621   md1.SetBeamPeriod(0);
622   md1.SetComment("TRD calib test");
623   // Store the infos for the pads
624   AliCDBMetaData md2; 
625   md2.SetObjectClassName("AliTRDCalPad");
626   md2.SetResponsible("Raphaelle Bailhache");
627   md2.SetBeamPeriod(0);
628   md2.SetComment("TRD calib test");
629
630   // Take the file from the DAQ file exchange server
631   TList *listdaq = GetFileSources(kDAQ,"VDRIFT");
632   if (!listdaq) {
633     Log("No list found for vdrift (DAQ)");
634     return kTRUE;
635   }
636   
637   if(listdaq->GetSize() !=1){
638     Log(Form("Problem on the size of the list: %d (DAQ)",listdaq->GetSize()));
639     delete listdaq;
640     return kTRUE;
641   }
642   
643   TObjString* fileNameEntry = (TObjString*) listdaq->At(0);
644   if(fileNameEntry != NULL){
645     TString fileName = GetFile(kDAQ, "VDRIFT",
646                                fileNameEntry->GetString().Data());
647     if(fileName.Length() ==0){
648       Log("Error retrieving the file vdrift (DAQ)");
649       delete listdaq;
650       return kTRUE;
651     }
652     TFile *filedaq = TFile::Open(fileName);
653     TProfile2D *histodriftvelocity = (TProfile2D *) filedaq->Get("PH2d");
654     if (histodriftvelocity) {
655       
656       // store as reference data
657       if(!StoreReferenceData("DAQData","VdriftT0",(TObject *) histodriftvelocity,&metaData)){
658         Log("Error storing 2D Profile for vdrift from the DAQ");
659         error = kTRUE;
660       }
661       
662       // analyse
663       
664       Log("Take the PH reference data. Now we will try to fit\n");
665       calibra->SetMinEntries(2000); // If there is less than 2000
666       calibra->AnalysePH(histodriftvelocity);
667       
668       Int_t nbtg = 6*4*18*((Int_t) ((AliTRDCalibraMode *)calibra->GetCalibraMode())->GetDetChamb0(1))
669         + 6*  18*((Int_t) ((AliTRDCalibraMode *)calibra->GetCalibraMode())->GetDetChamb2(1));
670       Int_t nbfit        = calibra->GetNumberFit();
671       Int_t nbE        = calibra->GetNumberEnt();
672       
673       // if enough statistics store the results
674       if ((nbtg >                  0) && 
675           (nbfit        >= 0.5*nbE)) {
676         // create the cal objects
677         calibra->PutMeanValueOtherVectorFit(1,kTRUE);
678         calibra->PutMeanValueOtherVectorFit2(1,kTRUE);
679         TObjArray object      = calibra->GetVectorFit();
680         AliTRDCalDet *objdriftvelocitydet = calibra->CreateDetObjectVdrift(&object,kTRUE);
681         TObject *objdriftvelocitypad = calibra->CreatePadObjectVdrift();
682         object              = calibra->GetVectorFit2();
683         AliTRDCalDet *objtime0det         = calibra->CreateDetObjectT0(&object,kTRUE);
684         TObject *objtime0pad         = calibra->CreatePadObjectT0();
685         calibra->ResetVectorFit();
686         // store
687         if(!Store("Calib","ChamberVdrift"    ,(TObject *) objdriftvelocitydet,&md1,0,kTRUE)){
688           Log("Error storing the calibration object for the chamber vdrift (DAQ)");
689           error = kTRUE;
690         }
691         if(!Store("Calib","ChamberT0"        ,(TObject *) objtime0det        ,&md1,0,kTRUE)){
692           Log("Error storing the calibration object for the chamber t0 (DAQ)");
693           error = kTRUE;
694         }
695         if(!Store("Calib","LocalVdrift"      ,(TObject *) objdriftvelocitypad,&md2,0,kTRUE)){
696           Log("Error storing the calibration object for the local drift velocity (DAQ)");
697           error = kTRUE;
698         }
699         if(!Store("Calib","LocalT0"          ,(TObject *) objtime0pad        ,&md2,0,kTRUE)){
700           Log("Error storing the calibration object for the local time0 (DAQ)");
701           error = kTRUE;
702         }
703       }
704       else{
705         Log("Not enough statistics for the average pulse height (DAQ)");
706       }
707     } // histo here
708   }// if fileNameEntry
709   
710   delete listdaq; 
711   return error; 
712   
713 }
714
715 //______________________________________________________________________________________________
716 Bool_t AliTRDPreprocessor::ExtractHLT()
717 {
718   //
719   // Gain, vdrift and PRF calibration running on HLT
720   // return kTRUE if NULL pointer to the list
721   //
722
723   Bool_t error = kFALSE;
724
725   // Objects for HLT and DAQ zusammen
726   AliTRDCalibraFit *calibra = AliTRDCalibraFit::Instance();
727   AliCDBMetaData metaData;
728   metaData.SetBeamPeriod(0);
729   metaData.SetResponsible("Raphaelle Bailhache");
730   metaData.SetComment("TRD calib test");
731   // Store the infos for the detector
732   AliCDBMetaData md1; 
733   md1.SetObjectClassName("AliTRDCalDet");
734   md1.SetResponsible("Raphaelle Bailhache");
735   md1.SetBeamPeriod(0);
736   md1.SetComment("TRD calib test");
737   // Store the infos for the pads
738   AliCDBMetaData md2; 
739   md2.SetObjectClassName("AliTRDCalPad");
740   md2.SetResponsible("Raphaelle Bailhache");
741   md2.SetBeamPeriod(0);
742   md2.SetComment("TRD calib test");
743   
744   // Take the file from the HLT file exchange server
745   TList *listhlt = GetFileSources(kHLT,"GAINDRIFTPRF");
746   if (!listhlt) {
747     Log("No list found for the HLT");
748     return kTRUE;
749   }
750
751   if(listhlt->GetSize() != 1) {
752     Log(Form("Problem on the size of the list: %d (HLT)",listhlt->GetSize()));
753     delete listhlt;
754     return kTRUE;
755   }
756   
757   TObjString* fileNameEntry = (TObjString*) listhlt->At(0);
758   if(fileNameEntry != NULL){
759     TString fileName = GetFile(kHLT, "GAINDRIFTPRF",
760                                fileNameEntry->GetString().Data());
761     if(fileName.Length() ==0){
762       Log("Error retrieving the file (HLT)");
763       delete listhlt;
764       return kTRUE;
765     }
766     // Take the file
767     TFile *filehlt = TFile::Open(fileName);
768     
769     // gain
770     TH2I *histogain = (TH2I *) filehlt->Get("CH2d");
771     histogain->SetDirectory(0);
772     if (histogain) {
773       // store the reference data
774       if(!StoreReferenceData("HLTData","Gain",(TObject *) histogain,&metaData)){
775         Log("Error storing 2D histos for gain");
776         error = kTRUE;
777       }
778       // analyse
779       Log("Take the CH reference data. Now we will try to fit\n");
780       calibra->SetMinEntries(800); // If there is less than 1000 entries in the histo: no fit
781       calibra->AnalyseCH(histogain);
782       Int_t nbtg = 6*4*18*((Int_t) ((AliTRDCalibraMode *)calibra->GetCalibraMode())->GetDetChamb0(0))
783         + 6*  18*((Int_t) ((AliTRDCalibraMode *)calibra->GetCalibraMode())->GetDetChamb2(0));
784       Int_t nbfit       = calibra->GetNumberFit();
785       Int_t nbE         = calibra->GetNumberEnt();
786       // enough statistics
787       if ((nbtg >                  0) && 
788           (nbfit        >= 0.5*nbE)) {
789         // create the cal objects
790         calibra->PutMeanValueOtherVectorFit(1,kTRUE);
791         TObjArray object           = calibra->GetVectorFit();
792         AliTRDCalDet *objgaindet   = calibra->CreateDetObjectGain(&object);
793         TObject *objgainpad        = calibra->CreatePadObjectGain();
794         // store them
795         if(!Store("Calib","ChamberGainFactor",(TObject *) objgaindet         ,&md1,0,kTRUE)){
796           Log("Error storing the calibration object for the chamber gain");
797           error = kTRUE;
798         }
799         if(!Store("Calib","LocalGainFactor"  ,(TObject *) objgainpad         ,&md2,0,kTRUE)){
800           Log("Error storing the calibration object for the local gain factor");
801           error = kTRUE;
802         }
803       }
804       calibra->ResetVectorFit();
805     }// if histogain
806     
807     // vdrift
808     fVdriftHLT = kFALSE;
809     TProfile2D *histodriftvelocity = (TProfile2D *) filehlt->Get("PH2d");
810     histodriftvelocity->SetDirectory(0);
811     if (histodriftvelocity) {
812       // store the reference data
813       if(!StoreReferenceData("HLTData","VdriftT0",(TObject *) histodriftvelocity,&metaData)){
814         Log("Error storing 2D Profile for average pulse height (HLT)");
815         error = kTRUE;
816       }
817       // analyse
818       Log("Take the PH reference data. Now we will try to fit\n");
819       calibra->SetMinEntries(800*20); // If there is less than 20000
820       calibra->AnalysePH(histodriftvelocity);
821       Int_t nbtg = 6*4*18*((Int_t) ((AliTRDCalibraMode *)calibra->GetCalibraMode())->GetDetChamb0(1))
822         + 6*  18*((Int_t) ((AliTRDCalibraMode *)calibra->GetCalibraMode())->GetDetChamb2(1));
823       Int_t nbfit        = calibra->GetNumberFit();
824       Int_t nbE          = calibra->GetNumberEnt();
825       // enough statistics
826       if ((nbtg >                  0) && 
827           (nbfit        >= 0.5*nbE)) {
828         // create the cal objects
829         calibra->PutMeanValueOtherVectorFit(1,kTRUE);
830         calibra->PutMeanValueOtherVectorFit2(1,kTRUE);
831         TObjArray object  = calibra->GetVectorFit();
832         AliTRDCalDet *objdriftvelocitydet = calibra->CreateDetObjectVdrift(&object,kTRUE);
833         TObject *objdriftvelocitypad      = calibra->CreatePadObjectVdrift();
834         object              = calibra->GetVectorFit2();
835         AliTRDCalDet *objtime0det  = calibra->CreateDetObjectT0(&object,kTRUE);
836         TObject *objtime0pad       = calibra->CreatePadObjectT0();
837         // store them
838         if(!Store("Calib","ChamberVdrift"    ,(TObject *) objdriftvelocitydet,&md1,0,kTRUE)){
839           Log("Error storing the calibration object for the chamber vdrift (HLT)");
840           error = kTRUE;                
841         }
842         if(!Store("Calib","ChamberT0"        ,(TObject *) objtime0det        ,&md1,0,kTRUE)){
843           Log("Error storing the calibration object for the chamber t0 (HLT)");
844           error = kTRUE;
845         }
846         if(!Store("Calib","LocalVdrift"      ,(TObject *) objdriftvelocitypad,&md2,0,kTRUE)){
847           Log("Error storing the calibration object for the local drift velocity (HLT)");
848           error = kTRUE;
849         }
850         if(!Store("Calib","LocalT0"          ,(TObject *) objtime0pad        ,&md2,0,kTRUE)){
851           Log("Error storing the calibration object for the local time0 (HLT)");
852           error = kTRUE;
853         }
854         fVdriftHLT = kTRUE;
855       }
856       calibra->ResetVectorFit();
857     }// if TProfile2D
858     
859     // prf
860     TProfile2D *histoprf = (TProfile2D *) filehlt->Get("PRF2d");
861     histoprf->SetDirectory(0);
862     if (histoprf) {
863       // store reference data
864       if(!StoreReferenceData("HLTData","PRF",(TObject *) histoprf,&metaData)){
865         Log("Error storing the 2D Profile for Pad Response Function");
866         error = kTRUE;
867       }
868       // analyse
869       Log("Take the PRF reference data. Now we will try to fit\n");
870       calibra->SetMinEntries(600); // If there is less than 20000
871       calibra->AnalysePRFMarianFit(histoprf);
872       Int_t nbtg = 6*4*18*((Int_t) ((AliTRDCalibraMode *)calibra->GetCalibraMode())->GetDetChamb0(2))
873         + 6*  18*((Int_t) ((AliTRDCalibraMode *)calibra->GetCalibraMode())->GetDetChamb2(2));
874       Int_t nbfit        = calibra->GetNumberFit();
875       Int_t nbE          = calibra->GetNumberEnt();
876       // enough statistics
877       if ((nbtg >                  0) && 
878           (nbfit        >= 0.95*nbE)) {
879         // create cal pad objects 
880         TObjArray object            = calibra->GetVectorFit();
881         TObject *objPRFpad          = calibra->CreatePadObjectPRF(&object);
882         // store them
883         if(!Store("Calib","PRFWidth"         ,(TObject *) objPRFpad          ,&md2,0,kTRUE)){
884           Log("Error storing the calibration object for the Pad Response Function");
885           error = kTRUE;
886         }
887       }
888       calibra->ResetVectorFit();
889     }// if PRF
890   }// if fileNameEntry
891   
892   delete listhlt;
893   return error;
894   
895 }
896
897 //_____________________________________________________________________________
898 UInt_t AliTRDPreprocessor::ProcessDCSConfigData()
899 {
900   // 
901   // process the configuration of FEE, PTR and GTU
902   // reteive XML filei(s) from the DCS FXS
903   // parse it/them and store TObjArrays in the CDB
904   //
905   // return 0 for success, otherwise:
906   //  5 : could not get the SOR file from the FXS
907   //  6 : could not get the EOR file from the FXS
908   //  7 : 
909   //  8 : something wrong with the SOR file
910   //  9 : something wrong with the EOR file
911   // 10 : SOR XML is not well-formed
912   // 11 : EOR XML is not well-formed
913   // 12 : ERROR in XML SAX validation: something wrong with the content
914   // 13 :
915   // 14 : ERROR while creating calibration objects in the handler
916   // 15 : error while storing data in the CDB
917   //
918
919   Log("Processing the DCS config summary files.");
920
921   // get the XML files
922   Log("Requesting the 2 summaryfiles from the FXS..");
923   const char *xmlFileS = GetFile(kDCS,"CONFIGSUMMARYSOR","");
924   const char *xmlFileE = GetFile(kDCS,"CONFIGSUMMARYEOR","");
925   // for the time being just request BOTH files from the FXS
926   // THEN it can be created online (otherwise the FXS would be messed up)
927   // the next step is to actually read BOTH files and store their informations
928   if (xmlFileS == NULL) {
929     Log(Form("ERROR: SOR File %s not found!",xmlFileS));
930     return 5;
931   } else if (xmlFileE == NULL) {
932     Log(Form("ERROR: EOR File %s not found!",xmlFileE));
933     return 6;
934   } else {
935     Log(Form("Both Files (%s and %s) found.",xmlFileS,xmlFileE));
936   }
937   
938   // test the files
939   std::ifstream fileTestS, fileTestE;
940   fileTestS.open(xmlFileS, std::ios_base::binary | std::ios_base::in);
941   fileTestE.open(xmlFileE, std::ios_base::binary | std::ios_base::in);
942   if (!fileTestS.good() || fileTestS.eof() || !fileTestS.is_open()) {
943     Log(Form("ERROR: File %s not valid!",xmlFileS));
944     return 8;
945   }
946   if (!fileTestE.good() || fileTestE.eof() || !fileTestE.is_open()) {
947     Log(Form("ERROR: File %s not valid!",xmlFileE));
948     return 9;
949   }
950   fileTestS.seekg(0, std::ios_base::end);
951   fileTestE.seekg(0, std::ios_base::end);
952   if (static_cast<int>(fileTestS.tellg()) < 2) {
953     Log(Form("ERROR: File %s is empty!",xmlFileS));
954     return 8;
955   }
956   if (static_cast<int>(fileTestE.tellg()) < 2) {
957     Log(Form("ERROR: File %s is empty!",xmlFileE));
958     return 9;
959   }
960   Log("Files are tested valid.");   
961
962   // make a robust XML validation
963   TSAXParser testParser;
964   if (testParser.ParseFile(xmlFileS) < 0 ) {
965     Log("ERROR: XML content (SOR) is not well-formed.");
966     return 10;
967   } else if (testParser.ParseFile(xmlFileE) < 0 ) {
968     Log("ERROR: XML content (EOR) is not well-formed.");
969     return 11;
970   }
971   Log("XML contents are well-formed.");
972       
973   // create parser and parse
974   TSAXParser saxParserS, saxParserE;
975   AliTRDSaxHandler saxHandlerS, saxHandlerE;
976   saxParserS.ConnectToHandler("AliTRDSaxHandler", &saxHandlerS);
977   saxParserS.ParseFile(xmlFileS);
978   saxParserE.ConnectToHandler("AliTRDSaxHandler", &saxHandlerE);
979   saxParserE.ParseFile(xmlFileE);
980
981   // report errors if present
982   if ((saxParserS.GetParseCode() == 0) && (saxParserE.GetParseCode() == 0)) {
983     Log("XML file validation OK.");
984   } else {
985     Log(Form("ERROR in XML file validation. Parsecodes: SOR: %s, EOR: %s", saxParserS.GetParseCode(), saxParserE.GetParseCode()));
986     return 12;
987   }
988   if ((saxHandlerS.GetHandlerStatus() == 0) && (saxHandlerE.GetHandlerStatus() == 0)) {
989     Log("SAX handler reports no errors.");
990   } else  {
991     Log(Form("ERROR while creating calibration objects. Error codes: SOR: %s, EOR: %s", saxHandlerS.GetHandlerStatus(), saxHandlerE.GetHandlerStatus()));
992     return 14;
993   }
994
995   // get the calibration object storing the data from the handler
996   AliTRDCalDCS* fCalDCSObjSOR = saxHandlerS.GetCalDCSObj();
997   AliTRDCalDCS* fCalDCSObjEOR = saxHandlerE.GetCalDCSObj();
998   fCalDCSObjSOR->EvaluateGlobalParameters();
999   fCalDCSObjEOR->EvaluateGlobalParameters();
1000   
1001   // put both objects in one TObjArray to store them
1002   TObjArray* fCalObjArray = new TObjArray(2);
1003   fCalObjArray->SetOwner();
1004   fCalObjArray->AddAt(fCalDCSObjSOR,0);
1005   fCalObjArray->AddAt(fCalDCSObjEOR,1);
1006   
1007   // store the DCS calib data in the CDB
1008   AliCDBMetaData metaData1;
1009   metaData1.SetBeamPeriod(0);
1010   metaData1.SetResponsible("Frederick Kramer");
1011   metaData1.SetComment("DCS configuration data in two AliTRDCalDCS objects in one TObjArray (0:SOR, 1:EOR).");
1012   if (!Store("Calib", "DCS", fCalObjArray, &metaData1, 0, kTRUE)) {
1013     Log("problems while storing DCS config data object");
1014     return 15;
1015   } else {
1016     Log("DCS config data object stored.");
1017   }
1018
1019   //delete fCalObjArray;
1020
1021   Log("Processing of the DCS config summary file DONE.");  
1022   return 0;
1023 }