]> git.uio.no Git - u/mrichter/AliRoot.git/blob - MUON/AliMUONTrackerRawDataMaker.cxx
mixing example
[u/mrichter/AliRoot.git] / MUON / AliMUONTrackerRawDataMaker.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 "AliMUONTrackerRawDataMaker.h"
19
20 #include "AliCDBManager.h"
21 #include "AliCDBStorage.h"
22 #include "AliCodeTimer.h"
23 #include "AliLog.h"
24 #include "AliLog.h"
25 #include "AliMUON2DMap.h"
26 #include "AliMUONCalibParamND.h"
27 #include "AliMUONCalibrationData.h"
28 #include "AliMUONRawStreamTracker.h"
29 #include "AliMUONRawStreamTrackerHP.h"
30 #include "AliMUONTrackerData.h"
31 #include "AliMpDDLStore.h"
32 #include "AliRawEventHeaderBase.h"
33 #include "AliRawReader.h"
34 #include <Riostream.h>
35
36 ///\class AliMUONTrackerRawDataMaker
37 ///
38 /// Creator of raw AliMUONVTrackerData from AliRawReader
39 /// 
40 ///\author Laurent Aphecetche, Subatech
41
42 ///\cond CLASSIMP
43 ClassImp(AliMUONTrackerRawDataMaker)
44 ///\endcond
45
46 Int_t AliMUONTrackerRawDataMaker::fgkCounter(0);
47
48 //_____________________________________________________________________________
49 AliMUONTrackerRawDataMaker::AliMUONTrackerRawDataMaker(TRootIOCtor*)
50 : AliMUONVTrackerDataMaker(),
51 fRawReader(0x0),
52 fIsOwnerOfRawReader(kFALSE),
53 fAccumulatedData(0x0),
54 fOneEventData(0x0),
55 fSource(""),
56 fIsRunning(kFALSE),
57 fNumberOfEvents(0),
58 fRunNumber(0),
59 fIsEventByEvent(kFALSE),
60 fUseHPDecoder(kTRUE)
61 {
62   /// Ctor
63   ++fgkCounter;
64 }
65
66 //_____________________________________________________________________________
67 AliMUONTrackerRawDataMaker::AliMUONTrackerRawDataMaker(AliRawReader* reader, 
68                                                        Bool_t histogram,
69                                                        Bool_t useHPdecoder)
70 : AliMUONVTrackerDataMaker(),
71 fRawReader(reader),
72 fIsOwnerOfRawReader(kTRUE),
73 fAccumulatedData(0x0),
74 fOneEventData(new AliMUON2DMap(true)),
75 fSource("unspecified"),
76 fIsRunning(kFALSE),
77 fNumberOfEvents(0),
78 fRunNumber(0),
79 fIsEventByEvent(kFALSE),
80 fUseHPDecoder(useHPdecoder)
81 {
82   /// Ctor
83   
84   if (fRawReader)
85   {
86     fRawReader->NextEvent(); // to be sure to get run number available
87     fRunNumber = fRawReader->GetRunNumber();
88     fRawReader->RewindEvents();
89   }
90     
91   Ctor(histogram);
92 }
93
94 //_____________________________________________________________________________
95 AliMUONTrackerRawDataMaker::AliMUONTrackerRawDataMaker(Int_t runNumber,
96                                                        AliRawReader* reader, 
97                                                        Bool_t histogram,
98                                                        Bool_t useHPdecoder)
99 : AliMUONVTrackerDataMaker(),
100 fRawReader(reader),
101 fIsOwnerOfRawReader(kTRUE),
102 fAccumulatedData(0x0),
103 fOneEventData(new AliMUON2DMap(true)),
104 fSource("unspecified"),
105 fIsRunning(kFALSE),
106 fNumberOfEvents(0),
107 fRunNumber(runNumber),
108 fIsEventByEvent(kFALSE),
109 fUseHPDecoder(useHPdecoder)
110 {
111   /// Ctor
112     
113   Ctor(histogram);
114 }
115
116 //_____________________________________________________________________________
117 void
118 AliMUONTrackerRawDataMaker::Ctor(Bool_t histogram)
119 {
120   /// Designated ctor
121   
122   TString name;
123   
124   if (!fRunNumber)
125   {
126     ++fgkCounter;    
127     name = Form("%sRAW_%d",(histogram?"H":""),fgkCounter);
128   }
129   else
130   {
131     name = Form("%sRAW%d",(histogram?"H":""),fRunNumber);
132   }
133   
134   fAccumulatedData = new AliMUONTrackerData(name.Data(),"charge values",1);
135   fAccumulatedData->SetDimensionName(0,"Raw charge");
136   if ( histogram ) 
137   {
138     fAccumulatedData->MakeHistogramForDimension(0,kTRUE);
139   }
140 }
141
142 //_____________________________________________________________________________
143 AliMUONTrackerRawDataMaker::~AliMUONTrackerRawDataMaker()
144 {
145   /// dtor
146   delete fOneEventData;
147   delete fAccumulatedData;
148         if (fIsOwnerOfRawReader) delete fRawReader;
149 }
150
151 //_____________________________________________________________________________
152 Bool_t
153 AliMUONTrackerRawDataMaker::Add(const AliMUONTrackerRawDataMaker& other) 
154 {
155   /// Adds other to this
156   
157 //  AliRawReader* fRawReader; //!< reader of the data (owner or not)
158 //  Bool_t fIsOwnerOfRawReader; //!< whether we must delete rawReader or not
159 //  AliMUONVTrackerData* fAccumulatedData; ///< data (owner)
160 //  AliMUONVStore* fOneEventData; ///< data for one event (owner)
161 //  TString fSource; ///< where the data comes from
162 //  Bool_t fIsRunning; ///< whether we are running or are paused
163 //  Int_t fNumberOfEvents; ///< number of events seen
164 //  Int_t fRunNumber; ///< run number of the data
165 //  Bool_t fIsEventByEvent; ///< we only keep one event's data (no accumulation)
166 //  Bool_t fUseHPDecoder; ///< whether to use high performance decoder or not
167 //  static Int_t fgkCounter; ///< to count the number of instances
168   
169   if (!fAccumulatedData) return kFALSE;
170   
171   if ( fIsEventByEvent )
172   {
173     AliError("Cannot add event by event objects !");
174     return kFALSE;
175   }
176   
177   if ( fRunNumber != other.fRunNumber ) fRunNumber = -1;
178   
179   fSource += "\n";
180   fSource += other.fSource;
181   
182   fNumberOfEvents += other.fNumberOfEvents;
183   
184   TList list;
185   list.Add(other.fAccumulatedData);
186   
187   fAccumulatedData->Merge(&list);
188   
189   return kTRUE;
190 }
191
192 //_____________________________________________________________________________
193 Long64_t
194 AliMUONTrackerRawDataMaker::Merge(TCollection* list)
195 {
196   /// Merge objects in collection
197   
198   if (!list) return 0;
199   
200   if ( list->IsEmpty() ) return NumberOfEvents();
201   
202   TIter next(list);
203   const TObject* o(0x0);
204   
205   while ( ( o = next() ) )
206   {
207     const AliMUONTrackerRawDataMaker* data = dynamic_cast<const AliMUONTrackerRawDataMaker*>(o);
208     if (!o)
209     {
210       AliError(Form("Object named %s is not an AliMUONTrackerRawDataMaker ! Skipping it",
211                     o->GetName()));
212     }
213     else
214     {
215       Bool_t ok = Add(*data);
216       if (!ok)
217       {
218         AliError("Got incompatible objects");
219       }
220     }
221   }
222   
223   return NumberOfEvents();
224 }
225
226 //_____________________________________________________________________________
227 Bool_t 
228 AliMUONTrackerRawDataMaker::NextEvent()
229 {
230   /// Read and process next event
231  
232   AliCodeTimerAuto("");
233   
234   static Int_t nphysics(0);
235   static Int_t ngood(0);
236
237   fOneEventData->Clear();
238   
239   if ( !IsRunning() ) return kTRUE;
240   
241   Bool_t ok = fRawReader->NextEvent();
242
243   if (!ok) 
244   {
245     return kFALSE;
246   }
247   
248   Int_t eventType = fRawReader->GetType();
249
250   ++fNumberOfEvents;
251   
252   if (eventType != AliRawEventHeaderBase::kPhysicsEvent ) 
253   {
254     return kTRUE; // for the moment
255   }
256
257   ++nphysics;
258
259         if ( ProcessEvent() )
260         {
261                 ++ngood;
262         }
263         
264         AliDebug(1,Form("n %10d nphysics %10d ngood %10d",fNumberOfEvents,nphysics,ngood));
265         
266         return kTRUE;
267 }
268
269 //_____________________________________________________________________________
270 Bool_t 
271 AliMUONTrackerRawDataMaker::ProcessEvent()
272 {
273         /// Process current event
274         
275   AliMUONVRawStreamTracker* stream = 0x0;
276   
277   if ( fUseHPDecoder ) 
278   {
279     stream = new AliMUONRawStreamTrackerHP(fRawReader);
280   }
281   else
282   {
283     stream = new AliMUONRawStreamTracker(fRawReader);
284   }
285     
286   stream->First();
287     
288   Int_t buspatchId;
289   UShort_t manuId;
290   UChar_t manuChannel;
291         UShort_t adc;
292   
293   while ( stream->Next(buspatchId,manuId,manuChannel,adc) )
294   {    
295     Int_t detElemId = AliMpDDLStore::Instance()->GetDEfromBus(buspatchId);
296     
297     AliMUONVCalibParam* param = static_cast<AliMUONVCalibParam*>(fOneEventData->FindObject(detElemId,manuId));
298     if (!param)
299     {
300       param = new AliMUONCalibParamND(1,64,detElemId,manuId,
301                                       AliMUONVCalibParam::InvalidFloatValue());
302       fOneEventData->Add(param);
303     }
304     
305     param->SetValueAsDouble(manuChannel,0,adc);    
306   }    
307   
308         Bool_t good(kFALSE);
309         
310   if ( !stream->IsErrorMessage() )
311   {
312     good = kTRUE;
313     fAccumulatedData->Add(*fOneEventData);
314   }
315
316   delete stream;
317   
318   return good;
319 }
320
321 //_____________________________________________________________________________
322 void
323 AliMUONTrackerRawDataMaker::Print(Option_t*) const
324 {
325   /// Printout
326   
327   cout << "Source=" << Source() << " Running=" << ( IsRunning() ? "YES" : "NO")
328   << endl;
329   
330 }
331
332 //_____________________________________________________________________________
333 void 
334 AliMUONTrackerRawDataMaker::Rewind()
335 {
336   /// Rewind events
337   fRawReader->RewindEvents();
338   fNumberOfEvents=0;
339 }
340
341 //_____________________________________________________________________________
342 void 
343 AliMUONTrackerRawDataMaker::SetRawReader(AliRawReader* rawReader)
344 {
345   /// Points to another raw reader
346         
347         if ( fIsOwnerOfRawReader ) 
348         {
349     AliFatal("Improper use of this class ! Cannot change raw reader in this case");
350         }
351         fRawReader = rawReader;
352 }