]> git.uio.no Git - u/mrichter/AliRoot.git/blame - EMCAL/AliEMCALCalibMapAPD.cxx
Coverity corrections
[u/mrichter/AliRoot.git] / EMCAL / AliEMCALCalibMapAPD.cxx
CommitLineData
d81e6423 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/* $Id: $ */
17
18// Objects of this class contain info on APD calibration and map info
19//
20
21#include <fstream>
22#include <TString.h>
61917ab3 23#include <TFile.h>
24#include <TTree.h>
d81e6423 25
26#include "AliEMCALCalibMapAPD.h"
27
28using namespace std;
29
30ClassImp(AliEMCALCalibMapAPD)
31
32//____________________________________________________________________________
2f17a269 33AliEMCALCalibMapAPD::AliEMCALCalibMapAPD(const int nSM) :
34 fNSuperModule(nSM),
35 fSuperModuleData()
d81e6423 36{
37 //Default constructor.
2f17a269 38 for (int i=0; i<fNSuperModule; i++) {
39 fSuperModuleData.Add(new AliEMCALSuperModuleCalibMapAPD(i));
40 }
41 fSuperModuleData.Compress(); // compress the TObjArray
61e4e2e3 42 fSuperModuleData.SetOwner(kTRUE);
d81e6423 43}
44
45//____________________________________________________________________________
61917ab3 46void AliEMCALCalibMapAPD::ReadTextCalibMapAPDInfo(Int_t nSM, const TString &txtFileName,
47 Bool_t swapSides)
d81e6423 48{
49 //Read data from txt file. ; coordinates given on SuperModule basis
50
51 std::ifstream inputFile(txtFileName.Data());
52 if (!inputFile) {
53 printf("AliEMCALCalibMapAPD::ReadCalibMapAPDInfo - Cannot open the APD info file %s\n", txtFileName.Data());
54 return;
55 }
56
57 fNSuperModule = nSM;
d81e6423 58
59 Int_t iSM = 0; // SuperModule index
60 Int_t iCol = 0;
61 Int_t iRow = 0;
62 // list of values to be read
63 Int_t iHW = 0;
ab962f7b 64 Int_t iAPDNum = 0;
65 Float_t v30 = 0;
66 Float_t par[3] = {0};
67 Float_t parErr[3] = {0};
68 Int_t iBreakDown = 0;
69 Float_t darkCurrent = 0;
d81e6423 70 // end - all values
71
72 Int_t nAPDPerSM = AliEMCALGeoParams::fgkEMCALCols * AliEMCALGeoParams::fgkEMCALRows;
73
74 for (Int_t i = 0; i < fNSuperModule; i++) {
2f17a269 75 AliEMCALSuperModuleCalibMapAPD * t = (AliEMCALSuperModuleCalibMapAPD*) fSuperModuleData[i];
d81e6423 76 if (!inputFile) {
77 printf("AliEMCALCalibMapAPD::ReadCalibMapAPDInfo - Error while reading input file; likely EOF..");
78 return;
79 }
80 inputFile >> iSM;
2f17a269 81 t->SetSuperModuleNum(iSM);
d81e6423 82
83 for (Int_t j=0; j<nAPDPerSM; j++) {
84 inputFile >> iCol >> iRow >> iHW
ab962f7b 85 >> iAPDNum >> v30
86 >> par[0] >> par[1] >> par[2]
87 >> parErr[0] >> parErr[1] >> parErr[2]
88 >> iBreakDown >> darkCurrent;
d81e6423 89
90 // assume that this info is already swapped and done for this basis?
91 if (swapSides) {
92 // C side, oriented differently than A side: swap is requested
93 iCol = AliEMCALGeoParams::fgkEMCALCols-1 - iCol;
94 iRow = AliEMCALGeoParams::fgkEMCALRows-1 - iRow;
95 }
96
2f17a269 97 AliEMCALCalibMapAPDVal * v = t->GetAPDVal(iCol, iRow);
98
99 v->SetHardWareId(iHW);
ab962f7b 100 v->SetAPDNum(iAPDNum);
101 v->SetV30(v30);
102 v->SetPar(0, par[0]);
103 v->SetPar(1, par[1]);
104 v->SetPar(2, par[2]);
105 v->SetParErr(0, parErr[0]);
106 v->SetParErr(1, parErr[1]);
107 v->SetParErr(2, parErr[2]);
108 v->SetBreakDown(iBreakDown);
109 v->SetDarkCurrent(darkCurrent);
d81e6423 110 }
111
112 } // i, SuperModule
113
114 inputFile.close();
115
116 return;
117}
118
119//____________________________________________________________________________
61917ab3 120void AliEMCALCalibMapAPD::WriteTextCalibMapAPDInfo(const TString &txtFileName,
121 Bool_t swapSides)
d81e6423 122{
123 // write data to txt file. ; coordinates given on SuperModule basis
124
125 std::ofstream outputFile(txtFileName.Data());
126 if (!outputFile) {
127 printf("AliEMCALCalibMapAPD::WriteCalibMapAPDInfo - Cannot open the APD output file %s\n", txtFileName.Data());
128 return;
129 }
130
131 Int_t iCol = 0;
132 Int_t iRow = 0;
133
134 Int_t nAPDPerSM = AliEMCALGeoParams::fgkEMCALCols * AliEMCALGeoParams::fgkEMCALRows;
135
136 for (Int_t i = 0; i < fNSuperModule; i++) {
2f17a269 137 AliEMCALSuperModuleCalibMapAPD * t = (AliEMCALSuperModuleCalibMapAPD*) fSuperModuleData[i];
138 outputFile << t->GetSuperModuleNum() << endl;
d81e6423 139
140 for (Int_t j=0; j<nAPDPerSM; j++) {
141 iCol = j / AliEMCALGeoParams::fgkEMCALRows;
142 iRow = j % AliEMCALGeoParams::fgkEMCALRows;
143
2f17a269 144 AliEMCALCalibMapAPDVal * v = t->GetAPDVal(iCol, iRow);
d81e6423 145
146 if (swapSides) {
147 // C side, oriented differently than A side: swap is requested
148 iCol = AliEMCALGeoParams::fgkEMCALCols-1 - iCol;
149 iRow = AliEMCALGeoParams::fgkEMCALRows-1 - iRow;
150 }
151
2f17a269 152 outputFile << iCol << " " << iRow << " " << v->GetHardWareId()
153 << " " << v->GetAPDNum() << " " << v->GetV30()
154 << " " << v->GetPar(0) << " " << v->GetPar(1) << " " << v->GetPar(2)
155 << " " << v->GetParErr(0) << " " << v->GetParErr(1) << " " << v->GetParErr(2)
156 << " " << v->GetBreakDown() << " " << v->GetDarkCurrent() << endl;
d81e6423 157 }
158
159 } // i, SuperModule
160
161 outputFile.close();
162
163 return;
164}
165
61917ab3 166//____________________________________________________________________________
167void AliEMCALCalibMapAPD::ReadRootCalibMapAPDInfo(const TString &rootFileName,
168 Bool_t swapSides)
169{
170 //Read data from root file. ; coordinates given on SuperModule basis
171 TFile inputFile(rootFileName, "read");
172
173 TTree *tree = (TTree*) inputFile.Get("tree");
174
175 ReadTreeCalibMapAPDInfo(tree, swapSides);
176
177 inputFile.Close();
178
179 return;
180}
181
182//____________________________________________________________________________
183void AliEMCALCalibMapAPD::ReadTreeCalibMapAPDInfo(TTree *tree,
184 Bool_t swapSides)
185{
186 // how many SuperModule's worth of entries / APDs do we have?
187 Int_t nAPDPerSM = AliEMCALGeoParams::fgkEMCALCols * AliEMCALGeoParams::fgkEMCALRows;
188 fNSuperModule = tree->GetEntries() / nAPDPerSM;
189
61917ab3 190 Int_t iSM = 0; // SuperModule index
191 Int_t iCol = 0;
192 Int_t iRow = 0;
193 // list of values to be read
194 Int_t iHW = 0;
ab962f7b 195 Int_t iAPDNum = 0;
196 Float_t v30 = 0;
197 Float_t par[3] = {0};
198 Float_t parErr[3] = {0};
199 Int_t iBreakDown = 0;
200 Float_t darkCurrent = 0;
61917ab3 201 // end - all values
202
203 // declare the branches
204 tree->SetBranchAddress("iSM", &iSM);
205 tree->SetBranchAddress("iCol", &iCol);
206 tree->SetBranchAddress("iRow", &iRow);
207 tree->SetBranchAddress("iHW", &iHW);
ab962f7b 208 tree->SetBranchAddress("APDNum", &iAPDNum);
209 tree->SetBranchAddress("V30", &v30);
210 tree->SetBranchAddress("Par", par);
211 tree->SetBranchAddress("ParErr", parErr);
212 tree->SetBranchAddress("BreakDown", &iBreakDown);
213 tree->SetBranchAddress("DarkCurrent", &darkCurrent);
61917ab3 214
215 for (int ient=0; ient<tree->GetEntries(); ient++) {
216 tree->GetEntry(ient);
217
218 // assume the index SuperModules come in order: i=iSM
2f17a269 219 AliEMCALSuperModuleCalibMapAPD * t = (AliEMCALSuperModuleCalibMapAPD*) fSuperModuleData[iSM];
220 t->SetSuperModuleNum(iSM);
61917ab3 221
222 // assume that this info is already swapped and done for this basis?
223 if (swapSides) {
224 // C side, oriented differently than A side: swap is requested
225 iCol = AliEMCALGeoParams::fgkEMCALCols-1 - iCol;
226 iRow = AliEMCALGeoParams::fgkEMCALRows-1 - iRow;
227 }
228
2f17a269 229 AliEMCALCalibMapAPDVal * v = t->GetAPDVal(iCol, iRow);
230
231 v->SetHardWareId(iHW);
ab962f7b 232 v->SetAPDNum(iAPDNum);
233 v->SetV30(v30);
234 v->SetPar(0, par[0]);
235 v->SetPar(1, par[1]);
236 v->SetPar(2, par[2]);
237 v->SetParErr(0, parErr[0]);
238 v->SetParErr(1, parErr[1]);
239 v->SetParErr(2, parErr[2]);
240 v->SetBreakDown(iBreakDown);
241 v->SetDarkCurrent(darkCurrent);
61917ab3 242 } //
243
244 return;
245}
246
247//____________________________________________________________________________
248void AliEMCALCalibMapAPD::WriteRootCalibMapAPDInfo(const TString &rootFileName,
249 Bool_t swapSides)
250{
251 // write data to root file. ; coordinates given on SuperModule basis
252 TFile destFile(rootFileName, "recreate");
253 if (destFile.IsZombie()) {
254 return;
255 }
256 destFile.cd();
257
258 TTree *tree = new TTree("tree","");
259
260 // variables for filling the TTree
261 Int_t iSM = 0; // SuperModule index
262 Int_t iHW = 0;
ab962f7b 263 Int_t iAPDNum = 0;
264 Float_t v30 = 0;
265 Float_t par[3] = {0};
266 Float_t parErr[3] = {0};
267 Int_t iBreakDown = 0;
268 Float_t darkCurrent = 0;
61917ab3 269 //
270 Int_t iCol = 0;
271 Int_t iRow = 0;
272 // declare the branches
273 tree->Branch("iSM", &iSM, "iSM/I");
274 tree->Branch("iCol", &iCol, "iCol/I");
275 tree->Branch("iRow", &iRow, "iRow/I");
276 tree->Branch("iHW", &iHW, "iHW/I");
ab962f7b 277 tree->Branch("APDNum", &iAPDNum, "APDNum/I");
278 tree->Branch("V30", &v30, "V30/F");
279 tree->Branch("Par", &par, "Par[3]/F");
280 tree->Branch("ParErr", &parErr, "ParErr[3]/F");
281 tree->Branch("BreakDown", &iBreakDown, "BreakDown/I");
282 tree->Branch("DarkCurrent", &darkCurrent, "DarkCurrent/F");
61917ab3 283
284 Int_t nAPDPerSM = AliEMCALGeoParams::fgkEMCALCols * AliEMCALGeoParams::fgkEMCALRows;
285
286 for (iSM = 0; iSM < fNSuperModule; iSM++) {
2f17a269 287 AliEMCALSuperModuleCalibMapAPD * t = (AliEMCALSuperModuleCalibMapAPD *) fSuperModuleData[iSM];
61917ab3 288
289 for (Int_t j=0; j<nAPDPerSM; j++) {
290 iCol = j / AliEMCALGeoParams::fgkEMCALRows;
291 iRow = j % AliEMCALGeoParams::fgkEMCALRows;
292
2f17a269 293 AliEMCALCalibMapAPDVal * v = t->GetAPDVal(iCol, iRow);
61917ab3 294
295 if (swapSides) {
296 // C side, oriented differently than A side: swap is requested
297 iCol = AliEMCALGeoParams::fgkEMCALCols-1 - iCol;
298 iRow = AliEMCALGeoParams::fgkEMCALRows-1 - iRow;
299 }
300
2f17a269 301 iHW = v->GetHardWareId();
ab962f7b 302 iAPDNum = v->GetAPDNum();
303 v30 = v->GetV30();
61917ab3 304 for (int k=0; k<3; k++) {
ab962f7b 305 par[k] = v->GetPar(k);
306 parErr[k] = v->GetParErr(k);
61917ab3 307 }
ab962f7b 308 iBreakDown = v->GetBreakDown();
309 darkCurrent = v->GetDarkCurrent();
61917ab3 310
311 tree->Fill();
312 }
313
314 } // i, SuperModule
315
316 tree->Write();
317 destFile.Close();
318
319 return;
320}
321
d81e6423 322//____________________________________________________________________________
323AliEMCALCalibMapAPD::~AliEMCALCalibMapAPD()
324{
2f17a269 325 fSuperModuleData.Delete();
d81e6423 326}
327
328//____________________________________________________________________________
2f17a269 329AliEMCALSuperModuleCalibMapAPD * AliEMCALCalibMapAPD::GetSuperModuleCalibMapAPDNum(Int_t supModIndex)const
d81e6423 330{
d81e6423 331 for (int i=0; i<fNSuperModule; i++) {
2f17a269 332 AliEMCALSuperModuleCalibMapAPD * t = (AliEMCALSuperModuleCalibMapAPD*) fSuperModuleData[i];
333 if (t->GetSuperModuleNum() == supModIndex) {
334 return t;
d81e6423 335 }
336 }
337
2f17a269 338 // if we arrived here, then nothing was found.. just return a NULL pointer
339 return NULL;
d81e6423 340}
341