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