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 #include "AliMUONTrackerCalibratedDataMaker.h"
20 #include "AliMUON2DMap.h"
21 #include "AliMUONCalibParamND.h"
22 #include "AliMUONCalibrationData.h"
23 #include "AliMUONDigitCalibrator.h"
24 #include "AliMUONDigitMaker.h"
25 #include "AliMUONDigitStoreV2R.h"
26 #include "AliMUONTrackerData.h"
27 #include "AliMUONVDigit.h"
28 #include "AliMUONVDigitStore.h"
29 #include "AliMpDDLStore.h"
30 #include "AliCodeTimer.h"
31 #include "AliCDBManager.h"
32 #include "AliCDBStorage.h"
33 #include "AliRawEventHeaderBase.h"
34 #include "AliRawReader.h"
36 #include <Riostream.h>
38 ///\class AliMUONTrackerCalibratedDataMaker
40 /// Creator of AliMUONVTrackerData from AliRawReader
42 ///\author Laurent Aphecetche, Subatech
45 ClassImp(AliMUONTrackerCalibratedDataMaker)
48 Int_t AliMUONTrackerCalibratedDataMaker::fgkCounter(0);
50 //_____________________________________________________________________________
51 AliMUONTrackerCalibratedDataMaker::AliMUONTrackerCalibratedDataMaker(AliRawReader* reader,
53 : AliMUONVTrackerDataMaker(),
55 fAccumulatedData(0x0),
56 fOneEventData(new AliMUON2DMap(true)),
58 fSource("unspecified"),
61 fDigitCalibrator(0x0),
62 fCalibrationData(0x0),
68 reader->NextEvent(); // to be sure to get run number available
70 Int_t runNumber = reader->GetRunNumber();
74 Bool_t calibrate = ( fCDBPath.Length() > 0 );
80 name = Form("%s(%d)",(calibrate ? "CAL" : "RAW"),fgkCounter);
84 name = Form("%s%d",(calibrate ? "CAL" : "RAW"),runNumber);
87 fAccumulatedData = new AliMUONTrackerData(name.Data(),"charge values",1);
88 fAccumulatedData->SetDimensionName(0,(calibrate ? "Calibrated charge" : "Raw charge"));
90 reader->RewindEvents();
92 fDigitMaker = new AliMUONDigitMaker;
93 fDigitMaker->SetMakeTriggerDigits(kFALSE);
94 fDigitStore = new AliMUONDigitStoreV2R;
98 fCalibrationData = new AliMUONCalibrationData(runNumber);
100 // force the reading of calibration NOW
101 // FIXME: not really elegant and error prone (as we have the list of calib data twice,
102 // once here and once in the digitcalibrator class, hence the change of them getting
104 // But with the current CDBManager implementation, I don't know how to solve
105 // this better (e.g. to avoid clearing cache messages and so on).
107 AliCDBStorage* storage = AliCDBManager::Instance()->GetDefaultStorage();
109 if ( storage->GetURI() != fCDBPath.Data() )
111 AliCDBManager::Instance()->SetDefaultStorage(fCDBPath.Data());
114 fCalibrationData->Pedestals();
115 fCalibrationData->Gains();
116 fCalibrationData->Neighbours();
117 fCalibrationData->HV();
118 fCalibrationData->Capacitances();
120 if ( storage->GetURI() != fCDBPath.Data() )
122 AliCDBManager::Instance()->SetDefaultStorage(storage);
125 fDigitCalibrator = new AliMUONDigitCalibrator(*fCalibrationData);
129 //_____________________________________________________________________________
130 AliMUONTrackerCalibratedDataMaker::~AliMUONTrackerCalibratedDataMaker()
133 delete fOneEventData;
134 if ( fIsOwner ) delete fAccumulatedData;
137 delete fCalibrationData;
139 delete fDigitCalibrator;
142 //_____________________________________________________________________________
144 AliMUONTrackerCalibratedDataMaker::NextEvent()
148 AliCodeTimerAuto("");
150 static Int_t nphysics(0);
151 static Int_t ngood(0);
153 if ( !IsRunning() ) return kTRUE;
155 Bool_t ok = fRawReader->NextEvent();
159 fDigitMaker->Print();
163 Int_t eventType = fRawReader->GetType();
167 if (eventType != AliRawEventHeaderBase::kPhysicsEvent )
169 return kTRUE; // for the moment
174 Int_t rv = fDigitMaker->Raw2Digits(fRawReader,fDigitStore);
176 if ( ( rv & AliMUONDigitMaker::kTrackerBAD ) != 0 ) return kTRUE;
178 if ( fDigitCalibrator )
180 fDigitCalibrator->Calibrate(*fDigitStore);
183 Bool_t dok = ConvertDigits();
188 fAccumulatedData->Add(*fOneEventData);
191 AliDebug(1,Form("n %10d nphysics %10d ngood %10d",fNumberOfEvents,nphysics,ngood));
196 //_____________________________________________________________________________
198 AliMUONTrackerCalibratedDataMaker::ConvertDigits()
200 /// Convert digitstore into fOneEventData
202 AliCodeTimerAuto("");
204 TIter next(fDigitStore->CreateIterator());
205 AliMUONVDigit* digit;
207 fOneEventData->Clear();
209 while ( ( digit = static_cast<AliMUONVDigit*>(next())) )
211 Double_t value = ( digit->IsCalibrated() ? digit->Charge() : digit->ADC() );
215 Int_t detElemId = digit->DetElemId();
216 Int_t manuId = digit->ManuId();
218 AliMUONVCalibParam* param = static_cast<AliMUONVCalibParam*>(fOneEventData->FindObject(detElemId,manuId));
221 param = new AliMUONCalibParamND(1,64,detElemId,manuId,
222 AliMUONVCalibParam::InvalidFloatValue());
223 fOneEventData->Add(param);
226 param->SetValueAsDouble(digit->ManuChannel(),0,value);
233 //_____________________________________________________________________________
235 AliMUONTrackerCalibratedDataMaker::Print(Option_t*) const
239 cout << "Source=" << Source() << " Running=" << ( IsRunning() ? "YES" : "NO")
244 //_____________________________________________________________________________
246 AliMUONTrackerCalibratedDataMaker::Rewind()
249 fRawReader->RewindEvents();