]> git.uio.no Git - u/mrichter/AliRoot.git/blob - AD/ADbase/AliADPreprocessor.cxx
Changes for Root6 (Mikolaj)
[u/mrichter/AliRoot.git] / AD / ADbase / AliADPreprocessor.cxx
1 #include "AliADPreprocessor.h"
2 #include "AliADCalibData.h"
3 #include "AliCDBMetaData.h"
4 #include "AliCDBEntry.h"
5 #include "AliDCSValue.h"
6 #include "AliLog.h"
7 #include "AliShuttleInterface.h"
8 #include "AliADDataDCS.h"
9
10 #include <TFile.h>
11 #include <TTimeStamp.h>
12 #include <TObjString.h>
13 #include <TSystem.h>
14 #include <TH1F.h>
15
16
17 class Tlist;
18
19 //
20 //  This class is  a simple preprocessor for AD detector.
21 //
22 //  It gets High Voltage values for a given run from DCS and Pedestal values from DAQ 
23 //  and writes them as Calibration MetaData into OCDB/AD/Calib/Data
24 //  It also retrieves FEE parameters from DCS archive   
25 //  and writes them as Trigger MetaData into OCDB/AD/Trigger/Data 
26 //  (to be used for trigger simulation)
27 //
28
29 ClassImp(AliADPreprocessor)
30
31 //______________________________________________________________________________________________
32 AliADPreprocessor::AliADPreprocessor(AliShuttleInterface* shuttle) :
33         AliPreprocessor("AD0", shuttle),
34         fDCSData(0)
35  
36 {
37   // constructor  
38   
39   AddRunType("STANDALONE_PULSER");
40   AddRunType("STANDALONE_BC");
41   AddRunType("PHYSICS");
42     
43 }
44
45 //______________________________________________________________________________________________
46 AliADPreprocessor::~AliADPreprocessor()
47 {
48   // destructor
49         delete fDCSData;
50         
51 }
52
53 //______________________________________________________________________________________________
54 void AliADPreprocessor::Initialize(Int_t run, UInt_t startTime,
55         UInt_t endTime)
56 {
57   // Creates AliADDataDCS object
58
59    AliPreprocessor::Initialize(run, startTime, endTime);
60   
61    Log(Form("\n\tRun %d \n\tStartTime %s \n\tEndTime %s", run,
62                 TTimeStamp(startTime).AsString(),
63                 TTimeStamp(endTime).AsString()));
64
65    fRun       = run;
66    // fStartTime = startTime;
67    // fEndTime   = endTime;
68    fStartTime = GetStartTimeDCSQuery ();
69    fEndTime   = GetEndTimeDCSQuery ();
70    time_t daqStart = (time_t) (((TString)GetRunParameter("DAQ_time_start")).Atoi());
71    time_t daqEnd   = (time_t) (((TString)GetRunParameter("DAQ_time_end")).Atoi());
72    time_t ctpStart = (time_t) (((TString)GetRunParameter("TRGTimeStart")).Atoi());
73    time_t ctpEnd   = (time_t) (((TString)GetRunParameter("TRGTimeEnd")).Atoi());
74    
75         fDCSData      = new AliADDataDCS(fRun, fStartTime, fEndTime,(UInt_t)daqStart, (UInt_t)daqEnd,(UInt_t)ctpStart, (UInt_t)ctpEnd); 
76    
77 }
78
79 //______________________________________________________________________________________________
80 UInt_t AliADPreprocessor::Process(TMap* dcsAliasMap)
81 {
82   // Fills data retrieved from DCS and DAQ into a AliADCalibData 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   AliADCalibData *calibData = new AliADCalibData();
94   
95   // *************** HV From DCS ******************
96   // Fills data into a AliADDataDCS object
97   if(!dcsAliasMap) return 1;
98
99         // The Processing of the DCS input data is forwarded to AliADDataDCS
100   if (!fDCSData->ProcessData(*dcsAliasMap)) return 1;
101
102         // Writes AD PMs HV values into AD calibration object and Timing resolution parameters
103         calibData->FillDCSData(fDCSData);
104            
105    // *************** From DAQ ******************
106    
107         TString sourcesId = "AD0da_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;
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[32], pedSigma[32], adcMean[32], adcSigma[32] ;
128                 for(Int_t j=0; j<32; j++) {
129                   Int_t resScan = fscanf(file,"%f %f %f %f",
130                                          &pedMean[j], &pedSigma[j], &adcMean[j], &adcSigma[j]);
131                   if (resScan != 4) Log(Form("Bad data in file %s !",fileName.Data()));
132                 }
133                 fclose(file);
134                 
135                 calibData->SetPedestal(pedMean);
136                 calibData->SetSigma(pedSigma);
137                 calibData->SetADCmean(adcMean);                 
138                 calibData->SetADCsigma(adcSigma);
139                 }                               
140
141         delete source;      
142   
143   // Check that everything was properly transmitted
144
145 //   for(Int_t j=0; j<128; j++){printf("Pedestal[%d] -> %f \n",j,calibData->GetPedestal(j));}
146 //   for(Int_t j=0; j<128; j++){printf("pedSigma[%d] -> %f \n",j,calibData->GetSigma(j));}
147 //   for(Int_t j=0; j<128; j++){printf("Gain[%d] -> %f \n",j,calibData->GetGain(j));}
148 //   for(Int_t j=0; j<128; j++){printf("adcSigma[%d] -> %f \n",j,calibData->GetADCsigma(j));}
149 //   for(Int_t j=0; j<64; j++){printf("MeanHV[%d] -> %f \n",j,calibData->GetMeanHV(j));}
150 //   for(Int_t j=0; j<64; j++){printf("WidthHV[%d] -> %f \n",j,calibData->GetWidthHV(j));}
151   
152   // Now we store the AD Calibration Object into CalibrationDB
153
154   Bool_t resECal=kTRUE;
155   
156   Bool_t result = 0;
157 //  if(sourceList && sourceList->GetEntries()>0)
158 //  {
159   AliCDBMetaData metaData;
160   metaData.SetBeamPeriod(0);
161   metaData.SetResponsible("Michal Broz");
162   metaData.SetComment("This preprocessor fills an AliADCalibData object");
163
164   resECal = Store("Calib", "Data", calibData, &metaData, 0, kTRUE);
165 //  }
166   if(resECal==kFALSE ) result = 1;
167   
168
169   delete calibData;
170   delete sourceList; 
171
172         
173   return result;
174 }
175