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
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
87 //____________________________________________________
88 AliFMDPreprocessor::AliFMDPreprocessor(AliShuttleInterface* shuttle)
89 : AliPreprocessor("FMD", shuttle)
91 AddRunType("PHYSICS");
92 AddRunType("STANDALONE");
93 AddRunType("PEDESTAL");
98 //____________________________________________________
99 Bool_t AliFMDPreprocessor::GetAndCheckFileSources(TList*& list,
103 // Convinience function
105 // list On return, list of files.
106 // system Alice system (DAQ, DCS, ...)
110 list = GetFileSources(system, id);
114 case kDAQ: sys = "DAQ"; break;
115 case kDCS: sys = "DCS"; break;
116 default: sys = "unknown"; break;
118 Log(Form("Failed to get file sources for %s/%s", sys.Data(), system));
124 //____________________________________________________
126 AliFMDPreprocessor::GetFromCDB(const char* second, const char* third)
128 return GetFromOCDB(second, third);
132 //____________________________________________________
133 UInt_t AliFMDPreprocessor::Process(TMap* /* dcsAliasMap */)
135 // Main member function.
137 // dcsAliassMap Map of DCS data point aliases.
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;
145 Bool_t infoCalib = kTRUE;
147 // if(!dcsAliasMap) return 1;
149 // Invoking the cdb manager and the FMD parameters class
150 // AliCDBManager* cdb = AliCDBManager::Instance();
151 // cdb->SetDefaultStorage("local://$ALICE_ROOT");
153 AliFMDParameters* pars = AliFMDParameters::Instance();
154 pars->Init(this, false, AliFMDParameters::kAltroMap);
155 // This is if the SOR contains Fee parameters, and we run a DA to
156 // extract these parameters. The same code could work if we get
157 // the information from DCS via the FXS
159 AliFMDCalibSampleRate* calibRate = 0;
160 AliFMDCalibStripRange* calibRange = 0;
161 AliFMDCalibZeroSuppression* calibZero = 0;
163 if (GetAndCheckFileSources(files, kDAQ,pars->GetConditionsShuttleID()))
164 infoCalib = GetInfoCalibration(files, calibRate, calibRange, calibZero);
166 resultRate = (!calibRate ? kFALSE : kTRUE);
167 resultRange = (!calibRange ? kFALSE : kTRUE);
168 resultZero = (!calibZero ? kFALSE : kTRUE);
172 TString runType(GetRunType());
174 //Creating calibration objects
175 AliFMDCalibPedestal* calibPed = 0;
176 AliFMDCalibGain* calibGain = 0;
177 if (runType.Contains("PEDESTAL", TString::kIgnoreCase)) {
178 if (GetAndCheckFileSources(files, kDAQ, pars->GetPedestalShuttleID())) {
180 calibPed = GetPedestalCalibration(files);
182 resultPed = (calibPed ? kTRUE : kFALSE);
184 if (runType.Contains("GAIN", TString::kIgnoreCase)) {
185 if (GetAndCheckFileSources(files, kDAQ, pars->GetGainShuttleID())) {
187 calibGain = GetGainCalibration(files);
189 resultGain = (calibGain ? kTRUE : kFALSE);
192 //Storing Calibration objects
193 AliCDBMetaData metaData;
194 metaData.SetBeamPeriod(0);
195 metaData.SetResponsible("Hans H. Dalsgaard");
196 metaData.SetComment("Preprocessor stores pedestals and gains for the FMD.");
199 resultPed = Store("Calib","Pedestal", calibPed, &metaData, 0, kTRUE);
203 resultGain = Store("Calib","PulseGain", calibGain, &metaData, 0, kTRUE);
207 resultRange = Store("Calib","StripRange", calibRange, &metaData, 0, kTRUE);
211 resultRate = Store("Calib","SampleRate", calibRate, &metaData, 0, kTRUE);
215 resultZero = Store("Calib","ZeroSuppression", calibZero,&metaData,0,kTRUE);
219 Bool_t success = (resultPed && resultGain && resultRange &&
220 resultRate && resultZero && infoCalib);
222 Log(Form("FMD preprocessor was %s", (success ? "successful" : "failed")));
223 return (success ? 0 : 1);
226 //____________________________________________________________________
228 AliFMDPreprocessor::GetInfoCalibration(TList* files,
229 AliFMDCalibSampleRate*& s,
230 AliFMDCalibStripRange*& r,
231 AliFMDCalibZeroSuppression*& z)
233 // Get info calibrations.
235 // files List of files.
236 // s On return, newly allocated object
237 // r On return, newly allocated object
238 // z On return, newly allocated object
241 if (!files) return kFALSE; // Should really be false
242 if (files->GetEntries() <= 0) return kFALSE;
244 s = new AliFMDCalibSampleRate();
245 r = new AliFMDCalibStripRange();
246 z = new AliFMDCalibZeroSuppression();
248 AliFMDParameters* pars = AliFMDParameters::Instance();
250 TObjString* fileSource;
252 while((fileSource = dynamic_cast<TObjString*>(iter.Next()))) {
253 const Char_t* filename = GetFile(kDAQ, pars->GetConditionsShuttleID(), fileSource->GetName());
254 std::ifstream in(filename);
256 Log(Form("File %s not found!", filename));
266 //____________________________________________________________________
268 AliFMDPreprocessor::GetPedestalCalibration(TList* pedFiles)
270 // Read DAQ DA produced CSV files of pedestals, and return a
271 // calibration object.
273 // pedFiles List of pedestal files
275 // A pointer to a newly allocated AliFMDCalibPedestal object, or
276 // null in case of errors.
277 if(!pedFiles) return 0;
279 AliFMDCalibPedestal* calibPed = new AliFMDCalibPedestal();
280 AliFMDParameters* pars = AliFMDParameters::Instance();
281 TIter iter(pedFiles);
282 TObjString* fileSource;
284 while((fileSource = dynamic_cast<TObjString*>(iter.Next()))) {
285 const Char_t* filename = GetFile(kDAQ, pars->GetPedestalShuttleID(), fileSource->GetName());
286 std::ifstream in(filename);
288 Log(Form("File %s not found!", filename));
292 // Get header (how long is it ?)
296 if(!header.Contains(pars->GetPedestalShuttleID())) {
297 Log("File header is not from pedestal!");
300 Log("File contains data from pedestals");
307 while(in.peek()!=EOF) {
309 Log(Form("Bad read at line %d in %s", lineno, filename));
312 UShort_t det, sec, strip;
314 Float_t ped, noise, mu, sigma, chi2ndf;
328 // Ignore trailing garbage
329 // if (strip > 127) continue;
331 //Setting DDL to comply with the FMD in DAQ
332 // UInt_t FmdDDLBase = 3072;
333 // ddl = ddl - FmdDDLBase;
334 //Setting the pedestals via the hardware address
337 // pars->Hardware2Detector(ddl,board,chip,channel,det,ring,sec,str);
340 calibPed->Set(det,ring,sec,strip,ped,noise);
347 //____________________________________________________________________
349 AliFMDPreprocessor::GetGainCalibration(TList* gainFiles)
351 // Read DAQ DA produced CSV files of pedestals, and return a
352 // calibration object.
354 // pedFiles List of pedestal files
356 // A pointer to a newly allocated AliFMDCalibPedestal object, or
357 // null in case of errors.
358 if(!gainFiles) return 0;
360 AliFMDCalibGain* calibGain = new AliFMDCalibGain();
361 AliFMDParameters* pars = AliFMDParameters::Instance();
362 TIter iter(gainFiles);
363 TObjString* fileSource;
364 while((fileSource = dynamic_cast<TObjString *>(iter.Next()))) {
365 const Char_t* filename = GetFile(kDAQ, pars->GetGainShuttleID(), fileSource->GetName());
366 std::ifstream in(filename);
368 Log(Form("File %s not found!", filename));
372 //Get header (how long is it ?)
376 if(!header.Contains(pars->GetGainShuttleID())) {
377 Log("File header is not from gain!");
380 Log("File contains data from pulse gain");
382 // Read column headers
387 while(in.peek()!=EOF) {
389 Log(Form("Bad read at line %d in %s", lineno, filename));
392 UShort_t det, sec, strip;
395 Float_t gain,error, chi2ndf;
406 // Ignore trailing garbage
407 //if(strip > 127) continue;
409 //Setting DDL to comply with the FMD in DAQ
410 // UInt_t FmdDDLBase = 3072;
411 // ddl = ddl - FmdDDLBase;
412 //Setting the pedestals via the hardware address
413 // pars->Hardware2Detector(ddl,board,chip,channel,det,ring,sec,str);
416 calibGain->Set(det,ring,sec,strip,gain);
422 //____________________________________________________________________