]> git.uio.no Git - u/mrichter/AliRoot.git/blob - VZERO/AliVZEROPreprocessor.cxx
Fix for bug#59210 (Alex)
[u/mrichter/AliRoot.git] / VZERO / AliVZEROPreprocessor.cxx
1 #include "AliVZEROPreprocessor.h"
2 #include "AliVZEROCalibData.h"
3 #include "AliVZEROTriggerData.h"
4 #include "AliCDBMetaData.h"
5 #include "AliCDBEntry.h"
6 #include "AliDCSValue.h"
7 #include "AliLog.h"
8 #include "AliShuttleInterface.h"
9 #include "AliVZERODataFEE.h"
10 #include "AliVZERODataDCS.h"
11
12 #include <TFile.h>
13 #include <TTimeStamp.h>
14 #include <TObjString.h>
15 #include <TSystem.h>
16
17
18 class Tlist;
19
20 //
21 //  This class is  a simple preprocessor for VZERO detector.
22 //
23 //  It gets High Voltage values for a given run from DCS and Pedestal values from DAQ 
24 //  and writes them as Calibration MetaData into OCDB/VZERO/Calib/Data
25 //  It also retrieves FEE parameters from DCS archive   
26 //  and writes them as Trigger MetaData into OCDB/VZERO/Trigger/Data 
27 //  (to be used for trigger simulation)
28 //
29
30 ClassImp(AliVZEROPreprocessor)
31
32 //______________________________________________________________________________________________
33 AliVZEROPreprocessor::AliVZEROPreprocessor(AliShuttleInterface* shuttle) :
34         AliPreprocessor("V00", shuttle),
35         fData(0),
36         fFEEData(0)
37  
38 {
39   // constructor  
40   
41   AddRunType("STANDALONE_PULSER");
42   AddRunType("STANDALONE_BC");
43   AddRunType("PHYSICS");
44     
45 }
46
47 //______________________________________________________________________________________________
48 AliVZEROPreprocessor::~AliVZEROPreprocessor()
49 {
50   // destructor
51         delete fFEEData;
52         delete fData;
53         
54 }
55
56 //______________________________________________________________________________________________
57 void AliVZEROPreprocessor::Initialize(Int_t run, UInt_t startTime,
58         UInt_t endTime)
59 {
60   // Creates AliVZERODataDCS object
61
62    AliPreprocessor::Initialize(run, startTime, endTime);
63   
64    Log(Form("\n\tRun %d \n\tStartTime %s \n\tEndTime %s", run,
65                 TTimeStamp(startTime).AsString(),
66                 TTimeStamp(endTime).AsString()));
67
68    fRun       = run;
69    // fStartTime = startTime;
70    // fEndTime   = endTime;
71    fStartTime = GetStartTimeDCSQuery ();
72    fEndTime   = GetEndTimeDCSQuery ();
73
74         fData      = new AliVZERODataDCS(fRun, fStartTime, fEndTime);
75         fFEEData   = new AliVZERODataFEE(fRun, fStartTime, fEndTime);           
76    
77 }
78
79 //______________________________________________________________________________________________
80 UInt_t AliVZEROPreprocessor::Process(TMap* dcsAliasMap)
81 {
82   // Fills data retrieved from DCS and DAQ into a AliVZEROCalibData object and 
83   // stores it into CalibrationDB
84
85
86   // *** GET RUN TYPE ***
87   TString runType = GetRunType();
88
89
90   // *** REFERENCE DATA *** 
91   
92   TString fileName; 
93   AliVZEROCalibData *calibData = new AliVZEROCalibData();
94   
95   // *************** HV From DCS ******************
96   // Fills data into a AliVZERODataDCS object
97   if(!dcsAliasMap) return 1;
98
99         // The Processing of the DCS input data is forwarded to AliVZERODataDCS
100         fData->ProcessData(*dcsAliasMap);
101
102         // Writes VZERO PMs HV values into VZERO calibration object and Timing resolution parameters
103         calibData->FillDCSData(fData);
104            
105    // *************** From DAQ ******************
106    
107         TString sourcesId = "V00da_results";
108
109         TList* sourceList = GetFileSources(kDAQ, sourcesId.Data());
110         if (!sourceList)  {
111                 Log(Form("No sources found for id %s", sourcesId.Data()));                      
112                 return 1; }
113         Log(Form("The following sources produced files with the id %s",sourcesId.Data()));
114         sourceList->Print();    
115
116         TIter iter(sourceList);
117         TObjString *source = 0;
118                 
119         while((source=dynamic_cast<TObjString*> (iter.Next()))){
120                 fileName = GetFile(kDAQ, sourcesId.Data(), source->GetName());
121                 if (fileName.Length() > 0)
122                 Log(Form("Got the file %s, now we can extract some values.", fileName.Data()));
123                 FILE *file;
124                 if((file = fopen(fileName.Data(),"r")) == NULL){
125                                    Log(Form("Cannot open file %s",fileName.Data()));
126                                    return 1;}
127                 Float_t pedMean[128], pedSigma[128], adcMean[128], adcSigma[128] ;
128                 for(Int_t j=0; j<128; j++)fscanf(file,"%f %f %f %f",
129                                           &pedMean[j], &pedSigma[j], &adcMean[j], &adcSigma[j]);
130                 fclose(file);
131                 
132                 calibData->SetPedestal(pedMean);
133                 calibData->SetSigma(pedSigma);                  
134                 calibData->SetGain(adcMean); 
135                 calibData->SetADCsigma(adcSigma);
136                 }                               
137
138         delete source;      
139   
140   // Check that everything was properly transmitted
141
142 //   for(Int_t j=0; j<128; j++){printf("Pedestal[%d] -> %f \n",j,calibData->GetPedestal(j));}
143 //   for(Int_t j=0; j<128; j++){printf("pedSigma[%d] -> %f \n",j,calibData->GetSigma(j));}
144 //   for(Int_t j=0; j<128; j++){printf("Gain[%d] -> %f \n",j,calibData->GetGain(j));}
145 //   for(Int_t j=0; j<128; j++){printf("adcSigma[%d] -> %f \n",j,calibData->GetADCsigma(j));}
146 //   for(Int_t j=0; j<64; j++){printf("MeanHV[%d] -> %f \n",j,calibData->GetMeanHV(j));}
147 //   for(Int_t j=0; j<64; j++){printf("WidthHV[%d] -> %f \n",j,calibData->GetWidthHV(j));}
148   
149   // Now we store the VZERO Calibration Object into CalibrationDB
150
151   Bool_t resECal=kTRUE;
152   
153   Bool_t result = 0;
154 //  if(sourceList && sourceList->GetEntries()>0)
155 //  {
156   AliCDBMetaData metaData;
157   metaData.SetBeamPeriod(0);
158   metaData.SetResponsible("Brigitte Cheynis");
159   metaData.SetComment("This preprocessor fills an AliVZEROCalibData object");
160
161   resECal = Store("Calib", "Data", calibData, &metaData, 0, kTRUE);
162 //  }
163   if(resECal==kFALSE ) result = 1;
164   
165
166   delete calibData;
167   delete sourceList; 
168
169  // -----------------------------------------------------------------------
170  // Retrieves Front End Electronics Parameters from  DCS archive
171  // -----------------------------------------------------------------------
172         AliVZEROTriggerData *triggerData = new AliVZEROTriggerData();
173
174         // The processing of the DCS input data is forwarded to AliVZERODataFEE
175         fFEEData->ProcessData(*dcsAliasMap);
176
177         // Writes VZERO FEE parameters values into VZERO  Trigger parametrization object
178         triggerData->FillData(fFEEData);
179
180         // Stores the VZERO Trigger Object into TriggerDB
181         
182         resECal=kTRUE;
183         
184         result = 0;
185         metaData.SetBeamPeriod(0);
186         metaData.SetResponsible("Brigitte Cheynis");
187         metaData.SetComment("This preprocessor fills an AliVZEROTriggerData object");
188         
189         resECal = Store("Trigger", "Data", triggerData, &metaData, 0, kTRUE);
190         if(resECal==kFALSE ) result = 1;
191         
192         
193   return result;
194 }
195