]> git.uio.no Git - u/mrichter/AliRoot.git/blob - VZERO/AliVZEROPreprocessor.cxx
First version of Preprocessor
[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
55 //______________________________________________________________________________________________
56 UInt_t AliVZEROPreprocessor::Process(TMap* dcsAliasMap)
57 {
58   // Fills data retrieved from DCS and DAQ into a AliVZEROCalibData object and 
59   // stores it into CalibrationDB
60
61
62   // *** GET RUN TYPE ***
63   TString runType = GetRunType();
64
65
66   // *** REFERENCE DATA *** 
67   
68   TString fileName; 
69   AliVZEROCalibData *calibData = new AliVZEROCalibData();
70   
71   // *************** From DCS ******************
72   // Fills data into a AliVZERODataDCS object
73   if(!dcsAliasMap) return 1;
74
75         // The processing of the DCS input data is forwarded to AliVZERODataDCS
76
77         fData->ProcessData(*dcsAliasMap);
78         //fData->Draw("");              // Draw the HV values as a function of time
79         //dcsAliasMap->Print("");       // Print out the HV values
80
81         // Writing VZERO PMs HV values into calibration object
82         calibData->SetMeanHV(fData->GetMeanHV());
83         calibData->SetWidthHV(fData->GetWidthHV());
84   
85   
86    // *************** From DAQ ******************
87         TString SourcesId[3];
88         SourcesId[0] = "PEDESTALS";
89         SourcesId[1] = "GAINS";
90         SourcesId[2] = "SIGMAS";
91
92         for(int iSource=0;iSource<3;iSource++){
93                 TList* sourceList = GetFileSources(kDAQ, SourcesId[iSource].Data());
94                 if (!sourceList){
95                         AliError(Form("No sources found for id %s", SourcesId[iSource].Data()));                
96                 return 1;   
97                 }
98                 AliInfo(Form("The following sources produced files with the id %s",SourcesId[iSource].Data()));
99                 sourceList->Print();    
100
101                 TIter iter(sourceList);
102                 TObjString *source = 0;
103                 
104                 while((source=dynamic_cast<TObjString*> (iter.Next()))){
105                         fileName = GetFile(kDAQ, SourcesId[iSource].Data(), source->GetName());
106                         if (fileName.Length() > 0)
107                         AliInfo(Form("Got the file %s, now we can extract some values.", fileName.Data()));
108                         FILE *file;
109                         if((file = fopen(fileName.Data(),"r")) == NULL){
110                 AliError(Form("Cannot open file %s",fileName.Data()));
111                         return 1;
112                         }
113                         Float_t Values[128];
114                         for(Int_t j=0; j<128; j++)fscanf(file,"%f",&Values[j]);
115                         fclose(file);
116                 switch(iSource){
117                                 case 0:
118                                         calibData->SetPedestal(Values);
119                                         break;
120                                 case 1:
121                                         calibData->SetGain(Values);
122                                         break;
123                                 case 2:
124                                         calibData->SetSigma(Values);
125                                         break;
126                                 }
127                 }
128                 delete sourceList;
129
130         }
131       
132   
133   // Check that everything was properly transmitted
134
135 //   for(Int_t j=0; j<128; j++){printf("ADCPedestal[%d] -> %f \n",j,calibData->GetPedestal(j));}
136 //   for(Int_t j=0; j<128; j++){printf("ADCGain[%d] -> %f \n",j,calibData->GetGain(j));}
137 //   for(Int_t j=0; j<128; j++){printf("ADCSigma[%d] -> %f \n",j,calibData->GetSigma(j));}
138 //   for(Int_t j=0; j<64; j++){printf("MeanHV[%d] -> %f \n",j,calibData->GetMeanHV(j));}
139 //   for(Int_t j=0; j<64; j++){printf("WidthHV[%d] -> %f \n",j,calibData->GetWidthHV(j));}
140 //   
141   // Now we  store the VZERO Calibration Object into CalibrationDB
142   
143   AliCDBMetaData metaData;
144   metaData.SetBeamPeriod(0);
145   metaData.SetResponsible("Brigitte Cheynis");
146   metaData.SetComment("This preprocessor fills an AliVZEROCalibData object");
147
148   Bool_t result = Store("Calib", "Data", calibData, &metaData, 0, kTRUE);
149
150   delete calibData;
151
152   if (!result) return 1;   
153   return 0;
154 }
155