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