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 // GetAndCheckFileSources(files, kDAQ,"info");
149 // if (!files) return 1;
150 AliFMDCalibSampleRate* calibRate = 0;
151 AliFMDCalibStripRange* calibRange = 0;
152 AliFMDCalibZeroSuppression* calibZero = 0;
153 GetInfoCalibration(files, calibRate, calibRange, calibZero);
155 // resultRate = (!calibRate ? kFALSE : kTRUE);
156 // resultRange = (!calibRange ? kFALSE : kTRUE);
157 // resultZero = (!calibZero ? kFALSE : kTRUE);
160 TString runType(GetRunType());
162 //Creating calibration objects
163 AliFMDCalibPedestal* calibPed = 0;
164 AliFMDCalibGain* calibGain = 0;
165 if (runType.Contains("PEDESTAL", TString::kIgnoreCase) &&
166 GetAndCheckFileSources(files, kDAQ, "pedestal"))
167 resultPed = (!(calibPed = GetPedestalCalibration(files)) ? kFALSE : kTRUE);
168 if (runType.Contains("PULSER", TString::kIgnoreCase) &&
169 GetAndCheckFileSources(files, kDAQ, "gain"))
170 resultGain = (!(calibGain = GetGainCalibration(files)) ? kFALSE : kTRUE);
172 //Storing Calibration objects
173 AliCDBMetaData metaData;
174 metaData.SetBeamPeriod(0);
175 metaData.SetResponsible("Hans H. Dalsgaard");
176 metaData.SetComment("Preprocessor stores pedestals and gains for the FMD.");
179 resultPed = Store("Calib","Pedestal", calibPed, &metaData, 0, kTRUE);
183 resultGain = Store("Calib","PulseGain", calibGain, &metaData, 0, kTRUE);
187 resultRange = Store("Calib","StripRange", calibRange, &metaData, 0, kTRUE);
191 resultRate = Store("Calib","SampleRate", calibRate, &metaData, 0, kTRUE);
195 resultZero = Store("Calib","ZeroSuppression", calibZero, &metaData,0,kTRUE);
200 // Disabled until we implement GetInfoCalibration properly
201 Bool_t success = (resultPed && resultGain && resultRange &&
202 resultRate && resultZero);
204 Bool_t success = resultPed && resultGain;
205 Log(Form("FMD preprocessor was %s", (success ? "successful" : "failed")));
206 return (success ? 0 : 1);
209 //____________________________________________________________________
211 AliFMDPreprocessor::GetInfoCalibration(TList* files,
212 AliFMDCalibSampleRate*& s,
213 AliFMDCalibStripRange*& r,
214 AliFMDCalibZeroSuppression*& z)
216 // Get info calibrations.
218 // files List of files.
219 // s On return, newly allocated object
220 // r On return, newly allocated object
221 // z On return, newly allocated object
224 if (!files) return kTRUE; // Should really be false
225 if (files->GetEntries() <= 0) return kTRUE;
227 s = new AliFMDCalibSampleRate();
228 r = new AliFMDCalibStripRange();
229 z = new AliFMDCalibZeroSuppression();
231 // AliFMDParameters* pars = AliFMDParameters::Instance();
233 TObjString* fileSource;
235 while((fileSource = dynamic_cast<TObjString*>(iter.Next()))) {
236 const Char_t* filename = GetFile(kDAQ, "info", fileSource->GetName());
237 std::ifstream in(filename);
239 Log(Form("File %s not found!", filename));
247 //____________________________________________________________________
249 AliFMDPreprocessor::GetPedestalCalibration(TList* pedFiles)
251 // Read DAQ DA produced CSV files of pedestals, and return a
252 // calibration object.
254 // pedFiles List of pedestal files
256 // A pointer to a newly allocated AliFMDCalibPedestal object, or
257 // null in case of errors.
258 if(!pedFiles) return 0;
260 AliFMDCalibPedestal* calibPed = new AliFMDCalibPedestal();
261 AliFMDParameters* pars = AliFMDParameters::Instance();
262 TIter iter(pedFiles);
263 TObjString* fileSource;
265 while((fileSource = dynamic_cast<TObjString*>(iter.Next()))) {
266 const Char_t* filename = GetFile(kDAQ, "pedestal", fileSource->GetName());
267 std::ifstream in(filename);
269 Log(Form("File %s not found!", filename));
273 // Get header (how long is it ?)
277 if(!header.Contains("pedestal")) {
278 Log("File header is not from pedestal!");
281 Log("File contains data from pedestals");
290 Log(Form("Bad read at line %d in %s", lineno, filename));
293 UInt_t ddl=2, board, chip, channel, strip, tb;
294 Float_t ped, noise, mu, sigma, chi2ndf;
309 // Ignore trailing garbage
310 if (strip > 127) continue;
312 //Setting the pedestals via the hardware address
313 UShort_t det, sec, str;
316 pars->Hardware2Detector(ddl,board,chip,channel,det,ring,sec,str);
318 calibPed->Set(det,ring,sec,strip,ped,noise);
324 //____________________________________________________________________
326 AliFMDPreprocessor::GetGainCalibration(TList* gainFiles)
328 // Read DAQ DA produced CSV files of pedestals, and return a
329 // calibration object.
331 // pedFiles List of pedestal files
333 // A pointer to a newly allocated AliFMDCalibPedestal object, or
334 // null in case of errors.
335 if(!gainFiles) return 0;
337 AliFMDCalibGain* calibGain = new AliFMDCalibGain();
338 AliFMDParameters* pars = AliFMDParameters::Instance();
339 TIter iter(gainFiles);
340 TObjString* fileSource;
341 while((fileSource = dynamic_cast<TObjString *>(iter.Next()))) {
342 const Char_t* filename = GetFile(kDAQ, "gain", fileSource->GetName());
343 std::ifstream in(filename);
345 Log(Form("File %s not found!", filename));
349 //Get header (how long is it ?)
353 if(!header.Contains("gain")) {
354 Log("File header is not from gain!");
357 Log("File contains data from pulse gain");
359 // Read column headers
366 Log(Form("Bad read at line %d in %s", lineno, filename));
369 UInt_t ddl=2, board, chip, channel, strip;
370 Float_t gain,error, chi2ndf;
382 // Ignore trailing garbage
383 if(strip > 127) continue;
385 //Setting the pedestals via the hardware address
386 UShort_t det, sec, str;
388 pars->Hardware2Detector(ddl,board,chip,channel,det,ring,sec,str);
391 calibGain->Set(det,ring,sec,strip,gain);
397 //____________________________________________________________________