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