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),
57 fDigitCalibrator(0x0),
58 fCalibrationData(0x0),
64 fIsOwnerOfRawReader(kFALSE),
65 fIsEventByEvent(kFALSE),
71 //_____________________________________________________________________________
72 AliMUONTrackerDataMaker::AliMUONTrackerDataMaker(const AliMUONRecoParam* recoParam,
74 AliRawReader* rawReader,
76 const char* calibMode,
81 AliMUONVTrackerDataMaker(),
82 fRawReader(rawReader),
83 fAccumulatedData(0x0),
84 fOneEventData(new AliMUON2DMap(true)),
85 fDigitCalibrator(0x0),
86 fCalibrationData(0x0),
90 fRunNumber(runNumber),
92 fIsOwnerOfRawReader(kFALSE),
93 fIsEventByEvent(kFALSE),
96 /// Ctor in which this object will NOT be the owner of the reader
97 /// and can NOT apply rewind to it, nor use Next on it.
98 Ctor(recoParam,runNumber,calibMode,histogram,xmin,xmax);
102 //_____________________________________________________________________________
103 AliMUONTrackerDataMaker::AliMUONTrackerDataMaker(const AliMUONRecoParam* recoParam,
104 AliRawReader* rawReader,
106 const char* calibMode,
111 AliMUONVTrackerDataMaker(),
112 fRawReader(rawReader),
113 fAccumulatedData(0x0),
114 fOneEventData(new AliMUON2DMap(true)),
115 fDigitCalibrator(0x0),
116 fCalibrationData(0x0),
122 fIsOwnerOfRawReader(kTRUE),
123 fIsEventByEvent(kFALSE),
126 /// Ctor in which we take the ownership of the rawReader, so we can rewind
127 /// and advance it as we wish
131 fRawReader->NextEvent(); // to be sure to get run number available
132 fRunNumber = fRawReader->GetRunNumber();
133 fRawReader->RewindEvents();
136 Ctor(recoParam,fRunNumber,calibMode,histogram,xmin,xmax);
139 //_____________________________________________________________________________
140 AliMUONTrackerDataMaker::AliMUONTrackerDataMaker(AliRawReader* rawReader, Bool_t histogram)
142 AliMUONVTrackerDataMaker(),
143 fRawReader(rawReader),
144 fAccumulatedData(0x0),
145 fOneEventData(new AliMUON2DMap(true)),
146 fDigitCalibrator(0x0),
147 fCalibrationData(0x0),
153 fIsOwnerOfRawReader(kTRUE),
154 fIsEventByEvent(kFALSE),
157 /// Ctor from raw data reader
160 fRawReader->NextEvent(); // to be sure to get run number available
161 fRunNumber = fRawReader->GetRunNumber();
162 fRawReader->RewindEvents();
165 Ctor(0x0,fRunNumber,"",histogram);
169 //_____________________________________________________________________________
171 AliMUONTrackerDataMaker::Ctor(const AliMUONRecoParam* recoParam,
173 const char* calibMode,
175 Double_t xmin, Double_t xmax)
177 /// "designated constructor"
179 Bool_t calibrate = ( strlen(calibMode) > 0 );
186 TString scalib(calibMode);
188 if ( scalib == "GAIN" ) type = "CALC";
189 if ( scalib == "NOGAIN" ) type = "CALZ";
190 if ( scalib == "GAINCONSTANTCAPA") type = "CALG";
191 if ( scalib == "INJECTIONGAIN" ) type = "CALE";
197 name = Form("%s%s_%d",(histogram?"H":""),type.Data(),fgkCounter);
201 name = Form("%s%s%d",(histogram?"H":""),type.Data(),fRunNumber);
204 fAccumulatedData = new AliMUONTrackerData(name.Data(),"charge values",1);
205 fAccumulatedData->SetDimensionName(0,(calibrate ? "Calibrated charge" : "Raw charge"));
208 fAccumulatedData->MakeHistogramForDimension(0,kTRUE,xmin,xmax);
213 fCalibrationData = new AliMUONCalibrationData(runNumber);
215 // force the reading of calibration NOW
216 // FIXME: not really elegant and error prone (as we have the list of calib data twice,
217 // once here and once in the digitcalibrator class, hence the change of them getting
219 // But with the current CDBManager implementation, I don't know how to solve
220 // this better (e.g. to avoid clearing cache messages and so on).
222 AliCDBStorage* storage(0x0);
224 if ( fOCDBPath.Length() > 0 )
226 storage = AliCDBManager::Instance()->GetDefaultStorage();
228 if ( storage && ( storage->GetURI() != fOCDBPath.Data() ) )
230 AliCDBManager::Instance()->SetDefaultStorage(fOCDBPath.Data());
234 fCalibrationData->Pedestals();
235 fCalibrationData->Gains();
236 fCalibrationData->Neighbours();
237 fCalibrationData->HV();
238 fCalibrationData->Capacitances();
240 if ( storage && ( storage->GetURI() != fOCDBPath.Data() ) )
242 AliCDBManager::Instance()->SetDefaultStorage(storage);
245 fDigitCalibrator = new AliMUONDigitCalibrator(*fCalibrationData,recoParam,calibMode);
246 //FIXME: get the reco param from GUI and/or from OCDB if not used from the QA code ?
250 //_____________________________________________________________________________
251 AliMUONTrackerDataMaker::~AliMUONTrackerDataMaker()
255 delete fOneEventData;
256 delete fAccumulatedData;
257 if ( fIsOwnerOfRawReader ) delete fRawReader;
258 delete fCalibrationData;
259 delete fDigitCalibrator;
262 //_____________________________________________________________________________
264 AliMUONTrackerDataMaker::Add(const AliMUONTrackerDataMaker& other)
266 /// Adds other to this
268 if (!fAccumulatedData) return kFALSE;
270 if ( fIsEventByEvent )
272 AliError("Cannot add event by event objects !");
276 if ( fRunNumber != other.fRunNumber ) fRunNumber = -1;
279 fSource += other.fSource;
281 fNumberOfEvents += other.fNumberOfEvents;
284 list.Add(other.fAccumulatedData);
286 fAccumulatedData->Merge(&list);
291 //_____________________________________________________________________________
293 AliMUONTrackerDataMaker::NextEvent()
295 /// Read and process next event
297 if ( !fIsOwnerOfRawReader )
299 AliError("I'm not the owner of the raw reader. Cannot use NextEvent");
303 AliCodeTimerAuto("",0);
305 static Int_t nphysics(0);
306 static Int_t ngood(0);
308 if ( !IsRunning() ) return kTRUE;
310 Bool_t ok = fRawReader->NextEvent();
317 Int_t eventType = fRawReader->GetType();
321 if (eventType != AliRawEventHeaderBase::kPhysicsEvent )
323 return kTRUE; // for the moment
328 Bool_t pok = ProcessEvent();
332 AliDebug(1,Form("n %10d nphysics %10d ngood %10d",fNumberOfEvents,nphysics,ngood));
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 !
350 AliCodeTimerAuto("",0);
352 AliMUONRawStreamTrackerHP stream(fRawReader);
354 stream.DisableWarnings();
355 stream.DisableRawReaderErrorLogger();
356 stream.DisableMUONErrorLogger();
360 stream.EnableMUONErrorLogger();
361 stream.SetMUONErrorLogger(fLogger);
362 stream.SetLoggingDetailLevel(AliMUONRawStreamTrackerHP::kMediumErrorDetail);
365 const Int_t nddls = AliDAQ::NumberOfDdls("MUONTRK");
366 TArrayI nevents(nddls);
368 for ( Int_t i = 0; i < nddls; ++i )
373 fOneEventData->Clear();
382 while ( stream.Next(buspatchId,manuId,manuChannel,adc,kTRUE) )
384 Int_t detElemId = AliMpDDLStore::Instance()->GetDEfromBus(buspatchId);
386 Int_t ddl = AliMpDDLStore::Instance()->GetDDLfromBus(buspatchId);
390 AliMUONVCalibParam* param = static_cast<AliMUONVCalibParam*>(fOneEventData->FindObject(detElemId,manuId));
393 param = new AliMUONCalibParamND(1,64,detElemId,manuId,
394 AliMUONVCalibParam::InvalidFloatValue());
395 fOneEventData->Add(param);
398 Double_t charge(adc);
400 if ( fDigitCalibrator )
402 if ( fDigitCalibrator->IsValidDigit(detElemId, manuId, manuChannel) )
404 charge = fDigitCalibrator->CalibrateDigit(detElemId, manuId, manuChannel,adc);
414 param->SetValueAsDouble(manuChannel,0,charge);
418 Bool_t badEvent = stream.HasPaddingError() || stream.HasGlitchError();
422 fAccumulatedData->Add(*fOneEventData,&nevents);
429 //_____________________________________________________________________________
431 AliMUONTrackerDataMaker::Print(Option_t*) const
435 cout << "Source=" << Source() << " Running=" << ( IsRunning() ? "YES" : "NO")
439 //_____________________________________________________________________________
440 void AliMUONTrackerDataMaker::Rewind()
443 if ( fIsOwnerOfRawReader )
445 fRawReader->RewindEvents();
450 AliError("Wrong usage of this class : cannot rewind as I am not owner of the raw reader !");
454 //_____________________________________________________________________________
455 Long64_t AliMUONTrackerDataMaker::Merge(TCollection* list)
457 /// Merge objects in collection
461 if ( list->IsEmpty() ) return NumberOfEvents();
464 const TObject* o(0x0);
466 while ( ( o = next() ) )
468 const AliMUONTrackerDataMaker* data = dynamic_cast<const AliMUONTrackerDataMaker*>(o);
471 AliError(Form("Object named %s is not an AliMUONTrackerDataMaker ! Skipping it",
476 Bool_t ok = Add(*data);
479 AliError("Got incompatible objects");
484 return NumberOfEvents();
487 //_____________________________________________________________________________
489 AliMUONTrackerDataMaker::SetRawReader(AliRawReader* rawReader)
491 /// Change the rawreader (only works if isowner=true)
493 if ( fIsOwnerOfRawReader )
495 AliFatal("Improper use of this class ! Cannot change raw reader in this case");
498 fRawReader = rawReader;