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