+bool AliHLTTriggerDomain::operator == (const AliHLTTriggerDomain& domain) const
+{
+ // Checks if two domains are the same.
+
+ if (fEntries.GetEntriesFast() != domain.fEntries.GetEntriesFast()) return false;
+
+ // We need to find for each entry in this domain an identical entry in the domain
+ // that we are comparing to. Both entries cannot have subset entries further down
+ // in the entries lists. i.e. for fEntries[n], there cannot be any entry fEntries[m]
+ // that is a subset of fEntries[n] where m > n. Similarly for domain.fEntries.
+ // If two such entries are matched and they respect the subset rule mentioned,
+ // then they are marked. We keep finding matching pairs until no more pairs are
+ // found and check if there are any unmarked entries in either list. If there are
+ // any unmatched pairs then the two domains do not match.
+ //
+ // Note: We use bit 14 in fBits to mark the entries.
+ // 2) We traverse fEntries from back to front (i.e. from N-1 down to 0) so that
+ // we are guaranteed that fEntries[n] has no subset entries above it that are
+ // not marked.
+ for (Int_t i = fEntries.GetEntriesFast() - 1; i >= 0; --i)
+ {
+ AliHLTDomainEntry* entry1 = static_cast<AliHLTDomainEntry*>(const_cast<TObject*>( fEntries.UncheckedAt(i) ));
+ // Find identical domain entry in domain.fEntries.
+ AliHLTDomainEntry* entry2 = NULL;
+ Int_t entry2index = -1;
+ for (Int_t j = fEntries.GetEntriesFast() - 1; j >= 0; --j)
+ {
+ AliHLTDomainEntry* current = static_cast<AliHLTDomainEntry*>(const_cast<TObject*>( domain.fEntries.UncheckedAt(j) ));
+ if (current->TestBit(BIT(14))) continue; // skip marked entries.
+ if (entry1->IdenticalTo(*current) and entry1->Exclusive() == current->Exclusive())
+ {
+ entry2 = current;
+ entry2index = j;
+ break;
+ }
+ }
+ if (entry2 == NULL)
+ {
+ // Could not find identical entry in domain.fEntries for fEntries[i] so we
+ // will have at least one unmatched entry and thus the domains do not match.
+ return false;
+ }
+ // Now check if entry2 has any subset entries below it. If it does then
+ // it fails our ordering requirements and the domains cannot match.
+ for (Int_t j = entry2index + 1; j < fEntries.GetEntriesFast(); ++j)
+ {
+ const AliHLTDomainEntry* current = static_cast<const AliHLTDomainEntry*>(const_cast<TObject*>( domain.fEntries.UncheckedAt(j) ));
+ if (current->TestBit(BIT(14))) continue; // skip marked entries.
+ if (entry1->SubsetOf(*current)) return false;
+ }
+ // If we got to this point then entry1 and entry2 are a match and obey the
+ // ordering rules, so mark them.
+ entry1->SetBit(BIT(14), true);
+ entry2->SetBit(BIT(14), true);
+ }
+ // At this point we could find all pairs so the domains match.
+ // We now just need to clear the bits that we set.
+ for (Int_t i = 0; i < fEntries.GetEntriesFast() - 1; ++i)
+ {
+ fEntries[i]->SetBit(BIT(14), false);
+ domain.fEntries[i]->SetBit(BIT(14), false);
+ }
+ return true;
+}
+
+