]> git.uio.no Git - u/mrichter/AliRoot.git/blob - HLT/TPCLib/AliHLTTPCRawDataUnpackerComponent.cxx
Added a dummy component into the sample library.
[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 "AliL3DigitData.h"
35 #include "AliL3Transform.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::gkPackedRawDataType );
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 = 3.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     AliL3DigitRowData* currentRow;
144     AliL3DigitData* currentDigit;
145     unsigned long long outputSize = 0;
146     unsigned long blockOutputSize = 0;
147     unsigned long rowSize = 0;
148     Int_t slice, patch, row[2];
149     outBPtr = outputPtr;
150     outPtr = (AliHLTTPCUnpackedRawData*)outputPtr;
151     currentRow = outPtr->fDigits;
152     currentDigit = currentRow->fDigitData;
153
154     for ( ndx = 0; ndx < evtData.fBlockCnt; ndx++ )
155         {
156         iter = blocks+ndx;
157         if ( iter->fDataType != AliHLTTPCDefinitions::gkDDLPackedRawDataType )
158             {
159             continue;
160             }
161         slice = AliHLTTPCDefinitions::GetMinSliceNr( *iter );
162         patch = AliHLTTPCDefinitions::GetMinPatchNr( *iter );
163         row[0] = AliL3Transform::GetFirstRow( patch );
164         row[1] = AliL3Transform::GetLastRow( patch );
165         blockOutputSize = 0;
166
167         fRawMemoryReader->SetMemory( reinterpret_cast<UChar_t*>( iter->fPtr ), iter->fSize );
168         bool readValue = true;
169         readValue = fTPCRawStream->Next();
170         int row = -1, oldRow = -1;
171         Int_t rowOffset = 0;
172         if ( patch >= 2 ) // Outer sector, patches 2, 3, 4, 5
173             rowOffset = AliL3Transform::GetFirstRow( 2 );
174
175         while ( readValue )
176             {
177             row = fTPCRawStream->GetRow();
178             if ( row != oldRow )
179                 {
180                 if ( oldRow!=-1 && rowSize != sizeof(AliL3DigitRowData)+currentRow->fNDigit*sizeof(AliL3DigitData) )
181                     {
182                     Logging( kHLTLogFatal, "TPCRawDataUnpackerSubscriber::ProcessEvent", "Size inconsistency", 
183                              "Size inconsistency for row %d data: %lu != %lu (%lu digits).", oldRow, rowSize, 
184                              sizeof(AliL3DigitRowData)+currentRow->fNDigit*sizeof(AliL3DigitData), currentRow->fNDigit );
185                     }
186                 rowSize = 0;
187                 if ( size < outputSize+sizeof(AliL3DigitRowData) )
188                     {
189                     Logging( kHLTLogFatal, "TPCRawDataUnpackerSubscriber::ProcessEvent", "Too much data", 
190                              "Output data too big, output memory full. Aborting event 0x%08lX (%lu)" , 
191                              evtData.fEventID, evtData.fEventID );
192                     return 0;
193                     }
194                 currentRow = (AliL3DigitRowData*)(outBPtr+outputSize);
195                 currentDigit = currentRow->fDigitData;
196                 currentRow->fRow = row+rowOffset;
197                 currentRow->fNDigit = 0;
198                 oldRow = row;
199                 outputSize += sizeof(AliL3DigitRowData);
200                 blockOutputSize += sizeof(AliL3DigitRowData);
201                 rowSize += sizeof(AliL3DigitRowData);
202                 }
203             if ( size < outputSize+sizeof(AliL3DigitData) )
204                 {
205                 Logging( kHLTLogFatal, "TPCRawDataUnpackerSubscriber::ProcessEvent", "Too much data", 
206                          "Output data too big, output memory full. Aborting event 0x%08lX (%lu)" , 
207                          evtData.fEventID, evtData.fEventID );
208                 return 0;
209                 }
210             currentDigit->fCharge = fTPCRawStream->GetSignal();
211             currentDigit->fPad = fTPCRawStream->GetPad();
212             currentDigit->fTime = fTPCRawStream->GetTime();
213             currentRow->fNDigit++;
214             currentDigit++;
215             outputSize += sizeof(AliL3DigitData);
216             blockOutputSize += sizeof(AliL3DigitData);
217             rowSize += sizeof(AliL3DigitData);
218             readValue = fTPCRawStream->Next();
219             }
220         if ( oldRow!=-1 && rowSize != sizeof(AliL3DigitRowData)+currentRow->fNDigit*sizeof(AliL3DigitData) )
221             {
222             Logging( kHLTLogFatal, "TPCRawDataUnpackerSubscriber::ProcessEvent", "Size inconsistency", 
223                      "Size inconsistency for row %d data: %lu != %lu (%lu digits).", oldRow, rowSize, 
224                      sizeof(AliL3DigitRowData)+currentRow->fNDigit*sizeof(AliL3DigitData), currentRow->fNDigit );
225             }
226
227         AliHLTComponent_BlockData bd;
228         FillBlockData( bd );
229         bd.fOffset = outputSize-blockOutputSize;
230         bd.fSize = blockOutputSize;
231         bd.fSpecification = iter->fSpecification;
232         //AliHLTSubEventDescriptor::FillBlockAttributes( bd.fAttributes );
233         outputBlocks.push_back( bd );
234         }
235
236     
237     size = outputSize;
238     return 0;
239     }
240
241