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