1 /**************************************************************************
2 * This file is property of and copyright by the ALICE HLT Project *
3 * All rights reserved. *
6 * Artur Szostak <artursz@iafrica.com> *
8 * Permission to use, copy, modify and distribute this software and its *
9 * documentation strictly for non-commercial purposes is hereby granted *
10 * without fee, provided that the above copyright notice appears in all *
11 * copies and that both the copyright notice and this permission notice *
12 * appear in the supporting documentation. The authors make no claims *
13 * about the suitability of this software for any purpose. It is *
14 * provided "as is" without express or implied warranty. *
15 **************************************************************************/
20 /// @file AliHLTMUONRootifierComponent.cxx
21 /// @author Artur Szostak <artursz@iafrica.com>
23 /// @brief Implementation of the AliHLTMUONRootifierComponent component.
25 /// Implements a component to convert dHLT raw data into TObjects.
27 #include "AliHLTMUONRootifierComponent.h"
28 #include "AliHLTMUONEvent.h"
29 #include "AliHLTMUONConstants.h"
30 #include "AliHLTMUONUtils.h"
31 #include "AliHLTMUONRecHit.h"
32 #include "AliHLTMUONTriggerRecord.h"
33 #include "AliHLTMUONMansoTrack.h"
34 #include "AliHLTMUONDecision.h"
35 #include "TClonesArray.h"
38 ClassImp(AliHLTMUONRootifierComponent);
41 AliHLTMUONRootifierComponent::AliHLTMUONRootifierComponent() :
42 AliHLTMUONProcessor(),
43 fWarnForUnexpecedBlock(false)
46 /// Default constructor.
51 AliHLTMUONRootifierComponent::~AliHLTMUONRootifierComponent()
54 /// Default destructor.
59 bool AliHLTMUONRootifierComponent::IgnoreArgument(const char* arg) const
61 /// Return true if the argument is one of -cdbpath -run or -delaysetup
62 /// to prevent the parent class from parsing these arguments in DoInit.
64 if (strcmp(arg, "-cdbpath") == 0 or strcmp(arg, "-run") == 0 or
65 strcmp(arg, "-delaysetup") == 0)
76 int AliHLTMUONRootifierComponent::DoInit(int argc, const char** argv)
79 /// Inherited from AliHLTComponent.
80 /// Parses the command line parameters and initialises the component.
83 HLTInfo("Initialising dHLT rootifier component.");
85 // Inherit the parents functionality.
86 int result = AliHLTMUONProcessor::DoInit(argc, argv);
87 if (result != 0) return result;
89 fWarnForUnexpecedBlock = false;
91 for (int i = 0; i < argc; i++)
93 if (ArgumentAlreadyHandled(i, argv[i])) continue;
95 if (strcmp(argv[i], "-warn_on_unexpected_block") == 0)
97 fWarnForUnexpecedBlock = true;
101 HLTError("Unknown option '%s'.", argv[i]);
109 int AliHLTMUONRootifierComponent::DoDeinit()
112 /// Inherited from AliHLTComponent. Performs a cleanup of the component.
115 HLTInfo("Deinitialising dHLT rootifier component.");
120 const char* AliHLTMUONRootifierComponent::GetComponentID()
123 /// Inherited from AliHLTComponent. Returns the component ID.
126 return AliHLTMUONConstants::RootifierComponentId();
130 AliHLTComponentDataType AliHLTMUONRootifierComponent::GetOutputDataType()
132 /// Inherited from AliHLTComponent. Returns kAliHLTMultipleDataType
133 /// refer to GetOutputDataTypes for all returned data types.
135 return kAliHLTMultipleDataType;
139 int AliHLTMUONRootifierComponent::GetOutputDataTypes(AliHLTComponentDataTypeList& tgtList)
141 /// Inherited from AliHLTComponent. Returns the output data types.
143 tgtList.push_back(AliHLTMUONConstants::RootifiedEventDataType());
144 return tgtList.size();
148 void AliHLTMUONRootifierComponent::GetInputDataTypes(AliHLTComponentDataTypeList& list)
151 /// Inherited from AliHLTProcessor. Returns the list of expected input data types.
154 list.push_back(kAliHLTAnyDataType);
158 void AliHLTMUONRootifierComponent::GetOutputDataSize(
159 unsigned long& constBase, double& inputMultiplier
163 /// Inherited from AliHLTComponent. Returns an estimate of the expected output data size.
166 constBase = 1024*1024;
167 inputMultiplier = 100;
171 AliHLTComponent* AliHLTMUONRootifierComponent::Spawn()
174 /// Inherited from AliHLTComponent. Creates a new object instance.
177 return new AliHLTMUONRootifierComponent();
181 int AliHLTMUONRootifierComponent::DoEvent(
182 const AliHLTComponentEventData& evtData,
183 AliHLTComponentTriggerData& trigData
187 /// Inherited from AliHLTProcessor. Processes the new event data.
190 if (not IsDataEvent()) return 0;
192 AliHLTMUONEvent event(evtData.fEventID);
193 const AliHLTComponentBlockData* block = NULL;
194 AliHLTUInt32_t specification = 0; // Contains the output data block spec bits.
196 // First process the blocks of reconstructed hits and trigger records.
197 for (int i = 0; i < GetNumberOfInputBlocks(); i++)
199 block = GetInputBlock(i);
200 assert( block != NULL );
202 HLTDebug("Handling block: %u, with fDataType = '%s', fPtr = %p and fSize = %u bytes.",
203 i, DataType2Text(block->fDataType).c_str(), block->fPtr, block->fSize
206 if (block->fDataType == AliHLTMUONConstants::RecHitsBlockDataType())
208 specification |= block->fSpecification;
209 AliHLTMUONRecHitsBlockReader inblock(block->fPtr, block->fSize);
210 if (not BlockStructureOk(inblock))
212 if (DumpDataOnError()) DumpEvent(evtData, trigData);
216 // Decode the source DDL from the specification bits.
217 Int_t sourceDDL = -1;
219 AliHLTMUONUtils::UnpackSpecBits(block->fSpecification, ddl);
220 for (int k = 0; k < 22; k++)
230 HLTWarning("The input data block %d contains"
231 " data from multiple DDL sources.", i
238 HLTWarning("The source DDL for input data block %d is %d."
239 " The expected range for the DDL is [1..20].",
244 for (AliHLTUInt32_t n = 0; n < inblock.Nentries(); n++)
246 const AliHLTMUONRecHitStruct& h = inblock[n];
247 AliHLTUInt8_t chamber;
248 AliHLTUInt16_t detElemId;
249 AliHLTMUONUtils::UnpackRecHitFlags(h.fFlags, chamber, detElemId);
250 event.Add(new AliHLTMUONRecHit(h.fX, h.fY, h.fZ, sourceDDL, detElemId));
253 else if (block->fDataType == AliHLTMUONConstants::TriggerRecordsBlockDataType())
255 specification |= block->fSpecification;
256 AliHLTMUONTriggerRecordsBlockReader inblock(block->fPtr, block->fSize);
257 if (not BlockStructureOk(inblock))
259 if (DumpDataOnError()) DumpEvent(evtData, trigData);
263 // Decode the source DDL from the specification bits.
264 Int_t sourceDDL = -1;
266 AliHLTMUONUtils::UnpackSpecBits(block->fSpecification, ddl);
267 for (int k = 0; k < 22; k++)
277 HLTWarning("The input data block %d contains"
278 " data from multiple DDL sources.", i
283 if (sourceDDL != -1 and (sourceDDL < 21 or sourceDDL > 22))
285 HLTWarning("The source DDL for input data block %d is %d."
286 " The expected range for the DDL is [21..22].",
291 for (AliHLTUInt32_t n = 0; n < inblock.Nentries(); n++)
293 const AliHLTMUONTriggerRecordStruct& t = inblock[n];
295 AliHLTMUONParticleSign sign;
297 AliHLTMUONUtils::UnpackTriggerRecordFlags(
298 t.fFlags, sign, hitset
301 AliHLTMUONTriggerRecord* tr = new AliHLTMUONTriggerRecord(
302 t.fId, sign, t.fPx, t.fPy, t.fPz, sourceDDL
304 for (int k = 0; k < 4; k++)
305 tr->SetHit(k+11, t.fHit[k].fX, t.fHit[k].fY, t.fHit[k].fZ);
311 if (block->fDataType != AliHLTMUONConstants::MansoTracksBlockDataType() and
312 block->fDataType != AliHLTMUONConstants::SinglesDecisionBlockDataType() and
313 block->fDataType != AliHLTMUONConstants::PairsDecisionBlockDataType()
316 // Log a message indicating that we got a data block that we
317 // do not know how to handle.
318 if (fWarnForUnexpecedBlock)
319 HLTWarning("Received a data block of a type we cannot handle: '%s', spec: 0x%X",
320 DataType2Text(block->fDataType).c_str(), block->fSpecification
324 HLTDebug("Received a data block of a type we cannot handle: '%s', spec: 0x%X",
325 DataType2Text(block->fDataType).c_str(), block->fSpecification
332 // We need to check if there are any cluster data blocks and add their
333 // information to the AliHLTMUONRecHit objects.
334 for (block = GetFirstInputBlock(AliHLTMUONConstants::ClusterBlockDataType());
336 block = GetNextInputBlock()
339 specification |= block->fSpecification;
340 AliHLTMUONClustersBlockReader inblock(block->fPtr, block->fSize);
341 if (not BlockStructureOk(inblock))
343 if (DumpDataOnError()) DumpEvent(evtData, trigData);
347 for (AliHLTUInt32_t n = 0; n < inblock.Nentries(); n++)
349 const AliHLTMUONClusterStruct& clust = inblock[n];
351 AliHLTUInt8_t chamber;
352 AliHLTUInt16_t detElemId;
353 AliHLTMUONUtils::UnpackRecHitFlags(clust.fHit.fFlags, chamber, detElemId);
354 if (clust.fDetElemId != detElemId)
356 HLTWarning("Found a cluster with a different detector element ID (%d)"
357 " from its corresponding hit (x,y,z = %f,%f,%f and detElemId = %d).",
359 clust.fHit.fX, clust.fHit.fY, clust.fHit.fZ,
364 // Try find the corresponding reconstructed hit in 'event'.
365 AliHLTMUONRecHit* hit = NULL;
366 for (Int_t k = 0; k < event.Array().GetEntriesFast(); k++)
368 if (event.Array()[k]->IsA() != AliHLTMUONRecHit::Class())
370 AliHLTMUONRecHit* h = static_cast<AliHLTMUONRecHit*>(event.Array()[k]);
371 if (h->DetElemId() == detElemId and h->X() == clust.fHit.fX
372 and h->Y() == clust.fHit.fY and h->Z() == clust.fHit.fZ)
379 // If we could not find the corresponding hit then we need to create
380 // a new hit object, otherwise we can just append the information.
383 // Decode the source DDL from the specification bits.
384 Int_t sourceDDL = -1;
386 AliHLTMUONUtils::UnpackSpecBits(block->fSpecification, ddl);
387 for (int k = 0; k < 22; k++)
397 HLTWarning("An input block of cluster data contains"
398 " data from multiple DDL sources."
405 HLTWarning("The source DDL of a cluster data input block is %d."
406 " The expected range for the DDL is [1..20].",
410 event.Add(new AliHLTMUONRecHit(
411 clust.fHit.fX, clust.fHit.fY, clust.fHit.fZ,
418 detElemId, clust.fId,
419 clust.fNchannelsB, clust.fNchannelsNB,
420 clust.fChargeB, clust.fChargeNB,
427 // Now we can look for tracks to add. We needed the ROOT trigger records
428 // and reco hits created before we can create track objects.
429 for (block = GetFirstInputBlock(AliHLTMUONConstants::MansoTracksBlockDataType());
431 block = GetNextInputBlock()
434 specification |= block->fSpecification;
435 AliHLTMUONMansoTracksBlockReader inblock(block->fPtr, block->fSize);
436 if (not BlockStructureOk(inblock))
438 if (DumpDataOnError()) DumpEvent(evtData, trigData);
442 for (AliHLTUInt32_t n = 0; n < inblock.Nentries(); n++)
444 const AliHLTMUONMansoTrackStruct& t = inblock[n];
446 AliHLTMUONParticleSign sign;
448 AliHLTMUONUtils::UnpackMansoTrackFlags(
449 t.fFlags, sign, hitset
452 // Try find the trigger record in 'event'.
453 const AliHLTMUONTriggerRecord* trigrec = NULL;
454 for (Int_t k = 0; k < event.Array().GetEntriesFast(); k++)
456 if (event.Array()[k]->IsA() != AliHLTMUONTriggerRecord::Class())
458 const AliHLTMUONTriggerRecord* tk =
459 static_cast<const AliHLTMUONTriggerRecord*>(event.Array()[k]);
460 if (tk->Id() == t.fTrigRec)
467 // Now try find the hits in 'event'.
468 // If they cannot be found then create new ones.
469 const AliHLTMUONRecHit* hit7 = NULL;
470 const AliHLTMUONRecHit* hit8 = NULL;
471 const AliHLTMUONRecHit* hit9 = NULL;
472 const AliHLTMUONRecHit* hit10 = NULL;
473 for (Int_t k = 0; k < event.Array().GetEntriesFast(); k++)
475 if (event.Array()[k]->IsA() != AliHLTMUONRecHit::Class())
477 const AliHLTMUONRecHit* h =
478 static_cast<const AliHLTMUONRecHit*>(event.Array()[k]);
480 if (hitset[0] and h->X() == t.fHit[0].fX and h->Y() == t.fHit[0].fY
481 and h->Z() == t.fHit[0].fZ)
485 if (hitset[1] and h->X() == t.fHit[1].fX and h->Y() == t.fHit[1].fY
486 and h->Z() == t.fHit[1].fZ)
490 if (hitset[2] and h->X() == t.fHit[2].fX and h->Y() == t.fHit[2].fY
491 and h->Z() == t.fHit[2].fZ)
495 if (hitset[3] and h->X() == t.fHit[3].fX and h->Y() == t.fHit[3].fY
496 and h->Z() == t.fHit[3].fZ)
501 AliHLTMUONRecHit* newhit;
502 if (hitset[0] and hit7 == NULL)
504 newhit = new AliHLTMUONRecHit(t.fHit[0].fX, t.fHit[0].fY, t.fHit[0].fZ);
508 if (hitset[1] and hit8 == NULL)
510 newhit = new AliHLTMUONRecHit(t.fHit[1].fX, t.fHit[1].fY, t.fHit[1].fZ);
514 if (hitset[2] and hit9 == NULL)
516 newhit = new AliHLTMUONRecHit(t.fHit[2].fX, t.fHit[2].fY, t.fHit[2].fZ);
520 if (hitset[3] and hit10 == NULL)
522 newhit = new AliHLTMUONRecHit(t.fHit[3].fX, t.fHit[3].fY, t.fHit[3].fZ);
527 AliHLTMUONMansoTrack* tr = new AliHLTMUONMansoTrack(
528 t.fId, sign, t.fPx, t.fPy, t.fPz, t.fChi2,
529 trigrec, hit7, hit8, hit9, hit10
535 bool decisionBlockFound = false;
537 UInt_t numHighPt = 0;
538 TClonesArray singlesDecisions("AliHLTMUONDecision::AliTrackDecision");
540 // Find the single tracks decision blocks and add their information.
541 // We just sum the trigger scalars and single decisions.
542 for (block = GetFirstInputBlock(AliHLTMUONConstants::SinglesDecisionBlockDataType());
544 block = GetNextInputBlock()
547 decisionBlockFound = true;
548 specification |= block->fSpecification;
549 AliHLTMUONSinglesDecisionBlockReader inblock(block->fPtr, block->fSize);
550 if (not BlockStructureOk(inblock))
552 if (DumpDataOnError()) DumpEvent(evtData, trigData);
556 numLowPt += inblock.BlockHeader().fNlowPt;
557 numHighPt += inblock.BlockHeader().fNhighPt;
559 for (AliHLTUInt32_t n = 0; n < inblock.Nentries(); n++)
561 const AliHLTMUONTrackDecisionStruct& t = inblock[n];
564 AliHLTMUONUtils::UnpackTrackDecisionBits(t.fTriggerBits, highPt, lowPt);
566 // Try find the corresponding track in the 'event'.
567 const AliHLTMUONMansoTrack* track = NULL;
568 for (Int_t k = 0; k < event.Array().GetEntriesFast(); k++)
570 if (event.Array()[k]->IsA() != AliHLTMUONMansoTrack::Class())
572 const AliHLTMUONMansoTrack* tk =
573 static_cast<const AliHLTMUONMansoTrack*>(event.Array()[k]);
574 if (tk->Id() == t.fTrackId)
581 // If the track was not found then create a dummy one.
584 AliHLTMUONMansoTrack* tr = new AliHLTMUONMansoTrack(t.fTrackId);
589 new (singlesDecisions[singlesDecisions.GetEntriesFast()])
590 AliHLTMUONDecision::AliTrackDecision(t.fPt, lowPt, highPt, track);
594 UInt_t numUnlikeAnyPt = 0;
595 UInt_t numUnlikeLowPt = 0;
596 UInt_t numUnlikeHighPt = 0;
597 UInt_t numLikeAnyPt = 0;
598 UInt_t numLikeLowPt = 0;
599 UInt_t numLikeHighPt = 0;
600 UInt_t numAnyMass = 0;
601 UInt_t numLowMass = 0;
602 UInt_t numHighMass = 0;
603 TClonesArray pairsDecisions("AliHLTMUONDecision::AliPairDecision");
605 // Find the track pairs decision blocks and add their information.
606 // We just sum the trigger scalars and track pair decisions.
607 for (block = GetFirstInputBlock(AliHLTMUONConstants::PairsDecisionBlockDataType());
609 block = GetNextInputBlock()
612 decisionBlockFound = true;
613 specification |= block->fSpecification;
614 AliHLTMUONPairsDecisionBlockReader inblock(block->fPtr, block->fSize);
615 if (not BlockStructureOk(inblock))
617 if (DumpDataOnError()) DumpEvent(evtData, trigData);
621 numUnlikeAnyPt += inblock.BlockHeader().fNunlikeAnyPt;
622 numUnlikeLowPt += inblock.BlockHeader().fNunlikeLowPt;
623 numUnlikeHighPt += inblock.BlockHeader().fNunlikeHighPt;
624 numLikeAnyPt += inblock.BlockHeader().fNlikeAnyPt;
625 numLikeLowPt += inblock.BlockHeader().fNlikeLowPt;
626 numLikeHighPt += inblock.BlockHeader().fNlikeHighPt;
627 numAnyMass += inblock.BlockHeader().fNmassAny;
628 numLowMass += inblock.BlockHeader().fNmassLow;
629 numHighMass += inblock.BlockHeader().fNmassHigh;
631 for (AliHLTUInt32_t n = 0; n < inblock.Nentries(); n++)
633 const AliHLTMUONPairDecisionStruct& t = inblock[n];
635 bool highMass, lowMass, unlike;
636 AliHLTUInt8_t highPtCount, lowPtCount;
637 AliHLTMUONUtils::UnpackPairDecisionBits(
638 t.fTriggerBits, highMass, lowMass, unlike,
639 highPtCount, lowPtCount
642 // Try find the corresponding tracks in the 'event'.
643 const AliHLTMUONMansoTrack* trackA = NULL;
644 const AliHLTMUONMansoTrack* trackB = NULL;
645 for (Int_t k = 0; k < event.Array().GetEntriesFast(); k++)
647 if (event.Array()[k]->IsA() != AliHLTMUONMansoTrack::Class())
649 const AliHLTMUONMansoTrack* tk =
650 static_cast<const AliHLTMUONMansoTrack*>(event.Array()[k]);
651 if (tk->Id() == t.fTrackAId) trackA = tk;
652 if (tk->Id() == t.fTrackBId) trackB = tk;
653 if (trackA != NULL and trackB != NULL) break;
656 // If either of the tracks was not found then create a dummy one.
659 AliHLTMUONMansoTrack* tr = new AliHLTMUONMansoTrack(t.fTrackAId);
665 AliHLTMUONMansoTrack* tr = new AliHLTMUONMansoTrack(t.fTrackBId);
670 new (pairsDecisions[pairsDecisions.GetEntriesFast()])
671 AliHLTMUONDecision::AliPairDecision(
672 t.fInvMass, lowMass, highMass, unlike,
673 lowPtCount, highPtCount, trackA, trackB
679 // Do not add the decision if no decision blocks were found.
680 if (decisionBlockFound)
682 AliHLTMUONDecision* triggerDecision = new AliHLTMUONDecision(
683 numLowPt, numHighPt, numUnlikeAnyPt, numUnlikeLowPt,
684 numUnlikeHighPt, numLikeAnyPt, numLikeLowPt,
685 numLikeHighPt, numAnyMass, numLowMass, numHighMass
687 for (Int_t i = 0; i < singlesDecisions.GetEntriesFast(); i++)
689 AliHLTMUONDecision::AliTrackDecision* decision =
690 static_cast<AliHLTMUONDecision::AliTrackDecision*>( singlesDecisions[i] );
691 triggerDecision->AddDecision(decision);
693 for (Int_t j = 0; j < pairsDecisions.GetEntriesFast(); j++)
695 AliHLTMUONDecision::AliPairDecision* decision =
696 static_cast<AliHLTMUONDecision::AliPairDecision*>( pairsDecisions[j] );
697 triggerDecision->AddDecision(decision);
700 event.Add(triggerDecision);
703 PushBack(&event, AliHLTMUONConstants::RootifiedEventDataType(), specification);