]> git.uio.no Git - u/mrichter/AliRoot.git/blame - PMD/AliPMDPreprocessor.cxx
online gain calibration added
[u/mrichter/AliRoot.git] / PMD / AliPMDPreprocessor.cxx
CommitLineData
ad6005fa 1// --- ROOT system
2#include <TFile.h>
3#include <TTimeStamp.h>
4
5#include "AliPMDPreprocessor.h"
cda4fe9e 6#include "AliPMDPedestal.h"
ad6005fa 7#include "AliPMDCalibData.h"
8#include "AliLog.h"
9#include "AliShuttleInterface.h"
10#include "AliCDBMetaData.h"
11#include <TTimeStamp.h>
12#include <TObjString.h>
13#include <TTree.h>
14#include <TSystem.h>
15
16
17ClassImp(AliPMDPreprocessor)
cda4fe9e 18
ad6005fa 19//______________________________________________________________________________________________
a80b0ff4 20AliPMDPreprocessor::AliPMDPreprocessor(AliShuttleInterface* shuttle) :
21 AliPreprocessor("PMD", shuttle)
ad6005fa 22{
23 // constructor
24}
25
26//______________________________________________________________________________________________
27AliPMDPreprocessor::~AliPMDPreprocessor()
28{
29 // destructor
30}
31
32//______________________________________________________________________________________________
33void AliPMDPreprocessor::Initialize(Int_t run, UInt_t startTime,
34 UInt_t endTime)
35{
36 // Creates AliPMDDataDAQ object
37
cda4fe9e 38 AliPreprocessor::Initialize(run, startTime, endTime);
ad6005fa 39
cda4fe9e 40 AliInfo(Form("\n\tRun %d \n\tStartTime %s \n\tEndTime %s", run,
41 TTimeStamp(startTime).AsString(),
42 TTimeStamp(endTime).AsString()));
ad6005fa 43
cda4fe9e 44 fRun = run;
45 fStartTime = startTime;
46 fEndTime = endTime;
ad6005fa 47
48}
49
50//______________________________________________________________________________________________
51UInt_t AliPMDPreprocessor::Process(TMap* pdaqAliasMap)
52{
cda4fe9e 53
54 if(!pdaqAliasMap) return 1;
55 TString runType = GetRunType();
56 if(runType == "PEDESTAL_RUN"){
57 AliPMDPedestal *pedestal = new AliPMDPedestal();
58
59 TList* filesources = GetFileSources(kDAQ, "PMD_PED");
60
61 if(!filesources) {
62 Log(Form("No sources found for PMD_PED!"));
63 return 1;
64 }
65
66 AliInfo("Here's the list of sources for PMD_PED");
67 filesources->Print();
68
69 TIter iter(filesources);
70 TObjString* source;
71 UInt_t result = 0;
72 TString filename;
73 while((source=dynamic_cast<TObjString*> (iter.Next()))){
74 filename = GetFile(kDAQ, "PMD_PED", source->GetName());
75 if(filename.Length() == 0) {
76 Log(Form("Error retrieving file from source %s failed!", source->GetName()));
77 delete filesources;
78 return 1;
79 }
80
81 Log(Form("File with id PMD_PED got from %s", source->GetName()));
82 Int_t DET,SM,ROW,COL;
83 Float_t MEAN,RMS;
84 TFile *f= new TFile(filename.Data());
85 if(!f || !f->IsOpen())
86 {
87 Log(Form("Error opening file with Id PMD_PED from source %s!", source->GetName()));
88 return 1;
89 }
90 TTree *tree = dynamic_cast<TTree *> (f->Get("ped"));
91 if (!tree)
92 {
93 Log("Could not find object \"ped\" in PED file!");
94 return 1;
95 }
96
97 tree->SetBranchAddress("DET", &DET);
98 tree->SetBranchAddress("SM", &SM);
99 tree->SetBranchAddress("ROW", &ROW);
100 tree->SetBranchAddress("COL", &COL);
101 tree->SetBranchAddress("MEAN", &MEAN);
102 tree->SetBranchAddress("RMS", &RMS);
103 Int_t nEntries = (Int_t) tree->GetEntries();
104 for(Int_t i = 0; i < nEntries; i++)
105 {
106 tree->GetEntry(i);
107 pedestal->SetPedMeanRms(DET,SM,ROW,COL,MEAN,RMS);
108 }
109 f->Close();
110 delete f;
111 }
112 AliCDBMetaData metaData;
113 metaData.SetBeamPeriod(0);
114 metaData.SetComment("test PMD preprocessor");
115
116 result = Store("Calib","Ped", pedestal, &metaData);
117 delete pedestal;
118 if(result==0)
119 {
120 Log("Error storing");
121 return 1;
122 }
123 else
124 {
125 return 0;
126 }
127
128 }else if (runType == "PHYSICS"){
ad6005fa 129
130 AliPMDCalibData *calibda = new AliPMDCalibData();
cda4fe9e 131
ad6005fa 132 TList* filesources = GetFileSources(kDAQ, "PMDGAINS");
cda4fe9e 133
ad6005fa 134 if(!filesources) {
cda4fe9e 135 Log(Form("No sources found for PMDGAINS!"));
136 return 1;
137 }
138
ad6005fa 139 AliInfo("Here's the list of sources for PMDGAINS");
140 filesources->Print();
cda4fe9e 141
ad6005fa 142 TIter iter(filesources);
143 TObjString* source;
ad6005fa 144 UInt_t result = 0;
145 TString filename;
146 while((source=dynamic_cast<TObjString*> (iter.Next()))){
cda4fe9e 147 filename = GetFile(kDAQ, "PMDGAINS", source->GetName());
148 if(filename.Length() == 0) {
149 Log(Form("Error retrieving file from source %s failed!", source->GetName()));
150 delete filesources;
151 return 1;
152 }
153
154 Log(Form("File with id PMDGAINS got from %s", source->GetName()));
155 Int_t DET,SM,ROW,COL;
156 Float_t GAIN;
157 TFile *f1= new TFile(filename.Data());
158 if(!f1 || !f1->IsOpen())
159 {
160 Log(Form("Error opening file with Id PMDGAINS from source %s!", source->GetName()));
161 return 1;
162 }
163 TTree *tree = dynamic_cast<TTree *> (f1->Get("ic"));
164 if (!tree)
165 {
166 Log("Could not find object \"ic\" in DAQ file!");
167 return 1;
168 }
169
170 tree->SetBranchAddress("DET", &DET);
171 tree->SetBranchAddress("SM", &SM);
172 tree->SetBranchAddress("ROW", &ROW);
173 tree->SetBranchAddress("COL", &COL);
174 tree->SetBranchAddress("GAIN", &GAIN);
175 Int_t nEntries = (Int_t) tree->GetEntries();
176 for(Int_t i = 0; i < nEntries; i++)
177 {
178 tree->GetEntry(i);
179// if(DET>1 || SM>23 || ROW>95 || COL>95) {
180// printf("Error! gain[%d,%d,%d,%d] = %f\n",DET,SM,ROW,COL,GAIN);
181// continue;
182 // }
183 calibda->SetGainFact(DET,SM,ROW,COL,GAIN);
184 }
185 f1->Close();
186 delete f1;
187 }
188
189 AliCDBMetaData metaData;
190 metaData.SetBeamPeriod(0);
191 metaData.SetComment("test PMD preprocessor");
192 result = Store("Calib","Gain", calibda, &metaData);
193 delete calibda;
194 if(result==0)
195 {
196 Log("Error storing");
197 return 1;
198 }
199 else
200 {
201 return 0;
202 }
203
204 }
205
206 return 2;
ad6005fa 207}
208