2 /**************************************************************************
3 * This file is property of and copyright by the ALICE HLT Project *
4 * ALICE Experiment at CERN, All rights reserved. *
6 * Primary Authors: Artur Szostak <artursz@iafrica.com> *
7 * for The ALICE HLT Project. *
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 **************************************************************************/
18 /// @file AliHLTTriggerDomain.cxx
19 /// @author Artur Szostak <artursz@iafrica.com>
21 /// @brief Implementation of the AliHLTTriggerDomain class.
23 /// The trigger domain class is the set of HLT raw data block types that should
24 /// be readout and sent to HLTOUT.
28 #include "AliHLTTriggerDomain.h"
29 #include "AliHLTDomainEntry.h"
30 #include "AliHLTReadoutList.h"
31 #include "Riostream.h"
32 #include "TObjArray.h"
33 #include "TObjString.h"
34 #include "AliHLTDAQ.h"
36 ClassImp(AliHLTTriggerDomain)
39 AliHLTTriggerDomain::AliHLTTriggerDomain() :
40 TObject(), fEntries(AliHLTDomainEntry::Class(), 10)
42 // Default constructor.
46 AliHLTTriggerDomain::AliHLTTriggerDomain(const char* list) :
47 TObject(), fEntries(AliHLTDomainEntry::Class(), 10)
49 // Constructs the domain from a list of entries.
52 TObjArray* entries = lst.Tokenize(",");
53 for (Int_t i = 0; i < entries->GetEntriesFast(); i++)
55 TString entry = static_cast<TObjString*>(entries->UncheckedAt(i))->GetString();
56 TObjArray* domainStrings = entry.Tokenize(":");
57 if (domainStrings->GetEntriesFast() <= 0 or domainStrings->GetEntriesFast() > 3)
59 Error("AliHLTTriggerDomain",
60 "The domain string must contain 1, 2 or 3 fields separated by a ':'."
66 bool inclusiveEntry = true;
67 TString typeString = "*******";
68 if (domainStrings->GetEntriesFast() >= 1)
70 typeString = static_cast<TObjString*>(domainStrings->UncheckedAt(0))->GetString();
71 if (typeString.Length() > 0)
73 if (typeString[0] == '+')
75 inclusiveEntry = true;
76 typeString.Remove(0, 1);
78 if (typeString[0] == '-')
80 inclusiveEntry = false;
81 typeString.Remove(0, 1);
85 TString originString = "***";
86 if (domainStrings->GetEntriesFast() >= 2)
88 originString = static_cast<TObjString*>(domainStrings->UncheckedAt(1))->GetString();
92 if (domainStrings->GetEntriesFast() == 3)
94 TString specString = static_cast<TObjString*>(domainStrings->UncheckedAt(2))->GetString();
96 spec = UInt_t( strtoul(specString.Data(), &error, 0) );
97 if (error == NULL or *error != '\0')
99 Error("AliHLTTriggerDomain",
100 "The last field of the domain string must be a number, but we received '%s'.",
113 Add(typeString.Data(), originString.Data(), spec);
115 Remove(typeString.Data(), originString.Data(), spec);
120 Add(typeString.Data(), originString.Data());
122 Remove(typeString.Data(), originString.Data());
125 delete domainStrings;
131 AliHLTTriggerDomain::AliHLTTriggerDomain(const AliHLTReadoutList& list) :
132 TObject(), fEntries(AliHLTDomainEntry::Class(), 10)
134 // Constructor creates a trigger domain from a readout list.
135 // See header file for more details.
141 AliHLTTriggerDomain::AliHLTTriggerDomain(const AliHLTTriggerDomain& domain) :
143 fEntries(AliHLTDomainEntry::Class(), domain.fEntries.GetEntriesFast())
145 // Copy constructor performs a deep copy.
146 // See header file for more details.
148 for (Int_t i = 0; i < domain.fEntries.GetEntriesFast(); i++)
150 const AliHLTDomainEntry* entry = static_cast<const AliHLTDomainEntry*>( domain.fEntries.UncheckedAt(i) );
151 new (fEntries[fEntries.GetEntriesFast()]) AliHLTDomainEntry(*entry);
156 AliHLTTriggerDomain::~AliHLTTriggerDomain()
158 // Default destructor.
162 void AliHLTTriggerDomain::Add(const AliHLTReadoutList& list)
164 // Adds the readout list to the trigger domain.
165 // See header file for more details.
168 AliHLTReadoutList::kITSSPD, AliHLTReadoutList::kITSSDD, AliHLTReadoutList::kITSSSD,
169 AliHLTReadoutList::kTPC, AliHLTReadoutList::kTRD, AliHLTReadoutList::kTOF,
170 AliHLTReadoutList::kHMPID, AliHLTReadoutList::kPHOS, AliHLTReadoutList::kCPV,
171 AliHLTReadoutList::kPMD, AliHLTReadoutList::kMUONTRK, AliHLTReadoutList::kMUONTRG,
172 AliHLTReadoutList::kFMD, AliHLTReadoutList::kT0, AliHLTReadoutList::kV0,
173 AliHLTReadoutList::kZDC, AliHLTReadoutList::kACORDE, AliHLTReadoutList::kTRG,
174 AliHLTReadoutList::kEMCAL, AliHLTReadoutList::kDAQTEST, AliHLTReadoutList::kHLT
177 for (Int_t deti = 0; deti < (Int_t)AliHLTDAQ::NumberOfDetectors() && deti < (Int_t)(sizeof(detId)/sizeof(Int_t)); deti++)
179 if (list.DetectorEnabled(detId[deti]))
181 Add(kAliHLTDAQRDOUTDataTypeID, AliHLTDAQ::OnlineName(deti));
185 for (Int_t i = 0; i < AliHLTDAQ::NumberOfDdls(deti); i++)
187 Int_t ddlId = AliHLTDAQ::DdlID(deti, i);
188 if (list.IsDDLEnabled(ddlId)) Add(kAliHLTDAQRDOUTDataTypeID, AliHLTDAQ::OnlineName(deti), ddlId);
194 void AliHLTTriggerDomain::Add(const AliHLTDomainEntry& entry)
196 // Adds a new domain entry to the trigger domain.
197 // See header file for more details.
199 AliHLTDomainEntry intersect;
200 bool alreadyInSet = false;
202 // Get the initial size of the fEntries array since we might add things to the
203 // end during the calculation.
204 Int_t count = fEntries.GetEntriesFast();
206 // Go through each entry that is already in fEntries and see if we can remove
207 // it because it will become redundant, or if we need to patch exclusion entries
208 // by adding inclusive intersects, or if we do not even need to add the new entry
209 // because it is already part of the trigger domain.
210 for (Int_t i = 0; i < count; i++)
212 AliHLTDomainEntry* ientry = static_cast<AliHLTDomainEntry*>(fEntries.UncheckedAt(i));
213 if (ientry->Inclusive())
215 if (entry.SubsetOf(*ientry))
219 else if (ientry->SubsetOf(entry))
221 ientry->SetBit(BIT(14), true); // mark for removal.
226 if (ientry->SubsetOf(entry))
228 ientry->SetBit(BIT(14), true); // mark for removal.
230 else if (entry.SubsetOf(*ientry))
232 alreadyInSet = false;
234 else if (ientry->IntersectWith(entry, intersect))
236 MarkForDeletionSubsetsOf(intersect, count);
237 new (fEntries[fEntries.GetEntriesFast()]) AliHLTDomainEntry(kFALSE, intersect);
242 // Check if we need to add the new entry.
243 if (not alreadyInSet)
245 MarkForDeletionSubsetsOf(entry, count);
246 new (fEntries[fEntries.GetEntriesFast()]) AliHLTDomainEntry(kFALSE, entry);
248 RemoveMarkedEntries();
252 void AliHLTTriggerDomain::Add(const AliHLTComponentDataType& datatype)
254 // Adds a new domain entry with the given data type to the trigger domain.
255 // But the data block specification is set to the any matching wild card.
256 // See header file for more details.
258 Add(AliHLTDomainEntry(datatype));
262 void AliHLTTriggerDomain::Add(const char* blocktype, const char* origin)
264 // Adds a new domain entry with the given data type and origin to the trigger domain.
265 // But the data block specification is set to the any matching wild card.
266 // See header file for more details.
268 Add(AliHLTDomainEntry(blocktype, origin));
272 void AliHLTTriggerDomain::Add(const AliHLTComponentDataType& datatype, UInt_t spec)
274 // Adds a new domain entry to the trigger domain with the data type and data block
275 // specification bits.
276 // See header file for more details.
278 Add(AliHLTDomainEntry(datatype, spec));
282 void AliHLTTriggerDomain::Add(const char* blocktype, const char* origin, UInt_t spec)
284 // Adds a new domain entry to the trigger domain with the given data type, origin
285 // and data block specification bits.
286 // See header file for more details.
288 Add(AliHLTDomainEntry(blocktype, origin, spec));
292 void AliHLTTriggerDomain::Remove(const AliHLTReadoutList& list)
294 // Removes the entries in the readout list from the trigger domain that are enabled.
295 // See header file for more details.
298 AliHLTReadoutList::kITSSPD, AliHLTReadoutList::kITSSDD, AliHLTReadoutList::kITSSSD,
299 AliHLTReadoutList::kTPC, AliHLTReadoutList::kTRD, AliHLTReadoutList::kTOF,
300 AliHLTReadoutList::kHMPID, AliHLTReadoutList::kPHOS, AliHLTReadoutList::kCPV,
301 AliHLTReadoutList::kPMD, AliHLTReadoutList::kMUONTRK, AliHLTReadoutList::kMUONTRG,
302 AliHLTReadoutList::kFMD, AliHLTReadoutList::kT0, AliHLTReadoutList::kV0,
303 AliHLTReadoutList::kZDC, AliHLTReadoutList::kACORDE, AliHLTReadoutList::kTRG,
304 AliHLTReadoutList::kEMCAL, AliHLTReadoutList::kDAQTEST, AliHLTReadoutList::kHLT
307 for (Int_t deti = 0; deti < (Int_t)AliHLTDAQ::NumberOfDetectors() && deti < (Int_t)(sizeof(detId)/sizeof(Int_t)); deti++)
309 if (list.DetectorEnabled(detId[deti]))
311 Remove(kAliHLTDAQRDOUTDataTypeID, AliHLTDAQ::OnlineName(deti));
315 for (Int_t i = 0; i < AliHLTDAQ::NumberOfDdls(deti); i++)
317 Int_t ddlId = AliHLTDAQ::DdlID(deti, i);
318 if (list.IsDDLEnabled(ddlId)) Remove(kAliHLTDAQRDOUTDataTypeID, AliHLTDAQ::OnlineName(deti), ddlId);
325 void AliHLTTriggerDomain::Remove(const AliHLTDomainEntry& entry)
327 // Removes the given domain entry from the trigger domain.
328 // See header file for more details.
330 AliHLTDomainEntry intersect;
331 bool addToExcludeSet = false;
333 // Get the initial size of the fEntries array since we might add things to the
334 // end during the calculation.
335 Int_t count = fEntries.GetEntriesFast();
337 // We need to go through all existing entries and see if they need to be removed
338 // because they would become redundant when we add the new 'entry' to the end of
339 // the fEntries list. We also need to check if the new entry needs to be added
340 // at all because the trigger domain might already not contain those entries.
341 // Lastly, some intersection entries might need to be added to patch up existing
342 // inclusive trigger domain entries (rules / patterns).
343 for (Int_t i = 0; i < count; i++)
345 AliHLTDomainEntry* ientry = static_cast<AliHLTDomainEntry*>(fEntries.UncheckedAt(i));
346 if (ientry->Inclusive())
348 if (ientry->SubsetOf(entry))
350 ientry->SetBit(BIT(14), true); // mark for removal.
352 else if (entry.SubsetOf(*ientry))
354 addToExcludeSet = true;
356 else if (ientry->IntersectWith(entry, intersect))
358 new (fEntries[fEntries.GetEntriesFast()]) AliHLTDomainEntry(kTRUE, intersect);
363 if (entry.SubsetOf(*ientry))
365 addToExcludeSet = false;
367 else if (ientry->SubsetOf(entry))
369 ientry->SetBit(BIT(14), true); // mark for removal.
374 // Check if we need to add the new entry.
377 MarkForDeletionSubsetsOf(entry, count);
378 new (fEntries[fEntries.GetEntriesFast()]) AliHLTDomainEntry(kTRUE, entry);
380 RemoveMarkedEntries();
384 void AliHLTTriggerDomain::Remove(const AliHLTComponentDataType& datatype)
386 // Removes the domain entries that have the given data type from the trigger domain.
387 // See header file for more details.
389 Remove(AliHLTDomainEntry(datatype));
393 void AliHLTTriggerDomain::Remove(const char* blocktype, const char* origin)
395 // Removes the domain entries that have the given data type and origin from the
397 // See header file for more details.
399 Remove(AliHLTDomainEntry(blocktype, origin));
403 void AliHLTTriggerDomain::Remove(const AliHLTComponentDataType& datatype, UInt_t spec)
405 // Removes the domain entries that have the given data type and data block
406 // specification bits from the trigger domain.
407 // See header file for more details.
409 Remove(AliHLTDomainEntry(datatype, spec));
413 void AliHLTTriggerDomain::Remove(const char* blocktype, const char* origin, UInt_t spec)
415 // Removes the domain entries that have the given data type, origin and data
416 // block specification bits from the trigger domain.
417 // See header file for more details.
419 Remove(AliHLTDomainEntry(blocktype, origin, spec));
423 bool AliHLTTriggerDomain::Contains(const AliHLTDomainEntry& entry) const
425 // Checks to see if the given domain entry is part of the trigger domain set.
426 // See header file for more details.
428 // Simply go through the whole list of fEntries and for each entry see if the
429 // given domain entry 'entry' being checked matches. If there is a match then
430 // update the result depending on the entry type. i.e. set to false if the entry
431 // in fEntries is an exclusion and set to true if it is an inclusion.
433 for (Int_t i = 0; i < fEntries.GetEntriesFast(); i++)
435 const AliHLTDomainEntry* ientry = static_cast<const AliHLTDomainEntry*>(fEntries.UncheckedAt(i));
436 if (ientry->Inclusive())
438 if (*ientry == entry) result = true;
442 if (entry.SubsetOf(*ientry)) result = false;
449 bool AliHLTTriggerDomain::IncludeInReadout(const AliHLTComponentBlockData* block) const
451 // Checks to see if the given data block is part of the trigger domain set and
452 // should be readout.
453 // See header file for more details.
455 // Same algorithm as for Contains() but applied directly to the data block
456 // descriptor structure.
457 AliHLTDomainEntry blockEntry(block->fDataType, block->fSpecification);
459 for (Int_t i = 0; i < fEntries.GetEntriesFast(); i++)
461 const AliHLTDomainEntry* entry = static_cast<const AliHLTDomainEntry*>(fEntries.UncheckedAt(i));
462 if (entry->Inclusive())
464 if (*entry == block) result = true;
468 if (blockEntry.SubsetOf(*entry)) result = false;
475 void AliHLTTriggerDomain::Clear(Option_t* option)
477 // Clears the trigger domain (Removes all entries).
479 fEntries.Clear(option);
483 void AliHLTTriggerDomain::Print(Option_t* /*option*/) const
485 // Prints the trigger domain entries in the order that they are applied.
486 // See header file for more details.
488 cout << "Trigger domain rules (applied in order of first to last):" << endl;
489 for (Int_t i = 0; i < fEntries.GetEntriesFast(); i++)
491 const AliHLTDomainEntry* entry = static_cast<const AliHLTDomainEntry*>( fEntries.UncheckedAt(i) );
492 if (entry->Inclusive())
502 if (fEntries.GetEntriesFast() == 0)
504 cout << "(empty)" << endl;
509 AliHLTTriggerDomain& AliHLTTriggerDomain::operator = (const AliHLTTriggerDomain& domain)
511 // Assignment operator performs a deep copy.
512 // See header file for more details.
514 if (this == &domain) return *this;
515 TObject::operator = (domain);
517 for (Int_t i = 0; i < domain.fEntries.GetEntriesFast(); i++)
519 const AliHLTDomainEntry* entry = static_cast<const AliHLTDomainEntry*>( domain.fEntries.UncheckedAt(i) );
520 new (fEntries[fEntries.GetEntriesFast()]) AliHLTDomainEntry(*entry);
526 AliHLTTriggerDomain& AliHLTTriggerDomain::operator |= (const AliHLTTriggerDomain& domain)
528 // This operator performs the set union.
529 // See header file for more details.
531 // Note that we partition the fEntries array into 3 regions for this calculation.
532 // - 0..entriesCount-1 : contains the initial entries of this trigger domain.
533 // - entriesCount..startOfIntersects-1 : is space reserved for the new entries
535 // - startOfIntersects..fEntries.GetEntriesFast()-1 : This will grow as we add
536 // all the new domain intersections created during the calculation.
538 // Get the number of entries now before we start adding more entries from 'domain'.
539 Int_t count = fEntries.GetEntriesFast();
540 // Mark the start location for new intersection entries.
541 Int_t startOfIntersects = count + domain.fEntries.GetEntriesFast();
542 Int_t newIndex = startOfIntersects;
544 // Allocate and initialise a single block of memory so that we do not call new twice.
545 bool* buffer = new bool[startOfIntersects];
546 for (Int_t i = 0; i < startOfIntersects; i++) buffer[i] = false;
547 bool* removeThisEntry = buffer;
548 bool* removeDomainEntry = buffer + count;
550 AliHLTDomainEntry intersect;
552 // The idea behind this algorithm is that we need to add all inclusion domain
553 // entries from 'domain' to this object that will not be redundant, but for
554 // the exclusion entries we patch the fEntries rule set by adding the appropriate
555 // intersections to the end of fEntries.
556 for (Int_t i = 0; i < domain.fEntries.GetEntriesFast(); i++)
558 const AliHLTDomainEntry* newEntry = static_cast<const AliHLTDomainEntry*>( domain.fEntries.UncheckedAt(i) );
559 for (Int_t j = 0; j < count; j++)
561 const AliHLTDomainEntry* currentEntry = static_cast<const AliHLTDomainEntry*>( fEntries.UncheckedAt(j) );
562 if (currentEntry->Inclusive() and newEntry->Inclusive())
564 // If either entry is a subset of the other then we do not need to add
565 // both, so make sure to remove the one that is redundant.
566 if (newEntry->SubsetOf(*currentEntry))
568 removeDomainEntry[i] = true;
570 else if (currentEntry->SubsetOf(*newEntry))
572 removeThisEntry[j] = true;
577 if (newEntry->IntersectWith(*currentEntry, intersect))
579 // We can remove all intersections that were already added that will
580 // become redundant when this intersection is added to fEntries.
581 MarkForDeletionSubsetsOf(intersect, startOfIntersects);
583 // Make the new intersection entry an exclusion if the newEntry and
584 // currentEntry flags are the same.
585 bool exclude = newEntry->Exclusive() == currentEntry->Exclusive();
586 new (fEntries[newIndex++]) AliHLTDomainEntry(exclude, intersect);
588 // We can also remove entries that are subsets of another entry in the
589 // opposite list, since they will be redundant when everything is merged
590 // together. For example, remove entry x from fEntries if it is a subset
591 // of entry y in domain.fEntries.
592 if (currentEntry->IdenticalTo(intersect)) removeThisEntry[j] = true;
593 if (newEntry->IdenticalTo(intersect)) removeDomainEntry[i] = true;
599 MergeEntries(removeThisEntry, count, removeDomainEntry, startOfIntersects, domain);
606 AliHLTTriggerDomain& AliHLTTriggerDomain::operator ^= (const AliHLTTriggerDomain& domain)
608 // This operator performs the set union, less the set intersect (something like and xor).
609 // See header file for more details.
611 // Note that we partition the fEntries array into 3 regions for this calculation.
612 // - 0..entriesCount-1 : contains the initial entries of this trigger domain.
613 // - entriesCount..startOfIntersects-1 : is space reserved for the new entries
615 // - startOfIntersects..fEntries.GetEntriesFast()-1 : This will grow as we add
616 // all the new domain intersections created during the calculation.
618 // Get the number of entries now before we start adding more entries from 'domain'.
619 Int_t count = fEntries.GetEntriesFast();
620 // Mark the start location for new intersection entries.
621 Int_t startOfIntersects = count + domain.fEntries.GetEntriesFast();
622 Int_t newIndex = startOfIntersects;
624 // Allocate and initialise a single block of memory so that we do not call new twice.
625 bool* buffer = new bool[startOfIntersects];
626 for (Int_t i = 0; i < startOfIntersects; i++) buffer[i] = false;
627 bool* removeThisEntry = buffer;
628 bool* removeDomainEntry = buffer + count;
630 AliHLTDomainEntry intersect;
632 // This algorithm is similar to the case for the set union (operator |=), except
633 // that we make sure to remove from the trigger domain all parts where the entries
634 // from fEntries and domain.fEntries intersect.
635 // This is done by adding the intersections to the end of fEntries such that they
636 // effectively remove those overlapping trigger domain entries when calculating
637 // IncludeInReadout() or Contains().
638 for (Int_t i = 0; i < domain.fEntries.GetEntriesFast(); i++)
640 const AliHLTDomainEntry* newEntry = static_cast<const AliHLTDomainEntry*>( domain.fEntries.UncheckedAt(i) );
641 for (Int_t j = 0; j < count; j++)
643 const AliHLTDomainEntry* currentEntry = static_cast<const AliHLTDomainEntry*>( fEntries.UncheckedAt(j) );
644 if (newEntry->IntersectWith(*currentEntry, intersect))
646 // We can remove all intersections that were already added that will
647 // become redundant when this intersection is added to fEntries.
648 MarkForDeletionSubsetsOf(intersect, startOfIntersects);
650 // Make the new intersection entry an exclusion if the newEntry and
651 // currentEntry flags are the same.
652 bool exclude = newEntry->Exclusive() == currentEntry->Exclusive();
653 new (fEntries[newIndex++]) AliHLTDomainEntry(exclude, intersect);
655 // We can also remove entries that are subsets of another entry in the
656 // opposite list, since they will be redundant when everything is merged
657 // together. For example, remove entry x from fEntries if it is a subset
658 // of entry y in domain.fEntries.
659 if (currentEntry->IdenticalTo(intersect)) removeThisEntry[j] = true;
660 if (newEntry->IdenticalTo(intersect)) removeDomainEntry[i] = true;
665 MergeEntries(removeThisEntry, count, removeDomainEntry, startOfIntersects, domain);
672 AliHLTTriggerDomain& AliHLTTriggerDomain::operator -= (const AliHLTTriggerDomain& domain)
674 // This operator performs the set difference.
675 // See header file for more details.
677 // Mark the number of entries in fEntries now before we start adding more
678 // entries from 'domain' or intersections.
679 Int_t startOfIntersects = fEntries.GetEntriesFast();
680 Int_t newIndex = startOfIntersects;
682 AliHLTDomainEntry intersect;
684 // To compute the set difference we need to remove all all parts that overlap
685 // with 'domain'. i.e. we need to find all the intersects between the domain
686 // entries in fEntries and those in domain.fEntries, and add the intersects
687 // to the fEntries list, such that they will cancel or remove the overlapping
688 // parts of the two trigger domains.
689 for (Int_t i = 0; i < domain.fEntries.GetEntriesFast(); i++)
691 const AliHLTDomainEntry* checkEntry = static_cast<const AliHLTDomainEntry*>( domain.fEntries.UncheckedAt(i) );
692 if (checkEntry->Inclusive())
694 // For inclusive entries we need to find the overlaps with the inclusive
695 // entries in fEntries and add exclusive entries that will remove that
696 // part of the trigger domain set.
697 for (Int_t j = 0; j < startOfIntersects; j++)
699 AliHLTDomainEntry* currentEntry = static_cast<AliHLTDomainEntry*>( fEntries.UncheckedAt(j) );
701 // We only need to consider the case where both entries are inclusive,
702 // since an exclusion in fEntries already eliminates those data blocks
703 // from the trigger domain set.
704 if (currentEntry->Exclusive()) continue;
706 if (checkEntry->IntersectWith(*currentEntry, intersect))
708 // We can remove all intersections that were already added that will
709 // become redundant when this intersection is added to fEntries.
710 MarkForDeletionSubsetsOf(intersect, startOfIntersects);
712 new (fEntries[newIndex++]) AliHLTDomainEntry(kTRUE, intersect);
713 if (currentEntry->IdenticalTo(intersect))
715 currentEntry->SetBit(BIT(14), true);
722 // For an exclusive entry in 'domain' we need to find the intersections with
723 // all of fEntries and re-apply these with the same exclude flags.
724 for (Int_t j = 0; j < startOfIntersects; j++)
726 AliHLTDomainEntry* currentEntry = static_cast<AliHLTDomainEntry*>( fEntries.UncheckedAt(j) );
727 if (checkEntry->IntersectWith(*currentEntry, intersect))
729 // We can remove all intersections that were already added that will
730 // become redundant when this intersection is added to fEntries.
731 MarkForDeletionSubsetsOf(intersect, startOfIntersects);
733 new (fEntries[newIndex++]) AliHLTDomainEntry(currentEntry->Exclusive(), intersect);
739 RemoveMarkedEntries();
745 AliHLTTriggerDomain AliHLTTriggerDomain::operator ~ () const
747 // Performs a set complement of the trigger domain.
749 // The set complement is calculated by creating a new trigger domain which
750 // accepts all possible data blocks, and then apply all the trigger domain
751 // entries (rules / patterns) from top to bottom, but apply them with the
752 // opposite meaning. For example, this->fEntries contains an inclusive domain
753 // entry then remove it from the new trigger domain 'result', but if it is
754 // an exclusion then add it.
755 AliHLTTriggerDomain result;
756 result.Add(kAliHLTAnyDataType);
757 for (Int_t i = 0; i < fEntries.GetEntriesFast(); i++)
759 const AliHLTDomainEntry* entry = static_cast<const AliHLTDomainEntry*>( fEntries.UncheckedAt(i) );
760 if (entry->Inclusive())
762 result.Remove(*entry);
773 AliHLTTriggerDomain AliHLTTriggerDomain::operator & (const AliHLTTriggerDomain& domain) const
775 // This operator finds the set intersect.
776 // See header file for more details.
778 AliHLTTriggerDomain result;
780 AliHLTDomainEntry intersect;
782 // To find the set intersect we need to compare each entry in 'domain' to those
783 // of fEntries. For each inclusive entry in 'domain' we need to add to the result
784 // the intersect between it and each entry of fEntries, with the same exclude flag
785 // value as the domain entry from fEntries.
786 // However, in principle, for the exclusion entries in 'domain' we just add them
787 // to the result, since those entries do not form part of the 'domain' trigger
788 // domain set, so they should not form part of the result (remember any data block
789 // must be contained in both trigger domains for a set intersect).
790 // In actual fact we just add the intersect of the exclusion entries in 'domain'
791 // with those of fEntries to the result. This has the same overall effect, but
792 // makes sure that all exclusion entries are always subsets of inclusion entries.
793 for (Int_t i = 0; i < domain.fEntries.GetEntriesFast(); i++)
795 const AliHLTDomainEntry* checkEntry = static_cast<const AliHLTDomainEntry*>( domain.fEntries.UncheckedAt(i) );
796 if (checkEntry->Inclusive())
798 for (Int_t j = 0; j < fEntries.GetEntriesFast(); j++)
800 AliHLTDomainEntry* currentEntry = static_cast<AliHLTDomainEntry*>( fEntries.UncheckedAt(j) );
801 if (checkEntry->IntersectWith(*currentEntry, intersect))
803 // We can remove all entries that were already added to the result that
804 // will become redundent because they are subsets of the new entry.
805 result.MarkForDeletionSubsetsOf(intersect, 0);
807 new (result.fEntries[newIndex++]) AliHLTDomainEntry(currentEntry->Exclusive(), intersect);
813 for (Int_t j = 0; j < fEntries.GetEntriesFast(); j++)
815 AliHLTDomainEntry* currentEntry = static_cast<AliHLTDomainEntry*>( fEntries.UncheckedAt(j) );
816 if (checkEntry->IntersectWith(*currentEntry, intersect))
818 // We can remove all entries that were already added to the result that
819 // will become redundant because they are subsets of the new entry.
820 result.MarkForDeletionSubsetsOf(intersect, 0);
822 new (result.fEntries[newIndex++]) AliHLTDomainEntry(kTRUE, intersect);
828 result.RemoveMarkedEntries();
834 bool AliHLTTriggerDomain::operator == (const AliHLTTriggerDomain& domain) const
836 // Checks if two domains are the same.
838 if (fEntries.GetEntriesFast() != domain.fEntries.GetEntriesFast()) return false;
840 // We need to find for each entry in this domain an identical entry in the domain
841 // that we are comparing to. Both entries cannot have subset entries further down
842 // in the entries lists. i.e. for fEntries[n], there cannot be any entry fEntries[m]
843 // that is a subset of fEntries[n] where m > n. Similarly for domain.fEntries.
844 // If two such entries are matched and they respect the subset rule mentioned,
845 // then they are marked. We keep finding matching pairs until no more pairs are
846 // found and check if there are any unmarked entries in either list. If there are
847 // any unmatched pairs then the two domains do not match.
849 // Note: We use bit 14 in fBits to mark the entries.
850 // 2) We traverse fEntries from back to front (i.e. from N-1 down to 0) so that
851 // we are guaranteed that fEntries[n] has no subset entries above it that are
853 for (Int_t i = fEntries.GetEntriesFast() - 1; i >= 0; --i)
855 AliHLTDomainEntry* entry1 = static_cast<AliHLTDomainEntry*>(const_cast<TObject*>( fEntries.UncheckedAt(i) ));
856 // Find identical domain entry in domain.fEntries.
857 AliHLTDomainEntry* entry2 = NULL;
858 Int_t entry2index = -1;
859 for (Int_t j = fEntries.GetEntriesFast() - 1; j >= 0; --j)
861 AliHLTDomainEntry* current = static_cast<AliHLTDomainEntry*>(const_cast<TObject*>( domain.fEntries.UncheckedAt(j) ));
862 if (current->TestBit(BIT(14))) continue; // skip marked entries.
863 if (entry1->IdenticalTo(*current) and entry1->Exclusive() == current->Exclusive())
872 // Could not find identical entry in domain.fEntries for fEntries[i] so we
873 // will have at least one unmatched entry and thus the domains do not match.
876 // Now check if entry2 has any subset entries below it. If it does then
877 // it fails our ordering requirements and the domains cannot match.
878 for (Int_t j = entry2index + 1; j < fEntries.GetEntriesFast(); ++j)
880 const AliHLTDomainEntry* current = static_cast<const AliHLTDomainEntry*>(const_cast<TObject*>( domain.fEntries.UncheckedAt(j) ));
881 if (current->TestBit(BIT(14))) continue; // skip marked entries.
882 if (entry1->SubsetOf(*current)) return false;
884 // If we got to this point then entry1 and entry2 are a match and obey the
885 // ordering rules, so mark them.
886 entry1->SetBit(BIT(14), true);
887 entry2->SetBit(BIT(14), true);
889 // At this point we could find all pairs so the domains match.
890 // We now just need to clear the bits that we set.
891 for (Int_t i = 0; i < fEntries.GetEntriesFast() - 1; ++i)
893 fEntries[i]->SetBit(BIT(14), false);
894 domain.fEntries[i]->SetBit(BIT(14), false);
900 AliHLTTriggerDomain::operator AliHLTReadoutList () const
902 // Typecast operator which constructs a readout list from the trigger domain.
904 AliHLTReadoutList result;
905 for (Int_t deti = 0; deti < AliHLTDAQ::NumberOfDetectors(); deti++)
907 for (Int_t i = 0; i < AliHLTDAQ::NumberOfDdls(deti); i++)
909 Int_t ddlId = AliHLTDAQ::DdlID(deti, i);
910 AliHLTComponentDataType type = AliHLTComponentDataTypeInitializer(kAliHLTDAQRDOUTDataTypeID, AliHLTDAQ::OnlineName(deti));
911 if (Contains(AliHLTDomainEntry(type, ddlId)))
913 result.EnableDDLBit(ddlId);
921 void AliHLTTriggerDomain::MergeEntries(
922 const bool* removeThisEntry, Int_t entriesCount,
923 const bool* removeDomainEntry, Int_t startOfIntersects,
924 const AliHLTTriggerDomain& domain
927 // Merges the entries in this trigger domain with the ones in 'domain', while
928 // removing all entries that were marked for removal.
929 // See header file for more information.
931 bool anythingRemoved = false;
933 // Remember this method is used at the end of the calculation of the binary operators
934 // and that fEntries is expected to be partitioned into 3 regions.
935 // - 0..entriesCount-1 : contains the original (initial) entries of this trigger domain.
936 // - entriesCount..startOfIntersects-1 : is space reserved for the new entries
937 // from the given trigger domain 'domain' being processed.
938 // - startOfIntersects..fEntries.GetEntriesFast()-1 : contains all new domain entry
939 // intersection created and added to fEntries.
941 // First we need to remove all entries marked for removal from the original entries.
942 for (Int_t i = 0; i < entriesCount; i++)
944 if (removeThisEntry[i])
946 fEntries.RemoveAt(i);
947 anythingRemoved = true;
951 // Now we copy over all the new entries from 'domain' which were not marked for removal
952 // and indicate anythingRemoved = true since there will now be gaps in the clones array
953 // that need to be compressed away later.
954 for (Int_t i = 0; i < domain.fEntries.GetEntriesFast(); i++)
956 if (removeDomainEntry[i])
958 anythingRemoved = true;
962 const AliHLTDomainEntry* newEntry = static_cast<const AliHLTDomainEntry*>( domain.fEntries.UncheckedAt(i) );
963 new (fEntries[entriesCount+i]) AliHLTDomainEntry(*newEntry);
967 // Finally remove all new intersection entries that were marked for removal by
968 // the MarkForDeletionSubsetsOf method.
969 for (Int_t i = startOfIntersects; i < fEntries.GetEntriesFast(); i++)
971 const AliHLTDomainEntry* ientry = static_cast<const AliHLTDomainEntry*>( fEntries.UncheckedAt(i) );
972 if (ientry->TestBit(BIT(14)))
974 fEntries.RemoveAt(i);
975 anythingRemoved = true;
978 if (anythingRemoved) fEntries.Compress();
982 void AliHLTTriggerDomain::MarkForDeletionSubsetsOf(const AliHLTDomainEntry& entry, Int_t min)
984 // Marks for deletion all the entries in this trigger domain that are subsets
985 // of the given entry.
986 // See header file for more information.
988 AliHLTDomainEntry intersect;
989 for (Int_t i = min; i < fEntries.GetEntriesFast(); i++)
991 AliHLTDomainEntry* ientry = static_cast<AliHLTDomainEntry*>( fEntries.UncheckedAt(i) );
992 if (ientry->TestBit(BIT(14))) continue;
993 if (ientry->SubsetOf(entry))
995 ientry->SetBit(BIT(14), true);
1001 void AliHLTTriggerDomain::RemoveMarkedEntries()
1003 // Removes all entries in this trigger domain which were marked for removal.
1004 // See header file for more information.
1006 bool anythingRemoved = false;
1007 for (Int_t i = 0; i < fEntries.GetEntriesFast(); i++)
1009 const AliHLTDomainEntry* ientry = static_cast<const AliHLTDomainEntry*>( fEntries.UncheckedAt(i) );
1010 if (ientry->TestBit(BIT(14)))
1012 fEntries.RemoveAt(i);
1013 anythingRemoved = true;
1016 if (anythingRemoved) fEntries.Compress();
1020 void AliHLTTriggerDomain::Optimise()
1022 // Removes redundant trigger domain entries from the trigger domain.
1023 // See header file for more information.
1025 AliHLTDomainEntry intersect;
1027 // Check that the first entry is not and exclusion which would be redundent.
1028 if (fEntries.GetEntriesFast() == 0) return;
1029 AliHLTDomainEntry* firstEntry = static_cast<AliHLTDomainEntry*>( fEntries[0] );
1030 if (firstEntry->Exclusive()) firstEntry->SetBit(BIT(14), true);
1032 for (Int_t i = 1; i < fEntries.GetEntriesFast(); i++)
1034 AliHLTDomainEntry* ientry = static_cast<AliHLTDomainEntry*>( fEntries.UncheckedAt(i) );
1036 // For the i'th entry in fEntries, compare it in reverse order with all other
1037 // entries that are before it and look for redundant ones, i.e. that are subsets
1038 // of the i'th entry.
1039 for (Int_t j = i-1; j >= 0; j--)
1041 AliHLTDomainEntry* jentry = static_cast<AliHLTDomainEntry*>( fEntries.UncheckedAt(j) );
1042 if (jentry->TestBit(BIT(14))) continue;
1043 // Find entries that intersect
1044 if (jentry->SubsetOf(*ientry))
1046 // jentry is a subset of ientry so it is redundant because for all values
1047 // ientry will override jentry when calling IncludeInReadout.
1048 jentry->SetBit(BIT(14), true);
1050 else if (*ientry == *jentry)
1052 // If intersecting entries have opposite exclude flags then search no further,
1053 // we know that we will need this entry for correct behaviour of IncludeInReadout.
1054 if (ientry->Inclusive() == jentry->Exclusive()) goto processNextEntry;
1056 if (ientry->SubsetOf(*jentry))
1058 ientry->SetBit(BIT(14), true);
1059 goto processNextEntry;
1064 // If we got to this point then we hit the top of the trigger domain rules
1065 // (pattern matching) list without hitting any and overlapping entries.
1066 // So now we need to check if ientry is an exclusion. If it is, then it is
1067 // redundant and we can mark it for removal.
1068 if (ientry->Exclusive()) ientry->SetBit(BIT(14), true);
1073 RemoveMarkedEntries();
1076 const AliHLTDomainEntry& AliHLTTriggerDomain::operator[](int index) const
1078 // Access individual entry of the domain
1079 return static_cast<AliHLTDomainEntry&>(*fEntries[index]);