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