]>
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" | |
dc02d468 | 63 | #include "AliFMDCalibStripRange.h" |
64 | #include "AliFMDCalibSampleRate.h" | |
f6449cc0 | 65 | #include "AliFMDParameters.h" |
66 | #include "AliCDBMetaData.h" | |
67 | #include "AliCDBManager.h" | |
68 | // #include "AliDCSValue.h" | |
69 | #include "AliLog.h" | |
70 | #include <TTimeStamp.h> | |
71 | // #include <TFile.h> | |
72 | #include <TObjString.h> | |
73 | #include <TString.h> | |
74 | #include <TNamed.h> | |
75 | ||
76 | ||
77 | ClassImp(AliFMDPreprocessor) | |
78 | #if 0 // Do not remove - here to make Emacs happy | |
79 | ; | |
80 | #endif | |
81 | ||
dc02d468 | 82 | //____________________________________________________ |
83 | Bool_t AliFMDPreprocessor::GetAndCheckFileSources(TList*& list, | |
84 | Int_t system, | |
85 | const char* id) | |
86 | { | |
87 | // Convinience function | |
88 | // Parameters: | |
89 | // list On return, list of files. | |
90 | // system Alice system (DAQ, DCS, ...) | |
91 | // id File id | |
92 | // Return: | |
93 | // kTRUE on success. | |
94 | list = GetFileSources(system, id); | |
95 | if (!list) { | |
96 | TString sys; | |
97 | switch (system) { | |
98 | case kDAQ: sys = "DAQ"; break; | |
99 | case kDCS: sys = "DCS"; break; | |
100 | default: sys = "unknown"; break; | |
101 | } | |
102 | Log(Form("Failed to get file sources for %s/%s", sys.Data(), system)); | |
103 | return kFALSE; | |
104 | } | |
105 | return kTRUE; | |
106 | } | |
107 | ||
108 | //____________________________________________________ | |
109 | AliCDBEntry* | |
110 | AliFMDPreprocessor::GetFromCDB(const char* second, const char* third) | |
111 | { | |
112 | return GetFromOCDB(second, third); | |
113 | } | |
114 | ||
115 | ||
f6449cc0 | 116 | //____________________________________________________ |
117 | UInt_t AliFMDPreprocessor::Process(TMap* /* dcsAliasMap */) | |
118 | { | |
119 | // Main member function. | |
120 | // Parameters: | |
121 | // dcsAliassMap Map of DCS data point aliases. | |
122 | // Return | |
123 | // ? | |
124 | ||
125 | // Do we need this ? | |
126 | // if(!dcsAliasMap) return 1; | |
127 | // | |
128 | // Invoking the cdb manager and the FMD parameters class | |
129 | // AliCDBManager* cdb = AliCDBManager::Instance(); | |
130 | // cdb->SetDefaultStorage("local://$ALICE_ROOT"); | |
131 | // cdb->SetRun(0); | |
132 | AliFMDParameters* pars = AliFMDParameters::Instance(); | |
dc02d468 | 133 | pars->Init(this, false, AliFMDParameters::kAltroMap); |
134 | ||
135 | // This is if the SOR contains Fee parameters, and we run a DA to | |
136 | // extract these parameters. The same code could work if we get | |
137 | // the information from DCS via the FXS | |
138 | TList* files = 0; | |
139 | GetAndCheckFileSources(files, kDAQ,"info"); | |
140 | // if (!ifiles) return 1; | |
141 | AliFMDCalibSampleRate* calibRate = 0; | |
142 | AliFMDCalibStripRange* calibRange = 0; | |
143 | AliFMDCalibZeroSuppression* calibZero = 0; | |
144 | GetInfoCalibration(files, calibRate, calibRange, calibZero); | |
f6449cc0 | 145 | |
dc02d468 | 146 | // Gt the run type |
147 | TString runType(GetRunType()); | |
148 | ||
f6449cc0 | 149 | //Creating calibration objects |
dc02d468 | 150 | AliFMDCalibPedestal* calibPed = 0; |
151 | AliFMDCalibGain* calibGain = 0; | |
152 | if (runType.Contains("PEDESTAL", TString::kIgnoreCase) && | |
153 | GetAndCheckFileSources(files, kDAQ, "pedestal")) | |
154 | calibPed = GetPedestalCalibration(files); | |
155 | if (runType.Contains("PULSER", TString::kIgnoreCase) && | |
156 | GetAndCheckFileSources(files, kDAQ, "gain")) | |
157 | calibGain = GetGainCalibration(files); | |
158 | ||
f6449cc0 | 159 | |
160 | ||
161 | //Storing Calibration objects | |
162 | AliCDBMetaData metaData; | |
163 | metaData.SetBeamPeriod(0); | |
164 | metaData.SetResponsible("Hans H. Dalsgaard"); | |
165 | metaData.SetComment("Preprocessor stores pedestals and gains for the FMD."); | |
166 | ||
dc02d468 | 167 | Bool_t resultPed = kFALSE; |
168 | Bool_t resultGain = kFALSE; | |
169 | Bool_t resultRange = kFALSE; | |
170 | Bool_t resultRate = kFALSE; | |
171 | Bool_t resultZero = kFALSE; | |
172 | if(calibPed) { | |
173 | resultPed = Store("Calib","Pedestal", calibPed, &metaData); | |
174 | delete calibPed; | |
175 | } | |
176 | if(calibGain) { | |
177 | resultGain = Store("Calib","PulseGain", calibGain, &metaData); | |
178 | delete calibGain; | |
179 | } | |
180 | if(calibRange) { | |
181 | resultRange = Store("Calib","StripRange", calibRange, &metaData); | |
182 | delete calibRange; | |
183 | } | |
184 | if(calibRate) { | |
185 | resultRate = Store("Calib","SampleRate", calibRate, &metaData); | |
186 | delete calibRate; | |
187 | } | |
188 | if(calibZero) { | |
189 | resultZero = Store("Calib","ZeroSuppression", calibZero, &metaData); | |
190 | delete calibZero; | |
191 | } | |
f6449cc0 | 192 | |
193 | return (resultPed && resultGain ? 0 : 1); | |
dc02d468 | 194 | #if 0 |
195 | // Disabled until we implement GetInfoCalibration properly | |
196 | return (resultPed && | |
197 | resultGain && | |
198 | resultRange && | |
199 | resultRate && | |
200 | resultZero | |
201 | ? 0 : 1); | |
202 | #endif | |
203 | } | |
204 | ||
205 | //____________________________________________________________________ | |
206 | Bool_t | |
207 | AliFMDPreprocessor::GetInfoCalibration(TList* files, | |
208 | AliFMDCalibSampleRate*& s, | |
209 | AliFMDCalibStripRange*& r, | |
210 | AliFMDCalibZeroSuppression*& z) | |
211 | { | |
212 | // Get info calibrations. | |
213 | // Parameters: | |
214 | // files List of files. | |
215 | // s On return, newly allocated object | |
216 | // r On return, newly allocated object | |
217 | // z On return, newly allocated object | |
218 | // Return: | |
219 | // kTRUE on success | |
220 | if (!files) return kTRUE; // Should really be false | |
221 | if (files->GetEntries() <= 0) return kTRUE; | |
222 | ||
223 | s = new AliFMDCalibSampleRate(); | |
224 | r = new AliFMDCalibStripRange(); | |
225 | z = new AliFMDCalibZeroSuppression(); | |
226 | ||
227 | // AliFMDParameters* pars = AliFMDParameters::Instance(); | |
228 | TIter iter(files); | |
229 | TObjString* fileSource; | |
230 | ||
231 | while((fileSource = dynamic_cast<TObjString*>(iter.Next()))) { | |
232 | const Char_t* filename = GetFile(kDAQ, "info", fileSource->GetName()); | |
233 | std::ifstream in(filename); | |
234 | if(!in) { | |
235 | AliError(Form("File %s not found!", filename)); | |
236 | continue; | |
237 | } | |
238 | } | |
239 | return kTRUE; | |
f6449cc0 | 240 | } |
241 | ||
dc02d468 | 242 | |
f6449cc0 | 243 | //____________________________________________________________________ |
244 | AliFMDCalibPedestal* | |
245 | AliFMDPreprocessor::GetPedestalCalibration(TList* pedFiles) | |
246 | { | |
247 | // Read DAQ DA produced CSV files of pedestals, and return a | |
248 | // calibration object. | |
249 | // Parameters: | |
250 | // pedFiles List of pedestal files | |
251 | // Return | |
252 | // A pointer to a newly allocated AliFMDCalibPedestal object, or | |
253 | // null in case of errors. | |
254 | if(!pedFiles) return 0; | |
255 | ||
256 | AliFMDCalibPedestal* calibPed = new AliFMDCalibPedestal(); | |
257 | AliFMDParameters* pars = AliFMDParameters::Instance(); | |
258 | TIter iter(pedFiles); | |
259 | TObjString* fileSource; | |
260 | ||
261 | while((fileSource = dynamic_cast<TObjString*>(iter.Next()))) { | |
262 | const Char_t* filename = GetFile(kDAQ, "pedestal", fileSource->GetName()); | |
263 | std::ifstream in(filename); | |
264 | if(!in) { | |
265 | AliError(Form("File %s not found!", filename)); | |
266 | continue; | |
267 | } | |
268 | ||
269 | // Get header (how long is it ?) | |
270 | TString header; | |
271 | header.ReadLine(in); | |
272 | header.ToLower(); | |
273 | if(!header.Contains("pedestal")) { | |
274 | AliError("File header is not from pedestal!"); | |
275 | continue; | |
276 | } | |
277 | Log("File contains data from pedestals"); | |
278 | ||
279 | // Read columns line | |
280 | int lineno = 2; | |
281 | header.ReadLine(in); | |
282 | ||
283 | // Loop until EOF | |
284 | while(!in.eof()) { | |
285 | if(in.bad()) { | |
286 | AliError(Form("Bad read at line %d in %s", lineno, filename)); | |
287 | break; | |
288 | } | |
289 | UInt_t ddl=2, board, chip, channel, strip, tb; | |
290 | Float_t ped, noise, mu, sigma, chi2ndf; | |
291 | Char_t c[10]; | |
292 | ||
293 | in // >> ddl >> c[0] | |
294 | >> board >> c[1] | |
295 | >> chip >> c[2] | |
296 | >> channel >> c[3] | |
297 | >> strip >> c[4] | |
298 | >> tb >> c[5] | |
299 | >> ped >> c[6] | |
300 | >> noise >> c[7] | |
301 | >> mu >> c[8] | |
302 | >> sigma >> c[9] | |
303 | >> chi2ndf; | |
304 | lineno++; | |
305 | // Ignore trailing garbage | |
306 | if (strip > 127) continue; | |
307 | ||
308 | //Setting the pedestals via the hardware address | |
309 | UShort_t det, sec, str; | |
310 | Char_t ring; | |
311 | ||
312 | pars->Hardware2Detector(ddl,board,chip,channel,det,ring,sec,str); | |
313 | strip += str; | |
314 | calibPed->Set(det,ring,sec,strip,ped,noise); | |
315 | } | |
316 | } | |
317 | return calibPed; | |
318 | } | |
319 | ||
320 | //____________________________________________________________________ | |
321 | AliFMDCalibGain* | |
322 | AliFMDPreprocessor::GetGainCalibration(TList* gainFiles) | |
323 | { | |
324 | // Read DAQ DA produced CSV files of pedestals, and return a | |
325 | // calibration object. | |
326 | // Parameters: | |
327 | // pedFiles List of pedestal files | |
328 | // Return | |
329 | // A pointer to a newly allocated AliFMDCalibPedestal object, or | |
330 | // null in case of errors. | |
331 | if(!gainFiles) return 0; | |
332 | ||
333 | AliFMDCalibGain* calibGain = new AliFMDCalibGain(); | |
334 | AliFMDParameters* pars = AliFMDParameters::Instance(); | |
335 | TIter iter(gainFiles); | |
336 | TObjString* fileSource; | |
337 | while((fileSource = dynamic_cast<TObjString *>(iter.Next()))) { | |
338 | const Char_t* filename = GetFile(kDAQ, "gain", fileSource->GetName()); | |
339 | std::ifstream in(filename); | |
340 | if(!in) { | |
341 | AliError(Form("File %s not found!", filename)); | |
342 | continue; | |
343 | } | |
344 | ||
345 | //Get header (how long is it ?) | |
346 | TString header; | |
347 | header.ReadLine(in); | |
348 | header.ToLower(); | |
349 | if(!header.Contains("gain")) { | |
350 | AliError("File header is not from gain!"); | |
351 | continue; | |
352 | } | |
353 | Log("File contains data from pulse gain"); | |
354 | ||
355 | // Read column headers | |
356 | header.ReadLine(in); | |
357 | ||
358 | int lineno = 2; | |
359 | // Read until EOF | |
360 | while(!in.eof()) { | |
361 | if(in.bad()) { | |
362 | AliError(Form("Bad read at line %d in %s", lineno, filename)); | |
363 | break; | |
364 | } | |
365 | UInt_t ddl=2, board, chip, channel, strip; | |
366 | Float_t gain,error, chi2ndf; | |
367 | Char_t c[7]; | |
368 | ||
369 | in // >> ddl >> c[0] | |
370 | >> board >> c[1] | |
371 | >> chip >> c[2] | |
372 | >> channel >> c[3] | |
373 | >> strip >> c[4] | |
374 | >> gain >> c[5] | |
375 | >> error >> c[6] | |
376 | >> chi2ndf; | |
377 | lineno++; | |
378 | // Ignore trailing garbage | |
379 | if(strip > 127) continue; | |
380 | ||
381 | //Setting the pedestals via the hardware address | |
382 | UShort_t det, sec, str; | |
383 | Char_t ring; | |
384 | pars->Hardware2Detector(ddl,board,chip,channel,det,ring,sec,str); | |
385 | ||
386 | strip += str; | |
387 | calibGain->Set(det,ring,sec,strip,gain); | |
388 | } | |
389 | } | |
390 | return calibGain; | |
391 | } | |
392 | ||
393 | //____________________________________________________________________ | |
394 | // | |
395 | // EOF | |
396 | // |