Fixing error in documentation.
[u/mrichter/AliRoot.git] / HLT / MUON / OnlineAnalysis / AliHLTMUONMansoTrackerFSMComponent.cxx
CommitLineData
b92524d0 1/**************************************************************************
2 * This file is property of and copyright by the ALICE HLT Project *
3 * All rights reserved. *
4 * *
5 * Primary Authors: *
6 * Artur Szostak <artursz@iafrica.com> *
7 * Indranil Das <indra.das@saha.ac.in> *
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 *
14 * about the suitability of this software for any purpose. It is *
15 * provided "as is" without express or implied warranty. *
16 **************************************************************************/
17
18/* $Id$ */
19
20/**
21 * @file AliHLTMUONMansoTrackerFSMComponent.cxx
22 * @author Artur Szostak <artursz@iafrica.com>,
23 * Indranil Das <indra.das@saha.ac.in>
24 * @date
25 * @brief Implementation of AliHLTMUONMansoTrackerFSMComponent class.
26 */
27
28#include "AliHLTMUONMansoTrackerFSMComponent.h"
29#include "AliHLTMUONConstants.h"
30#include "AliHLTMUONUtils.h"
31#include "AliHLTMUONMansoTrackerFSM.h"
32#include "AliHLTMUONDataBlockReader.h"
33#include "AliHLTMUONDataBlockWriter.h"
34#include <cstdlib>
35#include <cerrno>
36
37namespace
38{
39 // The global object used for automatic component registration.
40 // Note DO NOT use this component for calculation!
41 AliHLTMUONMansoTrackerFSMComponent gAliHLTMUONMansoTrackerFSMComponent;
42
43} // end of namespace
44
45
46ClassImp(AliHLTMUONMansoTrackerFSMComponent);
47
48
49AliHLTMUONMansoTrackerFSMComponent::AliHLTMUONMansoTrackerFSMComponent() :
50 AliHLTProcessor(),
51 AliHLTMUONMansoTrackerFSMCallback(),
52 fTracker(NULL),
53 fTrackCount(0),
54 fBlock(NULL)
55{
56}
57
58
59AliHLTMUONMansoTrackerFSMComponent::~AliHLTMUONMansoTrackerFSMComponent()
60{
61 assert( fTracker == NULL );
62}
63
64
65const char* AliHLTMUONMansoTrackerFSMComponent::GetComponentID()
66{
67 return AliHLTMUONConstants::MansoTrackerFSMId();
68}
69
70
71void AliHLTMUONMansoTrackerFSMComponent::GetInputDataTypes(
72 vector<AliHLTComponentDataType>& list
73 )
74{
75 assert( list.empty() );
76 list.push_back( AliHLTMUONConstants::TriggerRecordsBlockDataType() );
77 list.push_back( AliHLTMUONConstants::RecHitsBlockDataType() );
78}
79
80
81AliHLTComponentDataType AliHLTMUONMansoTrackerFSMComponent::GetOutputDataType()
82{
83 return AliHLTMUONConstants::MansoTracksBlockDataType();
84}
85
86
87void AliHLTMUONMansoTrackerFSMComponent::GetOutputDataSize(
88 unsigned long& constBase, double& inputMultiplier
89 )
90{
91 constBase = sizeof(AliHLTMUONMansoTracksBlockStruct);
92 inputMultiplier = 1;
93}
94
95
96AliHLTComponent* AliHLTMUONMansoTrackerFSMComponent::Spawn()
97{
98 return new AliHLTMUONMansoTrackerFSMComponent;
99}
100
101
102int AliHLTMUONMansoTrackerFSMComponent::DoInit(int argc, const char** argv)
103{
104 fTracker = new AliHLTMUONMansoTrackerFSM();
105 fTracker->SetCallback(this);
106 return 0;
107}
108
109
110int AliHLTMUONMansoTrackerFSMComponent::DoDeinit()
111{
112 if (fTracker != NULL)
113 {
114 delete fTracker;
115 fTracker = NULL;
116 }
117 return 0;
118}
119
120
121int 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
128 )
129{
130 Reset();
131 AliHLTUInt32_t specification = 0; // Contains the output data block spec bits.
132
133 AliHLTMUONMansoTracksBlockWriter block(outputPtr, size);
134 fBlock = &block;
135
136 if (not block.InitCommonHeader())
137 {
138 Logging(kHLTLogError,
139 "AliHLTMUONMansoTrackerFSMComponent::DoEvent",
140 "Buffer overflow",
141 "The buffer is only %d bytes in size. We need a minimum of %d bytes.",
142 size, sizeof(AliHLTMUONMansoTracksBlockWriter::HeaderType)
143 );
144 size = 0; // Important to tell framework that nothing was generated.
145 return ENOBUFS;
146 }
147
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++)
152 {
153 if (blocks[n].fDataType == AliHLTMUONConstants::RecHitsBlockDataType())
154 {
155 specification |= blocks[n].fSpecification;
156
157 AliHLTMUONRecHitsBlockReader inblock(blocks[n].fPtr, blocks[n].fSize);
158 if (not inblock.BufferSizeOk())
159 {
160 Logging(kHLTLogError,
161 "AliHLTMUONMansoTrackerFSMComponent::DoEvent",
162 "Invalid block",
163 "Received a reconstructed hits data block with an incorrect size: %d,"
164 " it might be corrupt.",
165 blocks[n].fSize
166 );
167 continue;
168 }
169
170 AddRecHits(blocks[n].fSpecification, inblock.GetArray(), inblock.Nentries());
171 }
172 else if (blocks[n].fDataType != AliHLTMUONConstants::TriggerRecordsBlockDataType())
173 {
174 // Log a message indicating that we got a data block that we
175 // do not know how to handle.
176 char id[kAliHLTComponentDataTypefIDsize+1];
177 for (int i = 0; i < kAliHLTComponentDataTypefIDsize; i++)
178 id[i] = blocks[n].fDataType.fID[i];
179 id[kAliHLTComponentDataTypefIDsize] = '\0';
180 char origin[kAliHLTComponentDataTypefOriginSize+1];
181 for (int i = 0; i < kAliHLTComponentDataTypefOriginSize; i++)
182 origin[i] = blocks[n].fDataType.fOrigin[i];
183 origin[kAliHLTComponentDataTypefOriginSize] = '\0';
184
185 Logging(kHLTLogError,
186 "AliHLTMUONMansoTrackerFSMComponent::DoEvent",
187 "Unexpected data",
188 "Received a data block of an unexpected type: %s origin %s",
189 static_cast<char*>(id), static_cast<char*>(origin)
190 );
191 }
192 }
193
194 // Again loop over all input blocks in the event, but this time look for
195 // the trigger record blocks and process these.
196 for (AliHLTUInt32_t n = 0; n < evtData.fBlockCnt; n++)
197 {
198 if (blocks[n].fDataType != AliHLTMUONConstants::TriggerRecordsBlockDataType())
199 continue;
200
201 AliHLTMUONTriggerRecordsBlockReader inblock(blocks[n].fPtr, blocks[n].fSize);
202 if (not inblock.BufferSizeOk())
203 {
204 Logging(kHLTLogError,
205 "AliHLTMUONMansoTrackerFSMComponent::DoEvent",
206 "Invalid block",
207 "Received a trigger record data block with an incorrect size: %d,"
208 " it might be corrupt.",
209 blocks[n].fSize
210 );
211 continue;
212 }
213 DebugTrace("Processing a trigger block with "
214 << inblock.Nentries() << " entries."
215 );
216
217 specification |= blocks[n].fSpecification;
218
219 for (AliHLTUInt32_t i = 0; i < inblock.Nentries(); i++)
220 {
221 fTracker->FindTrack(inblock[i]);
222
223 // Reset the tracker so that we do not double count tracks.
224 fTracker->Reset();
225 }
226 }
227
228 AliHLTComponentBlockData bd;
229 FillBlockData(bd);
230 bd.fPtr = outputPtr;
231 bd.fOffset = 0;
232 bd.fSize = block.BytesUsed();
233 bd.fDataType = AliHLTMUONConstants::MansoTracksBlockDataType();
234 bd.fSpecification = specification;
235 outputBlocks.push_back(bd);
236 size = block.BytesUsed();
237
238 return 0;
239}
240
241
242void AliHLTMUONMansoTrackerFSMComponent::Reset()
243{
244 DebugTrace("Resetting AliHLTMUONMansoTrackerFSMComponent.");
245
246 //fTracker->Reset(); // Not necessary here because it is done after every FindTrack call.
247 fTrackCount = 0;
248 fBlock = NULL; // Do not delete. Already done implicitly at the end of DoEvent.
249 for (int i = 0; i < 4; i++)
250 {
251 fRecHitBlock[i].erase(fRecHitBlock[i].begin(), fRecHitBlock[i].end());
252 }
253}
254
255
256void AliHLTMUONMansoTrackerFSMComponent::AddRecHits(
257 AliHLTUInt32_t specification,
258 const AliHLTMUONRecHitStruct* recHits,
259 AliHLTUInt32_t count
260 )
261{
262 DebugTrace("AliHLTMUONMansoTrackerFSMComponent::AddRecHits called with specification = 0x"
263 << std::hex << specification << std::dec << " and count = "
264 << count << " rec hits."
265 );
266
267 AliHLTUInt8_t chamberMap[20] = {
268 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9, 10, 10
269 };
270
271 // Identify the chamber the rec hits came from using the specifications field.
272 bool gotDataFromDDL[22];
273 AliHLTMUONUtils::UnpackSpecBits(specification, gotDataFromDDL);
274
275 AliHLTInt8_t chamber = -1;
276 for (int i = 0; i < 20; i++)
277 {
278 if (not gotDataFromDDL[i]) continue;
279 if (7 <= chamberMap[i] and chamberMap[i] <= 10)
280 {
281 if (chamber != -1 and chamber != chamberMap[i])
282 {
283 Logging(kHLTLogError,
284 "AliHLTMUONMansoTrackerFSMComponent::AddRecHits",
285 "Invalid block",
286 "Received a data block with data from multiple chambers."
287 " This component cannot handle such a case."
288 );
289 return;
290 }
291 else
292 chamber = chamberMap[i];
293 }
294 else
295 {
296 Logging(kHLTLogError,
297 "AliHLTMUONMansoTrackerFSMComponent::AddRecHits",
298 "Invalid chamber",
299 "Received a data block with data from chamber %d"
300 " which is outside the expected range: [7..10].",
301 chamberMap[i]
302 );
303 return;
304 }
305 }
306
307 // Make sure we got one chamber number.
308 if (chamber < 7 or 10 < chamber)
309 {
310 Logging(kHLTLogError,
311 "AliHLTMUONMansoTrackerFSMComponent::AddRecHits",
312 "Invalid block",
313 "Received a reconstructed hit data block with a null specification."
314 " Cannot know which chamber the data comes from."
315 );
316 return;
317 }
318
319 DebugTrace("Added " << count << " reconstructed hits from chamber "
320 << (int)chamber << " to the internal arrays.")
321 ;
322
323 RecHitBlockInfo info;
324 info.fCount = count;
325 info.fData = recHits;
326 fRecHitBlock[chamber-7].push_back(info);
327}
328
329
330void AliHLTMUONMansoTrackerFSMComponent::RequestClusters(
331 AliHLTMUONMansoTrackerFSM* tracker,
332 AliHLTFloat32_t /*left*/, AliHLTFloat32_t /*right*/,
333 AliHLTFloat32_t /*bottom*/, AliHLTFloat32_t /*top*/,
334 AliHLTMUONChamberName chamber, const void* tag
335 )
336{
337 DebugTrace("AliHLTMUONMansoTracker::RequestClusters(chamber = " << chamber << ")");
338 void* ctag = const_cast<void*>(tag);
339 int chNo = -1;
340 std::vector<RecHitBlockInfo>* recHitsBlock = NULL;
341 switch (chamber)
342 {
343 case kChamber7:
344 recHitsBlock = &fRecHitBlock[0];
345 chNo = 7;
346 break;
347
348 case kChamber8:
349 recHitsBlock = &fRecHitBlock[1];
350 chNo = 8;
351 break;
352
353 case kChamber9:
354 recHitsBlock = &fRecHitBlock[2];
355 chNo = 9;
356 break;
357
358 case kChamber10:
359 recHitsBlock = &fRecHitBlock[3];
360 chNo = 10;
361 break;
362
363 default: return;
364 }
365
366 DebugTrace("Returning requested hits for chamber " << chNo << ":");
367 for (AliHLTUInt32_t i = 0; i < recHitsBlock->size(); i++)
368 {
369 tracker->ReturnClusters(
370 ctag,
371 (*recHitsBlock)[i].fData,
372 (*recHitsBlock)[i].fCount
373 );
374 }
375 DebugTrace("Done returning hits from chamber " << chNo << ".");
376 tracker->EndOfClusters(ctag);
377}
378
379
380void AliHLTMUONMansoTrackerFSMComponent::EndOfClusterRequests(
381 AliHLTMUONMansoTrackerFSM* tracker
382 )
383{
384 DebugTrace("End of cluster requests.");
385}
386
387
388void AliHLTMUONMansoTrackerFSMComponent::FoundTrack(AliHLTMUONMansoTrackerFSM* tracker)
389{
390 DebugTrace("AliHLTMUONMansoTrackerFSMComponent::FoundTrack()");
391
392 AliHLTMUONMansoTracksBlockWriter* block =
393 reinterpret_cast<AliHLTMUONMansoTracksBlockWriter*>(fBlock);
394
395 AliHLTMUONMansoTrackStruct* track = block->AddEntry();
396 if (track == NULL)
397 {
398 Logging(kHLTLogError,
399 "AliHLTMUONMansoTrackerFSMComponent::FoundTrack",
400 "Buffer overflow",
401 "We have overflowed the output buffer for Manso track data."
402 " The output buffer size is only %d bytes.",
403 block->BufferSize()
404 );
405 return;
406 }
407
408 fTrackCount++;
409 tracker->FillTrackData(*track);
410 DebugTrace("\tTrack data = " << *track);
411}
412
413
414void AliHLTMUONMansoTrackerFSMComponent::NoTrackFound(AliHLTMUONMansoTrackerFSM* tracker)
415{
416 DebugTrace("No track found.");
417}
418