]> git.uio.no Git - u/mrichter/AliRoot.git/blob - HLT/TPCLib/AliHLTTPCCalibPedestalComponent.cxx
Calibration Processor and TPC calibration components (Jochen)
[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(const AliHLTTPCCalibPedestalComponent&)
65   :
66   fRawReader(NULL),
67   fRawStream(NULL),
68   fCalibPedestal(NULL),
69   fRCUFormat(kFALSE),
70   fMinPatch(5),
71   fMaxPatch(0),
72   fSpecification(0),
73   fEnableAnalysis(kFALSE) {
74   // see header file for class documentation
75
76   HLTFatal("copy constructor untested");
77 }
78
79 AliHLTTPCCalibPedestalComponent& AliHLTTPCCalibPedestalComponent::operator=(const AliHLTTPCCalibPedestalComponent&) { 
80   // see header file for class documentation
81
82   HLTFatal("assignment operator untested");
83   return *this;
84 }       
85
86 AliHLTTPCCalibPedestalComponent::~AliHLTTPCCalibPedestalComponent() {
87   // see header file for class documentation
88 }
89
90 // Public functions to implement AliHLTComponent's interface.
91 // These functions are required for the registration process
92
93 const char* AliHLTTPCCalibPedestalComponent::GetComponentID() {
94   // see header file for class documentation
95
96   return "TPCCalibPedestal";
97 }
98
99 void AliHLTTPCCalibPedestalComponent::GetInputDataTypes( vector<AliHLTComponentDataType>& list) {
100   // see header file for class documentation
101
102   list.clear(); 
103   list.push_back( AliHLTTPCDefinitions::fgkDDLPackedRawDataType );
104 }
105
106 AliHLTComponentDataType AliHLTTPCCalibPedestalComponent::GetOutputDataType() {
107   // see header file for class documentation
108
109   return AliHLTTPCDefinitions::fgkCalibPedestalDataType;
110 }
111
112 void AliHLTTPCCalibPedestalComponent::GetOutputDataSize( unsigned long& constBase, double& inputMultiplier ) {
113   // see header file for class documentation
114
115   // XXX TODO: Find more realistic values.  
116   constBase = 0;
117   inputMultiplier = (2.0);
118 }
119
120 AliHLTComponent* AliHLTTPCCalibPedestalComponent::Spawn() {
121   // see header file for class documentation
122
123   return new AliHLTTPCCalibPedestalComponent();
124 }  
125
126
127 Int_t AliHLTTPCCalibPedestalComponent::ScanArgument( Int_t argc, const char** argv ) {
128   // see header file for class documentation
129
130   Int_t iResult = 0;
131   TString argument = "";
132   TString parameter = "";
133
134   if ( !argc ) 
135     return -EINVAL;
136
137   argument = argv[iResult];
138   
139   if ( argument.IsNull() ) 
140     return -EINVAL;
141
142   // -rcuformat
143   if ( argument.CompareTo("-rcuformat") == 0 ) {
144
145     if ( ++iResult >= argc  ) {
146       iResult = -EPROTO;
147     }
148     else {
149       parameter = argv[1];
150       if ( parameter.CompareTo("old") == 0 ) {
151         fRCUFormat = kTRUE;
152         HLTInfo( "RCU Format is set to old." );
153       }
154       else if ( parameter.CompareTo("new") == 0 ) {
155         fRCUFormat = kFALSE;
156         HLTInfo( "RCU Format is set to new." );
157       }
158       else {
159         HLTError( "Cannot convert rcu format specifier '%s'.", argv[1] );
160         iResult = -EPROTO;
161       }
162     } 
163   }
164   else if ( argument.CompareTo("-enableanalysis") == 0 ) {
165     HLTInfo( "Analysis before shipping data to FXS enabled." );
166     fEnableAnalysis = kTRUE;
167   }
168   else {
169     iResult = -EINVAL;
170   }
171       
172   return iResult;
173 }
174
175 Int_t AliHLTTPCCalibPedestalComponent::InitCalibration() {
176   // see header file for class documentation
177     
178   // ** Create pedestal calibration
179   if ( fCalibPedestal )
180     return EINPROGRESS;
181   
182   fCalibPedestal = new AliTPCCalibPedestal();
183
184   // **  Create AliRoot Memory Reader
185   if (fRawReader)
186     return EINPROGRESS;
187
188 #if defined(HAVE_ALIRAWDATA) && defined(HAVE_ALITPCRAWSTREAM_H) 
189   fRawReader = new AliRawReaderMemory();
190 #else
191   HLTFatal("AliRawReader  not available - check your build");
192   return -ENODEV;
193 #endif
194
195   return 0;
196 }
197
198 Int_t AliHLTTPCCalibPedestalComponent::DeinitCalibration() {
199   // see header file for class documentation
200
201   if ( fRawReader )
202     delete fRawReader;
203   fRawReader = NULL;
204
205   if ( fCalibPedestal )
206     delete fCalibPedestal;
207   fCalibPedestal = NULL;
208
209   return 0;
210 }
211
212 /*
213  * --- setter for rcuformat need in AliTPCCalibPedestal class
214  */
215 Int_t AliHLTTPCCalibPedestalComponent::ProcessCalibration( const AliHLTComponentEventData& evtData, AliHLTComponentTriggerData& trigData ) {
216   // see header file for class documentation
217   
218   const AliHLTComponentBlockData* iter = NULL;
219
220   AliHLTUInt8_t slice, patch;
221   Int_t DDLid = 0;
222     
223   // ** Loop over all input blocks and specify which data format should be read - only select Raw Data
224   iter = GetFirstInputBlock( AliHLTTPCDefinitions::fgkDDLPackedRawDataType );
225   
226   while ( iter != NULL ) {
227     
228     // ** Print Debug output which data format was received
229     char tmp1[14], tmp2[14];
230     DataType2Text( iter->fDataType, tmp1 );
231     DataType2Text( AliHLTTPCDefinitions::fgkDDLPackedRawDataType, tmp2 );
232
233     HLTDebug ( "Event received - Event 0x%08LX (%Lu) received datatype: %s - required datatype: %s", 
234                evtData.fEventID, evtData.fEventID, tmp1, tmp2 );
235
236     // ** Get DDL ID in order to tell the memory reader which slice/patch to use
237     slice = AliHLTTPCDefinitions::GetMinSliceNr( *iter );
238     patch = AliHLTTPCDefinitions::GetMinPatchNr( *iter );
239
240     if (patch < 2) DDLid = 768 + (2 * slice) + patch;
241     else DDLid = 838 + (4*slice) + patch;
242
243     HLTDebug ( "Input Raw Data - Slice/Patch: %d/%d - EquipmentID : %d.", slice, patch, DDLid );
244
245     // ** Get min and max patch, used for output specification
246     if ( patch < fMinPatch ) fMinPatch =  patch;
247     if ( patch > fMaxPatch ) fMaxPatch =  patch;
248
249     // ** Init TPCRawStream
250     fRawReader->SetMemory( reinterpret_cast<UChar_t*>( iter->fPtr ), iter->fSize );
251     fRawReader->SetEquipmentID(DDLid);
252
253     fRawStream = new AliTPCRawStream( fRawReader );
254     fRawStream->SetOldRCUFormat( fRCUFormat );
255
256     // ** Process actual Pedestal Calibration - Fill histograms
257     fCalibPedestal->ProcessEvent( fRawStream );
258   
259     // ** Delete TPCRawStream
260     if ( fRawStream )
261       delete fRawStream;
262     fRawStream = NULL;    
263
264     // ** Get next input block, with the same specification as defined in GetFirstInputBlock()
265     iter = GetNextInputBlock();
266
267   } //  while ( iter != NULL ) {
268     
269   // ** Get output specification
270   fSpecification = AliHLTTPCDefinitions::EncodeDataSpecification( slice, slice, fMinPatch, fMaxPatch );
271
272   // ** PushBack data to shared memory ... 
273   PushBack( (TObject*) fCalibPedestal, AliHLTTPCDefinitions::fgkCalibPedestalDataType, fSpecification);
274   
275   return 0;
276 } // Int_t AliHLTTPCCalibPedestalComponent::ProcessCalibration( const AliHLTComponentEventData& evtData, AliHLTComponentTriggerData& trigData ) {
277
278
279 Int_t AliHLTTPCCalibPedestalComponent::ShipDataToFXS( const AliHLTComponentEventData& evtData, AliHLTComponentTriggerData& trigData ) {
280   // see header file for class documentation
281     
282   if ( fEnableAnalysis )
283     fCalibPedestal->Analyse();
284   
285   // ** PushBack data to FXS ...
286   PushToFXS( (TObject*) fCalibPedestal, "TPC", "Pedestal" ) ;
287   
288   return 0;
289 } // Int_t AliHLTTPCCalibPedestalComponent::ShipDataToFXS( const AliHLTComponentEventData& evtData, AliHLTComponentTriggerData& trigData ) {
290
291