correct mask for V0 charge decoding in STU payload
[u/mrichter/AliRoot.git] / VZERO / AliVZEROPreprocessor.cxx
CommitLineData
d2b85094 1#include "AliVZEROPreprocessor.h"
2#include "AliVZEROCalibData.h"
fad64858 3#include "AliVZEROTriggerData.h"
d2b85094 4#include "AliCDBMetaData.h"
5#include "AliCDBEntry.h"
6#include "AliDCSValue.h"
7#include "AliLog.h"
6472f844 8#include "AliShuttleInterface.h"
9#include "AliVZERODataFEE.h"
10#include "AliVZERODataDCS.h"
11
d2b85094 12#include <TFile.h>
13#include <TTimeStamp.h>
14#include <TObjString.h>
15#include <TSystem.h>
13067c49 16#include <TH1F.h>
d2b85094 17
6472f844 18
19class Tlist;
20
21//
22// This class is a simple preprocessor for VZERO detector.
d2b85094 23//
6472f844 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)
d2b85094 29//
30
31ClassImp(AliVZEROPreprocessor)
32
33//______________________________________________________________________________________________
34AliVZEROPreprocessor::AliVZEROPreprocessor(AliShuttleInterface* shuttle) :
fad64858 35 AliPreprocessor("V00", shuttle),
36 fData(0),
37 fFEEData(0)
d2b85094 38
39{
6b6c5c59 40 // constructor
41
e58b4e66 42 AddRunType("STANDALONE_PULSER");
43 AddRunType("STANDALONE_BC");
6b6c5c59 44 AddRunType("PHYSICS");
45
d2b85094 46}
47
48//______________________________________________________________________________________________
49AliVZEROPreprocessor::~AliVZEROPreprocessor()
50{
51 // destructor
fad64858 52 delete fFEEData;
53 delete fData;
54
d2b85094 55}
56
57//______________________________________________________________________________________________
58void AliVZEROPreprocessor::Initialize(Int_t run, UInt_t startTime,
59 UInt_t endTime)
60{
fad64858 61 // Creates AliVZERODataDCS object
d2b85094 62
d1c61c72 63 AliPreprocessor::Initialize(run, startTime, endTime);
64
65 Log(Form("\n\tRun %d \n\tStartTime %s \n\tEndTime %s", run,
d2b85094 66 TTimeStamp(startTime).AsString(),
67 TTimeStamp(endTime).AsString()));
68
d1c61c72 69 fRun = run;
312388a6 70 // fStartTime = startTime;
71 // fEndTime = endTime;
72 fStartTime = GetStartTimeDCSQuery ();
73 fEndTime = GetEndTimeDCSQuery ();
3b757990 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);
fad64858 78 fFEEData = new AliVZERODataFEE(fRun, fStartTime, fEndTime);
d1c61c72 79
d2b85094 80}
81
d2b85094 82//______________________________________________________________________________________________
83UInt_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
fad64858 98 // *************** HV From DCS ******************
d2b85094 99 // Fills data into a AliVZERODataDCS object
100 if(!dcsAliasMap) return 1;
101
fad64858 102 // The Processing of the DCS input data is forwarded to AliVZERODataDCS
75f53676 103 if (!fData->ProcessData(*dcsAliasMap)) return 1;
d2b85094 104
d5deaaa5 105 // Writes VZERO PMs HV values into VZERO calibration object and Timing resolution parameters
106 calibData->FillDCSData(fData);
7495d2be 107
d2b85094 108 // *************** From DAQ ******************
96da3fe8 109
6472f844 110 TString sourcesId = "V00da_results";
96da3fe8 111
6472f844 112 TList* sourceList = GetFileSources(kDAQ, sourcesId.Data());
96da3fe8 113 if (!sourceList) {
6472f844 114 Log(Form("No sources found for id %s", sourcesId.Data()));
96da3fe8 115 return 1; }
6472f844 116 Log(Form("The following sources produced files with the id %s",sourcesId.Data()));
96da3fe8 117 sourceList->Print();
118
119 TIter iter(sourceList);
e5c19018 120 TObjString *source;
96da3fe8 121
122 while((source=dynamic_cast<TObjString*> (iter.Next()))){
6472f844 123 fileName = GetFile(kDAQ, sourcesId.Data(), source->GetName());
96da3fe8 124 if (fileName.Length() > 0)
d1c61c72 125 Log(Form("Got the file %s, now we can extract some values.", fileName.Data()));
96da3fe8 126 FILE *file;
127 if((file = fopen(fileName.Data(),"r")) == NULL){
d1c61c72 128 Log(Form("Cannot open file %s",fileName.Data()));
96da3fe8 129 return 1;}
6472f844 130 Float_t pedMean[128], pedSigma[128], adcMean[128], adcSigma[128] ;
93f60e03 131 for(Int_t j=0; j<128; j++) {
132 Int_t resScan = fscanf(file,"%f %f %f %f",
133 &pedMean[j], &pedSigma[j], &adcMean[j], &adcSigma[j]);
134 if (resScan != 4) Log(Form("Bad data in file %s !",fileName.Data()));
135 }
96da3fe8 136 fclose(file);
137
6472f844 138 calibData->SetPedestal(pedMean);
139 calibData->SetSigma(pedSigma);
6472f844 140 calibData->SetADCsigma(adcSigma);
982d0603 141 }
025eb721 142
96da3fe8 143 delete source;
d2b85094 144
145 // Check that everything was properly transmitted
146
982d0603 147// for(Int_t j=0; j<128; j++){printf("Pedestal[%d] -> %f \n",j,calibData->GetPedestal(j));}
6472f844 148// for(Int_t j=0; j<128; j++){printf("pedSigma[%d] -> %f \n",j,calibData->GetSigma(j));}
982d0603 149// for(Int_t j=0; j<128; j++){printf("Gain[%d] -> %f \n",j,calibData->GetGain(j));}
6472f844 150// for(Int_t j=0; j<128; j++){printf("adcSigma[%d] -> %f \n",j,calibData->GetADCsigma(j));}
d2b85094 151// for(Int_t j=0; j<64; j++){printf("MeanHV[%d] -> %f \n",j,calibData->GetMeanHV(j));}
152// for(Int_t j=0; j<64; j++){printf("WidthHV[%d] -> %f \n",j,calibData->GetWidthHV(j));}
96da3fe8 153
d1c61c72 154 // Now we store the VZERO Calibration Object into CalibrationDB
312388a6 155
156 Bool_t resECal=kTRUE;
157
158 Bool_t result = 0;
159// if(sourceList && sourceList->GetEntries()>0)
160// {
161 AliCDBMetaData metaData;
162 metaData.SetBeamPeriod(0);
163 metaData.SetResponsible("Brigitte Cheynis");
164 metaData.SetComment("This preprocessor fills an AliVZEROCalibData object");
165
166 resECal = Store("Calib", "Data", calibData, &metaData, 0, kTRUE);
167// }
168 if(resECal==kFALSE ) result = 1;
d2b85094 169
d2b85094 170
171 delete calibData;
025eb721 172 delete sourceList;
d2b85094 173
fad64858 174 // -----------------------------------------------------------------------
6472f844 175 // Retrieves Front End Electronics Parameters from DCS archive
fad64858 176 // -----------------------------------------------------------------------
177 AliVZEROTriggerData *triggerData = new AliVZEROTriggerData();
178
179 // The processing of the DCS input data is forwarded to AliVZERODataFEE
180 fFEEData->ProcessData(*dcsAliasMap);
181
182 // Writes VZERO FEE parameters values into VZERO Trigger parametrization object
183 triggerData->FillData(fFEEData);
184
6472f844 185 // Stores the VZERO Trigger Object into TriggerDB
fad64858 186
187 resECal=kTRUE;
188
fad64858 189 metaData.SetBeamPeriod(0);
190 metaData.SetResponsible("Brigitte Cheynis");
191 metaData.SetComment("This preprocessor fills an AliVZEROTriggerData object");
192
193 resECal = Store("Trigger", "Data", triggerData, &metaData, 0, kTRUE);
194 if(resECal==kFALSE ) result = 1;
195
13067c49 196
197 // *************** From DAQ DA - Equalization factors ******************
198
199 TH1F *eqFactors = new TH1F("VZEROEqualizationFactors","VZERO Equalization Factors for Pb-Pb",64,-0.5,63.5);
200 sourcesId = "V00DAEqualFactors";
201
202 TList* sourceList2 = GetFileSources(kDAQ, sourcesId.Data());
203 if (!sourceList2) {
204 Log(Form("No sources found for id %s", sourcesId.Data()));
205 return 1; }
206 Log(Form("The following sources produced files with the id %s",sourcesId.Data()));
207 sourceList2->Print();
208
209 TIter iter2(sourceList2);
210 TObjString *source2;
211
212 while((source2=dynamic_cast<TObjString*> (iter2.Next()))){
213 fileName = GetFile(kDAQ, sourcesId.Data(), source2->GetName());
214 if (fileName.Length() > 0)
215 Log(Form("Got the file %s, now we can extract some values.", fileName.Data()));
216 FILE *file2;
217 if((file2 = fopen(fileName.Data(),"r")) == NULL){
218 Log(Form("Cannot open file %s",fileName.Data()));
219 return 1;}
220
221 Double_t alpha[66];
222 alpha[0] = alpha[65] = 0;
223 Int_t tempCh;
224 Float_t tempAlpha;
225 for(Int_t j=0; j<64; ++j) {
93f60e03 226 Int_t resScan = fscanf(file2,"%d %f", &tempCh, &tempAlpha);
227 if (resScan != 2) Log(Form("Bad data in file %s !",fileName.Data()));
13067c49 228 alpha[tempCh+1] = tempAlpha;
229 }
230 fclose(file2);
231
232 // Check that everything was properly transmitted
233 printf("Equalization factors (0->64): ");
2716ecba 234 for(Int_t j=0; j<64; ++j) printf("%.5f ",alpha[j+1]);
13067c49 235 printf("\n");
236
237 eqFactors->SetContent(alpha);
238 }
239
240 delete source2;
241
242 // Now we store the VZERO Equalization Factors Object into OCDB
243
244 resECal=kTRUE;
245
246 AliCDBMetaData metaData2;
247 metaData2.SetBeamPeriod(0);
248 metaData2.SetResponsible("Brigitte Cheynis");
249 metaData2.SetComment("VZERO Equalization Factors object filled by VZERO preprocessor");
250
251 resECal = Store("Calib", "EqualizationFactors", eqFactors, &metaData2, 0, kTRUE);
252
253 if(resECal==kFALSE ) result = 1;
254
255 delete eqFactors;
256 delete sourceList2;
257
fad64858 258
5fc81083 259 return result;
d2b85094 260}
261