]> git.uio.no Git - u/mrichter/AliRoot.git/blob - EMCAL/AliEMCALBiasAPD.cxx
changes in the MagF constructor
[u/mrichter/AliRoot.git] / EMCAL / AliEMCALBiasAPD.cxx
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>
23 #include <TFile.h>
24 #include <TTree.h>
25
26 #include "AliEMCALBiasAPD.h"
27
28 using namespace std;
29
30 ClassImp(AliEMCALBiasAPD)
31
32 //____________________________________________________________________________
33 AliEMCALBiasAPD::AliEMCALBiasAPD(const int nSM) : 
34   fNSuperModule(nSM), // make space for everyone 
35   fSuperModuleData()
36 {
37   //Default constructor.
38   for (int i=0; i<fNSuperModule; i++) {
39     fSuperModuleData.Add(new AliEMCALSuperModuleBiasAPD(i));
40   }
41   fSuperModuleData.Compress(); // compress the TObjArray
42 }
43
44 //____________________________________________________________________________
45 void AliEMCALBiasAPD::ReadTextBiasAPDInfo(Int_t nSM, const TString &txtFileName,
46                                           Bool_t swapSides)
47 {
48   //Read data from txt file. ; coordinates given on SuperModule basis
49
50   std::ifstream inputFile(txtFileName.Data());
51   if (!inputFile) {
52     printf("AliEMCALBiasAPD::ReadBiasAPDInfo - Cannot open the APD info file %s\n", txtFileName.Data());
53     return;
54   }
55
56   fNSuperModule = nSM;
57
58   Int_t iSM = 0; // SuperModule index
59   Int_t iCol = 0;
60   Int_t iRow = 0;
61   Int_t iElecId = 0;
62   Int_t iDAC = 0;
63   Float_t voltage = 0;
64
65   Int_t nAPDPerSM = AliEMCALGeoParams::fgkEMCALCols * AliEMCALGeoParams::fgkEMCALRows;
66
67   for (Int_t i = 0; i < fNSuperModule; i++) {
68     AliEMCALSuperModuleBiasAPD * t = (AliEMCALSuperModuleBiasAPD*) fSuperModuleData[i];
69
70     if (!inputFile) {
71       printf("AliEMCALBiasAPD::ReadBiasAPDInfo - Error while reading input file; likely EOF..");
72       return;
73     }
74     inputFile >> iSM;
75     t->SetSuperModuleNum(iSM);
76
77     for (Int_t j=0; j<nAPDPerSM; j++) {
78       inputFile >> iCol >> iRow >> iElecId >> iDAC >> voltage;
79
80       // assume that this info is already swapped and done for this basis?
81       if (swapSides) {
82         // C side, oriented differently than A side: swap is requested
83         iCol = AliEMCALGeoParams::fgkEMCALCols-1 - iCol;
84         iRow = AliEMCALGeoParams::fgkEMCALRows-1 - iRow;
85       }
86
87       t->SetElecId(iCol, iRow, iElecId);
88       t->SetDAC(iCol, iRow, iDAC);
89       t->SetVoltage(iCol, iRow, voltage);
90     }
91
92   } // i, SuperModule
93
94   inputFile.close();
95
96   return;
97 }
98
99 //____________________________________________________________________________
100 void AliEMCALBiasAPD::WriteTextBiasAPDInfo(const TString &txtFileName,
101                                            Bool_t swapSides)
102 {
103   // write data to txt file. ; coordinates given on SuperModule basis
104
105   std::ofstream outputFile(txtFileName.Data());
106   if (!outputFile) {
107     printf("AliEMCALBiasAPD::WriteBiasAPDInfo - Cannot open the APD output file %s\n", txtFileName.Data());
108     return;
109   }
110
111   Int_t iCol = 0;
112   Int_t iRow = 0;
113   Int_t iElecId = 0;
114   Int_t iDAC = 0;
115   Float_t voltage = 0;
116
117   Int_t nAPDPerSM = AliEMCALGeoParams::fgkEMCALCols * AliEMCALGeoParams::fgkEMCALRows;
118
119   for (Int_t i = 0; i < fNSuperModule; i++) {
120     AliEMCALSuperModuleBiasAPD * t = (AliEMCALSuperModuleBiasAPD*) fSuperModuleData[i];
121     outputFile << t->GetSuperModuleNum() << endl;
122
123     for (Int_t j=0; j<nAPDPerSM; j++) {
124       iCol = j / AliEMCALGeoParams::fgkEMCALRows;
125       iRow = j % AliEMCALGeoParams::fgkEMCALRows;
126
127       iElecId = t->GetElecId(iCol, iRow);
128       iDAC = t->GetDAC(iCol, iRow);
129       voltage = t->GetVoltage(iCol, iRow);
130
131       if (swapSides) {
132         // C side, oriented differently than A side: swap is requested
133         iCol = AliEMCALGeoParams::fgkEMCALCols-1 - iCol;
134         iRow = AliEMCALGeoParams::fgkEMCALRows-1 - iRow;
135       }
136
137       outputFile << iCol << " " << iRow << " " 
138                  << iElecId << " " << iDAC << " "
139                  << voltage << endl;
140     }
141
142   } // i, SuperModule
143
144   outputFile.close();
145
146   return;
147 }
148
149 //____________________________________________________________________________
150 void AliEMCALBiasAPD::ReadRootBiasAPDInfo(const TString &rootFileName,
151                                           Bool_t swapSides)
152 {
153   //Read data from root file. ; coordinates given on SuperModule basis
154   TFile inputFile(rootFileName, "read");  
155
156   TTree *tree = (TTree*) inputFile.Get("tree");
157
158   ReadTreeBiasAPDInfo(tree, swapSides);
159
160   inputFile.Close();
161
162   return;
163 }
164
165 //____________________________________________________________________________
166 void AliEMCALBiasAPD::ReadTreeBiasAPDInfo(TTree *tree,
167                                           Bool_t swapSides)
168 {
169  // how many SuperModule's worth of entries / APDs do we have?
170   Int_t nAPDPerSM = AliEMCALGeoParams::fgkEMCALCols * AliEMCALGeoParams::fgkEMCALRows;
171   fNSuperModule = tree->GetEntries() / nAPDPerSM;
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 = (AliEMCALSuperModuleBiasAPD*) fSuperModuleData[iSM];
195     t->SetSuperModuleNum(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->SetElecId(iCol, iRow, iElecId);
205     t->SetDAC(iCol, iRow, iDAC);
206     t->SetVoltage(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 = (AliEMCALSuperModuleBiasAPD*) 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->GetElecId(iCol, iRow);
251       iDAC = t->GetDAC(iCol, iRow);
252       voltage = t->GetVoltage(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 //____________________________________________________________________________
272 AliEMCALBiasAPD::~AliEMCALBiasAPD()
273 {
274   fSuperModuleData.Delete();
275 }
276
277 //____________________________________________________________________________
278 AliEMCALSuperModuleBiasAPD * AliEMCALBiasAPD::GetSuperModuleBiasAPDNum(Int_t supModIndex)const
279 {
280   for (int i=0; i<fNSuperModule; i++) {
281     AliEMCALSuperModuleBiasAPD * t = (AliEMCALSuperModuleBiasAPD*) fSuperModuleData[i];
282     if (t->GetSuperModuleNum() == supModIndex) {
283       return t;
284     }
285   }
286
287   // if we arrived here, then nothing was found.. just return a NULL pointer 
288   return NULL;
289 }
290