1 /**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
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 **************************************************************************/
18 // Objects of this class contain info on APD bias settings/voltages
26 #include "AliEMCALBiasAPD.h"
30 ClassImp(AliEMCALBiasAPD)
32 //____________________________________________________________________________
33 AliEMCALBiasAPD::AliEMCALBiasAPD() :
37 //Default constructor.
40 //____________________________________________________________________________
41 void AliEMCALBiasAPD::ReadTextBiasAPDInfo(Int_t nSM, const TString &txtFileName,
44 //Read data from txt file. ; coordinates given on SuperModule basis
46 std::ifstream inputFile(txtFileName.Data());
48 printf("AliEMCALBiasAPD::ReadBiasAPDInfo - Cannot open the APD info file %s\n", txtFileName.Data());
53 if (fSuperModuleData) delete [] fSuperModuleData;
54 fSuperModuleData = new AliEMCALSuperModuleBiasAPD[fNSuperModule];
56 Int_t iSM = 0; // SuperModule index
63 Int_t nAPDPerSM = AliEMCALGeoParams::fgkEMCALCols * AliEMCALGeoParams::fgkEMCALRows;
65 for (Int_t i = 0; i < fNSuperModule; i++) {
66 AliEMCALSuperModuleBiasAPD &t = fSuperModuleData[i];
68 printf("AliEMCALBiasAPD::ReadBiasAPDInfo - Error while reading input file; likely EOF..");
72 t.fSuperModuleNum = iSM;
74 for (Int_t j=0; j<nAPDPerSM; j++) {
75 inputFile >> iCol >> iRow >> iElecId >> iDAC >> voltage;
77 // assume that this info is already swapped and done for this basis?
79 // C side, oriented differently than A side: swap is requested
80 iCol = AliEMCALGeoParams::fgkEMCALCols-1 - iCol;
81 iRow = AliEMCALGeoParams::fgkEMCALRows-1 - iRow;
84 t.fElecId[iCol][iRow] = iElecId;
85 t.fDAC[iCol][iRow] = iDAC;
86 t.fVoltage[iCol][iRow] = voltage;
96 //____________________________________________________________________________
97 void AliEMCALBiasAPD::WriteTextBiasAPDInfo(const TString &txtFileName,
100 // write data to txt file. ; coordinates given on SuperModule basis
102 std::ofstream outputFile(txtFileName.Data());
104 printf("AliEMCALBiasAPD::WriteBiasAPDInfo - Cannot open the APD output file %s\n", txtFileName.Data());
114 Int_t nAPDPerSM = AliEMCALGeoParams::fgkEMCALCols * AliEMCALGeoParams::fgkEMCALRows;
116 for (Int_t i = 0; i < fNSuperModule; i++) {
117 AliEMCALSuperModuleBiasAPD &t = fSuperModuleData[i];
118 outputFile << t.fSuperModuleNum << endl;
120 for (Int_t j=0; j<nAPDPerSM; j++) {
121 iCol = j / AliEMCALGeoParams::fgkEMCALRows;
122 iRow = j % AliEMCALGeoParams::fgkEMCALRows;
124 iElecId = t.fElecId[iCol][iRow];
125 iDAC = t.fDAC[iCol][iRow];
126 voltage = t.fVoltage[iCol][iRow];
129 // C side, oriented differently than A side: swap is requested
130 iCol = AliEMCALGeoParams::fgkEMCALCols-1 - iCol;
131 iRow = AliEMCALGeoParams::fgkEMCALRows-1 - iRow;
134 outputFile << iCol << " " << iRow << " "
135 << iElecId << " " << iDAC << " "
146 //____________________________________________________________________________
147 void AliEMCALBiasAPD::ReadRootBiasAPDInfo(const TString &rootFileName,
150 //Read data from root file. ; coordinates given on SuperModule basis
151 TFile inputFile(rootFileName, "read");
153 TTree *tree = (TTree*) inputFile.Get("tree");
155 ReadTreeBiasAPDInfo(tree, swapSides);
162 //____________________________________________________________________________
163 void AliEMCALBiasAPD::ReadTreeBiasAPDInfo(TTree *tree,
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;
170 if (fSuperModuleData) delete [] fSuperModuleData;
171 fSuperModuleData = new AliEMCALSuperModuleBiasAPD[fNSuperModule];
173 Int_t iSM = 0; // SuperModule index
176 // list of values to be read
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);
190 for (int ient=0; ient<tree->GetEntries(); ient++) {
191 tree->GetEntry(ient);
193 // assume the index SuperModules come in order: i=iSM
194 AliEMCALSuperModuleBiasAPD &t = fSuperModuleData[iSM];
195 t.fSuperModuleNum = iSM;
197 // assume that this info is already swapped and done for this basis?
199 // C side, oriented differently than A side: swap is requested
200 iCol = AliEMCALGeoParams::fgkEMCALCols-1 - iCol;
201 iRow = AliEMCALGeoParams::fgkEMCALRows-1 - iRow;
204 t.fElecId[iCol][iRow] = iElecId;
205 t.fDAC[iCol][iRow] = iDAC;
206 t.fVoltage[iCol][iRow] = voltage;
213 //____________________________________________________________________________
214 void AliEMCALBiasAPD::WriteRootBiasAPDInfo(const TString &rootFileName,
217 // write data to root file. ; coordinates given on SuperModule basis
218 TFile destFile(rootFileName, "recreate");
219 if (destFile.IsZombie()) {
224 TTree *tree = new TTree("tree","");
226 // variables for filling the TTree
227 Int_t iSM = 0; // SuperModule index
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");
241 Int_t nAPDPerSM = AliEMCALGeoParams::fgkEMCALCols * AliEMCALGeoParams::fgkEMCALRows;
243 for (iSM = 0; iSM < fNSuperModule; iSM++) {
244 AliEMCALSuperModuleBiasAPD &t = fSuperModuleData[iSM];
246 for (Int_t j=0; j<nAPDPerSM; j++) {
247 iCol = j / AliEMCALGeoParams::fgkEMCALRows;
248 iRow = j % AliEMCALGeoParams::fgkEMCALRows;
250 iElecId = t.fElecId[iCol][iRow];
251 iDAC = t.fDAC[iCol][iRow];
252 voltage = t.fVoltage[iCol][iRow];
255 // C side, oriented differently than A side: swap is requested
256 iCol = AliEMCALGeoParams::fgkEMCALCols-1 - iCol;
257 iRow = AliEMCALGeoParams::fgkEMCALRows-1 - iRow;
271 //____________________________________________________________________________
272 AliEMCALBiasAPD::~AliEMCALBiasAPD()
274 delete [] fSuperModuleData;
277 //____________________________________________________________________________
278 AliEMCALSuperModuleBiasAPD AliEMCALBiasAPD::GetSuperModuleBiasAPDId(Int_t supModIndex)const
280 AliEMCALSuperModuleBiasAPD t; // just to maybe prevent a crash, but we are returning something not-initialized so maybe not better really..
281 if (!fSuperModuleData)
284 return fSuperModuleData[supModIndex];
287 //____________________________________________________________________________
288 AliEMCALSuperModuleBiasAPD AliEMCALBiasAPD::GetSuperModuleBiasAPDNum(Int_t supModIndex)const
290 AliEMCALSuperModuleBiasAPD t; // just to maybe prevent a crash, but we are returning something not-initialized so maybe not better really..
291 if (!fSuperModuleData)
294 for (int i=0; i<fNSuperModule; i++) {
295 if (fSuperModuleData[i].fSuperModuleNum == supModIndex) {
296 return fSuperModuleData[i];