]> git.uio.no Git - u/mrichter/AliRoot.git/blob - HLT/TPCLib/AliHLTTPCRawDataUnpackerComponent.cxx
coding conventions and compilation warnings
[u/mrichter/AliRoot.git] / HLT / TPCLib / AliHLTTPCRawDataUnpackerComponent.cxx
1 // $Id$
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: Matthias Richter <Matthias.Richter@ift.uib.no>        *
8  *                  Timm Steinbeck <timm@kip.uni-heidelberg.de>           *
9  *                  for The ALICE HLT Project.                            *
10  *                                                                        *
11  * Permission to use, copy, modify and distribute this software and its   *
12  * documentation strictly for non-commercial purposes is hereby granted   *
13  * without fee, provided that the above copyright notice appears in all   *
14  * copies and that both the copyright notice and this permission notice   *
15  * appear in the supporting documentation. The authors make no claims     *
16  * about the suitability of this software for any purpose. It is          *
17  * provided "as is" without express or implied warranty.                  *
18  **************************************************************************/
19
20 ///////////////////////////////////////////////////////////////////////////////
21 //                                                                           //
22 // a TPC cluster finder processing component for the HLT                     //
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 ///////////////////////////////////////////////////////////////////////////////
31
32 #if __GNUC__>= 3
33 using namespace std;
34 #endif
35
36 #include "AliHLTTPCRawDataUnpackerComponent.h"
37 #include "AliTPCRawStream.h"
38 #include "AliRawDataHeader.h"
39 #include "AliRawReaderMemory.h"
40 #include "AliHLTTPCDigitData.h"
41 #include "AliHLTTPCTransform.h"
42 #include "AliHLTTPCDefinitions.h"
43 #include <cstdlib>
44 #include <cerrno>
45
46 // this is a global object used for automatic component registration, do not use this
47 AliHLTTPCRawDataUnpackerComponent gAliHLTTPCRawDataUnpackerComponent;
48
49 ClassImp(AliHLTTPCRawDataUnpackerComponent);
50
51 AliHLTTPCRawDataUnpackerComponent::AliHLTTPCRawDataUnpackerComponent()
52   :
53   fRawMemoryReader(NULL),
54   fTPCRawStream(NULL)
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 AliHLTTPCRawDataUnpackerComponent::AliHLTTPCRawDataUnpackerComponent(const AliHLTTPCRawDataUnpackerComponent&)
64   :
65   fRawMemoryReader(NULL),
66   fTPCRawStream(NULL)
67 {
68   // see header file for class documentation
69 }
70
71 AliHLTTPCRawDataUnpackerComponent& AliHLTTPCRawDataUnpackerComponent::operator=(const AliHLTTPCRawDataUnpackerComponent&)
72
73   // see header file for class documentation
74   return *this;
75 }
76
77 AliHLTTPCRawDataUnpackerComponent::~AliHLTTPCRawDataUnpackerComponent()
78 {
79   // see header file for class documentation
80 }
81
82 // Public functions to implement AliHLTComponent's interface.
83 // These functions are required for the registration process
84
85 const char* AliHLTTPCRawDataUnpackerComponent::GetComponentID()
86 {
87   // see header file for class documentation
88   return "TPCRawDataUnpacker";
89 }
90
91 void AliHLTTPCRawDataUnpackerComponent::GetInputDataTypes( vector<AliHLTComponentDataType>& list)
92 {
93   // see header file for class documentation
94   list.clear();
95   list.push_back( AliHLTTPCDefinitions::fgkDDLPackedRawDataType );
96 }
97
98 AliHLTComponentDataType AliHLTTPCRawDataUnpackerComponent::GetOutputDataType()
99 {
100   // see header file for class documentation
101   return AliHLTTPCDefinitions::fgkUnpackedRawDataType;
102 }
103
104 void AliHLTTPCRawDataUnpackerComponent::GetOutputDataSize( unsigned long& constBase, double& inputMultiplier )
105 {
106   // see header file for class documentation
107   // XXX TODO: Find more realistic values.
108   constBase = 0;
109   inputMultiplier = 6.0;
110 }
111
112 AliHLTComponent* AliHLTTPCRawDataUnpackerComponent::Spawn()
113 {
114   // see header file for class documentation
115   return new AliHLTTPCRawDataUnpackerComponent;
116 }
117
118 int AliHLTTPCRawDataUnpackerComponent::DoInit( int argc, const char** argv )
119 {
120   // see header file for class documentation
121   if ( fRawMemoryReader || fTPCRawStream )
122     return EINPROGRESS;
123
124   int i = 0;
125   //     const char* tableFileBaseDir = NULL;
126   while ( i < argc )
127     {
128       //        if ( !strcmp( argv[i], "table-dir" ) )
129       //            {
130       //            if ( i+1>=argc )
131       //                {
132       //                Logging(kHLTLogError, "HLT::TPCRawDataUnpacker::DoInit", "Missing Argument", "Missing -table-dir parameter");
133       //                return ENOTSUP;
134       //                }
135       //            tableFileBaseDir = argv[i+1];
136       //            i += 2;
137       //            continue;
138       //            }
139       Logging(kHLTLogError, "HLT::TPCRawDataUnpacker::DoInit", "Unknown Option", "Unknown option '%s'", argv[i] );
140       return EINVAL;
141     }
142
143   //     if ( !tableFileBaseDir )
144   //    {
145   //    Logging(kHLTLogError, "HLT::TPCRawDataUnpacker::DoInit", "Table file directory missing ", 
146   //            "Table file base directory has to be set using the -table-dir component parameter." );
147   //    return EINVAL;
148   //    }
149
150   fRawMemoryReader = new AliRawReaderMemory;
151   //fTPCRawStream = new AliTPCRawStream( fRawMemoryReader, tableFileBaseDir );
152   fTPCRawStream = new AliTPCRawStream( fRawMemoryReader );
153     
154   return 0;
155 }
156
157 int AliHLTTPCRawDataUnpackerComponent::DoDeinit()
158 {
159   // see header file for class documentation
160   if ( fRawMemoryReader )
161     delete fRawMemoryReader;
162   fRawMemoryReader = NULL;
163   if ( fTPCRawStream )
164     delete fTPCRawStream;
165   fTPCRawStream = NULL;
166   return 0;
167 }
168
169 int AliHLTTPCRawDataUnpackerComponent::DoEvent( const AliHLTComponentEventData& evtData, const AliHLTComponentBlockData* blocks, 
170                                               AliHLTComponentTriggerData& trigData, AliHLTUInt8_t* outputPtr, 
171                                               AliHLTUInt32_t& size, vector<AliHLTComponentBlockData>& outputBlocks )
172 {
173   // see header file for class documentation
174   const AliHLTComponentBlockData* iter = NULL;
175   unsigned long ndx;
176
177   AliHLTUInt8_t* outBPtr;
178   AliHLTTPCUnpackedRawData* outPtr;
179   AliHLTTPCDigitRowData* currentRow;
180   AliHLTTPCDigitData* currentDigit;
181   unsigned long long outputSize = 0;
182   unsigned long blockOutputSize = 0;
183   unsigned long rowSize = 0;
184   Int_t slice, patch, rows[2];
185   outBPtr = outputPtr;
186   outPtr = (AliHLTTPCUnpackedRawData*)outputPtr;
187   currentRow = outPtr->fDigits;
188   currentDigit = currentRow->fDigitData;
189     
190   Logging( kHLTLogDebug, "HLT::TPCRawDataUnpackerSubscriber::DoEvent", "Event received", 
191            "Event 0x%08LX (%Lu) received with %lu blocks. Output data size: %lu",
192            evtData.fEventID, evtData.fEventID, evtData.fBlockCnt, size);
193   for ( ndx = 0; ndx < evtData.fBlockCnt; ndx++ )
194     {
195       iter = blocks+ndx;
196       char tmp1[14], tmp2[14];
197       DataType2Text( iter->fDataType, tmp1 );
198       DataType2Text( AliHLTTPCDefinitions::fgkDDLPackedRawDataType, tmp2 );
199       Logging( kHLTLogDebug, "HLT::TPCRawDataUnpackerSubscriber::DoEvent", "Event received", 
200                "Event 0x%08LX (%Lu) received datatype: %s - required datatype: %s",
201                evtData.fEventID, evtData.fEventID, tmp1, tmp2 );
202       if ( iter->fDataType != AliHLTTPCDefinitions::fgkDDLPackedRawDataType )
203         {
204           continue;
205         }
206       slice = AliHLTTPCDefinitions::GetMinSliceNr( *iter );
207       patch = AliHLTTPCDefinitions::GetMinPatchNr( *iter );
208       rows[0] = AliHLTTPCTransform::GetFirstRow( patch );
209       rows[1] = AliHLTTPCTransform::GetLastRow( patch );
210       blockOutputSize = 0;
211
212       Logging( kHLTLogDebug, "HLT::TPCRawDataUnpackerSubscriber::DoEvent", "Input Raw Packed Data", 
213                "Input: Slice/Patch/RowMin/RowMax: %d/%d/%d/%d.",
214                slice, patch, rows[0], rows[1] );
215
216       fRawMemoryReader->SetMemory( reinterpret_cast<UChar_t*>( iter->fPtr ), iter->fSize );
217       bool readValue = true;
218       readValue = fTPCRawStream->Next();
219       int row = -1, oldRow = -1;
220       Int_t rowOffset = 0;
221       if ( patch >= 2 ) // Outer sector, patches 2, 3, 4, 5
222         rowOffset = AliHLTTPCTransform::GetFirstRow( 2 );
223
224       while ( readValue )
225         {
226           row = fTPCRawStream->GetRow();
227           if ( row != oldRow )
228             {
229               if ( oldRow!=-1 && rowSize != sizeof(AliHLTTPCDigitRowData)+currentRow->fNDigit*sizeof(AliHLTTPCDigitData) )
230                 {
231                   Logging( kHLTLogFatal, "HLT::TPCRawDataUnpackerSubscriber::DoEvent", "Size inconsistency", 
232                            "Size inconsistency for row %d data: %lu != %lu (%lu digits).", oldRow, rowSize, 
233                            sizeof(AliHLTTPCDigitRowData)+currentRow->fNDigit*sizeof(AliHLTTPCDigitData), currentRow->fNDigit );
234                 }
235               rowSize = 0;
236               if ( size < outputSize+sizeof(AliHLTTPCDigitRowData) )
237                 {
238                   Logging( kHLTLogFatal, "HLT::TPCRawDataUnpackerSubscriber::DoEvent", "Too much data", 
239                            "Output data too big, output memory full. Aborting event 0x%08lX (%lu)" , 
240                            evtData.fEventID, evtData.fEventID );
241                   return 0;
242                 }
243               currentRow = (AliHLTTPCDigitRowData*)(outBPtr+outputSize);
244               currentDigit = currentRow->fDigitData;
245               currentRow->fRow = row+rowOffset;
246               currentRow->fNDigit = 0;
247               oldRow = row;
248               outputSize += sizeof(AliHLTTPCDigitRowData);
249               blockOutputSize += sizeof(AliHLTTPCDigitRowData);
250               rowSize += sizeof(AliHLTTPCDigitRowData);
251             }
252           if ( size < outputSize+sizeof(AliHLTTPCDigitData) )
253             {
254               Logging( kHLTLogFatal, "HLT::TPCRawDataUnpackerSubscriber::DoEvent", "Too much data", 
255                        "Output data too big, output memory full. Aborting event 0x%08lX (%lu)" , 
256                        evtData.fEventID, evtData.fEventID );
257               return 0;
258             }
259           currentDigit->fCharge = fTPCRawStream->GetSignal();
260           currentDigit->fPad = fTPCRawStream->GetPad();
261           currentDigit->fTime = fTPCRawStream->GetTime();
262           currentRow->fNDigit++;
263           currentDigit++;
264           outputSize += sizeof(AliHLTTPCDigitData);
265           blockOutputSize += sizeof(AliHLTTPCDigitData);
266           rowSize += sizeof(AliHLTTPCDigitData);
267           readValue = fTPCRawStream->Next();
268         }
269       if ( oldRow!=-1 && rowSize != sizeof(AliHLTTPCDigitRowData)+currentRow->fNDigit*sizeof(AliHLTTPCDigitData) )
270         {
271           Logging( kHLTLogFatal, "HLT::TPCRawDataUnpackerSubscriber::DoEvent", "Size inconsistency", 
272                    "Size inconsistency for row %d data: %lu != %lu (%lu digits).", oldRow, rowSize, 
273                    sizeof(AliHLTTPCDigitRowData)+currentRow->fNDigit*sizeof(AliHLTTPCDigitData), currentRow->fNDigit );
274         }
275
276       AliHLTComponentBlockData bd;
277       FillBlockData( bd );
278       bd.fOffset = outputSize-blockOutputSize;
279       bd.fSize = blockOutputSize;
280       bd.fSpecification = iter->fSpecification;
281       Logging( kHLTLogDebug, "HLT::TPCRawDataUnpackerSubscriber::DoEvent", "Event received", 
282                "Event 0x%08LX (%Lu) output data block %lu of %lu bytes at offset %lu",
283                evtData.fEventID, evtData.fEventID, ndx, blockOutputSize, outputSize-blockOutputSize );
284       //AliHLTSubEventDescriptor::FillBlockAttributes( bd.fAttributes );
285       outputBlocks.push_back( bd );
286     }
287
288     
289   size = outputSize;
290   return 0;
291 }
292
293