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 ////////////////////////////////////////////////////////////////////////////
38 #include <TProfile2D.h>
39 #include <TObjString.h>
42 #include <TSAXParser.h>
44 #include "AliCDBMetaData.h"
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"
60 ClassImp(AliTRDPreprocessor)
62 //______________________________________________________________________________________________
63 AliTRDPreprocessor::AliTRDPreprocessor(AliShuttleInterface *shuttle)
64 :AliPreprocessor("TRD", shuttle)
71 AddRunType("PHYSICS");
72 AddRunType("STANDALONE");
73 AddRunType("PEDESTAL");
78 //______________________________________________________________________________________________
79 AliTRDPreprocessor::~AliTRDPreprocessor()
87 //______________________________________________________________________________________________
88 void AliTRDPreprocessor::Initialize(Int_t run, UInt_t startTime, UInt_t endTime)
91 // Initialization routine for the TRD preprocessor
94 AliPreprocessor::Initialize(run,startTime,endTime);
98 //______________________________________________________________________________________________
99 UInt_t AliTRDPreprocessor::Process(TMap* dcsAliasMap)
102 // Process DCS and calibration part for HLT
105 TString runType = GetRunType();
106 Log(Form("runtype %s\n",runType.Data()));
108 // always process the configuration data
109 if(ProcessDCSConfigData()) return 1;
111 if (runType=="PEDESTAL"){
112 if(ExtractPedestals()) return 1;
116 if ((runType=="PHYSICS") || (runType=="STANDALONE") || (runType=="DAQ")){
118 if(ProcessDCS(dcsAliasMap)) return 1;
119 if(runType=="PHYSICS"){
121 //TString runPar = GetRunParameter("HLTStatus");
124 if(ExtractHLT()) return 1; // for testing!
128 if(ExtractDriftVelocityDAQ()) return 1; // for testing!
136 //______________________________________________________________________________
137 Bool_t AliTRDPreprocessor::ProcessDCS()
140 // Default process DCS method
143 TString runType = GetRunType();
144 if ((runType == "PHYSICS") || (runType == "STANDALONE")) {
151 //______________________________________________________________________________
152 Bool_t AliTRDPreprocessor::ProcessDCS(TMap *dcsAliasMap)
155 // Process DCS method
158 Bool_t error = kFALSE;
160 AliCDBMetaData metaData;
161 metaData.SetBeamPeriod(0);
162 metaData.SetResponsible("Wilfried Monange/Raphaelle Bailhache");
163 metaData.SetComment("TRD calib test");
165 Log("****** DCS ******\n");
167 TObjArray * list=AliTRDSensorArray::GetList ();
170 Log ("Error during AliTRDSensorArray::GetList");
171 Log ("DCS will not be processing");
175 Int_t nEntries = list->GetEntries ();
176 Log (Form ("%d alias loaded", nEntries));
178 Bool_t * results=new Bool_t [nEntries];
179 Int_t * nGraph=new Int_t [nEntries];
181 for (Int_t iAlias = 0; iAlias < nEntries; iAlias++) {
183 AliTRDSensorArray * oneTRDDCS = (AliTRDSensorArray *)list->At (iAlias);
185 oneTRDDCS->SetStartTime (TTimeStamp (fStartTime));
186 oneTRDDCS->SetEndTime (TTimeStamp (fEndTime));
188 Log(Form("Processing DCS : \"%s\"", oneTRDDCS->GetStoreName ().Data ()));
192 map=oneTRDDCS->ExtractDCS (dcsAliasMap);
194 nGraph [iAlias] = map->GetEntries ();
196 if (nGraph [iAlias] == 0) {
197 Log("No TGraph for this dcsDatapointAlias : not stored");
198 results [iAlias] = kFALSE;
203 oneTRDDCS->SetGraph(map);
204 results[iAlias]=Store("Calib", oneTRDDCS->GetStoreName().Data(), oneTRDDCS, &metaData, 0, kTRUE);
207 //results [iAlias] = StoreReferenceData("Calib", oneTRDDCS->GetStoreName ().Data (), oneTRDDCS, &metaData);
209 if (!results[iAlias]) {
210 AliError("Problem during StoreRef DCS");
214 //BEGIN TEST (should not be removed ...)
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);
225 if(iAlias==1 || iAlias==19) continue;
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);
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);
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",
257 Log ("*********** End of DCS **********");
266 //______________________________________________________________________________________________
267 Bool_t AliTRDPreprocessor::ExtractPedestals()
270 // Pedestal running on LDCs at the DAQ
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
281 Bool_t error = kFALSE;
283 // Init a AliTRDCalibPadStatus
284 AliTRDCalibPadStatus calPedSum = AliTRDCalibPadStatus();
286 AliCDBMetaData metaData;
287 metaData.SetBeamPeriod(0);
288 metaData.SetResponsible("Raphaelle Bailhache");
289 metaData.SetComment("TRD calib test");
291 // Sum the contributions of the LDCs
292 TList * listpad = GetFileSources(kDAQ,"PADSTATUS");
294 Log("No list found for the PEDESTRAL Run");
298 // loop through all files from LDCs
300 while (listpad->At(index)!=NULL) {
301 TObjString* fileNameEntry = (TObjString*) listpad->At(index);
302 if (fileNameEntry != NULL)
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));
312 TFile *f = TFile::Open(fileName);
313 AliTRDCalibPadStatus *calPed;
314 f->GetObject("calibpadstatus",calPed);
321 //calPed->AnalyseHisto();
323 // Add to the calPedSum
324 for (Int_t idet=0; idet<540; idet++) {
325 AliTRDCalROC *rocMean = calPed->GetCalRocMean(idet, kFALSE);
327 calPedSum.SetCalRocMean(rocMean,idet);
328 ldc = (Int_t) (idet / 30);
330 AliTRDCalROC *rocRMS = calPed->GetCalRocRMS(idet, kFALSE);
332 calPedSum.SetCalRocRMS(rocRMS,idet);
334 AliTRDCalROC *rocMeand = calPed->GetCalRocMeand(idet, kFALSE);
336 calPedSum.SetCalRocMeand(rocMeand,idet);
338 AliTRDCalROC *rocRMSd = calPed->GetCalRocRMSd(idet, kFALSE);
340 calPedSum.SetCalRocRMSd(rocRMSd,idet);
344 if((ldc==0) || (ldc==1) || (ldc==2) || (ldc==9) || (ldc==10) || (ldc==11)) ldc = 1;
345 if((ldc==3) || (ldc==4) || (ldc==5) || (ldc==12) || (ldc==13) || (ldc==14)) ldc = 2;
346 if((ldc==6) || (ldc==7) || (ldc==8) || (ldc==15) || (ldc==16) || (ldc==17)) ldc = 3;
348 // store as reference data
349 TString name("PadStatus");
351 if(!StoreReferenceData("DAQData",(const char *)name,(TObject *) calPed,&metaData)){
352 Log(Form("Error storing AliTRDCalibPadStatus object %d as reference data",(Int_t)index));
361 Log(Form("%d elements found in the list for the pedestal",(Int_t)index));
372 AliTRDCalPadStatus *calPadStatus = calPedSum.CreateCalPadStatus();
374 //Make the AliTRDCalPad
375 AliTRDCalPad *calPad2 = calPedSum.CreateCalPad();
376 //Make the AliTRDCalDet correspondant
377 AliTRDCalDet *calDet = calPedSum.CreateCalDet();
380 // Take the noise and Pad status from the previous OCDB
383 AliTRDCalPad *calPadPrevious=0;
384 AliCDBEntry* entry = GetFromOCDB("Calib", "PadNoise");
385 if (entry) calPadPrevious = (AliTRDCalPad*)entry->GetObject();
386 if ( calPadPrevious==NULL ) {
387 Log("AliTRDPreprocsessor: No previous TRD pad noise entry available.\n");
388 calPadPrevious = new AliTRDCalPad("PadNoise", "PadNoise");
391 AliTRDCalPadStatus *calPadStatusPrevious=0;
392 entry = GetFromOCDB("Calib", "PadStatus");
393 if (entry) calPadStatusPrevious = (AliTRDCalPadStatus*)entry->GetObject();
394 if ( calPadStatusPrevious==NULL ) {
395 Log("AliTRDPreprocsessor: No previous TRD pad status entry available.\n");
396 calPadStatusPrevious = new AliTRDCalPadStatus("padstatus", "padstatus");
397 for (Int_t idet=0; idet<540; ++idet)
399 AliTRDCalSingleChamberStatus *calROC = calPadStatusPrevious->GetCalROC(idet);
400 for(Int_t k = 0; k < calROC->GetNchannels(); k++){
401 calROC->SetStatus(k,AliTRDCalPadStatus::kMasked);
407 // Loop over detectors for check
408 for (Int_t det=0; det<AliTRDgeometry::kNdet; ++det) {
411 AliTRDCalROC *calROCPreviousNoise = calPadPrevious->GetCalROC(det);
412 AliTRDCalROC *calROCNoise = calPad2->GetCalROC(det);
415 AliTRDCalSingleChamberStatus *calROCPreviousStatus = calPadStatusPrevious->GetCalROC(det);
416 AliTRDCalSingleChamberStatus *calROCStatus = calPadStatus->GetCalROC(det);
419 // loop over first half and second half chamber
420 for(Int_t half = 0; half < 2; half++){
422 Bool_t data = AreThereDataPedestal(calROCStatus,(Bool_t)half);
423 //printf("There are data for the detector %d the half %d: %d\n",det,half,data);
425 // look if data in the OCDB
426 Bool_t dataPrevious = AreThereDataPedestal(calROCPreviousStatus,(Bool_t)half);
427 // if no data at all, set to default value
429 SetDefaultStatus(*calROCStatus,(Bool_t)half);
430 SetDefaultNoise(*calROCNoise,(Bool_t)half);
433 // if data, set to previous value
434 SetStatus(*calROCStatus,calROCPreviousStatus,(Bool_t)half);
435 SetNoise(*calROCNoise,calROCPreviousNoise,(Bool_t)half);
446 md3.SetObjectClassName("AliTRDCalPadStatus");
447 md3.SetResponsible("Raphaelle Bailhache");
448 md3.SetBeamPeriod(1);
449 md3.SetComment("TRD calib test");
450 if(!Store("Calib","PadStatus" ,(TObject *)calPadStatus, &md3, 0, kTRUE)){
451 Log("Error storing the pedestal");
457 md4.SetObjectClassName("AliTRDCalPad");
458 md4.SetResponsible("Raphaelle Bailhache");
459 md4.SetBeamPeriod(1);
460 md4.SetComment("TRD calib test");
461 if(!Store("Calib","PadNoise" ,(TObject *)calPad2, &md4, 0, kTRUE)){
462 Log("Error storing the pedestal");
468 md5.SetObjectClassName("AliTRDCalDet");
469 md5.SetResponsible("Raphaelle Bailhache");
470 md5.SetBeamPeriod(1);
471 md5.SetComment("TRD calib test");
472 if(!Store("Calib","DetNoise" ,(TObject *)calDet, &md5, 0, kTRUE)){
473 Log("Error storing the pedestal");
483 //__________________________________________________________________
484 Bool_t AliTRDPreprocessor::AreThereDataPedestal(AliTRDCalSingleChamberStatus * const calROCStatus
489 // Data for this half chamber
492 Bool_t data = kFALSE;
493 Int_t nCols = calROCStatus->GetNcols();
495 Int_t nColE = (Int_t) nCols/2 - 2;
501 Int_t totalnumberofpads = 0;
502 Int_t totalnumberofdata = 0;
504 for(Int_t col = nCol0; col < nColE; col++){
505 for(Int_t row = 0; row < calROCStatus->GetNrows(); row++){
507 //printf("ismasked %d\n",(Int_t)calROCStatus->IsMasked(col,row));
508 if(!calROCStatus->GetStatus(col,row)) {
514 if(totalnumberofdata < (Int_t)(totalnumberofpads/2)) data = kFALSE;
519 //__________________________________________________________________
520 void AliTRDPreprocessor::SetDefaultStatus(AliTRDCalSingleChamberStatus &calROCStatus, Bool_t second){
523 // default status for this half chamber
526 Int_t nCols = calROCStatus.GetNcols();
528 Int_t nColE = (Int_t) nCols/2;
533 for(Int_t col = nCol0; col < nColE; col++){
534 for(Int_t row = 0; row < calROCStatus.GetNrows(); row++){
535 calROCStatus.SetStatus(col,row,0);
539 //__________________________________________________________________
540 void AliTRDPreprocessor::SetStatus(AliTRDCalSingleChamberStatus &calROCStatus, AliTRDCalSingleChamberStatus *calROCStatusPrevious,Bool_t second){
543 // previous status for this half chamber
546 Int_t nCols = calROCStatus.GetNcols();
548 Int_t nColE = (Int_t) nCols/2;
553 for(Int_t col = nCol0; col < nColE; col++){
554 for(Int_t row = 0; row < calROCStatus.GetNrows(); row++){
555 calROCStatus.SetStatus(col,row,calROCStatusPrevious->GetStatus(col,row));
559 //__________________________________________________________________
560 void AliTRDPreprocessor::SetDefaultNoise(AliTRDCalROC &calROCNoise, Bool_t second){
563 // default noise for this half chamber
566 Int_t nCols = calROCNoise.GetNcols();
568 Int_t nColE = (Int_t) nCols/2;
573 for(Int_t col = nCol0; col < nColE; col++){
574 for(Int_t row = 0; row < calROCNoise.GetNrows(); row++){
575 calROCNoise.SetValue(col,row,0.12);
579 //__________________________________________________________________
580 void AliTRDPreprocessor::SetNoise(AliTRDCalROC &calROCNoise, AliTRDCalROC *calROCNoisePrevious, Bool_t second){
583 // previous noise for this half chamber
586 Int_t nCols = calROCNoise.GetNcols();
588 Int_t nColE = (Int_t) nCols/2;
593 for(Int_t col = nCol0; col < nColE; col++){
594 for(Int_t row = 0; row < calROCNoise.GetNrows(); row++){
595 calROCNoise.SetValue(col,row,calROCNoisePrevious->GetValue(col,row));
599 //______________________________________________________________________________________________
600 Bool_t AliTRDPreprocessor::ExtractDriftVelocityDAQ()
603 // Drift velocity DA running on monitoring servers at the DAQ
606 Bool_t error = kFALSE;
608 // Objects for HLT and DAQ zusammen
609 AliTRDCalibraFit *calibra = AliTRDCalibraFit::Instance();
610 AliCDBMetaData metaData;
611 metaData.SetBeamPeriod(0);
612 metaData.SetResponsible("Raphaelle Bailhache");
613 metaData.SetComment("TRD calib test");
614 // Store the infos for the detector
616 md1.SetObjectClassName("AliTRDCalDet");
617 md1.SetResponsible("Raphaelle Bailhache");
618 md1.SetBeamPeriod(0);
619 md1.SetComment("TRD calib test");
620 // Store the infos for the pads
622 md2.SetObjectClassName("AliTRDCalPad");
623 md2.SetResponsible("Raphaelle Bailhache");
624 md2.SetBeamPeriod(0);
625 md2.SetComment("TRD calib test");
627 // Take the file from the DAQ file exchange server
628 TList *listdaq = GetFileSources(kDAQ,"VDRIFT");
630 Log("No list found for vdrift (DAQ)");
634 if(listdaq->GetSize() !=1){
635 Log(Form("Problem on the size of the list: %d (DAQ)",listdaq->GetSize()));
640 TObjString* fileNameEntry = (TObjString*) listdaq->At(0);
641 if(fileNameEntry != NULL){
642 TString fileName = GetFile(kDAQ, "VDRIFT",
643 fileNameEntry->GetString().Data());
644 if(fileName.Length() ==0){
645 Log("Error retrieving the file vdrift (DAQ)");
649 TFile *filedaq = TFile::Open(fileName);
650 TProfile2D *histodriftvelocity = (TProfile2D *) filedaq->Get("PH2d");
651 if (histodriftvelocity) {
653 // store as reference data
654 if(!StoreReferenceData("DAQData","VdriftT0",(TObject *) histodriftvelocity,&metaData)){
655 Log("Error storing 2D Profile for vdrift from the DAQ");
661 Log("Take the PH reference data. Now we will try to fit\n");
662 calibra->SetMinEntries(2000); // If there is less than 2000
663 calibra->AnalysePH(histodriftvelocity);
665 Int_t nbtg = 6*4*18*((Int_t) ((AliTRDCalibraMode *)calibra->GetCalibraMode())->GetDetChamb0(1))
666 + 6* 18*((Int_t) ((AliTRDCalibraMode *)calibra->GetCalibraMode())->GetDetChamb2(1));
667 Int_t nbfit = calibra->GetNumberFit();
668 Int_t nbE = calibra->GetNumberEnt();
670 // if enough statistics store the results
672 (nbfit >= 0.5*nbE)) {
673 // create the cal objects
674 calibra->PutMeanValueOtherVectorFit(1,kTRUE);
675 calibra->PutMeanValueOtherVectorFit2(1,kTRUE);
676 TObjArray object = calibra->GetVectorFit();
677 AliTRDCalDet *objdriftvelocitydet = calibra->CreateDetObjectVdrift(&object,kTRUE);
678 TObject *objdriftvelocitypad = calibra->CreatePadObjectVdrift();
679 object = calibra->GetVectorFit2();
680 AliTRDCalDet *objtime0det = calibra->CreateDetObjectT0(&object,kTRUE);
681 TObject *objtime0pad = calibra->CreatePadObjectT0();
682 calibra->ResetVectorFit();
684 if(!Store("Calib","ChamberVdrift" ,(TObject *) objdriftvelocitydet,&md1,0,kTRUE)){
685 Log("Error storing the calibration object for the chamber vdrift (DAQ)");
688 if(!Store("Calib","ChamberT0" ,(TObject *) objtime0det ,&md1,0,kTRUE)){
689 Log("Error storing the calibration object for the chamber t0 (DAQ)");
692 if(!Store("Calib","LocalVdrift" ,(TObject *) objdriftvelocitypad,&md2,0,kTRUE)){
693 Log("Error storing the calibration object for the local drift velocity (DAQ)");
696 if(!Store("Calib","LocalT0" ,(TObject *) objtime0pad ,&md2,0,kTRUE)){
697 Log("Error storing the calibration object for the local time0 (DAQ)");
702 Log("Not enough statistics for the average pulse height (DAQ)");
712 //______________________________________________________________________________________________
713 Bool_t AliTRDPreprocessor::ExtractHLT()
716 // Gain, vdrift and PRF calibration running on HLT
717 // return kTRUE if NULL pointer to the list
720 Bool_t error = kFALSE;
722 // Objects for HLT and DAQ zusammen
723 AliTRDCalibraFit *calibra = AliTRDCalibraFit::Instance();
724 AliCDBMetaData metaData;
725 metaData.SetBeamPeriod(0);
726 metaData.SetResponsible("Raphaelle Bailhache");
727 metaData.SetComment("TRD calib test");
728 // Store the infos for the detector
730 md1.SetObjectClassName("AliTRDCalDet");
731 md1.SetResponsible("Raphaelle Bailhache");
732 md1.SetBeamPeriod(0);
733 md1.SetComment("TRD calib test");
734 // Store the infos for the pads
736 md2.SetObjectClassName("AliTRDCalPad");
737 md2.SetResponsible("Raphaelle Bailhache");
738 md2.SetBeamPeriod(0);
739 md2.SetComment("TRD calib test");
741 // Take the file from the HLT file exchange server
742 TList *listhlt = GetFileSources(kHLT,"GAINDRIFTPRF");
744 Log("No list found for the HLT");
748 if(listhlt->GetSize() != 1) {
749 Log(Form("Problem on the size of the list: %d (HLT)",listhlt->GetSize()));
754 TObjString* fileNameEntry = (TObjString*) listhlt->At(0);
755 if(fileNameEntry != NULL){
756 TString fileName = GetFile(kHLT, "GAINDRIFTPRF",
757 fileNameEntry->GetString().Data());
758 if(fileName.Length() ==0){
759 Log("Error retrieving the file (HLT)");
764 TFile *filehlt = TFile::Open(fileName);
767 TH2I *histogain = (TH2I *) filehlt->Get("CH2d");
768 histogain->SetDirectory(0);
770 // store the reference data
771 if(!StoreReferenceData("HLTData","Gain",(TObject *) histogain,&metaData)){
772 Log("Error storing 2D histos for gain");
776 Log("Take the CH reference data. Now we will try to fit\n");
777 calibra->SetMinEntries(800); // If there is less than 1000 entries in the histo: no fit
778 calibra->AnalyseCH(histogain);
779 Int_t nbtg = 6*4*18*((Int_t) ((AliTRDCalibraMode *)calibra->GetCalibraMode())->GetDetChamb0(0))
780 + 6* 18*((Int_t) ((AliTRDCalibraMode *)calibra->GetCalibraMode())->GetDetChamb2(0));
781 Int_t nbfit = calibra->GetNumberFit();
782 Int_t nbE = calibra->GetNumberEnt();
785 (nbfit >= 0.5*nbE)) {
786 // create the cal objects
787 calibra->PutMeanValueOtherVectorFit(1,kTRUE);
788 TObjArray object = calibra->GetVectorFit();
789 AliTRDCalDet *objgaindet = calibra->CreateDetObjectGain(&object);
790 TObject *objgainpad = calibra->CreatePadObjectGain();
792 if(!Store("Calib","ChamberGainFactor",(TObject *) objgaindet ,&md1,0,kTRUE)){
793 Log("Error storing the calibration object for the chamber gain");
796 if(!Store("Calib","LocalGainFactor" ,(TObject *) objgainpad ,&md2,0,kTRUE)){
797 Log("Error storing the calibration object for the local gain factor");
801 calibra->ResetVectorFit();
806 TProfile2D *histodriftvelocity = (TProfile2D *) filehlt->Get("PH2d");
807 histodriftvelocity->SetDirectory(0);
808 if (histodriftvelocity) {
809 // store the reference data
810 if(!StoreReferenceData("HLTData","VdriftT0",(TObject *) histodriftvelocity,&metaData)){
811 Log("Error storing 2D Profile for average pulse height (HLT)");
815 Log("Take the PH reference data. Now we will try to fit\n");
816 calibra->SetMinEntries(800*20); // If there is less than 20000
817 calibra->AnalysePH(histodriftvelocity);
818 Int_t nbtg = 6*4*18*((Int_t) ((AliTRDCalibraMode *)calibra->GetCalibraMode())->GetDetChamb0(1))
819 + 6* 18*((Int_t) ((AliTRDCalibraMode *)calibra->GetCalibraMode())->GetDetChamb2(1));
820 Int_t nbfit = calibra->GetNumberFit();
821 Int_t nbE = calibra->GetNumberEnt();
824 (nbfit >= 0.5*nbE)) {
825 // create the cal objects
826 calibra->PutMeanValueOtherVectorFit(1,kTRUE);
827 calibra->PutMeanValueOtherVectorFit2(1,kTRUE);
828 TObjArray object = calibra->GetVectorFit();
829 AliTRDCalDet *objdriftvelocitydet = calibra->CreateDetObjectVdrift(&object,kTRUE);
830 TObject *objdriftvelocitypad = calibra->CreatePadObjectVdrift();
831 object = calibra->GetVectorFit2();
832 AliTRDCalDet *objtime0det = calibra->CreateDetObjectT0(&object,kTRUE);
833 TObject *objtime0pad = calibra->CreatePadObjectT0();
835 if(!Store("Calib","ChamberVdrift" ,(TObject *) objdriftvelocitydet,&md1,0,kTRUE)){
836 Log("Error storing the calibration object for the chamber vdrift (HLT)");
839 if(!Store("Calib","ChamberT0" ,(TObject *) objtime0det ,&md1,0,kTRUE)){
840 Log("Error storing the calibration object for the chamber t0 (HLT)");
843 if(!Store("Calib","LocalVdrift" ,(TObject *) objdriftvelocitypad,&md2,0,kTRUE)){
844 Log("Error storing the calibration object for the local drift velocity (HLT)");
847 if(!Store("Calib","LocalT0" ,(TObject *) objtime0pad ,&md2,0,kTRUE)){
848 Log("Error storing the calibration object for the local time0 (HLT)");
853 calibra->ResetVectorFit();
857 TProfile2D *histoprf = (TProfile2D *) filehlt->Get("PRF2d");
858 histoprf->SetDirectory(0);
860 // store reference data
861 if(!StoreReferenceData("HLTData","PRF",(TObject *) histoprf,&metaData)){
862 Log("Error storing the 2D Profile for Pad Response Function");
866 Log("Take the PRF reference data. Now we will try to fit\n");
867 calibra->SetMinEntries(600); // If there is less than 20000
868 calibra->AnalysePRFMarianFit(histoprf);
869 Int_t nbtg = 6*4*18*((Int_t) ((AliTRDCalibraMode *)calibra->GetCalibraMode())->GetDetChamb0(2))
870 + 6* 18*((Int_t) ((AliTRDCalibraMode *)calibra->GetCalibraMode())->GetDetChamb2(2));
871 Int_t nbfit = calibra->GetNumberFit();
872 Int_t nbE = calibra->GetNumberEnt();
875 (nbfit >= 0.95*nbE)) {
876 // create cal pad objects
877 TObjArray object = calibra->GetVectorFit();
878 TObject *objPRFpad = calibra->CreatePadObjectPRF(&object);
880 if(!Store("Calib","PRFWidth" ,(TObject *) objPRFpad ,&md2,0,kTRUE)){
881 Log("Error storing the calibration object for the Pad Response Function");
885 calibra->ResetVectorFit();
894 //_____________________________________________________________________________
895 UInt_t AliTRDPreprocessor::ProcessDCSConfigData()
898 // process the configuration of FEE, PTR and GTU
899 // reteive XML filei(s) from the DCS FXS
900 // parse it/them and store TObjArrays in the CDB
902 // return 0 for success, otherwise:
903 // 5 : could not get the SOR file from the FXS
904 // 6 : could not get the EOR file from the FXS
906 // 8 : something wrong with the SOR file
907 // 9 : something wrong with the EOR file
908 // 10 : SOR XML is not well-formed
909 // 11 : EOR XML is not well-formed
910 // 12 : ERROR in XML SAX validation: something wrong with the content
912 // 14 : ERROR while creating calibration objects in the handler
913 // 15 : error while storing data in the CDB
916 Log("Processing the DCS config summary files.");
919 Log("Requesting the 2 summaryfiles from the FXS..");
920 const char *xmlFileS = GetFile(kDCS,"CONFIGSUMMARYSOR","");
921 const char *xmlFileE = GetFile(kDCS,"CONFIGSUMMARYEOR","");
922 // for the time being just request BOTH files from the FXS
923 // THEN it can be created online (otherwise the FXS would be messed up)
924 // the next step is to actually read BOTH files and store their informations
925 if (xmlFileS == NULL) {
926 Log(Form("ERROR: SOR File %s not found!",xmlFileS));
928 } else if (xmlFileE == NULL) {
929 Log(Form("ERROR: EOR File %s not found!",xmlFileE));
932 Log(Form("Both Files (%s and %s) found.",xmlFileS,xmlFileE));
936 std::ifstream fileTestS, fileTestE;
937 fileTestS.open(xmlFileS, std::ios_base::binary | std::ios_base::in);
938 fileTestE.open(xmlFileE, std::ios_base::binary | std::ios_base::in);
939 if (!fileTestS.good() || fileTestS.eof() || !fileTestS.is_open()) {
940 Log(Form("ERROR: File %s not valid!",xmlFileS));
943 if (!fileTestE.good() || fileTestE.eof() || !fileTestE.is_open()) {
944 Log(Form("ERROR: File %s not valid!",xmlFileE));
947 fileTestS.seekg(0, std::ios_base::end);
948 fileTestE.seekg(0, std::ios_base::end);
949 if (static_cast<int>(fileTestS.tellg()) < 2) {
950 Log(Form("ERROR: File %s is empty!",xmlFileS));
953 if (static_cast<int>(fileTestE.tellg()) < 2) {
954 Log(Form("ERROR: File %s is empty!",xmlFileE));
957 Log("Files are tested valid.");
959 // make a robust XML validation
960 TSAXParser testParser;
961 if (testParser.ParseFile(xmlFileS) < 0 ) {
962 Log("ERROR: XML content (SOR) is not well-formed.");
964 } else if (testParser.ParseFile(xmlFileE) < 0 ) {
965 Log("ERROR: XML content (EOR) is not well-formed.");
968 Log("XML contents are well-formed.");
970 // create parser and parse
971 TSAXParser saxParserS, saxParserE;
972 AliTRDSaxHandler saxHandlerS, saxHandlerE;
973 saxParserS.ConnectToHandler("AliTRDSaxHandler", &saxHandlerS);
974 saxParserS.ParseFile(xmlFileS);
975 saxParserE.ConnectToHandler("AliTRDSaxHandler", &saxHandlerE);
976 saxParserE.ParseFile(xmlFileE);
978 // report errors if present
979 if ((saxParserS.GetParseCode() == 0) && (saxParserE.GetParseCode() == 0)) {
980 Log("XML file validation OK.");
982 Log(Form("ERROR in XML file validation. Parsecodes: SOR: %s, EOR: %s", saxParserS.GetParseCode(), saxParserE.GetParseCode()));
985 if ((saxHandlerS.GetHandlerStatus() == 0) && (saxHandlerE.GetHandlerStatus() == 0)) {
986 Log("SAX handler reports no errors.");
988 Log(Form("ERROR while creating calibration objects. Error codes: SOR: %s, EOR: %s", saxHandlerS.GetHandlerStatus(), saxHandlerE.GetHandlerStatus()));
992 // get the calibration object storing the data from the handler
993 AliTRDCalDCS* fCalDCSObjSOR = saxHandlerS.GetCalDCSObj();
994 AliTRDCalDCS* fCalDCSObjEOR = saxHandlerE.GetCalDCSObj();
995 fCalDCSObjSOR->EvaluateGlobalParameters();
996 fCalDCSObjEOR->EvaluateGlobalParameters();
998 // put both objects in one TObjArray to store them
999 TObjArray* fCalObjArray = new TObjArray(2);
1000 fCalObjArray->SetOwner();
1001 fCalObjArray->AddAt(fCalDCSObjSOR,0);
1002 fCalObjArray->AddAt(fCalDCSObjEOR,1);
1004 // store the DCS calib data in the CDB
1005 AliCDBMetaData metaData1;
1006 metaData1.SetBeamPeriod(0);
1007 metaData1.SetResponsible("Frederick Kramer");
1008 metaData1.SetComment("DCS configuration data in two AliTRDCalDCS objects in one TObjArray (0:SOR, 1:EOR).");
1009 if (!Store("Calib", "DCS", fCalObjArray, &metaData1, 0, kTRUE)) {
1010 Log("problems while storing DCS config data object");
1013 Log("DCS config data object stored.");
1016 //delete fCalObjArray;
1018 Log("Processing of the DCS config summary file DONE.");