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