]> git.uio.no Git - u/mrichter/AliRoot.git/blob - VZERO/AliVZEROPreprocessor.cxx
Add macros for Train2, using the latest Analysis Framework
[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   AddRunType("STANDALONE");
28   AddRunType("PHYSICS");
29     
30 }
31
32 //______________________________________________________________________________________________
33 AliVZEROPreprocessor::~AliVZEROPreprocessor()
34 {
35   // destructor
36   
37    delete fData;
38 }
39
40 //______________________________________________________________________________________________
41 void AliVZEROPreprocessor::Initialize(Int_t run, UInt_t startTime,
42         UInt_t endTime)
43 {
44   // Creates AliZDCDataDCS object
45
46    AliPreprocessor::Initialize(run, startTime, endTime);
47   
48    Log(Form("\n\tRun %d \n\tStartTime %s \n\tEndTime %s", run,
49                 TTimeStamp(startTime).AsString(),
50                 TTimeStamp(endTime).AsString()));
51
52    fRun       = run;
53    // fStartTime = startTime;
54    // fEndTime   = endTime;
55    fStartTime = GetStartTimeDCSQuery ();
56    fEndTime   = GetEndTimeDCSQuery ();
57
58    fData      = new AliVZERODataDCS(fRun, fStartTime, fEndTime);
59    
60 }
61
62 //______________________________________________________________________________________________
63 UInt_t AliVZEROPreprocessor::Process(TMap* dcsAliasMap)
64 {
65   // Fills data retrieved from DCS and DAQ into a AliVZEROCalibData object and 
66   // stores it into CalibrationDB
67
68
69   // *** GET RUN TYPE ***
70   TString runType = GetRunType();
71
72
73   // *** REFERENCE DATA *** 
74   
75   TString fileName; 
76   AliVZEROCalibData *calibData = new AliVZEROCalibData();
77   
78   // *************** From DCS ******************
79   // Fills data into a AliVZERODataDCS object
80   if(!dcsAliasMap) return 1;
81
82         // The processing of the DCS input data is forwarded to AliVZERODataDCS
83
84         fData->ProcessData(*dcsAliasMap);
85         //fData->Draw("");              // Draws the HV values as a function of time
86         //dcsAliasMap->Print("");       // Prints out the HV values
87
88         // Writes VZERO PMs HV values into VZERO calibration object
89         calibData->SetMeanHV(fData->GetMeanHV());
90         calibData->SetWidthHV(fData->GetWidthHV());
91     
92    // *************** From DAQ ******************
93    
94         TString SourcesId = "V00da_results";
95
96         TList* sourceList = GetFileSources(kDAQ, SourcesId.Data());
97         if (!sourceList)  {
98                 Log(Form("No sources found for id %s", SourcesId.Data()));                      
99                 return 1; }
100         Log(Form("The following sources produced files with the id %s",SourcesId.Data()));
101         sourceList->Print();    
102
103         TIter iter(sourceList);
104         TObjString *source = 0;
105                 
106         while((source=dynamic_cast<TObjString*> (iter.Next()))){
107                 fileName = GetFile(kDAQ, SourcesId.Data(), source->GetName());
108                 if (fileName.Length() > 0)
109                 Log(Form("Got the file %s, now we can extract some values.", fileName.Data()));
110                 FILE *file;
111                 if((file = fopen(fileName.Data(),"r")) == NULL){
112                                    Log(Form("Cannot open file %s",fileName.Data()));
113                                    return 1;}
114                 Float_t PEDmean[128], PEDsigma[128], ADCmean[128], ADCsigma[128] ;
115                 for(Int_t j=0; j<128; j++)fscanf(file,"%f %f %f %f",
116                                           &PEDmean[j], &PEDsigma[j], &ADCmean[j], &ADCsigma[j]);
117                 fclose(file);
118                 
119                 calibData->SetPedestal(PEDmean);
120                 calibData->SetSigma(PEDsigma);                  
121                 calibData->SetGain(ADCmean); 
122                 calibData->SetADCsigma(ADCsigma);
123                 }                               
124
125         delete source;      
126   
127   // Check that everything was properly transmitted
128
129 //   for(Int_t j=0; j<128; j++){printf("Pedestal[%d] -> %f \n",j,calibData->GetPedestal(j));}
130 //   for(Int_t j=0; j<128; j++){printf("PedSigma[%d] -> %f \n",j,calibData->GetSigma(j));}
131 //   for(Int_t j=0; j<128; j++){printf("Gain[%d] -> %f \n",j,calibData->GetGain(j));}
132 //   for(Int_t j=0; j<128; j++){printf("ADCsigma[%d] -> %f \n",j,calibData->GetADCsigma(j));}
133 //   for(Int_t j=0; j<64; j++){printf("MeanHV[%d] -> %f \n",j,calibData->GetMeanHV(j));}
134 //   for(Int_t j=0; j<64; j++){printf("WidthHV[%d] -> %f \n",j,calibData->GetWidthHV(j));}
135   
136   // Now we store the VZERO Calibration Object into CalibrationDB
137
138   Bool_t resECal=kTRUE;
139   
140   Bool_t result = 0;
141 //  if(sourceList && sourceList->GetEntries()>0)
142 //  {
143   AliCDBMetaData metaData;
144   metaData.SetBeamPeriod(0);
145   metaData.SetResponsible("Brigitte Cheynis");
146   metaData.SetComment("This preprocessor fills an AliVZEROCalibData object");
147
148   resECal = Store("Calib", "Data", calibData, &metaData, 0, kTRUE);
149 //  }
150   if(resECal==kFALSE ) result = 1;
151   
152
153   delete calibData;
154   delete sourceList; 
155
156   return result;
157 }
158