]> git.uio.no Git - u/mrichter/AliRoot.git/blob - VZERO/AliVZEROPreprocessor.cxx
d18258f88cd92b730e63cab939b04a0b8a2f4060
[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
101         fData->ProcessData(*dcsAliasMap);
102         //fData->Draw("");              // Draws the HV values as a function of time
103         //dcsAliasMap->Print("");       // Prints out the HV values
104
105         // Writes VZERO PMs HV values into VZERO calibration object
106         calibData->SetMeanHV(fData->GetMeanHV());
107         calibData->SetWidthHV(fData->GetWidthHV());
108         calibData->SetDeadMap(fData->GetDeadMap());
109            
110    // *************** From DAQ ******************
111    
112         TString sourcesId = "V00da_results";
113
114         TList* sourceList = GetFileSources(kDAQ, sourcesId.Data());
115         if (!sourceList)  {
116                 Log(Form("No sources found for id %s", sourcesId.Data()));                      
117                 return 1; }
118         Log(Form("The following sources produced files with the id %s",sourcesId.Data()));
119         sourceList->Print();    
120
121         TIter iter(sourceList);
122         TObjString *source = 0;
123                 
124         while((source=dynamic_cast<TObjString*> (iter.Next()))){
125                 fileName = GetFile(kDAQ, sourcesId.Data(), source->GetName());
126                 if (fileName.Length() > 0)
127                 Log(Form("Got the file %s, now we can extract some values.", fileName.Data()));
128                 FILE *file;
129                 if((file = fopen(fileName.Data(),"r")) == NULL){
130                                    Log(Form("Cannot open file %s",fileName.Data()));
131                                    return 1;}
132                 Float_t pedMean[128], pedSigma[128], adcMean[128], adcSigma[128] ;
133                 for(Int_t j=0; j<128; j++)fscanf(file,"%f %f %f %f",
134                                           &pedMean[j], &pedSigma[j], &adcMean[j], &adcSigma[j]);
135                 fclose(file);
136                 
137                 calibData->SetPedestal(pedMean);
138                 calibData->SetSigma(pedSigma);                  
139                 calibData->SetGain(adcMean); 
140                 calibData->SetADCsigma(adcSigma);
141                 }                               
142
143         delete source;      
144   
145   // Check that everything was properly transmitted
146
147 //   for(Int_t j=0; j<128; j++){printf("Pedestal[%d] -> %f \n",j,calibData->GetPedestal(j));}
148 //   for(Int_t j=0; j<128; j++){printf("pedSigma[%d] -> %f \n",j,calibData->GetSigma(j));}
149 //   for(Int_t j=0; j<128; j++){printf("Gain[%d] -> %f \n",j,calibData->GetGain(j));}
150 //   for(Int_t j=0; j<128; j++){printf("adcSigma[%d] -> %f \n",j,calibData->GetADCsigma(j));}
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));}
153   
154   // Now we store the VZERO Calibration Object into CalibrationDB
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;
169   
170
171   delete calibData;
172   delete sourceList; 
173
174  // -----------------------------------------------------------------------
175  // Retrieves Front End Electronics Parameters from  DCS archive
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
185         // Stores the VZERO Trigger Object into TriggerDB
186         
187         resECal=kTRUE;
188         
189         result = 0;
190         metaData.SetBeamPeriod(0);
191         metaData.SetResponsible("Brigitte Cheynis");
192         metaData.SetComment("This preprocessor fills an AliVZEROTriggerData object");
193         
194         resECal = Store("Trigger", "Data", triggerData, &metaData, 0, kTRUE);
195         if(resECal==kFALSE ) result = 1;
196         
197         
198   return result;
199 }
200