]>
Commit | Line | Data |
---|---|---|
6efe69e7 | 1 | /************************************************************************** |
b39b98c8 | 2 | * This file is property of and copyright by the ALICE HLT Project * |
6efe69e7 | 3 | * All rights reserved. * |
4 | * * | |
5 | * Primary Authors: * | |
6 | * Indranil Das <indra.das@saha.ac.in> * | |
b39b98c8 | 7 | * Artur Szostak <artursz@iafrica.com> * |
6efe69e7 | 8 | * * |
9 | * Permission to use, copy, modify and distribute this software and its * | |
10 | * documentation strictly for non-commercial purposes is hereby granted * | |
11 | * without fee, provided that the above copyright notice appears in all * | |
12 | * copies and that both the copyright notice and this permission notice * | |
13 | * appear in the supporting documentation. The authors make no claims * | |
b39b98c8 | 14 | * about the suitability of this software for any purpose. It is * |
6efe69e7 | 15 | * provided "as is" without express or implied warranty. * |
16 | **************************************************************************/ | |
17 | ||
18 | /* $Id$ */ | |
19 | ||
6253e09b | 20 | /// |
21 | /// @file AliHLTMUONTriggerReconstructorComponent.cxx | |
22 | /// @author Indranil Das <indra.das@saha.ac.in>, Artur Szostak <artursz@iafrica.com> | |
23 | /// @date | |
24 | /// @brief Implementation of the trigger DDL reconstructor component. | |
25 | /// | |
6efe69e7 | 26 | |
6efe69e7 | 27 | #include "AliHLTMUONTriggerReconstructorComponent.h" |
960d54ad | 28 | #include "AliHLTMUONTriggerReconstructor.h" |
29 | #include "AliHLTMUONHitReconstructor.h" | |
30 | #include "AliHLTMUONConstants.h" | |
b39b98c8 | 31 | #include "AliHLTMUONUtils.h" |
227e7192 | 32 | #include "AliHLTMUONDataBlockWriter.h" |
33 | #include <cstdlib> | |
34 | #include <cerrno> | |
5d1682b9 | 35 | #include <cassert> |
b39b98c8 | 36 | #include <fstream> |
6efe69e7 | 37 | |
6efe69e7 | 38 | ClassImp(AliHLTMUONTriggerReconstructorComponent) |
b39b98c8 | 39 | |
40 | ||
227e7192 | 41 | AliHLTMUONTriggerReconstructorComponent::AliHLTMUONTriggerReconstructorComponent() : |
6253e09b | 42 | AliHLTProcessor(), |
227e7192 | 43 | fTrigRec(NULL), |
b39b98c8 | 44 | fDDL(-1), |
80590aa1 | 45 | fWarnForUnexpecedBlock(false), |
46 | fSuppressPartialTrigs(false) | |
960d54ad | 47 | { |
6253e09b | 48 | /// |
49 | /// Default constructor. | |
50 | /// | |
960d54ad | 51 | } |
52 | ||
6efe69e7 | 53 | |
54 | AliHLTMUONTriggerReconstructorComponent::~AliHLTMUONTriggerReconstructorComponent() | |
960d54ad | 55 | { |
6253e09b | 56 | /// |
57 | /// Default destructor. | |
58 | /// | |
960d54ad | 59 | } |
60 | ||
6efe69e7 | 61 | |
62 | const char* AliHLTMUONTriggerReconstructorComponent::GetComponentID() | |
960d54ad | 63 | { |
6253e09b | 64 | /// |
65 | /// Inherited from AliHLTComponent. Returns the component ID. | |
66 | /// | |
67 | ||
227e7192 | 68 | return AliHLTMUONConstants::TriggerReconstructorId(); |
960d54ad | 69 | } |
70 | ||
71 | ||
72 | void AliHLTMUONTriggerReconstructorComponent::GetInputDataTypes( std::vector<AliHLTComponentDataType>& list) | |
73 | { | |
6253e09b | 74 | /// |
75 | /// Inherited from AliHLTProcessor. Returns the list of expected input data types. | |
76 | /// | |
77 | ||
227e7192 | 78 | list.clear(); |
79 | list.push_back( AliHLTMUONConstants::TriggerDDLRawDataType() ); | |
960d54ad | 80 | } |
6efe69e7 | 81 | |
6efe69e7 | 82 | |
83 | AliHLTComponentDataType AliHLTMUONTriggerReconstructorComponent::GetOutputDataType() | |
960d54ad | 84 | { |
6253e09b | 85 | /// |
86 | /// Inherited from AliHLTComponent. Returns the output data type. | |
87 | /// | |
88 | ||
227e7192 | 89 | return AliHLTMUONConstants::TriggerRecordsBlockDataType(); |
960d54ad | 90 | } |
6efe69e7 | 91 | |
6efe69e7 | 92 | |
227e7192 | 93 | void AliHLTMUONTriggerReconstructorComponent::GetOutputDataSize( |
94 | unsigned long& constBase, double& inputMultiplier | |
95 | ) | |
960d54ad | 96 | { |
6253e09b | 97 | /// |
98 | /// Inherited from AliHLTComponent. Returns an estimate of the expected output data size. | |
99 | /// | |
100 | ||
227e7192 | 101 | constBase = sizeof(AliHLTMUONTriggerRecordsBlockWriter::HeaderType); |
c2e03d6e | 102 | inputMultiplier = 4; |
960d54ad | 103 | } |
6efe69e7 | 104 | |
105 | ||
6efe69e7 | 106 | AliHLTComponent* AliHLTMUONTriggerReconstructorComponent::Spawn() |
960d54ad | 107 | { |
6253e09b | 108 | /// |
109 | /// Inherited from AliHLTComponent. Creates a new object instance. | |
110 | /// | |
111 | ||
227e7192 | 112 | return new AliHLTMUONTriggerReconstructorComponent; |
960d54ad | 113 | } |
114 | ||
6efe69e7 | 115 | |
960d54ad | 116 | int AliHLTMUONTriggerReconstructorComponent::DoInit(int argc, const char** argv) |
6efe69e7 | 117 | { |
6253e09b | 118 | /// |
119 | /// Inherited from AliHLTComponent. | |
120 | /// Parses the command line parameters and initialises the component. | |
121 | /// | |
122 | ||
b39b98c8 | 123 | // perform initialization. |
124 | ||
125 | HLTInfo("Initialising dHLT trigger reconstructor component."); | |
6efe69e7 | 126 | |
b39b98c8 | 127 | fWarnForUnexpecedBlock = false; |
128 | fSuppressPartialTrigs = false; | |
129 | assert(fTrigRec == NULL); | |
130 | fTrigRec = new AliHLTMUONTriggerReconstructor(); | |
960d54ad | 131 | |
b39b98c8 | 132 | const char* lutFileName = NULL; |
133 | ||
134 | for (int i = 0; i < argc; i++) | |
135 | { | |
136 | if ( !strcmp( argv[i], "-lut" ) ) | |
137 | { | |
138 | if ( argc <= i+1 ) | |
139 | { | |
140 | HLTError("LookupTable filename not specified." ); | |
141 | return EINVAL; /* Invalid argument */ | |
142 | } | |
143 | ||
144 | lutFileName = argv[i+1]; | |
145 | ||
146 | i++; | |
147 | continue; | |
148 | } | |
149 | ||
150 | if ( !strcmp( argv[i], "-ddl" ) ) | |
151 | { | |
152 | if ( argc <= i+1 ) | |
153 | { | |
154 | HLTError("DDL number not specified." ); | |
155 | return EINVAL; /* Invalid argument */ | |
156 | } | |
157 | ||
158 | char* cpErr = NULL; | |
159 | unsigned long num = strtoul(argv[i+1], &cpErr, 0); | |
160 | if (cpErr == NULL or *cpErr != '\0') | |
161 | { | |
162 | HLTError("Cannot convert '%s' to a DDL Number.", argv[i+1] ); | |
163 | return EINVAL; | |
164 | } | |
165 | if (num < 21 or 22 < num) | |
166 | { | |
167 | HLTError("The DDL number must be in the range [21..22]."); | |
168 | return EINVAL; | |
169 | } | |
170 | fDDL = num - 1; // Convert to DDL number in the range 0..21 | |
171 | ||
172 | i++; | |
173 | continue; | |
174 | } | |
175 | ||
176 | if (not strcmp( argv[i], "-warn_on_unexpected_block" )) | |
177 | { | |
178 | fWarnForUnexpecedBlock = true; | |
179 | continue; | |
180 | } | |
181 | ||
182 | if (not strcmp( argv[i], "-suppress_partial_triggers" )) | |
183 | { | |
184 | fSuppressPartialTrigs = true; | |
185 | continue; | |
186 | } | |
187 | ||
188 | HLTError("Unknown option '%s'.", argv[i] ); | |
189 | return EINVAL; | |
190 | ||
191 | }//while loop | |
192 | ||
193 | if (fDDL == -1) | |
194 | { | |
195 | HLTWarning("DDL number not specified. Cannot check if incomming data is valid."); | |
960d54ad | 196 | } |
960d54ad | 197 | |
b39b98c8 | 198 | if (lutFileName != NULL) |
199 | { | |
200 | if (not ReadLookUpTable(lutFileName)) | |
201 | { | |
202 | HLTError("Failed to read lut, lut cannot be read"); | |
203 | return ENOENT ; /* No such file or directory */ | |
204 | } | |
960d54ad | 205 | } |
b39b98c8 | 206 | else |
207 | { | |
208 | HLTWarning("The lookup table has not been specified. Output results will be invalid."); | |
960d54ad | 209 | } |
b39b98c8 | 210 | |
211 | return 0; | |
6efe69e7 | 212 | } |
213 | ||
960d54ad | 214 | |
6efe69e7 | 215 | int AliHLTMUONTriggerReconstructorComponent::DoDeinit() |
960d54ad | 216 | { |
6253e09b | 217 | /// |
218 | /// Inherited from AliHLTComponent. Performs a cleanup of the component. | |
219 | /// | |
220 | ||
b39b98c8 | 221 | HLTInfo("Deinitialising dHLT trigger reconstructor component."); |
227e7192 | 222 | |
b39b98c8 | 223 | if (fTrigRec != NULL) |
227e7192 | 224 | { |
225 | delete fTrigRec; | |
226 | fTrigRec = NULL; | |
227 | } | |
228 | return 0; | |
960d54ad | 229 | } |
6efe69e7 | 230 | |
227e7192 | 231 | |
960d54ad | 232 | int AliHLTMUONTriggerReconstructorComponent::DoEvent( |
233 | const AliHLTComponentEventData& evtData, | |
b39b98c8 | 234 | const AliHLTComponentBlockData* blocks, |
235 | AliHLTComponentTriggerData& /*trigData*/, | |
236 | AliHLTUInt8_t* outputPtr, | |
960d54ad | 237 | AliHLTUInt32_t& size, |
238 | std::vector<AliHLTComponentBlockData>& outputBlocks | |
239 | ) | |
240 | { | |
6253e09b | 241 | /// |
242 | /// Inherited from AliHLTProcessor. Processes the new event data. | |
243 | /// | |
244 | ||
227e7192 | 245 | // Process an event |
246 | unsigned long totalSize = 0; // Amount of memory currently consumed in bytes. | |
6efe69e7 | 247 | |
227e7192 | 248 | HLTDebug("Processing event %llu with %u input data blocks.", |
249 | evtData.fEventID, evtData.fBlockCnt | |
250 | ); | |
6efe69e7 | 251 | |
227e7192 | 252 | // Loop over all input blocks in the event and run the trigger DDL |
253 | // reconstruction algorithm on the raw data. | |
254 | for (AliHLTUInt32_t n = 0; n < evtData.fBlockCnt; n++) | |
255 | { | |
5d1682b9 | 256 | #ifdef __DEBUG |
227e7192 | 257 | char id[kAliHLTComponentDataTypefIDsize+1]; |
258 | for (int i = 0; i < kAliHLTComponentDataTypefIDsize; i++) | |
259 | id[i] = blocks[n].fDataType.fID[i]; | |
260 | id[kAliHLTComponentDataTypefIDsize] = '\0'; | |
261 | char origin[kAliHLTComponentDataTypefOriginSize+1]; | |
262 | for (int i = 0; i < kAliHLTComponentDataTypefOriginSize; i++) | |
263 | origin[i] = blocks[n].fDataType.fOrigin[i]; | |
264 | origin[kAliHLTComponentDataTypefOriginSize] = '\0'; | |
5d1682b9 | 265 | #endif // __DEBUG |
227e7192 | 266 | HLTDebug("Handling block: %u, with fDataType.fID = '%s'," |
267 | " fDataType.fID = '%s', fPtr = %p and fSize = %u bytes.", | |
a31f86fa | 268 | n, static_cast<char*>(id), static_cast<char*>(origin), |
227e7192 | 269 | blocks[n].fPtr, blocks[n].fSize |
270 | ); | |
271 | ||
272 | if (blocks[n].fDataType != AliHLTMUONConstants::TriggerDDLRawDataType()) | |
273 | { | |
274 | // Log a message indicating that we got a data block that we | |
275 | // do not know how to handle. | |
276 | char id[kAliHLTComponentDataTypefIDsize+1]; | |
277 | for (int i = 0; i < kAliHLTComponentDataTypefIDsize; i++) | |
278 | id[i] = blocks[n].fDataType.fID[i]; | |
279 | id[kAliHLTComponentDataTypefIDsize] = '\0'; | |
280 | char origin[kAliHLTComponentDataTypefOriginSize+1]; | |
281 | for (int i = 0; i < kAliHLTComponentDataTypefOriginSize; i++) | |
282 | origin[i] = blocks[n].fDataType.fOrigin[i]; | |
283 | origin[kAliHLTComponentDataTypefOriginSize] = '\0'; | |
284 | ||
5d1682b9 | 285 | if (fWarnForUnexpecedBlock) |
286 | HLTWarning("Received a data block of a type we can not handle: %s origin %s", | |
287 | static_cast<char*>(id), static_cast<char*>(origin) | |
288 | ); | |
289 | else | |
290 | HLTDebug("Received a data block of a type we can not handle: %s origin %s", | |
291 | static_cast<char*>(id), static_cast<char*>(origin) | |
292 | ); | |
293 | ||
227e7192 | 294 | continue; |
295 | } | |
296 | ||
b39b98c8 | 297 | bool ddl[22]; |
298 | AliHLTMUONUtils::UnpackSpecBits(blocks[n].fSpecification, ddl); | |
299 | if (not ddl[fDDL]) | |
300 | { | |
301 | HLTWarning("Received trigger DDL raw data from a DDL which we did not expect."); | |
302 | } | |
303 | ||
227e7192 | 304 | // Create a new output data block and initialise the header. |
305 | AliHLTMUONTriggerRecordsBlockWriter block(outputPtr+totalSize, size-totalSize); | |
306 | if (not block.InitCommonHeader()) | |
307 | { | |
308 | HLTError("There is not enough space in the output buffer for the new data block.", | |
b39b98c8 | 309 | " We require at least %ufTrigRec->GetkDDLHeaderSize() bytes, but have %u bytes left.", |
227e7192 | 310 | sizeof(AliHLTMUONTriggerRecordsBlockWriter::HeaderType), |
311 | block.BufferSize() | |
312 | ); | |
313 | break; | |
314 | } | |
315 | ||
316 | AliHLTUInt32_t totalDDLSize = blocks[n].fSize / sizeof(AliHLTUInt32_t); | |
b39b98c8 | 317 | AliHLTUInt32_t ddlRawDataSize = totalDDLSize - 8; |
318 | AliHLTUInt32_t* buffer = reinterpret_cast<AliHLTUInt32_t*>(blocks[n].fPtr) + 8; | |
227e7192 | 319 | AliHLTUInt32_t nofTrigRec = block.MaxNumberOfEntries(); |
320 | ||
80590aa1 | 321 | bool runOk = fTrigRec->Run( |
322 | buffer, ddlRawDataSize, | |
323 | block.GetArray(), nofTrigRec, | |
324 | fSuppressPartialTrigs | |
325 | ); | |
326 | if (not runOk) | |
227e7192 | 327 | { |
328 | HLTError("Error while processing of trigger DDL reconstruction algorithm."); | |
329 | size = totalSize; // Must tell the framework how much buffer space was used. | |
330 | return EIO; | |
331 | } | |
332 | ||
333 | // nofTrigRec should now contain the number of triggers actually found | |
334 | // and filled into the output data block, so we can set this number. | |
335 | assert( nofTrigRec <= block.MaxNumberOfEntries() ); | |
336 | block.SetNumberOfEntries(nofTrigRec); | |
337 | ||
338 | HLTDebug("Number of trigger records found is %d", nofTrigRec); | |
339 | ||
340 | // Fill a block data structure for our output block. | |
341 | AliHLTComponentBlockData bd; | |
342 | FillBlockData(bd); | |
343 | bd.fPtr = outputPtr; | |
344 | // This block's start (offset) is after all other blocks written so far. | |
345 | bd.fOffset = totalSize; | |
346 | bd.fSize = block.BytesUsed(); | |
347 | bd.fDataType = AliHLTMUONConstants::TriggerRecordsBlockDataType(); | |
348 | bd.fSpecification = blocks[n].fSpecification; | |
349 | outputBlocks.push_back(bd); | |
350 | ||
351 | HLTDebug("Created a new output data block at fPtr = %p," | |
352 | " with fOffset = %u (0x%.X) and fSize = %u bytes.", | |
353 | bd.fPtr, bd.fOffset, bd.fOffset, bd.fSize | |
354 | ); | |
355 | ||
356 | // Increase the total amount of data written so far to our output memory. | |
357 | totalSize += block.BytesUsed(); | |
358 | } | |
960d54ad | 359 | |
227e7192 | 360 | // Finally we set the total size of output memory we consumed. |
361 | size = totalSize; | |
362 | return 0; | |
960d54ad | 363 | } |
364 | ||
6efe69e7 | 365 | |
b39b98c8 | 366 | bool AliHLTMUONTriggerReconstructorComponent::ReadLookUpTable(const char* lutpath) |
6efe69e7 | 367 | { |
6253e09b | 368 | /// |
369 | /// Read in the lookup table from file. | |
370 | /// | |
371 | ||
b39b98c8 | 372 | assert(fTrigRec != NULL); |
6efe69e7 | 373 | |
b39b98c8 | 374 | fstream file; |
375 | file.open(lutpath, fstream::binary | fstream::in); | |
376 | if (not file) | |
377 | { | |
378 | HLTError("Could not open file: %s", lutpath); | |
379 | return false; | |
380 | } | |
381 | ||
382 | file.read(reinterpret_cast<char*>(fTrigRec->LookupTableBuffer()), fTrigRec->LookupTableSize()); | |
383 | if (file.eof()) | |
384 | { | |
385 | HLTError("The file %s was too short to contain a valid lookup table for this component.", lutpath); | |
386 | file.close(); | |
387 | return false; | |
388 | } | |
389 | if (file.bad()) | |
390 | { | |
391 | HLTError("Could not read from file: %s", lutpath); | |
392 | file.close(); | |
393 | return false; | |
394 | } | |
395 | ||
396 | file.close(); | |
397 | return true; | |
960d54ad | 398 | } |