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"
39 // The global object used for automatic component registration.
40 // Note DO NOT use this component for calculation!
41 AliHLTMUONMansoTrackerFSMComponent gAliHLTMUONMansoTrackerFSMComponent;
46 ClassImp(AliHLTMUONMansoTrackerFSMComponent);
49 AliHLTMUONMansoTrackerFSMComponent::AliHLTMUONMansoTrackerFSMComponent() :
51 AliHLTMUONMansoTrackerFSMCallback(),
59 AliHLTMUONMansoTrackerFSMComponent::~AliHLTMUONMansoTrackerFSMComponent()
61 assert( fTracker == NULL );
65 const char* AliHLTMUONMansoTrackerFSMComponent::GetComponentID()
67 return AliHLTMUONConstants::MansoTrackerFSMId();
71 void AliHLTMUONMansoTrackerFSMComponent::GetInputDataTypes(
72 vector<AliHLTComponentDataType>& list
75 assert( list.empty() );
76 list.push_back( AliHLTMUONConstants::TriggerRecordsBlockDataType() );
77 list.push_back( AliHLTMUONConstants::RecHitsBlockDataType() );
81 AliHLTComponentDataType AliHLTMUONMansoTrackerFSMComponent::GetOutputDataType()
83 return AliHLTMUONConstants::MansoTracksBlockDataType();
87 void AliHLTMUONMansoTrackerFSMComponent::GetOutputDataSize(
88 unsigned long& constBase, double& inputMultiplier
91 constBase = sizeof(AliHLTMUONMansoTracksBlockStruct);
96 AliHLTComponent* AliHLTMUONMansoTrackerFSMComponent::Spawn()
98 return new AliHLTMUONMansoTrackerFSMComponent;
102 int AliHLTMUONMansoTrackerFSMComponent::DoInit(int argc, const char** argv)
104 fTracker = new AliHLTMUONMansoTrackerFSM();
105 fTracker->SetCallback(this);
110 int AliHLTMUONMansoTrackerFSMComponent::DoDeinit()
112 if (fTracker != NULL)
121 int AliHLTMUONMansoTrackerFSMComponent::DoEvent(
122 const AliHLTComponentEventData& evtData,
123 const AliHLTComponentBlockData* blocks,
124 AliHLTComponentTriggerData& trigData,
125 AliHLTUInt8_t* outputPtr,
126 AliHLTUInt32_t& size,
127 std::vector<AliHLTComponentBlockData>& outputBlocks
131 AliHLTUInt32_t specification = 0; // Contains the output data block spec bits.
133 AliHLTMUONMansoTracksBlockWriter block(outputPtr, size);
136 if (not block.InitCommonHeader())
138 Logging(kHLTLogError,
139 "AliHLTMUONMansoTrackerFSMComponent::DoEvent",
141 "The buffer is only %d bytes in size. We need a minimum of %d bytes.",
142 size, sizeof(AliHLTMUONMansoTracksBlockWriter::HeaderType)
144 size = 0; // Important to tell framework that nothing was generated.
148 // Loop over all input blocks in the event and add the ones that contain
149 // reconstructed hits into the hit buffers. The blocks containing trigger
150 // records are ignored for now and will be processed later.
151 for (AliHLTUInt32_t n = 0; n < evtData.fBlockCnt; n++)
153 if (blocks[n].fDataType == AliHLTMUONConstants::RecHitsBlockDataType())
155 specification |= blocks[n].fSpecification;
157 AliHLTMUONRecHitsBlockReader inblock(blocks[n].fPtr, blocks[n].fSize);
158 if (not inblock.BufferSizeOk())
160 Logging(kHLTLogError,
161 "AliHLTMUONMansoTrackerFSMComponent::DoEvent",
163 "Received a reconstructed hits data block with an incorrect size: %d,"
164 " it might be corrupt.",
170 if (inblock.Nentries() != 0)
171 AddRecHits(blocks[n].fSpecification, inblock.GetArray(), inblock.Nentries());
174 Logging(kHLTLogWarning,
175 "AliHLTMUONMansoTrackerFSMComponent::DoEvent",
177 "Received a reconstructed hits data block which contains no entries."
181 else if (blocks[n].fDataType != AliHLTMUONConstants::TriggerRecordsBlockDataType())
183 // Log a message indicating that we got a data block that we
184 // do not know how to handle.
185 char id[kAliHLTComponentDataTypefIDsize+1];
186 for (int i = 0; i < kAliHLTComponentDataTypefIDsize; i++)
187 id[i] = blocks[n].fDataType.fID[i];
188 id[kAliHLTComponentDataTypefIDsize] = '\0';
189 char origin[kAliHLTComponentDataTypefOriginSize+1];
190 for (int i = 0; i < kAliHLTComponentDataTypefOriginSize; i++)
191 origin[i] = blocks[n].fDataType.fOrigin[i];
192 origin[kAliHLTComponentDataTypefOriginSize] = '\0';
194 Logging(kHLTLogError,
195 "AliHLTMUONMansoTrackerFSMComponent::DoEvent",
197 "Received a data block of an unexpected type: %s origin %s",
198 static_cast<char*>(id), static_cast<char*>(origin)
203 // Again loop over all input blocks in the event, but this time look for
204 // the trigger record blocks and process these.
205 for (AliHLTUInt32_t n = 0; n < evtData.fBlockCnt; n++)
207 if (blocks[n].fDataType != AliHLTMUONConstants::TriggerRecordsBlockDataType())
210 AliHLTMUONTriggerRecordsBlockReader inblock(blocks[n].fPtr, blocks[n].fSize);
211 if (not inblock.BufferSizeOk())
213 Logging(kHLTLogError,
214 "AliHLTMUONMansoTrackerFSMComponent::DoEvent",
216 "Received a trigger record data block with an incorrect size: %d,"
217 " it might be corrupt.",
222 DebugTrace("Processing a trigger block with "
223 << inblock.Nentries() << " entries."
226 specification |= blocks[n].fSpecification;
228 for (AliHLTUInt32_t i = 0; i < inblock.Nentries(); i++)
230 fTracker->FindTrack(inblock[i]);
232 // Reset the tracker so that we do not double count tracks.
237 AliHLTComponentBlockData bd;
241 bd.fSize = block.BytesUsed();
242 bd.fDataType = AliHLTMUONConstants::MansoTracksBlockDataType();
243 bd.fSpecification = specification;
244 outputBlocks.push_back(bd);
245 size = block.BytesUsed();
251 void AliHLTMUONMansoTrackerFSMComponent::Reset()
253 DebugTrace("Resetting AliHLTMUONMansoTrackerFSMComponent.");
255 //fTracker->Reset(); // Not necessary here because it is done after every FindTrack call.
257 fBlock = NULL; // Do not delete. Already done implicitly at the end of DoEvent.
258 for (int i = 0; i < 4; i++)
260 fRecHitBlock[i].erase(fRecHitBlock[i].begin(), fRecHitBlock[i].end());
265 void AliHLTMUONMansoTrackerFSMComponent::AddRecHits(
266 AliHLTUInt32_t specification,
267 const AliHLTMUONRecHitStruct* recHits,
271 DebugTrace("AliHLTMUONMansoTrackerFSMComponent::AddRecHits called with specification = 0x"
272 << std::hex << specification << std::dec << " and count = "
273 << count << " rec hits."
276 AliHLTUInt8_t chamberMap[20] = {
277 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9, 10, 10
280 // Identify the chamber the rec hits came from using the specifications field.
281 bool gotDataFromDDL[22];
282 AliHLTMUONUtils::UnpackSpecBits(specification, gotDataFromDDL);
284 AliHLTInt8_t chamber = -1;
285 for (int i = 0; i < 20; i++)
287 if (not gotDataFromDDL[i]) continue;
288 if (7 <= chamberMap[i] and chamberMap[i] <= 10)
290 if (chamber != -1 and chamber != chamberMap[i])
292 Logging(kHLTLogError,
293 "AliHLTMUONMansoTrackerFSMComponent::AddRecHits",
295 "Received a data block with data from multiple chambers."
296 " This component cannot handle such a case."
301 chamber = chamberMap[i];
305 Logging(kHLTLogError,
306 "AliHLTMUONMansoTrackerFSMComponent::AddRecHits",
308 "Received a data block with data from chamber %d"
309 " which is outside the expected range: [7..10].",
316 // Make sure we got one chamber number.
317 if (chamber < 7 or 10 < chamber)
319 Logging(kHLTLogError,
320 "AliHLTMUONMansoTrackerFSMComponent::AddRecHits",
322 "Received a reconstructed hit data block with a null specification."
323 " Cannot know which chamber the data comes from."
328 DebugTrace("Added " << count << " reconstructed hits from chamber "
329 << (int)chamber << " to the internal arrays.")
332 RecHitBlockInfo info;
334 info.fData = recHits;
335 fRecHitBlock[chamber-7].push_back(info);
339 void AliHLTMUONMansoTrackerFSMComponent::RequestClusters(
340 AliHLTMUONMansoTrackerFSM* tracker,
341 AliHLTFloat32_t /*left*/, AliHLTFloat32_t /*right*/,
342 AliHLTFloat32_t /*bottom*/, AliHLTFloat32_t /*top*/,
343 AliHLTMUONChamberName chamber, const void* tag
346 DebugTrace("AliHLTMUONMansoTracker::RequestClusters(chamber = " << chamber << ")");
347 void* ctag = const_cast<void*>(tag);
349 std::vector<RecHitBlockInfo>* recHitsBlock = NULL;
353 recHitsBlock = &fRecHitBlock[0];
358 recHitsBlock = &fRecHitBlock[1];
363 recHitsBlock = &fRecHitBlock[2];
368 recHitsBlock = &fRecHitBlock[3];
375 DebugTrace("Returning requested hits for chamber " << chNo << ":");
376 for (AliHLTUInt32_t i = 0; i < recHitsBlock->size(); i++)
378 tracker->ReturnClusters(
380 (*recHitsBlock)[i].fData,
381 (*recHitsBlock)[i].fCount
384 DebugTrace("Done returning hits from chamber " << chNo << ".");
385 tracker->EndOfClusters(ctag);
389 void AliHLTMUONMansoTrackerFSMComponent::EndOfClusterRequests(
390 AliHLTMUONMansoTrackerFSM* tracker
393 DebugTrace("End of cluster requests.");
397 void AliHLTMUONMansoTrackerFSMComponent::FoundTrack(AliHLTMUONMansoTrackerFSM* tracker)
399 DebugTrace("AliHLTMUONMansoTrackerFSMComponent::FoundTrack()");
401 AliHLTMUONMansoTracksBlockWriter* block =
402 reinterpret_cast<AliHLTMUONMansoTracksBlockWriter*>(fBlock);
404 AliHLTMUONMansoTrackStruct* track = block->AddEntry();
407 Logging(kHLTLogError,
408 "AliHLTMUONMansoTrackerFSMComponent::FoundTrack",
410 "We have overflowed the output buffer for Manso track data."
411 " The output buffer size is only %d bytes.",
418 tracker->FillTrackData(*track);
419 DebugTrace("\tTrack data = " << *track);
423 void AliHLTMUONMansoTrackerFSMComponent::NoTrackFound(AliHLTMUONMansoTrackerFSM* tracker)
425 DebugTrace("No track found.");