AliRoot Core  edcc906 (edcc906)
AliMUONTrackerDataMaker.cxx
Go to the documentation of this file.
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 
24 
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 "AliMUONLogger.h"
38 #include "AliMUONTrackerData.h"
39 #include "AliMpDDLStore.h"
40 #include "AliRawEventHeaderBase.h"
41 #include "AliRawReader.h"
42 #include "Riostream.h"
43 
44 using std::endl;
45 using std::cout;
49 
50 Int_t AliMUONTrackerDataMaker::fgkCounter(0);
51 
52 //_____________________________________________________________________________
54 :
56 fRawReader(0x0),
57 fAccumulatedData(0x0),
58 fIsOwnerOfAccumulatedData(kTRUE),
59 fOneEventData(0x0),
60 fDigitCalibrator(0x0),
61 fCalibrationData(0x0),
62 fSource(""),
63 fOCDBPath(""),
64 fNumberOfEvents(0),
65 fRunNumber(0),
66 fIsRunning(kFALSE),
67 fIsOwnerOfRawReader(kFALSE),
68 fIsEventByEvent(kFALSE),
69 fLogger(0x0),
70 fLastEventWasEmpty(kFALSE),
71 fNumberOfPhysicsEvents(0),
72 fNumberOfGoodPhysicsEvents(0),
73 fTryRecover(kFALSE),
74 fFirstEvent(-1),
75 fLastEvent(-1)
76 {
78 }
79 
80 //_____________________________________________________________________________
82  Int_t runNumber,
83  AliRawReader* rawReader,
84  const char* cdbPath,
85  const char* calibMode,
86  Bool_t histogram,
87  Double_t xmin,
88  Double_t xmax)
89 :
91 fRawReader(rawReader),
92 fAccumulatedData(0x0),
93 fIsOwnerOfAccumulatedData(kTRUE),
94 fOneEventData(new AliMUON2DMap(true)),
95 fDigitCalibrator(0x0),
96 fCalibrationData(0x0),
97 fSource(""),
98 fOCDBPath(cdbPath),
99 fNumberOfEvents(0),
100 fRunNumber(runNumber),
101 fIsRunning(kFALSE),
102 fIsOwnerOfRawReader(kFALSE),
103 fIsEventByEvent(kFALSE),
104 fLogger(0x0),
105 fLastEventWasEmpty(kFALSE),
106 fNumberOfPhysicsEvents(0),
107 fNumberOfGoodPhysicsEvents(0),
108 fTryRecover(kFALSE),
109 fFirstEvent(-1),
110 fLastEvent(-1)
111 {
114  Ctor(recoParam,runNumber,calibMode,histogram,xmin,xmax);
115 }
116 
117 
118 //_____________________________________________________________________________
120  AliRawReader* rawReader,
121  const char* cdbPath,
122  const char* calibMode,
123  Bool_t histogram,
124  Double_t xmin,
125  Double_t xmax)
126 :
128 fRawReader(rawReader),
129 fAccumulatedData(0x0),
131 fOneEventData(new AliMUON2DMap(true)),
132 fDigitCalibrator(0x0),
133 fCalibrationData(0x0),
134 fSource(""),
135 fOCDBPath(cdbPath),
136 fNumberOfEvents(0),
137 fRunNumber(0),
138 fIsRunning(kFALSE),
139 fIsOwnerOfRawReader(kTRUE),
140 fIsEventByEvent(kFALSE),
141 fLogger(0x0),
142 fLastEventWasEmpty(kFALSE),
145 fTryRecover(kFALSE),
146 fFirstEvent(-1),
147 fLastEvent(-1)
148 {
151 
152  if ( fRawReader && fRawReader->NextEvent() )
153  {
154  fRunNumber = fRawReader->GetRunNumber();
155  fRawReader->RewindEvents();
156  }
157 
158  Ctor(recoParam,fRunNumber,calibMode,histogram,xmin,xmax);
159 }
160 
161 //_____________________________________________________________________________
162 AliMUONTrackerDataMaker::AliMUONTrackerDataMaker(AliRawReader* rawReader, Bool_t histogram)
163 :
165 fRawReader(rawReader),
166 fAccumulatedData(0x0),
168 fOneEventData(new AliMUON2DMap(true)),
169 fDigitCalibrator(0x0),
170 fCalibrationData(0x0),
171 fSource(""),
172 fOCDBPath(""),
173 fNumberOfEvents(0),
174 fRunNumber(0),
175 fIsRunning(kFALSE),
176 fIsOwnerOfRawReader(kTRUE),
177 fIsEventByEvent(kFALSE),
178 fLogger(0x0),
179 fLastEventWasEmpty(kFALSE),
182 fTryRecover(kFALSE),
183 fFirstEvent(-1),
184 fLastEvent(-1)
185 {
187  if ( fRawReader && fRawReader->NextEvent() )
188  {
189  fRunNumber = fRawReader->GetRunNumber();
190  fRawReader->RewindEvents();
191  }
192 
193  Ctor(0x0,fRunNumber,"",histogram);
194 
195 }
196 
197 //_____________________________________________________________________________
198 void
200  Int_t runNumber,
201  const char* calibMode,
202  Bool_t histogram,
203  Double_t xmin, Double_t xmax)
204 {
206 
207  Bool_t calibrate = ( strlen(calibMode) > 0 );
208 
209  TString name;
210  TString type("RAW");
211 
212  if ( calibrate )
213  {
214  TString scalib(calibMode);
215  scalib.ToUpper();
216  if ( scalib == "GAIN" ) type = "CALC";
217  if ( scalib == "NOGAIN" ) type = "CALZ";
218  if ( scalib == "GAINCONSTANTCAPA") type = "CALG";
219  if ( scalib == "INJECTIONGAIN" ) type = "CALE";
220  }
221 
222  if ( !fRunNumber )
223  {
224  ++fgkCounter;
225  name = Form("%s%s_%d",(histogram?"H":""),type.Data(),fgkCounter);
226  }
227  else
228  {
229  name = Form("%s%s%d",(histogram?"H":""),type.Data(),fRunNumber);
230  }
231 
232  fAccumulatedData = new AliMUONTrackerData(name.Data(),"charge values",1);
233  fAccumulatedData->SetDimensionName(0,(calibrate ? "Calibrated charge" : "Raw charge"));
234  if (histogram)
235  {
236  fAccumulatedData->MakeHistogramForDimension(0,kTRUE,xmin,xmax);
237  }
238 
239  if ( calibrate )
240  {
241  fCalibrationData = new AliMUONCalibrationData(runNumber);
242 
243  // force the reading of calibration NOW
244  // FIXME: not really elegant and error prone (as we have the list of calib data twice,
245  // once here and once in the digitcalibrator class, hence the change of them getting
246  // out of sync)
247  // But with the current CDBManager implementation, I don't know how to solve
248  // this better (e.g. to avoid clearing cache messages and so on).
249 
250  AliCDBStorage* storage(0x0);
251 
252  if ( fOCDBPath.Length() > 0 )
253  {
255 
256  if ( storage && ( storage->GetURI() != fOCDBPath.Data() ) )
257  {
259  }
260  }
261 
264  fCalibrationData->HV();
265 
266  if ( storage && ( storage->GetURI() != fOCDBPath.Data() ) )
267  {
269  }
270 
272  //FIXME: get the reco param from GUI and/or from OCDB if not used from the QA code ?
273  }
274 }
275 
276 //_____________________________________________________________________________
278 {
280 
281  delete fOneEventData;
283  if ( fIsOwnerOfRawReader ) delete fRawReader;
284  delete fCalibrationData;
285  delete fDigitCalibrator;
286 }
287 
288 //_____________________________________________________________________________
289 Bool_t
291 {
293 
294  if (!fAccumulatedData) return kFALSE;
295 
296  if ( fIsEventByEvent )
297  {
298  AliError("Cannot add event by event objects !");
299  return kFALSE;
300  }
301 
302  if ( fRunNumber != other.fRunNumber ) fRunNumber = -1;
303 
304  fSource += "\n";
305  fSource += other.fSource;
306 
310 
311  TList list;
312  list.Add(other.fAccumulatedData);
313 
314  fAccumulatedData->Merge(&list);
315 
316  return kTRUE;
317 }
318 
319 //_____________________________________________________________________________
320 Bool_t
322 {
324 
325  if ( !fIsOwnerOfRawReader )
326  {
327  AliError("I'm not the owner of the raw reader. Cannot use NextEvent");
328  return kFALSE;
329  }
330 
331  AliCodeTimerAuto("",0);
332 
333  if ( !IsRunning() ) return kTRUE;
334 
335  Bool_t ok(kTRUE);
336 
337  if ( fLastEvent >= fFirstEvent && fLastEvent > 0 ) // do we have an event range to consider ?
338  {
339  // skip up to first event
340 
341  while ( (fNumberOfEvents-1) < fFirstEvent && ( ok = fRawReader->NextEvent() ) )
342  {
343  ++fNumberOfEvents;
344  }
345 
346  if ( ok && (fNumberOfEvents-1) <= fLastEvent )
347  {
348  ok = fRawReader->NextEvent();
349  }
350  else
351  {
353  return kFALSE;
354  }
355  }
356  else
357  {
358  // no event range, just proceed...
359  ok = fRawReader->NextEvent();
360  }
361 
362  if (!ok)
363  {
364  return kFALSE;
365  }
366 
367  ProcessEvent();
368 
369  return kTRUE;
370 }
371 
372 //_____________________________________________________________________________
374 {
384 
385  ++fNumberOfEvents;
386 
387  Int_t eventType = fRawReader->GetType();
388 
389  if (eventType != AliRawEventHeaderBase::kPhysicsEvent )
390  {
391  return kTRUE; // for the moment
392  }
393 
395 
396  fLastEventWasEmpty = kFALSE;
397 
398  AliCodeTimerAuto("",0);
399 
401 
402  stream.DisableWarnings();
404  stream.DisableMUONErrorLogger();
405 
406  if ( fTryRecover )
407  {
408  stream.TryRecover(kTRUE);
409  }
410  else
411  {
412  stream.TryRecover(kFALSE);
413  }
414 
415  if (fLogger)
416  {
417  stream.EnableMUONErrorLogger();
418  stream.SetMUONErrorLogger(fLogger);
420  }
421 
422  const Int_t nddls = AliDAQ::NumberOfDdls("MUONTRK");
423  TArrayI nevents(nddls);
424 
425  for ( Int_t i = 0; i < nddls; ++i )
426  {
427  nevents[i] = 0;
428  }
429 
430  fOneEventData->Clear();
431 
432  Int_t buspatchId;
433  UShort_t manuId;
434  UChar_t manuChannel;
435  UShort_t adc;
436 
437  stream.First();
438 
439  while ( stream.Next(buspatchId,manuId,manuChannel,adc,kTRUE) )
440  {
441  Int_t detElemId = AliMpDDLStore::Instance()->GetDEfromBus(buspatchId);
442 
443  Int_t ddl = AliMpDDLStore::Instance()->GetDDLfromBus(buspatchId);
444 
445  nevents[ddl] = 1;
446 
447  AliMUONVCalibParam* param = static_cast<AliMUONVCalibParam*>(fOneEventData->FindObject(detElemId,manuId));
448  if (!param)
449  {
450  param = new AliMUONCalibParamND(1,64,detElemId,manuId,
452  fOneEventData->Add(param);
453  }
454 
455  Double_t charge(adc);
456 
457  if ( fDigitCalibrator )
458  {
459  if ( fDigitCalibrator->IsValidDigit(detElemId, manuId, manuChannel) )
460  {
461  charge = fDigitCalibrator->CalibrateDigit(detElemId, manuId, manuChannel,adc);
462  }
463  else
464  {
465  charge = 0.0;
466  }
467  }
468 
469  if (charge > 0.0 )
470  {
471  param->SetValueAsDouble(manuChannel,0,charge);
472  }
473  }
474 
475  Bool_t badEvent = stream.HasPaddingError() || stream.HasGlitchError();
476 
477  if (!badEvent)
478  {
479  fAccumulatedData->Add(*fOneEventData,&nevents);
480  if ( fOneEventData->GetSize() == 0 ) fLastEventWasEmpty = kTRUE;
482  }
483 
484  AliDebug(1,Form("n %10d nphysics %10d ngood %10d",fNumberOfEvents,fNumberOfPhysicsEvents,fNumberOfGoodPhysicsEvents));
485 
486  return !badEvent;
487 }
488 
489 
490 //_____________________________________________________________________________
491 void
493 {
495 
496  cout << "Source=" << Source() << " Running=" << ( IsRunning() ? "YES" : "NO")
497  << endl;
498 }
499 
500 //_____________________________________________________________________________
502 {
504  if ( fIsOwnerOfRawReader )
505  {
506  fRawReader->RewindEvents();
507  fNumberOfEvents=0;
510  }
511  else
512  {
513  AliError("Wrong usage of this class : cannot rewind as I am not owner of the raw reader !");
514  }
515 }
516 
517 //_____________________________________________________________________________
518 Long64_t AliMUONTrackerDataMaker::Merge(TCollection* list)
519 {
521 
522  if (!list) return 0;
523 
524  if ( list->IsEmpty() ) return NumberOfEvents();
525 
526  TIter next(list);
527  const TObject* o(0x0);
528 
529  while ( ( o = next() ) )
530  {
531  const AliMUONTrackerDataMaker* data = dynamic_cast<const AliMUONTrackerDataMaker*>(o);
532  if (!data)
533  {
534  AliError(Form("Object named %s is not an AliMUONTrackerDataMaker ! Skipping it",
535  o->GetName()));
536  }
537  else
538  {
539  Bool_t ok = Add(*data);
540  if (!ok)
541  {
542  AliError("Got incompatible objects");
543  }
544  }
545  }
546 
547  return NumberOfEvents();
548 }
549 
550 //_____________________________________________________________________________
551 void
553 {
555 
556  if ( fIsOwnerOfRawReader )
557  {
558  AliFatal("Improper use of this class ! Cannot change raw reader in this case");
559  }
560 
561  fRawReader = rawReader;
562 
563 }
A high performance stream decoder for muon tracking DDL streams.
const TString & GetURI() const
Definition: AliCDBStorage.h:34
void DisableRawReaderErrorLogger()
Disable logging to the raw reader.
Implementation of AliMUONVTrackerData.
Int_t fRunNumber
run number of the data
static Float_t InvalidFloatValue()
Return 1E38 as invalid float value.
virtual Long64_t Merge(TCollection *list)=0
To allow merging of different objects.
TMap * HV(Bool_t patched=kTRUE) const
Get the HV values. Use patched=kFALSE to get unprocessed (i.e. "raw") values as they are in the OCDB...
Bool_t IsRunning() const
Whether we are running or not.
AliMUONVStore * Neighbours() const
Get the neighbours store.
TString fSource
where the data comes from
Long64_t Merge(TCollection *li)
Merge.
virtual Int_t GetSize() const =0
The number of objects stored.
Int_t GetDEfromBus(Int_t busPatchId) const
Producer of some AliMUONVTrackerData.
virtual void SetDimensionName(Int_t index, const char *value)
Set the name of a given dimension.
Class with MUON reconstruction parameters.
void SetLoggingDetailLevel(EDetailLevel level)
Sets the level of detail used in the error messages.
Bool_t fIsEventByEvent
we only keep one event&#39;s data (no accumulation)
AliMUONVStore * fOneEventData
data for a single event (owner)
void DisableWarnings()
Set warnings flag to disable warnings on data errors.
AliRawReader * fRawReader
! reader of the data (owner or not)
Bool_t TryRecover() const
Returns the "try to recover from errors" flag.
Container of calibration values for a given number of channels.
static AliMpDDLStore * Instance(Bool_t warn=true)
Bool_t NextEvent()
Advance to next event and process it (no effect if not runnable)
Bool_t HasPaddingError() const
Whether we got padding errors or not.
Float_t CalibrateDigit(Int_t detElemId, Int_t manuId, Int_t manuChannel, Float_t adc, Float_t nsigmas=-1, Bool_t *isSaturated=0x0) const
void SetMUONErrorLogger(AliMUONLogger *logger)
Sets the logger object to use. Ownership of the logger object remains with the caller.
void Print(Option_t *opt="") const
Class to calibrate the digits.
Int_t fNumberOfGoodPhysicsEvents
number of errors with no (fatal) readout error
Int_t fFirstEvent
first event to consider
#define AliCodeTimerAuto(message, counter)
Definition: AliCodeTimer.h:137
Implementation of AliMUONVCalibParam for tuples of double.
Logs minimal information in the error messages.
Int_t fLastEvent
last event to consider
Bool_t ProcessEvent()
Process current event.
Bool_t fTryRecover
whether we should try to recover corrupted raw data
AliMUONVStore * Pedestals() const
Get the pedestal store.
AliMUONDigitCalibrator * fDigitCalibrator
! digit calibrator (if calibrating)
Bool_t fIsRunning
whether we are running or not
#define AliFatal(message)
Definition: AliLog.h:640
void DisableMUONErrorLogger()
Disable logging to AliMUONLogger.
Basic implementation of AliMUONVStore container using AliMpExMap internally.
Definition: AliMUON2DMap.h:20
void SetDefaultStorage(const char *dbString)
Int_t NumberOfEvents() const
Number of events seen.
virtual Bool_t Add(TObject *object)=0
Add an object to the store.
Bool_t HasGlitchError() const
Whether we got glitch errors or not.
#define AliDebug(logLevel, message)
Definition: AliLog.h:300
Single entry point to access MUON calibration data.
Implementation of VTrackerDataMaker to read raw data.
virtual void First()
Initialize iterator.
void Rewind()
Rewind events (no effect if not runnable)
AliMUONCalibrationData * fCalibrationData
calibration data (if calibrating)
static Int_t fgkCounter
to count the number of instances
TString fOCDBPath
OCDB path (if calibrating)
virtual Bool_t Add(const AliMUONVStore &store, TArrayI *arrayOfNofEventsPerDDL=0x0)=0
Add values for one event from one full store.
AliMUONVTrackerData * fAccumulatedData
data (owner or not)
Bool_t fIsOwnerOfRawReader
whether we must delete rawReader or not
void Ctor(const AliMUONRecoParam *param, Int_t runNumber, const char *calibMode, Bool_t histogram, Double_t xmin=0.0, Double_t xmax=4095.0)
TString Source() const
Get our source URI.
AliCDBStorage * GetDefaultStorage() const
Definition: AliCDBManager.h:61
static Int_t runNumber
Definition: pdc06_config.C:126
AliMUONLogger * fLogger
error logger (not owner)
virtual void Clear(Option_t *opt="")=0
Clear ourselves (i.e. Reset)
Int_t fNumberOfPhysicsEvents
number of physics events seen
#define AliError(message)
Definition: AliLog.h:591
Bool_t Add(const AliMUONTrackerDataMaker &other)
static AliCDBManager * Instance(TMap *entryCache=NULL, Int_t run=-1)
void SetRawReader(AliRawReader *rawReader)
static Int_t NumberOfDdls(const char *detectorName)
Definition: AliDAQ.cxx:368
Bool_t IsValidDigit(Int_t detElemId, Int_t manuId, Int_t manuChannel, Int_t *statusMap=0x0) const
void EnableMUONErrorLogger()
Enable error info logging to AliMUONLogger.
Int_t fNumberOfEvents
number of events seen
Bool_t fIsOwnerOfAccumulatedData
owner or not of fAccumulatedData
Declaration of the high performance decoder for muon trigger chamber raw streams. ...
Int_t GetDDLfromBus(Int_t busPatchId) const
virtual Bool_t Next(Int_t &busPatchId, UShort_t &manuId, UChar_t &manuChannel, UShort_t &adc)
Advance one step in the iteration. Returns false if finished.
Bool_t fLastEventWasEmpty
whether last decoded event was empty
virtual TObject * FindObject(const char *name) const
Find an object by name.
virtual void SetValueAsDouble(Int_t i, Int_t j, Double_t value)