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 "AliMUONRawStreamTrackerHP.h"
37 #include "AliMUONTrackerData.h"
38 #include "AliMpDDLStore.h"
39 #include "AliRawEventHeaderBase.h"
40 #include "AliRawReader.h"
41 #include "Riostream.h"
44 ClassImp(AliMUONTrackerDataMaker)
47 Int_t AliMUONTrackerDataMaker::fgkCounter(0);
49 //_____________________________________________________________________________
50 AliMUONTrackerDataMaker::AliMUONTrackerDataMaker(TRootIOCtor*)
52 AliMUONVTrackerDataMaker(),
54 fAccumulatedData(0x0),
56 fDigitCalibrator(0x0),
57 fCalibrationData(0x0),
63 fIsOwnerOfRawReader(kFALSE),
64 fIsEventByEvent(kFALSE)
69 //_____________________________________________________________________________
70 AliMUONTrackerDataMaker::AliMUONTrackerDataMaker(const AliMUONRecoParam* recoParam,
72 AliRawReader* rawReader,
74 const char* calibMode,
79 AliMUONVTrackerDataMaker(),
80 fRawReader(rawReader),
81 fAccumulatedData(0x0),
82 fOneEventData(new AliMUON2DMap(true)),
83 fDigitCalibrator(0x0),
84 fCalibrationData(0x0),
88 fRunNumber(runNumber),
90 fIsOwnerOfRawReader(kFALSE),
91 fIsEventByEvent(kFALSE)
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);
99 //_____________________________________________________________________________
100 AliMUONTrackerDataMaker::AliMUONTrackerDataMaker(const AliMUONRecoParam* recoParam,
101 AliRawReader* rawReader,
103 const char* calibMode,
108 AliMUONVTrackerDataMaker(),
109 fRawReader(rawReader),
110 fAccumulatedData(0x0),
111 fOneEventData(new AliMUON2DMap(true)),
112 fDigitCalibrator(0x0),
113 fCalibrationData(0x0),
119 fIsOwnerOfRawReader(kTRUE),
120 fIsEventByEvent(kFALSE)
122 /// Ctor in which we take the ownership of the rawReader, so we can rewind
123 /// and advance it as we wish
127 fRawReader->NextEvent(); // to be sure to get run number available
128 fRunNumber = fRawReader->GetRunNumber();
129 fRawReader->RewindEvents();
132 Ctor(recoParam,fRunNumber,calibMode,histogram,xmin,xmax);
135 //_____________________________________________________________________________
136 AliMUONTrackerDataMaker::AliMUONTrackerDataMaker(AliRawReader* rawReader, Bool_t histogram)
138 AliMUONVTrackerDataMaker(),
139 fRawReader(rawReader),
140 fAccumulatedData(0x0),
141 fOneEventData(new AliMUON2DMap(true)),
142 fDigitCalibrator(0x0),
143 fCalibrationData(0x0),
149 fIsOwnerOfRawReader(kTRUE),
150 fIsEventByEvent(kFALSE)
154 fRawReader->NextEvent(); // to be sure to get run number available
155 fRunNumber = fRawReader->GetRunNumber();
156 fRawReader->RewindEvents();
159 Ctor(0x0,fRunNumber,"",histogram);
163 //_____________________________________________________________________________
165 AliMUONTrackerDataMaker::Ctor(const AliMUONRecoParam* recoParam,
167 const char* calibMode,
169 Double_t xmin, Double_t xmax)
171 /// "designated constructor"
172 Bool_t calibrate = ( fOCDBPath.Length() > 0 );
179 TString scalib(calibMode);
181 if ( scalib == "GAIN" ) type = "CALC";
182 if ( scalib == "NOGAIN" ) type = "CALZ";
183 if ( scalib == "GAINCONSTANTCAPA") type = "CALG";
189 name = Form("%s%s_%d",(histogram?"H":""),type.Data(),fgkCounter);
193 name = Form("%s%s%d",(histogram?"H":""),type.Data(),fRunNumber);
196 fAccumulatedData = new AliMUONTrackerData(name.Data(),"charge values",1);
197 fAccumulatedData->SetDimensionName(0,(calibrate ? "Calibrated charge" : "Raw charge"));
200 fAccumulatedData->MakeHistogramForDimension(0,kTRUE,xmin,xmax);
205 fCalibrationData = new AliMUONCalibrationData(runNumber);
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
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).
214 AliCDBStorage* storage = AliCDBManager::Instance()->GetDefaultStorage();
216 if ( storage->GetURI() != fOCDBPath.Data() )
218 AliCDBManager::Instance()->SetDefaultStorage(fOCDBPath.Data());
221 fCalibrationData->Pedestals();
222 fCalibrationData->Gains();
223 fCalibrationData->Neighbours();
224 fCalibrationData->HV();
225 fCalibrationData->Capacitances();
227 if ( storage->GetURI() != fOCDBPath.Data() )
229 AliCDBManager::Instance()->SetDefaultStorage(storage);
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 ?
237 //_____________________________________________________________________________
238 AliMUONTrackerDataMaker::~AliMUONTrackerDataMaker()
242 delete fOneEventData;
243 delete fAccumulatedData;
244 if ( fIsOwnerOfRawReader ) delete fRawReader;
245 delete fCalibrationData;
246 delete fDigitCalibrator;
249 //_____________________________________________________________________________
251 AliMUONTrackerDataMaker::Add(const AliMUONTrackerDataMaker& other)
253 /// Adds other to this
255 if (!fAccumulatedData) return kFALSE;
257 if ( fIsEventByEvent )
259 AliError("Cannot add event by event objects !");
263 if ( fRunNumber != other.fRunNumber ) fRunNumber = -1;
266 fSource += other.fSource;
268 fNumberOfEvents += other.fNumberOfEvents;
271 list.Add(other.fAccumulatedData);
273 fAccumulatedData->Merge(&list);
278 //_____________________________________________________________________________
280 AliMUONTrackerDataMaker::NextEvent()
282 /// Read and process next event
284 if ( !fIsOwnerOfRawReader )
286 AliError("I'm not the owner of the raw reader. Cannot use NextEvent");
290 AliCodeTimerAuto("");
292 static Int_t nphysics(0);
293 static Int_t ngood(0);
295 if ( !IsRunning() ) return kTRUE;
297 Bool_t ok = fRawReader->NextEvent();
304 Int_t eventType = fRawReader->GetType();
308 if (eventType != AliRawEventHeaderBase::kPhysicsEvent )
310 return kTRUE; // for the moment
315 Bool_t pok = ProcessEvent();
319 AliDebug(1,Form("n %10d nphysics %10d ngood %10d",fNumberOfEvents,nphysics,ngood));
324 //_____________________________________________________________________________
325 Bool_t AliMUONTrackerDataMaker::ProcessEvent()
327 /// Process current event
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 !
337 AliCodeTimerAuto("");
339 AliMUONRawStreamTrackerHP stream(fRawReader);
341 stream.DisableWarnings();
342 // stream.EnabbleErrorLogger();
344 const Int_t nddls = AliDAQ::NumberOfDdls("MUONTRK");
345 TArrayI nevents(nddls);
347 for ( Int_t i = 0; i < nddls; ++i )
352 fOneEventData->Clear();
361 while ( stream.Next(buspatchId,manuId,manuChannel,adc,kTRUE) )
363 Int_t detElemId = AliMpDDLStore::Instance()->GetDEfromBus(buspatchId);
365 Int_t ddl = AliMpDDLStore::Instance()->GetDDLfromBus(buspatchId);
369 AliMUONVCalibParam* param = static_cast<AliMUONVCalibParam*>(fOneEventData->FindObject(detElemId,manuId));
372 param = new AliMUONCalibParamND(1,64,detElemId,manuId,
373 AliMUONVCalibParam::InvalidFloatValue());
374 fOneEventData->Add(param);
377 Double_t charge(adc);
379 if ( fDigitCalibrator )
381 if ( fDigitCalibrator->IsValidDigit(detElemId, manuId, manuChannel) )
383 charge = fDigitCalibrator->CalibrateDigit(detElemId, manuId, manuChannel,adc,3.0);
393 param->SetValueAsDouble(manuChannel,0,charge);
397 Bool_t badEvent = stream.HasPaddingError() || stream.HasGlitchError();
401 fAccumulatedData->Add(*fOneEventData,&nevents);
408 //_____________________________________________________________________________
410 AliMUONTrackerDataMaker::Print(Option_t*) const
414 cout << "Source=" << Source() << " Running=" << ( IsRunning() ? "YES" : "NO")
418 //_____________________________________________________________________________
419 void AliMUONTrackerDataMaker::Rewind()
422 if ( fIsOwnerOfRawReader )
424 fRawReader->RewindEvents();
429 AliError("Wrong usage of this class : cannot rewind as I am not owner of the raw reader !");
433 //_____________________________________________________________________________
434 Long64_t AliMUONTrackerDataMaker::Merge(TCollection* list)
436 /// Merge objects in collection
440 if ( list->IsEmpty() ) return NumberOfEvents();
443 const TObject* o(0x0);
445 while ( ( o = next() ) )
447 const AliMUONTrackerDataMaker* data = dynamic_cast<const AliMUONTrackerDataMaker*>(o);
450 AliError(Form("Object named %s is not an AliMUONTrackerDataMaker ! Skipping it",
455 Bool_t ok = Add(*data);
458 AliError("Got incompatible objects");
463 return NumberOfEvents();
466 //_____________________________________________________________________________
468 AliMUONTrackerDataMaker::SetRawReader(AliRawReader* rawReader)
470 /// Change the rawreader (only works if isowner=true)
472 if ( fIsOwnerOfRawReader )
474 AliFatal("Improper use of this class ! Cannot change raw reader in this case");
477 fRawReader = rawReader;