Line data Source code
1 : // $Id$
2 : /**************************************************************************
3 : * This file is property of and copyright by the ALICE HLT Project *
4 : * ALICE Experiment at CERN, All rights reserved. *
5 : * *
6 : * Primary Authors: Artur Szostak <artursz@iafrica.com> *
7 : * for The ALICE HLT Project. *
8 : * *
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 : **************************************************************************/
17 :
18 : /// @file AliHLTTriggerDomain.cxx
19 : /// @author Artur Szostak <artursz@iafrica.com>
20 : /// @date 19 Nov 2008
21 : /// @brief Implementation of the AliHLTTriggerDomain class.
22 : ///
23 : /// The trigger domain class is the set of HLT raw data block types that should
24 : /// be readout and sent to HLTOUT.
25 :
26 : #include <stdlib.h>
27 :
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"
35 :
36 126 : ClassImp(AliHLTTriggerDomain)
37 :
38 :
39 : AliHLTTriggerDomain::AliHLTTriggerDomain() :
40 30 : TObject(), fEntries(AliHLTDomainEntry::Class(), 10)
41 50 : {
42 : // Default constructor.
43 20 : }
44 :
45 :
46 : AliHLTTriggerDomain::AliHLTTriggerDomain(const char* list) :
47 0 : TObject(), fEntries(AliHLTDomainEntry::Class(), 10)
48 0 : {
49 : // Constructs the domain from a list of entries.
50 :
51 0 : TString lst = list;
52 0 : TObjArray* entries = lst.Tokenize(",");
53 0 : for (Int_t i = 0; i < entries->GetEntriesFast(); i++)
54 : {
55 0 : TString entry = static_cast<TObjString*>(entries->UncheckedAt(i))->GetString();
56 0 : TObjArray* domainStrings = entry.Tokenize(":");
57 0 : if (domainStrings->GetEntriesFast() <= 0 or domainStrings->GetEntriesFast() > 3)
58 : {
59 0 : Error("AliHLTTriggerDomain",
60 : "The domain string must contain 1, 2 or 3 fields separated by a ':'."
61 : );
62 0 : delete domainStrings;
63 0 : continue;
64 : }
65 :
66 : bool inclusiveEntry = true;
67 0 : TString typeString = "*******";
68 0 : if (domainStrings->GetEntriesFast() >= 1)
69 : {
70 0 : typeString = static_cast<TObjString*>(domainStrings->UncheckedAt(0))->GetString();
71 0 : if (typeString.Length() > 0)
72 : {
73 0 : if (typeString[0] == '+')
74 : {
75 : inclusiveEntry = true;
76 0 : typeString.Remove(0, 1);
77 : }
78 0 : if (typeString[0] == '-')
79 : {
80 : inclusiveEntry = false;
81 0 : typeString.Remove(0, 1);
82 : }
83 : }
84 : }
85 0 : TString originString = "***";
86 0 : if (domainStrings->GetEntriesFast() >= 2)
87 : {
88 0 : originString = static_cast<TObjString*>(domainStrings->UncheckedAt(1))->GetString();
89 0 : }
90 : bool usespec = false;
91 : UInt_t spec = 0;
92 0 : if (domainStrings->GetEntriesFast() == 3)
93 : {
94 0 : TString specString = static_cast<TObjString*>(domainStrings->UncheckedAt(2))->GetString();
95 0 : char* error = NULL;
96 0 : spec = UInt_t( strtoul(specString.Data(), &error, 0) );
97 0 : if (error == NULL or *error != '\0')
98 : {
99 0 : Error("AliHLTTriggerDomain",
100 : "The last field of the domain string must be a number, but we received '%s'.",
101 0 : specString.Data()
102 : );
103 : }
104 : else
105 : {
106 : usespec = true;
107 : }
108 0 : }
109 :
110 0 : if (usespec)
111 : {
112 0 : if (inclusiveEntry)
113 0 : Add(typeString.Data(), originString.Data(), spec);
114 : else
115 0 : Remove(typeString.Data(), originString.Data(), spec);
116 : }
117 : else
118 : {
119 0 : if (inclusiveEntry)
120 0 : Add(typeString.Data(), originString.Data());
121 : else
122 0 : Remove(typeString.Data(), originString.Data());
123 : }
124 :
125 0 : delete domainStrings;
126 0 : }
127 0 : delete entries;
128 0 : }
129 :
130 :
131 : AliHLTTriggerDomain::AliHLTTriggerDomain(const AliHLTReadoutList& list) :
132 0 : TObject(), fEntries(AliHLTDomainEntry::Class(), 10)
133 0 : {
134 : // Constructor creates a trigger domain from a readout list.
135 : // See header file for more details.
136 :
137 0 : Add(list);
138 0 : }
139 :
140 :
141 : AliHLTTriggerDomain::AliHLTTriggerDomain(const AliHLTTriggerDomain& domain) :
142 0 : TObject(domain),
143 0 : fEntries(AliHLTDomainEntry::Class(), domain.fEntries.GetEntriesFast())
144 0 : {
145 : // Copy constructor performs a deep copy.
146 : // See header file for more details.
147 :
148 0 : for (Int_t i = 0; i < domain.fEntries.GetEntriesFast(); i++)
149 : {
150 0 : const AliHLTDomainEntry* entry = static_cast<const AliHLTDomainEntry*>( domain.fEntries.UncheckedAt(i) );
151 0 : new (fEntries[fEntries.GetEntriesFast()]) AliHLTDomainEntry(*entry);
152 : }
153 0 : }
154 :
155 :
156 : AliHLTTriggerDomain::~AliHLTTriggerDomain()
157 8 : {
158 : // Default destructor.
159 4 : }
160 :
161 :
162 : void AliHLTTriggerDomain::Add(const AliHLTReadoutList& list)
163 : {
164 : // Adds the readout list to the trigger domain.
165 : // See header file for more details.
166 0 : for (Int_t deti = 0; deti < (Int_t)AliHLTDAQ::NumberOfDetectors() ; deti++)
167 : {
168 0 : if (deti == AliHLTDAQ::NumberOfDetectors()-1){
169 0 : deti=AliHLTDAQ::HLTId(); // HLT
170 0 : }
171 0 : if (list.DetectorEnabled(0x1<<deti))
172 : {
173 0 : Add(kAliHLTDAQRDOUTDataTypeID, AliHLTDAQ::OnlineName(deti));
174 0 : }
175 : else
176 : {
177 0 : for (Int_t i = 0; i < AliHLTDAQ::NumberOfDdls(deti); i++)
178 : {
179 0 : Int_t ddlId = AliHLTDAQ::DdlID(deti, i);
180 0 : if (list.IsDDLEnabled(ddlId)) Add(kAliHLTDAQRDOUTDataTypeID, AliHLTDAQ::OnlineName(deti), ddlId);
181 : }
182 : }
183 : }
184 0 : }
185 :
186 : void AliHLTTriggerDomain::Add(const AliHLTDomainEntry& entry)
187 : {
188 : // Adds a new domain entry to the trigger domain.
189 : // See header file for more details.
190 :
191 0 : AliHLTDomainEntry intersect;
192 : bool alreadyInSet = false;
193 :
194 : // Get the initial size of the fEntries array since we might add things to the
195 : // end during the calculation.
196 0 : Int_t count = fEntries.GetEntriesFast();
197 :
198 : // Go through each entry that is already in fEntries and see if we can remove
199 : // it because it will become redundant, or if we need to patch exclusion entries
200 : // by adding inclusive intersects, or if we do not even need to add the new entry
201 : // because it is already part of the trigger domain.
202 0 : for (Int_t i = 0; i < count; i++)
203 : {
204 0 : AliHLTDomainEntry* ientry = static_cast<AliHLTDomainEntry*>(fEntries.UncheckedAt(i));
205 0 : if (ientry->Inclusive())
206 : {
207 0 : if (entry.SubsetOf(*ientry))
208 : {
209 : alreadyInSet = true;
210 0 : }
211 0 : else if (ientry->SubsetOf(entry))
212 : {
213 0 : ientry->SetBit(BIT(14), true); // mark for removal.
214 : }
215 : }
216 : else
217 : {
218 0 : if (ientry->SubsetOf(entry))
219 : {
220 0 : ientry->SetBit(BIT(14), true); // mark for removal.
221 : }
222 0 : else if (entry.SubsetOf(*ientry))
223 : {
224 : alreadyInSet = false;
225 0 : }
226 0 : else if (ientry->IntersectWith(entry, intersect))
227 : {
228 0 : MarkForDeletionSubsetsOf(intersect, count);
229 0 : new (fEntries[fEntries.GetEntriesFast()]) AliHLTDomainEntry(kFALSE, intersect);
230 : }
231 : }
232 : }
233 :
234 : // Check if we need to add the new entry.
235 0 : if (not alreadyInSet)
236 : {
237 0 : MarkForDeletionSubsetsOf(entry, count);
238 0 : new (fEntries[fEntries.GetEntriesFast()]) AliHLTDomainEntry(kFALSE, entry);
239 : }
240 0 : RemoveMarkedEntries();
241 0 : }
242 :
243 :
244 : void AliHLTTriggerDomain::Add(const AliHLTComponentDataType& datatype)
245 : {
246 : // Adds a new domain entry with the given data type to the trigger domain.
247 : // But the data block specification is set to the any matching wild card.
248 : // See header file for more details.
249 :
250 0 : Add(AliHLTDomainEntry(datatype));
251 0 : }
252 :
253 :
254 : void AliHLTTriggerDomain::Add(const char* blocktype, const char* origin)
255 : {
256 : // Adds a new domain entry with the given data type and origin to the trigger domain.
257 : // But the data block specification is set to the any matching wild card.
258 : // See header file for more details.
259 :
260 0 : Add(AliHLTDomainEntry(blocktype, origin));
261 0 : }
262 :
263 :
264 : void AliHLTTriggerDomain::Add(const AliHLTComponentDataType& datatype, UInt_t spec)
265 : {
266 : // Adds a new domain entry to the trigger domain with the data type and data block
267 : // specification bits.
268 : // See header file for more details.
269 :
270 0 : Add(AliHLTDomainEntry(datatype, spec));
271 0 : }
272 :
273 :
274 : void AliHLTTriggerDomain::Add(const char* blocktype, const char* origin, UInt_t spec)
275 : {
276 : // Adds a new domain entry to the trigger domain with the given data type, origin
277 : // and data block specification bits.
278 : // See header file for more details.
279 :
280 0 : Add(AliHLTDomainEntry(blocktype, origin, spec));
281 0 : }
282 :
283 :
284 : void AliHLTTriggerDomain::Remove(const AliHLTReadoutList& list)
285 : {
286 : // Removes the entries in the readout list from the trigger domain that are enabled.
287 : // See header file for more details.
288 0 : for (Int_t deti = 0; deti < (Int_t)AliHLTDAQ::NumberOfDetectors() ; deti++)
289 : {
290 0 : if (deti == AliHLTDAQ::NumberOfDetectors()-1){
291 0 : deti=AliHLTDAQ::HLTId(); // HLT
292 0 : }
293 0 : if (list.DetectorEnabled(0x1 << deti))
294 : {
295 0 : Remove(kAliHLTDAQRDOUTDataTypeID, AliHLTDAQ::OnlineName(deti));
296 0 : }
297 : else
298 : {
299 0 : for (Int_t i = 0; i < AliHLTDAQ::NumberOfDdls(deti); i++)
300 : {
301 0 : Int_t ddlId = AliHLTDAQ::DdlID(deti, i);
302 0 : if (list.IsDDLEnabled(ddlId)) Remove(kAliHLTDAQRDOUTDataTypeID, AliHLTDAQ::OnlineName(deti), ddlId);
303 : }
304 : }
305 : }
306 0 : }
307 :
308 :
309 : void AliHLTTriggerDomain::Remove(const AliHLTDomainEntry& entry)
310 : {
311 : // Removes the given domain entry from the trigger domain.
312 : // See header file for more details.
313 :
314 0 : AliHLTDomainEntry intersect;
315 : bool addToExcludeSet = false;
316 :
317 : // Get the initial size of the fEntries array since we might add things to the
318 : // end during the calculation.
319 0 : Int_t count = fEntries.GetEntriesFast();
320 :
321 : // We need to go through all existing entries and see if they need to be removed
322 : // because they would become redundant when we add the new 'entry' to the end of
323 : // the fEntries list. We also need to check if the new entry needs to be added
324 : // at all because the trigger domain might already not contain those entries.
325 : // Lastly, some intersection entries might need to be added to patch up existing
326 : // inclusive trigger domain entries (rules / patterns).
327 0 : for (Int_t i = 0; i < count; i++)
328 : {
329 0 : AliHLTDomainEntry* ientry = static_cast<AliHLTDomainEntry*>(fEntries.UncheckedAt(i));
330 0 : if (ientry->Inclusive())
331 : {
332 0 : if (ientry->SubsetOf(entry))
333 : {
334 0 : ientry->SetBit(BIT(14), true); // mark for removal.
335 : }
336 0 : else if (entry.SubsetOf(*ientry))
337 : {
338 : addToExcludeSet = true;
339 0 : }
340 0 : else if (ientry->IntersectWith(entry, intersect))
341 : {
342 0 : new (fEntries[fEntries.GetEntriesFast()]) AliHLTDomainEntry(kTRUE, intersect);
343 : }
344 : }
345 : else
346 : {
347 0 : if (entry.SubsetOf(*ientry))
348 : {
349 : addToExcludeSet = false;
350 0 : }
351 0 : else if (ientry->SubsetOf(entry))
352 : {
353 0 : ientry->SetBit(BIT(14), true); // mark for removal.
354 : }
355 : }
356 : }
357 :
358 : // Check if we need to add the new entry.
359 0 : if (addToExcludeSet)
360 : {
361 0 : MarkForDeletionSubsetsOf(entry, count);
362 0 : new (fEntries[fEntries.GetEntriesFast()]) AliHLTDomainEntry(kTRUE, entry);
363 : }
364 0 : RemoveMarkedEntries();
365 0 : }
366 :
367 :
368 : void AliHLTTriggerDomain::Remove(const AliHLTComponentDataType& datatype)
369 : {
370 : // Removes the domain entries that have the given data type from the trigger domain.
371 : // See header file for more details.
372 :
373 0 : Remove(AliHLTDomainEntry(datatype));
374 0 : }
375 :
376 :
377 : void AliHLTTriggerDomain::Remove(const char* blocktype, const char* origin)
378 : {
379 : // Removes the domain entries that have the given data type and origin from the
380 : // trigger domain.
381 : // See header file for more details.
382 :
383 0 : Remove(AliHLTDomainEntry(blocktype, origin));
384 0 : }
385 :
386 :
387 : void AliHLTTriggerDomain::Remove(const AliHLTComponentDataType& datatype, UInt_t spec)
388 : {
389 : // Removes the domain entries that have the given data type and data block
390 : // specification bits from the trigger domain.
391 : // See header file for more details.
392 :
393 0 : Remove(AliHLTDomainEntry(datatype, spec));
394 0 : }
395 :
396 :
397 : void AliHLTTriggerDomain::Remove(const char* blocktype, const char* origin, UInt_t spec)
398 : {
399 : // Removes the domain entries that have the given data type, origin and data
400 : // block specification bits from the trigger domain.
401 : // See header file for more details.
402 :
403 0 : Remove(AliHLTDomainEntry(blocktype, origin, spec));
404 0 : }
405 :
406 :
407 : bool AliHLTTriggerDomain::Contains(const AliHLTDomainEntry& entry) const
408 : {
409 : // Checks to see if the given domain entry is part of the trigger domain set.
410 : // See header file for more details.
411 :
412 : // Simply go through the whole list of fEntries and for each entry see if the
413 : // given domain entry 'entry' being checked matches. If there is a match then
414 : // update the result depending on the entry type. i.e. set to false if the entry
415 : // in fEntries is an exclusion and set to true if it is an inclusion.
416 : bool result = false;
417 0 : for (Int_t i = 0; i < fEntries.GetEntriesFast(); i++)
418 : {
419 0 : const AliHLTDomainEntry* ientry = static_cast<const AliHLTDomainEntry*>(fEntries.UncheckedAt(i));
420 0 : if (ientry->Inclusive())
421 : {
422 0 : if (*ientry == entry) result = true;
423 : }
424 : else
425 : {
426 0 : if (entry.SubsetOf(*ientry)) result = false;
427 : }
428 : }
429 0 : return result;
430 : }
431 :
432 :
433 : bool AliHLTTriggerDomain::IncludeInReadout(const AliHLTComponentBlockData* block) const
434 : {
435 : // Checks to see if the given data block is part of the trigger domain set and
436 : // should be readout.
437 : // See header file for more details.
438 :
439 : // Same algorithm as for Contains() but applied directly to the data block
440 : // descriptor structure.
441 0 : AliHLTDomainEntry blockEntry(block->fDataType, block->fSpecification);
442 : bool result = false;
443 0 : for (Int_t i = 0; i < fEntries.GetEntriesFast(); i++)
444 : {
445 0 : const AliHLTDomainEntry* entry = static_cast<const AliHLTDomainEntry*>(fEntries.UncheckedAt(i));
446 0 : if (entry->Inclusive())
447 : {
448 0 : if (*entry == block) result = true;
449 : }
450 : else
451 : {
452 0 : if (blockEntry.SubsetOf(*entry)) result = false;
453 : }
454 : }
455 0 : return result;
456 0 : }
457 :
458 :
459 : void AliHLTTriggerDomain::Clear(Option_t* option)
460 : {
461 : // Clears the trigger domain (Removes all entries).
462 :
463 34 : fEntries.Clear(option);
464 17 : }
465 :
466 :
467 : void AliHLTTriggerDomain::Print(Option_t* /*option*/) const
468 : {
469 : // Prints the trigger domain entries in the order that they are applied.
470 : // See header file for more details.
471 :
472 0 : cout << "Trigger domain rules (applied in order of first to last):" << endl;
473 0 : for (Int_t i = 0; i < fEntries.GetEntriesFast(); i++)
474 : {
475 0 : const AliHLTDomainEntry* entry = static_cast<const AliHLTDomainEntry*>( fEntries.UncheckedAt(i) );
476 0 : if (entry->Inclusive())
477 : {
478 0 : cout << "Include ";
479 0 : }
480 : else
481 : {
482 0 : cout << "Exclude ";
483 : }
484 0 : entry->Print();
485 : }
486 0 : if (fEntries.GetEntriesFast() == 0)
487 : {
488 0 : cout << "(empty)" << endl;
489 0 : }
490 0 : }
491 :
492 :
493 : AliHLTTriggerDomain& AliHLTTriggerDomain::operator = (const AliHLTTriggerDomain& domain)
494 : {
495 : // Assignment operator performs a deep copy.
496 : // See header file for more details.
497 :
498 4 : if (this == &domain) return *this;
499 2 : TObject::operator = (domain);
500 2 : fEntries.Clear();
501 4 : for (Int_t i = 0; i < domain.fEntries.GetEntriesFast(); i++)
502 : {
503 0 : const AliHLTDomainEntry* entry = static_cast<const AliHLTDomainEntry*>( domain.fEntries.UncheckedAt(i) );
504 0 : new (fEntries[fEntries.GetEntriesFast()]) AliHLTDomainEntry(*entry);
505 : }
506 2 : return *this;
507 2 : }
508 :
509 :
510 : AliHLTTriggerDomain& AliHLTTriggerDomain::operator |= (const AliHLTTriggerDomain& domain)
511 : {
512 : // This operator performs the set union.
513 : // See header file for more details.
514 :
515 : // Note that we partition the fEntries array into 3 regions for this calculation.
516 : // - 0..entriesCount-1 : contains the initial entries of this trigger domain.
517 : // - entriesCount..startOfIntersects-1 : is space reserved for the new entries
518 : // from 'domain'.
519 : // - startOfIntersects..fEntries.GetEntriesFast()-1 : This will grow as we add
520 : // all the new domain intersections created during the calculation.
521 : //
522 : // Get the number of entries now before we start adding more entries from 'domain'.
523 0 : Int_t count = fEntries.GetEntriesFast();
524 : // Mark the start location for new intersection entries.
525 0 : Int_t startOfIntersects = count + domain.fEntries.GetEntriesFast();
526 : Int_t newIndex = startOfIntersects;
527 :
528 : // Allocate and initialise a single block of memory so that we do not call new twice.
529 0 : bool* buffer = new bool[startOfIntersects];
530 0 : for (Int_t i = 0; i < startOfIntersects; i++) buffer[i] = false;
531 : bool* removeThisEntry = buffer;
532 0 : bool* removeDomainEntry = buffer + count;
533 :
534 0 : AliHLTDomainEntry intersect;
535 :
536 : // The idea behind this algorithm is that we need to add all inclusion domain
537 : // entries from 'domain' to this object that will not be redundant, but for
538 : // the exclusion entries we patch the fEntries rule set by adding the appropriate
539 : // intersections to the end of fEntries.
540 0 : for (Int_t i = 0; i < domain.fEntries.GetEntriesFast(); i++)
541 : {
542 0 : const AliHLTDomainEntry* newEntry = static_cast<const AliHLTDomainEntry*>( domain.fEntries.UncheckedAt(i) );
543 0 : for (Int_t j = 0; j < count; j++)
544 : {
545 0 : const AliHLTDomainEntry* currentEntry = static_cast<const AliHLTDomainEntry*>( fEntries.UncheckedAt(j) );
546 0 : if (currentEntry->Inclusive() and newEntry->Inclusive())
547 : {
548 : // If either entry is a subset of the other then we do not need to add
549 : // both, so make sure to remove the one that is redundant.
550 0 : if (newEntry->SubsetOf(*currentEntry))
551 : {
552 0 : removeDomainEntry[i] = true;
553 0 : }
554 0 : else if (currentEntry->SubsetOf(*newEntry))
555 : {
556 0 : removeThisEntry[j] = true;
557 0 : }
558 : }
559 : else
560 : {
561 0 : if (newEntry->IntersectWith(*currentEntry, intersect))
562 : {
563 : // We can remove all intersections that were already added that will
564 : // become redundant when this intersection is added to fEntries.
565 0 : MarkForDeletionSubsetsOf(intersect, startOfIntersects);
566 :
567 : // Make the new intersection entry an exclusion if the newEntry and
568 : // currentEntry flags are the same.
569 0 : bool exclude = newEntry->Exclusive() == currentEntry->Exclusive();
570 0 : new (fEntries[newIndex++]) AliHLTDomainEntry(exclude, intersect);
571 :
572 : // We can also remove entries that are subsets of another entry in the
573 : // opposite list, since they will be redundant when everything is merged
574 : // together. For example, remove entry x from fEntries if it is a subset
575 : // of entry y in domain.fEntries.
576 0 : if (currentEntry->IdenticalTo(intersect)) removeThisEntry[j] = true;
577 0 : if (newEntry->IdenticalTo(intersect)) removeDomainEntry[i] = true;
578 0 : }
579 : }
580 : }
581 : }
582 :
583 0 : MergeEntries(removeThisEntry, count, removeDomainEntry, startOfIntersects, domain);
584 0 : delete [] buffer;
585 0 : Optimise();
586 : return *this;
587 0 : }
588 :
589 :
590 : AliHLTTriggerDomain& AliHLTTriggerDomain::operator ^= (const AliHLTTriggerDomain& domain)
591 : {
592 : // This operator performs the set union, less the set intersect (something like and xor).
593 : // See header file for more details.
594 :
595 : // Note that we partition the fEntries array into 3 regions for this calculation.
596 : // - 0..entriesCount-1 : contains the initial entries of this trigger domain.
597 : // - entriesCount..startOfIntersects-1 : is space reserved for the new entries
598 : // from 'domain'.
599 : // - startOfIntersects..fEntries.GetEntriesFast()-1 : This will grow as we add
600 : // all the new domain intersections created during the calculation.
601 : //
602 : // Get the number of entries now before we start adding more entries from 'domain'.
603 0 : Int_t count = fEntries.GetEntriesFast();
604 : // Mark the start location for new intersection entries.
605 0 : Int_t startOfIntersects = count + domain.fEntries.GetEntriesFast();
606 : Int_t newIndex = startOfIntersects;
607 :
608 : // Allocate and initialise a single block of memory so that we do not call new twice.
609 0 : bool* buffer = new bool[startOfIntersects];
610 0 : for (Int_t i = 0; i < startOfIntersects; i++) buffer[i] = false;
611 : bool* removeThisEntry = buffer;
612 0 : bool* removeDomainEntry = buffer + count;
613 :
614 0 : AliHLTDomainEntry intersect;
615 :
616 : // This algorithm is similar to the case for the set union (operator |=), except
617 : // that we make sure to remove from the trigger domain all parts where the entries
618 : // from fEntries and domain.fEntries intersect.
619 : // This is done by adding the intersections to the end of fEntries such that they
620 : // effectively remove those overlapping trigger domain entries when calculating
621 : // IncludeInReadout() or Contains().
622 0 : for (Int_t i = 0; i < domain.fEntries.GetEntriesFast(); i++)
623 : {
624 0 : const AliHLTDomainEntry* newEntry = static_cast<const AliHLTDomainEntry*>( domain.fEntries.UncheckedAt(i) );
625 0 : for (Int_t j = 0; j < count; j++)
626 : {
627 0 : const AliHLTDomainEntry* currentEntry = static_cast<const AliHLTDomainEntry*>( fEntries.UncheckedAt(j) );
628 0 : if (newEntry->IntersectWith(*currentEntry, intersect))
629 : {
630 : // We can remove all intersections that were already added that will
631 : // become redundant when this intersection is added to fEntries.
632 0 : MarkForDeletionSubsetsOf(intersect, startOfIntersects);
633 :
634 : // Make the new intersection entry an exclusion if the newEntry and
635 : // currentEntry flags are the same.
636 0 : bool exclude = newEntry->Exclusive() == currentEntry->Exclusive();
637 0 : new (fEntries[newIndex++]) AliHLTDomainEntry(exclude, intersect);
638 :
639 : // We can also remove entries that are subsets of another entry in the
640 : // opposite list, since they will be redundant when everything is merged
641 : // together. For example, remove entry x from fEntries if it is a subset
642 : // of entry y in domain.fEntries.
643 0 : if (currentEntry->IdenticalTo(intersect)) removeThisEntry[j] = true;
644 0 : if (newEntry->IdenticalTo(intersect)) removeDomainEntry[i] = true;
645 0 : }
646 : }
647 : }
648 :
649 0 : MergeEntries(removeThisEntry, count, removeDomainEntry, startOfIntersects, domain);
650 0 : delete [] buffer;
651 0 : Optimise();
652 : return *this;
653 0 : }
654 :
655 :
656 : AliHLTTriggerDomain& AliHLTTriggerDomain::operator -= (const AliHLTTriggerDomain& domain)
657 : {
658 : // This operator performs the set difference.
659 : // See header file for more details.
660 :
661 : // Mark the number of entries in fEntries now before we start adding more
662 : // entries from 'domain' or intersections.
663 0 : Int_t startOfIntersects = fEntries.GetEntriesFast();
664 : Int_t newIndex = startOfIntersects;
665 :
666 0 : AliHLTDomainEntry intersect;
667 :
668 : // To compute the set difference we need to remove all all parts that overlap
669 : // with 'domain'. i.e. we need to find all the intersects between the domain
670 : // entries in fEntries and those in domain.fEntries, and add the intersects
671 : // to the fEntries list, such that they will cancel or remove the overlapping
672 : // parts of the two trigger domains.
673 0 : for (Int_t i = 0; i < domain.fEntries.GetEntriesFast(); i++)
674 : {
675 0 : const AliHLTDomainEntry* checkEntry = static_cast<const AliHLTDomainEntry*>( domain.fEntries.UncheckedAt(i) );
676 0 : if (checkEntry->Inclusive())
677 : {
678 : // For inclusive entries we need to find the overlaps with the inclusive
679 : // entries in fEntries and add exclusive entries that will remove that
680 : // part of the trigger domain set.
681 0 : for (Int_t j = 0; j < startOfIntersects; j++)
682 : {
683 0 : AliHLTDomainEntry* currentEntry = static_cast<AliHLTDomainEntry*>( fEntries.UncheckedAt(j) );
684 :
685 : // We only need to consider the case where both entries are inclusive,
686 : // since an exclusion in fEntries already eliminates those data blocks
687 : // from the trigger domain set.
688 0 : if (currentEntry->Exclusive()) continue;
689 :
690 0 : if (checkEntry->IntersectWith(*currentEntry, intersect))
691 : {
692 : // We can remove all intersections that were already added that will
693 : // become redundant when this intersection is added to fEntries.
694 0 : MarkForDeletionSubsetsOf(intersect, startOfIntersects);
695 :
696 0 : new (fEntries[newIndex++]) AliHLTDomainEntry(kTRUE, intersect);
697 0 : if (currentEntry->IdenticalTo(intersect))
698 : {
699 0 : currentEntry->SetBit(BIT(14), true);
700 : }
701 : }
702 0 : }
703 0 : }
704 : else
705 : {
706 : // For an exclusive entry in 'domain' we need to find the intersections with
707 : // all of fEntries and re-apply these with the same exclude flags.
708 0 : for (Int_t j = 0; j < startOfIntersects; j++)
709 : {
710 0 : AliHLTDomainEntry* currentEntry = static_cast<AliHLTDomainEntry*>( fEntries.UncheckedAt(j) );
711 0 : if (checkEntry->IntersectWith(*currentEntry, intersect))
712 : {
713 : // We can remove all intersections that were already added that will
714 : // become redundant when this intersection is added to fEntries.
715 0 : MarkForDeletionSubsetsOf(intersect, startOfIntersects);
716 :
717 0 : new (fEntries[newIndex++]) AliHLTDomainEntry(currentEntry->Exclusive(), intersect);
718 : }
719 : }
720 : }
721 : }
722 :
723 0 : RemoveMarkedEntries();
724 0 : Optimise();
725 : return *this;
726 0 : }
727 :
728 :
729 : AliHLTTriggerDomain AliHLTTriggerDomain::operator ~ () const
730 : {
731 : // Performs a set complement of the trigger domain.
732 :
733 : // The set complement is calculated by creating a new trigger domain which
734 : // accepts all possible data blocks, and then apply all the trigger domain
735 : // entries (rules / patterns) from top to bottom, but apply them with the
736 : // opposite meaning. For example, this->fEntries contains an inclusive domain
737 : // entry then remove it from the new trigger domain 'result', but if it is
738 : // an exclusion then add it.
739 0 : AliHLTTriggerDomain result;
740 0 : result.Add(kAliHLTAnyDataType);
741 0 : for (Int_t i = 0; i < fEntries.GetEntriesFast(); i++)
742 : {
743 0 : const AliHLTDomainEntry* entry = static_cast<const AliHLTDomainEntry*>( fEntries.UncheckedAt(i) );
744 0 : if (entry->Inclusive())
745 : {
746 0 : result.Remove(*entry);
747 : }
748 : else
749 : {
750 0 : result.Add(*entry);
751 : }
752 : }
753 : return result;
754 0 : }
755 :
756 :
757 : AliHLTTriggerDomain AliHLTTriggerDomain::operator & (const AliHLTTriggerDomain& domain) const
758 : {
759 : // This operator finds the set intersect.
760 : // See header file for more details.
761 :
762 0 : AliHLTTriggerDomain result;
763 : Int_t newIndex = 0;
764 0 : AliHLTDomainEntry intersect;
765 :
766 : // To find the set intersect we need to compare each entry in 'domain' to those
767 : // of fEntries. For each inclusive entry in 'domain' we need to add to the result
768 : // the intersect between it and each entry of fEntries, with the same exclude flag
769 : // value as the domain entry from fEntries.
770 : // However, in principle, for the exclusion entries in 'domain' we just add them
771 : // to the result, since those entries do not form part of the 'domain' trigger
772 : // domain set, so they should not form part of the result (remember any data block
773 : // must be contained in both trigger domains for a set intersect).
774 : // In actual fact we just add the intersect of the exclusion entries in 'domain'
775 : // with those of fEntries to the result. This has the same overall effect, but
776 : // makes sure that all exclusion entries are always subsets of inclusion entries.
777 0 : for (Int_t i = 0; i < domain.fEntries.GetEntriesFast(); i++)
778 : {
779 0 : const AliHLTDomainEntry* checkEntry = static_cast<const AliHLTDomainEntry*>( domain.fEntries.UncheckedAt(i) );
780 0 : if (checkEntry->Inclusive())
781 : {
782 0 : for (Int_t j = 0; j < fEntries.GetEntriesFast(); j++)
783 : {
784 0 : AliHLTDomainEntry* currentEntry = static_cast<AliHLTDomainEntry*>( fEntries.UncheckedAt(j) );
785 0 : if (checkEntry->IntersectWith(*currentEntry, intersect))
786 : {
787 : // We can remove all entries that were already added to the result that
788 : // will become redundent because they are subsets of the new entry.
789 0 : result.MarkForDeletionSubsetsOf(intersect, 0);
790 :
791 0 : new (result.fEntries[newIndex++]) AliHLTDomainEntry(currentEntry->Exclusive(), intersect);
792 : }
793 : }
794 0 : }
795 : else
796 : {
797 0 : for (Int_t j = 0; j < fEntries.GetEntriesFast(); j++)
798 : {
799 0 : AliHLTDomainEntry* currentEntry = static_cast<AliHLTDomainEntry*>( fEntries.UncheckedAt(j) );
800 0 : if (checkEntry->IntersectWith(*currentEntry, intersect))
801 : {
802 : // We can remove all entries that were already added to the result that
803 : // will become redundant because they are subsets of the new entry.
804 0 : result.MarkForDeletionSubsetsOf(intersect, 0);
805 :
806 0 : new (result.fEntries[newIndex++]) AliHLTDomainEntry(kTRUE, intersect);
807 : }
808 : }
809 : }
810 : }
811 :
812 0 : result.RemoveMarkedEntries();
813 0 : result.Optimise();
814 : return result;
815 0 : }
816 :
817 :
818 : bool AliHLTTriggerDomain::operator == (const AliHLTTriggerDomain& domain) const
819 : {
820 : // Checks if two domains are the same.
821 :
822 0 : if (fEntries.GetEntriesFast() != domain.fEntries.GetEntriesFast()) return false;
823 :
824 : // We need to find for each entry in this domain an identical entry in the domain
825 : // that we are comparing to. Both entries cannot have subset entries further down
826 : // in the entries lists. i.e. for fEntries[n], there cannot be any entry fEntries[m]
827 : // that is a subset of fEntries[n] where m > n. Similarly for domain.fEntries.
828 : // If two such entries are matched and they respect the subset rule mentioned,
829 : // then they are marked. We keep finding matching pairs until no more pairs are
830 : // found and check if there are any unmarked entries in either list. If there are
831 : // any unmatched pairs then the two domains do not match.
832 : //
833 : // Note: We use bit 14 in fBits to mark the entries.
834 : // 2) We traverse fEntries from back to front (i.e. from N-1 down to 0) so that
835 : // we are guaranteed that fEntries[n] has no subset entries above it that are
836 : // not marked.
837 0 : for (Int_t i = fEntries.GetEntriesFast() - 1; i >= 0; --i)
838 : {
839 0 : AliHLTDomainEntry* entry1 = static_cast<AliHLTDomainEntry*>(const_cast<TObject*>( fEntries.UncheckedAt(i) ));
840 : // Find identical domain entry in domain.fEntries.
841 : AliHLTDomainEntry* entry2 = NULL;
842 : Int_t entry2index = -1;
843 0 : for (Int_t j = fEntries.GetEntriesFast() - 1; j >= 0; --j)
844 : {
845 0 : AliHLTDomainEntry* current = static_cast<AliHLTDomainEntry*>(const_cast<TObject*>( domain.fEntries.UncheckedAt(j) ));
846 0 : if (current->TestBit(BIT(14))) continue; // skip marked entries.
847 0 : if (entry1->IdenticalTo(*current) and entry1->Exclusive() == current->Exclusive())
848 : {
849 : entry2 = current;
850 : entry2index = j;
851 0 : break;
852 : }
853 0 : }
854 0 : if (entry2 == NULL)
855 : {
856 : // Could not find identical entry in domain.fEntries for fEntries[i] so we
857 : // will have at least one unmatched entry and thus the domains do not match.
858 0 : return false;
859 : }
860 : // Now check if entry2 has any subset entries below it. If it does then
861 : // it fails our ordering requirements and the domains cannot match.
862 0 : for (Int_t j = entry2index + 1; j < fEntries.GetEntriesFast(); ++j)
863 : {
864 0 : const AliHLTDomainEntry* current = static_cast<const AliHLTDomainEntry*>(const_cast<TObject*>( domain.fEntries.UncheckedAt(j) ));
865 0 : if (current->TestBit(BIT(14))) continue; // skip marked entries.
866 0 : if (entry1->SubsetOf(*current)) return false;
867 0 : }
868 : // If we got to this point then entry1 and entry2 are a match and obey the
869 : // ordering rules, so mark them.
870 0 : entry1->SetBit(BIT(14), true);
871 0 : entry2->SetBit(BIT(14), true);
872 0 : }
873 : // At this point we could find all pairs so the domains match.
874 : // We now just need to clear the bits that we set.
875 0 : for (Int_t i = 0; i < fEntries.GetEntriesFast() - 1; ++i)
876 : {
877 0 : fEntries[i]->SetBit(BIT(14), false);
878 0 : domain.fEntries[i]->SetBit(BIT(14), false);
879 : }
880 0 : return true;
881 0 : }
882 :
883 :
884 : AliHLTTriggerDomain::operator AliHLTReadoutList () const
885 : {
886 : // Typecast operator which constructs a readout list from the trigger domain.
887 :
888 0 : AliHLTReadoutList result;
889 0 : for (Int_t deti = 0; deti < AliHLTDAQ::NumberOfDetectors(); deti++)
890 : {
891 0 : for (Int_t i = 0; i < AliHLTDAQ::NumberOfDdls(deti); i++)
892 : {
893 0 : Int_t ddlId = AliHLTDAQ::DdlID(deti, i);
894 0 : AliHLTComponentDataType type = AliHLTComponentDataTypeInitializer(kAliHLTDAQRDOUTDataTypeID, AliHLTDAQ::OnlineName(deti));
895 0 : if (Contains(AliHLTDomainEntry(type, ddlId)))
896 : {
897 0 : result.EnableDDLBit(ddlId);
898 : }
899 0 : }
900 : }
901 : return result;
902 0 : }
903 :
904 :
905 : void AliHLTTriggerDomain::MergeEntries(
906 : const bool* removeThisEntry, Int_t entriesCount,
907 : const bool* removeDomainEntry, Int_t startOfIntersects,
908 : const AliHLTTriggerDomain& domain
909 : )
910 : {
911 : // Merges the entries in this trigger domain with the ones in 'domain', while
912 : // removing all entries that were marked for removal.
913 : // See header file for more information.
914 :
915 : bool anythingRemoved = false;
916 :
917 : // Remember this method is used at the end of the calculation of the binary operators
918 : // and that fEntries is expected to be partitioned into 3 regions.
919 : // - 0..entriesCount-1 : contains the original (initial) entries of this trigger domain.
920 : // - entriesCount..startOfIntersects-1 : is space reserved for the new entries
921 : // from the given trigger domain 'domain' being processed.
922 : // - startOfIntersects..fEntries.GetEntriesFast()-1 : contains all new domain entry
923 : // intersection created and added to fEntries.
924 : //
925 : // First we need to remove all entries marked for removal from the original entries.
926 0 : for (Int_t i = 0; i < entriesCount; i++)
927 : {
928 0 : if (removeThisEntry[i])
929 : {
930 0 : fEntries.RemoveAt(i);
931 : anythingRemoved = true;
932 0 : }
933 : }
934 :
935 : // Now we copy over all the new entries from 'domain' which were not marked for removal
936 : // and indicate anythingRemoved = true since there will now be gaps in the clones array
937 : // that need to be compressed away later.
938 0 : for (Int_t i = 0; i < domain.fEntries.GetEntriesFast(); i++)
939 : {
940 0 : if (removeDomainEntry[i])
941 : {
942 : anythingRemoved = true;
943 0 : }
944 : else
945 : {
946 0 : const AliHLTDomainEntry* newEntry = static_cast<const AliHLTDomainEntry*>( domain.fEntries.UncheckedAt(i) );
947 0 : new (fEntries[entriesCount+i]) AliHLTDomainEntry(*newEntry);
948 : }
949 : }
950 :
951 : // Finally remove all new intersection entries that were marked for removal by
952 : // the MarkForDeletionSubsetsOf method.
953 0 : for (Int_t i = startOfIntersects; i < fEntries.GetEntriesFast(); i++)
954 : {
955 0 : const AliHLTDomainEntry* ientry = static_cast<const AliHLTDomainEntry*>( fEntries.UncheckedAt(i) );
956 0 : if (ientry->TestBit(BIT(14)))
957 : {
958 0 : fEntries.RemoveAt(i);
959 : anythingRemoved = true;
960 0 : }
961 : }
962 0 : if (anythingRemoved) fEntries.Compress();
963 0 : }
964 :
965 :
966 : void AliHLTTriggerDomain::MarkForDeletionSubsetsOf(const AliHLTDomainEntry& entry, Int_t min)
967 : {
968 : // Marks for deletion all the entries in this trigger domain that are subsets
969 : // of the given entry.
970 : // See header file for more information.
971 :
972 0 : AliHLTDomainEntry intersect;
973 0 : for (Int_t i = min; i < fEntries.GetEntriesFast(); i++)
974 : {
975 0 : AliHLTDomainEntry* ientry = static_cast<AliHLTDomainEntry*>( fEntries.UncheckedAt(i) );
976 0 : if (ientry->TestBit(BIT(14))) continue;
977 0 : if (ientry->SubsetOf(entry))
978 : {
979 0 : ientry->SetBit(BIT(14), true);
980 : }
981 0 : }
982 0 : }
983 :
984 :
985 : void AliHLTTriggerDomain::RemoveMarkedEntries()
986 : {
987 : // Removes all entries in this trigger domain which were marked for removal.
988 : // See header file for more information.
989 :
990 : bool anythingRemoved = false;
991 0 : for (Int_t i = 0; i < fEntries.GetEntriesFast(); i++)
992 : {
993 0 : const AliHLTDomainEntry* ientry = static_cast<const AliHLTDomainEntry*>( fEntries.UncheckedAt(i) );
994 0 : if (ientry->TestBit(BIT(14)))
995 : {
996 0 : fEntries.RemoveAt(i);
997 : anythingRemoved = true;
998 0 : }
999 : }
1000 0 : if (anythingRemoved) fEntries.Compress();
1001 0 : }
1002 :
1003 :
1004 : void AliHLTTriggerDomain::Optimise()
1005 : {
1006 : // Removes redundant trigger domain entries from the trigger domain.
1007 : // See header file for more information.
1008 :
1009 0 : AliHLTDomainEntry intersect;
1010 :
1011 : // Check that the first entry is not and exclusion which would be redundent.
1012 0 : if (fEntries.GetEntriesFast() == 0) return;
1013 0 : AliHLTDomainEntry* firstEntry = static_cast<AliHLTDomainEntry*>( fEntries[0] );
1014 0 : if (firstEntry->Exclusive()) firstEntry->SetBit(BIT(14), true);
1015 :
1016 0 : for (Int_t i = 1; i < fEntries.GetEntriesFast(); i++)
1017 : {
1018 0 : AliHLTDomainEntry* ientry = static_cast<AliHLTDomainEntry*>( fEntries.UncheckedAt(i) );
1019 :
1020 : // For the i'th entry in fEntries, compare it in reverse order with all other
1021 : // entries that are before it and look for redundant ones, i.e. that are subsets
1022 : // of the i'th entry.
1023 0 : for (Int_t j = i-1; j >= 0; j--)
1024 : {
1025 0 : AliHLTDomainEntry* jentry = static_cast<AliHLTDomainEntry*>( fEntries.UncheckedAt(j) );
1026 0 : if (jentry->TestBit(BIT(14))) continue;
1027 : // Find entries that intersect
1028 0 : if (jentry->SubsetOf(*ientry))
1029 : {
1030 : // jentry is a subset of ientry so it is redundant because for all values
1031 : // ientry will override jentry when calling IncludeInReadout.
1032 0 : jentry->SetBit(BIT(14), true);
1033 : }
1034 0 : else if (*ientry == *jentry)
1035 : {
1036 : // If intersecting entries have opposite exclude flags then search no further,
1037 : // we know that we will need this entry for correct behaviour of IncludeInReadout.
1038 0 : if (ientry->Inclusive() == jentry->Exclusive()) goto processNextEntry;
1039 :
1040 0 : if (ientry->SubsetOf(*jentry))
1041 : {
1042 0 : ientry->SetBit(BIT(14), true);
1043 0 : goto processNextEntry;
1044 : }
1045 : }
1046 0 : }
1047 :
1048 : // If we got to this point then we hit the top of the trigger domain rules
1049 : // (pattern matching) list without hitting any and overlapping entries.
1050 : // So now we need to check if ientry is an exclusion. If it is, then it is
1051 : // redundant and we can mark it for removal.
1052 0 : if (ientry->Exclusive()) ientry->SetBit(BIT(14), true);
1053 :
1054 : processNextEntry: ;
1055 : }
1056 :
1057 0 : RemoveMarkedEntries();
1058 0 : }
1059 :
1060 : const AliHLTDomainEntry& AliHLTTriggerDomain::operator[](int index) const
1061 : {
1062 : // Access individual entry of the domain
1063 0 : return static_cast<AliHLTDomainEntry&>(*fEntries[index]);
1064 : }
|