1 /**************************************************************************
2 * Copyright(c) 2004, ALICE Experiment at CERN, All rights reserved. *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
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 **************************************************************************/
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
21 //___________________________________________________________________
23 // The class processes data points from DCS (via Amanada), and DAQ DA
24 // files (via FXS) to make calibration data for the FMD.
30 // * pedestals - a (ASCII) Comma Separated Values files with the
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
46 // board FEC board number
47 // chip ALTRO chip number on FEC
48 // channel ALTRO channel number
49 // strip VA1 strip number
51 // error Error on gain
52 // chi2 Chi^2 per degrees of freedom of fit
54 // Latest changes by Christian Holm Christensen
57 // #include <iostream>
60 #include "AliFMDPreprocessor.h"
61 #include "AliFMDCalibPedestal.h"
62 #include "AliFMDCalibGain.h"
63 #include "AliFMDCalibStripRange.h"
64 #include "AliFMDCalibSampleRate.h"
65 #include "AliFMDParameters.h"
66 #include "AliCDBMetaData.h"
67 #include "AliCDBManager.h"
68 // #include "AliDCSValue.h"
70 #include <TTimeStamp.h>
72 #include <TObjString.h>
77 ClassImp(AliFMDPreprocessor)
78 #if 0 // Do not remove - here to make Emacs happy
82 //____________________________________________________
83 Bool_t AliFMDPreprocessor::GetAndCheckFileSources(TList*& list,
87 // Convinience function
89 // list On return, list of files.
90 // system Alice system (DAQ, DCS, ...)
94 list = GetFileSources(system, id);
98 case kDAQ: sys = "DAQ"; break;
99 case kDCS: sys = "DCS"; break;
100 default: sys = "unknown"; break;
102 Log(Form("Failed to get file sources for %s/%s", sys.Data(), system));
108 //____________________________________________________
110 AliFMDPreprocessor::GetFromCDB(const char* second, const char* third)
112 return GetFromOCDB(second, third);
116 //____________________________________________________
117 UInt_t AliFMDPreprocessor::Process(TMap* /* dcsAliasMap */)
119 // Main member function.
121 // dcsAliassMap Map of DCS data point aliases.
126 // if(!dcsAliasMap) return 1;
128 // Invoking the cdb manager and the FMD parameters class
129 // AliCDBManager* cdb = AliCDBManager::Instance();
130 // cdb->SetDefaultStorage("local://$ALICE_ROOT");
132 AliFMDParameters* pars = AliFMDParameters::Instance();
133 pars->Init(this, false, AliFMDParameters::kAltroMap);
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
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);
147 TString runType(GetRunType());
149 //Creating calibration objects
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);
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.");
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;
173 resultPed = Store("Calib","Pedestal", calibPed, &metaData);
177 resultGain = Store("Calib","PulseGain", calibGain, &metaData);
181 resultRange = Store("Calib","StripRange", calibRange, &metaData);
185 resultRate = Store("Calib","SampleRate", calibRate, &metaData);
189 resultZero = Store("Calib","ZeroSuppression", calibZero, &metaData);
193 return (resultPed && resultGain ? 0 : 1);
195 // Disabled until we implement GetInfoCalibration properly
205 //____________________________________________________________________
207 AliFMDPreprocessor::GetInfoCalibration(TList* files,
208 AliFMDCalibSampleRate*& s,
209 AliFMDCalibStripRange*& r,
210 AliFMDCalibZeroSuppression*& z)
212 // Get info calibrations.
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
220 if (!files) return kTRUE; // Should really be false
221 if (files->GetEntries() <= 0) return kTRUE;
223 s = new AliFMDCalibSampleRate();
224 r = new AliFMDCalibStripRange();
225 z = new AliFMDCalibZeroSuppression();
227 // AliFMDParameters* pars = AliFMDParameters::Instance();
229 TObjString* fileSource;
231 while((fileSource = dynamic_cast<TObjString*>(iter.Next()))) {
232 const Char_t* filename = GetFile(kDAQ, "info", fileSource->GetName());
233 std::ifstream in(filename);
235 AliError(Form("File %s not found!", filename));
243 //____________________________________________________________________
245 AliFMDPreprocessor::GetPedestalCalibration(TList* pedFiles)
247 // Read DAQ DA produced CSV files of pedestals, and return a
248 // calibration object.
250 // pedFiles List of pedestal files
252 // A pointer to a newly allocated AliFMDCalibPedestal object, or
253 // null in case of errors.
254 if(!pedFiles) return 0;
256 AliFMDCalibPedestal* calibPed = new AliFMDCalibPedestal();
257 AliFMDParameters* pars = AliFMDParameters::Instance();
258 TIter iter(pedFiles);
259 TObjString* fileSource;
261 while((fileSource = dynamic_cast<TObjString*>(iter.Next()))) {
262 const Char_t* filename = GetFile(kDAQ, "pedestal", fileSource->GetName());
263 std::ifstream in(filename);
265 AliError(Form("File %s not found!", filename));
269 // Get header (how long is it ?)
273 if(!header.Contains("pedestal")) {
274 AliError("File header is not from pedestal!");
277 Log("File contains data from pedestals");
286 AliError(Form("Bad read at line %d in %s", lineno, filename));
289 UInt_t ddl=2, board, chip, channel, strip, tb;
290 Float_t ped, noise, mu, sigma, chi2ndf;
305 // Ignore trailing garbage
306 if (strip > 127) continue;
308 //Setting the pedestals via the hardware address
309 UShort_t det, sec, str;
312 pars->Hardware2Detector(ddl,board,chip,channel,det,ring,sec,str);
314 calibPed->Set(det,ring,sec,strip,ped,noise);
320 //____________________________________________________________________
322 AliFMDPreprocessor::GetGainCalibration(TList* gainFiles)
324 // Read DAQ DA produced CSV files of pedestals, and return a
325 // calibration object.
327 // pedFiles List of pedestal files
329 // A pointer to a newly allocated AliFMDCalibPedestal object, or
330 // null in case of errors.
331 if(!gainFiles) return 0;
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);
341 AliError(Form("File %s not found!", filename));
345 //Get header (how long is it ?)
349 if(!header.Contains("gain")) {
350 AliError("File header is not from gain!");
353 Log("File contains data from pulse gain");
355 // Read column headers
362 AliError(Form("Bad read at line %d in %s", lineno, filename));
365 UInt_t ddl=2, board, chip, channel, strip;
366 Float_t gain,error, chi2ndf;
378 // Ignore trailing garbage
379 if(strip > 127) continue;
381 //Setting the pedestals via the hardware address
382 UShort_t det, sec, str;
384 pars->Hardware2Detector(ddl,board,chip,channel,det,ring,sec,str);
387 calibGain->Set(det,ring,sec,strip,gain);
393 //____________________________________________________________________