]> git.uio.no Git - u/mrichter/AliRoot.git/blob - MUON/AliMUONTrackerCalibratedDataMaker.cxx
No effc++ warnings in RALICE
[u/mrichter/AliRoot.git] / MUON / AliMUONTrackerCalibratedDataMaker.cxx
1 /**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
3 *                                                                        *
4 * Author: The ALICE Off-line Project.                                    *
5 * Contributors are mentioned in the code where appropriate.              *
6 *                                                                        *
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 **************************************************************************/
15
16 // $Id$
17
18 #include "AliMUONTrackerCalibratedDataMaker.h"
19
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"
35 #include "AliLog.h"
36 #include <Riostream.h>
37
38 ///\class AliMUONTrackerCalibratedDataMaker
39 ///
40 /// Creator of AliMUONVTrackerData from AliRawReader
41 /// 
42 ///\author Laurent Aphecetche, Subatech
43
44 ///\cond CLASSIMP
45 ClassImp(AliMUONTrackerCalibratedDataMaker)
46 ///\endcond
47
48 Int_t AliMUONTrackerCalibratedDataMaker::fgkCounter(0);
49
50 //_____________________________________________________________________________
51 AliMUONTrackerCalibratedDataMaker::AliMUONTrackerCalibratedDataMaker(AliRawReader* reader,
52                                                                      const char* cdbpath,
53                                                                      const char* calibMode,
54                                                                      Bool_t histogram,
55                                                                      Double_t xmin,
56                                                                      Double_t xmax)
57 : AliMUONVTrackerDataMaker(),
58   fRawReader(reader),
59   fAccumulatedData(0x0),
60   fOneEventData(new AliMUON2DMap(true)),
61   fIsOwner(kTRUE),
62   fSource("unspecified"),
63   fIsRunning(kFALSE),
64   fDigitMaker(0x0),
65   fDigitCalibrator(0x0),
66   fCalibrationData(0x0),
67   fDigitStore(0x0), 
68   fCDBPath(cdbpath),
69   fNumberOfEvents(0){
70   /// Ctor
71   reader->NextEvent(); // to be sure to get run number available
72   
73   Int_t runNumber = reader->GetRunNumber();
74   
75   ++fgkCounter;
76   
77   Bool_t calibrate = ( fCDBPath.Length() > 0 );
78   TString name;
79   TString basename("RAW");
80   
81   if ( calibrate ) 
82   {
83     TString scalib(calibMode);
84     scalib.ToUpper();
85     if ( scalib == "GAIN" ) basename = "CALC";
86     if ( scalib == "NOGAIN" ) basename = "CALZ";
87     if ( scalib == "GAINCONSTANTCAPA" ) basename = "CALG";
88   }
89   
90   if (!runNumber)
91   {
92     name = Form("%s%s(%d)",
93                 (histogram ? "H" : ""),
94                 basename.Data(),
95                 fgkCounter);
96   }
97   else
98   {
99     name = Form("%s%s%d",
100                 (histogram ? "H" : ""),
101                 basename.Data(),
102                 runNumber);
103   }
104   
105   fAccumulatedData = new AliMUONTrackerData(name.Data(),"charge values",1);
106   fAccumulatedData->SetDimensionName(0,(calibrate ? "Calibrated charge" : "Raw charge"));
107   if ( histogram ) 
108   {
109     fAccumulatedData->MakeHistogramForDimension(0,kTRUE,xmin,xmax);
110     AliInfo(Form("Will histogram between %e and %e",xmin,xmax));
111   }
112   
113   reader->RewindEvents();
114
115   fDigitMaker = new AliMUONDigitMaker;
116   fDigitMaker->SetMakeTriggerDigits(kFALSE);
117   fDigitStore = new AliMUONDigitStoreV2R;
118
119   if ( calibrate ) 
120   {
121     fCalibrationData = new AliMUONCalibrationData(runNumber);
122     
123     // force the reading of calibration NOW
124     // FIXME: not really elegant and error prone (as we have the list of calib data twice, 
125     // once here and once in the digitcalibrator class, hence the change of them getting
126     // out of sync)
127     // But with the current CDBManager implementation, I don't know how to solve
128     // this better (e.g. to avoid clearing cache messages and so on).
129     
130     AliCDBStorage* storage = AliCDBManager::Instance()->GetDefaultStorage();
131     
132     if ( storage->GetURI() != fCDBPath.Data() ) 
133     {
134       AliCDBManager::Instance()->SetDefaultStorage(fCDBPath.Data());
135     }
136     
137     fCalibrationData->Pedestals();
138     fCalibrationData->Gains();
139     fCalibrationData->Neighbours();
140     fCalibrationData->HV();
141     fCalibrationData->Capacitances();
142     
143     if ( storage->GetURI() != fCDBPath.Data() ) 
144     {
145       AliCDBManager::Instance()->SetDefaultStorage(storage);
146     }
147     
148     fDigitCalibrator = new AliMUONDigitCalibrator(*fCalibrationData,calibMode);
149   }
150 }
151
152 //_____________________________________________________________________________
153 AliMUONTrackerCalibratedDataMaker::~AliMUONTrackerCalibratedDataMaker()
154 {
155   /// dtor
156   delete fOneEventData;
157   if ( fIsOwner ) delete fAccumulatedData;
158   delete fRawReader;
159   delete fDigitStore;
160   delete fCalibrationData;
161   delete fDigitMaker;
162   delete fDigitCalibrator;
163 }
164
165 //_____________________________________________________________________________
166 Bool_t 
167 AliMUONTrackerCalibratedDataMaker::NextEvent()
168 {
169   /// Read next event
170  
171   AliCodeTimerAuto("");
172   
173   static Int_t nphysics(0);
174   static Int_t ngood(0);
175
176   if ( !IsRunning() ) return kTRUE;
177   
178   Bool_t ok = fRawReader->NextEvent();
179
180   if (!ok) 
181   {
182     fDigitMaker->Print();
183     return kFALSE;
184   }
185   
186   Int_t eventType = fRawReader->GetType();
187
188   ++fNumberOfEvents;
189   
190   if (eventType != AliRawEventHeaderBase::kPhysicsEvent ) 
191   {
192     return kTRUE; // for the moment
193   }
194
195   ++nphysics;
196
197   Int_t rv = fDigitMaker->Raw2Digits(fRawReader,fDigitStore);
198   
199   if ( ( rv & AliMUONDigitMaker::kTrackerBAD ) != 0 ) return kTRUE;
200
201   if ( fDigitCalibrator ) 
202   {
203     fDigitCalibrator->Calibrate(*fDigitStore);
204   }
205   
206   Bool_t dok = ConvertDigits();
207   
208   if ( dok )
209     {
210       ++ngood;
211       fAccumulatedData->Add(*fOneEventData);
212     }
213
214   AliDebug(1,Form("n %10d nphysics %10d ngood %10d",fNumberOfEvents,nphysics,ngood));
215
216   return kTRUE;
217 }
218
219 //_____________________________________________________________________________
220 Bool_t 
221 AliMUONTrackerCalibratedDataMaker::ConvertDigits()
222 {
223   /// Convert digitstore into fOneEventData
224   
225   AliCodeTimerAuto("");
226   
227   TIter next(fDigitStore->CreateIterator());
228   AliMUONVDigit* digit;
229
230   fOneEventData->Clear();
231   
232   while ( ( digit = static_cast<AliMUONVDigit*>(next())) )
233   {
234     Double_t value = ( digit->IsCalibrated() ? digit->Charge() : digit->ADC() );
235
236     if ( value > 0 ) 
237     {
238       Int_t detElemId = digit->DetElemId();
239       Int_t manuId = digit->ManuId();
240     
241       AliMUONVCalibParam* param = static_cast<AliMUONVCalibParam*>(fOneEventData->FindObject(detElemId,manuId));
242       if (!param)
243       {
244         param = new AliMUONCalibParamND(1,64,detElemId,manuId,
245                                       AliMUONVCalibParam::InvalidFloatValue());
246         fOneEventData->Add(param);
247       }
248     
249       param->SetValueAsDouble(digit->ManuChannel(),0,value);
250     }
251   }
252
253   return kTRUE;
254 }
255
256 //_____________________________________________________________________________
257 void
258 AliMUONTrackerCalibratedDataMaker::Print(Option_t*) const
259 {
260   /// Printout
261   
262   cout << "Source=" << Source() << " Running=" << ( IsRunning() ? "YES" : "NO")
263   << endl;
264   
265 }
266
267 //_____________________________________________________________________________
268 void 
269 AliMUONTrackerCalibratedDataMaker::Rewind()
270 {
271   /// Rewind events
272   fRawReader->RewindEvents();
273   fNumberOfEvents=0;
274 }