1 /**************************************************************************
2 * Copyright(c) 1998-1999, 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 **************************************************************************/
18 /// \class AliMUONTrackerDataMaker
20 /// Implementation of VTrackerDataMaker to read raw data and
21 /// calibrate it (if required)
23 /// \author Laurent Aphecetche, Subatech
25 #include "AliMUONTrackerDataMaker.h"
27 #include "AliCDBManager.h"
28 #include "AliCDBStorage.h"
29 #include "AliCodeTimer.h"
32 #include "AliMUON2DMap.h"
33 #include "AliMUONCalibParamND.h"
34 #include "AliMUONCalibrationData.h"
35 #include "AliMUONDigitCalibrator.h"
36 #include "AliMUONLogger.h"
37 #include "AliMUONRawStreamTrackerHP.h"
38 #include "AliMUONTrackerData.h"
39 #include "AliMpDDLStore.h"
40 #include "AliRawEventHeaderBase.h"
41 #include "AliRawReader.h"
42 #include "Riostream.h"
45 ClassImp(AliMUONTrackerDataMaker)
48 Int_t AliMUONTrackerDataMaker::fgkCounter(0);
50 //_____________________________________________________________________________
51 AliMUONTrackerDataMaker::AliMUONTrackerDataMaker(TRootIOCtor*)
53 AliMUONVTrackerDataMaker(),
55 fAccumulatedData(0x0),
56 fIsOwnerOfAccumulatedData(kTRUE),
58 fDigitCalibrator(0x0),
59 fCalibrationData(0x0),
65 fIsOwnerOfRawReader(kFALSE),
66 fIsEventByEvent(kFALSE),
68 fLastEventWasEmpty(kFALSE),
69 fNumberOfPhysicsEvents(0),
70 fNumberOfGoodPhysicsEvents(0)
75 //_____________________________________________________________________________
76 AliMUONTrackerDataMaker::AliMUONTrackerDataMaker(const AliMUONRecoParam* recoParam,
78 AliRawReader* rawReader,
80 const char* calibMode,
85 AliMUONVTrackerDataMaker(),
86 fRawReader(rawReader),
87 fAccumulatedData(0x0),
88 fIsOwnerOfAccumulatedData(kTRUE),
89 fOneEventData(new AliMUON2DMap(true)),
90 fDigitCalibrator(0x0),
91 fCalibrationData(0x0),
95 fRunNumber(runNumber),
97 fIsOwnerOfRawReader(kFALSE),
98 fIsEventByEvent(kFALSE),
100 fLastEventWasEmpty(kFALSE),
101 fNumberOfPhysicsEvents(0),
102 fNumberOfGoodPhysicsEvents(0)
104 /// Ctor in which this object will NOT be the owner of the reader
105 /// and can NOT apply rewind to it, nor use Next on it.
106 Ctor(recoParam,runNumber,calibMode,histogram,xmin,xmax);
110 //_____________________________________________________________________________
111 AliMUONTrackerDataMaker::AliMUONTrackerDataMaker(const AliMUONRecoParam* recoParam,
112 AliRawReader* rawReader,
114 const char* calibMode,
119 AliMUONVTrackerDataMaker(),
120 fRawReader(rawReader),
121 fAccumulatedData(0x0),
122 fIsOwnerOfAccumulatedData(kTRUE),
123 fOneEventData(new AliMUON2DMap(true)),
124 fDigitCalibrator(0x0),
125 fCalibrationData(0x0),
131 fIsOwnerOfRawReader(kTRUE),
132 fIsEventByEvent(kFALSE),
134 fLastEventWasEmpty(kFALSE),
135 fNumberOfPhysicsEvents(0),
136 fNumberOfGoodPhysicsEvents(0)
138 /// Ctor in which we take the ownership of the rawReader, so we can rewind
139 /// and advance it as we wish
143 fRawReader->NextEvent(); // to be sure to get run number available
144 fRunNumber = fRawReader->GetRunNumber();
145 fRawReader->RewindEvents();
148 Ctor(recoParam,fRunNumber,calibMode,histogram,xmin,xmax);
151 //_____________________________________________________________________________
152 AliMUONTrackerDataMaker::AliMUONTrackerDataMaker(AliRawReader* rawReader, Bool_t histogram)
154 AliMUONVTrackerDataMaker(),
155 fRawReader(rawReader),
156 fAccumulatedData(0x0),
157 fIsOwnerOfAccumulatedData(kTRUE),
158 fOneEventData(new AliMUON2DMap(true)),
159 fDigitCalibrator(0x0),
160 fCalibrationData(0x0),
166 fIsOwnerOfRawReader(kTRUE),
167 fIsEventByEvent(kFALSE),
169 fLastEventWasEmpty(kFALSE),
170 fNumberOfPhysicsEvents(0),
171 fNumberOfGoodPhysicsEvents(0)
173 /// Ctor from raw data reader
176 fRawReader->NextEvent(); // to be sure to get run number available
177 fRunNumber = fRawReader->GetRunNumber();
178 fRawReader->RewindEvents();
181 Ctor(0x0,fRunNumber,"",histogram);
185 //_____________________________________________________________________________
187 AliMUONTrackerDataMaker::Ctor(const AliMUONRecoParam* recoParam,
189 const char* calibMode,
191 Double_t xmin, Double_t xmax)
193 /// "designated constructor"
195 Bool_t calibrate = ( strlen(calibMode) > 0 );
202 TString scalib(calibMode);
204 if ( scalib == "GAIN" ) type = "CALC";
205 if ( scalib == "NOGAIN" ) type = "CALZ";
206 if ( scalib == "GAINCONSTANTCAPA") type = "CALG";
207 if ( scalib == "INJECTIONGAIN" ) type = "CALE";
213 name = Form("%s%s_%d",(histogram?"H":""),type.Data(),fgkCounter);
217 name = Form("%s%s%d",(histogram?"H":""),type.Data(),fRunNumber);
220 fAccumulatedData = new AliMUONTrackerData(name.Data(),"charge values",1);
221 fAccumulatedData->SetDimensionName(0,(calibrate ? "Calibrated charge" : "Raw charge"));
224 fAccumulatedData->MakeHistogramForDimension(0,kTRUE,xmin,xmax);
229 fCalibrationData = new AliMUONCalibrationData(runNumber);
231 // force the reading of calibration NOW
232 // FIXME: not really elegant and error prone (as we have the list of calib data twice,
233 // once here and once in the digitcalibrator class, hence the change of them getting
235 // But with the current CDBManager implementation, I don't know how to solve
236 // this better (e.g. to avoid clearing cache messages and so on).
238 AliCDBStorage* storage(0x0);
240 if ( fOCDBPath.Length() > 0 )
242 storage = AliCDBManager::Instance()->GetDefaultStorage();
244 if ( storage && ( storage->GetURI() != fOCDBPath.Data() ) )
246 AliCDBManager::Instance()->SetDefaultStorage(fOCDBPath.Data());
250 fCalibrationData->Pedestals();
251 fCalibrationData->Gains();
252 fCalibrationData->Neighbours();
253 fCalibrationData->HV();
254 fCalibrationData->Capacitances();
256 if ( storage && ( storage->GetURI() != fOCDBPath.Data() ) )
258 AliCDBManager::Instance()->SetDefaultStorage(storage);
261 fDigitCalibrator = new AliMUONDigitCalibrator(*fCalibrationData,recoParam,calibMode);
262 //FIXME: get the reco param from GUI and/or from OCDB if not used from the QA code ?
266 //_____________________________________________________________________________
267 AliMUONTrackerDataMaker::~AliMUONTrackerDataMaker()
271 delete fOneEventData;
272 if ( fIsOwnerOfAccumulatedData ) delete fAccumulatedData;
273 if ( fIsOwnerOfRawReader ) delete fRawReader;
274 delete fCalibrationData;
275 delete fDigitCalibrator;
278 //_____________________________________________________________________________
280 AliMUONTrackerDataMaker::Add(const AliMUONTrackerDataMaker& other)
282 /// Adds other to this
284 if (!fAccumulatedData) return kFALSE;
286 if ( fIsEventByEvent )
288 AliError("Cannot add event by event objects !");
292 if ( fRunNumber != other.fRunNumber ) fRunNumber = -1;
295 fSource += other.fSource;
297 fNumberOfEvents += other.fNumberOfEvents;
298 fNumberOfPhysicsEvents += other.fNumberOfPhysicsEvents;
299 fNumberOfGoodPhysicsEvents += other.fNumberOfGoodPhysicsEvents;
302 list.Add(other.fAccumulatedData);
304 fAccumulatedData->Merge(&list);
309 //_____________________________________________________________________________
311 AliMUONTrackerDataMaker::NextEvent()
313 /// Read and process next event
315 if ( !fIsOwnerOfRawReader )
317 AliError("I'm not the owner of the raw reader. Cannot use NextEvent");
321 AliCodeTimerAuto("",0);
323 if ( !IsRunning() ) return kTRUE;
325 Bool_t ok = fRawReader->NextEvent();
337 //_____________________________________________________________________________
338 Bool_t AliMUONTrackerDataMaker::ProcessEvent()
340 /// Process current event
342 /// Note that in case of calibration, we do not simply reuse the
343 /// AliMUONDigitCalibrator::Calibrate(AliMUONVDigitStore&) method,
344 /// as this would require filling first a digitStore, and then calibrate it,
345 /// and then convert it into a VStore, all this taking too much time.
346 /// But we *do* reuse the AliMUONDigitCalibrator::CalibrateDigit in order not to
347 /// duplicate this critical piece of calibration code !
352 Int_t eventType = fRawReader->GetType();
354 if (eventType != AliRawEventHeaderBase::kPhysicsEvent )
356 return kTRUE; // for the moment
359 ++fNumberOfPhysicsEvents;
361 fLastEventWasEmpty = kFALSE;
363 AliCodeTimerAuto("",0);
365 AliMUONRawStreamTrackerHP stream(fRawReader);
367 stream.DisableWarnings();
368 stream.DisableRawReaderErrorLogger();
369 stream.DisableMUONErrorLogger();
373 stream.EnableMUONErrorLogger();
374 stream.SetMUONErrorLogger(fLogger);
375 stream.SetLoggingDetailLevel(AliMUONRawStreamTrackerHP::kMediumErrorDetail);
378 const Int_t nddls = AliDAQ::NumberOfDdls("MUONTRK");
379 TArrayI nevents(nddls);
381 for ( Int_t i = 0; i < nddls; ++i )
386 fOneEventData->Clear();
395 while ( stream.Next(buspatchId,manuId,manuChannel,adc,kTRUE) )
397 Int_t detElemId = AliMpDDLStore::Instance()->GetDEfromBus(buspatchId);
399 Int_t ddl = AliMpDDLStore::Instance()->GetDDLfromBus(buspatchId);
403 AliMUONVCalibParam* param = static_cast<AliMUONVCalibParam*>(fOneEventData->FindObject(detElemId,manuId));
406 param = new AliMUONCalibParamND(1,64,detElemId,manuId,
407 AliMUONVCalibParam::InvalidFloatValue());
408 fOneEventData->Add(param);
411 Double_t charge(adc);
413 if ( fDigitCalibrator )
415 if ( fDigitCalibrator->IsValidDigit(detElemId, manuId, manuChannel) )
417 charge = fDigitCalibrator->CalibrateDigit(detElemId, manuId, manuChannel,adc);
427 param->SetValueAsDouble(manuChannel,0,charge);
431 Bool_t badEvent = stream.HasPaddingError() || stream.HasGlitchError();
435 fAccumulatedData->Add(*fOneEventData,&nevents);
436 if ( fOneEventData->GetSize() == 0 ) fLastEventWasEmpty = kTRUE;
437 ++fNumberOfGoodPhysicsEvents;
440 AliDebug(1,Form("n %10d nphysics %10d ngood %10d",fNumberOfEvents,fNumberOfPhysicsEvents,fNumberOfGoodPhysicsEvents));
446 //_____________________________________________________________________________
448 AliMUONTrackerDataMaker::Print(Option_t*) const
452 cout << "Source=" << Source() << " Running=" << ( IsRunning() ? "YES" : "NO")
456 //_____________________________________________________________________________
457 void AliMUONTrackerDataMaker::Rewind()
460 if ( fIsOwnerOfRawReader )
462 fRawReader->RewindEvents();
464 fNumberOfPhysicsEvents=0;
465 fNumberOfGoodPhysicsEvents=0;
469 AliError("Wrong usage of this class : cannot rewind as I am not owner of the raw reader !");
473 //_____________________________________________________________________________
474 Long64_t AliMUONTrackerDataMaker::Merge(TCollection* list)
476 /// Merge objects in collection
480 if ( list->IsEmpty() ) return NumberOfEvents();
483 const TObject* o(0x0);
485 while ( ( o = next() ) )
487 const AliMUONTrackerDataMaker* data = dynamic_cast<const AliMUONTrackerDataMaker*>(o);
490 AliError(Form("Object named %s is not an AliMUONTrackerDataMaker ! Skipping it",
495 Bool_t ok = Add(*data);
498 AliError("Got incompatible objects");
503 return NumberOfEvents();
506 //_____________________________________________________________________________
508 AliMUONTrackerDataMaker::SetRawReader(AliRawReader* rawReader)
510 /// Change the rawreader (only works if isowner=true)
512 if ( fIsOwnerOfRawReader )
514 AliFatal("Improper use of this class ! Cannot change raw reader in this case");
517 fRawReader = rawReader;