1 /**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
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 **************************************************************************/
18 ////////////////////////////////////////////////////////////////////////////
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 //
29 // R. Bailhache (R.Bailhache@gsi.de) //
30 // W. Monange (w.monange@gsi.de) //
31 // F. Kramer (kramer@ikf.uni-frankfurt.de) //
33 ////////////////////////////////////////////////////////////////////////////
36 #include <TProfile2D.h>
37 #include <TStopwatch.h>
38 #include <TObjString.h>
41 #include <TCollection.h>
42 #include <TSAXParser.h>
45 #include "AliCDBMetaData.h"
48 #include "AliTRDPreprocessor.h"
49 #include "AliTRDSensorArray.h"
50 #include "AliTRDCalibraFit.h"
51 #include "AliTRDCalibraMode.h"
52 #include "AliTRDCalibPadStatus.h"
53 #include "AliTRDSaxHandler.h"
54 #include "Cal/AliTRDCalDet.h"
55 #include "Cal/AliTRDCalPad.h"
56 #include "Cal/AliTRDCalPadStatus.h"
57 #include "Cal/AliTRDCalDCS.h"
58 #include "Cal/AliTRDCalSingleChamberStatus.h"
59 #include "Cal/AliTRDCalROC.h"
62 ClassImp(AliTRDPreprocessor)
64 //______________________________________________________________________________________________
65 AliTRDPreprocessor::AliTRDPreprocessor(AliShuttleInterface *shuttle)
66 :AliPreprocessor("TRD", shuttle)
73 AddRunType("PHYSICS");
74 AddRunType("STANDALONE");
75 AddRunType("PEDESTAL");
80 //______________________________________________________________________________________________
81 AliTRDPreprocessor::~AliTRDPreprocessor()
89 //______________________________________________________________________________________________
90 void AliTRDPreprocessor::Initialize(Int_t run, UInt_t startTime, UInt_t endTime)
93 // Initialization routine for the TRD preprocessor
96 AliPreprocessor::Initialize(run,startTime,endTime);
100 //______________________________________________________________________________________________
101 UInt_t AliTRDPreprocessor::Process(TMap* dcsAliasMap)
104 // Process DCS and calibration part for HLT
107 TString runType = GetRunType();
108 Log(Form("runtype %s\n",runType.Data()));
110 // always process the configuration data
111 /* Int_t resultDCSC = */ProcessDCSConfigData(); // for testing!
113 if (runType=="PEDESTAL"){
114 if(ExtractPedestals()) return 1;
118 if ((runType=="PHYSICS") || (runType=="STANDALONE") || (runType=="DAQ")){
120 /*if(*/ProcessDCS(dcsAliasMap)/*) return 1*/; // for testing!
121 if(runType=="PHYSICS"){
123 //TString runPar = GetRunParameter("HLTStatus");
126 /*if(*/ExtractHLT()/*) return 1*/; // for testing!
130 /*if(*/ExtractDriftVelocityDAQ()/*) return 1*/; // for testing!
138 //______________________________________________________________________________
139 Bool_t AliTRDPreprocessor::ProcessDCS()
142 // Default process DCS method
145 TString runType = GetRunType();
146 if ((runType == "PHYSICS") || (runType == "STANDALONE")) {
153 //______________________________________________________________________________
154 Bool_t AliTRDPreprocessor::ProcessDCS(TMap *dcsAliasMap)
157 // Process DCS method
160 Bool_t error = kFALSE;
162 AliCDBMetaData metaData;
163 metaData.SetBeamPeriod(0);
164 metaData.SetResponsible("Wilfried Monange/Raphaelle Bailhache");
165 metaData.SetComment("TRD calib test");
167 Log("****** DCS ******\n");
169 TObjArray * list=AliTRDSensorArray::GetList ();
172 Log ("Error during AliTRDSensorArray::GetList");
173 Log ("DCS will not be processing");
177 Int_t nEntries = list->GetEntries ();
178 Log (Form ("%d alias loaded", nEntries));
180 Bool_t * results=new Bool_t [nEntries];
181 Int_t * nGraph=new Int_t [nEntries];
183 for (Int_t iAlias = 0; iAlias < nEntries; iAlias++) {
185 AliTRDSensorArray * oneTRDDCS = (AliTRDSensorArray *)list->At (iAlias);
187 oneTRDDCS->SetStartTime (TTimeStamp (fStartTime));
188 oneTRDDCS->SetEndTime (TTimeStamp (fEndTime));
190 Log(Form("Processing DCS : \"%s\"", oneTRDDCS->GetStoreName ().Data ()));
194 map=oneTRDDCS->ExtractDCS (dcsAliasMap);
196 nGraph [iAlias] = map->GetEntries ();
198 if (nGraph [iAlias] == 0) {
199 Log("No TGraph for this dcsDatapointAlias : not stored");
200 results [iAlias] = kFALSE;
205 oneTRDDCS->SetGraph(map);
206 results[iAlias]=Store("Calib", oneTRDDCS->GetStoreName().Data(), oneTRDDCS, &metaData, 0, kTRUE);
209 //results [iAlias] = StoreReferenceData("Calib", oneTRDDCS->GetStoreName ().Data (), oneTRDDCS, &metaData);
211 if (!results[iAlias]) {
212 AliError("Problem during StoreRef DCS");
216 //BEGIN TEST (should not be removed ...)
218 oneTRDDCS->ClearGraph();
219 oneTRDDCS->ClearFit();
220 oneTRDDCS->SetDiffCut2 (0.1);
221 map=oneTRDDCS->ExtractDCS (dcsAliasMap);
222 oneTRDDCS->SetGraph (map);
223 Store("Calib", ("cut_"+oneTRDDCS->GetStoreName()).Data(), oneTRDDCS, &metaData, 0, kTRUE);
227 if(iAlias==1 || iAlias==19) continue;
229 oneTRDDCS->ClearGraph();
230 oneTRDDCS->ClearFit();
231 oneTRDDCS->SetDiffCut2(0);
232 map=oneTRDDCS->ExtractDCS(dcsAliasMap);
233 oneTRDDCS->MakeSplineFit(map);
234 Store("Calib", ("fit_"+oneTRDDCS->GetStoreName()).Data() , oneTRDDCS, &metaData, 0, kTRUE);
238 oneTRDDCS->ClearGraph();
239 oneTRDDCS->ClearFit();
240 oneTRDDCS->SetDiffCut2 (0.1);
241 map=oneTRDDCS->ExtractDCS (dcsAliasMap);
242 oneTRDDCS->MakeSplineFit(map);
243 Store("Calib", ("cutfit_"+oneTRDDCS->GetStoreName()).Data() , oneTRDDCS, &metaData, 0, kTRUE);
250 Log (" Summury of DCS :\n");
251 Log (Form("%30s %10s %10s", "dcsDatapointAlias", "Stored ?", "# graph"));
252 for (Int_t iAlias = 0; iAlias < nEntries; iAlias++) {
253 AliTRDSensorArray * oneTRDDCS = (AliTRDSensorArray *)list->At (iAlias);
254 Log (Form ("%30s %10s %4d",
255 oneTRDDCS->GetStoreName ().Data (),
256 results[iAlias] ? "ok" : "X",
259 Log ("*********** End of DCS **********");
268 //______________________________________________________________________________________________
269 Bool_t AliTRDPreprocessor::ExtractPedestals()
272 // Pedestal running on LDCs at the DAQ
276 // The reference data are stored in:
277 // PadStatus1 for sm-00-01-02-09-10-11
278 // PadStatus2 for sm-03-04-05-12-13-14
279 // PadStatus3 for sm-06-07-08-15-16-17
280 // PadStatus0 if nothing found..means problems
283 Bool_t error = kFALSE;
285 // Init a AliTRDCalibPadStatus
286 AliTRDCalibPadStatus calPedSum = AliTRDCalibPadStatus();
288 AliCDBMetaData metaData;
289 metaData.SetBeamPeriod(0);
290 metaData.SetResponsible("Raphaelle Bailhache");
291 metaData.SetComment("TRD calib test");
293 // Sum the contributions of the LDCs
294 TList * listpad = GetFileSources(kDAQ,"PADSTATUS");
296 Log("No list found for the PEDESTRAL Run");
300 // loop through all files from LDCs
302 while (listpad->At(index)!=NULL) {
303 TObjString* fileNameEntry = (TObjString*) listpad->At(index);
304 if (fileNameEntry != NULL)
306 TString fileName = GetFile(kDAQ, "PADSTATUS",
307 fileNameEntry->GetString().Data());
308 if(fileName.Length() ==0){
309 Log(Form("Error by retrieving the file %d for the pedestal",(Int_t)index));
314 TFile *f = TFile::Open(fileName);
315 AliTRDCalibPadStatus *calPed;
316 f->GetObject("calibpadstatus",calPed);
323 //calPed->AnalyseHisto();
325 // Add to the calPedSum
326 for (Int_t idet=0; idet<540; idet++) {
327 AliTRDCalROC *rocMean = calPed->GetCalRocMean(idet, kFALSE);
329 calPedSum.SetCalRocMean(rocMean,idet);
330 ldc = (Int_t) (idet / 30);
332 AliTRDCalROC *rocRMS = calPed->GetCalRocRMS(idet, kFALSE);
334 calPedSum.SetCalRocRMS(rocRMS,idet);
336 AliTRDCalROC *rocMeand = calPed->GetCalRocMeand(idet, kFALSE);
338 calPedSum.SetCalRocMeand(rocMeand,idet);
340 AliTRDCalROC *rocRMSd = calPed->GetCalRocRMSd(idet, kFALSE);
342 calPedSum.SetCalRocRMSd(rocRMSd,idet);
346 if((ldc==0) || (ldc==1) || (ldc==2) || (ldc==9) || (ldc==10) || (ldc==11)) ldc = 1;
347 if((ldc==3) || (ldc==4) || (ldc==5) || (ldc==12) || (ldc==13) || (ldc==14)) ldc = 2;
348 if((ldc==6) || (ldc==7) || (ldc==8) || (ldc==15) || (ldc==16) || (ldc==17)) ldc = 3;
350 // store as reference data
351 TString name("PadStatus");
353 if(!StoreReferenceData("DAQData",(const char *)name,(TObject *) calPed,&metaData)){
354 Log(Form("Error storing AliTRDCalibPadStatus object %d as reference data",(Int_t)index));
363 Log(Form("%d elements found in the list for the pedestal",(Int_t)index));
374 AliTRDCalPadStatus *calPadStatus = calPedSum.CreateCalPadStatus();
376 //Make the AliTRDCalPad
377 AliTRDCalPad *calPad2 = calPedSum.CreateCalPad();
378 //Make the AliTRDCalDet correspondant
379 AliTRDCalDet *calDet = calPedSum.CreateCalDet();
382 // Take the noise and Pad status from the previous OCDB
385 AliTRDCalPad *calPadPrevious=0;
386 AliCDBEntry* entry = GetFromOCDB("Calib", "PadNoise");
387 if (entry) calPadPrevious = (AliTRDCalPad*)entry->GetObject();
388 if ( calPadPrevious==NULL ) {
389 Log("AliTRDPreprocsessor: No previous TRD pad noise entry available.\n");
390 calPadPrevious = new AliTRDCalPad("PadNoise", "PadNoise");
393 AliTRDCalPadStatus *calPadStatusPrevious=0;
394 entry = GetFromOCDB("Calib", "PadStatus");
395 if (entry) calPadStatusPrevious = (AliTRDCalPadStatus*)entry->GetObject();
396 if ( calPadStatusPrevious==NULL ) {
397 Log("AliTRDPreprocsessor: No previous TRD pad status entry available.\n");
398 calPadStatusPrevious = new AliTRDCalPadStatus("padstatus", "padstatus");
399 for (Int_t idet=0; idet<540; ++idet)
401 AliTRDCalSingleChamberStatus *calROC = calPadStatusPrevious->GetCalROC(idet);
402 for(Int_t k = 0; k < calROC->GetNchannels(); k++){
403 calROC->SetStatus(k,AliTRDCalPadStatus::kMasked);
409 // Loop over detectors for check
410 for (Int_t det=0; det<AliTRDgeometry::kNdet; ++det) {
413 AliTRDCalROC *calROCPreviousNoise = calPadPrevious->GetCalROC(det);
414 AliTRDCalROC *calROCNoise = calPad2->GetCalROC(det);
417 AliTRDCalSingleChamberStatus *calROCPreviousStatus = calPadStatusPrevious->GetCalROC(det);
418 AliTRDCalSingleChamberStatus *calROCStatus = calPadStatus->GetCalROC(det);
421 // loop over first half and second half chamber
422 for(Int_t half = 0; half < 2; half++){
424 Bool_t data = AreThereDataPedestal(calROCStatus,(Bool_t)half);
425 //printf("There are data for the detector %d the half %d: %d\n",det,half,data);
427 // look if data in the OCDB
428 Bool_t dataPrevious = AreThereDataPedestal(calROCPreviousStatus,(Bool_t)half);
429 // if no data at all, set to default value
431 SetDefaultStatus(*calROCStatus,(Bool_t)half);
432 SetDefaultNoise(*calROCNoise,(Bool_t)half);
435 // if data, set to previous value
436 SetStatus(*calROCStatus,calROCPreviousStatus,(Bool_t)half);
437 SetNoise(*calROCNoise,calROCPreviousNoise,(Bool_t)half);
448 md3.SetObjectClassName("AliTRDCalPadStatus");
449 md3.SetResponsible("Raphaelle Bailhache");
450 md3.SetBeamPeriod(1);
451 md3.SetComment("TRD calib test");
452 if(!Store("Calib","PadStatus" ,(TObject *)calPadStatus, &md3, 0, kTRUE)){
453 Log("Error storing the pedestal");
459 md4.SetObjectClassName("AliTRDCalPad");
460 md4.SetResponsible("Raphaelle Bailhache");
461 md4.SetBeamPeriod(1);
462 md4.SetComment("TRD calib test");
463 if(!Store("Calib","PadNoise" ,(TObject *)calPad2, &md4, 0, kTRUE)){
464 Log("Error storing the pedestal");
470 md5.SetObjectClassName("AliTRDCalDet");
471 md5.SetResponsible("Raphaelle Bailhache");
472 md5.SetBeamPeriod(1);
473 md5.SetComment("TRD calib test");
474 if(!Store("Calib","DetNoise" ,(TObject *)calDet, &md5, 0, kTRUE)){
475 Log("Error storing the pedestal");
484 //__________________________________________________________________
485 Bool_t AliTRDPreprocessor::AreThereDataPedestal(AliTRDCalSingleChamberStatus *calROCStatus, Bool_t second){
488 // Data for this half chamber
491 Bool_t data = kFALSE;
492 Int_t nCols = calROCStatus->GetNcols();
494 Int_t nColE = (Int_t) nCols/2 - 2;
500 Int_t totalnumberofpads = 0;
501 Int_t totalnumberofdata = 0;
503 for(Int_t col = nCol0; col < nColE; col++){
504 for(Int_t row = 0; row < calROCStatus->GetNrows(); row++){
506 //printf("ismasked %d\n",(Int_t)calROCStatus->IsMasked(col,row));
507 if(!calROCStatus->GetStatus(col,row)) {
513 if(totalnumberofdata < (Int_t)(totalnumberofpads/2)) data = kFALSE;
518 //__________________________________________________________________
519 void AliTRDPreprocessor::SetDefaultStatus(AliTRDCalSingleChamberStatus &calROCStatus, Bool_t second){
522 // default status for this half chamber
525 Int_t nCols = calROCStatus.GetNcols();
527 Int_t nColE = (Int_t) nCols/2;
532 for(Int_t col = nCol0; col < nColE; col++){
533 for(Int_t row = 0; row < calROCStatus.GetNrows(); row++){
534 calROCStatus.SetStatus(col,row,0);
538 //__________________________________________________________________
539 void AliTRDPreprocessor::SetStatus(AliTRDCalSingleChamberStatus &calROCStatus, AliTRDCalSingleChamberStatus *calROCStatusPrevious,Bool_t second){
542 // previous status for this half chamber
545 Int_t nCols = calROCStatus.GetNcols();
547 Int_t nColE = (Int_t) nCols/2;
552 for(Int_t col = nCol0; col < nColE; col++){
553 for(Int_t row = 0; row < calROCStatus.GetNrows(); row++){
554 calROCStatus.SetStatus(col,row,calROCStatusPrevious->GetStatus(col,row));
558 //__________________________________________________________________
559 void AliTRDPreprocessor::SetDefaultNoise(AliTRDCalROC &calROCNoise, Bool_t second){
562 // default noise for this half chamber
565 Int_t nCols = calROCNoise.GetNcols();
567 Int_t nColE = (Int_t) nCols/2;
572 for(Int_t col = nCol0; col < nColE; col++){
573 for(Int_t row = 0; row < calROCNoise.GetNrows(); row++){
574 calROCNoise.SetValue(col,row,0.12);
578 //__________________________________________________________________
579 void AliTRDPreprocessor::SetNoise(AliTRDCalROC &calROCNoise, AliTRDCalROC *calROCNoisePrevious, Bool_t second){
582 // previous noise for this half chamber
585 Int_t nCols = calROCNoise.GetNcols();
587 Int_t nColE = (Int_t) nCols/2;
592 for(Int_t col = nCol0; col < nColE; col++){
593 for(Int_t row = 0; row < calROCNoise.GetNrows(); row++){
594 calROCNoise.SetValue(col,row,calROCNoisePrevious->GetValue(col,row));
598 //______________________________________________________________________________________________
599 Bool_t AliTRDPreprocessor::ExtractDriftVelocityDAQ()
602 // Drift velocity DA running on monitoring servers at the DAQ
605 Bool_t error = kFALSE;
607 // Objects for HLT and DAQ zusammen
608 AliTRDCalibraFit *calibra = AliTRDCalibraFit::Instance();
609 AliCDBMetaData metaData;
610 metaData.SetBeamPeriod(0);
611 metaData.SetResponsible("Raphaelle Bailhache");
612 metaData.SetComment("TRD calib test");
613 // Store the infos for the detector
615 md1.SetObjectClassName("AliTRDCalDet");
616 md1.SetResponsible("Raphaelle Bailhache");
617 md1.SetBeamPeriod(0);
618 md1.SetComment("TRD calib test");
619 // Store the infos for the pads
621 md2.SetObjectClassName("AliTRDCalPad");
622 md2.SetResponsible("Raphaelle Bailhache");
623 md2.SetBeamPeriod(0);
624 md2.SetComment("TRD calib test");
626 // Take the file from the DAQ file exchange server
627 TList *listdaq = GetFileSources(kDAQ,"VDRIFT");
629 Log("No list found for vdrift (DAQ)");
633 if(listdaq->GetSize() !=1){
634 Log(Form("Problem on the size of the list: %d (DAQ)",listdaq->GetSize()));
639 TObjString* fileNameEntry = (TObjString*) listdaq->At(0);
640 if(fileNameEntry != NULL){
641 TString fileName = GetFile(kDAQ, "VDRIFT",
642 fileNameEntry->GetString().Data());
643 if(fileName.Length() ==0){
644 Log("Error retrieving the file vdrift (DAQ)");
648 TFile *filedaq = TFile::Open(fileName);
649 TProfile2D *histodriftvelocity = (TProfile2D *) filedaq->Get("PH2d");
650 if (histodriftvelocity) {
652 // store as reference data
653 if(!StoreReferenceData("DAQData","VdriftT0",(TObject *) histodriftvelocity,&metaData)){
654 Log("Error storing 2D Profile for vdrift from the DAQ");
660 Log("Take the PH reference data. Now we will try to fit\n");
661 calibra->SetMinEntries(2000); // If there is less than 2000
662 calibra->AnalysePH(histodriftvelocity);
664 Int_t nbtg = 6*4*18*((Int_t) ((AliTRDCalibraMode *)calibra->GetCalibraMode())->GetDetChamb0(1))
665 + 6* 18*((Int_t) ((AliTRDCalibraMode *)calibra->GetCalibraMode())->GetDetChamb2(1));
666 Int_t nbfit = calibra->GetNumberFit();
667 Int_t nbE = calibra->GetNumberEnt();
669 // if enough statistics store the results
671 (nbfit >= 0.5*nbE)) {
672 // create the cal objects
673 calibra->PutMeanValueOtherVectorFit(1,kTRUE);
674 calibra->PutMeanValueOtherVectorFit2(1,kTRUE);
675 TObjArray object = calibra->GetVectorFit();
676 AliTRDCalDet *objdriftvelocitydet = calibra->CreateDetObjectVdrift(&object,kTRUE);
677 TObject *objdriftvelocitypad = calibra->CreatePadObjectVdrift();
678 object = calibra->GetVectorFit2();
679 AliTRDCalDet *objtime0det = calibra->CreateDetObjectT0(&object,kTRUE);
680 TObject *objtime0pad = calibra->CreatePadObjectT0();
681 calibra->ResetVectorFit();
683 if(!Store("Calib","ChamberVdrift" ,(TObject *) objdriftvelocitydet,&md1,0,kTRUE)){
684 Log("Error storing the calibration object for the chamber vdrift (DAQ)");
687 if(!Store("Calib","ChamberT0" ,(TObject *) objtime0det ,&md1,0,kTRUE)){
688 Log("Error storing the calibration object for the chamber t0 (DAQ)");
691 if(!Store("Calib","LocalVdrift" ,(TObject *) objdriftvelocitypad,&md2,0,kTRUE)){
692 Log("Error storing the calibration object for the local drift velocity (DAQ)");
695 if(!Store("Calib","LocalT0" ,(TObject *) objtime0pad ,&md2,0,kTRUE)){
696 Log("Error storing the calibration object for the local time0 (DAQ)");
701 Log("Not enough statistics for the average pulse height (DAQ)");
711 //______________________________________________________________________________________________
712 Bool_t AliTRDPreprocessor::ExtractHLT()
715 // Gain, vdrift and PRF calibration running on HLT
716 // return kTRUE if NULL pointer to the list
719 Bool_t error = kFALSE;
721 // Objects for HLT and DAQ zusammen
722 AliTRDCalibraFit *calibra = AliTRDCalibraFit::Instance();
723 AliCDBMetaData metaData;
724 metaData.SetBeamPeriod(0);
725 metaData.SetResponsible("Raphaelle Bailhache");
726 metaData.SetComment("TRD calib test");
727 // Store the infos for the detector
729 md1.SetObjectClassName("AliTRDCalDet");
730 md1.SetResponsible("Raphaelle Bailhache");
731 md1.SetBeamPeriod(0);
732 md1.SetComment("TRD calib test");
733 // Store the infos for the pads
735 md2.SetObjectClassName("AliTRDCalPad");
736 md2.SetResponsible("Raphaelle Bailhache");
737 md2.SetBeamPeriod(0);
738 md2.SetComment("TRD calib test");
740 // Take the file from the HLT file exchange server
741 TList *listhlt = GetFileSources(kHLT,"GAINDRIFTPRF");
743 Log("No list found for the HLT");
747 if(listhlt->GetSize() != 1) {
748 Log(Form("Problem on the size of the list: %d (HLT)",listhlt->GetSize()));
753 TObjString* fileNameEntry = (TObjString*) listhlt->At(0);
754 if(fileNameEntry != NULL){
755 TString fileName = GetFile(kHLT, "GAINDRIFTPRF",
756 fileNameEntry->GetString().Data());
757 if(fileName.Length() ==0){
758 Log("Error retrieving the file (HLT)");
763 TFile *filehlt = TFile::Open(fileName);
766 TH2I *histogain = (TH2I *) filehlt->Get("CH2d");
767 histogain->SetDirectory(0);
769 // store the reference data
770 if(!StoreReferenceData("HLTData","Gain",(TObject *) histogain,&metaData)){
771 Log("Error storing 2D histos for gain");
775 Log("Take the CH reference data. Now we will try to fit\n");
776 calibra->SetMinEntries(800); // If there is less than 1000 entries in the histo: no fit
777 calibra->AnalyseCH(histogain);
778 Int_t nbtg = 6*4*18*((Int_t) ((AliTRDCalibraMode *)calibra->GetCalibraMode())->GetDetChamb0(0))
779 + 6* 18*((Int_t) ((AliTRDCalibraMode *)calibra->GetCalibraMode())->GetDetChamb2(0));
780 Int_t nbfit = calibra->GetNumberFit();
781 Int_t nbE = calibra->GetNumberEnt();
784 (nbfit >= 0.5*nbE)) {
785 // create the cal objects
786 calibra->PutMeanValueOtherVectorFit(1,kTRUE);
787 TObjArray object = calibra->GetVectorFit();
788 AliTRDCalDet *objgaindet = calibra->CreateDetObjectGain(&object);
789 TObject *objgainpad = calibra->CreatePadObjectGain();
791 if(!Store("Calib","ChamberGainFactor",(TObject *) objgaindet ,&md1,0,kTRUE)){
792 Log("Error storing the calibration object for the chamber gain");
795 if(!Store("Calib","LocalGainFactor" ,(TObject *) objgainpad ,&md2,0,kTRUE)){
796 Log("Error storing the calibration object for the local gain factor");
800 calibra->ResetVectorFit();
805 TProfile2D *histodriftvelocity = (TProfile2D *) filehlt->Get("PH2d");
806 histodriftvelocity->SetDirectory(0);
807 if (histodriftvelocity) {
808 // store the reference data
809 if(!StoreReferenceData("HLTData","VdriftT0",(TObject *) histodriftvelocity,&metaData)){
810 Log("Error storing 2D Profile for average pulse height (HLT)");
814 Log("Take the PH reference data. Now we will try to fit\n");
815 calibra->SetMinEntries(800*20); // If there is less than 20000
816 calibra->AnalysePH(histodriftvelocity);
817 Int_t nbtg = 6*4*18*((Int_t) ((AliTRDCalibraMode *)calibra->GetCalibraMode())->GetDetChamb0(1))
818 + 6* 18*((Int_t) ((AliTRDCalibraMode *)calibra->GetCalibraMode())->GetDetChamb2(1));
819 Int_t nbfit = calibra->GetNumberFit();
820 Int_t nbE = calibra->GetNumberEnt();
823 (nbfit >= 0.5*nbE)) {
824 // create the cal objects
825 calibra->PutMeanValueOtherVectorFit(1,kTRUE);
826 calibra->PutMeanValueOtherVectorFit2(1,kTRUE);
827 TObjArray object = calibra->GetVectorFit();
828 AliTRDCalDet *objdriftvelocitydet = calibra->CreateDetObjectVdrift(&object,kTRUE);
829 TObject *objdriftvelocitypad = calibra->CreatePadObjectVdrift();
830 object = calibra->GetVectorFit2();
831 AliTRDCalDet *objtime0det = calibra->CreateDetObjectT0(&object,kTRUE);
832 TObject *objtime0pad = calibra->CreatePadObjectT0();
834 if(!Store("Calib","ChamberVdrift" ,(TObject *) objdriftvelocitydet,&md1,0,kTRUE)){
835 Log("Error storing the calibration object for the chamber vdrift (HLT)");
838 if(!Store("Calib","ChamberT0" ,(TObject *) objtime0det ,&md1,0,kTRUE)){
839 Log("Error storing the calibration object for the chamber t0 (HLT)");
842 if(!Store("Calib","LocalVdrift" ,(TObject *) objdriftvelocitypad,&md2,0,kTRUE)){
843 Log("Error storing the calibration object for the local drift velocity (HLT)");
846 if(!Store("Calib","LocalT0" ,(TObject *) objtime0pad ,&md2,0,kTRUE)){
847 Log("Error storing the calibration object for the local time0 (HLT)");
852 calibra->ResetVectorFit();
856 TProfile2D *histoprf = (TProfile2D *) filehlt->Get("PRF2d");
857 histoprf->SetDirectory(0);
859 // store reference data
860 if(!StoreReferenceData("HLTData","PRF",(TObject *) histoprf,&metaData)){
861 Log("Error storing the 2D Profile for Pad Response Function");
865 Log("Take the PRF reference data. Now we will try to fit\n");
866 calibra->SetMinEntries(600); // If there is less than 20000
867 calibra->AnalysePRFMarianFit(histoprf);
868 Int_t nbtg = 6*4*18*((Int_t) ((AliTRDCalibraMode *)calibra->GetCalibraMode())->GetDetChamb0(2))
869 + 6* 18*((Int_t) ((AliTRDCalibraMode *)calibra->GetCalibraMode())->GetDetChamb2(2));
870 Int_t nbfit = calibra->GetNumberFit();
871 Int_t nbE = calibra->GetNumberEnt();
874 (nbfit >= 0.95*nbE)) {
875 // create cal pad objects
876 TObjArray object = calibra->GetVectorFit();
877 TObject *objPRFpad = calibra->CreatePadObjectPRF(&object);
879 if(!Store("Calib","PRFWidth" ,(TObject *) objPRFpad ,&md2,0,kTRUE)){
880 Log("Error storing the calibration object for the Pad Response Function");
884 calibra->ResetVectorFit();
893 //_____________________________________________________________________________
894 UInt_t AliTRDPreprocessor::ProcessDCSConfigData()
897 // process the configuration of FEE, PTR and GTU
898 // reteive XML filei(s) from the DCS FXS
899 // parse it/them and store TObjArrays in the CDB
901 // return 0 for success, otherwise:
902 // 5 : could not get the SOR file from the FXS
903 // 6 : could not get the EOR file from the FXS
905 // 8 : something wrong with the SOR file
906 // 9 : something wrong with the EOR file
907 // 10 : SOR XML is not well-formed
908 // 11 : EOR XML is not well-formed
909 // 12 : ERROR in XML SAX validation: something wrong with the content
911 // 14 : ERROR while creating calibration objects in the handler
912 // 15 : error while storing data in the CDB
915 Log("Processing the DCS config summary files.");
918 Log("Requesting the 2 summaryfiles from the FXS..");
919 const char *xmlFileS = GetFile(kDCS,"CONFIGSUMMARYSOR","");
920 const char *xmlFileE = GetFile(kDCS,"CONFIGSUMMARYEOR","");
921 // for the time being just request BOTH files from the FXS
922 // THEN it can be created online (otherwise the FXS would be messed up)
923 // the next step is to actually read BOTH files and store their informations
924 if (xmlFileS == NULL) {
925 Log(Form("ERROR: SOR File %s not found!",xmlFileS));
927 } else if (xmlFileE == NULL) {
928 Log(Form("ERROR: EOR File %s not found!",xmlFileE));
931 Log(Form("Both Files (%s and %s) found.",xmlFileS,xmlFileE));
935 std::ifstream fileTestS, fileTestE;
936 fileTestS.open(xmlFileS, std::ios_base::binary | std::ios_base::in);
937 fileTestE.open(xmlFileE, std::ios_base::binary | std::ios_base::in);
938 if (!fileTestS.good() || fileTestS.eof() || !fileTestS.is_open()) {
939 Log(Form("ERROR: File %s not valid!",xmlFileS));
942 if (!fileTestE.good() || fileTestE.eof() || !fileTestE.is_open()) {
943 Log(Form("ERROR: File %s not valid!",xmlFileE));
946 fileTestS.seekg(0, std::ios_base::end);
947 fileTestE.seekg(0, std::ios_base::end);
948 if (static_cast<int>(fileTestS.tellg()) < 2) {
949 Log(Form("ERROR: File %s is empty!",xmlFileS));
952 if (static_cast<int>(fileTestE.tellg()) < 2) {
953 Log(Form("ERROR: File %s is empty!",xmlFileE));
956 Log("Files are tested valid.");
958 // make a robust XML validation
959 TSAXParser testParser;
960 if (testParser.ParseFile(xmlFileS) < 0 ) {
961 Log("ERROR: XML content (SOR) is not well-formed.");
963 } else if (testParser.ParseFile(xmlFileE) < 0 ) {
964 Log("ERROR: XML content (EOR) is not well-formed.");
967 Log("XML contents are well-formed.");
969 // create parser and parse
970 TSAXParser saxParserS, saxParserE;
971 AliTRDSaxHandler saxHandlerS, saxHandlerE;
972 saxParserS.ConnectToHandler("AliTRDSaxHandler", &saxHandlerS);
973 saxParserS.ParseFile(xmlFileS);
974 saxParserE.ConnectToHandler("AliTRDSaxHandler", &saxHandlerE);
975 saxParserE.ParseFile(xmlFileE);
977 // report errors if present
978 if ((saxParserS.GetParseCode() == 0) && (saxParserE.GetParseCode() == 0)) {
979 Log("XML file validation OK.");
981 Log(Form("ERROR in XML file validation. Parsecodes: SOR: %s, EOR: %s", saxParserS.GetParseCode(), saxParserE.GetParseCode()));
984 if ((saxHandlerS.GetHandlerStatus() == 0) && (saxHandlerE.GetHandlerStatus() == 0)) {
985 Log("SAX handler reports no errors.");
987 Log(Form("ERROR while creating calibration objects. Error codes: SOR: %s, EOR: %s", saxHandlerS.GetHandlerStatus(), saxHandlerE.GetHandlerStatus()));
991 // get the calibration object storing the data from the handler
992 AliTRDCalDCS* fCalDCSObjSOR = saxHandlerS.GetCalDCSObj();
993 AliTRDCalDCS* fCalDCSObjEOR = saxHandlerE.GetCalDCSObj();
994 fCalDCSObjSOR->EvaluateGlobalParameters();
995 fCalDCSObjEOR->EvaluateGlobalParameters();
997 // put both objects in one TObjArray to store them
998 TObjArray* fCalObjArray = new TObjArray(2);
999 fCalObjArray->SetOwner();
1000 fCalObjArray->AddAt(fCalDCSObjSOR,0);
1001 fCalObjArray->AddAt(fCalDCSObjEOR,1);
1003 // store the DCS calib data in the CDB
1004 AliCDBMetaData metaData1;
1005 metaData1.SetBeamPeriod(0);
1006 metaData1.SetResponsible("Frederick Kramer");
1007 metaData1.SetComment("DCS configuration data in two AliTRDCalDCS objects in one TObjArray (0:SOR, 1:EOR).");
1008 if (!Store("Calib", "DCS", fCalObjArray, &metaData1, 0, kTRUE)) {
1009 Log("problems while storing DCS config data object");
1012 Log("DCS config data object stored.");
1015 //delete fCalObjArray;
1017 Log("Processing of the DCS config summary file DONE.");