1 /**************************************************************************
2 * This file is property of and copyright by the ALICE HLT Project *
3 * All rights reserved. *
6 * Artur Szostak <artursz@iafrica.com> *
7 * Indranil Das <indra.das@saha.ac.in> *
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 AliHLTMUONMansoTrackerFSMComponent.cxx
22 * @author Artur Szostak <artursz@iafrica.com>,
23 * Indranil Das <indra.das@saha.ac.in>
25 * @brief Implementation of AliHLTMUONMansoTrackerFSMComponent class.
28 #include "AliHLTMUONMansoTrackerFSMComponent.h"
29 #include "AliHLTMUONConstants.h"
30 #include "AliHLTMUONUtils.h"
31 #include "AliHLTMUONMansoTrackerFSM.h"
32 #include "AliHLTMUONDataBlockReader.h"
33 #include "AliHLTMUONDataBlockWriter.h"
40 // The global object used for automatic component registration.
41 // Note DO NOT use this component for calculation!
42 AliHLTMUONMansoTrackerFSMComponent gAliHLTMUONMansoTrackerFSMComponent;
47 ClassImp(AliHLTMUONMansoTrackerFSMComponent);
50 AliHLTMUONMansoTrackerFSMComponent::AliHLTMUONMansoTrackerFSMComponent() :
52 AliHLTMUONMansoTrackerFSMCallback(),
56 fWarnForUnexpecedBlock(false)
61 AliHLTMUONMansoTrackerFSMComponent::~AliHLTMUONMansoTrackerFSMComponent()
63 assert( fTracker == NULL );
67 const char* AliHLTMUONMansoTrackerFSMComponent::GetComponentID()
69 return AliHLTMUONConstants::MansoTrackerFSMId();
73 void AliHLTMUONMansoTrackerFSMComponent::GetInputDataTypes(
74 vector<AliHLTComponentDataType>& list
77 assert( list.empty() );
78 list.push_back( AliHLTMUONConstants::TriggerRecordsBlockDataType() );
79 list.push_back( AliHLTMUONConstants::RecHitsBlockDataType() );
83 AliHLTComponentDataType AliHLTMUONMansoTrackerFSMComponent::GetOutputDataType()
85 return AliHLTMUONConstants::MansoTracksBlockDataType();
89 void AliHLTMUONMansoTrackerFSMComponent::GetOutputDataSize(
90 unsigned long& constBase, double& inputMultiplier
93 constBase = sizeof(AliHLTMUONMansoTracksBlockStruct);
98 AliHLTComponent* AliHLTMUONMansoTrackerFSMComponent::Spawn()
100 return new AliHLTMUONMansoTrackerFSMComponent;
104 int AliHLTMUONMansoTrackerFSMComponent::DoInit(int argc, const char** argv)
106 fTracker = new AliHLTMUONMansoTrackerFSM();
107 fTracker->SetCallback(this);
109 fWarnForUnexpecedBlock = false;
111 for (int i = 0; i < argc; i++)
113 if (strcmp(argv[i], "-warn_on_unexpected_block") == 0)
114 fWarnForUnexpecedBlock = true;
121 int AliHLTMUONMansoTrackerFSMComponent::DoDeinit()
123 if (fTracker != NULL)
132 int AliHLTMUONMansoTrackerFSMComponent::DoEvent(
133 const AliHLTComponentEventData& evtData,
134 const AliHLTComponentBlockData* blocks,
135 AliHLTComponentTriggerData& trigData,
136 AliHLTUInt8_t* outputPtr,
137 AliHLTUInt32_t& size,
138 std::vector<AliHLTComponentBlockData>& outputBlocks
142 AliHLTUInt32_t specification = 0; // Contains the output data block spec bits.
144 AliHLTMUONMansoTracksBlockWriter block(outputPtr, size);
147 if (not block.InitCommonHeader())
149 Logging(kHLTLogError,
150 "AliHLTMUONMansoTrackerFSMComponent::DoEvent",
152 "The buffer is only %d bytes in size. We need a minimum of %d bytes.",
153 size, sizeof(AliHLTMUONMansoTracksBlockWriter::HeaderType)
155 size = 0; // Important to tell framework that nothing was generated.
159 // Loop over all input blocks in the event and add the ones that contain
160 // reconstructed hits into the hit buffers. The blocks containing trigger
161 // records are ignored for now and will be processed later.
162 for (AliHLTUInt32_t n = 0; n < evtData.fBlockCnt; n++)
164 if (blocks[n].fDataType == AliHLTMUONConstants::RecHitsBlockDataType())
166 specification |= blocks[n].fSpecification;
168 AliHLTMUONRecHitsBlockReader inblock(blocks[n].fPtr, blocks[n].fSize);
169 if (not inblock.BufferSizeOk())
171 size_t headerSize = sizeof(AliHLTMUONRecHitsBlockReader::HeaderType);
172 if (blocks[n].fSize < headerSize)
174 HLTError("Received a reconstructed hits data block with a size of %d bytes,"
175 " which is smaller than the minimum valid header size of %d bytes."
176 " The block must be corrupt.",
177 blocks[n].fSize, headerSize
182 size_t expectedWidth = sizeof(AliHLTMUONRecHitsBlockReader::ElementType);
183 if (inblock.CommonBlockHeader().fRecordWidth != expectedWidth)
185 HLTError("Received a reconstructed hits data block with a record"
186 " width of %d bytes, but the expected value is %d bytes."
187 " The block might be corrupt.",
188 blocks[n].fSize, headerSize
193 HLTError("Received a reconstructed hits data block with a size of %d bytes,"
194 " but the block header claims the block should be %d bytes."
195 " The block might be corrupt.",
196 blocks[n].fSize, inblock.BytesUsed()
201 if (inblock.Nentries() != 0)
202 AddRecHits(blocks[n].fSpecification, inblock.GetArray(), inblock.Nentries());
205 Logging(kHLTLogDebug,
206 "AliHLTMUONMansoTrackerFSMComponent::DoEvent",
208 "Received a reconstructed hits data block which contains no entries."
212 else if (blocks[n].fDataType != AliHLTMUONConstants::TriggerRecordsBlockDataType())
214 // Log a message indicating that we got a data block that we
215 // do not know how to handle.
216 char id[kAliHLTComponentDataTypefIDsize+1];
217 for (int i = 0; i < kAliHLTComponentDataTypefIDsize; i++)
218 id[i] = blocks[n].fDataType.fID[i];
219 id[kAliHLTComponentDataTypefIDsize] = '\0';
220 char origin[kAliHLTComponentDataTypefOriginSize+1];
221 for (int i = 0; i < kAliHLTComponentDataTypefOriginSize; i++)
222 origin[i] = blocks[n].fDataType.fOrigin[i];
223 origin[kAliHLTComponentDataTypefOriginSize] = '\0';
225 if (fWarnForUnexpecedBlock)
226 HLTWarning("Received a data block of a type we cannot handle: %s origin: %s",
227 static_cast<char*>(id), static_cast<char*>(origin)
230 HLTDebug("Received a data block of a type we cannot handle: %s origin: %s",
231 static_cast<char*>(id), static_cast<char*>(origin)
236 // Again loop over all input blocks in the event, but this time look for
237 // the trigger record blocks and process these.
238 for (AliHLTUInt32_t n = 0; n < evtData.fBlockCnt; n++)
240 if (blocks[n].fDataType != AliHLTMUONConstants::TriggerRecordsBlockDataType())
243 AliHLTMUONTriggerRecordsBlockReader inblock(blocks[n].fPtr, blocks[n].fSize);
244 if (not inblock.BufferSizeOk())
246 size_t headerSize = sizeof(AliHLTMUONTriggerRecordsBlockReader::HeaderType);
247 if (blocks[n].fSize < headerSize)
249 HLTError("Received a trigger records data block with a size of %d bytes,"
250 " which is smaller than the minimum valid header size of %d bytes."
251 " The block must be corrupt.",
252 blocks[n].fSize, headerSize
257 size_t expectedWidth = sizeof(AliHLTMUONTriggerRecordsBlockReader::ElementType);
258 if (inblock.CommonBlockHeader().fRecordWidth != expectedWidth)
260 HLTError("Received a trigger records data block with a record"
261 " width of %d bytes, but the expected value is %d bytes."
262 " The block might be corrupt.",
263 blocks[n].fSize, headerSize
268 HLTError("Received a trigger records data block with a size of %d bytes,"
269 " but the block header claims the block should be %d bytes."
270 " The block might be corrupt.",
271 blocks[n].fSize, inblock.BytesUsed()
275 DebugTrace("Processing a trigger block with "
276 << inblock.Nentries() << " entries."
279 specification |= blocks[n].fSpecification;
281 for (AliHLTUInt32_t i = 0; i < inblock.Nentries(); i++)
283 fTracker->FindTrack(inblock[i]);
285 // Reset the tracker so that we do not double count tracks.
290 AliHLTComponentBlockData bd;
294 bd.fSize = block.BytesUsed();
295 bd.fDataType = AliHLTMUONConstants::MansoTracksBlockDataType();
296 bd.fSpecification = specification;
297 outputBlocks.push_back(bd);
298 size = block.BytesUsed();
304 void AliHLTMUONMansoTrackerFSMComponent::Reset()
306 DebugTrace("Resetting AliHLTMUONMansoTrackerFSMComponent.");
308 //fTracker->Reset(); // Not necessary here because it is done after every FindTrack call.
310 fBlock = NULL; // Do not delete. Already done implicitly at the end of DoEvent.
311 for (int i = 0; i < 4; i++)
313 fRecHitBlock[i].erase(fRecHitBlock[i].begin(), fRecHitBlock[i].end());
318 void AliHLTMUONMansoTrackerFSMComponent::AddRecHits(
319 AliHLTUInt32_t specification,
320 const AliHLTMUONRecHitStruct* recHits,
324 DebugTrace("AliHLTMUONMansoTrackerFSMComponent::AddRecHits called with specification = 0x"
325 << std::hex << specification << std::dec << " and count = "
326 << count << " rec hits."
329 AliHLTUInt8_t chamberMap[20] = {
330 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9, 10, 10
333 // Identify the chamber the rec hits came from using the specifications field.
334 bool gotDataFromDDL[22];
335 AliHLTMUONUtils::UnpackSpecBits(specification, gotDataFromDDL);
337 AliHLTInt8_t chamber = -1;
338 for (int i = 0; i < 20; i++)
340 if (not gotDataFromDDL[i]) continue;
341 if (7 <= chamberMap[i] and chamberMap[i] <= 10)
343 if (chamber != -1 and chamber != chamberMap[i])
345 Logging(kHLTLogError,
346 "AliHLTMUONMansoTrackerFSMComponent::AddRecHits",
348 "Received a data block with data from multiple chambers."
349 " This component cannot handle such a case."
354 chamber = chamberMap[i];
358 Logging(kHLTLogError,
359 "AliHLTMUONMansoTrackerFSMComponent::AddRecHits",
361 "Received a data block with data from chamber %d"
362 " which is outside the expected range: [7..10].",
369 // Make sure we got one chamber number.
370 if (chamber < 7 or 10 < chamber)
372 Logging(kHLTLogError,
373 "AliHLTMUONMansoTrackerFSMComponent::AddRecHits",
375 "Received a reconstructed hit data block with a null specification."
376 " Cannot know which chamber the data comes from."
381 DebugTrace("Added " << count << " reconstructed hits from chamber "
382 << (int)chamber << " to the internal arrays."
385 RecHitBlockInfo info;
387 info.fData = recHits;
388 fRecHitBlock[chamber-7].push_back(info);
392 void AliHLTMUONMansoTrackerFSMComponent::RequestClusters(
393 AliHLTMUONMansoTrackerFSM* tracker,
394 AliHLTFloat32_t /*left*/, AliHLTFloat32_t /*right*/,
395 AliHLTFloat32_t /*bottom*/, AliHLTFloat32_t /*top*/,
396 AliHLTMUONChamberName chamber, const void* tag
399 DebugTrace("AliHLTMUONMansoTracker::RequestClusters(chamber = " << chamber << ")");
400 void* ctag = const_cast<void*>(tag);
402 std::vector<RecHitBlockInfo>* recHitsBlock = NULL;
406 recHitsBlock = &fRecHitBlock[0];
411 recHitsBlock = &fRecHitBlock[1];
416 recHitsBlock = &fRecHitBlock[2];
421 recHitsBlock = &fRecHitBlock[3];
428 DebugTrace("Returning requested hits for chamber " << chNo << ":");
429 for (AliHLTUInt32_t i = 0; i < recHitsBlock->size(); i++)
431 tracker->ReturnClusters(
433 (*recHitsBlock)[i].fData,
434 (*recHitsBlock)[i].fCount
437 DebugTrace("Done returning hits from chamber " << chNo << ".");
438 tracker->EndOfClusters(ctag);
442 void AliHLTMUONMansoTrackerFSMComponent::EndOfClusterRequests(
443 AliHLTMUONMansoTrackerFSM* tracker
446 DebugTrace("End of cluster requests.");
450 void AliHLTMUONMansoTrackerFSMComponent::FoundTrack(AliHLTMUONMansoTrackerFSM* tracker)
452 DebugTrace("AliHLTMUONMansoTrackerFSMComponent::FoundTrack()");
454 AliHLTMUONMansoTracksBlockWriter* block =
455 reinterpret_cast<AliHLTMUONMansoTracksBlockWriter*>(fBlock);
457 AliHLTMUONMansoTrackStruct* track = block->AddEntry();
460 Logging(kHLTLogError,
461 "AliHLTMUONMansoTrackerFSMComponent::FoundTrack",
463 "We have overflowed the output buffer for Manso track data."
464 " The output buffer size is only %d bytes.",
471 tracker->FillTrackData(*track);
472 DebugTrace("\tTrack data = " << *track);
476 void AliHLTMUONMansoTrackerFSMComponent::NoTrackFound(AliHLTMUONMansoTrackerFSM* tracker)
478 DebugTrace("No track found.");