first version of new classes for time-dependent corrections; not yet used in Preproce...
[u/mrichter/AliRoot.git] / EMCAL / AliEMCALBiasAPD.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 bias settings/voltages
19//
20
21#include <fstream>
22#include <TString.h>
23
24#include "AliEMCALBiasAPD.h"
25
26using namespace std;
27
28ClassImp(AliEMCALBiasAPD)
29
30//____________________________________________________________________________
31AliEMCALBiasAPD::AliEMCALBiasAPD() :
32 fNSuperModule(0),
33 fSuperModuleData(0)
34{
35 //Default constructor.
36}
37
38//____________________________________________________________________________
39void AliEMCALBiasAPD::ReadBiasAPDInfo(Int_t nSM, const TString &txtFileName,
40 Bool_t swapSides)
41{
42 //Read data from txt file. ; coordinates given on SuperModule basis
43
44 std::ifstream inputFile(txtFileName.Data());
45 if (!inputFile) {
46 printf("AliEMCALBiasAPD::ReadBiasAPDInfo - Cannot open the APD info file %s\n", txtFileName.Data());
47 return;
48 }
49
50 fNSuperModule = nSM;
51 if (fSuperModuleData) delete [] fSuperModuleData;
52 fSuperModuleData = new AliEMCALSuperModuleBiasAPD[fNSuperModule];
53
54 Int_t iSM = 0; // SuperModule index
55 Int_t iCol = 0;
56 Int_t iRow = 0;
57 Int_t iElecId = 0;
58 Int_t iDAC = 0;
59 Float_t voltage = 0;
60
61 Int_t nAPDPerSM = AliEMCALGeoParams::fgkEMCALCols * AliEMCALGeoParams::fgkEMCALRows;
62
63 for (Int_t i = 0; i < fNSuperModule; i++) {
64 AliEMCALSuperModuleBiasAPD &t = fSuperModuleData[i];
65 if (!inputFile) {
66 printf("AliEMCALBiasAPD::ReadBiasAPDInfo - Error while reading input file; likely EOF..");
67 return;
68 }
69 inputFile >> iSM;
70 t.fSuperModuleNum = iSM;
71
72 for (Int_t j=0; j<nAPDPerSM; j++) {
73 inputFile >> iCol >> iRow >> iElecId >> iDAC >> voltage;
74
75 // assume that this info is already swapped and done for this basis?
76 if (swapSides) {
77 // C side, oriented differently than A side: swap is requested
78 iCol = AliEMCALGeoParams::fgkEMCALCols-1 - iCol;
79 iRow = AliEMCALGeoParams::fgkEMCALRows-1 - iRow;
80 }
81
82 t.fElecId[iCol][iRow] = iElecId;
83 t.fDAC[iCol][iRow] = iDAC;
84 t.fVoltage[iCol][iRow] = voltage;
85 }
86
87 } // i, SuperModule
88
89 inputFile.close();
90
91 return;
92}
93
94//____________________________________________________________________________
95void AliEMCALBiasAPD::WriteBiasAPDInfo(const TString &txtFileName,
96 Bool_t swapSides)
97{
98 // write data to txt file. ; coordinates given on SuperModule basis
99
100 std::ofstream outputFile(txtFileName.Data());
101 if (!outputFile) {
102 printf("AliEMCALBiasAPD::WriteBiasAPDInfo - Cannot open the APD output file %s\n", txtFileName.Data());
103 return;
104 }
105
106 Int_t iCol = 0;
107 Int_t iRow = 0;
108 Int_t iElecId = 0;
109 Int_t iDAC = 0;
110 Float_t voltage = 0;
111
112 Int_t nAPDPerSM = AliEMCALGeoParams::fgkEMCALCols * AliEMCALGeoParams::fgkEMCALRows;
113
114 for (Int_t i = 0; i < fNSuperModule; i++) {
115 AliEMCALSuperModuleBiasAPD &t = fSuperModuleData[i];
116 outputFile << t.fSuperModuleNum << endl;
117
118 for (Int_t j=0; j<nAPDPerSM; j++) {
119 iCol = j / AliEMCALGeoParams::fgkEMCALRows;
120 iRow = j % AliEMCALGeoParams::fgkEMCALRows;
121
122 iElecId = t.fElecId[iCol][iRow];
123 iDAC = t.fDAC[iCol][iRow];
124 voltage = t.fVoltage[iCol][iRow];
125
126 if (swapSides) {
127 // C side, oriented differently than A side: swap is requested
128 iCol = AliEMCALGeoParams::fgkEMCALCols-1 - iCol;
129 iRow = AliEMCALGeoParams::fgkEMCALRows-1 - iRow;
130 }
131
132 outputFile << iCol << " " << iRow << " "
133 << iElecId << " " << iDAC << " "
134 << voltage << endl;
135 }
136
137 } // i, SuperModule
138
139 outputFile.close();
140
141 return;
142}
143
144//____________________________________________________________________________
145AliEMCALBiasAPD::~AliEMCALBiasAPD()
146{
147 delete [] fSuperModuleData;
148}
149
150//____________________________________________________________________________
151AliEMCALBiasAPD::AliEMCALSuperModuleBiasAPD AliEMCALBiasAPD::GetSuperModuleBiasAPDId(Int_t supModIndex)const
152{
153 AliEMCALSuperModuleBiasAPD t; // just to maybe prevent a crash, but we are returning something not-initialized so maybe not better really..
154 if (!fSuperModuleData)
155 return t;
156
157 return fSuperModuleData[supModIndex];
158}
159
160//____________________________________________________________________________
161AliEMCALBiasAPD::AliEMCALSuperModuleBiasAPD AliEMCALBiasAPD::GetSuperModuleBiasAPDNum(Int_t supModIndex)const
162{
163 AliEMCALSuperModuleBiasAPD t; // just to maybe prevent a crash, but we are returning something not-initialized so maybe not better really..
164 if (!fSuperModuleData)
165 return t;
166
167 for (int i=0; i<fNSuperModule; i++) {
168 if (fSuperModuleData[i].fSuperModuleNum == supModIndex) {
169 return fSuperModuleData[i];
170 }
171 }
172
173 return t;
174}
175