]> git.uio.no Git - u/mrichter/AliRoot.git/blob - VZERO/AliVZEROPreprocessor.cxx
Macro to check the calib OCDB object.
[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 #include <TH1F.h>
17
18
19 class Tlist;
20
21 //
22 //  This class is  a simple preprocessor for VZERO detector.
23 //
24 //  It gets High Voltage values for a given run from DCS and Pedestal values from DAQ 
25 //  and writes them as Calibration MetaData into OCDB/VZERO/Calib/Data
26 //  It also retrieves FEE parameters from DCS archive   
27 //  and writes them as Trigger MetaData into OCDB/VZERO/Trigger/Data 
28 //  (to be used for trigger simulation)
29 //
30
31 ClassImp(AliVZEROPreprocessor)
32
33 //______________________________________________________________________________________________
34 AliVZEROPreprocessor::AliVZEROPreprocessor(AliShuttleInterface* shuttle) :
35         AliPreprocessor("V00", shuttle),
36         fData(0),
37         fFEEData(0)
38  
39 {
40   // constructor  
41   
42   AddRunType("STANDALONE_PULSER");
43   AddRunType("STANDALONE_BC");
44   AddRunType("PHYSICS");
45     
46 }
47
48 //______________________________________________________________________________________________
49 AliVZEROPreprocessor::~AliVZEROPreprocessor()
50 {
51   // destructor
52         delete fFEEData;
53         delete fData;
54         
55 }
56
57 //______________________________________________________________________________________________
58 void AliVZEROPreprocessor::Initialize(Int_t run, UInt_t startTime,
59         UInt_t endTime)
60 {
61   // Creates AliVZERODataDCS object
62
63    AliPreprocessor::Initialize(run, startTime, endTime);
64   
65    Log(Form("\n\tRun %d \n\tStartTime %s \n\tEndTime %s", run,
66                 TTimeStamp(startTime).AsString(),
67                 TTimeStamp(endTime).AsString()));
68
69    fRun       = run;
70    // fStartTime = startTime;
71    // fEndTime   = endTime;
72    fStartTime = GetStartTimeDCSQuery ();
73    fEndTime   = GetEndTimeDCSQuery ();
74    time_t daqStart = (time_t) (((TString)GetRunParameter("DAQ_time_start")).Atoi());
75    time_t daqEnd   = (time_t) (((TString)GetRunParameter("DAQ_time_end")).Atoi());
76    
77         fData      = new AliVZERODataDCS(fRun, fStartTime, fEndTime,(UInt_t)daqStart, (UInt_t)daqEnd);
78         fFEEData   = new AliVZERODataFEE(fRun, fStartTime, fEndTime);           
79    
80 }
81
82 //______________________________________________________________________________________________
83 UInt_t AliVZEROPreprocessor::Process(TMap* dcsAliasMap)
84 {
85   // Fills data retrieved from DCS and DAQ into a AliVZEROCalibData object and 
86   // stores it into CalibrationDB
87
88
89   // *** GET RUN TYPE ***
90   TString runType = GetRunType();
91
92
93   // *** REFERENCE DATA *** 
94   
95   TString fileName; 
96   AliVZEROCalibData *calibData = new AliVZEROCalibData();
97   
98   // *************** HV From DCS ******************
99   // Fills data into a AliVZERODataDCS object
100   if(!dcsAliasMap) return 1;
101
102         // The Processing of the DCS input data is forwarded to AliVZERODataDCS
103   if (!fData->ProcessData(*dcsAliasMap)) return 1;
104
105         // Writes VZERO PMs HV values into VZERO calibration object and Timing resolution parameters
106         calibData->FillDCSData(fData);
107            
108    // *************** From DAQ ******************
109    
110         TString sourcesId = "V00da_results";
111
112         TList* sourceList = GetFileSources(kDAQ, sourcesId.Data());
113         if (!sourceList)  {
114                 Log(Form("No sources found for id %s", sourcesId.Data()));                      
115                 return 1; }
116         Log(Form("The following sources produced files with the id %s",sourcesId.Data()));
117         sourceList->Print();    
118
119         TIter iter(sourceList);
120         TObjString *source;
121                 
122         while((source=dynamic_cast<TObjString*> (iter.Next()))){
123                 fileName = GetFile(kDAQ, sourcesId.Data(), source->GetName());
124                 if (fileName.Length() > 0)
125                 Log(Form("Got the file %s, now we can extract some values.", fileName.Data()));
126                 FILE *file;
127                 if((file = fopen(fileName.Data(),"r")) == NULL){
128                                    Log(Form("Cannot open file %s",fileName.Data()));
129                                    return 1;}
130                 Float_t pedMean[128], pedSigma[128], adcMean[128], adcSigma[128] ;
131                 for(Int_t j=0; j<128; j++)fscanf(file,"%f %f %f %f",
132                                           &pedMean[j], &pedSigma[j], &adcMean[j], &adcSigma[j]);
133                 fclose(file);
134                 
135                 calibData->SetPedestal(pedMean);
136                 calibData->SetSigma(pedSigma);                  
137                 calibData->SetADCsigma(adcSigma);
138                 }                               
139
140         delete source;      
141   
142   // Check that everything was properly transmitted
143
144 //   for(Int_t j=0; j<128; j++){printf("Pedestal[%d] -> %f \n",j,calibData->GetPedestal(j));}
145 //   for(Int_t j=0; j<128; j++){printf("pedSigma[%d] -> %f \n",j,calibData->GetSigma(j));}
146 //   for(Int_t j=0; j<128; j++){printf("Gain[%d] -> %f \n",j,calibData->GetGain(j));}
147 //   for(Int_t j=0; j<128; j++){printf("adcSigma[%d] -> %f \n",j,calibData->GetADCsigma(j));}
148 //   for(Int_t j=0; j<64; j++){printf("MeanHV[%d] -> %f \n",j,calibData->GetMeanHV(j));}
149 //   for(Int_t j=0; j<64; j++){printf("WidthHV[%d] -> %f \n",j,calibData->GetWidthHV(j));}
150   
151   // Now we store the VZERO Calibration Object into CalibrationDB
152
153   Bool_t resECal=kTRUE;
154   
155   Bool_t result = 0;
156 //  if(sourceList && sourceList->GetEntries()>0)
157 //  {
158   AliCDBMetaData metaData;
159   metaData.SetBeamPeriod(0);
160   metaData.SetResponsible("Brigitte Cheynis");
161   metaData.SetComment("This preprocessor fills an AliVZEROCalibData object");
162
163   resECal = Store("Calib", "Data", calibData, &metaData, 0, kTRUE);
164 //  }
165   if(resECal==kFALSE ) result = 1;
166   
167
168   delete calibData;
169   delete sourceList; 
170
171  // -----------------------------------------------------------------------
172  // Retrieves Front End Electronics Parameters from  DCS archive
173  // -----------------------------------------------------------------------
174         AliVZEROTriggerData *triggerData = new AliVZEROTriggerData();
175
176         // The processing of the DCS input data is forwarded to AliVZERODataFEE
177         fFEEData->ProcessData(*dcsAliasMap);
178
179         // Writes VZERO FEE parameters values into VZERO  Trigger parametrization object
180         triggerData->FillData(fFEEData);
181
182         // Stores the VZERO Trigger Object into TriggerDB
183         
184         resECal=kTRUE;
185         
186         metaData.SetBeamPeriod(0);
187         metaData.SetResponsible("Brigitte Cheynis");
188         metaData.SetComment("This preprocessor fills an AliVZEROTriggerData object");
189         
190         resECal = Store("Trigger", "Data", triggerData, &metaData, 0, kTRUE);
191         if(resECal==kFALSE ) result = 1;
192         
193
194    // *************** From DAQ DA - Equalization factors ******************
195   
196   TH1F *eqFactors = new TH1F("VZEROEqualizationFactors","VZERO Equalization Factors for Pb-Pb",64,-0.5,63.5);
197   sourcesId = "V00DAEqualFactors";
198
199   TList* sourceList2 = GetFileSources(kDAQ, sourcesId.Data());
200   if (!sourceList2)  {
201     Log(Form("No sources found for id %s", sourcesId.Data()));                  
202     return 1; }
203   Log(Form("The following sources produced files with the id %s",sourcesId.Data()));
204   sourceList2->Print();
205
206   TIter iter2(sourceList2);
207   TObjString *source2;
208                 
209   while((source2=dynamic_cast<TObjString*> (iter2.Next()))){
210     fileName = GetFile(kDAQ, sourcesId.Data(), source2->GetName());
211     if (fileName.Length() > 0)
212       Log(Form("Got the file %s, now we can extract some values.", fileName.Data()));
213     FILE *file2;
214     if((file2 = fopen(fileName.Data(),"r")) == NULL){
215       Log(Form("Cannot open file %s",fileName.Data()));
216       return 1;}
217
218     Double_t alpha[66];
219     alpha[0] = alpha[65] = 0;
220     Int_t tempCh;
221     Float_t tempAlpha;
222     for(Int_t j=0; j<64; ++j) {
223       fscanf(file2,"%d %f", &tempCh, &tempAlpha);
224       alpha[tempCh+1] = tempAlpha;
225     }
226     fclose(file2);
227
228     // Check that everything was properly transmitted
229     printf("Equalization factors (0->64): ");
230     for(Int_t j=0; j<64; ++j) printf("%.3f ",alpha[j+1]);
231     printf("\n");
232
233     eqFactors->SetContent(alpha);
234   }
235
236   delete source2;      
237   
238   // Now we store the VZERO Equalization Factors Object into OCDB
239
240   resECal=kTRUE;
241   
242   AliCDBMetaData metaData2;
243   metaData2.SetBeamPeriod(0);
244   metaData2.SetResponsible("Brigitte Cheynis");
245   metaData2.SetComment("VZERO Equalization Factors object filled by VZERO preprocessor");
246
247   resECal = Store("Calib", "EqualizationFactors", eqFactors, &metaData2, 0, kTRUE);
248
249   if(resECal==kFALSE ) result = 1;
250
251   delete eqFactors;
252   delete sourceList2; 
253
254         
255   return result;
256 }
257