]> git.uio.no Git - u/mrichter/AliRoot.git/blob - MUON/AliMUONTrackerRawDataMaker.cxx
New raw-reader class which deals with events taken from shared memory via the DATE...
[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 "AliMUONDigitCalibrator.h"
29 #include "AliMUONDigitMaker.h"
30 #include "AliMUONDigitStoreV2R.h"
31 #include "AliMUONRawStreamTracker.h"
32 #include "AliMUONRawStreamTrackerHP.h"
33 #include "AliMUONTrackerData.h"
34 #include "AliMUONVDigit.h"
35 #include "AliMUONVDigitStore.h"
36 #include "AliMpDDLStore.h"
37 #include "AliRawEventHeaderBase.h"
38 #include "AliRawReader.h"
39 #include <Riostream.h>
40
41 ///\class AliMUONTrackerRawDataMaker
42 ///
43 /// Creator of raw AliMUONVTrackerData from AliRawReader
44 /// 
45 ///\author Laurent Aphecetche, Subatech
46
47 ///\cond CLASSIMP
48 ClassImp(AliMUONTrackerRawDataMaker)
49 ///\endcond
50
51 Int_t AliMUONTrackerRawDataMaker::fgkCounter(0);
52
53 //_____________________________________________________________________________
54 AliMUONTrackerRawDataMaker::AliMUONTrackerRawDataMaker(AliRawReader* reader, 
55                                                        Bool_t histogram,
56                                                        Bool_t useHPdecoder)
57 : AliMUONVTrackerDataMaker(),
58   fRawReader(reader),
59   fAccumulatedData(0x0),
60   fOneEventData(new AliMUON2DMap(true)),
61   fSource("unspecified"),
62   fIsRunning(kFALSE),
63   fNumberOfEvents(0),
64   fRunNumber(0),
65   fIsEventByEvent(kFALSE),
66   fUseHPDecoder(useHPdecoder)
67 {
68   /// Ctor
69     
70   if (fRawReader)
71   {
72     fRawReader->NextEvent(); // to be sure to get run number available
73     fRunNumber = fRawReader->GetRunNumber();
74     fRawReader->RewindEvents();
75   }
76     
77   TString name;
78   
79   if (!fRunNumber)
80   {
81     ++fgkCounter;    
82     name = Form("%sRAW(%d)",(histogram?"H":""),fgkCounter);
83   }
84   else
85   {
86     name = Form("%sRAW%d",(histogram?"H":""),fRunNumber);
87   }
88   
89   fAccumulatedData = new AliMUONTrackerData(name.Data(),"charge values",1);
90   fAccumulatedData->SetDimensionName(0,"Raw charge");
91   if ( histogram ) 
92   {
93     fAccumulatedData->MakeHistogramForDimension(0,kTRUE);
94   }
95 }
96
97 //_____________________________________________________________________________
98 AliMUONTrackerRawDataMaker::~AliMUONTrackerRawDataMaker()
99 {
100   /// dtor
101   delete fOneEventData;
102   delete fAccumulatedData;
103   delete fRawReader;
104 }
105
106 //_____________________________________________________________________________
107 Long64_t
108 AliMUONTrackerRawDataMaker::Merge(TCollection*)
109 {
110   /// Merge objects in collection
111   
112 //  AliRawReader* fRawReader; //!< reader of the data (owner)
113 //  AliMUONVTrackerData* fAccumulatedData; ///< data (owner)
114 //  AliMUONVStore* fOneEventData; ///< data for one event (owner)
115 //  TString fSource; ///< where the data comes from
116 //  Bool_t fIsRunning; ///< whether we are running or are paused
117 //  Int_t fNumberOfEvents; ///< number of events seen
118 //  Int_t fRunNumber; ///< run number of the data
119 //  Bool_t fIsEventByEvent; ///< we only keep one event's data (no accumulation)
120 //  Bool_t fUseHPDecoder; ///< whether to use high performance decoder or not (false by default)
121
122   AliError("Not implemented yet");
123   return 0;
124 }
125
126 //_____________________________________________________________________________
127 Bool_t 
128 AliMUONTrackerRawDataMaker::NextEvent()
129 {
130   /// Read next event
131  
132   AliCodeTimerAuto("");
133   
134   static Int_t nphysics(0);
135   static Int_t ngood(0);
136
137   fOneEventData->Clear();
138   
139   if ( !IsRunning() ) return kTRUE;
140   
141   Bool_t ok = fRawReader->NextEvent();
142
143   if (!ok) 
144   {
145     return kFALSE;
146   }
147   
148   Int_t eventType = fRawReader->GetType();
149
150   ++fNumberOfEvents;
151   
152   if (eventType != AliRawEventHeaderBase::kPhysicsEvent ) 
153   {
154     return kTRUE; // for the moment
155   }
156
157   ++nphysics;
158
159   AliMUONVRawStreamTracker* stream = 0x0;
160   
161   if ( fUseHPDecoder ) 
162   {
163     stream = new AliMUONRawStreamTrackerHP(fRawReader);
164   }
165   else
166   {
167     stream = new AliMUONRawStreamTracker(fRawReader);
168   }
169     
170   stream->First();
171     
172   Int_t buspatchId;
173   UShort_t manuId;
174   UChar_t manuChannel;
175         UShort_t adc;
176   
177   while ( stream->Next(buspatchId,manuId,manuChannel,adc) )
178   {    
179     Int_t detElemId = AliMpDDLStore::Instance()->GetDEfromBus(buspatchId);
180     
181     AliMUONVCalibParam* param = static_cast<AliMUONVCalibParam*>(fOneEventData->FindObject(detElemId,manuId));
182     if (!param)
183     {
184       param = new AliMUONCalibParamND(1,64,detElemId,manuId,
185                                       AliMUONVCalibParam::InvalidFloatValue());
186       fOneEventData->Add(param);
187     }
188     
189     param->SetValueAsDouble(manuChannel,0,adc);    
190   }    
191   
192   if ( !stream->IsErrorMessage() )
193   {
194     ++ngood;
195     fAccumulatedData->Add(*fOneEventData);
196   }
197
198   AliDebug(1,Form("n %10d nphysics %10d ngood %10d",fNumberOfEvents,nphysics,ngood));
199
200   delete stream;
201   
202   return kTRUE;
203 }
204
205 //_____________________________________________________________________________
206 void
207 AliMUONTrackerRawDataMaker::Print(Option_t*) const
208 {
209   /// Printout
210   
211   cout << "Source=" << Source() << " Running=" << ( IsRunning() ? "YES" : "NO")
212   << endl;
213   
214 }
215
216 //_____________________________________________________________________________
217 void 
218 AliMUONTrackerRawDataMaker::Rewind()
219 {
220   /// Rewind events
221   fRawReader->RewindEvents();
222   fNumberOfEvents=0;
223 }