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