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 AliHLTGlobalTriggerComponent.cxx
19 /// @author Artur Szostak <artursz@iafrica.com>
21 /// @brief Implementation of the AliHLTGlobalTriggerComponent component class.
23 /// The AliHLTGlobalTriggerComponentComponent class applies the global HLT trigger to all
24 /// trigger information produced by components deriving from AliHLTTrigger.
26 #include "AliHLTGlobalTriggerComponent.h"
27 #include "AliHLTGlobalTriggerDecision.h"
28 #include "AliHLTGlobalTrigger.h"
29 #include "AliHLTGlobalTriggerConfig.h"
30 #include "AliHLTTriggerMenu.h"
31 #include "AliHLTCTPData.h"
32 #include "AliCDBManager.h"
33 #include "AliCDBStorage.h"
34 #include "AliCDBEntry.h"
39 #include "TClonesArray.h"
40 #include "TObjString.h"
42 #include "TInterpreter.h"
48 ClassImp(AliHLTGlobalTriggerComponent)
50 const char* AliHLTGlobalTriggerComponent::fgkTriggerMenuCDBPath = "HLT/ConfigHLT/HLTGlobalTrigger";
53 AliHLTGlobalTriggerComponent::AliHLTGlobalTriggerComponent() :
57 fRuntimeCompile(true),
58 fSkipCTPCounters(false),
62 // Default constructor.
64 ClearInfoForNewEvent(false);
68 AliHLTGlobalTriggerComponent::~AliHLTGlobalTriggerComponent()
70 // Default destructor.
72 if (fTrigger != NULL) delete fTrigger;
75 fCTPDecisions->Delete();
81 void AliHLTGlobalTriggerComponent::GetOutputDataSize(unsigned long& constBase, double& inputMultiplier)
83 // Returns the output data size estimate.
85 // the real size can actually not be determined here since an arbitrary
86 // number of objects can be part of the decision
87 // collect the known ones and add a margin
89 constBase += 2*sizeof(AliHLTGlobalTriggerDecision);
90 constBase += sizeof(AliHLTCTPData);
91 constBase += 5*sizeof(AliHLTTriggerDecision);
96 Int_t AliHLTGlobalTriggerComponent::DoInit(int argc, const char** argv)
98 // Initialises the global trigger component.
101 const char* configFileName = NULL;
102 const char* codeFileName = NULL;
104 TClonesArray includePaths(TObjString::Class());
105 TClonesArray includeFiles(TObjString::Class());
107 for (int i = 0; i < argc; i++)
109 if (strcmp(argv[i], "-config") == 0)
111 if (configFileName != NULL)
113 HLTWarning("Trigger configuration macro was already specified."
114 " Will replace previous value given by -config."
119 HLTError("The trigger configuration macro filename was not specified." );
122 configFileName = argv[i+1];
127 if (strcmp(argv[i], "-includepath") == 0)
131 HLTError("The include path was not specified." );
134 new (includePaths[includePaths.GetEntriesFast()]) TObjString(argv[i+1]);
139 if (strcmp(argv[i], "-include") == 0)
143 HLTError("The include file name was not specified." );
146 new (includeFiles[includeFiles.GetEntriesFast()]) TObjString(argv[i+1]);
151 if (strcmp(argv[i], "-debug") == 0)
153 if (fDebugMode == true)
155 HLTWarning("The debug flag was already specified. Ignoring this instance.");
161 if (strcmp(argv[i], "-cint") == 0)
163 fRuntimeCompile = false;
167 if (strcmp(argv[i], "-usecode") == 0)
169 if (codeFileName != NULL)
171 HLTWarning("Custom trigger code file was already specified."
172 " Will replace previous value given by -usecode."
177 HLTError("The custom trigger code filename was not specified." );
180 codeFileName = argv[i+1];
183 HLTError("The custom trigger class name was not specified." );
186 classname = argv[i+2];
191 if (strcmp(argv[i], "-skipctp") == 0)
193 HLTInfo("Skipping CTP counters in trigger decision");
194 fSkipCTPCounters=true;
198 HLTError("Unknown option '%s'.", argv[i]);
202 const AliHLTTriggerMenu* menu = NULL;
203 if (configFileName != NULL)
206 cmd += configFileName;
207 gROOT->ProcessLine(cmd);
208 menu = AliHLTGlobalTriggerConfig::Menu();
211 // Try load the trigger menu from the CDB if it is not loaded yet with the
213 if (menu == NULL and AliCDBManager::Instance() != NULL)
215 AliCDBStorage* store = AliCDBManager::Instance()->GetDefaultStorage();
218 HLTError("Could not get the the default storage for the CDB.");
221 Int_t version = store->GetLatestVersion(fgkTriggerMenuCDBPath, GetRunNo());
222 Int_t subVersion = store->GetLatestSubVersion(fgkTriggerMenuCDBPath, GetRunNo(), version);
223 AliCDBEntry* entry = AliCDBManager::Instance()->Get(fgkTriggerMenuCDBPath, GetRunNo(), version, subVersion);
226 HLTError("Could not get the CDB entry for \"%s\".", fgkTriggerMenuCDBPath);
229 TObject* obj = entry->GetObject();
232 HLTError("Configuration object for \"%s\" is missing.", fgkTriggerMenuCDBPath);
235 if (obj->IsA() != AliHLTTriggerMenu::Class())
237 HLTError("Wrong type for configuration object in \"%s\". Found a %s but we expect a AliHLTTriggerMenu.",
238 fgkTriggerMenuCDBPath, obj->ClassName()
242 menu = dynamic_cast<AliHLTTriggerMenu*>(obj);
247 HLTError("No trigger menu configuration found or specified.");
252 if (codeFileName == NULL)
254 HLTDebug("Generating custom HLT trigger class.");
255 result = GenerateTrigger(menu, classname, includePaths, includeFiles);
259 HLTDebug("Loading HLT trigger class from file '%s'.", codeFileName);
260 result = LoadTriggerClass(codeFileName, includePaths);
262 if (result != 0) return result;
264 fTrigger = AliHLTGlobalTrigger::CreateNew(classname.Data());
265 if (fTrigger == NULL)
267 HLTError("Could not create a new instance of '%s'.", classname.Data());
271 fTrigger->FillFromMenu(*menu);
272 fTrigger->ResetCounters(menu->NumberOfItems());
274 // setup the CTP accounting in AliHLTComponent
277 // Set the default values from the trigger menu.
278 SetDescription(menu->DefaultDescription());
279 SetTriggerDomain(menu->DefaultTriggerDomain());
285 Int_t AliHLTGlobalTriggerComponent::DoDeinit()
287 // Cleans up the global trigger component.
289 if (fTrigger != NULL)
295 if (!fCodeFileName.IsNull() && gSystem->AccessPathName(fCodeFileName)==0 && !fDebugMode) {
296 fCodeFileName.ReplaceAll(".cxx", "*");
297 TString command="rm "; command+=fCodeFileName;
298 gSystem->Exec(command);
303 fCTPDecisions->Delete();
304 delete fCTPDecisions;
312 AliHLTComponent* AliHLTGlobalTriggerComponent::Spawn()
314 // Creates a new object instance.
316 return new AliHLTGlobalTriggerComponent;
320 int AliHLTGlobalTriggerComponent::DoTrigger()
322 // This method will apply the global trigger decision.
324 if (fTrigger == NULL)
326 HLTFatal("Global trigger implementation object is NULL!");
330 AliHLTUInt32_t eventType=0;
331 if (!IsDataEvent(&eventType)) {
332 if (eventType==gkAliEventTypeEndOfRun) PrintStatistics(fTrigger, kHLTLogImportant, 0);
336 fTrigger->NewEvent();
338 // Fill in the input data.
339 const TObject* obj = GetFirstInputObject();
342 fTrigger->Add(obj, GetDataType(), GetSpecification());
343 obj = GetNextInputObject();
346 // add trigger decisions for every CTP class
347 const AliHLTCTPData* pCTPData=CTPData();
349 AddCTPDecisions(fTrigger, pCTPData, GetTriggerData());
352 // Calculate the global trigger result and trigger domain, then create and push
353 // back the new global trigger decision object.
355 AliHLTTriggerDomain triggerDomain;
356 bool triggerResult = fTrigger->CalculateTriggerDecision(triggerDomain, description);
358 AliHLTGlobalTriggerDecision decision(
360 // The following will cause the decision to be generated with default values
361 // (set in fTriggerDomain and fDescription) if the trigger result is false.
362 (triggerResult == true) ? triggerDomain : GetTriggerDomain(),
363 (triggerResult == true) ? description.Data() : GetDescription()
366 // mask the readout list according to the CTP trigger
367 // if the classes have been initialized (mask non-zero)
368 if (pCTPData && pCTPData->Mask()) {
369 AliHLTEventDDL eventDDL=pCTPData->ReadoutList(*GetTriggerData());
370 AliHLTReadoutList ctpreadout(eventDDL);
371 ctpreadout.Enable(AliHLTReadoutList::kHLT);
372 AliHLTReadoutList maskedList=decision.ReadoutList();
373 maskedList.AndEq(ctpreadout);
374 decision.ReadoutList(maskedList);
377 decision.SetCounters(fTrigger->Counters(), GetEventCount()+1);
378 static UInt_t lastTime=0;
380 if (time.Get()-lastTime>5) {
382 PrintStatistics(fTrigger);
385 // Add the input objects used to the global decision.
386 obj = GetFirstInputObject();
389 if (obj->IsA() == AliHLTTriggerDecision::Class())
391 decision.AddTriggerInput( *static_cast<const AliHLTTriggerDecision*>(obj) );
395 decision.AddInputObject(obj);
397 obj = GetNextInputObject();
400 if (!fSkipCTPCounters && CTPData()) decision.AddInputObject(CTPData());
402 CreateEventDoneReadoutFilter(decision.TriggerDomain(), 3);
403 CreateEventDoneReadoutFilter(decision.TriggerDomain(), 4);
404 TriggerEvent(&decision);
409 int AliHLTGlobalTriggerComponent::GenerateTrigger(
410 const AliHLTTriggerMenu* menu, TString& name,
411 const TClonesArray& includePaths, const TClonesArray& includeFiles
414 // Generates the global trigger class that will implement the specified trigger menu.
415 // See header for more details.
417 // Create a new UUID and replace the '-' characters with '_' to make it a valid
420 TString uuidstr = uuid.AsString();
421 for (Int_t i = 0; i < uuidstr.Length(); i++)
423 if (uuidstr[i] == '-') uuidstr[i] = '_';
426 // Create the name of the new class.
427 name = "AliHLTGlobalTriggerImpl_";
429 fCodeFileName = name + ".cxx";
431 // Open a text file to write the code and generate the new class.
432 fstream code(fCodeFileName.Data(), ios_base::out | ios_base::trunc);
435 HLTError("Could not open file '%s' for writing.", fCodeFileName.Data());
439 TClonesArray symbols(AliHLTTriggerMenuSymbol::Class());
440 int result = BuildSymbolList(menu, symbols);
441 if (result != 0) return result;
443 //code << "#ifndef __CINT__" << endl;
444 code << "#include <cstring>" << endl;
445 code << "#include \"TString.h\"" << endl;
446 code << "#include \"TClonesArray.h\"" << endl;
447 code << "#include \"AliHLTGlobalTrigger.h\"" << endl;
448 code << "#include \"AliHLTGlobalTriggerDecision.h\"" << endl;
449 code << "#include \"AliHLTDomainEntry.h\"" << endl;
450 code << "#include \"AliHLTTriggerDomain.h\"" << endl;
451 code << "#include \"AliHLTReadoutList.h\"" << endl;
452 code << "#include \"AliHLTTriggerMenu.h\"" << endl;
453 code << "#include \"AliHLTTriggerMenuItem.h\"" << endl;
454 code << "#include \"AliHLTTriggerMenuSymbol.h\"" << endl;
455 //code << "#endif //__CINT__" << endl;
457 // Add any include files that were specified on the command line.
458 for (Int_t i = 0; i < includeFiles.GetEntriesFast(); i++)
460 TString file = static_cast<TObjString*>(includeFiles.UncheckedAt(i))->String();
461 code << "#include \"" << file.Data() << "\"" << endl;
464 code << "class " << name << " : public AliHLTGlobalTrigger" << endl;
466 code << "public:" << endl;
468 code << " " << name << "() : AliHLTGlobalTrigger()";
469 // Write the symbols in the trigger menu in the initialisation list.
470 for (Int_t i = 0; i < symbols.GetEntriesFast(); i++)
473 AliHLTTriggerMenuSymbol* symbol = static_cast<AliHLTTriggerMenuSymbol*>( symbols.UncheckedAt(i) );
474 code << " " << symbol->Name() << "()," << endl;
475 if (strcmp(symbol->ObjectClass(), "AliHLTTriggerDecision") == 0)
477 code << " " << symbol->Name() << "TriggerDomain()," << endl;
479 code << " " << symbol->Name() << "DomainEntry(kAliHLTAnyDataType)";
481 for (UInt_t i = 0; i < menu->NumberOfItems(); i++)
483 code << "," << endl << " fMenuItemDescription" << i << "()";
485 code << endl << " {" << endl;
488 code << " SetLocalLoggingLevel(kHLTLogAll);" << endl;
489 code << " HLTInfo(\"Creating new instance at %p.\", this);" << endl;
491 code << " }" << endl;
493 code << " virtual ~" << name << "() {" << endl;
496 code << " HLTInfo(\"Deleting instance at %p.\", this);" << endl;
498 code << " }" << endl;
500 // Generate the FillFromMenu method.
501 code << " virtual void FillFromMenu(const AliHLTTriggerMenu& menu) {" << endl;
504 code << " HLTDebug(\"Filling description entries from trigger menu for global trigger %p.\", this);" << endl;
506 for (UInt_t i = 0; i < menu->NumberOfItems(); i++)
508 code << " fMenuItemDescription" << i << " = (menu.Item(" << i
509 << ") != NULL) ? menu.Item(" << i << ")->Description() : \"\";" << endl;
513 code << " HLTDebug(\"Finished filling description entries from trigger menu.\");" << endl;
514 code << " HLTDebug(\"Filling domain entries from trigger menu symbols for global trigger %p.\", this);" << endl;
516 code << " for (Int_t i = 0; i < menu.SymbolArray().GetEntriesFast(); i++) {" << endl;
517 code << " const AliHLTTriggerMenuSymbol* symbol = dynamic_cast<const"
518 " AliHLTTriggerMenuSymbol*>(menu.SymbolArray().UncheckedAt(i));" << endl;
519 code << " if (symbol == NULL) continue;" << endl;
520 for (Int_t i = 0; i < symbols.GetEntriesFast(); i++)
522 AliHLTTriggerMenuSymbol* symbol = static_cast<AliHLTTriggerMenuSymbol*>( symbols.UncheckedAt(i) );
523 code << " if (strcmp(symbol->Name(), \"" << symbol->RealName() << "\") == 0) {" << endl;
526 code << " HLTDebug(\"Assinging domain entry value to match for symbol '%s' to '%s'.\","
527 " symbol->Name(), symbol->BlockType().AsString().Data());" << endl;
529 code << " " << symbol->Name() << "DomainEntry = symbol->BlockType();" << endl;
530 code << " continue;" << endl;
531 code << " }" << endl;
533 code << " }" << endl;
536 code << " HLTDebug(\"Finished filling domain entries from trigger menu symbols.\");" << endl;
538 code << " }" << endl;
540 // Generate the NewEvent method.
541 code << " virtual void NewEvent() {" << endl;
544 code << " HLTDebug(\"New event for global trigger object %p, initialising variables to default values.\", this);" << endl;
546 // Write code to initialise the symbols in the trigger menu to their default values.
547 for (Int_t i = 0; i < symbols.GetEntriesFast(); i++)
549 AliHLTTriggerMenuSymbol* symbol = static_cast<AliHLTTriggerMenuSymbol*>( symbols.UncheckedAt(i) );
550 code << " " << symbol->Name() << " = " << symbol->DefaultValue() << ";" << endl;
551 if (strcmp(symbol->ObjectClass(), "AliHLTTriggerDecision") == 0)
553 code << " " << symbol->Name() << "TriggerDomain.Clear();" << endl;
558 code << " HLTDebug(\"Finished initialising variables.\");" << endl;
560 code << " }" << endl;
562 // Generate the Add method.
563 code << " virtual void Add(const TObject* _object_, const AliHLTComponentDataType& _type_, AliHLTUInt32_t _spec_) {" << endl;
564 code << " AliHLTDomainEntry _type_spec_(_type_, _spec_);" << endl;
567 code << " HLTDebug(\"Adding TObject %p, with class name '%s' from data block"
568 " '%s', to global trigger object %p\", _object_, _object_->ClassName(),"
569 " _type_spec_.AsString().Data(), this);" << endl;
570 code << " _object_->Print();" << endl;
571 code << " bool _object_assigned_ = false;" << endl;
573 for (Int_t i = 0; i < symbols.GetEntriesFast(); i++)
575 // Write code to check if the block type, specification and class name is correct.
576 // Then write code to assign the variable from the input object.
577 AliHLTTriggerMenuSymbol* symbol = static_cast<AliHLTTriggerMenuSymbol*>( symbols.UncheckedAt(i) );
578 TString expr = symbol->AssignExpression();
579 if (expr == "") continue; // Skip entries that have no assignment expression.
580 bool isTrigDecision = strcmp(symbol->ObjectClass(), "AliHLTTriggerDecision") == 0;
585 code << " HLTDebug(\"Trying to match input object to class '"
586 << symbol->ObjectClass() << "', trigger name '" << symbol->RealName()
587 << "' and block type '%s'\", " << symbol->Name()
588 << "DomainEntry.AsString().Data());" << endl;
592 code << " HLTDebug(\"Trying to match input object to class '"
593 << symbol->ObjectClass() << "' and block type '%s'\", "
594 << symbol->Name() << "DomainEntry.AsString().Data());" << endl;
597 code << " const " << symbol->ObjectClass() << "* " << symbol->Name()
598 << "_object_ = dynamic_cast<const " << symbol->ObjectClass()
599 << "*>(_object_);" << endl;
600 code << " if (" << symbol->Name() << "_object_ != NULL and ";
603 code << "strcmp(" << symbol->Name() << "_object_->Name(), \""
604 << symbol->RealName() << "\") == 0 and ";
606 code << symbol->Name() << "DomainEntry == _type_spec_) {" << endl;
607 TString fullname = symbol->Name();
608 fullname += "_object_";
609 expr.ReplaceAll("this", fullname);
610 code << " this->" << symbol->Name() << " = " << expr.Data() << ";" << endl;
613 code << " this->" << symbol->Name() << "TriggerDomain = "
614 << fullname.Data() << "->TriggerDomain();" << endl;
618 code << " HLTDebug(\"Added TObject %p with class name '%s' to variable "
619 << symbol->Name() << "\", _object_, _object_->ClassName());" << endl;
620 code << " _object_assigned_ = true;" << endl;
622 code << " }" << endl;
626 code << " if (not _object_assigned_) HLTDebug(\"Did not assign TObject %p"
627 " with class name '%s' to any variable.\", _object_, _object_->ClassName());"
630 code << " }" << endl;
632 // Generate the CalculateTriggerDecision method.
633 code << " virtual bool CalculateTriggerDecision(AliHLTTriggerDomain& _domain_, TString& _description_) {" << endl;
636 code << " HLTDebug(\"Calculating global HLT trigger result with trigger object at %p.\", this);" << endl;
638 code << " bool result=false;" << endl;
639 for (UInt_t i = 0; i < menu->NumberOfItems(); i++)
641 const AliHLTTriggerMenuItem* item = menu->Item(i);
642 TString triggerCondision = item->TriggerCondision();
643 TString mergeExpr = item->MergeExpression();
644 for (Int_t j = 0; j < symbols.GetEntriesFast(); j++)
646 AliHLTTriggerMenuSymbol* symbol = static_cast<AliHLTTriggerMenuSymbol*>( symbols.UncheckedAt(j) );
647 if (strcmp(symbol->ObjectClass(), "AliHLTTriggerDecision") != 0) continue;
648 TString newname = symbol->Name();
649 newname += "TriggerDomain";
650 mergeExpr.ReplaceAll(symbol->RealName(), newname);
651 triggerCondision.ReplaceAll(symbol->RealName(), symbol->Name());
655 code << " HLTDebug(\"Trying trigger condition " << i
656 << " (Description = '%s').\", fMenuItemDescription" << i << ".Data());"
659 code << " if (" << triggerCondision << ") {" << endl;
660 code << " IncrementCounter(" << i << ");" << endl;
661 const char* indentation = "";
662 if (item->PreScalar() != 0)
665 code << " if ((GetCounter(" << i << ") % " << item->PreScalar() << ") == 1) {" << endl;
667 code << indentation << " _domain_ |= " << mergeExpr.Data() << ";" << endl;
668 code << indentation << " if (!_description_.IsNull()) _description_+= \",\";" << endl;
669 code << indentation << " _description_ += fMenuItemDescription" << i << ";" << endl;
672 code << indentation << " HLTDebug(\"Matched trigger condition " << i
673 << " (Description = '%s').\", fMenuItemDescription" << i << ".Data());" << endl;
675 code << indentation << " result=true;" << endl;
676 if (item->PreScalar() != 0)
678 code << " }" << endl;
680 code << " }" << endl;
682 code << " return result;" << endl;
683 code << " }" << endl;
685 // Generate the custom Factory class.
686 code << " class FactoryImpl : public AliHLTGlobalTrigger::Factory" << endl;
687 code << " {" << endl;
688 code << " public:" << endl;
689 code << " virtual const char* ClassName() const {" << endl;
690 code << " return \"" << name << "\";" << endl;
691 code << " }" << endl;
692 code << " virtual AliHLTGlobalTrigger* New() const {" << endl;
693 code << " return new " << name << "();" << endl;
694 code << " }" << endl;
695 code << " };" << endl;
697 code << "private:" << endl;
698 // Add the symbols in the trigger menu to the list of private variables.
699 for (Int_t i = 0; i < symbols.GetEntriesFast(); i++)
701 AliHLTTriggerMenuSymbol* symbol = static_cast<AliHLTTriggerMenuSymbol*>( symbols.UncheckedAt(i) );
702 code << " " << symbol->Type() << " " << symbol->Name() << ";" << endl;
703 if (strcmp(symbol->ObjectClass(), "AliHLTTriggerDecision") == 0)
705 code << " AliHLTTriggerDomain " << symbol->Name() << "TriggerDomain;" << endl;
707 code << " AliHLTDomainEntry " << symbol->Name() << "DomainEntry;" << endl;
709 for (UInt_t i = 0; i < menu->NumberOfItems(); i++)
711 code << " TString fMenuItemDescription" << i << ";" << endl;
713 code << "};" << endl;
715 // Write a global object for the Factory class for automatic registration.
716 code << "namespace {" << endl;
717 code << " const " << name << "::FactoryImpl gkFactoryImpl;" << endl;
718 code << "};" << endl;
722 // Now we need to compile and load the new class.
723 result = LoadTriggerClass(fCodeFileName, includePaths);
728 int AliHLTGlobalTriggerComponent::LoadTriggerClass(
729 const char* filename, const TClonesArray& includePaths
732 // Loads the code for a custom global trigger class implementation on the fly.
734 TString compiler = gSystem->GetBuildCompilerVersion();
735 if (fRuntimeCompile && (compiler.Contains("gcc") or compiler.Contains("icc")))
738 #if defined(PKGINCLUDEDIR)
739 // this is especially for the HLT build system where the package is installed
740 // in a specific directory including proper treatment of include files
741 includePath.Form("-I%s", PKGINCLUDEDIR);
743 // the default AliRoot behavior, all include files can be found in the
744 // $ALICE_ROOT subfolders
745 includePath = "-I${ALICE_ROOT}/include -I${ALICE_ROOT}/HLT/BASE -I${ALICE_ROOT}/HLT/trigger";
747 HLTDebug("using include settings: %s", includePath.Data());
748 // Add any include paths that were specified on the command line.
749 for (Int_t i = 0; i < includePaths.GetEntriesFast(); i++)
751 TString path = static_cast<TObjString*>(includePaths.UncheckedAt(i))->String();
755 gSystem->SetIncludePath(includePath);
756 gSystem->SetFlagsOpt("-O3 -DNDEBUG");
757 gSystem->SetFlagsDebug("-g3 -DDEBUG -D__DEBUG");
762 result = gSystem->CompileMacro(filename, "g");
766 result = gSystem->CompileMacro(filename, "O");
770 HLTFatal("Could not compile and load global trigger menu implementation.");
776 // If we do not support the compiler then try interpret the class instead.
779 Int_t errorcode = TInterpreter::kNoError;
780 gROOT->ProcessLine(cmd, &errorcode);
781 if (errorcode != TInterpreter::kNoError)
783 HLTFatal("Could not load interpreted global trigger menu implementation"
784 " (Interpreter error code = %d).",
795 int AliHLTGlobalTriggerComponent::FindSymbol(const char* name, const TClonesArray& list)
797 // Searches for the named symbol in the given list.
798 // See header for more details.
800 for (int i = 0; i < list.GetEntriesFast(); i++)
802 const AliHLTTriggerMenuSymbol* symbol = dynamic_cast<const AliHLTTriggerMenuSymbol*>( list.UncheckedAt(i) );
803 if (symbol == NULL) continue;
804 if (strcmp(symbol->Name(), name) == 0) return i;
810 int AliHLTGlobalTriggerComponent::BuildSymbolList(const AliHLTTriggerMenu* menu, TClonesArray& list)
812 // Builds the list of symbols to use in the custom global trigger menu
813 // implementation class.
814 // See header for more details.
816 for (UInt_t i = 0; i < menu->NumberOfSymbols(); i++)
818 const AliHLTTriggerMenuSymbol* symbol = menu->Symbol(i);
819 if (FindSymbol(symbol->Name(), list) != -1)
821 HLTError("Multiple symbols with the name '%s' defined in the trigger menu.", symbol->Name());
824 new (list[list.GetEntriesFast()]) AliHLTTriggerMenuSymbol(*symbol);
827 TRegexp exp("[_a-zA-Z][-_a-zA-Z0-9]*");
828 TRegexp hexexp("x[a-fA-F0-9]+");
829 for (UInt_t i = 0; i < menu->NumberOfItems(); i++)
831 const AliHLTTriggerMenuItem* item = menu->Item(i);
832 TString str = item->TriggerCondision();
837 Ssiz_t pos = exp.Index(str, &length, start);
838 if (pos == kNPOS) break;
841 // Check if there is a numerical character before the found
842 // regular expression. If so, then the symbol is not a valid one
843 // and should be skipped.
846 bool notValid = false;
849 case '0': case '1': case '2': case '3': case '4':
850 case '5': case '6': case '7': case '8': case '9':
857 if (notValid) continue;
859 TString s = str(pos, length);
861 if (s == "and" or s == "and_eq" or s == "bitand" or s == "bitor" or
862 s == "compl" or s == "not" or s == "not_eq" or s == "or" or
863 s == "or_eq" or s == "xor" or s == "xor_eq" or s == "true" or
867 // Ignore iso646.h and other keywords.
871 if (FindSymbol(s.Data(), list) == -1)
873 AliHLTTriggerMenuSymbol newSymbol;
874 newSymbol.Name(s.Data());
875 newSymbol.Type("bool");
876 newSymbol.ObjectClass("AliHLTTriggerDecision");
877 newSymbol.AssignExpression("this->Result()");
878 newSymbol.DefaultValue("false");
879 new (list[list.GetEntriesFast()]) AliHLTTriggerMenuSymbol(newSymbol);
882 while (start < str.Length());
888 int AliHLTGlobalTriggerComponent::PrintStatistics(const AliHLTGlobalTrigger* pTrigger, AliHLTComponentLogSeverity level, int offset) const
890 // print some statistics
891 int totalEvents=GetEventCount()+offset;
892 for (int i=0; i<pTrigger->Counters().GetSize(); i++) {
893 ULong64_t count=pTrigger->Counters()[i];
895 if (totalEvents>0) ratio=100*(float)count/totalEvents;
896 HLTLog(level, "Item %d: total events: %d - triggered events: %llu (%.1f%%)", i, totalEvents, count, ratio);
901 int AliHLTGlobalTriggerComponent::AddCTPDecisions(AliHLTGlobalTrigger* pTrigger, const AliHLTCTPData* pCTPData, const AliHLTComponentTriggerData* trigData)
903 // add trigger decisions for the valid CTP classes
904 if (!pCTPData || !pTrigger) return 0;
906 AliHLTUInt64_t triggerMask=pCTPData->Mask();
907 AliHLTUInt64_t bit0=0x1;
908 if (!fCTPDecisions) {
909 fCTPDecisions=new TClonesArray(AliHLTTriggerDecision::Class(), gkNCTPTriggerClasses);
910 if (!fCTPDecisions) return -ENOMEM;
912 fCTPDecisions->ExpandCreate(gkNCTPTriggerClasses);
913 for (int i=0; i<gkNCTPTriggerClasses; i++) {
914 const char* name=pCTPData->Name(i);
915 if (triggerMask&(bit0<<i) && name) {
916 AliHLTTriggerDecision* pDecision=dynamic_cast<AliHLTTriggerDecision*>(fCTPDecisions->At(i));
919 delete fCTPDecisions;
923 pDecision->Name(name);
928 for (int i=0; i<gkNCTPTriggerClasses; i++) {
929 const char* name=pCTPData->Name(i);
930 if ((triggerMask&(bit0<<i))==0 || name==NULL) continue;
931 AliHLTTriggerDecision* pDecision=dynamic_cast<AliHLTTriggerDecision*>(fCTPDecisions->At(i));
932 HLTDebug("updating CTP trigger decision %d %s (%p casted %p)", i, name, fCTPDecisions->At(i), pDecision);
933 if (!pDecision) return -ENOENT;
936 if (trigData) result=pCTPData->EvaluateCTPTriggerClass(name, *trigData);
937 else result=pCTPData->EvaluateCTPTriggerClass(name);
938 pDecision->Result(result);
939 pDecision->TriggerDomain().Clear();
940 if (trigData) pDecision->TriggerDomain().Add(pCTPData->ReadoutList(*trigData));
941 else pDecision->TriggerDomain().Add(pCTPData->ReadoutList());
943 pTrigger->Add(fCTPDecisions->At(i), kAliHLTDataTypeTriggerDecision, kAliHLTVoidDataSpec);