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