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 bias settings/voltages |
19 | // |
20 | |
21 | #include <fstream> |
22 | #include <TString.h> |
61917ab3 |
23 | #include <TFile.h> |
24 | #include <TTree.h> |
d81e6423 |
25 | |
26 | #include "AliEMCALBiasAPD.h" |
27 | |
28 | using namespace std; |
29 | |
30 | ClassImp(AliEMCALBiasAPD) |
31 | |
32 | //____________________________________________________________________________ |
33 | AliEMCALBiasAPD::AliEMCALBiasAPD() : |
34 | fNSuperModule(0), |
35 | fSuperModuleData(0) |
36 | { |
37 | //Default constructor. |
38 | } |
39 | |
40 | //____________________________________________________________________________ |
61917ab3 |
41 | void AliEMCALBiasAPD::ReadTextBiasAPDInfo(Int_t nSM, const TString &txtFileName, |
42 | Bool_t swapSides) |
d81e6423 |
43 | { |
44 | //Read data from txt file. ; coordinates given on SuperModule basis |
45 | |
46 | std::ifstream inputFile(txtFileName.Data()); |
47 | if (!inputFile) { |
48 | printf("AliEMCALBiasAPD::ReadBiasAPDInfo - Cannot open the APD info file %s\n", txtFileName.Data()); |
49 | return; |
50 | } |
51 | |
52 | fNSuperModule = nSM; |
53 | if (fSuperModuleData) delete [] fSuperModuleData; |
54 | fSuperModuleData = new AliEMCALSuperModuleBiasAPD[fNSuperModule]; |
55 | |
56 | Int_t iSM = 0; // SuperModule index |
57 | Int_t iCol = 0; |
58 | Int_t iRow = 0; |
59 | Int_t iElecId = 0; |
60 | Int_t iDAC = 0; |
61 | Float_t voltage = 0; |
62 | |
63 | Int_t nAPDPerSM = AliEMCALGeoParams::fgkEMCALCols * AliEMCALGeoParams::fgkEMCALRows; |
64 | |
65 | for (Int_t i = 0; i < fNSuperModule; i++) { |
66 | AliEMCALSuperModuleBiasAPD &t = fSuperModuleData[i]; |
67 | if (!inputFile) { |
68 | printf("AliEMCALBiasAPD::ReadBiasAPDInfo - Error while reading input file; likely EOF.."); |
69 | return; |
70 | } |
71 | inputFile >> iSM; |
72 | t.fSuperModuleNum = iSM; |
73 | |
74 | for (Int_t j=0; j<nAPDPerSM; j++) { |
75 | inputFile >> iCol >> iRow >> iElecId >> iDAC >> voltage; |
76 | |
77 | // assume that this info is already swapped and done for this basis? |
78 | if (swapSides) { |
79 | // C side, oriented differently than A side: swap is requested |
80 | iCol = AliEMCALGeoParams::fgkEMCALCols-1 - iCol; |
81 | iRow = AliEMCALGeoParams::fgkEMCALRows-1 - iRow; |
82 | } |
83 | |
84 | t.fElecId[iCol][iRow] = iElecId; |
85 | t.fDAC[iCol][iRow] = iDAC; |
86 | t.fVoltage[iCol][iRow] = voltage; |
87 | } |
88 | |
89 | } // i, SuperModule |
90 | |
91 | inputFile.close(); |
92 | |
93 | return; |
94 | } |
95 | |
96 | //____________________________________________________________________________ |
61917ab3 |
97 | void AliEMCALBiasAPD::WriteTextBiasAPDInfo(const TString &txtFileName, |
98 | Bool_t swapSides) |
d81e6423 |
99 | { |
100 | // write data to txt file. ; coordinates given on SuperModule basis |
101 | |
102 | std::ofstream outputFile(txtFileName.Data()); |
103 | if (!outputFile) { |
104 | printf("AliEMCALBiasAPD::WriteBiasAPDInfo - Cannot open the APD output file %s\n", txtFileName.Data()); |
105 | return; |
106 | } |
107 | |
108 | Int_t iCol = 0; |
109 | Int_t iRow = 0; |
110 | Int_t iElecId = 0; |
111 | Int_t iDAC = 0; |
112 | Float_t voltage = 0; |
113 | |
114 | Int_t nAPDPerSM = AliEMCALGeoParams::fgkEMCALCols * AliEMCALGeoParams::fgkEMCALRows; |
115 | |
116 | for (Int_t i = 0; i < fNSuperModule; i++) { |
117 | AliEMCALSuperModuleBiasAPD &t = fSuperModuleData[i]; |
118 | outputFile << t.fSuperModuleNum << endl; |
119 | |
120 | for (Int_t j=0; j<nAPDPerSM; j++) { |
121 | iCol = j / AliEMCALGeoParams::fgkEMCALRows; |
122 | iRow = j % AliEMCALGeoParams::fgkEMCALRows; |
123 | |
124 | iElecId = t.fElecId[iCol][iRow]; |
125 | iDAC = t.fDAC[iCol][iRow]; |
126 | voltage = t.fVoltage[iCol][iRow]; |
127 | |
128 | if (swapSides) { |
129 | // C side, oriented differently than A side: swap is requested |
130 | iCol = AliEMCALGeoParams::fgkEMCALCols-1 - iCol; |
131 | iRow = AliEMCALGeoParams::fgkEMCALRows-1 - iRow; |
132 | } |
133 | |
134 | outputFile << iCol << " " << iRow << " " |
135 | << iElecId << " " << iDAC << " " |
136 | << voltage << endl; |
137 | } |
138 | |
139 | } // i, SuperModule |
140 | |
141 | outputFile.close(); |
142 | |
143 | return; |
144 | } |
145 | |
146 | //____________________________________________________________________________ |
61917ab3 |
147 | void AliEMCALBiasAPD::ReadRootBiasAPDInfo(const TString &rootFileName, |
148 | Bool_t swapSides) |
149 | { |
150 | //Read data from root file. ; coordinates given on SuperModule basis |
151 | TFile inputFile(rootFileName, "read"); |
152 | |
153 | TTree *tree = (TTree*) inputFile.Get("tree"); |
154 | |
155 | ReadTreeBiasAPDInfo(tree, swapSides); |
156 | |
157 | inputFile.Close(); |
158 | |
159 | return; |
160 | } |
161 | |
162 | //____________________________________________________________________________ |
163 | void AliEMCALBiasAPD::ReadTreeBiasAPDInfo(TTree *tree, |
164 | Bool_t swapSides) |
165 | { |
166 | // how many SuperModule's worth of entries / APDs do we have? |
167 | Int_t nAPDPerSM = AliEMCALGeoParams::fgkEMCALCols * AliEMCALGeoParams::fgkEMCALRows; |
168 | fNSuperModule = tree->GetEntries() / nAPDPerSM; |
169 | |
170 | if (fSuperModuleData) delete [] fSuperModuleData; |
171 | fSuperModuleData = new AliEMCALSuperModuleBiasAPD[fNSuperModule]; |
172 | |
173 | Int_t iSM = 0; // SuperModule index |
174 | Int_t iCol = 0; |
175 | Int_t iRow = 0; |
176 | // list of values to be read |
177 | Int_t iElecId = 0; |
178 | Int_t iDAC = 0; |
179 | Float_t voltage = 0; |
180 | // end - all values |
181 | |
182 | // declare the branches |
183 | tree->SetBranchAddress("iSM", &iSM); |
184 | tree->SetBranchAddress("iCol", &iCol); |
185 | tree->SetBranchAddress("iRow", &iRow); |
186 | tree->SetBranchAddress("iElecId", &iElecId); |
187 | tree->SetBranchAddress("iDAC", &iDAC); |
188 | tree->SetBranchAddress("voltage", &voltage); |
189 | |
190 | for (int ient=0; ient<tree->GetEntries(); ient++) { |
191 | tree->GetEntry(ient); |
192 | |
193 | // assume the index SuperModules come in order: i=iSM |
194 | AliEMCALSuperModuleBiasAPD &t = fSuperModuleData[iSM]; |
195 | t.fSuperModuleNum = iSM; |
196 | |
197 | // assume that this info is already swapped and done for this basis? |
198 | if (swapSides) { |
199 | // C side, oriented differently than A side: swap is requested |
200 | iCol = AliEMCALGeoParams::fgkEMCALCols-1 - iCol; |
201 | iRow = AliEMCALGeoParams::fgkEMCALRows-1 - iRow; |
202 | } |
203 | |
204 | t.fElecId[iCol][iRow] = iElecId; |
205 | t.fDAC[iCol][iRow] = iDAC; |
206 | t.fVoltage[iCol][iRow] = voltage; |
207 | |
208 | } // |
209 | |
210 | return; |
211 | } |
212 | |
213 | //____________________________________________________________________________ |
214 | void AliEMCALBiasAPD::WriteRootBiasAPDInfo(const TString &rootFileName, |
215 | Bool_t swapSides) |
216 | { |
217 | // write data to root file. ; coordinates given on SuperModule basis |
218 | TFile destFile(rootFileName, "recreate"); |
219 | if (destFile.IsZombie()) { |
220 | return; |
221 | } |
222 | destFile.cd(); |
223 | |
224 | TTree *tree = new TTree("tree",""); |
225 | |
226 | // variables for filling the TTree |
227 | Int_t iSM = 0; // SuperModule index |
228 | Int_t iCol = 0; |
229 | Int_t iRow = 0; |
230 | Int_t iElecId = 0; |
231 | Int_t iDAC = 0; |
232 | Float_t voltage = 0; |
233 | // declare the branches |
234 | tree->Branch("iSM", &iSM, "iSM/I"); |
235 | tree->Branch("iCol", &iCol, "iCol/I"); |
236 | tree->Branch("iRow", &iRow, "iRow/I"); |
237 | tree->Branch("iElecId", &iElecId, "iElecId/I"); |
238 | tree->Branch("iDAC", &iDAC, "iDAC/I"); |
239 | tree->Branch("voltage", &voltage, "voltage/F"); |
240 | |
241 | Int_t nAPDPerSM = AliEMCALGeoParams::fgkEMCALCols * AliEMCALGeoParams::fgkEMCALRows; |
242 | |
243 | for (iSM = 0; iSM < fNSuperModule; iSM++) { |
244 | AliEMCALSuperModuleBiasAPD &t = fSuperModuleData[iSM]; |
245 | |
246 | for (Int_t j=0; j<nAPDPerSM; j++) { |
247 | iCol = j / AliEMCALGeoParams::fgkEMCALRows; |
248 | iRow = j % AliEMCALGeoParams::fgkEMCALRows; |
249 | |
250 | iElecId = t.fElecId[iCol][iRow]; |
251 | iDAC = t.fDAC[iCol][iRow]; |
252 | voltage = t.fVoltage[iCol][iRow]; |
253 | |
254 | if (swapSides) { |
255 | // C side, oriented differently than A side: swap is requested |
256 | iCol = AliEMCALGeoParams::fgkEMCALCols-1 - iCol; |
257 | iRow = AliEMCALGeoParams::fgkEMCALRows-1 - iRow; |
258 | } |
259 | |
260 | tree->Fill(); |
261 | } |
262 | |
263 | } // i, SuperModule |
264 | |
265 | tree->Write(); |
266 | destFile.Close(); |
267 | |
268 | return; |
269 | } |
270 | |
271 | //____________________________________________________________________________ |
d81e6423 |
272 | AliEMCALBiasAPD::~AliEMCALBiasAPD() |
273 | { |
274 | delete [] fSuperModuleData; |
275 | } |
276 | |
277 | //____________________________________________________________________________ |
61917ab3 |
278 | AliEMCALSuperModuleBiasAPD AliEMCALBiasAPD::GetSuperModuleBiasAPDId(Int_t supModIndex)const |
d81e6423 |
279 | { |
280 | AliEMCALSuperModuleBiasAPD t; // just to maybe prevent a crash, but we are returning something not-initialized so maybe not better really.. |
281 | if (!fSuperModuleData) |
282 | return t; |
283 | |
284 | return fSuperModuleData[supModIndex]; |
285 | } |
286 | |
287 | //____________________________________________________________________________ |
61917ab3 |
288 | AliEMCALSuperModuleBiasAPD AliEMCALBiasAPD::GetSuperModuleBiasAPDNum(Int_t supModIndex)const |
d81e6423 |
289 | { |
290 | AliEMCALSuperModuleBiasAPD t; // just to maybe prevent a crash, but we are returning something not-initialized so maybe not better really.. |
291 | if (!fSuperModuleData) |
292 | return t; |
293 | |
294 | for (int i=0; i<fNSuperModule; i++) { |
295 | if (fSuperModuleData[i].fSuperModuleNum == supModIndex) { |
296 | return fSuperModuleData[i]; |
297 | } |
298 | } |
299 | |
300 | return t; |
301 | } |
302 | |