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