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