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),
78 //_____________________________________________________________________________
79 AliMUONTrackerDataMaker::AliMUONTrackerDataMaker(const AliMUONRecoParam* recoParam,
81 AliRawReader* rawReader,
83 const char* calibMode,
88 AliMUONVTrackerDataMaker(),
89 fRawReader(rawReader),
90 fAccumulatedData(0x0),
91 fIsOwnerOfAccumulatedData(kTRUE),
92 fOneEventData(new AliMUON2DMap(true)),
93 fDigitCalibrator(0x0),
94 fCalibrationData(0x0),
98 fRunNumber(runNumber),
100 fIsOwnerOfRawReader(kFALSE),
101 fIsEventByEvent(kFALSE),
103 fLastEventWasEmpty(kFALSE),
104 fNumberOfPhysicsEvents(0),
105 fNumberOfGoodPhysicsEvents(0),
110 /// Ctor in which this object will NOT be the owner of the reader
111 /// and can NOT apply rewind to it, nor use Next on it.
112 Ctor(recoParam,runNumber,calibMode,histogram,xmin,xmax);
116 //_____________________________________________________________________________
117 AliMUONTrackerDataMaker::AliMUONTrackerDataMaker(const AliMUONRecoParam* recoParam,
118 AliRawReader* rawReader,
120 const char* calibMode,
125 AliMUONVTrackerDataMaker(),
126 fRawReader(rawReader),
127 fAccumulatedData(0x0),
128 fIsOwnerOfAccumulatedData(kTRUE),
129 fOneEventData(new AliMUON2DMap(true)),
130 fDigitCalibrator(0x0),
131 fCalibrationData(0x0),
137 fIsOwnerOfRawReader(kTRUE),
138 fIsEventByEvent(kFALSE),
140 fLastEventWasEmpty(kFALSE),
141 fNumberOfPhysicsEvents(0),
142 fNumberOfGoodPhysicsEvents(0),
147 /// Ctor in which we take the ownership of the rawReader, so we can rewind
148 /// and advance it as we wish
150 if ( fRawReader && fRawReader->NextEvent() )
152 fRunNumber = fRawReader->GetRunNumber();
153 fRawReader->RewindEvents();
156 Ctor(recoParam,fRunNumber,calibMode,histogram,xmin,xmax);
159 //_____________________________________________________________________________
160 AliMUONTrackerDataMaker::AliMUONTrackerDataMaker(AliRawReader* rawReader, Bool_t histogram)
162 AliMUONVTrackerDataMaker(),
163 fRawReader(rawReader),
164 fAccumulatedData(0x0),
165 fIsOwnerOfAccumulatedData(kTRUE),
166 fOneEventData(new AliMUON2DMap(true)),
167 fDigitCalibrator(0x0),
168 fCalibrationData(0x0),
174 fIsOwnerOfRawReader(kTRUE),
175 fIsEventByEvent(kFALSE),
177 fLastEventWasEmpty(kFALSE),
178 fNumberOfPhysicsEvents(0),
179 fNumberOfGoodPhysicsEvents(0),
184 /// Ctor from raw data reader
185 if ( fRawReader && fRawReader->NextEvent() )
187 fRunNumber = fRawReader->GetRunNumber();
188 fRawReader->RewindEvents();
191 Ctor(0x0,fRunNumber,"",histogram);
195 //_____________________________________________________________________________
197 AliMUONTrackerDataMaker::Ctor(const AliMUONRecoParam* recoParam,
199 const char* calibMode,
201 Double_t xmin, Double_t xmax)
203 /// "designated constructor"
205 Bool_t calibrate = ( strlen(calibMode) > 0 );
212 TString scalib(calibMode);
214 if ( scalib == "GAIN" ) type = "CALC";
215 if ( scalib == "NOGAIN" ) type = "CALZ";
216 if ( scalib == "GAINCONSTANTCAPA") type = "CALG";
217 if ( scalib == "INJECTIONGAIN" ) type = "CALE";
223 name = Form("%s%s_%d",(histogram?"H":""),type.Data(),fgkCounter);
227 name = Form("%s%s%d",(histogram?"H":""),type.Data(),fRunNumber);
230 fAccumulatedData = new AliMUONTrackerData(name.Data(),"charge values",1);
231 fAccumulatedData->SetDimensionName(0,(calibrate ? "Calibrated charge" : "Raw charge"));
234 fAccumulatedData->MakeHistogramForDimension(0,kTRUE,xmin,xmax);
239 fCalibrationData = new AliMUONCalibrationData(runNumber);
241 // force the reading of calibration NOW
242 // FIXME: not really elegant and error prone (as we have the list of calib data twice,
243 // once here and once in the digitcalibrator class, hence the change of them getting
245 // But with the current CDBManager implementation, I don't know how to solve
246 // this better (e.g. to avoid clearing cache messages and so on).
248 AliCDBStorage* storage(0x0);
250 if ( fOCDBPath.Length() > 0 )
252 storage = AliCDBManager::Instance()->GetDefaultStorage();
254 if ( storage && ( storage->GetURI() != fOCDBPath.Data() ) )
256 AliCDBManager::Instance()->SetDefaultStorage(fOCDBPath.Data());
260 fCalibrationData->Pedestals();
261 fCalibrationData->Gains();
262 fCalibrationData->Neighbours();
263 fCalibrationData->HV();
264 fCalibrationData->Capacitances();
266 if ( storage && ( storage->GetURI() != fOCDBPath.Data() ) )
268 AliCDBManager::Instance()->SetDefaultStorage(storage);
271 fDigitCalibrator = new AliMUONDigitCalibrator(*fCalibrationData,recoParam,calibMode);
272 //FIXME: get the reco param from GUI and/or from OCDB if not used from the QA code ?
276 //_____________________________________________________________________________
277 AliMUONTrackerDataMaker::~AliMUONTrackerDataMaker()
281 delete fOneEventData;
282 if ( fIsOwnerOfAccumulatedData ) delete fAccumulatedData;
283 if ( fIsOwnerOfRawReader ) delete fRawReader;
284 delete fCalibrationData;
285 delete fDigitCalibrator;
288 //_____________________________________________________________________________
290 AliMUONTrackerDataMaker::Add(const AliMUONTrackerDataMaker& other)
292 /// Adds other to this
294 if (!fAccumulatedData) return kFALSE;
296 if ( fIsEventByEvent )
298 AliError("Cannot add event by event objects !");
302 if ( fRunNumber != other.fRunNumber ) fRunNumber = -1;
305 fSource += other.fSource;
307 fNumberOfEvents += other.fNumberOfEvents;
308 fNumberOfPhysicsEvents += other.fNumberOfPhysicsEvents;
309 fNumberOfGoodPhysicsEvents += other.fNumberOfGoodPhysicsEvents;
312 list.Add(other.fAccumulatedData);
314 fAccumulatedData->Merge(&list);
319 //_____________________________________________________________________________
321 AliMUONTrackerDataMaker::NextEvent()
323 /// Read and process next event
325 if ( !fIsOwnerOfRawReader )
327 AliError("I'm not the owner of the raw reader. Cannot use NextEvent");
331 AliCodeTimerAuto("",0);
333 if ( !IsRunning() ) return kTRUE;
337 if ( fLastEvent >= fFirstEvent && fLastEvent > 0 ) // do we have an event range to consider ?
339 // skip up to first event
341 while ( (fNumberOfEvents-1) < fFirstEvent && ( ok = fRawReader->NextEvent() ) )
346 if ( ok && (fNumberOfEvents-1) <= fLastEvent )
348 ok = fRawReader->NextEvent();
352 fNumberOfEvents=fLastEvent+1;
358 // no event range, just proceed...
359 ok = fRawReader->NextEvent();
372 //_____________________________________________________________________________
373 Bool_t AliMUONTrackerDataMaker::ProcessEvent()
375 /// Process current event
377 /// Note that in case of calibration, we do not simply reuse the
378 /// AliMUONDigitCalibrator::Calibrate(AliMUONVDigitStore&) method,
379 /// as this would require filling first a digitStore, and then calibrate it,
380 /// and then convert it into a VStore, all this taking too much time.
381 /// But we *do* reuse the AliMUONDigitCalibrator::CalibrateDigit in order not to
382 /// duplicate this critical piece of calibration code !
387 Int_t eventType = fRawReader->GetType();
389 if (eventType != AliRawEventHeaderBase::kPhysicsEvent )
391 return kTRUE; // for the moment
394 ++fNumberOfPhysicsEvents;
396 fLastEventWasEmpty = kFALSE;
398 AliCodeTimerAuto("",0);
400 AliMUONRawStreamTrackerHP stream(fRawReader);
402 stream.DisableWarnings();
403 stream.DisableRawReaderErrorLogger();
404 stream.DisableMUONErrorLogger();
408 stream.TryRecover(kTRUE);
412 stream.TryRecover(kFALSE);
417 stream.EnableMUONErrorLogger();
418 stream.SetMUONErrorLogger(fLogger);
419 stream.SetLoggingDetailLevel(AliMUONRawStreamTrackerHP::kMediumErrorDetail);
422 const Int_t nddls = AliDAQ::NumberOfDdls("MUONTRK");
423 TArrayI nevents(nddls);
425 for ( Int_t i = 0; i < nddls; ++i )
430 fOneEventData->Clear();
439 while ( stream.Next(buspatchId,manuId,manuChannel,adc,kTRUE) )
441 Int_t detElemId = AliMpDDLStore::Instance()->GetDEfromBus(buspatchId);
443 Int_t ddl = AliMpDDLStore::Instance()->GetDDLfromBus(buspatchId);
447 AliMUONVCalibParam* param = static_cast<AliMUONVCalibParam*>(fOneEventData->FindObject(detElemId,manuId));
450 param = new AliMUONCalibParamND(1,64,detElemId,manuId,
451 AliMUONVCalibParam::InvalidFloatValue());
452 fOneEventData->Add(param);
455 Double_t charge(adc);
457 if ( fDigitCalibrator )
459 if ( fDigitCalibrator->IsValidDigit(detElemId, manuId, manuChannel) )
461 charge = fDigitCalibrator->CalibrateDigit(detElemId, manuId, manuChannel,adc);
471 param->SetValueAsDouble(manuChannel,0,charge);
475 Bool_t badEvent = stream.HasPaddingError() || stream.HasGlitchError();
479 fAccumulatedData->Add(*fOneEventData,&nevents);
480 if ( fOneEventData->GetSize() == 0 ) fLastEventWasEmpty = kTRUE;
481 ++fNumberOfGoodPhysicsEvents;
484 AliDebug(1,Form("n %10d nphysics %10d ngood %10d",fNumberOfEvents,fNumberOfPhysicsEvents,fNumberOfGoodPhysicsEvents));
490 //_____________________________________________________________________________
492 AliMUONTrackerDataMaker::Print(Option_t*) const
496 cout << "Source=" << Source() << " Running=" << ( IsRunning() ? "YES" : "NO")
500 //_____________________________________________________________________________
501 void AliMUONTrackerDataMaker::Rewind()
504 if ( fIsOwnerOfRawReader )
506 fRawReader->RewindEvents();
508 fNumberOfPhysicsEvents=0;
509 fNumberOfGoodPhysicsEvents=0;
513 AliError("Wrong usage of this class : cannot rewind as I am not owner of the raw reader !");
517 //_____________________________________________________________________________
518 Long64_t AliMUONTrackerDataMaker::Merge(TCollection* list)
520 /// Merge objects in collection
524 if ( list->IsEmpty() ) return NumberOfEvents();
527 const TObject* o(0x0);
529 while ( ( o = next() ) )
531 const AliMUONTrackerDataMaker* data = dynamic_cast<const AliMUONTrackerDataMaker*>(o);
534 AliError(Form("Object named %s is not an AliMUONTrackerDataMaker ! Skipping it",
539 Bool_t ok = Add(*data);
542 AliError("Got incompatible objects");
547 return NumberOfEvents();
550 //_____________________________________________________________________________
552 AliMUONTrackerDataMaker::SetRawReader(AliRawReader* rawReader)
554 /// Change the rawreader (only works if isowner=true)
556 if ( fIsOwnerOfRawReader )
558 AliFatal("Improper use of this class ! Cannot change raw reader in this case");
561 fRawReader = rawReader;