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
56 // http://aliceinfo.cern.ch/Offline/Activities/Shuttle.html
58 // Latest changes by Christian Holm Christensen
61 // #include <iostream>
64 #include "AliFMDPreprocessor.h"
65 #include "AliFMDCalibPedestal.h"
66 #include "AliFMDCalibGain.h"
67 #include "AliFMDCalibStripRange.h"
68 #include "AliFMDCalibSampleRate.h"
69 #include "AliFMDParameters.h"
70 #include "AliCDBMetaData.h"
71 #include "AliCDBManager.h"
72 // #include "AliDCSValue.h"
74 #include <TTimeStamp.h>
76 #include <TObjString.h>
81 ClassImp(AliFMDPreprocessor)
82 #if 0 // Do not remove - here to make Emacs happy
86 //____________________________________________________
87 Bool_t AliFMDPreprocessor::GetAndCheckFileSources(TList*& list,
91 // Convinience function
93 // list On return, list of files.
94 // system Alice system (DAQ, DCS, ...)
98 list = GetFileSources(system, id);
102 case kDAQ: sys = "DAQ"; break;
103 case kDCS: sys = "DCS"; break;
104 default: sys = "unknown"; break;
106 Log(Form("Failed to get file sources for %s/%s", sys.Data(), system));
112 //____________________________________________________
114 AliFMDPreprocessor::GetFromCDB(const char* second, const char* third)
116 return GetFromOCDB(second, third);
120 //____________________________________________________
121 UInt_t AliFMDPreprocessor::Process(TMap* /* dcsAliasMap */)
123 // Main member function.
125 // dcsAliassMap Map of DCS data point aliases.
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;
135 // if(!dcsAliasMap) return 1;
137 // Invoking the cdb manager and the FMD parameters class
138 // AliCDBManager* cdb = AliCDBManager::Instance();
139 // cdb->SetDefaultStorage("local://$ALICE_ROOT");
141 AliFMDParameters* pars = AliFMDParameters::Instance();
142 pars->Init(this, false, AliFMDParameters::kAltroMap);
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
148 AliFMDCalibSampleRate* calibRate = 0;
149 AliFMDCalibStripRange* calibRange = 0;
150 AliFMDCalibZeroSuppression* calibZero = 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);
161 TString runType(GetRunType());
163 //Creating calibration objects
164 AliFMDCalibPedestal* calibPed = 0;
165 AliFMDCalibGain* calibGain = 0;
166 if (runType.Contains("PEDESTAL", TString::kIgnoreCase)) {
167 if (GetAndCheckFileSources(files, kDAQ, "pedestals")) {
169 calibPed = GetPedestalCalibration(files);
171 resultPed = (calibPed ? kTRUE : kFALSE);
173 if (runType.Contains("PULSER", TString::kIgnoreCase)) {
174 if (GetAndCheckFileSources(files, kDAQ, "gains")) {
176 calibGain = GetGainCalibration(files);
178 resultGain = (calibGain ? kTRUE : kFALSE);
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.");
188 resultPed = Store("Calib","Pedestal", calibPed, &metaData, 0, kTRUE);
192 resultGain = Store("Calib","PulseGain", calibGain, &metaData, 0, kTRUE);
196 resultRange = Store("Calib","StripRange", calibRange, &metaData, 0, kTRUE);
200 resultRate = Store("Calib","SampleRate", calibRate, &metaData, 0, kTRUE);
204 resultZero = Store("Calib","ZeroSuppression", calibZero,&metaData,0,kTRUE);
209 // Disabled until we implement GetInfoCalibration properly
210 Bool_t success = (resultPed && resultGain && resultRange &&
211 resultRate && resultZero);
213 Bool_t success = resultPed && resultGain;
214 Log(Form("FMD preprocessor was %s", (success ? "successful" : "failed")));
215 return (success ? 0 : 1);
218 //____________________________________________________________________
220 AliFMDPreprocessor::GetInfoCalibration(TList* files,
221 AliFMDCalibSampleRate*& s,
222 AliFMDCalibStripRange*& r,
223 AliFMDCalibZeroSuppression*& z)
225 // Get info calibrations.
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
233 if (!files) return kTRUE; // Should really be false
234 if (files->GetEntries() <= 0) return kTRUE;
236 s = new AliFMDCalibSampleRate();
237 r = new AliFMDCalibStripRange();
238 z = new AliFMDCalibZeroSuppression();
240 // AliFMDParameters* pars = AliFMDParameters::Instance();
242 TObjString* fileSource;
244 while((fileSource = dynamic_cast<TObjString*>(iter.Next()))) {
245 const Char_t* filename = GetFile(kDAQ, "info", fileSource->GetName());
246 std::ifstream in(filename);
248 Log(Form("File %s not found!", filename));
256 //____________________________________________________________________
258 AliFMDPreprocessor::GetPedestalCalibration(TList* pedFiles)
260 // Read DAQ DA produced CSV files of pedestals, and return a
261 // calibration object.
263 // pedFiles List of pedestal files
265 // A pointer to a newly allocated AliFMDCalibPedestal object, or
266 // null in case of errors.
267 if(!pedFiles) return 0;
269 AliFMDCalibPedestal* calibPed = new AliFMDCalibPedestal();
270 AliFMDParameters* pars = AliFMDParameters::Instance();
271 TIter iter(pedFiles);
272 TObjString* fileSource;
274 while((fileSource = dynamic_cast<TObjString*>(iter.Next()))) {
275 const Char_t* filename = GetFile(kDAQ, "pedestals", fileSource->GetName());
276 std::ifstream in(filename);
278 Log(Form("File %s not found!", filename));
282 // Get header (how long is it ?)
286 if(!header.Contains("pedestal")) {
287 Log("File header is not from pedestal!");
290 Log("File contains data from pedestals");
297 while(in.peek()!=EOF) {
299 Log(Form("Bad read at line %d in %s", lineno, filename));
302 UInt_t ddl=2, board, chip, channel, strip, sample, tb;
303 Float_t ped, noise, mu, sigma, chi2ndf;
320 // Ignore trailing garbage
321 if (strip > 127) continue;
323 //Setting DDL to comply with the FMD in DAQ
324 UInt_t FmdDDLBase = 3072;
325 ddl = ddl - FmdDDLBase;
326 //Setting the pedestals via the hardware address
327 UShort_t det, sec, str;
330 pars->Hardware2Detector(ddl,board,chip,channel,det,ring,sec,str);
333 calibPed->Set(det,ring,sec,strip,ped,noise);
340 //____________________________________________________________________
342 AliFMDPreprocessor::GetGainCalibration(TList* gainFiles)
344 // Read DAQ DA produced CSV files of pedestals, and return a
345 // calibration object.
347 // pedFiles List of pedestal files
349 // A pointer to a newly allocated AliFMDCalibPedestal object, or
350 // null in case of errors.
351 if(!gainFiles) return 0;
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()))) {
358 const Char_t* filename = GetFile(kDAQ, "gains", fileSource->GetName());
359 std::ifstream in(filename);
361 Log(Form("File %s not found!", filename));
365 //Get header (how long is it ?)
369 if(!header.Contains("gain")) {
370 Log("File header is not from gain!");
373 Log("File contains data from pulse gain");
375 // Read column headers
380 while(in.peek()!=EOF) {
382 Log(Form("Bad read at line %d in %s", lineno, filename));
385 UInt_t ddl=2, board, chip, channel, strip;
386 Float_t gain,error, chi2ndf;
398 // Ignore trailing garbage
399 if(strip > 127) continue;
401 //Setting DDL to comply with the FMD in DAQ
402 UInt_t FmdDDLBase = 3072;
403 ddl = ddl - FmdDDLBase;
404 //Setting the pedestals via the hardware address
405 UShort_t det, sec, str;
407 pars->Hardware2Detector(ddl,board,chip,channel,det,ring,sec,str);
410 calibGain->Set(det,ring,sec,strip,gain);
416 //____________________________________________________________________