]>
Commit | Line | Data |
---|---|---|
a8827307 | 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 read txt file with APD number data | |
19 | // | |
20 | ||
21 | #include <fstream> | |
22 | #include <TString.h> | |
23 | ||
24 | #include "AliEMCALCalibAPD.h" | |
25 | ||
26 | const int kMaxLen = 1000; // maximum length of single line (# of characters) | |
27 | // an OK line with complete info should have a certain number of characters | |
28 | const int kMinLenAPDLine = 145; | |
29 | const int kMaxLenAPDLine = 170; | |
30 | ||
31 | ClassImp(AliEMCALCalibAPD) | |
32 | ||
33 | //____________________________________________________________________________ | |
34 | AliEMCALCalibAPD::AliEMCALCalibAPD() : | |
35 | fNCalibAPD(0), | |
36 | fData(0) | |
37 | { | |
38 | //Default constructor. | |
39 | } | |
40 | ||
41 | //____________________________________________________________________________ | |
42 | void AliEMCALCalibAPD::ReadCalibAPDInfo(Int_t nAPD, const TString &txtFileName) | |
43 | { | |
44 | //Read data from txt file. ; coordinates given on SuperModule basis | |
45 | ||
46 | std::ifstream inputFile(txtFileName.Data()); | |
47 | if (!inputFile) { | |
48 | printf("AliEMCALCalibAPD::ReadCalibAPDInfo - Cannot open the APD info file %s\n", txtFileName.Data()); | |
49 | return; | |
50 | } | |
51 | ||
52 | fNCalibAPD = nAPD; | |
53 | if (fData) delete [] fData; | |
54 | fData = new AliEMCALCalibAPDData[fNCalibAPD]; | |
55 | ||
56 | char line[kMaxLen]; | |
57 | ||
58 | // get header lines: | |
59 | inputFile.getline(line, kMaxLen); | |
60 | // printf(" 1st header line character count %d\n", inputFile.gcount()); | |
61 | inputFile.getline(line, kMaxLen); | |
62 | // printf(" 2nd header line character count %d\n", inputFile.gcount()); | |
63 | ||
64 | // variables for reading | |
65 | int i1,i2,i3,i4,i5; | |
66 | float f1,f2,f3,f4,f5,f6,f7,f8,f9,f10,f11,f12; | |
67 | char c1[10], c2[20]; | |
68 | ||
69 | int j = 0; // index for the ones that were read OK | |
70 | for (Int_t i = 0; i < fNCalibAPD; i++) { | |
71 | AliEMCALCalibAPDData &t = fData[j]; | |
72 | if (!inputFile) { | |
73 | printf("AliEMCALCalibAPD::ReadCalibAPDInfo - Error while reading input file.\n"); | |
74 | fNCalibAPD = j; // that's how many we actually read succesfully | |
75 | printf("AliEMCALCalibAPD::ReadCalibAPDInfo - read %d OK\n", fNCalibAPD); | |
76 | return; | |
77 | } | |
78 | ||
79 | // use some temporary/local values to perhaps help with the order when | |
80 | // trying to read all the many fields in a line.. | |
81 | inputFile.getline(line, kMaxLen); | |
82 | int nchar = inputFile.gcount(); | |
83 | // printf(" line %d ok %d - character count %d\n", i, j, nchar); | |
84 | ||
85 | if (nchar>kMinLenAPDLine && nchar<kMaxLenAPDLine) { | |
86 | // looks like the line has about the right number of characters, let's | |
87 | // try to decode it now.. | |
88 | ||
89 | // printf("input: %s\n",line); | |
90 | sscanf(line, "%d,%u,%8s,%9s,%d,%d,%f,%f,%f,%f,%f,%f,%f,%f,%f,%d,%f,%f,%f", | |
91 | &i1, &i2, c1, c2, &i3, &i4, // header-type info | |
92 | &f1, &f2, &f3, &f4, &f5, &f6, &f7, &f8, &f9, // measurements | |
93 | &i5, &f10, &f11, &f12); // Hamamatsu | |
94 | ||
95 | // printf("after scanf: %s\n",line); | |
96 | /* | |
97 | printf("%d,%u,%s,%s,%d,%d,%g,%g,%g,%g,%g,%g,%g,%g,%g,%d,%g,%13.11f,%g\n", | |
98 | i1, i2, c1, c2, i3, i4, // header-type info | |
99 | f1, f2, f3, f4, f5, f6, f7, f8, f9, // measurements | |
100 | i5, f10, f11, f12); // Hamamatsu | |
101 | */ | |
102 | // assign the variables: | |
103 | t.fAPDNum = i1; | |
104 | t.fSerialNum = i2; | |
105 | sprintf(t.fStatus,"%s",c1); | |
106 | sprintf(t.fLocation,"%s",c2); | |
107 | t.fRunNum = i3; | |
108 | t.fTestPos = i4; | |
109 | ||
110 | t.fV30 = f1; | |
111 | t.fV50 = f2; | |
112 | t.fVoltCoeff = f3; | |
113 | t.fPar[0] = f4; | |
114 | t.fPar[1] = f5; | |
115 | t.fPar[2] = f6; | |
116 | t.fParErr[0] = f7; | |
117 | t.fParErr[1] = f8; | |
118 | t.fParErr[2] = f9; | |
119 | ||
120 | t.fBreakDown = i5; | |
121 | t.fHamV50 = f10; | |
122 | t.fDarkCurrent = f11; | |
123 | t.fTestTemp = f12; | |
124 | ||
125 | j++; // increment our 'OK' counter.. | |
126 | } // line length appears OK | |
127 | } // i, APD | |
128 | ||
129 | inputFile.close(); | |
130 | ||
131 | return; | |
132 | } | |
133 | ||
134 | //____________________________________________________________________________ | |
135 | void AliEMCALCalibAPD::WriteCalibAPDInfo(const TString &txtFileName) | |
136 | { | |
137 | // write data to txt file. ; coordinates given on SuperModule basis | |
138 | ||
139 | std::ofstream outputFile(txtFileName.Data()); | |
140 | if (!outputFile) { | |
141 | printf("AliEMCALCalibAPD::WriteCalibAPDInfo - Cannot open the APD output file %s\n", txtFileName.Data()); | |
142 | return; | |
143 | } | |
144 | ||
145 | char *comma = ","; | |
146 | ||
147 | for (Int_t i = 0; i < fNCalibAPD; i++) { | |
148 | AliEMCALCalibAPDData &t = fData[i]; | |
149 | ||
150 | outputFile << t.fAPDNum << comma | |
151 | << t.fSerialNum << comma // Serial Number; from Hamamatsu | |
152 | << t.fStatus << comma // | |
153 | << t.fLocation << comma // | |
154 | << t.fRunNum << comma | |
155 | << t.fTestPos << comma | |
156 | << t.fV30 << comma // Catania/Houston Voltage V30 (V) at T = 25 deg C | |
157 | << t.fV50 << comma | |
158 | << t.fVoltCoeff << comma // 1/M x dM/dV | |
159 | << t.fPar[0] << comma // fit parameters, p0,p1,p2 - for ADC vs bias measurement | |
160 | << t.fPar[1] << comma | |
161 | << t.fPar[2] << comma | |
162 | << t.fParErr[0] << comma // error on fit parameters | |
163 | << t.fParErr[1] << comma | |
164 | << t.fParErr[2] << comma | |
165 | << t.fBreakDown << comma // Hamamatsu Breakdown Voltage (V) | |
166 | << t.fHamV50 << comma; // Hamamatsu Voltage V50 (V) | |
167 | // I wasn't able to quite reproduce the values as they appeared on the | |
168 | // original file: e.g. dark current is not always 11-field - if last digit is zero.. | |
169 | // the other floats have 6 significant digits, but sometimes switch to | |
170 | // scientific notation - don't know how to handle this for varying length of fields.. -leave it as is for now.. | |
171 | outputFile << t.fDarkCurrent << comma; // Hamamatsu Dark Current (A) | |
172 | /* | |
173 | // some tweaking for the dark-current field to get the output the same | |
174 | // as on the original CSV | |
175 | outputFile.precision(11); | |
176 | outputFile << fixed << t.fDarkCurrent << comma; // Hamamatsu Dark Current (A) | |
177 | // back to normal.. | |
178 | outputFile.precision(6); outputFile.unsetf(ios_base::floatfield); | |
179 | */ | |
180 | ||
181 | outputFile << t.fTestTemp // Hamamatsu Testing Temperature (deg C) | |
182 | << endl; | |
183 | ||
184 | } // i, APD | |
185 | ||
186 | outputFile.close(); | |
187 | ||
188 | return; | |
189 | } | |
190 | ||
191 | //____________________________________________________________________________ | |
192 | AliEMCALCalibAPD::~AliEMCALCalibAPD() | |
193 | { | |
194 | delete [] fData; | |
195 | } | |
196 | ||
197 | //____________________________________________________________________________ | |
198 | AliEMCALCalibAPD::AliEMCALCalibAPDData AliEMCALCalibAPD::GetCalibAPDDataId(Int_t apdIndex)const | |
199 | { | |
200 | AliEMCALCalibAPDData t; // just to maybe prevent a crash, but we are returning something not-initialized so maybe not better really.. | |
201 | if (!fData) | |
202 | return t; | |
203 | ||
204 | return fData[apdIndex]; | |
205 | } | |
206 | ||
207 | //____________________________________________________________________________ | |
208 | AliEMCALCalibAPD::AliEMCALCalibAPDData AliEMCALCalibAPD::GetCalibAPDDataNum(Int_t apdNum)const | |
209 | { | |
210 | AliEMCALCalibAPDData t; // just to maybe prevent a crash, but we are returning something not-initialized so maybe not better really.. | |
211 | if (!fData) | |
212 | return t; | |
213 | ||
214 | for (int i=0; i<fNCalibAPD; i++) { | |
215 | if (fData[i].fAPDNum == apdNum) { | |
216 | return fData[i]; | |
217 | } | |
218 | } | |
219 | ||
220 | // if we made it to here, then no match was found - just return then | |
221 | return t; | |
222 | } | |
223 | ||
224 |