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 bool givenConfigPath = strcmp(cdbEntry, AliHLTMUONConstants::MansoTrackerFSMCDBPath()) == 0;
503 if (cdbEntry == NULL or givenConfigPath)
505 HLTInfo("Reading new configuration entries from CDB for component '%s'.", componentId);
506 ResetCanLoadFlags(); // Make sure to allow reading all values from CDB.
507 int result = ReadConfigFromCDB();
508 if (result != 0) return result;
515 int AliHLTMUONMansoTrackerFSMComponent::ReadPreprocessorValues(const char* modules)
517 /// Inherited from AliHLTComponent.
518 /// Updates the configuration of this component if HLT or ALL has been
519 /// specified in the 'modules' list.
521 TString mods = modules;
522 if (mods.Contains("ALL"))
524 return Reconfigure(NULL, GetComponentID());
526 if (mods.Contains("HLT"))
528 return Reconfigure(AliHLTMUONConstants::MansoTrackerFSMCDBPath(), GetComponentID());
534 int AliHLTMUONMansoTrackerFSMComponent::ReadConfigFromCDB()
536 /// Reads this component's configuration parameters from the CDB.
537 /// These include the middle of the dipole Z coordinate (zmiddle), the
538 /// integrated magnetic field of the dipole, Z coordinates of the chambers
539 /// and the region of interest parameters used during the tracking.
540 /// \param setZmiddle Indicates if the zmiddle parameter should be set
542 /// \param setBL Indicates if the integrated magnetic field parameter should
543 /// be set (default true).
544 /// \return 0 if no errors occured and negative error code compatible with
545 /// the HLT framework on errors.
547 const char* pathToEntry = AliHLTMUONConstants::MansoTrackerFSMCDBPath();
550 int result = FetchTMapFromCDB(pathToEntry, map);
551 if (result != 0) return result;
556 result = GetFloatFromTMap(map, "zmiddle", value, pathToEntry, "dipole middle Z coordinate");
557 if (result != 0) return result;
558 AliHLTMUONCalculations::Zf(value);
563 Double_t bfieldintegral;
564 result = FetchFieldIntegral(bfieldintegral);
567 AliHLTMUONCalculations::QBL(bfieldintegral);
571 HLTWarning("Failed to load the magnetic field integral from GRP information.");
572 result = GetFloatFromTMap(map, "bfieldintegral", value, pathToEntry, "integrated magnetic field");
573 if (result != 0) return result;
574 HLTWarning(Form("Using deprecated magnetic field integral value of %f T.m.", value));
575 AliHLTMUONCalculations::QBL(value);
581 result = GetFloatFromTMap(map, "roi_paramA_chamber7", value, pathToEntry, "chamber 7 region of interest 'A'");
582 if (result != 0) return result;
583 fTracker->SetA7(value);
587 result = GetFloatFromTMap(map, "roi_paramA_chamber8", value, pathToEntry, "chamber 8 region of interest 'A'");
588 if (result != 0) return result;
589 fTracker->SetA8(value);
593 result = GetFloatFromTMap(map, "roi_paramA_chamber9", value, pathToEntry, "chamber 9 region of interest 'A'");
594 if (result != 0) return result;
595 fTracker->SetA9(value);
599 result = GetFloatFromTMap(map, "roi_paramA_chamber10", value, pathToEntry, "chamber 10 region of interest 'A'");
600 if (result != 0) return result;
601 fTracker->SetA10(value);
606 result = GetFloatFromTMap(map, "roi_paramB_chamber7", value, pathToEntry, "chamber 7 region of interest 'B'");
607 if (result != 0) return result;
608 fTracker->SetB7(value);
612 result = GetFloatFromTMap(map, "roi_paramB_chamber8", value, pathToEntry, "chamber 8 region of interest 'B'");
613 if (result != 0) return result;
614 fTracker->SetB8(value);
618 result = GetFloatFromTMap(map, "roi_paramB_chamber9", value, pathToEntry, "chamber 9 region of interest 'B'");
619 if (result != 0) return result;
620 fTracker->SetB9(value);
624 result = GetFloatFromTMap(map, "roi_paramB_chamber10", value, pathToEntry, "chamber 10 region of interest 'B'");
625 if (result != 0) return result;
626 fTracker->SetB10(value);
631 result = GetFloatFromTMap(map, "chamber7postion", value, pathToEntry, "nominal chamber 7 Z coordinate");
632 if (result != 0) return result;
633 fTracker->SetZ7(value);
637 result = GetFloatFromTMap(map, "chamber8postion", value, pathToEntry, "nominal chamber 8 Z coordinate");
638 if (result != 0) return result;
639 fTracker->SetZ8(value);
643 result = GetFloatFromTMap(map, "chamber9postion", value, pathToEntry, "nominal chamber 9 Z coordinate");
644 if (result != 0) return result;
645 fTracker->SetZ9(value);
649 result = GetFloatFromTMap(map, "chamber10postion", value, pathToEntry, "nominal chamber 10 Z coordinate");
650 if (result != 0) return result;
651 fTracker->SetZ10(value);
655 result = GetFloatFromTMap(map, "chamber11postion", value, pathToEntry, "nominal chamber 11 Z coordinate");
656 if (result != 0) return result;
657 fTracker->SetZ11(value);
661 result = GetFloatFromTMap(map, "chamber13postion", value, pathToEntry, "nominal chamber 13 Z coordinate");
662 if (result != 0) return result;
663 fTracker->SetZ13(value);
666 HLTDebug("Using the following configuration parameters:");
667 HLTDebug(" Middle of dipole Z coordinate = %f cm", AliHLTMUONCalculations::Zf());
668 HLTDebug(" Magnetic field integral = %f T.m", AliHLTMUONCalculations::QBL());
669 HLTDebug(" Region of interest parameter 'A' for chamber 7 = %f", fTracker->GetA7());
670 HLTDebug(" Region of interest parameter 'B' for chamber 7 = %f cm", fTracker->GetB7());
671 HLTDebug(" Region of interest parameter 'A' for chamber 8 = %f", fTracker->GetA8());
672 HLTDebug(" Region of interest parameter 'B' for chamber 8 = %f cm", fTracker->GetB8());
673 HLTDebug(" Region of interest parameter 'A' for chamber 9 = %f", fTracker->GetA9());
674 HLTDebug(" Region of interest parameter 'B' for chamber 9 = %f cm", fTracker->GetB9());
675 HLTDebug(" Region of interest parameter 'A' for chamber 10 = %f", fTracker->GetA10());
676 HLTDebug(" Region of interest parameter 'B' for chamber 10 = %f cm", fTracker->GetB10());
677 HLTDebug(" Nominal Z coordinate for chamber 7 = %f cm", fTracker->GetZ7());
678 HLTDebug(" Nominal Z coordinate for chamber 8 = %f cm", fTracker->GetZ8());
679 HLTDebug(" Nominal Z coordinate for chamber 9 = %f cm", fTracker->GetZ9());
680 HLTDebug(" Nominal Z coordinate for chamber 10 = %f cm", fTracker->GetZ10());
681 HLTDebug(" Nominal Z coordinate for chamber 11 = %f cm", fTracker->GetZ11());
682 HLTDebug(" Nominal Z coordinate for chamber 13 = %f cm", fTracker->GetZ13());
688 int AliHLTMUONMansoTrackerFSMComponent::DoDeinit()
691 /// Inherited from AliHLTComponent. Performs a cleanup of the component.
694 HLTInfo("Deinitialising dHLT manso tracker FSM component.");
700 int AliHLTMUONMansoTrackerFSMComponent::DoEvent(
701 const AliHLTComponentEventData& evtData,
702 const AliHLTComponentBlockData* blocks,
703 AliHLTComponentTriggerData& trigData,
704 AliHLTUInt8_t* outputPtr,
705 AliHLTUInt32_t& size,
706 AliHLTComponentBlockDataList& outputBlocks
710 /// Inherited from AliHLTProcessor. Processes the new event data.
713 // Initialise the configuration parameters from CDB if we were
714 // requested to initialise only when the first event was received.
717 // Load the configuration paramters from CDB if they have not
718 // been given on the command line.
719 if (AtLeastOneCanLoadFlagsIsSet())
721 HLTInfo("Loading configuration parameters from CDB.");
722 int result = ReadConfigFromCDB();
723 if (result != 0) return result;
727 ResetCanLoadFlags(); // From this point read all parameters from CDB.
731 AliHLTUInt32_t specification = 0; // Contains the output data block spec bits.
733 // Resize the rec hit arrays if we possibly will need more space.
734 // To guarantee that they will not overflow we need to make sure each
735 // array is at least as big as the number of input data blocks.
736 if (fRecHitBlockArraySize < evtData.fBlockCnt)
738 // Release the old memory block and allocate more memory.
739 if (fRecHitBlock[0] != NULL)
741 delete [] fRecHitBlock[0];
744 // Reset the number of records actually stored in the arrays.
745 for (Int_t i = 0; i < 4; i++)
747 fRecHitBlockCount[i] = 0;
752 fRecHitBlock[0] = new AliRecHitBlockInfo[evtData.fBlockCnt*4];
754 catch (const std::bad_alloc&)
756 HLTError("Could not allocate more memory for the reconstructed hit arrays.");
757 // Ok so now we need to clear all the pointers because we actually
758 // deleted the memory.
759 fRecHitBlockArraySize = 0;
760 for (Int_t i = 0; i < 4; i++)
762 fRecHitBlock[i] = NULL;
764 if (DumpDataOnError()) DumpEvent(evtData, blocks, trigData, outputPtr, size, outputBlocks);
767 // Only set the arrays' size once we have successfully allocated the memory for the arrays.
768 fRecHitBlockArraySize = evtData.fBlockCnt;
769 // Now we need to set the pointers fRecHitBlock[i] {i>0} relative to fRecHitBlock[0].
770 for (Int_t i = 1; i < 4; i++)
772 fRecHitBlock[i] = fRecHitBlock[i-1] + fRecHitBlockArraySize;
776 AliHLTMUONMansoTracksBlockWriter block(outputPtr, size);
779 if (not block.InitCommonHeader())
781 Logging(kHLTLogError,
782 "AliHLTMUONMansoTrackerFSMComponent::DoEvent",
784 "The buffer is only %d bytes in size. We need a minimum of %d bytes.",
785 size, sizeof(AliHLTMUONMansoTracksBlockWriter::HeaderType)
787 if (DumpDataOnError()) DumpEvent(evtData, blocks, trigData, outputPtr, size, outputBlocks);
788 size = 0; // Important to tell framework that nothing was generated.
792 // Loop over all input blocks in the event and add the ones that contain
793 // reconstructed hits into the hit buffers. The blocks containing trigger
794 // records are ignored for now and will be processed later.
795 for (AliHLTUInt32_t n = 0; n < evtData.fBlockCnt; n++)
797 HLTDebug("Handling block: %u, with fDataType = '%s', fPtr = %p and fSize = %u bytes.",
798 n, DataType2Text(blocks[n].fDataType).c_str(), blocks[n].fPtr, blocks[n].fSize
801 if (blocks[n].fDataType == AliHLTMUONConstants::RecHitsBlockDataType())
803 specification |= blocks[n].fSpecification;
805 AliHLTMUONRecHitsBlockReader inblock(blocks[n].fPtr, blocks[n].fSize);
806 if (not BlockStructureOk(inblock))
808 if (DumpDataOnError()) DumpEvent(evtData, blocks, trigData, outputPtr, size, outputBlocks);
812 if (inblock.Nentries() != 0)
813 AddRecHits(blocks[n].fSpecification, inblock.GetArray(), inblock.Nentries());
816 Logging(kHLTLogDebug,
817 "AliHLTMUONMansoTrackerFSMComponent::DoEvent",
819 "Received a reconstructed hits data block which contains no entries."
823 else if (blocks[n].fDataType != AliHLTMUONConstants::TriggerRecordsBlockDataType())
825 // Log a message indicating that we got a data block that we
826 // do not know how to handle.
827 if (fWarnForUnexpecedBlock)
828 HLTWarning("Received a data block of a type we cannot handle: '%s', spec: 0x%X",
829 DataType2Text(blocks[n].fDataType).c_str(), blocks[n].fSpecification
833 HLTDebug("Received a data block of a type we cannot handle: '%s', spec: 0x%X",
834 DataType2Text(blocks[n].fDataType).c_str(), blocks[n].fSpecification
840 // Again loop over all input blocks in the event, but this time look for
841 // the trigger record blocks and process these.
842 for (AliHLTUInt32_t n = 0; n < evtData.fBlockCnt; n++)
844 if (blocks[n].fDataType != AliHLTMUONConstants::TriggerRecordsBlockDataType())
847 AliHLTMUONTriggerRecordsBlockReader inblock(blocks[n].fPtr, blocks[n].fSize);
848 if (not BlockStructureOk(inblock))
850 if (DumpDataOnError()) DumpEvent(evtData, blocks, trigData, outputPtr, size, outputBlocks);
854 DebugTrace("Processing a trigger block with "
855 << inblock.Nentries() << " entries."
858 specification |= blocks[n].fSpecification;
860 for (AliHLTUInt32_t i = 0; i < inblock.Nentries(); i++)
862 fTracker->FindTrack(inblock[i]);
864 // Reset the tracker so that we do not double count tracks.
869 AliHLTComponentBlockData bd;
873 bd.fSize = block.BytesUsed();
874 bd.fDataType = AliHLTMUONConstants::MansoTracksBlockDataType();
875 bd.fSpecification = specification;
876 outputBlocks.push_back(bd);
877 AliHLTUInt32_t totalSize = block.BytesUsed();
879 if (fTracker->MakeCandidates())
881 AliHLTMUONMansoCandidatesBlockWriter candidatesBlock(outputPtr+totalSize, size-totalSize);
882 if (not candidatesBlock.InitCommonHeader())
884 HLTError("Buffer overflowed. There are only %d bytes left in the buffer,"
885 " but we need a minimum of %d bytes.",
886 size, sizeof(AliHLTMUONMansoCandidatesBlockWriter::HeaderType)
888 if (DumpDataOnError()) DumpEvent(evtData, blocks, trigData, outputPtr, size, outputBlocks);
889 size = 0; // Important to tell framework that nothing was generated.
893 // Fill in the output block buffer.
894 candidatesBlock.SetNumberOfEntries(fTracker->TrackCandidatesCount());
895 for (AliHLTUInt32_t i = 0; i < fTracker->TrackCandidatesCount(); ++i)
897 candidatesBlock[i] = fTracker->TrackCandidates()[i];
900 fTracker->ZeroTrackCandidatesList();
902 AliHLTComponentBlockData bdc;
904 bdc.fPtr = outputPtr;
905 bdc.fOffset = totalSize;
906 bdc.fSize = candidatesBlock.BytesUsed();
907 bdc.fDataType = AliHLTMUONConstants::MansoCandidatesBlockDataType();
908 bdc.fSpecification = specification;
909 outputBlocks.push_back(bdc);
910 totalSize += candidatesBlock.BytesUsed();
918 void AliHLTMUONMansoTrackerFSMComponent::Reset()
921 /// Reset the track count and reconstructed hit data block arrays.
924 DebugTrace("Resetting AliHLTMUONMansoTrackerFSMComponent.");
926 //fTracker->Reset(); // Not necessary here because it is done after every FindTrack call.
928 fBlock = NULL; // Do not delete. Already done implicitly at the end of DoEvent.
929 for (int i = 0; i < 4; i++)
931 fRecHitBlockCount[i] = 0;
936 void AliHLTMUONMansoTrackerFSMComponent::FreeMemory()
938 /// Deletes any objects and arrays allocated by this component and releases
939 /// the memory used. This is called as a helper routine by the init and deinit
940 /// methods. If some or all of the object pointers are already NULL then
941 /// nothing is done for those. This method guarantees that all the relevant
942 /// pointers will be NULL after returning from this method.
944 if (fTracker != NULL)
950 // Remember that only fRecHitBlock[0] stores the pointer to the allocated memory.
951 // The other pointers are just reletive to this.
952 if (fRecHitBlock[0] != NULL)
953 delete [] fRecHitBlock[0];
955 fRecHitBlockArraySize = 0;
956 for (Int_t i = 0; i < 4; i++)
958 fRecHitBlockCount[i] = 0;
959 fRecHitBlock[i] = NULL;
964 void AliHLTMUONMansoTrackerFSMComponent::AddRecHits(
965 AliHLTUInt32_t specification,
966 const AliHLTMUONRecHitStruct* recHits,
971 /// Adds a new reconstructed hit data block to the internal list of blocks
972 /// for the tracker to process.
973 /// These lists will later be used when the tracker requests them through
974 /// the callback method 'RequestClusters'.
977 DebugTrace("AliHLTMUONMansoTrackerFSMComponent::AddRecHits called with specification = 0x"
978 << std::hex << specification << std::dec << " and count = "
979 << count << " rec hits."
982 AliHLTUInt8_t chamberMap[20] = {
983 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9, 10, 10
986 // Identify the chamber the rec hits came from using the specifications field.
987 bool gotDataFromDDL[22];
988 AliHLTMUONUtils::UnpackSpecBits(specification, gotDataFromDDL);
990 AliHLTInt8_t chamber = -1;
991 for (int i = 0; i < 20; i++)
993 if (not gotDataFromDDL[i]) continue;
994 if (7 <= chamberMap[i] and chamberMap[i] <= 10)
996 if (chamber != -1 and chamber != chamberMap[i])
998 Logging(kHLTLogError,
999 "AliHLTMUONMansoTrackerFSMComponent::AddRecHits",
1001 "Received a data block with data from multiple chambers."
1002 " This component cannot handle such a case."
1007 chamber = chamberMap[i];
1011 Logging(kHLTLogError,
1012 "AliHLTMUONMansoTrackerFSMComponent::AddRecHits",
1014 "Received a data block with data from chamber %d"
1015 " which is outside the expected range: [7..10].",
1022 // Make sure we got one chamber number.
1023 if (chamber < 7 or 10 < chamber)
1025 Logging(kHLTLogError,
1026 "AliHLTMUONMansoTrackerFSMComponent::AddRecHits",
1028 "Received a reconstructed hit data block with a null specification."
1029 " Cannot know which chamber the data comes from."
1034 DebugTrace("Added " << count << " reconstructed hits from chamber "
1035 << (int)chamber << " to the internal arrays."
1038 assert( fRecHitBlockCount[chamber-7] < fRecHitBlockArraySize );
1039 AliRecHitBlockInfo info(count, recHits);
1040 fRecHitBlock[chamber-7][fRecHitBlockCount[chamber-7]] = info;
1041 fRecHitBlockCount[chamber-7]++;
1045 void AliHLTMUONMansoTrackerFSMComponent::ResetCanLoadFlags()
1047 /// Resets all the fCanLoad* flags to true. This enables loading of all
1048 /// those CDB entries in the method ReadConfigFromCDB.
1050 fCanLoadZmiddle = true;
1052 for (int i = 0; i < 4; i++)
1054 fCanLoadA[i] = true;
1055 fCanLoadB[i] = true;
1057 for (int i = 0; i < 6; i++)
1059 fCanLoadZ[i] = true;
1064 bool AliHLTMUONMansoTrackerFSMComponent::AtLeastOneCanLoadFlagsIsSet() const
1066 /// Returns true if at least one fCanLoad* flag was true and false otherwise.
1068 if (fCanLoadZmiddle or fCanLoadBL) return true;
1069 for (int i = 0; i < 4; i++)
1071 if (fCanLoadA[i]) return true;
1072 if (fCanLoadB[i]) return true;
1074 for (int i = 0; i < 6; i++)
1076 if (fCanLoadZ[i]) return true;
1082 void AliHLTMUONMansoTrackerFSMComponent::RequestClusters(
1083 AliHLTMUONMansoTrackerFSM* tracker,
1084 AliHLTFloat32_t left, AliHLTFloat32_t right,
1085 AliHLTFloat32_t bottom, AliHLTFloat32_t top,
1086 AliHLTMUONChamberName chamber, const void* tag
1090 /// Inherited from AliHLTMUONMansoTrackerFSMCallback.
1091 /// This is the call back method used by the tracker algorithm to request
1092 /// clusters on a certain chamber.
1095 DebugTrace("AliHLTMUONMansoTracker::RequestClusters(chamber = " << chamber << ")");
1096 void* ctag = const_cast<void*>(tag);
1098 AliHLTUInt32_t recHitsCount = 0;
1099 AliRecHitBlockInfo* recHitsBlock = NULL;
1103 recHitsCount = fRecHitBlockCount[0];
1104 recHitsBlock = fRecHitBlock[0];
1109 recHitsCount = fRecHitBlockCount[1];
1110 recHitsBlock = fRecHitBlock[1];
1115 recHitsCount = fRecHitBlockCount[2];
1116 recHitsBlock = fRecHitBlock[2];
1121 recHitsCount = fRecHitBlockCount[3];
1122 recHitsBlock = fRecHitBlock[3];
1129 DebugTrace("Returning requested hits for chamber " << chNo << ":");
1130 for (AliHLTUInt32_t i = 0; i < recHitsCount; i++)
1131 for (AliHLTUInt32_t j = 0; j < recHitsBlock[i].Count(); j++)
1133 const AliHLTMUONRecHitStruct* hit = &(recHitsBlock[i].Data()[j]);
1134 if (left < hit->fX and hit->fX < right and bottom < hit->fY and hit->fY < top)
1135 tracker->ReturnClusters(ctag, hit, 1);
1137 DebugTrace("Done returning hits from chamber " << chNo << ".");
1138 tracker->EndOfClusters(ctag);
1142 void AliHLTMUONMansoTrackerFSMComponent::EndOfClusterRequests(
1143 AliHLTMUONMansoTrackerFSM* /*tracker*/
1147 /// Inherited from AliHLTMUONMansoTrackerFSMCallback.
1148 /// Nothing special to do here.
1151 DebugTrace("End of cluster requests.");
1155 void AliHLTMUONMansoTrackerFSMComponent::FoundTrack(AliHLTMUONMansoTrackerFSM* tracker)
1158 /// Inherited from AliHLTMUONMansoTrackerFSMCallback.
1159 /// This is the call back method used by the tracker algorithm to declare
1160 /// that a new track has been found.
1163 DebugTrace("AliHLTMUONMansoTrackerFSMComponent::FoundTrack()");
1165 AliHLTMUONMansoTracksBlockWriter* block =
1166 reinterpret_cast<AliHLTMUONMansoTracksBlockWriter*>(fBlock);
1168 AliHLTMUONMansoTrackStruct newTrack;
1169 tracker->FillTrackData(newTrack);
1171 // The indicies of the duplicate tracks. If set to block->Nentries() then
1172 // this indicates the index is not used.
1173 AliHLTUInt32_t dup1 = block->Nentries();
1174 AliHLTUInt32_t dup2 = block->Nentries();
1176 // Check if there are any tracks that use the same hits as the one found.
1177 // If there are, then use the one that has the highest pT.
1178 // There will be at most 2 duplicate tracks.
1179 for (AliHLTUInt32_t i = 0; i < block->Nentries(); i++)
1181 AliHLTMUONMansoTrackStruct& track = (*block)[i];
1182 bool hasNoDuplicates = true;
1183 for (AliHLTUInt32_t j = 0; j < 4; j++)
1185 if (track.fHit[j] == AliHLTMUONConstants::NilRecHitStruct()) continue;
1186 if (newTrack.fHit[j] == AliHLTMUONConstants::NilRecHitStruct()) continue;
1187 if (track.fHit[j] == newTrack.fHit[j])
1189 hasNoDuplicates = false;
1193 if (hasNoDuplicates) continue;
1195 if (dup1 == block->Nentries())
1199 else if (dup2 == block->Nentries())
1205 HLTError("Found more than 2 tracks with duplicate hits. This is completely unexpected. Something is seriously wrong!");
1209 if (dup1 != block->Nentries() and dup2 != block->Nentries())
1211 // In this case we found 2 duplicate entries.
1212 // Figure out which one has the highest pT and keep only that one.
1213 AliHLTMUONMansoTrackStruct& track1 = (*block)[dup1];
1214 AliHLTMUONMansoTrackStruct& track2 = (*block)[dup2];
1215 double newPt = sqrt(newTrack.fPx * newTrack.fPx + newTrack.fPy * newTrack.fPy);
1216 double dupPt1 = sqrt(track1.fPx * track1.fPx + track1.fPy * track1.fPy);
1217 double dupPt2 = sqrt(track2.fPx * track2.fPx + track2.fPy * track2.fPy);
1219 if (newPt >= dupPt1 and newPt >= dupPt2)
1221 // The new track must replace both existing tracks.
1223 track2 = (*block)[block->Nentries()-1];
1225 else if (dupPt1 >= newPt and dupPt1 >= dupPt2)
1227 // track1 has the highest pT so ignore the new track and delete track2.
1228 track2 = (*block)[block->Nentries()-1];
1232 // In this case track2 must have the highest pT so ignore the new
1233 // track and delete track1.
1234 track1 = (*block)[block->Nentries()-1];
1237 // Decrement the number of entries because we deleted a track.
1238 assert(fTrackCount > 0);
1239 assert(block->Nentries() > 0);
1240 block->SetNumberOfEntries(block->Nentries()-1);
1243 else if (dup1 != block->Nentries())
1245 // Only one track with duplicate hits found.
1246 // See if the new track has higher pT. If it does then replace the
1247 // exisiting track, otherwise ignore the new track.
1248 AliHLTMUONMansoTrackStruct& track1 = (*block)[dup1];
1249 double newPt = sqrt(newTrack.fPx * newTrack.fPx + newTrack.fPy * newTrack.fPy);
1250 double dupPt1 = sqrt(track1.fPx * track1.fPx + track1.fPy * track1.fPy);
1251 if (newPt >= dupPt1)
1258 // No track found with duplicate hits so we can add the new track as it is.
1259 AliHLTMUONMansoTrackStruct* track = block->AddEntry();
1262 Logging(kHLTLogError,
1263 "AliHLTMUONMansoTrackerFSMComponent::FoundTrack",
1265 "We have overflowed the output buffer for Manso track data."
1266 " The output buffer size is only %d bytes.",
1274 DebugTrace("\tAdded new track: " << *track);
1279 void AliHLTMUONMansoTrackerFSMComponent::NoTrackFound(AliHLTMUONMansoTrackerFSM* /*tracker*/)
1282 /// Inherited from AliHLTMUONMansoTrackerFSMCallback.
1283 /// Nothing special to do here.
1286 DebugTrace("No track found.");