]>
Commit | Line | Data |
---|---|---|
f6449cc0 | 1 | /************************************************************************** |
2 | * Copyright(c) 2004, 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 | /* $Id$ */ | |
16 | /** @file AliFMDPreprocessor.cxx | |
17 | @author Hans Hjersing Dalsgaard <canute@nbi.dk> | |
18 | @date Mon Mar 27 12:39:09 2006 | |
19 | @brief Shuttle "preprocessor" for the FMD | |
20 | */ | |
21 | //___________________________________________________________________ | |
22 | // | |
23 | // The class processes data points from DCS (via Amanada), and DAQ DA | |
24 | // files (via FXS) to make calibration data for the FMD. | |
25 | // | |
26 | // Data points: | |
27 | // * Nothing yet. | |
28 | // | |
29 | // DAQ FXS file: | |
30 | // * pedestals - a (ASCII) Comma Separated Values files with the | |
31 | // fields | |
32 | // rcu DDL number | |
33 | // board FEC board number | |
34 | // chip ALTRO chip number on FEC | |
35 | // channel ALTRO channel number | |
36 | // strip VA1 strip number | |
37 | // sample Sample number | |
38 | // ped Mean of ADC spectra | |
39 | // noise Spread of ADC spectra | |
40 | // mu Mean of Gaussian fit to ADC spectra | |
41 | // sigma Variance of Gaussian fit to ADC spectra | |
42 | // chi2 Chi^2 per degrees of freedom of fit | |
43 | // * Gains - a (ASCII) Comma Separated Values files with the | |
44 | // fields | |
45 | // rcu DDL number | |
46 | // board FEC board number | |
47 | // chip ALTRO chip number on FEC | |
48 | // channel ALTRO channel number | |
49 | // strip VA1 strip number | |
50 | // gain Slope of gain | |
51 | // error Error on gain | |
52 | // chi2 Chi^2 per degrees of freedom of fit | |
53 | // | |
54 | // Latest changes by Christian Holm Christensen | |
55 | // | |
56 | ||
57 | // #include <iostream> | |
58 | ||
59 | #include <fstream> | |
60 | #include "AliFMDPreprocessor.h" | |
61 | #include "AliFMDCalibPedestal.h" | |
62 | #include "AliFMDCalibGain.h" | |
63 | #include "AliFMDParameters.h" | |
64 | #include "AliCDBMetaData.h" | |
65 | #include "AliCDBManager.h" | |
66 | // #include "AliDCSValue.h" | |
67 | #include "AliLog.h" | |
68 | #include <TTimeStamp.h> | |
69 | // #include <TFile.h> | |
70 | #include <TObjString.h> | |
71 | #include <TString.h> | |
72 | #include <TNamed.h> | |
73 | ||
74 | ||
75 | ClassImp(AliFMDPreprocessor) | |
76 | #if 0 // Do not remove - here to make Emacs happy | |
77 | ; | |
78 | #endif | |
79 | ||
80 | //____________________________________________________ | |
81 | UInt_t AliFMDPreprocessor::Process(TMap* /* dcsAliasMap */) | |
82 | { | |
83 | // Main member function. | |
84 | // Parameters: | |
85 | // dcsAliassMap Map of DCS data point aliases. | |
86 | // Return | |
87 | // ? | |
88 | ||
89 | // Do we need this ? | |
90 | // if(!dcsAliasMap) return 1; | |
91 | // | |
92 | // Invoking the cdb manager and the FMD parameters class | |
93 | // AliCDBManager* cdb = AliCDBManager::Instance(); | |
94 | // cdb->SetDefaultStorage("local://$ALICE_ROOT"); | |
95 | // cdb->SetRun(0); | |
96 | AliFMDParameters* pars = AliFMDParameters::Instance(); | |
97 | pars->Init(false, AliFMDParameters::kAltroMap); | |
98 | ||
99 | //Creating calibration objects | |
100 | TList* pedFiles = GetFileSources(kDAQ,"pedestal"); | |
101 | TList* gainFiles = GetFileSources(kDAQ, "gain"); | |
102 | AliFMDCalibPedestal* calibPed = GetPedestalCalibration(pedFiles); | |
103 | AliFMDCalibGain* calibGain = GetGainCalibration(gainFiles); | |
104 | ||
105 | ||
106 | //Storing Calibration objects | |
107 | AliCDBMetaData metaData; | |
108 | metaData.SetBeamPeriod(0); | |
109 | metaData.SetResponsible("Hans H. Dalsgaard"); | |
110 | metaData.SetComment("Preprocessor stores pedestals and gains for the FMD."); | |
111 | ||
112 | Bool_t resultPed = kFALSE, resultGain = kFALSE; | |
113 | if(calibPed) resultPed = Store("Calib","Pedestal", calibPed, &metaData); | |
114 | if(calibGain) resultGain = Store("Calib","PulseGain", calibGain, &metaData); | |
115 | if (calibPed) delete calibPed; | |
116 | if (calibGain) delete calibGain; | |
117 | ||
118 | return (resultPed && resultGain ? 0 : 1); | |
119 | } | |
120 | ||
121 | //____________________________________________________________________ | |
122 | AliFMDCalibPedestal* | |
123 | AliFMDPreprocessor::GetPedestalCalibration(TList* pedFiles) | |
124 | { | |
125 | // Read DAQ DA produced CSV files of pedestals, and return a | |
126 | // calibration object. | |
127 | // Parameters: | |
128 | // pedFiles List of pedestal files | |
129 | // Return | |
130 | // A pointer to a newly allocated AliFMDCalibPedestal object, or | |
131 | // null in case of errors. | |
132 | if(!pedFiles) return 0; | |
133 | ||
134 | AliFMDCalibPedestal* calibPed = new AliFMDCalibPedestal(); | |
135 | AliFMDParameters* pars = AliFMDParameters::Instance(); | |
136 | TIter iter(pedFiles); | |
137 | TObjString* fileSource; | |
138 | ||
139 | while((fileSource = dynamic_cast<TObjString*>(iter.Next()))) { | |
140 | const Char_t* filename = GetFile(kDAQ, "pedestal", fileSource->GetName()); | |
141 | std::ifstream in(filename); | |
142 | if(!in) { | |
143 | AliError(Form("File %s not found!", filename)); | |
144 | continue; | |
145 | } | |
146 | ||
147 | // Get header (how long is it ?) | |
148 | TString header; | |
149 | header.ReadLine(in); | |
150 | header.ToLower(); | |
151 | if(!header.Contains("pedestal")) { | |
152 | AliError("File header is not from pedestal!"); | |
153 | continue; | |
154 | } | |
155 | Log("File contains data from pedestals"); | |
156 | ||
157 | // Read columns line | |
158 | int lineno = 2; | |
159 | header.ReadLine(in); | |
160 | ||
161 | // Loop until EOF | |
162 | while(!in.eof()) { | |
163 | if(in.bad()) { | |
164 | AliError(Form("Bad read at line %d in %s", lineno, filename)); | |
165 | break; | |
166 | } | |
167 | UInt_t ddl=2, board, chip, channel, strip, tb; | |
168 | Float_t ped, noise, mu, sigma, chi2ndf; | |
169 | Char_t c[10]; | |
170 | ||
171 | in // >> ddl >> c[0] | |
172 | >> board >> c[1] | |
173 | >> chip >> c[2] | |
174 | >> channel >> c[3] | |
175 | >> strip >> c[4] | |
176 | >> tb >> c[5] | |
177 | >> ped >> c[6] | |
178 | >> noise >> c[7] | |
179 | >> mu >> c[8] | |
180 | >> sigma >> c[9] | |
181 | >> chi2ndf; | |
182 | lineno++; | |
183 | // Ignore trailing garbage | |
184 | if (strip > 127) continue; | |
185 | ||
186 | //Setting the pedestals via the hardware address | |
187 | UShort_t det, sec, str; | |
188 | Char_t ring; | |
189 | ||
190 | pars->Hardware2Detector(ddl,board,chip,channel,det,ring,sec,str); | |
191 | strip += str; | |
192 | calibPed->Set(det,ring,sec,strip,ped,noise); | |
193 | } | |
194 | } | |
195 | return calibPed; | |
196 | } | |
197 | ||
198 | //____________________________________________________________________ | |
199 | AliFMDCalibGain* | |
200 | AliFMDPreprocessor::GetGainCalibration(TList* gainFiles) | |
201 | { | |
202 | // Read DAQ DA produced CSV files of pedestals, and return a | |
203 | // calibration object. | |
204 | // Parameters: | |
205 | // pedFiles List of pedestal files | |
206 | // Return | |
207 | // A pointer to a newly allocated AliFMDCalibPedestal object, or | |
208 | // null in case of errors. | |
209 | if(!gainFiles) return 0; | |
210 | ||
211 | AliFMDCalibGain* calibGain = new AliFMDCalibGain(); | |
212 | AliFMDParameters* pars = AliFMDParameters::Instance(); | |
213 | TIter iter(gainFiles); | |
214 | TObjString* fileSource; | |
215 | while((fileSource = dynamic_cast<TObjString *>(iter.Next()))) { | |
216 | const Char_t* filename = GetFile(kDAQ, "gain", fileSource->GetName()); | |
217 | std::ifstream in(filename); | |
218 | if(!in) { | |
219 | AliError(Form("File %s not found!", filename)); | |
220 | continue; | |
221 | } | |
222 | ||
223 | //Get header (how long is it ?) | |
224 | TString header; | |
225 | header.ReadLine(in); | |
226 | header.ToLower(); | |
227 | if(!header.Contains("gain")) { | |
228 | AliError("File header is not from gain!"); | |
229 | continue; | |
230 | } | |
231 | Log("File contains data from pulse gain"); | |
232 | ||
233 | // Read column headers | |
234 | header.ReadLine(in); | |
235 | ||
236 | int lineno = 2; | |
237 | // Read until EOF | |
238 | while(!in.eof()) { | |
239 | if(in.bad()) { | |
240 | AliError(Form("Bad read at line %d in %s", lineno, filename)); | |
241 | break; | |
242 | } | |
243 | UInt_t ddl=2, board, chip, channel, strip; | |
244 | Float_t gain,error, chi2ndf; | |
245 | Char_t c[7]; | |
246 | ||
247 | in // >> ddl >> c[0] | |
248 | >> board >> c[1] | |
249 | >> chip >> c[2] | |
250 | >> channel >> c[3] | |
251 | >> strip >> c[4] | |
252 | >> gain >> c[5] | |
253 | >> error >> c[6] | |
254 | >> chi2ndf; | |
255 | lineno++; | |
256 | // Ignore trailing garbage | |
257 | if(strip > 127) continue; | |
258 | ||
259 | //Setting the pedestals via the hardware address | |
260 | UShort_t det, sec, str; | |
261 | Char_t ring; | |
262 | pars->Hardware2Detector(ddl,board,chip,channel,det,ring,sec,str); | |
263 | ||
264 | strip += str; | |
265 | calibGain->Set(det,ring,sec,strip,gain); | |
266 | } | |
267 | } | |
268 | return calibGain; | |
269 | } | |
270 | ||
271 | //____________________________________________________________________ | |
272 | // | |
273 | // EOF | |
274 | // |