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