]> git.uio.no Git - u/mrichter/AliRoot.git/blob - HLT/TPCLib/AliHLTTPCCalibPedestalComponent.cxx
code cleanup, coding rules, eff C++
[u/mrichter/AliRoot.git] / HLT / TPCLib / AliHLTTPCCalibPedestalComponent.cxx
1 /**************************************************************************
2  * This file is property of and copyright by the ALICE HLT Project        * 
3  * ALICE Experiment at CERN, All rights reserved.                         *
4  *                                                                        *
5  * Primary Authors: Jochen Thaeder <thaeder@kip.uni-heidelberg.de>        *
6  *                  for The ALICE HLT Project.                            *
7  *                                                                        *
8  * Permission to use, copy, modify and distribute this software and its   *
9  * documentation strictly for non-commercial purposes is hereby granted   *
10  * without fee, provided that the above copyright notice appears in all   *
11  * copies and that both the copyright notice and this permission notice   *
12  * appear in the supporting documentation. The authors make no claims     *
13  * about the suitability of this software for any purpose. It is          *
14  * provided "as is" without express or implied warranty.                  *
15  **************************************************************************/
16
17 /** @file   AliHLTTPCCalibPedestalComponent.cxx
18     @author Jochen Thaeder
19     @date   
20     @brief  A pedestal calibration component for the TPC.
21 */
22
23 #if __GNUC__>= 3
24 using namespace std;
25 #endif
26
27 #include "AliHLTTPCLogging.h"
28 #include "AliHLTTPCTransform.h"
29
30 #include "AliHLTTPCCalibPedestalComponent.h"
31
32 #include "AliRawDataHeader.h"
33 #include "AliRawReaderMemory.h"
34 #include "AliTPCRawStream.h"
35
36 #include "AliTPCCalibPedestal.h"
37
38 #include <stdlib.h>
39 #include <errno.h>
40 #include "TString.h"
41
42 // this is a global object used for automatic component registration, do not use this
43 AliHLTTPCCalibPedestalComponent gAliHLTTPCCalibPedestalComponent;
44
45 ClassImp(AliHLTTPCCalibPedestalComponent)
46
47 AliHLTTPCCalibPedestalComponent::AliHLTTPCCalibPedestalComponent()
48   :
49   fRawReader(NULL),
50   fRawStream(NULL),
51   fCalibPedestal(NULL),
52   fRCUFormat(kFALSE),
53   fMinPatch(5),
54   fMaxPatch(0),
55   fSpecification(0) ,
56   fEnableAnalysis(kFALSE) {
57   // see header file for class documentation
58   // or
59   // refer to README to build package
60   // or
61   // visit http://web.ift.uib.no/~kjeks/doc/alice-hlt
62 }
63
64 AliHLTTPCCalibPedestalComponent::~AliHLTTPCCalibPedestalComponent() {
65   // see header file for class documentation
66 }
67
68 // Public functions to implement AliHLTComponent's interface.
69 // These functions are required for the registration process
70
71 const char* AliHLTTPCCalibPedestalComponent::GetComponentID() {
72   // see header file for class documentation
73
74   return "TPCCalibPedestal";
75 }
76
77 void AliHLTTPCCalibPedestalComponent::GetInputDataTypes( vector<AliHLTComponentDataType>& list) {
78   // see header file for class documentation
79
80   list.clear(); 
81   list.push_back( AliHLTTPCDefinitions::fgkDDLPackedRawDataType );
82 }
83
84 AliHLTComponentDataType AliHLTTPCCalibPedestalComponent::GetOutputDataType() {
85   // see header file for class documentation
86
87   return AliHLTTPCDefinitions::fgkCalibPedestalDataType;
88 }
89
90 void AliHLTTPCCalibPedestalComponent::GetOutputDataSize( unsigned long& constBase, double& inputMultiplier ) {
91   // see header file for class documentation
92
93   // XXX TODO: Find more realistic values.  
94   constBase = 0;
95   inputMultiplier = (2.0);
96 }
97
98 AliHLTComponent* AliHLTTPCCalibPedestalComponent::Spawn() {
99   // see header file for class documentation
100
101   return new AliHLTTPCCalibPedestalComponent();
102 }  
103
104
105 Int_t AliHLTTPCCalibPedestalComponent::ScanArgument( Int_t argc, const char** argv ) {
106   // see header file for class documentation
107
108   Int_t iResult = 0;
109   TString argument = "";
110   TString parameter = "";
111
112   if ( !argc ) 
113     return -EINVAL;
114
115   argument = argv[iResult];
116   
117   if ( argument.IsNull() ) 
118     return -EINVAL;
119
120   // -rcuformat
121   if ( argument.CompareTo("-rcuformat") == 0 ) {
122
123     if ( ++iResult >= argc  ) {
124       iResult = -EPROTO;
125     }
126     else {
127       parameter = argv[1];
128       if ( parameter.CompareTo("old") == 0 ) {
129         fRCUFormat = kTRUE;
130         HLTInfo( "RCU Format is set to old." );
131       }
132       else if ( parameter.CompareTo("new") == 0 ) {
133         fRCUFormat = kFALSE;
134         HLTInfo( "RCU Format is set to new." );
135       }
136       else {
137         HLTError( "Cannot convert rcu format specifier '%s'.", argv[1] );
138         iResult = -EPROTO;
139       }
140     } 
141   }
142   else if ( argument.CompareTo("-enableanalysis") == 0 ) {
143     HLTInfo( "Analysis before shipping data to FXS enabled." );
144     fEnableAnalysis = kTRUE;
145   }
146   else {
147     iResult = -EINVAL;
148   }
149       
150   return iResult;
151 }
152
153 Int_t AliHLTTPCCalibPedestalComponent::InitCalibration() {
154   // see header file for class documentation
155     
156   // ** Create pedestal calibration
157   if ( fCalibPedestal )
158     return EINPROGRESS;
159   
160   fCalibPedestal = new AliTPCCalibPedestal();
161
162   // **  Create AliRoot Memory Reader
163   if (fRawReader)
164     return EINPROGRESS;
165
166 #if defined(HAVE_ALIRAWDATA) && defined(HAVE_ALITPCRAWSTREAM_H) 
167   fRawReader = new AliRawReaderMemory();
168 #else
169   HLTFatal("AliRawReader  not available - check your build");
170   return -ENODEV;
171 #endif
172
173   return 0;
174 }
175
176 Int_t AliHLTTPCCalibPedestalComponent::DeinitCalibration() {
177   // see header file for class documentation
178
179   if ( fRawReader )
180     delete fRawReader;
181   fRawReader = NULL;
182
183   if ( fCalibPedestal )
184     delete fCalibPedestal;
185   fCalibPedestal = NULL;
186
187   return 0;
188 }
189
190 /*
191  * --- setter for rcuformat need in AliTPCCalibPedestal class
192  */
193 Int_t AliHLTTPCCalibPedestalComponent::ProcessCalibration( const AliHLTComponentEventData& evtData, AliHLTComponentTriggerData& trigData ) {
194   // see header file for class documentation
195   
196   const AliHLTComponentBlockData* iter = NULL;
197
198   AliHLTUInt8_t slice=0, patch=0;
199   Int_t DDLid = 0;
200     
201   // ** Loop over all input blocks and specify which data format should be read - only select Raw Data
202   iter = GetFirstInputBlock( AliHLTTPCDefinitions::fgkDDLPackedRawDataType );
203   
204   while ( iter != NULL ) {
205     
206     // ** Print Debug output which data format was received
207     char tmp1[14], tmp2[14];
208     DataType2Text( iter->fDataType, tmp1 );
209     DataType2Text( AliHLTTPCDefinitions::fgkDDLPackedRawDataType, tmp2 );
210
211     HLTDebug ( "Event received - Event 0x%08LX (%Lu) received datatype: %s - required datatype: %s", 
212                evtData.fEventID, evtData.fEventID, tmp1, tmp2 );
213
214     // ** Get DDL ID in order to tell the memory reader which slice/patch to use
215     slice = AliHLTTPCDefinitions::GetMinSliceNr( *iter );
216     patch = AliHLTTPCDefinitions::GetMinPatchNr( *iter );
217
218     if (patch < 2) DDLid = 768 + (2 * slice) + patch;
219     else DDLid = 838 + (4*slice) + patch;
220
221     HLTDebug ( "Input Raw Data - Slice/Patch: %d/%d - EquipmentID : %d.", slice, patch, DDLid );
222
223     // ** Get min and max patch, used for output specification
224     if ( patch < fMinPatch ) fMinPatch =  patch;
225     if ( patch > fMaxPatch ) fMaxPatch =  patch;
226
227     // ** Init TPCRawStream
228     fRawReader->SetMemory( reinterpret_cast<UChar_t*>( iter->fPtr ), iter->fSize );
229     fRawReader->SetEquipmentID(DDLid);
230
231     fRawStream = new AliTPCRawStream( fRawReader );
232     fRawStream->SetOldRCUFormat( fRCUFormat );
233
234     // ** Process actual Pedestal Calibration - Fill histograms
235     fCalibPedestal->ProcessEvent( fRawStream );
236   
237     // ** Delete TPCRawStream
238     if ( fRawStream )
239       delete fRawStream;
240     fRawStream = NULL;    
241
242     // ** Get next input block, with the same specification as defined in GetFirstInputBlock()
243     iter = GetNextInputBlock();
244
245   } //  while ( iter != NULL ) {
246     
247   // ** Get output specification
248   fSpecification = AliHLTTPCDefinitions::EncodeDataSpecification( slice, slice, fMinPatch, fMaxPatch );
249
250   // ** PushBack data to shared memory ... 
251   PushBack( (TObject*) fCalibPedestal, AliHLTTPCDefinitions::fgkCalibPedestalDataType, fSpecification);
252   
253   return 0;
254 } // Int_t AliHLTTPCCalibPedestalComponent::ProcessCalibration( const AliHLTComponentEventData& evtData, AliHLTComponentTriggerData& trigData ) {
255
256
257 Int_t AliHLTTPCCalibPedestalComponent::ShipDataToFXS( const AliHLTComponentEventData& /*evtData*/, AliHLTComponentTriggerData& /*trigData*/ ) {
258   // see header file for class documentation
259     
260   if ( fEnableAnalysis )
261     fCalibPedestal->Analyse();
262   
263   // ** PushBack data to FXS ...
264   PushToFXS( (TObject*) fCalibPedestal, "TPC", "Pedestal" ) ;
265   
266   return 0;
267 } // Int_t AliHLTTPCCalibPedestalComponent::ShipDataToFXS( const AliHLTComponentEventData& evtData, AliHLTComponentTriggerData& trigData ) {
268
269