]> git.uio.no Git - u/mrichter/AliRoot.git/blob - HLT/MUON/utils/AliHLTMUONRawDataHistoComponent.h
Improving documentation and macros.
[u/mrichter/AliRoot.git] / HLT / MUON / utils / AliHLTMUONRawDataHistoComponent.h
1 #ifndef AliHLTMUONRAWDATAHISTOCOMPONENT_H
2 #define AliHLTMUONRAWDATAHISTOCOMPONENT_H
3 /* This file is property of and copyright by the ALICE HLT Project        *
4  * ALICE Experiment at CERN, All rights reserved.                         *
5  * See cxx source for full Copyright notice                               */
6
7 // $Id: $
8
9 ///
10 ///  @file   AliHLTMUONRawDataHistoComponent.h
11 ///  @author Artur Szostak <artursz@iafrica.com>
12 ///  @date   30 April 2008
13 ///  @brief  Declaration of a component to generate basic monitoring histograms of raw data.
14 ///
15
16 #include "AliHLTMUONProcessor.h"
17 #include "AliHLTMUONDataTypes.h"
18 #include "AliMUONTrackerDDLDecoder.h"
19 #include "AliMUONTriggerDDLDecoder.h"
20 #include "TH1D.h"
21
22 /**
23  * @class AliHLTMUONRawDataHistoComponent
24  * @brief Dimuon HLT component for generating basic monitoring histograms for raw data.
25  *
26  * This component is useful for performing basic monitoring tasks on the raw data
27  * from the muon spectrometer. It will try and decode the data and histogram the
28  * following information:
29  * \li The distribution of signals per DDL.
30  * \li The number of ADC values found per MANU for each DDL.
31  * \li The error codes found by the decoders while trying to decode the data for each DDL.
32  *
33  * <h2>General properties:</h2>
34  *
35  * Component ID: \b MUONRawDataHistogrammer <br>
36  * Library: \b libAliHLTMUON.so <br>
37  * Input Data Types:  AliHLTMUONConstants::DDLRawDataType() = "DDL_RAW :MUON" <br>
38  * Output Data Types: AliHLTMUONConstants::HistogramDataType() = "ROOTHIST:MUON" <br>
39  *
40  * <h2>Mandatory arguments:</h2>
41  * None.
42  *
43  * <h2>Optional arguments:</h2>
44  * \li -pubdelay <i>delay</i> <br>
45  *      Indicates the number of seconds to wait between publishing the histograms.
46  *      The default is zero seconds. <i>delay</i> must be a positive floating point
47  *      number. <br>
48  * \li -noemptyhists <br>
49  *      If indicated then any histograms that are empty will not be published.
50  *      By default all events are processed. <br>
51  * \li -onlydataevents <br>
52  *      If indicated then only data events are processed.
53  *      By default all events are processed. <br>
54  * \li -clearafterpub <br>
55  *      If specified then all the internal histograms are cleared after they are
56  *      published, so they will not accumilate statistics over the whole run.
57  *      This is off by default. <br>
58  * \li -tryrecover <br>
59  *      This is a special option to the raw data decoder to turn on logic which will
60  *      try and recover from corrupt raw DDL data. This is off by default. <br>
61  *
62  * <h2>Standard configuration:</h2>
63  * There is no special configuration for this component.
64  *
65  * <h2>Default CDB entries:</h2>
66  * None.
67  *
68  * <h2>Performance:</h2>
69  * A few milliseconds per event.
70  *
71  * <h2>Memory consumption:</h2>
72  * Minimal, under 1 MBytes.
73  *
74  * <h2>Output size:</h2>
75  * A few kBytes.
76  *
77  * @ingroup alihlt_dimuon_component
78  */
79 class AliHLTMUONRawDataHistoComponent : public AliHLTMUONProcessor
80 {
81 public:
82         AliHLTMUONRawDataHistoComponent();
83         virtual ~AliHLTMUONRawDataHistoComponent();
84
85         // Public functions to implement the AliHLTProcessor interface.
86         // These functions are required for the registration process.
87         virtual const char* GetComponentID();
88         virtual void GetInputDataTypes(AliHLTComponentDataTypeList& list);
89         virtual AliHLTComponentDataType GetOutputDataType();
90         virtual void GetOutputDataSize(unsigned long& constBase, double& inputMultiplier);
91         virtual AliHLTComponent* Spawn();
92
93 protected:
94
95         // Protected functions to implement the AliHLTProcessor interface.
96         // These functions provide initialization as well as the actual processing
97         // capabilities of the component.
98         virtual int DoInit(int argc, const char** argv);
99         virtual bool IgnoreArgument(const char* arg) const;
100         virtual int DoDeinit();
101         virtual int DoEvent(
102                         const AliHLTComponentEventData& evtData,
103                         AliHLTComponentTriggerData& trigData
104                 );
105         
106         using AliHLTProcessor::DoEvent;
107
108 private:
109
110         class AliDecoderHandler : public AliHLTLogging
111         {
112         public:
113         
114                 AliDecoderHandler() : AliHLTLogging(), fErrorHist(NULL) {}
115                 virtual ~AliDecoderHandler() {}
116                 
117                 /// Returns the error codes histogram.
118                 TH1D* ErrorHist() const { return fErrorHist; }
119                 
120                 /// Sets the error codes histogram.
121                 void ErrorHist(TH1D* hist) { fErrorHist = hist; }
122         
123         protected:
124         
125                 /// Fills the error histogram with the given error code.
126                 void FillErrorHist(Int_t code);
127         
128                 TH1D* fErrorHist;   /// Histogram of error codes found.
129                 
130         private:
131         
132                 // Do not allow copying of this object.
133                 /// Not implemented.
134                 AliDecoderHandler(const AliDecoderHandler& obj);
135                 /// Not implemented.
136                 AliDecoderHandler& operator = (const AliDecoderHandler& obj);
137         };
138
139         class AliTrackerDecoderHandler :
140                 public AliMUONTrackerDDLDecoderEventHandler, public AliDecoderHandler
141         {
142         public:
143                 AliTrackerDecoderHandler() :
144                         AliMUONTrackerDDLDecoderEventHandler(),
145                         AliDecoderHandler(),
146                         fManuHist(NULL),
147                         fSignalHist(NULL)
148                 {}
149                 
150                 virtual ~AliTrackerDecoderHandler() {}
151                 
152                 /// Returns the signals per MANU histogram.
153                 TH1D* ManuHist() const { return fManuHist; }
154                 
155                 /// Sets the signals per MANU histogram.
156                 void ManuHist(TH1D* hist) { fManuHist = hist; }
157                 
158                 /// Returns the signals histogram.
159                 TH1D* SignalHist() const { return fSignalHist; }
160                 
161                 /// Sets the signals histogram.
162                 void SignalHist(TH1D* hist) { fSignalHist = hist; }
163                 
164                 // Methods inherited from AliMUONTrackerDDLDecoderEventHandler:
165                 
166                 /// Called for each new data word found.
167                 void OnData(UInt_t data, bool /*parityError*/);
168                 
169                 /// Fills the fErrorHist histogram with the error code received.
170                 void OnError(ErrorCode code, const void* /*location*/) { FillErrorHist(Int_t(code)); }
171         
172         private:
173         
174                 // Do not allow copying of this object.
175                 /// Not implemented.
176                 AliTrackerDecoderHandler(const AliTrackerDecoderHandler& obj);
177                 /// Not implemented.
178                 AliTrackerDecoderHandler& operator = (const AliTrackerDecoderHandler& obj);
179                 
180                 TH1D* fManuHist;    /// Histogram of signal distribution per MANU.
181                 TH1D* fSignalHist;  /// Histogram of the ADC signal distribution.
182         };
183         
184         class AliTriggerDecoderHandler :
185                 public AliMUONTriggerDDLDecoderEventHandler, public AliDecoderHandler
186         {
187         public:
188                 AliTriggerDecoderHandler() :
189                         AliMUONTriggerDDLDecoderEventHandler(),
190                         AliDecoderHandler()
191                 {}
192                 
193                 virtual ~AliTriggerDecoderHandler() {}
194                 
195                 // Methods inherited from AliMUONTriggerDDLDecoderEventHandler:
196                 
197                 /// Fills the fErrorHist histogram with the error code received.
198                 void OnError(ErrorCode code, const void* /*location*/) { FillErrorHist(Int_t(code)); }
199         
200         private:
201         
202                 // Do not allow copying of this object.
203                 /// Not implemented.
204                 AliTriggerDecoderHandler(const AliTriggerDecoderHandler& obj);
205                 /// Not implemented.
206                 AliTriggerDecoderHandler& operator = (const AliTriggerDecoderHandler& obj);
207         };
208
209         // Do not allow copying of this class.
210         AliHLTMUONRawDataHistoComponent(const AliHLTMUONRawDataHistoComponent& /*obj*/);
211         AliHLTMUONRawDataHistoComponent& operator = (const AliHLTMUONRawDataHistoComponent& /*obj*/);
212
213         /**
214          * Decodes the tracker DDL data block and fills the histograms.
215          * \param block  The data block to decode.
216          * \returns true if the block could be decoded and false if there was an error in the data.
217          */
218         bool ProcessTrackerDDL(const AliHLTComponentBlockData* block);
219         
220         /**
221          * Decodes the trigger DDL data block and fills the histograms.
222          * \param block  The data block to decode.
223          * \returns true if the block could be decoded and false if there was an error in the data.
224          */
225         bool ProcessTriggerDDL(const AliHLTComponentBlockData* block);
226         
227         /**
228          * Deletes all the histograms and resets the pointers.
229          */
230         void FreeObjects();
231         
232         AliMUONTrackerDDLDecoder<AliTrackerDecoderHandler> fTrackerDecoder;  // Raw data decoder for the tracker data.
233         AliMUONTriggerDDLDecoder<AliTriggerDecoderHandler> fTriggerDecoder;  // Raw data decoder for the trigger data.
234         
235         double fLastPublishTime;  /// Timestamp for the last time we published data (seconds).
236         double fCurrentEventTime;  /// Timestamp for the current event being processed (seconds).
237         double fPublishDelay;  /// Delay in second to wait between publishing data.
238         TH1D* fErrorHist[22]; /// Histograms for error codes per DDL.
239         TH1D* fManuHist[20]; /// Histograms for MANU distributions per DDL.
240         TH1D* fSignalHist[20]; /// Histograms for signal distributions per DDL.
241         bool fSuppressEmptyHists;  /// Flag indicating if empty histograms should be published or not.
242         bool fProcessDataEventsOnly;  /// Flag indicating if only data events should be processed.
243         bool fClearAfterPublish;  /// Inficates if the histograms should be reset after being published.
244         
245         ClassDef(AliHLTMUONRawDataHistoComponent, 0);  // Trigger decision component for the dimuon HLT.
246 };
247
248 //-----------------------------------------------------------------------------
249
250 inline void AliHLTMUONRawDataHistoComponent::AliDecoderHandler::FillErrorHist(Int_t code)
251 {
252         /// Fills the error code into the error code histogram.
253         
254         assert(fErrorHist != NULL);
255         Int_t mincode = Int_t( fErrorHist->GetXaxis()->GetBinCenter(1) );
256         Int_t maxcode = Int_t( fErrorHist->GetXaxis()->GetBinCenter(fErrorHist->GetNbinsX()) );
257         if (code < mincode or maxcode < code)
258         {
259                 HLTError("Filling an error code which is out of range."
260                         " Received code %d, but expected it to be in the range [%d..%d]",
261                         int(code), mincode, maxcode
262                 );
263         }
264         fErrorHist->Fill(code);
265 }
266
267
268 inline void AliHLTMUONRawDataHistoComponent::AliTrackerDecoderHandler::OnData(
269                 UInt_t data, bool /*parityError*/
270         )
271 {
272         /// Fills the signals histogram and also the signal per MANU histogram.
273
274         UInt_t minadc = UInt_t( fSignalHist->GetXaxis()->GetBinCenter(1) );
275         UInt_t maxadc = UInt_t( fSignalHist->GetXaxis()->GetBinCenter(fSignalHist->GetNbinsX()) );
276         UInt_t minmanu = UInt_t( fManuHist->GetXaxis()->GetBinCenter(1) );
277         UInt_t maxmanu = UInt_t( fManuHist->GetXaxis()->GetBinCenter(fManuHist->GetNbinsX()) );
278         
279         UShort_t manuId; UChar_t channelId; UShort_t adc;
280         UnpackADC(data, manuId, channelId, adc);
281         
282         if (adc < minadc or maxadc < adc)
283         {
284                 HLTError("Filling a signal value which is out of range. Received ADC value"
285                         " of %d channels, but expected it to be in the range [%d..%d]",
286                         int(adc), minadc, maxadc
287                 );
288         }
289         fSignalHist->Fill(adc);
290         
291         if (manuId < minmanu or maxmanu < manuId)
292         {
293                 HLTError("Filling a MANU ID value which is out of range. Received"
294                         " value of %d, but expected it to be in the range [%d..%d]",
295                         int(manuId), minmanu, maxmanu
296                 );
297         }
298         fManuHist->Fill(manuId);
299 }
300
301 #endif // AliHLTMUONRAWDATAHISTOCOMPONENT_H
302