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[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("DAQRDOUT", 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("DAQRDOUT", 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[i]);
213 if (ientry->Inclusive())
215 if (entry.SubsetOf(*ientry))
219 else if (ientry->SubsetOf(entry))
221 ientry->SetBit(14, true); // mark for removal.
226 if (ientry->SubsetOf(entry))
228 ientry->SetBit(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("DAQRDOUT", 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("DAQRDOUT", 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[i]);
346 if (ientry->Inclusive())
348 if (ientry->SubsetOf(entry))
350 ientry->SetBit(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(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[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[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[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[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[i] );
559 for (Int_t j = 0; j < count; j++)
561 const AliHLTDomainEntry* currentEntry = static_cast<const AliHLTDomainEntry*>( fEntries[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[i] );
641 for (Int_t j = 0; j < count; j++)
643 const AliHLTDomainEntry* currentEntry = static_cast<const AliHLTDomainEntry*>( fEntries[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[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[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(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[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[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[i] );
796 if (checkEntry->Inclusive())
798 for (Int_t j = 0; j < fEntries.GetEntriesFast(); j++)
800 AliHLTDomainEntry* currentEntry = static_cast<AliHLTDomainEntry*>( fEntries[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[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 AliHLTTriggerDomain::operator AliHLTReadoutList () const
836 // Typecast operator which constructs a readout list from the trigger domain.
838 AliHLTReadoutList result;
839 for (Int_t deti = 0; deti < AliHLTDAQ::NumberOfDetectors(); deti++)
841 for (Int_t i = 0; i < AliHLTDAQ::NumberOfDdls(deti); i++)
843 Int_t ddlId = AliHLTDAQ::DdlID(deti, i);
844 if (Contains(AliHLTDomainEntry("DAQRDOUT", AliHLTDAQ::OnlineName(deti), ddlId)))
846 result.EnableDDLBit(ddlId);
854 void AliHLTTriggerDomain::MergeEntries(
855 const bool* removeThisEntry, Int_t entriesCount,
856 const bool* removeDomainEntry, Int_t startOfIntersects,
857 const AliHLTTriggerDomain& domain
860 // Merges the entries in this trigger domain with the ones in 'domain', while
861 // removing all entries that were marked for removal.
862 // See header file for more information.
864 bool anythingRemoved = false;
866 // Remember this method is used at the end of the calculation of the binary operators
867 // and that fEntries is expected to be partitioned into 3 regions.
868 // - 0..entriesCount-1 : contains the original (initial) entries of this trigger domain.
869 // - entriesCount..startOfIntersects-1 : is space reserved for the new entries
870 // from the given trigger domain 'domain' being processed.
871 // - startOfIntersects..fEntries.GetEntriesFast()-1 : contains all new domain entry
872 // intersection created and added to fEntries.
874 // First we need to remove all entries marked for removal from the original entries.
875 for (Int_t i = 0; i < entriesCount; i++)
877 if (removeThisEntry[i])
879 fEntries.RemoveAt(i);
880 anythingRemoved = true;
884 // Now we copy over all the new entries from 'domain' which were not marked for removal
885 // and indicate anythingRemoved = true since there will now be gaps in the clones array
886 // that need to be compressed away later.
887 for (Int_t i = 0; i < domain.fEntries.GetEntriesFast(); i++)
889 if (removeDomainEntry[i])
891 anythingRemoved = true;
895 const AliHLTDomainEntry* newEntry = static_cast<const AliHLTDomainEntry*>( domain.fEntries[i] );
896 new (fEntries[entriesCount+i]) AliHLTDomainEntry(*newEntry);
900 // Finally remove all new intersection entries that were marked for removal by
901 // the MarkForDeletionSubsetsOf method.
902 for (Int_t i = startOfIntersects; i < fEntries.GetEntriesFast(); i++)
904 const AliHLTDomainEntry* ientry = static_cast<const AliHLTDomainEntry*>( fEntries[i] );
905 if (ientry->TestBit(14))
907 fEntries.RemoveAt(i);
908 anythingRemoved = true;
911 if (anythingRemoved) fEntries.Compress();
915 void AliHLTTriggerDomain::MarkForDeletionSubsetsOf(const AliHLTDomainEntry& entry, Int_t min)
917 // Marks for deletion all the entries in this trigger domain that are subsets
918 // of the given entry.
919 // See header file for more information.
921 AliHLTDomainEntry intersect;
922 for (Int_t i = min; i < fEntries.GetEntriesFast(); i++)
924 AliHLTDomainEntry* ientry = static_cast<AliHLTDomainEntry*>( fEntries[i] );
925 if (ientry->TestBit(14)) continue;
926 if (ientry->SubsetOf(entry))
928 ientry->SetBit(14, true);
934 void AliHLTTriggerDomain::RemoveMarkedEntries()
936 // Removes all entries in this trigger domain which were marked for removal.
937 // See header file for more information.
939 bool anythingRemoved = false;
940 for (Int_t i = 0; i < fEntries.GetEntriesFast(); i++)
942 const AliHLTDomainEntry* ientry = static_cast<const AliHLTDomainEntry*>( fEntries[i] );
943 if (ientry->TestBit(14))
945 fEntries.RemoveAt(i);
946 anythingRemoved = true;
949 if (anythingRemoved) fEntries.Compress();
953 void AliHLTTriggerDomain::Optimise()
955 // Removes redundant trigger domain entries from the trigger domain.
956 // See header file for more information.
958 AliHLTDomainEntry intersect;
960 // Check that the first entry is not and exclusion which would be redundent.
961 if (fEntries.GetEntriesFast() == 0) return;
962 AliHLTDomainEntry* firstEntry = static_cast<AliHLTDomainEntry*>( fEntries[0] );
963 if (firstEntry->Exclusive()) firstEntry->SetBit(14, true);
965 for (Int_t i = 1; i < fEntries.GetEntriesFast(); i++)
967 AliHLTDomainEntry* ientry = static_cast<AliHLTDomainEntry*>( fEntries[i] );
969 // For the i'th entry in fEntries, compare it in reverse order with all other
970 // entries that are before it and look for redundant ones, i.e. that are subsets
971 // of the i'th entry.
972 for (Int_t j = i-1; j >= 0; j--)
974 AliHLTDomainEntry* jentry = static_cast<AliHLTDomainEntry*>( fEntries[j] );
975 if (jentry->TestBit(14)) continue;
976 // Find entries that intersect
977 if (jentry->SubsetOf(*ientry))
979 // jentry is a subset of ientry so it is redundant because for all values
980 // ientry will override jentry when calling IncludeInReadout.
981 jentry->SetBit(14, true);
983 else if (*ientry == *jentry)
985 // If intersecting entries have opposite exclude flags then search no further,
986 // we know that we will need this entry for correct behaviour of IncludeInReadout.
987 if (ientry->Inclusive() == jentry->Exclusive()) goto processNextEntry;
989 if (ientry->SubsetOf(*jentry))
991 ientry->SetBit(14, true);
992 goto processNextEntry;
997 // If we got to this point then we hit the top of the trigger domain rules
998 // (pattern matching) list without hitting any and overlapping entries.
999 // So now we need to check if ientry is an exclusion. If it is, then it is
1000 // redundant and we can mark it for removal.
1001 if (ientry->Exclusive()) ientry->SetBit(14, true);
1006 RemoveMarkedEntries();