Fixed also smell detection
[u/mrichter/AliRoot.git] / PMD / AliPMDPreprocessor.cxx
CommitLineData
c1e70747 1/***************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
3 * *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
6 * *
7 * Permission to use, copy, modify and distribute this software and its *
8 * documentation strictly for non-commercial purposes is hereby granted *
9 * without fee, provided that the above copyright notice appears in all *
10 * copies and that both the copyright notice and this permission notice *
11 * appear in the supporting documentation. The authors make no claims *
12 * about the suitability of this software for any purpose. It is *
13 * provided "as is" without express or implied warranty. *
14 **************************************************************************/
15//-----------------------------------------------------//
16// //
17// Source File : AliPMDPreprocessor.cxx //
18// //
19// //
20//-----------------------------------------------------//
21
ad6005fa 22// --- ROOT system
23#include <TFile.h>
ad6005fa 24
25#include "AliPMDPreprocessor.h"
cda4fe9e 26#include "AliPMDPedestal.h"
ad6005fa 27#include "AliPMDCalibData.h"
28#include "AliLog.h"
29#include "AliShuttleInterface.h"
30#include "AliCDBMetaData.h"
31#include <TTimeStamp.h>
32#include <TObjString.h>
33#include <TTree.h>
ad6005fa 34
35
36ClassImp(AliPMDPreprocessor)
cda4fe9e 37
ad6005fa 38//______________________________________________________________________________________________
a80b0ff4 39AliPMDPreprocessor::AliPMDPreprocessor(AliShuttleInterface* shuttle) :
40 AliPreprocessor("PMD", shuttle)
ad6005fa 41{
42 // constructor
43}
44
45//______________________________________________________________________________________________
46AliPMDPreprocessor::~AliPMDPreprocessor()
47{
48 // destructor
49}
50
51//______________________________________________________________________________________________
52void AliPMDPreprocessor::Initialize(Int_t run, UInt_t startTime,
53 UInt_t endTime)
54{
55 // Creates AliPMDDataDAQ object
56
cda4fe9e 57 AliPreprocessor::Initialize(run, startTime, endTime);
ad6005fa 58
cda4fe9e 59 AliInfo(Form("\n\tRun %d \n\tStartTime %s \n\tEndTime %s", run,
60 TTimeStamp(startTime).AsString(),
61 TTimeStamp(endTime).AsString()));
ad6005fa 62
cda4fe9e 63 fRun = run;
64 fStartTime = startTime;
65 fEndTime = endTime;
ad6005fa 66
67}
68
69//______________________________________________________________________________________________
70UInt_t AliPMDPreprocessor::Process(TMap* pdaqAliasMap)
71{
c1e70747 72 // This reads the pedestal and gain files and stores in the database
73
74
cda4fe9e 75 if(!pdaqAliasMap) return 1;
76 TString runType = GetRunType();
77 if(runType == "PEDESTAL_RUN"){
78 AliPMDPedestal *pedestal = new AliPMDPedestal();
79
80 TList* filesources = GetFileSources(kDAQ, "PMD_PED");
81
82 if(!filesources) {
83 Log(Form("No sources found for PMD_PED!"));
84 return 1;
85 }
86
87 AliInfo("Here's the list of sources for PMD_PED");
88 filesources->Print();
89
90 TIter iter(filesources);
91 TObjString* source;
92 UInt_t result = 0;
93 TString filename;
94 while((source=dynamic_cast<TObjString*> (iter.Next()))){
95 filename = GetFile(kDAQ, "PMD_PED", source->GetName());
96 if(filename.Length() == 0) {
97 Log(Form("Error retrieving file from source %s failed!", source->GetName()));
98 delete filesources;
99 return 1;
100 }
101
102 Log(Form("File with id PMD_PED got from %s", source->GetName()));
c1e70747 103
104 Int_t det, sm, row, col;
105 Float_t mean, rms;
106
cda4fe9e 107 TFile *f= new TFile(filename.Data());
108 if(!f || !f->IsOpen())
109 {
110 Log(Form("Error opening file with Id PMD_PED from source %s!", source->GetName()));
111 return 1;
112 }
113 TTree *tree = dynamic_cast<TTree *> (f->Get("ped"));
114 if (!tree)
115 {
116 Log("Could not find object \"ped\" in PED file!");
117 return 1;
118 }
119
c1e70747 120 tree->SetBranchAddress("det", &det);
121 tree->SetBranchAddress("sm", &sm);
122 tree->SetBranchAddress("row", &row);
123 tree->SetBranchAddress("col", &col);
124 tree->SetBranchAddress("mean", &mean);
125 tree->SetBranchAddress("rms", &rms);
cda4fe9e 126 Int_t nEntries = (Int_t) tree->GetEntries();
127 for(Int_t i = 0; i < nEntries; i++)
128 {
129 tree->GetEntry(i);
c1e70747 130 pedestal->SetPedMeanRms(det,sm,row,col,mean,rms);
cda4fe9e 131 }
132 f->Close();
133 delete f;
134 }
135 AliCDBMetaData metaData;
136 metaData.SetBeamPeriod(0);
137 metaData.SetComment("test PMD preprocessor");
138
139 result = Store("Calib","Ped", pedestal, &metaData);
140 delete pedestal;
141 if(result==0)
142 {
143 Log("Error storing");
144 return 1;
145 }
146 else
147 {
148 return 0;
149 }
150
151 }else if (runType == "PHYSICS"){
ad6005fa 152
153 AliPMDCalibData *calibda = new AliPMDCalibData();
cda4fe9e 154
ad6005fa 155 TList* filesources = GetFileSources(kDAQ, "PMDGAINS");
cda4fe9e 156
ad6005fa 157 if(!filesources) {
cda4fe9e 158 Log(Form("No sources found for PMDGAINS!"));
159 return 1;
160 }
161
ad6005fa 162 AliInfo("Here's the list of sources for PMDGAINS");
163 filesources->Print();
cda4fe9e 164
ad6005fa 165 TIter iter(filesources);
166 TObjString* source;
ad6005fa 167 UInt_t result = 0;
168 TString filename;
169 while((source=dynamic_cast<TObjString*> (iter.Next()))){
cda4fe9e 170 filename = GetFile(kDAQ, "PMDGAINS", source->GetName());
171 if(filename.Length() == 0) {
172 Log(Form("Error retrieving file from source %s failed!", source->GetName()));
173 delete filesources;
174 return 1;
175 }
176
177 Log(Form("File with id PMDGAINS got from %s", source->GetName()));
c1e70747 178
179 Int_t det, sm, row, col;
180 Float_t gain;
181
cda4fe9e 182 TFile *f1= new TFile(filename.Data());
183 if(!f1 || !f1->IsOpen())
184 {
185 Log(Form("Error opening file with Id PMDGAINS from source %s!", source->GetName()));
186 return 1;
187 }
188 TTree *tree = dynamic_cast<TTree *> (f1->Get("ic"));
189 if (!tree)
190 {
191 Log("Could not find object \"ic\" in DAQ file!");
192 return 1;
193 }
194
c1e70747 195 tree->SetBranchAddress("det", &det);
196 tree->SetBranchAddress("sm", &sm);
197 tree->SetBranchAddress("row", &row);
198 tree->SetBranchAddress("col", &col);
199 tree->SetBranchAddress("gain", &gain);
cda4fe9e 200 Int_t nEntries = (Int_t) tree->GetEntries();
201 for(Int_t i = 0; i < nEntries; i++)
202 {
203 tree->GetEntry(i);
204// if(DET>1 || SM>23 || ROW>95 || COL>95) {
205// printf("Error! gain[%d,%d,%d,%d] = %f\n",DET,SM,ROW,COL,GAIN);
206// continue;
207 // }
c1e70747 208 calibda->SetGainFact(det,sm,row,col,gain);
cda4fe9e 209 }
210 f1->Close();
211 delete f1;
212 }
213
214 AliCDBMetaData metaData;
215 metaData.SetBeamPeriod(0);
216 metaData.SetComment("test PMD preprocessor");
217 result = Store("Calib","Gain", calibda, &metaData);
218 delete calibda;
219 if(result==0)
220 {
221 Log("Error storing");
222 return 1;
223 }
224 else
225 {
226 return 0;
227 }
228
229 }
230
231 return 2;
ad6005fa 232}
233