1 /**************************************************************************
2 * This file is property of and copyright by the ALICE HLT Project *
3 * All rights reserved. *
6 * Indranil Das <indra.das@saha.ac.in> *
7 * Artur Szostak <artursz@iafrica.com> *
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 *
14 * about the suitability of this software for any purpose. It is *
15 * provided "as is" without express or implied warranty. *
16 **************************************************************************/
21 /// @file AliHLTMUONTriggerReconstructorComponent.cxx
22 /// @author Indranil Das <indra.das@saha.ac.in>, Artur Szostak <artursz@iafrica.com>
24 /// @brief Implementation of the trigger DDL reconstructor component.
27 #include "AliHLTMUONTriggerReconstructorComponent.h"
28 #include "AliHLTMUONTriggerReconstructor.h"
29 #include "AliHLTMUONHitReconstructor.h"
30 #include "AliHLTMUONConstants.h"
31 #include "AliHLTMUONUtils.h"
32 #include "AliHLTMUONDataBlockWriter.h"
38 ClassImp(AliHLTMUONTriggerReconstructorComponent)
41 AliHLTMUONTriggerReconstructorComponent::AliHLTMUONTriggerReconstructorComponent() :
45 fWarnForUnexpecedBlock(false),
46 fSuppressPartialTrigs(false)
49 /// Default constructor.
54 AliHLTMUONTriggerReconstructorComponent::~AliHLTMUONTriggerReconstructorComponent()
57 /// Default destructor.
62 const char* AliHLTMUONTriggerReconstructorComponent::GetComponentID()
65 /// Inherited from AliHLTComponent. Returns the component ID.
68 return AliHLTMUONConstants::TriggerReconstructorId();
72 void AliHLTMUONTriggerReconstructorComponent::GetInputDataTypes( std::vector<AliHLTComponentDataType>& list)
75 /// Inherited from AliHLTProcessor. Returns the list of expected input data types.
79 list.push_back( AliHLTMUONConstants::DDLRawDataType() );
83 AliHLTComponentDataType AliHLTMUONTriggerReconstructorComponent::GetOutputDataType()
86 /// Inherited from AliHLTComponent. Returns the output data type.
89 return AliHLTMUONConstants::TriggerRecordsBlockDataType();
93 void AliHLTMUONTriggerReconstructorComponent::GetOutputDataSize(
94 unsigned long& constBase, double& inputMultiplier
98 /// Inherited from AliHLTComponent. Returns an estimate of the expected output data size.
101 constBase = sizeof(AliHLTMUONTriggerRecordsBlockWriter::HeaderType);
106 AliHLTComponent* AliHLTMUONTriggerReconstructorComponent::Spawn()
109 /// Inherited from AliHLTComponent. Creates a new object instance.
112 return new AliHLTMUONTriggerReconstructorComponent;
116 int AliHLTMUONTriggerReconstructorComponent::DoInit(int argc, const char** argv)
119 /// Inherited from AliHLTComponent.
120 /// Parses the command line parameters and initialises the component.
123 // perform initialization.
125 HLTInfo("Initialising dHLT trigger reconstructor component.");
127 fWarnForUnexpecedBlock = false;
128 fSuppressPartialTrigs = false;
129 assert(fTrigRec == NULL);
130 fTrigRec = new AliHLTMUONTriggerReconstructor();
132 const char* lutFileName = NULL;
134 for (int i = 0; i < argc; i++)
136 if ( !strcmp( argv[i], "-lut" ) )
140 HLTError("LookupTable filename not specified." );
141 return EINVAL; /* Invalid argument */
144 lutFileName = argv[i+1];
150 if ( !strcmp( argv[i], "-ddl" ) )
154 HLTError("DDL number not specified." );
155 return EINVAL; /* Invalid argument */
159 unsigned long num = strtoul(argv[i+1], &cpErr, 0);
160 if (cpErr == NULL or *cpErr != '\0')
162 HLTError("Cannot convert '%s' to a DDL Number.", argv[i+1] );
165 if (num < 21 or 22 < num)
167 HLTError("The DDL number must be in the range [21..22].");
170 fDDL = num - 1; // Convert to DDL number in the range 0..21
176 if (not strcmp( argv[i], "-warn_on_unexpected_block" ))
178 fWarnForUnexpecedBlock = true;
182 if (not strcmp( argv[i], "-suppress_partial_triggers" ))
184 fSuppressPartialTrigs = true;
188 HLTError("Unknown option '%s'.", argv[i] );
195 HLTWarning("DDL number not specified. Cannot check if incomming data is valid.");
198 if (lutFileName != NULL)
200 if (not ReadLookUpTable(lutFileName))
202 HLTError("Failed to read lut, lut cannot be read");
203 return ENOENT ; /* No such file or directory */
208 HLTWarning("The lookup table has not been specified. Output results will be invalid.");
215 int AliHLTMUONTriggerReconstructorComponent::DoDeinit()
218 /// Inherited from AliHLTComponent. Performs a cleanup of the component.
221 HLTInfo("Deinitialising dHLT trigger reconstructor component.");
223 if (fTrigRec != NULL)
232 int AliHLTMUONTriggerReconstructorComponent::DoEvent(
233 const AliHLTComponentEventData& evtData,
234 const AliHLTComponentBlockData* blocks,
235 AliHLTComponentTriggerData& /*trigData*/,
236 AliHLTUInt8_t* outputPtr,
237 AliHLTUInt32_t& size,
238 std::vector<AliHLTComponentBlockData>& outputBlocks
242 /// Inherited from AliHLTProcessor. Processes the new event data.
246 unsigned long totalSize = 0; // Amount of memory currently consumed in bytes.
248 HLTDebug("Processing event %llu with %u input data blocks.",
249 evtData.fEventID, evtData.fBlockCnt
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++)
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';
266 HLTDebug("Handling block: %u, with fDataType.fID = '%s',"
267 " fDataType.fID = '%s', fPtr = %p and fSize = %u bytes.",
268 n, static_cast<char*>(id), static_cast<char*>(origin),
269 blocks[n].fPtr, blocks[n].fSize
272 if (blocks[n].fDataType != AliHLTMUONConstants::DDLRawDataType()
273 or not AliHLTMUONUtils::IsTriggerDDL(blocks[n].fSpecification)
276 // Log a message indicating that we got a data block that we
277 // do not know how to handle.
278 char id[kAliHLTComponentDataTypefIDsize+1];
279 for (int i = 0; i < kAliHLTComponentDataTypefIDsize; i++)
280 id[i] = blocks[n].fDataType.fID[i];
281 id[kAliHLTComponentDataTypefIDsize] = '\0';
282 char origin[kAliHLTComponentDataTypefOriginSize+1];
283 for (int i = 0; i < kAliHLTComponentDataTypefOriginSize; i++)
284 origin[i] = blocks[n].fDataType.fOrigin[i];
285 origin[kAliHLTComponentDataTypefOriginSize] = '\0';
287 if (fWarnForUnexpecedBlock)
288 HLTWarning("Received a data block of a type we cannot handle: '%s' origin: '%s' spec: 0x%X",
289 static_cast<char*>(id), static_cast<char*>(origin), blocks[n].fSpecification
292 HLTDebug("Received a data block of a type we cannot handle: '%s' origin: '%s' spec: 0x%X",
293 static_cast<char*>(id), static_cast<char*>(origin), blocks[n].fSpecification
300 AliHLTMUONUtils::UnpackSpecBits(blocks[n].fSpecification, ddl);
303 HLTWarning("Received trigger DDL raw data from a DDL which we did not expect.");
306 // Create a new output data block and initialise the header.
307 AliHLTMUONTriggerRecordsBlockWriter block(outputPtr+totalSize, size-totalSize);
308 if (not block.InitCommonHeader())
310 HLTError("There is not enough space in the output buffer for the new data block.",
311 " We require at least %ufTrigRec->GetkDDLHeaderSize() bytes, but have %u bytes left.",
312 sizeof(AliHLTMUONTriggerRecordsBlockWriter::HeaderType),
318 AliHLTUInt32_t totalDDLSize = blocks[n].fSize / sizeof(AliHLTUInt32_t);
319 AliHLTUInt32_t ddlRawDataSize = totalDDLSize - 8;
320 AliHLTUInt32_t* buffer = reinterpret_cast<AliHLTUInt32_t*>(blocks[n].fPtr) + 8;
321 AliHLTUInt32_t nofTrigRec = block.MaxNumberOfEntries();
323 bool runOk = fTrigRec->Run(
324 buffer, ddlRawDataSize,
325 block.GetArray(), nofTrigRec,
326 fSuppressPartialTrigs
330 HLTError("Error while processing of trigger DDL reconstruction algorithm.");
331 size = totalSize; // Must tell the framework how much buffer space was used.
335 // nofTrigRec should now contain the number of triggers actually found
336 // and filled into the output data block, so we can set this number.
337 assert( nofTrigRec <= block.MaxNumberOfEntries() );
338 block.SetNumberOfEntries(nofTrigRec);
340 HLTDebug("Number of trigger records found is %d", nofTrigRec);
342 // Fill a block data structure for our output block.
343 AliHLTComponentBlockData bd;
346 // This block's start (offset) is after all other blocks written so far.
347 bd.fOffset = totalSize;
348 bd.fSize = block.BytesUsed();
349 bd.fDataType = AliHLTMUONConstants::TriggerRecordsBlockDataType();
350 bd.fSpecification = blocks[n].fSpecification;
351 outputBlocks.push_back(bd);
353 HLTDebug("Created a new output data block at fPtr = %p,"
354 " with fOffset = %u (0x%.X) and fSize = %u bytes.",
355 bd.fPtr, bd.fOffset, bd.fOffset, bd.fSize
358 // Increase the total amount of data written so far to our output memory.
359 totalSize += block.BytesUsed();
362 // Finally we set the total size of output memory we consumed.
368 bool AliHLTMUONTriggerReconstructorComponent::ReadLookUpTable(const char* lutpath)
371 /// Read in the lookup table from file.
374 assert(fTrigRec != NULL);
377 file.open(lutpath, fstream::binary | fstream::in);
380 HLTError("Could not open file: %s", lutpath);
384 file.read(reinterpret_cast<char*>(fTrigRec->LookupTableBuffer()), fTrigRec->LookupTableSize());
387 HLTError("The file %s was too short to contain a valid lookup table for this component.", lutpath);
393 HLTError("Could not read from file: %s", lutpath);