]> git.uio.no Git - u/mrichter/AliRoot.git/blame - MUON/AliMUONTrackerDataMaker.cxx
Fixing once again the QA
[u/mrichter/AliRoot.git] / MUON / AliMUONTrackerDataMaker.cxx
CommitLineData
b6f591ae 1/**************************************************************************
2* Copyright(c) 1998-1999, 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
16// $Id$
17
18/// \class AliMUONTrackerDataMaker
19///
20/// Implementation of VTrackerDataMaker to read raw data and
21/// calibrate it (if required)
22///
23/// \author Laurent Aphecetche, Subatech
24
25#include "AliMUONTrackerDataMaker.h"
26
27#include "AliCDBManager.h"
28#include "AliCDBStorage.h"
29#include "AliCodeTimer.h"
30#include "AliDAQ.h"
31#include "AliLog.h"
32#include "AliMUON2DMap.h"
33#include "AliMUONCalibParamND.h"
34#include "AliMUONCalibrationData.h"
35#include "AliMUONDigitCalibrator.h"
36#include "AliMUONRawStreamTrackerHP.h"
37#include "AliMUONTrackerData.h"
38#include "AliMpDDLStore.h"
39#include "AliRawEventHeaderBase.h"
40#include "AliRawReader.h"
41#include "Riostream.h"
42
43/// \cond CLASSIMP
44ClassImp(AliMUONTrackerDataMaker)
45/// \endcond
46
47Int_t AliMUONTrackerDataMaker::fgkCounter(0);
48
49//_____________________________________________________________________________
50AliMUONTrackerDataMaker::AliMUONTrackerDataMaker(TRootIOCtor*)
51:
52AliMUONVTrackerDataMaker(),
53fRawReader(0x0),
54fAccumulatedData(0x0),
55fOneEventData(0x0),
56fDigitCalibrator(0x0),
57fCalibrationData(0x0),
58fSource(""),
59fOCDBPath(""),
60fNumberOfEvents(0),
61fRunNumber(0),
62fIsRunning(kFALSE),
63fIsOwnerOfRawReader(kFALSE),
64fIsEventByEvent(kFALSE)
65{
cddcc1f3 66/// Root IO ctor
b6f591ae 67}
68
69//_____________________________________________________________________________
70AliMUONTrackerDataMaker::AliMUONTrackerDataMaker(const AliMUONRecoParam* recoParam,
71 Int_t runNumber,
72 AliRawReader* rawReader,
73 const char* cdbPath,
74 const char* calibMode,
75 Bool_t histogram,
76 Double_t xmin,
77 Double_t xmax)
78:
79AliMUONVTrackerDataMaker(),
80fRawReader(rawReader),
81fAccumulatedData(0x0),
82fOneEventData(new AliMUON2DMap(true)),
83fDigitCalibrator(0x0),
84fCalibrationData(0x0),
85fSource(""),
86fOCDBPath(cdbPath),
87fNumberOfEvents(0),
88fRunNumber(runNumber),
89fIsRunning(kFALSE),
90fIsOwnerOfRawReader(kFALSE),
91fIsEventByEvent(kFALSE)
92{
93 /// Ctor in which this object will NOT be the owner of the reader
94 /// and can NOT apply rewind to it, nor use Next on it.
95 Ctor(recoParam,runNumber,calibMode,histogram,xmin,xmax);
96}
97
98
99//_____________________________________________________________________________
100AliMUONTrackerDataMaker::AliMUONTrackerDataMaker(const AliMUONRecoParam* recoParam,
101 AliRawReader* rawReader,
102 const char* cdbPath,
103 const char* calibMode,
104 Bool_t histogram,
105 Double_t xmin,
106 Double_t xmax)
107:
108AliMUONVTrackerDataMaker(),
109fRawReader(rawReader),
110fAccumulatedData(0x0),
111fOneEventData(new AliMUON2DMap(true)),
112fDigitCalibrator(0x0),
113fCalibrationData(0x0),
114fSource(""),
115fOCDBPath(cdbPath),
116fNumberOfEvents(0),
117fRunNumber(0),
118fIsRunning(kFALSE),
119fIsOwnerOfRawReader(kTRUE),
120fIsEventByEvent(kFALSE)
121{
122 /// Ctor in which we take the ownership of the rawReader, so we can rewind
123 /// and advance it as we wish
124
125 if (fRawReader)
126 {
127 fRawReader->NextEvent(); // to be sure to get run number available
128 fRunNumber = fRawReader->GetRunNumber();
129 fRawReader->RewindEvents();
130 }
131
132 Ctor(recoParam,fRunNumber,calibMode,histogram,xmin,xmax);
133}
134
135//_____________________________________________________________________________
136AliMUONTrackerDataMaker::AliMUONTrackerDataMaker(AliRawReader* rawReader, Bool_t histogram)
137:
138AliMUONVTrackerDataMaker(),
139fRawReader(rawReader),
140fAccumulatedData(0x0),
141fOneEventData(new AliMUON2DMap(true)),
142fDigitCalibrator(0x0),
143fCalibrationData(0x0),
144fSource(""),
145fOCDBPath(""),
146fNumberOfEvents(0),
147fRunNumber(0),
148fIsRunning(kFALSE),
149fIsOwnerOfRawReader(kTRUE),
150fIsEventByEvent(kFALSE)
151{
152 if (fRawReader)
153 {
154 fRawReader->NextEvent(); // to be sure to get run number available
155 fRunNumber = fRawReader->GetRunNumber();
156 fRawReader->RewindEvents();
157 }
158
159 Ctor(0x0,fRunNumber,"",histogram);
160
161}
162
163//_____________________________________________________________________________
164void
165AliMUONTrackerDataMaker::Ctor(const AliMUONRecoParam* recoParam,
166 Int_t runNumber,
167 const char* calibMode,
168 Bool_t histogram,
169 Double_t xmin, Double_t xmax)
170{
171 /// "designated constructor"
172 Bool_t calibrate = ( fOCDBPath.Length() > 0 );
173
174 TString name;
175 TString type("RAW");
176
177 if ( calibrate )
178 {
179 TString scalib(calibMode);
180 scalib.ToUpper();
181 if ( scalib == "GAIN" ) type = "CALC";
182 if ( scalib == "NOGAIN" ) type = "CALZ";
183 if ( scalib == "GAINCONSTANTCAPA") type = "CALG";
184 }
185
186 if ( !fRunNumber )
187 {
188 ++fgkCounter;
189 name = Form("%s%s_%d",(histogram?"H":""),type.Data(),fgkCounter);
190 }
191 else
192 {
193 name = Form("%s%s%d",(histogram?"H":""),type.Data(),fRunNumber);
194 }
195
196 fAccumulatedData = new AliMUONTrackerData(name.Data(),"charge values",1);
197 fAccumulatedData->SetDimensionName(0,(calibrate ? "Calibrated charge" : "Raw charge"));
198 if (histogram)
199 {
200 fAccumulatedData->MakeHistogramForDimension(0,kTRUE,xmin,xmax);
201 }
202
203 if ( calibrate )
204 {
205 fCalibrationData = new AliMUONCalibrationData(runNumber);
206
207 // force the reading of calibration NOW
208 // FIXME: not really elegant and error prone (as we have the list of calib data twice,
209 // once here and once in the digitcalibrator class, hence the change of them getting
210 // out of sync)
211 // But with the current CDBManager implementation, I don't know how to solve
212 // this better (e.g. to avoid clearing cache messages and so on).
213
214 AliCDBStorage* storage = AliCDBManager::Instance()->GetDefaultStorage();
215
216 if ( storage->GetURI() != fOCDBPath.Data() )
217 {
218 AliCDBManager::Instance()->SetDefaultStorage(fOCDBPath.Data());
219 }
220
221 fCalibrationData->Pedestals();
222 fCalibrationData->Gains();
223 fCalibrationData->Neighbours();
224 fCalibrationData->HV();
225 fCalibrationData->Capacitances();
226
227 if ( storage->GetURI() != fOCDBPath.Data() )
228 {
229 AliCDBManager::Instance()->SetDefaultStorage(storage);
230 }
231
232 fDigitCalibrator = new AliMUONDigitCalibrator(*fCalibrationData,recoParam,calibMode);
233 //FIXME: get the reco param from GUI and/or from OCDB if not used from the QA code ?
234 }
235}
236
237//_____________________________________________________________________________
238AliMUONTrackerDataMaker::~AliMUONTrackerDataMaker()
239{
cddcc1f3 240/// dtor
241
b6f591ae 242 delete fOneEventData;
243 delete fAccumulatedData;
244 if ( fIsOwnerOfRawReader ) delete fRawReader;
245 delete fCalibrationData;
246 delete fDigitCalibrator;
247}
248
249//_____________________________________________________________________________
250Bool_t
251AliMUONTrackerDataMaker::Add(const AliMUONTrackerDataMaker& other)
252{
253 /// Adds other to this
254
255 if (!fAccumulatedData) return kFALSE;
256
257 if ( fIsEventByEvent )
258 {
259 AliError("Cannot add event by event objects !");
260 return kFALSE;
261 }
262
263 if ( fRunNumber != other.fRunNumber ) fRunNumber = -1;
264
265 fSource += "\n";
266 fSource += other.fSource;
267
268 fNumberOfEvents += other.fNumberOfEvents;
269
270 TList list;
271 list.Add(other.fAccumulatedData);
272
273 fAccumulatedData->Merge(&list);
274
275 return kTRUE;
276}
277
278//_____________________________________________________________________________
279Bool_t
280AliMUONTrackerDataMaker::NextEvent()
281{
282 /// Read and process next event
283
284 if ( !fIsOwnerOfRawReader )
285 {
286 AliError("I'm not the owner of the raw reader. Cannot use NextEvent");
287 return kFALSE;
288 }
289
290 AliCodeTimerAuto("");
291
292 static Int_t nphysics(0);
293 static Int_t ngood(0);
294
295 if ( !IsRunning() ) return kTRUE;
296
297 Bool_t ok = fRawReader->NextEvent();
298
299 if (!ok)
300 {
301 return kFALSE;
302 }
303
304 Int_t eventType = fRawReader->GetType();
305
306 ++fNumberOfEvents;
307
308 if (eventType != AliRawEventHeaderBase::kPhysicsEvent )
309 {
310 return kTRUE; // for the moment
311 }
312
313 ++nphysics;
314
315 Bool_t pok = ProcessEvent();
316
317 if ( pok ) ++ngood;
318
319 AliDebug(1,Form("n %10d nphysics %10d ngood %10d",fNumberOfEvents,nphysics,ngood));
320
321 return kTRUE;
322}
323
324//_____________________________________________________________________________
325Bool_t AliMUONTrackerDataMaker::ProcessEvent()
326{
327 /// Process current event
328 ///
329 /// Note that in case of calibration, we do not simply reuse the
330 /// AliMUONDigitCalibrator::Calibrate(AliMUONVDigitStore&) method,
331 /// as this would require filling first a digitStore, and then calibrate it,
332 /// and then convert it into a VStore, all this taking too much time.
333 /// But we *do* reuse the AliMUONDigitCalibrator::CalibrateDigit in order not to
334 /// duplicate this critical piece of calibration code !
335 ///
336
337 AliCodeTimerAuto("");
338
339 AliMUONRawStreamTrackerHP stream(fRawReader);
340
341 stream.DisableWarnings();
342// stream.EnabbleErrorLogger();
343
344 const Int_t nddls = AliDAQ::NumberOfDdls("MUONTRK");
345 TArrayI nevents(nddls);
346
347 for ( Int_t i = 0; i < nddls; ++i )
348 {
349 nevents[i] = 0;
350 }
351
352 fOneEventData->Clear();
353
354 Int_t buspatchId;
355 UShort_t manuId;
356 UChar_t manuChannel;
357 UShort_t adc;
358
359 stream.First();
360
361 while ( stream.Next(buspatchId,manuId,manuChannel,adc,kTRUE) )
362 {
363 Int_t detElemId = AliMpDDLStore::Instance()->GetDEfromBus(buspatchId);
364
365 Int_t ddl = AliMpDDLStore::Instance()->GetDDLfromBus(buspatchId);
366
367 nevents[ddl] = 1;
368
369 AliMUONVCalibParam* param = static_cast<AliMUONVCalibParam*>(fOneEventData->FindObject(detElemId,manuId));
370 if (!param)
371 {
372 param = new AliMUONCalibParamND(1,64,detElemId,manuId,
373 AliMUONVCalibParam::InvalidFloatValue());
374 fOneEventData->Add(param);
375 }
376
377 Double_t charge(adc);
378
379 if ( fDigitCalibrator )
380 {
381 if ( fDigitCalibrator->IsValidDigit(detElemId, manuId, manuChannel) )
382 {
383 charge = fDigitCalibrator->CalibrateDigit(detElemId, manuId, manuChannel,adc,3.0);
384 }
2b8a1212 385 else
386 {
387 charge = 0.0;
388 }
b6f591ae 389 }
390
391 if (charge > 0.0 )
392 {
393 param->SetValueAsDouble(manuChannel,0,charge);
394 }
395 }
396
397 Bool_t badEvent = stream.HasPaddingError() || stream.HasGlitchError();
398
399 if (!badEvent)
400 {
401 fAccumulatedData->Add(*fOneEventData,&nevents);
402 }
403
404 return !badEvent;
405}
406
407
408//_____________________________________________________________________________
409void
410AliMUONTrackerDataMaker::Print(Option_t*) const
411{
412 /// Printout
413
414 cout << "Source=" << Source() << " Running=" << ( IsRunning() ? "YES" : "NO")
415 << endl;
416}
417
418//_____________________________________________________________________________
419void AliMUONTrackerDataMaker::Rewind()
420{
421 /// Rewind events
422 if ( fIsOwnerOfRawReader )
423 {
424 fRawReader->RewindEvents();
425 fNumberOfEvents=0;
426 }
427 else
428 {
429 AliError("Wrong usage of this class : cannot rewind as I am not owner of the raw reader !");
430 }
431}
432
433//_____________________________________________________________________________
434Long64_t AliMUONTrackerDataMaker::Merge(TCollection* list)
435{
436 /// Merge objects in collection
437
438 if (!list) return 0;
439
440 if ( list->IsEmpty() ) return NumberOfEvents();
441
442 TIter next(list);
443 const TObject* o(0x0);
444
445 while ( ( o = next() ) )
446 {
447 const AliMUONTrackerDataMaker* data = dynamic_cast<const AliMUONTrackerDataMaker*>(o);
448 if (!o)
449 {
450 AliError(Form("Object named %s is not an AliMUONTrackerDataMaker ! Skipping it",
451 o->GetName()));
452 }
453 else
454 {
455 Bool_t ok = Add(*data);
456 if (!ok)
457 {
458 AliError("Got incompatible objects");
459 }
460 }
461 }
462
463 return NumberOfEvents();
464}
465
466//_____________________________________________________________________________
467void
468AliMUONTrackerDataMaker::SetRawReader(AliRawReader* rawReader)
469{
470 /// Change the rawreader (only works if isowner=true)
471
472 if ( fIsOwnerOfRawReader )
473 {
474 AliFatal("Improper use of this class ! Cannot change raw reader in this case");
475 }
476
477 fRawReader = rawReader;
478
479}