]>
Commit | Line | Data |
---|---|---|
6efe69e7 | 1 | /************************************************************************** |
2 | * This file is property of and copyright by the ALICE HLT Project * | |
3 | * All rights reserved. * | |
4 | * * | |
5 | * Primary Authors: * | |
6 | * Indranil Das <indra.das@saha.ac.in> * | |
7 | * * | |
8 | * Permission to use, copy, modify and distribute this software and its * | |
9 | * documentation strictly for non-commercial purposes is hereby granted * | |
10 | * without fee, provided that the above copyright notice appears in all * | |
11 | * copies and that both the copyright notice and this permission notice * | |
12 | * appear in the supporting documentation. The authors make no claims * | |
13 | * about the suitability of this software for any purpose. It is * | |
14 | * provided "as is" without express or implied warranty. * | |
15 | **************************************************************************/ | |
16 | ||
17 | /* $Id$ */ | |
18 | ||
19 | /** @file AliHLTMUONTriggerReconstructorComponent.cxx | |
20 | @author Indranil Das | |
21 | @date | |
22 | @brief A processing component for the dHLT TrigRec. */ | |
23 | ||
24 | #if __GNUC__ >= 3 | |
25 | using namespace std; | |
26 | #endif | |
27 | ||
28 | #include "AliHLTSystem.h" | |
29 | #include "AliHLTMUONTriggerReconstructorComponent.h" | |
30 | #include "AliHLTDefinitions.h" | |
31 | #include <stdlib.h> | |
32 | #include <errno.h> | |
33 | ||
34 | // this is a global object used for automatic component registration, do not use this | |
35 | AliHLTMUONTriggerReconstructorComponent gAliHLTMUONTriggerReconstructorComponent; | |
36 | ||
37 | ClassImp(AliHLTMUONTriggerReconstructorComponent) | |
38 | ||
39 | AliHLTMUONTriggerReconstructorComponent::AliHLTMUONTriggerReconstructorComponent() | |
40 | : | |
41 | fOutputPercentage(100), // By default we copy to the output exactly what we got as input | |
42 | fDDLDir(""), | |
43 | fDDL(0), | |
44 | fTrigRec(NULL) | |
45 | { | |
46 | } | |
47 | ||
48 | AliHLTMUONTriggerReconstructorComponent::~AliHLTMUONTriggerReconstructorComponent() | |
49 | { | |
50 | } | |
51 | ||
52 | const char* AliHLTMUONTriggerReconstructorComponent::GetComponentID() | |
53 | { | |
54 | return "MUONTrigRec"; // The ID of this component | |
55 | } | |
56 | ||
57 | void AliHLTMUONTriggerReconstructorComponent::GetInputDataTypes( vector<AliHLTComponentDataType>& list) | |
58 | { | |
59 | /* in order to be backward compatible we have to keep the old code, at | |
60 | * least for a while. Remember to use the new const kAliHLTVoidDataType | |
61 | * if you are using a more recent AliRoot version (from Jan 07) | |
62 | list.push_back(kAliHLTAnyDataType); // We do not have any requirements for our input data type(s). | |
63 | */ | |
64 | ||
65 | list.clear(); | |
66 | list.push_back( AliHLTMUONConstants::TriggerDDLRawDataType() ); | |
67 | } | |
68 | ||
69 | AliHLTComponentDataType AliHLTMUONTriggerReconstructorComponent::GetOutputDataType() | |
70 | { | |
71 | /* in order to be backward compatible we have to keep the old code, at | |
72 | * least for a while. Remember to use the new const kAliHLTVoidDataType | |
73 | * if you are using a more recent AliRoot version (from Jan 07) | |
74 | return kAliHLTVoidDataType; | |
75 | */ | |
76 | return AliHLTMUONConstants::TriggerRecordsBlockDataType(); | |
77 | } | |
78 | ||
79 | void AliHLTMUONTriggerReconstructorComponent::GetOutputDataSize( unsigned long& constBase, double& inputMultiplier ) | |
80 | { | |
81 | constBase = 0; | |
82 | inputMultiplier = ((double)fOutputPercentage)/100.0; | |
83 | } | |
84 | ||
85 | ||
86 | ||
87 | // Spawn function, return new instance of this class | |
88 | AliHLTComponent* AliHLTMUONTriggerReconstructorComponent::Spawn() | |
89 | { | |
90 | return new AliHLTMUONTriggerReconstructorComponent; | |
91 | } | |
92 | ||
93 | int AliHLTMUONTriggerReconstructorComponent::DoInit( int argc, const char** argv ) | |
94 | { | |
95 | // perform initialization. We check whether our relative output size is specified in the arguments. | |
96 | ||
97 | fTrigRec = new AliHLTMUONTriggerReconstructor(); | |
98 | ||
99 | HLTInfo("dHLT trigrec"); | |
100 | if (argc==0 && argv==NULL) { | |
101 | Logging( kHLTLogError, "AliHLTMUONTriggerReconstructorComponent::DoInit", "Arguments missing", " no arguments" ); | |
102 | // this is just to get rid of the warning "unused parameter" | |
103 | } | |
104 | ||
105 | //Int_t i = 0; | |
106 | char lutFileName[500], ddlDir[500]; | |
107 | ||
108 | fOutputPercentage = 100; | |
109 | int i = 0; | |
110 | char* cpErr; | |
111 | while ( i < argc ) | |
112 | { | |
113 | Logging( kHLTLogDebug, "HLT::MUONTrigRec::DoInit", "Arguments", "argv[%d] == %s", i, argv[i] ); | |
114 | if ( !strcmp( argv[i], "output_percentage" ) ) | |
115 | { | |
116 | if ( i+1>=argc ) | |
117 | { | |
118 | Logging(kHLTLogError, "HLT::MUONTrigRec::DoInit", "Missing Argument", "Missing output_percentage parameter"); | |
119 | return ENOTSUP; | |
120 | } | |
121 | Logging( kHLTLogDebug, "HLT::MUONTrigRec::DoInit", "Arguments", "argv[%d+1] == %s", i, argv[i+1] ); | |
122 | fOutputPercentage = strtoul( argv[i+1], &cpErr, 0 ); | |
123 | if ( *cpErr ) | |
124 | { | |
125 | Logging(kHLTLogError, "HLT::MUONTrigRec::DoInit", "Wrong Argument", "Cannot convert output_percentage parameter '%s'", argv[i+1] ); | |
126 | return EINVAL; | |
127 | } | |
128 | Logging( kHLTLogInfo, "HLT::MUONTrigRec::DoInit", "Output percentage set", "Output percentage set to %lu %%", fOutputPercentage ); | |
129 | i += 2; | |
130 | continue; | |
131 | } | |
132 | ||
133 | ||
134 | if ( !strcmp( argv[i], "lut" ) ) { | |
135 | if ( argc <= i+1 ) { | |
136 | Logging( kHLTLogError, "AliHLTMUONTriggerReconstructorComponent::DoInit", "Missing LookupTable filename", "LookupTable filename not specified" ); | |
137 | return EINVAL; /* Invalid argument */ | |
138 | } | |
139 | ||
140 | sprintf(lutFileName,"%s",argv[i+1]); | |
141 | ||
142 | i += 2; | |
143 | continue; | |
144 | }// lut argument | |
145 | ||
146 | ||
147 | if ( !strcmp( argv[i], "ddl" ) ) { | |
148 | if ( argc <= i+1 ) { | |
149 | Logging( kHLTLogError, "AliHLTMUONTriggerReconstructorComponent::DoInit", "Missing DDL argument", "DDL number not specified" ); | |
150 | HLTError("AliHLTMUONTriggerReconstructorComponent::DoInit : DDL number is not specified "); | |
151 | return EINVAL; /* Invalid argument */ | |
152 | } | |
153 | ||
154 | fDDL = atoi(argv[i+1]); | |
155 | ||
156 | i += 2; | |
157 | continue; | |
158 | }// ddl argument | |
159 | ||
160 | ||
161 | if ( !strcmp( argv[i], "rawdir" ) ) { | |
162 | if ( argc <= i+1 ) { | |
163 | Logging( kHLTLogError, "AliHLTMUONTriggerReconstructorComponent::DoInit", "Missing DDL directory", "DDL directory not specified" ); | |
164 | HLTError("AliHLTMUONTriggerReconstructorComponent::DoInit : DDL directory is not specified "); | |
165 | return EINVAL; /* Invalid argument */ | |
166 | } | |
167 | ||
168 | fDDLDir = argv[i+1] ; | |
169 | ||
170 | i += 2; | |
171 | continue; | |
172 | }// ddl directory argument | |
173 | ||
174 | Logging(kHLTLogError, "HLT::MUONTrigRec::DoInit", "Unknown Option", "Unknown option '%s'", argv[i] ); | |
175 | return EINVAL; | |
176 | ||
177 | }//while loop | |
178 | ||
179 | int lutline = fTrigRec->GetLutLine(); | |
180 | AliHLTMUONHitReconstructor::DHLTLut* lookupTable = new AliHLTMUONHitReconstructor::DHLTLut[lutline]; | |
181 | if(!ReadLookUpTable(lookupTable,lutFileName)){ | |
182 | Logging(kHLTLogInfo, "AliHLTMUONTriggerReconstructorComponent::DoInit", "Failed to read lut", "lut cannot be read, DoInit"); | |
183 | return ENOENT ; /* No such file or directory */ | |
184 | }else{ | |
185 | ||
186 | fTrigRec->LoadLookUpTable(lookupTable,fDDL); | |
187 | ||
188 | }// reading lut | |
189 | ||
190 | delete []lookupTable; | |
191 | ||
192 | return 0; | |
193 | } | |
194 | ||
195 | int AliHLTMUONTriggerReconstructorComponent::DoDeinit() | |
196 | { | |
197 | if(fTrigRec) | |
198 | delete fTrigRec; | |
199 | HLTInfo("dHLT trigrec"); | |
200 | return 0; | |
201 | ||
202 | return 0; | |
203 | } | |
204 | ||
205 | int AliHLTMUONTriggerReconstructorComponent::DoEvent( const AliHLTComponentEventData& evtData, const AliHLTComponentBlockData* blocks, | |
206 | AliHLTComponentTriggerData& trigData, AliHLTUInt8_t* outputPtr, | |
207 | AliHLTUInt32_t& size, vector<AliHLTComponentBlockData>& outputBlocks ) | |
208 | { | |
209 | // Process an event | |
210 | unsigned long totalSize = 0; | |
211 | Logging( kHLTLogInfo, "HLT::MUONTrigRec::DoEvent", "Output percentage set", "Output percentage set to %lu %% and totalSize %lu", fOutputPercentage,totalSize ); | |
212 | ||
213 | // Loop over all input blocks in the event | |
214 | for ( unsigned long n = 0; n < evtData.fBlockCnt; n++ ) | |
215 | { | |
216 | ||
217 | if ( totalSize > size ) | |
218 | break; | |
219 | ||
220 | int totalDDLSize = blocks[n].fSize/4; | |
221 | int ddlRawDataSize = totalDDLSize - AliHLTMUONTriggerReconstructor::GetkDDLHeaderSize(); | |
222 | //cout<<"ddlRawDataSize :"<<ddlRawDataSize<<endl; | |
223 | int *buffer = (int *)((int *)blocks[n].fPtr + AliHLTMUONTriggerReconstructor::GetkDDLHeaderSize()) ; | |
224 | ||
225 | AliHLTMUONTriggerRecordStruct trigRecord[300]; | |
226 | int nofTrigRec = 300; | |
227 | ||
228 | if(! (fTrigRec->Run(buffer,&ddlRawDataSize,trigRecord,&nofTrigRec))){ | |
229 | HLTError("ERROR In Processing of TrigRec Algo "); | |
230 | return EIO; | |
231 | } | |
232 | ||
233 | // if(! (fTrigRec->Run((int)evtData.fEventID,fDDL,trigRecord,&nofTrigRec))){ | |
234 | // HLTError("ERROR In Processing of TrigRec Algo "); | |
235 | // return EIO; | |
236 | // } | |
237 | ||
238 | unsigned long mySize = sizeof(AliHLTMUONTriggerRecordStruct)*nofTrigRec; | |
239 | ||
240 | // cout<<"nofHit "<<nofHit<<endl; | |
241 | // for(int i=0;i<nofHit;i++) | |
242 | // cout<<"\t 0 : recHit["<<i<<"].fX :"<<recHit[i].fX | |
243 | // <<" recHit["<<i<<"].fY :"<<recHit[i].fY | |
244 | // <<" recHit["<<i<<"].fZ :"<<recHit[i].fZ | |
245 | // <<" recHit["<<i<<"].fDetElemId :"<<recHit[i].fDetElemId | |
246 | // <<endl; | |
247 | ||
248 | //unsigned long mySize = (blocks[n].fSize * fOutputPercentage) / 100; | |
249 | ||
250 | Logging( kHLTLogInfo, "HLT::MUONTrigRec::DoEvent", "mySize set (1)", "mySize == %lu B - blocks[%lu].fSize == %lu - fOutputPercentage == %lu", | |
251 | mySize, n, blocks[n].fSize, fOutputPercentage ); | |
252 | ||
253 | // Check how much space we have left and adapt this output block's size accordingly. | |
254 | if ( totalSize + mySize > size ) | |
255 | mySize = size-totalSize; | |
256 | ||
257 | Logging( kHLTLogInfo, "HLT::MUONTrigRec::DoEvent", "mySize set (2)", "mySize == %lu B - totalSize == %lu - size == %lu", | |
258 | mySize, totalSize, size ); | |
259 | ||
260 | if ( mySize<=0 ) | |
261 | continue; // No room left to write a further block. | |
262 | ||
263 | // Now copy the input block | |
264 | unsigned long copied = 0; | |
265 | // First copy all full multiples of the input block | |
266 | ||
267 | // And the copy the remaining fragment of the block | |
268 | Logging( kHLTLogInfo, "1 : HLT::MUONTrigRec::DoEvent", "Copying", "Copying %lu B - Copied: %lu B - totalSize: %lu B", | |
269 | mySize-copied, copied, totalSize ); | |
270 | //memcpy( outputPtr+totalSize+copied, blocks[n].fPtr, mySize-copied ); | |
271 | memcpy( outputPtr+totalSize+copied, &trigRecord[0], mySize); | |
272 | Logging( kHLTLogInfo, "HLT::MUONTrigRec::DoEvent", "Copied", "Copied: %lu B - totalSize: %lu B", | |
273 | copied, totalSize ); | |
274 | // Fill a block data structure for our output block. | |
275 | AliHLTComponentBlockData ob; | |
276 | // Let the structure be filled with the default values. | |
277 | // This takes care of setting the shared memory and data type values to default values, | |
278 | // so that they can be filled in by the calling code. | |
279 | FillBlockData( ob ); | |
280 | // This block's start (offset) is after all other blocks written so far | |
281 | ob.fOffset = totalSize; | |
282 | // the size of this block's data. | |
283 | ob.fSize = mySize; | |
284 | // The specification of the data is copied from the input block. | |
285 | ob.fSpecification = blocks[n].fSpecification; | |
286 | // The data type is set automatically to the component's specified output data type. | |
287 | // Place this block into the list of output blocks | |
288 | outputBlocks.push_back( ob ); | |
289 | // Increase the total amount of data written so far to our output memory | |
290 | totalSize += mySize; | |
291 | } | |
292 | // Finally we set the total size of output memory we consumed. | |
293 | size = totalSize; | |
294 | ||
295 | return 0; | |
296 | } | |
297 | ||
298 | bool AliHLTMUONTriggerReconstructorComponent::ReadLookUpTable(AliHLTMUONHitReconstructor::DHLTLut* lookupTable, const char* lutpath) | |
299 | { | |
300 | if (fDDL < AliHLTMUONTriggerReconstructor::GetkDDLOffSet() || | |
301 | fDDL >= AliHLTMUONTriggerReconstructor::GetkDDLOffSet() + AliHLTMUONTriggerReconstructor::GetkNofDDL()){ | |
302 | HLTError("DDL number is out of range"); | |
303 | return false; | |
304 | } | |
305 | ||
306 | int lutLine = fTrigRec->GetLutLine(); | |
307 | ||
308 | FILE* fin = fopen(lutpath, "r"); | |
309 | if (fin == NULL){ | |
310 | HLTError("Failed to open file: %s",lutpath); | |
311 | return false; | |
312 | } | |
313 | ||
314 | for(int i=0;i<lutLine;i++){ | |
315 | fscanf( | |
316 | fin, | |
317 | "%d\t%d\t%d\t%f\t%f\t%f\t%d\t%d\n", | |
318 | &lookupTable[i].fIdManuChannel, | |
319 | &lookupTable[i].fIX, | |
320 | &lookupTable[i].fIY, | |
321 | &lookupTable[i].fRealX, | |
322 | &lookupTable[i].fRealY, | |
323 | &lookupTable[i].fRealZ, | |
324 | &lookupTable[i].fPlane, | |
325 | &lookupTable[i].fPcbZone | |
326 | ); | |
327 | } | |
328 | ||
329 | fclose(fin); | |
330 | return true; | |
331 | } | |
332 | ||
333 | // implement this as well. | |
334 |