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"
40 // This is a global object used for automatic component registration,
41 // do not use this for calculation.
42 AliHLTMUONTriggerReconstructorComponent gAliHLTMUONTriggerReconstructorComponent;
47 ClassImp(AliHLTMUONTriggerReconstructorComponent)
50 AliHLTMUONTriggerReconstructorComponent::AliHLTMUONTriggerReconstructorComponent() :
53 fWarnForUnexpecedBlock(false),
54 fSuppressPartialTrigs(false)
59 AliHLTMUONTriggerReconstructorComponent::~AliHLTMUONTriggerReconstructorComponent()
64 const char* AliHLTMUONTriggerReconstructorComponent::GetComponentID()
66 return AliHLTMUONConstants::TriggerReconstructorId();
70 void AliHLTMUONTriggerReconstructorComponent::GetInputDataTypes( std::vector<AliHLTComponentDataType>& list)
73 list.push_back( AliHLTMUONConstants::TriggerDDLRawDataType() );
77 AliHLTComponentDataType AliHLTMUONTriggerReconstructorComponent::GetOutputDataType()
79 return AliHLTMUONConstants::TriggerRecordsBlockDataType();
83 void AliHLTMUONTriggerReconstructorComponent::GetOutputDataSize(
84 unsigned long& constBase, double& inputMultiplier
87 constBase = sizeof(AliHLTMUONTriggerRecordsBlockWriter::HeaderType);
92 AliHLTComponent* AliHLTMUONTriggerReconstructorComponent::Spawn()
94 return new AliHLTMUONTriggerReconstructorComponent;
98 int AliHLTMUONTriggerReconstructorComponent::DoInit(int argc, const char** argv)
100 // perform initialization.
102 HLTInfo("Initialising dHLT trigger reconstructor component.");
104 fWarnForUnexpecedBlock = false;
105 fSuppressPartialTrigs = false;
106 assert(fTrigRec == NULL);
107 fTrigRec = new AliHLTMUONTriggerReconstructor();
109 const char* lutFileName = NULL;
111 for (int i = 0; i < argc; i++)
113 if ( !strcmp( argv[i], "-lut" ) )
117 HLTError("LookupTable filename not specified." );
118 return EINVAL; /* Invalid argument */
121 lutFileName = argv[i+1];
127 if ( !strcmp( argv[i], "-ddl" ) )
131 HLTError("DDL number not specified." );
132 return EINVAL; /* Invalid argument */
136 unsigned long num = strtoul(argv[i+1], &cpErr, 0);
137 if (cpErr == NULL or *cpErr != '\0')
139 HLTError("Cannot convert '%s' to a DDL Number.", argv[i+1] );
142 if (num < 21 or 22 < num)
144 HLTError("The DDL number must be in the range [21..22].");
147 fDDL = num - 1; // Convert to DDL number in the range 0..21
153 if (not strcmp( argv[i], "-warn_on_unexpected_block" ))
155 fWarnForUnexpecedBlock = true;
159 if (not strcmp( argv[i], "-suppress_partial_triggers" ))
161 fSuppressPartialTrigs = true;
165 HLTError("Unknown option '%s'.", argv[i] );
172 HLTWarning("DDL number not specified. Cannot check if incomming data is valid.");
175 if (lutFileName != NULL)
177 if (not ReadLookUpTable(lutFileName))
179 HLTError("Failed to read lut, lut cannot be read");
180 return ENOENT ; /* No such file or directory */
185 HLTWarning("The lookup table has not been specified. Output results will be invalid.");
192 int AliHLTMUONTriggerReconstructorComponent::DoDeinit()
194 HLTInfo("Deinitialising dHLT trigger reconstructor component.");
196 if (fTrigRec != NULL)
205 int AliHLTMUONTriggerReconstructorComponent::DoEvent(
206 const AliHLTComponentEventData& evtData,
207 const AliHLTComponentBlockData* blocks,
208 AliHLTComponentTriggerData& /*trigData*/,
209 AliHLTUInt8_t* outputPtr,
210 AliHLTUInt32_t& size,
211 std::vector<AliHLTComponentBlockData>& outputBlocks
215 unsigned long totalSize = 0; // Amount of memory currently consumed in bytes.
217 HLTDebug("Processing event %llu with %u input data blocks.",
218 evtData.fEventID, evtData.fBlockCnt
221 // Loop over all input blocks in the event and run the trigger DDL
222 // reconstruction algorithm on the raw data.
223 for (AliHLTUInt32_t n = 0; n < evtData.fBlockCnt; n++)
226 char id[kAliHLTComponentDataTypefIDsize+1];
227 for (int i = 0; i < kAliHLTComponentDataTypefIDsize; i++)
228 id[i] = blocks[n].fDataType.fID[i];
229 id[kAliHLTComponentDataTypefIDsize] = '\0';
230 char origin[kAliHLTComponentDataTypefOriginSize+1];
231 for (int i = 0; i < kAliHLTComponentDataTypefOriginSize; i++)
232 origin[i] = blocks[n].fDataType.fOrigin[i];
233 origin[kAliHLTComponentDataTypefOriginSize] = '\0';
235 HLTDebug("Handling block: %u, with fDataType.fID = '%s',"
236 " fDataType.fID = '%s', fPtr = %p and fSize = %u bytes.",
237 n, static_cast<char*>(id), static_cast<char*>(origin),
238 blocks[n].fPtr, blocks[n].fSize
241 if (blocks[n].fDataType != AliHLTMUONConstants::TriggerDDLRawDataType())
243 // Log a message indicating that we got a data block that we
244 // do not know how to handle.
245 char id[kAliHLTComponentDataTypefIDsize+1];
246 for (int i = 0; i < kAliHLTComponentDataTypefIDsize; i++)
247 id[i] = blocks[n].fDataType.fID[i];
248 id[kAliHLTComponentDataTypefIDsize] = '\0';
249 char origin[kAliHLTComponentDataTypefOriginSize+1];
250 for (int i = 0; i < kAliHLTComponentDataTypefOriginSize; i++)
251 origin[i] = blocks[n].fDataType.fOrigin[i];
252 origin[kAliHLTComponentDataTypefOriginSize] = '\0';
254 if (fWarnForUnexpecedBlock)
255 HLTWarning("Received a data block of a type we can not handle: %s origin %s",
256 static_cast<char*>(id), static_cast<char*>(origin)
259 HLTDebug("Received a data block of a type we can not handle: %s origin %s",
260 static_cast<char*>(id), static_cast<char*>(origin)
267 AliHLTMUONUtils::UnpackSpecBits(blocks[n].fSpecification, ddl);
270 HLTWarning("Received trigger DDL raw data from a DDL which we did not expect.");
273 // Create a new output data block and initialise the header.
274 AliHLTMUONTriggerRecordsBlockWriter block(outputPtr+totalSize, size-totalSize);
275 if (not block.InitCommonHeader())
277 HLTError("There is not enough space in the output buffer for the new data block.",
278 " We require at least %ufTrigRec->GetkDDLHeaderSize() bytes, but have %u bytes left.",
279 sizeof(AliHLTMUONTriggerRecordsBlockWriter::HeaderType),
285 AliHLTUInt32_t totalDDLSize = blocks[n].fSize / sizeof(AliHLTUInt32_t);
286 AliHLTUInt32_t ddlRawDataSize = totalDDLSize - 8;
287 AliHLTUInt32_t* buffer = reinterpret_cast<AliHLTUInt32_t*>(blocks[n].fPtr) + 8;
288 AliHLTUInt32_t nofTrigRec = block.MaxNumberOfEntries();
290 bool runOk = fTrigRec->Run(
291 buffer, ddlRawDataSize,
292 block.GetArray(), nofTrigRec,
293 fSuppressPartialTrigs
297 HLTError("Error while processing of trigger DDL reconstruction algorithm.");
298 size = totalSize; // Must tell the framework how much buffer space was used.
302 // nofTrigRec should now contain the number of triggers actually found
303 // and filled into the output data block, so we can set this number.
304 assert( nofTrigRec <= block.MaxNumberOfEntries() );
305 block.SetNumberOfEntries(nofTrigRec);
307 HLTDebug("Number of trigger records found is %d", nofTrigRec);
309 // Fill a block data structure for our output block.
310 AliHLTComponentBlockData bd;
313 // This block's start (offset) is after all other blocks written so far.
314 bd.fOffset = totalSize;
315 bd.fSize = block.BytesUsed();
316 bd.fDataType = AliHLTMUONConstants::TriggerRecordsBlockDataType();
317 bd.fSpecification = blocks[n].fSpecification;
318 outputBlocks.push_back(bd);
320 HLTDebug("Created a new output data block at fPtr = %p,"
321 " with fOffset = %u (0x%.X) and fSize = %u bytes.",
322 bd.fPtr, bd.fOffset, bd.fOffset, bd.fSize
325 // Increase the total amount of data written so far to our output memory.
326 totalSize += block.BytesUsed();
329 // Finally we set the total size of output memory we consumed.
335 bool AliHLTMUONTriggerReconstructorComponent::ReadLookUpTable(const char* lutpath)
337 assert(fTrigRec != NULL);
340 file.open(lutpath, fstream::binary | fstream::in);
343 HLTError("Could not open file: %s", lutpath);
347 file.read(reinterpret_cast<char*>(fTrigRec->LookupTableBuffer()), fTrigRec->LookupTableSize());
350 HLTError("The file %s was too short to contain a valid lookup table for this component.", lutpath);
356 HLTError("Could not read from file: %s", lutpath);