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"
173 Bool_t calibrate = ( strlen(calibMode) > 0 );
180 TString scalib(calibMode);
182 if ( scalib == "GAIN" ) type = "CALC";
183 if ( scalib == "NOGAIN" ) type = "CALZ";
184 if ( scalib == "GAINCONSTANTCAPA") type = "CALG";
185 if ( scalib == "INJECTIONGAIN" ) type = "CALE";
191 name = Form("%s%s_%d",(histogram?"H":""),type.Data(),fgkCounter);
195 name = Form("%s%s%d",(histogram?"H":""),type.Data(),fRunNumber);
198 fAccumulatedData = new AliMUONTrackerData(name.Data(),"charge values",1);
199 fAccumulatedData->SetDimensionName(0,(calibrate ? "Calibrated charge" : "Raw charge"));
202 fAccumulatedData->MakeHistogramForDimension(0,kTRUE,xmin,xmax);
207 fCalibrationData = new AliMUONCalibrationData(runNumber);
209 // force the reading of calibration NOW
210 // FIXME: not really elegant and error prone (as we have the list of calib data twice,
211 // once here and once in the digitcalibrator class, hence the change of them getting
213 // But with the current CDBManager implementation, I don't know how to solve
214 // this better (e.g. to avoid clearing cache messages and so on).
216 AliCDBStorage* storage(0x0);
218 if ( fOCDBPath.Length() > 0 )
220 storage = AliCDBManager::Instance()->GetDefaultStorage();
222 if ( storage && ( storage->GetURI() != fOCDBPath.Data() ) )
224 AliCDBManager::Instance()->SetDefaultStorage(fOCDBPath.Data());
228 fCalibrationData->Pedestals();
229 fCalibrationData->Gains();
230 fCalibrationData->Neighbours();
231 fCalibrationData->HV();
232 fCalibrationData->Capacitances();
234 if ( storage && ( storage->GetURI() != fOCDBPath.Data() ) )
236 AliCDBManager::Instance()->SetDefaultStorage(storage);
239 fDigitCalibrator = new AliMUONDigitCalibrator(*fCalibrationData,recoParam,calibMode);
240 //FIXME: get the reco param from GUI and/or from OCDB if not used from the QA code ?
244 //_____________________________________________________________________________
245 AliMUONTrackerDataMaker::~AliMUONTrackerDataMaker()
249 delete fOneEventData;
250 delete fAccumulatedData;
251 if ( fIsOwnerOfRawReader ) delete fRawReader;
252 delete fCalibrationData;
253 delete fDigitCalibrator;
256 //_____________________________________________________________________________
258 AliMUONTrackerDataMaker::Add(const AliMUONTrackerDataMaker& other)
260 /// Adds other to this
262 if (!fAccumulatedData) return kFALSE;
264 if ( fIsEventByEvent )
266 AliError("Cannot add event by event objects !");
270 if ( fRunNumber != other.fRunNumber ) fRunNumber = -1;
273 fSource += other.fSource;
275 fNumberOfEvents += other.fNumberOfEvents;
278 list.Add(other.fAccumulatedData);
280 fAccumulatedData->Merge(&list);
285 //_____________________________________________________________________________
287 AliMUONTrackerDataMaker::NextEvent()
289 /// Read and process next event
291 if ( !fIsOwnerOfRawReader )
293 AliError("I'm not the owner of the raw reader. Cannot use NextEvent");
297 AliCodeTimerAuto("",0);
299 static Int_t nphysics(0);
300 static Int_t ngood(0);
302 if ( !IsRunning() ) return kTRUE;
304 Bool_t ok = fRawReader->NextEvent();
311 Int_t eventType = fRawReader->GetType();
315 if (eventType != AliRawEventHeaderBase::kPhysicsEvent )
317 return kTRUE; // for the moment
322 Bool_t pok = ProcessEvent();
326 AliDebug(1,Form("n %10d nphysics %10d ngood %10d",fNumberOfEvents,nphysics,ngood));
331 //_____________________________________________________________________________
332 Bool_t AliMUONTrackerDataMaker::ProcessEvent()
334 /// Process current event
336 /// Note that in case of calibration, we do not simply reuse the
337 /// AliMUONDigitCalibrator::Calibrate(AliMUONVDigitStore&) method,
338 /// as this would require filling first a digitStore, and then calibrate it,
339 /// and then convert it into a VStore, all this taking too much time.
340 /// But we *do* reuse the AliMUONDigitCalibrator::CalibrateDigit in order not to
341 /// duplicate this critical piece of calibration code !
344 AliCodeTimerAuto("",0);
346 AliMUONRawStreamTrackerHP stream(fRawReader);
348 stream.DisableWarnings();
349 // stream.EnabbleErrorLogger();
351 const Int_t nddls = AliDAQ::NumberOfDdls("MUONTRK");
352 TArrayI nevents(nddls);
354 for ( Int_t i = 0; i < nddls; ++i )
359 fOneEventData->Clear();
368 while ( stream.Next(buspatchId,manuId,manuChannel,adc,kTRUE) )
370 Int_t detElemId = AliMpDDLStore::Instance()->GetDEfromBus(buspatchId);
372 Int_t ddl = AliMpDDLStore::Instance()->GetDDLfromBus(buspatchId);
376 AliMUONVCalibParam* param = static_cast<AliMUONVCalibParam*>(fOneEventData->FindObject(detElemId,manuId));
379 param = new AliMUONCalibParamND(1,64,detElemId,manuId,
380 AliMUONVCalibParam::InvalidFloatValue());
381 fOneEventData->Add(param);
384 Double_t charge(adc);
386 if ( fDigitCalibrator )
388 if ( fDigitCalibrator->IsValidDigit(detElemId, manuId, manuChannel) )
390 charge = fDigitCalibrator->CalibrateDigit(detElemId, manuId, manuChannel,adc);
400 param->SetValueAsDouble(manuChannel,0,charge);
404 Bool_t badEvent = stream.HasPaddingError() || stream.HasGlitchError();
408 fAccumulatedData->Add(*fOneEventData,&nevents);
415 //_____________________________________________________________________________
417 AliMUONTrackerDataMaker::Print(Option_t*) const
421 cout << "Source=" << Source() << " Running=" << ( IsRunning() ? "YES" : "NO")
425 //_____________________________________________________________________________
426 void AliMUONTrackerDataMaker::Rewind()
429 if ( fIsOwnerOfRawReader )
431 fRawReader->RewindEvents();
436 AliError("Wrong usage of this class : cannot rewind as I am not owner of the raw reader !");
440 //_____________________________________________________________________________
441 Long64_t AliMUONTrackerDataMaker::Merge(TCollection* list)
443 /// Merge objects in collection
447 if ( list->IsEmpty() ) return NumberOfEvents();
450 const TObject* o(0x0);
452 while ( ( o = next() ) )
454 const AliMUONTrackerDataMaker* data = dynamic_cast<const AliMUONTrackerDataMaker*>(o);
457 AliError(Form("Object named %s is not an AliMUONTrackerDataMaker ! Skipping it",
462 Bool_t ok = Add(*data);
465 AliError("Got incompatible objects");
470 return NumberOfEvents();
473 //_____________________________________________________________________________
475 AliMUONTrackerDataMaker::SetRawReader(AliRawReader* rawReader)
477 /// Change the rawreader (only works if isowner=true)
479 if ( fIsOwnerOfRawReader )
481 AliFatal("Improper use of this class ! Cannot change raw reader in this case");
484 fRawReader = rawReader;