]> git.uio.no Git - u/mrichter/AliRoot.git/blame - FMD/AliFMDPreprocessor.cxx
From Cesar: make selection and two-selection working with the new
[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
2f7fce12 61 #include <iostream>
f6449cc0 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;
2f7fce12 145 Bool_t infoCalib = kTRUE;
f6449cc0 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();
162637e4 151 // cdb->SetDefaultStorage("local://$ALICE_ROOT/OCDB");
f6449cc0 152 // cdb->SetRun(0);
153 AliFMDParameters* pars = AliFMDParameters::Instance();
dc02d468 154 pars->Init(this, false, AliFMDParameters::kAltroMap);
dc02d468 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
158 TList* files = 0;
dc02d468 159 AliFMDCalibSampleRate* calibRate = 0;
160 AliFMDCalibStripRange* calibRange = 0;
161 AliFMDCalibZeroSuppression* calibZero = 0;
2f7fce12 162
ae3f7f5f 163 if (GetAndCheckFileSources(files, kDAQ,pars->GetConditionsShuttleID()))
2f7fce12 164 infoCalib = GetInfoCalibration(files, calibRate, calibRange, calibZero);
165
bd44b1d9 166 resultRate = (!calibRate ? kFALSE : kTRUE);
167 resultRange = (!calibRange ? kFALSE : kTRUE);
168 resultZero = (!calibZero ? kFALSE : kTRUE);
2f7fce12 169
826a3db2 170
2f7fce12 171 // Get the run type
dc02d468 172 TString runType(GetRunType());
173
f6449cc0 174 //Creating calibration objects
dc02d468 175 AliFMDCalibPedestal* calibPed = 0;
176 AliFMDCalibGain* calibGain = 0;
bd44b1d9 177 if (runType.Contains("PEDESTAL", TString::kIgnoreCase)) {
ae3f7f5f 178 if (GetAndCheckFileSources(files, kDAQ, pars->GetPedestalShuttleID())) {
bd44b1d9 179 if(files->GetSize())
180 calibPed = GetPedestalCalibration(files);
181 }
182 resultPed = (calibPed ? kTRUE : kFALSE);
183 }
bece5229 184 if (runType.Contains("GAIN", TString::kIgnoreCase)) {
ae3f7f5f 185 if (GetAndCheckFileSources(files, kDAQ, pars->GetGainShuttleID())) {
bd44b1d9 186 if(files->GetSize())
187 calibGain = GetGainCalibration(files);
188 }
189 resultGain = (calibGain ? kTRUE : kFALSE);
190 }
f6449cc0 191
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.");
197
dc02d468 198 if(calibPed) {
826a3db2 199 resultPed = Store("Calib","Pedestal", calibPed, &metaData, 0, kTRUE);
dc02d468 200 delete calibPed;
201 }
202 if(calibGain) {
826a3db2 203 resultGain = Store("Calib","PulseGain", calibGain, &metaData, 0, kTRUE);
dc02d468 204 delete calibGain;
205 }
206 if(calibRange) {
826a3db2 207 resultRange = Store("Calib","StripRange", calibRange, &metaData, 0, kTRUE);
dc02d468 208 delete calibRange;
209 }
210 if(calibRate) {
826a3db2 211 resultRate = Store("Calib","SampleRate", calibRate, &metaData, 0, kTRUE);
dc02d468 212 delete calibRate;
213 }
214 if(calibZero) {
bd44b1d9 215 resultZero = Store("Calib","ZeroSuppression", calibZero,&metaData,0,kTRUE);
dc02d468 216 delete calibZero;
217 }
826a3db2 218
826a3db2 219 Bool_t success = (resultPed && resultGain && resultRange &&
2f7fce12 220 resultRate && resultZero && infoCalib);
221
826a3db2 222 Log(Form("FMD preprocessor was %s", (success ? "successful" : "failed")));
223 return (success ? 0 : 1);
dc02d468 224}
225
226//____________________________________________________________________
227Bool_t
228AliFMDPreprocessor::GetInfoCalibration(TList* files,
229 AliFMDCalibSampleRate*& s,
230 AliFMDCalibStripRange*& r,
231 AliFMDCalibZeroSuppression*& z)
232{
233 // Get info calibrations.
234 // Parameters:
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
239 // Return:
240 // kTRUE on success
2f7fce12 241 if (!files) return kFALSE; // Should really be false
242 if (files->GetEntries() <= 0) return kFALSE;
dc02d468 243
244 s = new AliFMDCalibSampleRate();
245 r = new AliFMDCalibStripRange();
246 z = new AliFMDCalibZeroSuppression();
247
ae3f7f5f 248 AliFMDParameters* pars = AliFMDParameters::Instance();
dc02d468 249 TIter iter(files);
250 TObjString* fileSource;
251
252 while((fileSource = dynamic_cast<TObjString*>(iter.Next()))) {
ae3f7f5f 253 const Char_t* filename = GetFile(kDAQ, pars->GetConditionsShuttleID(), fileSource->GetName());
dc02d468 254 std::ifstream in(filename);
255 if(!in) {
826a3db2 256 Log(Form("File %s not found!", filename));
dc02d468 257 continue;
258 }
b0dbd59f 259 s->ReadFromFile(in);
260 r->ReadFromFile(in);
dc02d468 261 }
262 return kTRUE;
f6449cc0 263}
264
dc02d468 265
f6449cc0 266//____________________________________________________________________
267AliFMDCalibPedestal*
268AliFMDPreprocessor::GetPedestalCalibration(TList* pedFiles)
269{
270 // Read DAQ DA produced CSV files of pedestals, and return a
271 // calibration object.
272 // Parameters:
273 // pedFiles List of pedestal files
274 // Return
275 // A pointer to a newly allocated AliFMDCalibPedestal object, or
276 // null in case of errors.
277 if(!pedFiles) return 0;
278
279 AliFMDCalibPedestal* calibPed = new AliFMDCalibPedestal();
280 AliFMDParameters* pars = AliFMDParameters::Instance();
281 TIter iter(pedFiles);
282 TObjString* fileSource;
283
284 while((fileSource = dynamic_cast<TObjString*>(iter.Next()))) {
ae3f7f5f 285 const Char_t* filename = GetFile(kDAQ, pars->GetPedestalShuttleID(), fileSource->GetName());
f6449cc0 286 std::ifstream in(filename);
287 if(!in) {
826a3db2 288 Log(Form("File %s not found!", filename));
f6449cc0 289 continue;
290 }
291
292 // Get header (how long is it ?)
293 TString header;
294 header.ReadLine(in);
295 header.ToLower();
2f7fce12 296 if(!header.Contains(pars->GetPedestalShuttleID())) {
826a3db2 297 Log("File header is not from pedestal!");
f6449cc0 298 continue;
299 }
300 Log("File contains data from pedestals");
301
302 // Read columns line
303 int lineno = 2;
304 header.ReadLine(in);
305
306 // Loop until EOF
bd44b1d9 307 while(in.peek()!=EOF) {
f6449cc0 308 if(in.bad()) {
826a3db2 309 Log(Form("Bad read at line %d in %s", lineno, filename));
f6449cc0 310 break;
311 }
3bae5d02 312 UShort_t det, sec, strip;
313 Char_t ring;
f6449cc0 314 Float_t ped, noise, mu, sigma, chi2ndf;
3bae5d02 315 Char_t c[8];
f6449cc0 316
3bae5d02 317 in >> det >> c[0]
318 >> ring >> c[1]
319 >> sec >> c[2]
320 >> strip >> c[3]
321 >> ped >> c[4]
322 >> noise >> c[5]
323 >> mu >> c[6]
324 >> sigma >> c[7]
f6449cc0 325 >> chi2ndf;
326 lineno++;
bd44b1d9 327
f6449cc0 328 // Ignore trailing garbage
3bae5d02 329 // if (strip > 127) continue;
f6449cc0 330
bd44b1d9 331 //Setting DDL to comply with the FMD in DAQ
3bae5d02 332 // UInt_t FmdDDLBase = 3072;
333 // ddl = ddl - FmdDDLBase;
f6449cc0 334 //Setting the pedestals via the hardware address
bd44b1d9 335
3bae5d02 336
337 // pars->Hardware2Detector(ddl,board,chip,channel,det,ring,sec,str);
338 // strip += str;
bd44b1d9 339
f6449cc0 340 calibPed->Set(det,ring,sec,strip,ped,noise);
bd44b1d9 341
f6449cc0 342 }
343 }
344 return calibPed;
345}
346
347//____________________________________________________________________
348AliFMDCalibGain*
349AliFMDPreprocessor::GetGainCalibration(TList* gainFiles)
350{
351 // Read DAQ DA produced CSV files of pedestals, and return a
352 // calibration object.
353 // Parameters:
354 // pedFiles List of pedestal files
355 // Return
356 // A pointer to a newly allocated AliFMDCalibPedestal object, or
357 // null in case of errors.
358 if(!gainFiles) return 0;
359
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()))) {
ae3f7f5f 365 const Char_t* filename = GetFile(kDAQ, pars->GetGainShuttleID(), fileSource->GetName());
f6449cc0 366 std::ifstream in(filename);
367 if(!in) {
826a3db2 368 Log(Form("File %s not found!", filename));
f6449cc0 369 continue;
370 }
371
372 //Get header (how long is it ?)
373 TString header;
374 header.ReadLine(in);
375 header.ToLower();
2f7fce12 376 if(!header.Contains(pars->GetGainShuttleID())) {
826a3db2 377 Log("File header is not from gain!");
f6449cc0 378 continue;
379 }
380 Log("File contains data from pulse gain");
381
382 // Read column headers
383 header.ReadLine(in);
384
385 int lineno = 2;
386 // Read until EOF
bd44b1d9 387 while(in.peek()!=EOF) {
f6449cc0 388 if(in.bad()) {
826a3db2 389 Log(Form("Bad read at line %d in %s", lineno, filename));
f6449cc0 390 break;
391 }
3bae5d02 392 UShort_t det, sec, strip;
393 Char_t ring;
394
f6449cc0 395 Float_t gain,error, chi2ndf;
3bae5d02 396 Char_t c[6];
397
398 in >> det >> c[0]
399 >> ring >> c[1]
400 >> sec >> c[2]
401 >> strip >> c[3]
402 >> gain >> c[4]
403 >> error >> c[5]
f6449cc0 404 >> chi2ndf;
405 lineno++;
406 // Ignore trailing garbage
3bae5d02 407 //if(strip > 127) continue;
f6449cc0 408
bd44b1d9 409 //Setting DDL to comply with the FMD in DAQ
3bae5d02 410 // UInt_t FmdDDLBase = 3072;
411 // ddl = ddl - FmdDDLBase;
f6449cc0 412 //Setting the pedestals via the hardware address
3bae5d02 413 // pars->Hardware2Detector(ddl,board,chip,channel,det,ring,sec,str);
f6449cc0 414
3bae5d02 415 // strip += str;
f6449cc0 416 calibGain->Set(det,ring,sec,strip,gain);
417 }
418 }
419 return calibGain;
420}
421
422//____________________________________________________________________
423//
424// EOF
425//