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 "AliHLTMUONCalculations.h"
31 #include "AliHLTMUONUtils.h"
32 #include "AliHLTMUONMansoTrackerFSM.h"
33 #include "AliHLTMUONDataBlockReader.h"
34 #include "AliHLTMUONDataBlockWriter.h"
40 ClassImp(AliHLTMUONMansoTrackerFSMComponent);
43 AliHLTMUONMansoTrackerFSMComponent::AliHLTMUONMansoTrackerFSMComponent() :
44 AliHLTMUONProcessor(),
45 AliHLTMUONMansoTrackerFSMCallback(),
49 fRecHitBlockArraySize(0),
50 fWarnForUnexpecedBlock(false),
51 fCanLoadZmiddle(true),
55 /// Default constructor.
58 for (int i = 0; i < 4; i++)
60 fRecHitBlockCount[i] = 0;
61 fRecHitBlock[i] = NULL;
68 AliHLTMUONMansoTrackerFSMComponent::~AliHLTMUONMansoTrackerFSMComponent()
71 /// Default destructor.
74 // Should never have the following 2 pointers non-NULL since DoDeinit
75 // should have been called before, but handle this case anyway.
76 if (fTracker != NULL) delete fTracker;
78 // Remember that only fRecHitBlock[0] stores the pointer to the allocated
79 // memory. The other pointers are just reletive to this.
80 if (fRecHitBlock[0] != NULL) delete [] fRecHitBlock[0];
84 const char* AliHLTMUONMansoTrackerFSMComponent::GetComponentID()
87 /// Inherited from AliHLTComponent. Returns the component ID.
90 return AliHLTMUONConstants::MansoTrackerFSMId();
94 void AliHLTMUONMansoTrackerFSMComponent::GetInputDataTypes(
95 AliHLTComponentDataTypeList& list
99 /// Inherited from AliHLTProcessor. Returns the list of expected input data types.
102 assert( list.empty() );
103 list.push_back( AliHLTMUONConstants::TriggerRecordsBlockDataType() );
104 list.push_back( AliHLTMUONConstants::RecHitsBlockDataType() );
108 AliHLTComponentDataType AliHLTMUONMansoTrackerFSMComponent::GetOutputDataType()
111 /// Inherited from AliHLTComponent. Returns the output data type.
114 return kAliHLTMultipleDataType;
118 int AliHLTMUONMansoTrackerFSMComponent::GetOutputDataTypes(AliHLTComponentDataTypeList& list)
120 /// Inherited from AliHLTComponent. Returns the output data types.
122 assert( list.empty() );
123 list.push_back( AliHLTMUONConstants::MansoTracksBlockDataType() );
124 list.push_back( AliHLTMUONConstants::MansoCandidatesBlockDataType() );
129 void AliHLTMUONMansoTrackerFSMComponent::GetOutputDataSize(
130 unsigned long& constBase, double& inputMultiplier
134 /// Inherited from AliHLTComponent. Returns an estimate of the expected output data size.
137 constBase = sizeof(AliHLTMUONMansoTracksBlockStruct) + 1024*1024;
142 AliHLTComponent* AliHLTMUONMansoTrackerFSMComponent::Spawn()
145 /// Inherited from AliHLTComponent. Creates a new object instance.
148 return new AliHLTMUONMansoTrackerFSMComponent;
152 int AliHLTMUONMansoTrackerFSMComponent::DoInit(int argc, const char** argv)
155 /// Inherited from AliHLTComponent.
156 /// Parses the command line parameters and initialises the component.
159 HLTInfo("Initialising dHLT manso tracker FSM component.");
161 // Inherit the parents functionality.
162 int result = AliHLTMUONProcessor::DoInit(argc, argv);
163 if (result != 0) return result;
165 // Just in case for whatever reason we still have some of the internal
166 // object allocated previously still hanging around delete them now.
169 fWarnForUnexpecedBlock = false;
170 bool makeCandidates = false;
173 double bfieldintegral = 0;
174 double roiA[4] = {0, 0, 0, 0};
175 double roiB[4] = {0, 0, 0, 0};
176 double chamberZ[6] = {0, 0, 0, 0, 0, 0};
178 for (int i = 0; i < argc; i++)
180 if (ArgumentAlreadyHandled(i, argv[i])) continue;
182 if (strcmp( argv[i], "-zmiddle" ) == 0)
184 if (not fCanLoadZmiddle)
186 HLTWarning("The Z coordinate for the middle of the dipole was already specified."
187 " Will replace previous value given by -zmiddle."
193 HLTError("The Z coordinate for the middle of the dipole was not specified." );
198 zmiddle = strtod(argv[i+1], &cpErr);
199 if (cpErr == NULL or *cpErr != '\0')
201 HLTError("Cannot convert '%s' to a valid floating point number.",
207 fCanLoadZmiddle = false; // Prevent loading from CDB.
212 if (strcmp( argv[i], "-bfieldintegral" ) == 0)
216 HLTWarning("The magnetic field integral was already specified."
217 " Will replace previous value given by -bfieldintegral."
223 HLTError("The magnetic field integral was not specified." );
228 bfieldintegral = strtod(argv[i+1], &cpErr);
229 if (cpErr == NULL or *cpErr != '\0')
231 HLTError("Cannot convert '%s' to a valid floating point number.",
237 fCanLoadBL = false; // Prevent loading from CDB.
242 if (strcmp(argv[i], "-a7") == 0 or strcmp(argv[i], "-a8") == 0 or
243 strcmp(argv[i], "-a9") == 0 or strcmp(argv[i], "-a10") == 0
246 int chamber = 7; int chamberIndex = 0;
249 case '7': chamber = 7; chamberIndex = 0; break;
250 case '8': chamber = 8; chamberIndex = 1; break;
251 case '9': chamber = 9; chamberIndex = 2; break;
252 case '1': chamber = 10; chamberIndex = 3; break;
255 if (not fCanLoadA[chamberIndex])
257 HLTWarning("The region of interest parameter 'A' for chamber %d was"
258 " already specified. Will replace previous value given by -a%d.",
265 HLTError("The region of interest parameter was not specified." );
270 roiA[chamberIndex] = strtod(argv[i+1], &cpErr);
271 if (cpErr == NULL or *cpErr != '\0')
273 HLTError("Cannot convert '%s' to a valid floating point number.",
279 fCanLoadA[chamberIndex] = false; // Prevent loading from CDB.
284 if (strcmp(argv[i], "-b7") == 0 or strcmp(argv[i], "-b8") == 0 or
285 strcmp(argv[i], "-b9") == 0 or strcmp(argv[i], "-b10") == 0
288 int chamber = 7; int chamberIndex = 0;
291 case '7': chamber = 7; chamberIndex = 0; break;
292 case '8': chamber = 8; chamberIndex = 1; break;
293 case '9': chamber = 9; chamberIndex = 2; break;
294 case '1': chamber = 10; chamberIndex = 3; break;
297 if (not fCanLoadB[chamberIndex])
299 HLTWarning("The region of interest parameter 'B' for chamber %d was"
300 " already specified. Will replace previous value given by -b%d.",
307 HLTError("The region of interest parameter was not specified." );
312 roiB[chamberIndex] = strtod(argv[i+1], &cpErr);
313 if (cpErr == NULL or *cpErr != '\0')
315 HLTError("Cannot convert '%s' to a valid floating point number.",
321 fCanLoadB[chamberIndex] = false; // Prevent loading from CDB.
326 if (strcmp(argv[i], "-z7") == 0 or strcmp(argv[i], "-z8") == 0 or
327 strcmp(argv[i], "-z9") == 0 or strcmp(argv[i], "-z10") == 0 or
328 strcmp(argv[i], "-z11") == 0 or strcmp(argv[i], "-z13") == 0
331 int chamber = 7; int chamberIndex = 0;
334 case '7': chamber = 7; chamberIndex = 0; break;
335 case '8': chamber = 8; chamberIndex = 1; break;
336 case '9': chamber = 9; chamberIndex = 2; break;
340 case '0': chamber = 10; chamberIndex = 3; break;
341 case '1': chamber = 11; chamberIndex = 4; break;
342 case '3': chamber = 13; chamberIndex = 5; break;
347 if (not fCanLoadZ[chamberIndex])
349 HLTWarning("The nominal Z coordinate of chamber %d was already"
350 " specified. Will replace previous value given by -z%d.",
357 HLTError("The region of interest parameter was not specified." );
362 chamberZ[chamberIndex] = strtod(argv[i+1], &cpErr);
363 if (cpErr == NULL or *cpErr != '\0')
365 HLTError("Cannot convert '%s' to a valid floating point number.",
371 fCanLoadZ[chamberIndex] = false; // Prevent loading from CDB.
376 if (strcmp(argv[i], "-warn_on_unexpected_block") == 0)
378 fWarnForUnexpecedBlock = true;
382 if (strcmp(argv[i], "-makecandidates") == 0)
384 makeCandidates = true;
388 HLTError("Unknown option '%s'.", argv[i]);
394 fTracker = new AliHLTMUONMansoTrackerFSM();
396 catch (const std::bad_alloc&)
398 HLTError("Could not allocate more memory for the tracker component.");
401 fTracker->SetCallback(this);
402 fTracker->MakeCandidates(makeCandidates);
404 // Set all the parameters that were found on the command line.
405 if (not fCanLoadZmiddle) AliHLTMUONCalculations::Zf(zmiddle);
406 if (not fCanLoadBL) AliHLTMUONCalculations::QBL(bfieldintegral);
407 if (not fCanLoadA[0]) fTracker->SetA7(roiA[0]);
408 if (not fCanLoadA[1]) fTracker->SetA8(roiA[1]);
409 if (not fCanLoadA[2]) fTracker->SetA9(roiA[2]);
410 if (not fCanLoadA[3]) fTracker->SetA10(roiA[3]);
411 if (not fCanLoadB[0]) fTracker->SetB7(roiB[0]);
412 if (not fCanLoadB[1]) fTracker->SetB8(roiB[1]);
413 if (not fCanLoadB[2]) fTracker->SetB9(roiB[2]);
414 if (not fCanLoadB[3]) fTracker->SetB10(roiB[3]);
415 if (not fCanLoadZ[0]) fTracker->SetZ7(chamberZ[0]);
416 if (not fCanLoadZ[1]) fTracker->SetZ8(chamberZ[1]);
417 if (not fCanLoadZ[2]) fTracker->SetZ9(chamberZ[2]);
418 if (not fCanLoadZ[3]) fTracker->SetZ10(chamberZ[3]);
419 if (not fCanLoadZ[4]) fTracker->SetZ11(chamberZ[4]);
420 if (not fCanLoadZ[5]) fTracker->SetZ13(chamberZ[5]);
422 if (not DelaySetup())
424 if (AtLeastOneCanLoadFlagsIsSet())
426 HLTInfo("Loading configuration parameters from CDB.");
428 result = ReadConfigFromCDB();
431 // Error messages already generated in ReadConfigFromCDB.
432 FreeMemory(); // Make sure we cleanup to avoid partial initialisation.
438 // Print the debug messages here since ReadConfigFromCDB does not get called,
439 // in-which the debug messages would have been printed.
440 HLTDebug("Using the following configuration parameters:");
441 HLTDebug(" Middle of dipole Z coordinate = %f cm", AliHLTMUONCalculations::Zf());
442 HLTDebug(" Magnetic field integral = %f T.m", AliHLTMUONCalculations::QBL());
443 HLTDebug(" Region of interest parameter 'A' for chamber 7 = %f", fTracker->GetA7());
444 HLTDebug(" Region of interest parameter 'B' for chamber 7 = %f cm", fTracker->GetB7());
445 HLTDebug(" Region of interest parameter 'A' for chamber 8 = %f", fTracker->GetA8());
446 HLTDebug(" Region of interest parameter 'B' for chamber 8 = %f cm", fTracker->GetB8());
447 HLTDebug(" Region of interest parameter 'A' for chamber 9 = %f", fTracker->GetA9());
448 HLTDebug(" Region of interest parameter 'B' for chamber 9 = %f cm", fTracker->GetB9());
449 HLTDebug(" Region of interest parameter 'A' for chamber 10 = %f", fTracker->GetA10());
450 HLTDebug(" Region of interest parameter 'B' for chamber 10 = %f cm", fTracker->GetB10());
451 HLTDebug(" Nominal Z coordinate for chamber 7 = %f cm", fTracker->GetZ7());
452 HLTDebug(" Nominal Z coordinate for chamber 8 = %f cm", fTracker->GetZ8());
453 HLTDebug(" Nominal Z coordinate for chamber 9 = %f cm", fTracker->GetZ9());
454 HLTDebug(" Nominal Z coordinate for chamber 10 = %f cm", fTracker->GetZ10());
455 HLTDebug(" Nominal Z coordinate for chamber 11 = %f cm", fTracker->GetZ11());
456 HLTDebug(" Nominal Z coordinate for chamber 13 = %f cm", fTracker->GetZ13());
459 ResetCanLoadFlags(); // From this point read all parameters from CDB.
462 const int initArraySize = 10;
463 // Allocate some initial memory for the reconstructed hit arrays.
466 fRecHitBlock[0] = new AliRecHitBlockInfo[initArraySize*4];
468 catch (const std::bad_alloc&)
470 HLTError("Could not allocate more memory for the reconstructed hit arrays.");
471 FreeMemory(); // Make sure we cleanup to avoid partial initialisation.
474 // Only set the arrays' size once we have successfully allocated the memory for the arrays.
475 fRecHitBlockArraySize = initArraySize;
476 // Now we need to set the pointers fRecHitBlock[i] {i>0} relative to fRecHitBlock[0].
477 for (Int_t i = 1; i < 4; i++)
479 fRecHitBlock[i] = fRecHitBlock[i-1] + fRecHitBlockArraySize;
481 // And reset the number of records actually stored in the arrays.
482 for (Int_t i = 0; i < 4; i++)
484 fRecHitBlockCount[i] = 0;
491 int AliHLTMUONMansoTrackerFSMComponent::Reconfigure(
492 const char* cdbEntry, const char* componentId
495 /// Inherited from AliHLTComponent. This method will reload CDB configuration
496 /// entries for this component from the CDB.
497 /// \param cdbEntry If this is NULL or equals "HLT/ConfigMUON/MansoTrackerFSM"
498 /// then new configuration parameters are loaded, otherwise nothing is done.
499 /// \param componentId The name of the component in the current chain.
501 TString path = cdbEntry;
502 bool givenConfigPath = (path == AliHLTMUONConstants::MansoTrackerFSMCDBPath());
504 if (cdbEntry == NULL or givenConfigPath)
506 HLTInfo("Reading new configuration entries from CDB for component '%s'.", componentId);
507 ResetCanLoadFlags(); // Make sure to allow reading all values from CDB.
508 int result = ReadConfigFromCDB();
509 if (result != 0) return result;
516 int AliHLTMUONMansoTrackerFSMComponent::ReadPreprocessorValues(const char* modules)
518 /// Inherited from AliHLTComponent.
519 /// Updates the configuration of this component if HLT or ALL has been
520 /// specified in the 'modules' list.
522 TString mods = modules;
523 if (mods.Contains("ALL"))
525 return Reconfigure(NULL, GetComponentID());
527 if (mods.Contains("HLT"))
529 return Reconfigure(AliHLTMUONConstants::MansoTrackerFSMCDBPath(), GetComponentID());
535 int AliHLTMUONMansoTrackerFSMComponent::ReadConfigFromCDB()
537 /// Reads this component's configuration parameters from the CDB.
538 /// These include the middle of the dipole Z coordinate (zmiddle), the
539 /// integrated magnetic field of the dipole, Z coordinates of the chambers
540 /// and the region of interest parameters used during the tracking.
541 /// \param setZmiddle Indicates if the zmiddle parameter should be set
543 /// \param setBL Indicates if the integrated magnetic field parameter should
544 /// be set (default true).
545 /// \return 0 if no errors occured and negative error code compatible with
546 /// the HLT framework on errors.
548 const char* pathToEntry = AliHLTMUONConstants::MansoTrackerFSMCDBPath();
551 int result = FetchTMapFromCDB(pathToEntry, map);
552 if (result != 0) return result;
557 result = GetFloatFromTMap(map, "zmiddle", value, pathToEntry, "dipole middle Z coordinate");
558 if (result != 0) return result;
559 AliHLTMUONCalculations::Zf(value);
564 Double_t bfieldintegral;
565 result = FetchFieldIntegral(bfieldintegral);
568 AliHLTMUONCalculations::QBL(bfieldintegral);
572 HLTWarning("Failed to load the magnetic field integral from GRP information.");
573 result = GetFloatFromTMap(map, "bfieldintegral", value, pathToEntry, "integrated magnetic field");
574 if (result != 0) return result;
575 HLTWarning(Form("Using deprecated magnetic field integral value of %f T.m.", value));
576 AliHLTMUONCalculations::QBL(value);
582 result = GetFloatFromTMap(map, "roi_paramA_chamber7", value, pathToEntry, "chamber 7 region of interest 'A'");
583 if (result != 0) return result;
584 fTracker->SetA7(value);
588 result = GetFloatFromTMap(map, "roi_paramA_chamber8", value, pathToEntry, "chamber 8 region of interest 'A'");
589 if (result != 0) return result;
590 fTracker->SetA8(value);
594 result = GetFloatFromTMap(map, "roi_paramA_chamber9", value, pathToEntry, "chamber 9 region of interest 'A'");
595 if (result != 0) return result;
596 fTracker->SetA9(value);
600 result = GetFloatFromTMap(map, "roi_paramA_chamber10", value, pathToEntry, "chamber 10 region of interest 'A'");
601 if (result != 0) return result;
602 fTracker->SetA10(value);
607 result = GetFloatFromTMap(map, "roi_paramB_chamber7", value, pathToEntry, "chamber 7 region of interest 'B'");
608 if (result != 0) return result;
609 fTracker->SetB7(value);
613 result = GetFloatFromTMap(map, "roi_paramB_chamber8", value, pathToEntry, "chamber 8 region of interest 'B'");
614 if (result != 0) return result;
615 fTracker->SetB8(value);
619 result = GetFloatFromTMap(map, "roi_paramB_chamber9", value, pathToEntry, "chamber 9 region of interest 'B'");
620 if (result != 0) return result;
621 fTracker->SetB9(value);
625 result = GetFloatFromTMap(map, "roi_paramB_chamber10", value, pathToEntry, "chamber 10 region of interest 'B'");
626 if (result != 0) return result;
627 fTracker->SetB10(value);
632 result = GetFloatFromTMap(map, "chamber7postion", value, pathToEntry, "nominal chamber 7 Z coordinate");
633 if (result != 0) return result;
634 fTracker->SetZ7(value);
638 result = GetFloatFromTMap(map, "chamber8postion", value, pathToEntry, "nominal chamber 8 Z coordinate");
639 if (result != 0) return result;
640 fTracker->SetZ8(value);
644 result = GetFloatFromTMap(map, "chamber9postion", value, pathToEntry, "nominal chamber 9 Z coordinate");
645 if (result != 0) return result;
646 fTracker->SetZ9(value);
650 result = GetFloatFromTMap(map, "chamber10postion", value, pathToEntry, "nominal chamber 10 Z coordinate");
651 if (result != 0) return result;
652 fTracker->SetZ10(value);
656 result = GetFloatFromTMap(map, "chamber11postion", value, pathToEntry, "nominal chamber 11 Z coordinate");
657 if (result != 0) return result;
658 fTracker->SetZ11(value);
662 result = GetFloatFromTMap(map, "chamber13postion", value, pathToEntry, "nominal chamber 13 Z coordinate");
663 if (result != 0) return result;
664 fTracker->SetZ13(value);
667 HLTDebug("Using the following configuration parameters:");
668 HLTDebug(" Middle of dipole Z coordinate = %f cm", AliHLTMUONCalculations::Zf());
669 HLTDebug(" Magnetic field integral = %f T.m", AliHLTMUONCalculations::QBL());
670 HLTDebug(" Region of interest parameter 'A' for chamber 7 = %f", fTracker->GetA7());
671 HLTDebug(" Region of interest parameter 'B' for chamber 7 = %f cm", fTracker->GetB7());
672 HLTDebug(" Region of interest parameter 'A' for chamber 8 = %f", fTracker->GetA8());
673 HLTDebug(" Region of interest parameter 'B' for chamber 8 = %f cm", fTracker->GetB8());
674 HLTDebug(" Region of interest parameter 'A' for chamber 9 = %f", fTracker->GetA9());
675 HLTDebug(" Region of interest parameter 'B' for chamber 9 = %f cm", fTracker->GetB9());
676 HLTDebug(" Region of interest parameter 'A' for chamber 10 = %f", fTracker->GetA10());
677 HLTDebug(" Region of interest parameter 'B' for chamber 10 = %f cm", fTracker->GetB10());
678 HLTDebug(" Nominal Z coordinate for chamber 7 = %f cm", fTracker->GetZ7());
679 HLTDebug(" Nominal Z coordinate for chamber 8 = %f cm", fTracker->GetZ8());
680 HLTDebug(" Nominal Z coordinate for chamber 9 = %f cm", fTracker->GetZ9());
681 HLTDebug(" Nominal Z coordinate for chamber 10 = %f cm", fTracker->GetZ10());
682 HLTDebug(" Nominal Z coordinate for chamber 11 = %f cm", fTracker->GetZ11());
683 HLTDebug(" Nominal Z coordinate for chamber 13 = %f cm", fTracker->GetZ13());
689 int AliHLTMUONMansoTrackerFSMComponent::DoDeinit()
692 /// Inherited from AliHLTComponent. Performs a cleanup of the component.
695 HLTInfo("Deinitialising dHLT manso tracker FSM component.");
701 int AliHLTMUONMansoTrackerFSMComponent::DoEvent(
702 const AliHLTComponentEventData& evtData,
703 const AliHLTComponentBlockData* blocks,
704 AliHLTComponentTriggerData& trigData,
705 AliHLTUInt8_t* outputPtr,
706 AliHLTUInt32_t& size,
707 AliHLTComponentBlockDataList& outputBlocks
711 /// Inherited from AliHLTProcessor. Processes the new event data.
714 // Initialise the configuration parameters from CDB if we were
715 // requested to initialise only when the first event was received.
718 // Load the configuration paramters from CDB if they have not
719 // been given on the command line.
720 if (AtLeastOneCanLoadFlagsIsSet())
722 HLTInfo("Loading configuration parameters from CDB.");
723 int result = ReadConfigFromCDB();
724 if (result != 0) return result;
728 ResetCanLoadFlags(); // From this point read all parameters from CDB.
732 AliHLTUInt32_t specification = 0; // Contains the output data block spec bits.
734 // Resize the rec hit arrays if we possibly will need more space.
735 // To guarantee that they will not overflow we need to make sure each
736 // array is at least as big as the number of input data blocks.
737 if (fRecHitBlockArraySize < evtData.fBlockCnt)
739 // Release the old memory block and allocate more memory.
740 if (fRecHitBlock[0] != NULL)
742 delete [] fRecHitBlock[0];
745 // Reset the number of records actually stored in the arrays.
746 for (Int_t i = 0; i < 4; i++)
748 fRecHitBlockCount[i] = 0;
753 fRecHitBlock[0] = new AliRecHitBlockInfo[evtData.fBlockCnt*4];
755 catch (const std::bad_alloc&)
757 HLTError("Could not allocate more memory for the reconstructed hit arrays.");
758 // Ok so now we need to clear all the pointers because we actually
759 // deleted the memory.
760 fRecHitBlockArraySize = 0;
761 for (Int_t i = 0; i < 4; i++)
763 fRecHitBlock[i] = NULL;
765 if (DumpDataOnError()) DumpEvent(evtData, blocks, trigData, outputPtr, size, outputBlocks);
768 // Only set the arrays' size once we have successfully allocated the memory for the arrays.
769 fRecHitBlockArraySize = evtData.fBlockCnt;
770 // Now we need to set the pointers fRecHitBlock[i] {i>0} relative to fRecHitBlock[0].
771 for (Int_t i = 1; i < 4; i++)
773 fRecHitBlock[i] = fRecHitBlock[i-1] + fRecHitBlockArraySize;
777 AliHLTMUONMansoTracksBlockWriter block(outputPtr, size);
780 if (not block.InitCommonHeader())
782 Logging(kHLTLogError,
783 "AliHLTMUONMansoTrackerFSMComponent::DoEvent",
785 "The buffer is only %d bytes in size. We need a minimum of %d bytes.",
786 size, sizeof(AliHLTMUONMansoTracksBlockWriter::HeaderType)
788 if (DumpDataOnError()) DumpEvent(evtData, blocks, trigData, outputPtr, size, outputBlocks);
789 size = 0; // Important to tell framework that nothing was generated.
793 // Loop over all input blocks in the event and add the ones that contain
794 // reconstructed hits into the hit buffers. The blocks containing trigger
795 // records are ignored for now and will be processed later.
796 for (AliHLTUInt32_t n = 0; n < evtData.fBlockCnt; n++)
798 HLTDebug("Handling block: %u, with fDataType = '%s', fPtr = %p and fSize = %u bytes.",
799 n, DataType2Text(blocks[n].fDataType).c_str(), blocks[n].fPtr, blocks[n].fSize
802 if (blocks[n].fDataType == AliHLTMUONConstants::RecHitsBlockDataType())
804 specification |= blocks[n].fSpecification;
806 AliHLTMUONRecHitsBlockReader inblock(blocks[n].fPtr, blocks[n].fSize);
807 if (not BlockStructureOk(inblock))
809 if (DumpDataOnError()) DumpEvent(evtData, blocks, trigData, outputPtr, size, outputBlocks);
813 if (inblock.Nentries() != 0)
814 AddRecHits(blocks[n].fSpecification, inblock.GetArray(), inblock.Nentries());
817 Logging(kHLTLogDebug,
818 "AliHLTMUONMansoTrackerFSMComponent::DoEvent",
820 "Received a reconstructed hits data block which contains no entries."
824 else if (blocks[n].fDataType != AliHLTMUONConstants::TriggerRecordsBlockDataType())
826 // Log a message indicating that we got a data block that we
827 // do not know how to handle.
828 if (fWarnForUnexpecedBlock)
829 HLTWarning("Received a data block of a type we cannot handle: '%s', spec: 0x%X",
830 DataType2Text(blocks[n].fDataType).c_str(), blocks[n].fSpecification
834 HLTDebug("Received a data block of a type we cannot handle: '%s', spec: 0x%X",
835 DataType2Text(blocks[n].fDataType).c_str(), blocks[n].fSpecification
841 // Again loop over all input blocks in the event, but this time look for
842 // the trigger record blocks and process these.
843 for (AliHLTUInt32_t n = 0; n < evtData.fBlockCnt; n++)
845 if (blocks[n].fDataType != AliHLTMUONConstants::TriggerRecordsBlockDataType())
848 AliHLTMUONTriggerRecordsBlockReader inblock(blocks[n].fPtr, blocks[n].fSize);
849 if (not BlockStructureOk(inblock))
851 if (DumpDataOnError()) DumpEvent(evtData, blocks, trigData, outputPtr, size, outputBlocks);
855 DebugTrace("Processing a trigger block with "
856 << inblock.Nentries() << " entries."
859 specification |= blocks[n].fSpecification;
861 for (AliHLTUInt32_t i = 0; i < inblock.Nentries(); i++)
863 fTracker->FindTrack(inblock[i]);
865 // Reset the tracker so that we do not double count tracks.
870 AliHLTComponentBlockData bd;
874 bd.fSize = block.BytesUsed();
875 bd.fDataType = AliHLTMUONConstants::MansoTracksBlockDataType();
876 bd.fSpecification = specification;
877 outputBlocks.push_back(bd);
878 AliHLTUInt32_t totalSize = block.BytesUsed();
880 if (fTracker->MakeCandidates())
882 AliHLTMUONMansoCandidatesBlockWriter candidatesBlock(outputPtr+totalSize, size-totalSize);
883 if (not candidatesBlock.InitCommonHeader())
885 HLTError("Buffer overflowed. There are only %d bytes left in the buffer,"
886 " but we need a minimum of %d bytes.",
887 size, sizeof(AliHLTMUONMansoCandidatesBlockWriter::HeaderType)
889 if (DumpDataOnError()) DumpEvent(evtData, blocks, trigData, outputPtr, size, outputBlocks);
890 size = 0; // Important to tell framework that nothing was generated.
894 // Fill in the output block buffer.
895 candidatesBlock.SetNumberOfEntries(fTracker->TrackCandidatesCount());
896 for (AliHLTUInt32_t i = 0; i < fTracker->TrackCandidatesCount(); ++i)
898 candidatesBlock[i] = fTracker->TrackCandidates()[i];
901 fTracker->ZeroTrackCandidatesList();
903 AliHLTComponentBlockData bdc;
905 bdc.fPtr = outputPtr;
906 bdc.fOffset = totalSize;
907 bdc.fSize = candidatesBlock.BytesUsed();
908 bdc.fDataType = AliHLTMUONConstants::MansoCandidatesBlockDataType();
909 bdc.fSpecification = specification;
910 outputBlocks.push_back(bdc);
911 totalSize += candidatesBlock.BytesUsed();
919 void AliHLTMUONMansoTrackerFSMComponent::Reset()
922 /// Reset the track count and reconstructed hit data block arrays.
925 DebugTrace("Resetting AliHLTMUONMansoTrackerFSMComponent.");
927 //fTracker->Reset(); // Not necessary here because it is done after every FindTrack call.
929 fBlock = NULL; // Do not delete. Already done implicitly at the end of DoEvent.
930 for (int i = 0; i < 4; i++)
932 fRecHitBlockCount[i] = 0;
937 void AliHLTMUONMansoTrackerFSMComponent::FreeMemory()
939 /// Deletes any objects and arrays allocated by this component and releases
940 /// the memory used. This is called as a helper routine by the init and deinit
941 /// methods. If some or all of the object pointers are already NULL then
942 /// nothing is done for those. This method guarantees that all the relevant
943 /// pointers will be NULL after returning from this method.
945 if (fTracker != NULL)
951 // Remember that only fRecHitBlock[0] stores the pointer to the allocated memory.
952 // The other pointers are just reletive to this.
953 if (fRecHitBlock[0] != NULL)
954 delete [] fRecHitBlock[0];
956 fRecHitBlockArraySize = 0;
957 for (Int_t i = 0; i < 4; i++)
959 fRecHitBlockCount[i] = 0;
960 fRecHitBlock[i] = NULL;
965 void AliHLTMUONMansoTrackerFSMComponent::AddRecHits(
966 AliHLTUInt32_t specification,
967 const AliHLTMUONRecHitStruct* recHits,
972 /// Adds a new reconstructed hit data block to the internal list of blocks
973 /// for the tracker to process.
974 /// These lists will later be used when the tracker requests them through
975 /// the callback method 'RequestClusters'.
978 DebugTrace("AliHLTMUONMansoTrackerFSMComponent::AddRecHits called with specification = 0x"
979 << std::hex << specification << std::dec << " and count = "
980 << count << " rec hits."
983 AliHLTUInt8_t chamberMap[20] = {
984 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9, 10, 10
987 // Identify the chamber the rec hits came from using the specifications field.
988 bool gotDataFromDDL[22];
989 AliHLTMUONUtils::UnpackSpecBits(specification, gotDataFromDDL);
991 AliHLTInt8_t chamber = -1;
992 for (int i = 0; i < 20; i++)
994 if (not gotDataFromDDL[i]) continue;
995 if (7 <= chamberMap[i] and chamberMap[i] <= 10)
997 if (chamber != -1 and chamber != chamberMap[i])
999 Logging(kHLTLogError,
1000 "AliHLTMUONMansoTrackerFSMComponent::AddRecHits",
1002 "Received a data block with data from multiple chambers."
1003 " This component cannot handle such a case."
1008 chamber = chamberMap[i];
1012 if (fWarnForUnexpecedBlock)
1014 Logging(kHLTLogWarning,
1015 "AliHLTMUONMansoTrackerFSMComponent::AddRecHits",
1017 "Received a data block with data from chamber %d"
1018 " which is outside the expected range: [7..10].",
1026 // Make sure we got one chamber number.
1027 if (chamber < 7 or 10 < chamber)
1029 Logging(kHLTLogError,
1030 "AliHLTMUONMansoTrackerFSMComponent::AddRecHits",
1032 "Received a reconstructed hit data block with a null specification."
1033 " Cannot know which chamber the data comes from."
1038 DebugTrace("Added " << count << " reconstructed hits from chamber "
1039 << (int)chamber << " to the internal arrays."
1042 assert( fRecHitBlockCount[chamber-7] < fRecHitBlockArraySize );
1043 AliRecHitBlockInfo info(count, recHits);
1044 fRecHitBlock[chamber-7][fRecHitBlockCount[chamber-7]] = info;
1045 fRecHitBlockCount[chamber-7]++;
1049 void AliHLTMUONMansoTrackerFSMComponent::ResetCanLoadFlags()
1051 /// Resets all the fCanLoad* flags to true. This enables loading of all
1052 /// those CDB entries in the method ReadConfigFromCDB.
1054 fCanLoadZmiddle = true;
1056 for (int i = 0; i < 4; i++)
1058 fCanLoadA[i] = true;
1059 fCanLoadB[i] = true;
1061 for (int i = 0; i < 6; i++)
1063 fCanLoadZ[i] = true;
1068 bool AliHLTMUONMansoTrackerFSMComponent::AtLeastOneCanLoadFlagsIsSet() const
1070 /// Returns true if at least one fCanLoad* flag was true and false otherwise.
1072 if (fCanLoadZmiddle or fCanLoadBL) return true;
1073 for (int i = 0; i < 4; i++)
1075 if (fCanLoadA[i]) return true;
1076 if (fCanLoadB[i]) return true;
1078 for (int i = 0; i < 6; i++)
1080 if (fCanLoadZ[i]) return true;
1086 void AliHLTMUONMansoTrackerFSMComponent::RequestClusters(
1087 AliHLTMUONMansoTrackerFSM* tracker,
1088 AliHLTFloat32_t left, AliHLTFloat32_t right,
1089 AliHLTFloat32_t bottom, AliHLTFloat32_t top,
1090 AliHLTMUONChamberName chamber, const void* tag
1094 /// Inherited from AliHLTMUONMansoTrackerFSMCallback.
1095 /// This is the call back method used by the tracker algorithm to request
1096 /// clusters on a certain chamber.
1099 DebugTrace("AliHLTMUONMansoTracker::RequestClusters(chamber = " << chamber << ")");
1100 void* ctag = const_cast<void*>(tag);
1102 AliHLTUInt32_t recHitsCount = 0;
1103 AliRecHitBlockInfo* recHitsBlock = NULL;
1107 recHitsCount = fRecHitBlockCount[0];
1108 recHitsBlock = fRecHitBlock[0];
1113 recHitsCount = fRecHitBlockCount[1];
1114 recHitsBlock = fRecHitBlock[1];
1119 recHitsCount = fRecHitBlockCount[2];
1120 recHitsBlock = fRecHitBlock[2];
1125 recHitsCount = fRecHitBlockCount[3];
1126 recHitsBlock = fRecHitBlock[3];
1133 DebugTrace("Returning requested hits for chamber " << chNo << ":");
1134 for (AliHLTUInt32_t i = 0; i < recHitsCount; i++)
1135 for (AliHLTUInt32_t j = 0; j < recHitsBlock[i].Count(); j++)
1137 const AliHLTMUONRecHitStruct* hit = &(recHitsBlock[i].Data()[j]);
1138 if (left < hit->fX and hit->fX < right and bottom < hit->fY and hit->fY < top)
1139 tracker->ReturnClusters(ctag, hit, 1);
1141 DebugTrace("Done returning hits from chamber " << chNo << ".");
1142 tracker->EndOfClusters(ctag);
1146 void AliHLTMUONMansoTrackerFSMComponent::EndOfClusterRequests(
1147 AliHLTMUONMansoTrackerFSM* /*tracker*/
1151 /// Inherited from AliHLTMUONMansoTrackerFSMCallback.
1152 /// Nothing special to do here.
1155 DebugTrace("End of cluster requests.");
1159 void AliHLTMUONMansoTrackerFSMComponent::FoundTrack(AliHLTMUONMansoTrackerFSM* tracker)
1162 /// Inherited from AliHLTMUONMansoTrackerFSMCallback.
1163 /// This is the call back method used by the tracker algorithm to declare
1164 /// that a new track has been found.
1167 DebugTrace("AliHLTMUONMansoTrackerFSMComponent::FoundTrack()");
1169 AliHLTMUONMansoTracksBlockWriter* block =
1170 reinterpret_cast<AliHLTMUONMansoTracksBlockWriter*>(fBlock);
1172 AliHLTMUONMansoTrackStruct newTrack;
1173 tracker->FillTrackData(newTrack);
1175 // The indicies of the duplicate tracks. If set to block->Nentries() then
1176 // this indicates the index is not used.
1177 AliHLTUInt32_t dup1 = block->Nentries();
1178 AliHLTUInt32_t dup2 = block->Nentries();
1180 // Check if there are any tracks that use the same hits as the one found.
1181 // If there are, then use the one that has the highest pT.
1182 // There will be at most 2 duplicate tracks.
1183 for (AliHLTUInt32_t i = 0; i < block->Nentries(); i++)
1185 AliHLTMUONMansoTrackStruct& track = (*block)[i];
1186 bool hasNoDuplicates = true;
1187 for (AliHLTUInt32_t j = 0; j < 4; j++)
1189 if (track.fHit[j] == AliHLTMUONConstants::NilRecHitStruct()) continue;
1190 if (newTrack.fHit[j] == AliHLTMUONConstants::NilRecHitStruct()) continue;
1191 if (track.fHit[j] == newTrack.fHit[j])
1193 hasNoDuplicates = false;
1197 if (hasNoDuplicates) continue;
1199 if (dup1 == block->Nentries())
1203 else if (dup2 == block->Nentries())
1209 HLTError("Found more than 2 tracks with duplicate hits. This is completely unexpected. Something is seriously wrong!");
1213 if (dup1 != block->Nentries() and dup2 != block->Nentries())
1215 // In this case we found 2 duplicate entries.
1216 // Figure out which one has the highest pT and keep only that one.
1217 AliHLTMUONMansoTrackStruct& track1 = (*block)[dup1];
1218 AliHLTMUONMansoTrackStruct& track2 = (*block)[dup2];
1219 double newPt = sqrt(newTrack.fPx * newTrack.fPx + newTrack.fPy * newTrack.fPy);
1220 double dupPt1 = sqrt(track1.fPx * track1.fPx + track1.fPy * track1.fPy);
1221 double dupPt2 = sqrt(track2.fPx * track2.fPx + track2.fPy * track2.fPy);
1223 if (newPt >= dupPt1 and newPt >= dupPt2)
1225 // The new track must replace both existing tracks.
1227 track2 = (*block)[block->Nentries()-1];
1229 else if (dupPt1 >= newPt and dupPt1 >= dupPt2)
1231 // track1 has the highest pT so ignore the new track and delete track2.
1232 track2 = (*block)[block->Nentries()-1];
1236 // In this case track2 must have the highest pT so ignore the new
1237 // track and delete track1.
1238 track1 = (*block)[block->Nentries()-1];
1241 // Decrement the number of entries because we deleted a track.
1242 assert(fTrackCount > 0);
1243 assert(block->Nentries() > 0);
1244 block->SetNumberOfEntries(block->Nentries()-1);
1247 else if (dup1 != block->Nentries())
1249 // Only one track with duplicate hits found.
1250 // See if the new track has higher pT. If it does then replace the
1251 // exisiting track, otherwise ignore the new track.
1252 AliHLTMUONMansoTrackStruct& track1 = (*block)[dup1];
1253 double newPt = sqrt(newTrack.fPx * newTrack.fPx + newTrack.fPy * newTrack.fPy);
1254 double dupPt1 = sqrt(track1.fPx * track1.fPx + track1.fPy * track1.fPy);
1255 if (newPt >= dupPt1)
1262 // No track found with duplicate hits so we can add the new track as it is.
1263 AliHLTMUONMansoTrackStruct* track = block->AddEntry();
1266 Logging(kHLTLogError,
1267 "AliHLTMUONMansoTrackerFSMComponent::FoundTrack",
1269 "We have overflowed the output buffer for Manso track data."
1270 " The output buffer size is only %d bytes.",
1278 DebugTrace("\tAdded new track: " << *track);
1283 void AliHLTMUONMansoTrackerFSMComponent::NoTrackFound(AliHLTMUONMansoTrackerFSM* /*tracker*/)
1286 /// Inherited from AliHLTMUONMansoTrackerFSMCallback.
1287 /// Nothing special to do here.
1290 DebugTrace("No track found.");