]> git.uio.no Git - u/mrichter/AliRoot.git/blob - VZERO/AliVZEROPreprocessor.cxx
ADC calibration information from DAQ merged into one file
[u/mrichter/AliRoot.git] / VZERO / AliVZEROPreprocessor.cxx
1 #include "AliVZEROPreprocessor.h"
2 #include "AliVZEROCalibData.h"
3 #include "AliCDBMetaData.h"
4 #include "AliCDBEntry.h"
5 #include "AliDCSValue.h"
6 #include "AliLog.h"
7 #include <TFile.h>
8 #include <TTimeStamp.h>
9 #include <TObjString.h>
10 #include <TSystem.h>
11 #include <TList.h>
12
13 //
14 // This class is  a simple preprocessor for V0.
15 //
16
17 ClassImp(AliVZEROPreprocessor)
18
19 //______________________________________________________________________________________________
20 AliVZEROPreprocessor::AliVZEROPreprocessor(AliShuttleInterface* shuttle) :
21   AliPreprocessor("V00", shuttle),
22   fData(0)
23  
24 {
25   // constructor
26 }
27
28 //______________________________________________________________________________________________
29 AliVZEROPreprocessor::~AliVZEROPreprocessor()
30 {
31   // destructor
32 }
33
34 //______________________________________________________________________________________________
35 void AliVZEROPreprocessor::Initialize(Int_t run, UInt_t startTime,
36         UInt_t endTime)
37 {
38   // Creates AliZDCDataDCS object
39
40   AliPreprocessor::Initialize(run, startTime, endTime);
41
42         Log(Form("\n\tRun %d \n\tStartTime %s \n\tEndTime %s", run,
43                 TTimeStamp(startTime).AsString(),
44                 TTimeStamp(endTime).AsString()));
45
46         fRun = run;
47         fStartTime = startTime;
48         fEndTime = endTime;
49
50         fData = new AliVZERODataDCS(fRun, fStartTime, fEndTime);
51 }
52
53 //______________________________________________________________________________________________
54 UInt_t AliVZEROPreprocessor::Process(TMap* dcsAliasMap)
55 {
56   // Fills data retrieved from DCS and DAQ into a AliVZEROCalibData object and 
57   // stores it into CalibrationDB
58
59
60   // *** GET RUN TYPE ***
61   TString runType = GetRunType();
62
63
64   // *** REFERENCE DATA *** 
65   
66   TString fileName; 
67   AliVZEROCalibData *calibData = new AliVZEROCalibData();
68   
69   // *************** From DCS ******************
70   // Fills data into a AliVZERODataDCS object
71   if(!dcsAliasMap) return 1;
72
73         // The processing of the DCS input data is forwarded to AliVZERODataDCS
74
75         fData->ProcessData(*dcsAliasMap);
76         //fData->Draw("");              // Draws the HV values as a function of time
77         //dcsAliasMap->Print("");       // Prints out the HV values
78
79         // Writes VZERO PMs HV values into VZERO calibration object
80         calibData->SetMeanHV(fData->GetMeanHV());
81         calibData->SetWidthHV(fData->GetWidthHV());
82     
83    // *************** From DAQ ******************
84    
85         TString SourcesId = "CALIB";
86
87         TList* sourceList = GetFileSources(kDAQ, SourcesId.Data());
88         if (!sourceList)  {
89                 AliError(Form("No sources found for id %s", SourcesId.Data()));                 
90                 return 1; }
91         AliInfo(Form("The following sources produced files with the id %s",SourcesId.Data()));
92         sourceList->Print();    
93
94         TIter iter(sourceList);
95         TObjString *source = 0;
96                 
97         while((source=dynamic_cast<TObjString*> (iter.Next()))){
98                 fileName = GetFile(kDAQ, SourcesId.Data(), source->GetName());
99                 if (fileName.Length() > 0)
100                 AliInfo(Form("Got the file %s, now we can extract some values.", fileName.Data()));
101                 FILE *file;
102                 if((file = fopen(fileName.Data(),"r")) == NULL){
103                                    AliError(Form("Cannot open file %s",fileName.Data()));
104                                    return 1;}
105                 Float_t Pedestals[128], Sigmas[128], Gains[128];
106                 for(Int_t j=0; j<128; j++)fscanf(file,"%f %f %f ",
107                                           &Pedestals[j], &Sigmas[j], &Gains[j]);
108                 fclose(file);
109                 
110                 calibData->SetPedestal(Pedestals);
111                 calibData->SetSigma(Sigmas);                    
112                 calibData->SetGain(Gains); }                            
113                 
114         delete sourceList; 
115         delete source;      
116   
117   // Check that everything was properly transmitted
118
119 //   for(Int_t j=0; j<128; j++){printf("ADCPedestal[%d] -> %f \n",j,calibData->GetPedestal(j));}
120 //   for(Int_t j=0; j<128; j++){printf("ADCGain[%d] -> %f \n",j,calibData->GetGain(j));}
121 //   for(Int_t j=0; j<128; j++){printf("ADCSigma[%d] -> %f \n",j,calibData->GetSigma(j));}
122 //   for(Int_t j=0; j<64; j++){printf("MeanHV[%d] -> %f \n",j,calibData->GetMeanHV(j));}
123 //   for(Int_t j=0; j<64; j++){printf("WidthHV[%d] -> %f \n",j,calibData->GetWidthHV(j));}
124   
125   // Now we  store the VZERO Calibration Object into CalibrationDB
126   
127   AliCDBMetaData metaData;
128   metaData.SetBeamPeriod(0);
129   metaData.SetResponsible("Brigitte Cheynis");
130   metaData.SetComment("This preprocessor fills an AliVZEROCalibData object");
131
132   Bool_t result = Store("Calib", "Data", calibData, &metaData, 0, kTRUE);
133
134   delete calibData;
135
136   if (!result) return 1;   
137   return 0;
138 }
139