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"
52 ClassImp(AliHLTGlobalTriggerComponent)
54 const char* AliHLTGlobalTriggerComponent::fgkTriggerMenuCDBPath = "HLT/ConfigHLT/HLTGlobalTrigger";
60 * This method is used as a comparison functor with the STL sort routines.
62 bool AliHLTDescendingNumbers(UInt_t a, UInt_t b)
69 AliHLTGlobalTriggerComponent::AliHLTGlobalTriggerComponent() :
73 fRuntimeCompile(true),
74 fDeleteCodeFile(false),
78 fBufferSizeConst(2*(sizeof(AliHLTGlobalTriggerDecision) + sizeof(AliHLTReadoutList))),
79 fBufferSizeMultiplier(1.),
80 fIncludePaths(TObjString::Class()),
81 fIncludeFiles(TObjString::Class()),
86 // Default constructor.
88 ClearInfoForNewEvent(false);
92 AliHLTGlobalTriggerComponent::~AliHLTGlobalTriggerComponent()
94 // Default destructor.
96 if (fTrigger != NULL) delete fTrigger;
99 fCTPDecisions->Delete();
100 delete fCTPDecisions;
105 void AliHLTGlobalTriggerComponent::GetOutputDataTypes(AliHLTComponentDataTypeList& list) const
107 // Returns the kAliHLTDataTypeGlobalTrigger type as output.
108 list.push_back(kAliHLTDataTypeGlobalTrigger);
112 void AliHLTGlobalTriggerComponent::GetOutputDataSize(unsigned long& constBase, double& inputMultiplier)
114 // Returns the output data size estimate.
116 constBase = fBufferSizeConst;
117 inputMultiplier = fBufferSizeMultiplier;
121 Int_t AliHLTGlobalTriggerComponent::DoInit(int argc, const char** argv)
123 // Initialises the global trigger component.
128 fDeleteCodeFile = false;
129 const char* configFileName = NULL;
130 const char* codeFileName = NULL;
131 fIncludePaths.Clear();
132 fIncludeFiles.Clear();
133 SetBit(kIncludeInput);
134 fDataEventsOnly = true;
136 for (int i = 0; i < argc; i++)
138 if (strcmp(argv[i], "-config") == 0)
140 if (configFileName != NULL)
142 HLTWarning("Trigger configuration macro was already specified."
143 " Will replace previous value given by -config."
148 HLTError("The trigger configuration macro filename was not specified." );
151 configFileName = argv[i+1];
156 if (strcmp(argv[i], "-includepath") == 0)
160 HLTError("The include path was not specified." );
163 new (fIncludePaths[fIncludePaths.GetEntriesFast()]) TObjString(argv[i+1]);
168 if (strcmp(argv[i], "-include") == 0)
172 HLTError("The include file name was not specified." );
175 new (fIncludeFiles[fIncludeFiles.GetEntriesFast()]) TObjString(argv[i+1]);
180 if (strcmp(argv[i], "-debug") == 0)
182 if (fDebugMode == true)
184 HLTWarning("The debug flag was already specified. Ignoring this instance.");
190 if (strcmp(argv[i], "-cint") == 0)
192 fRuntimeCompile = false;
196 if (strcmp(argv[i], "-usecode") == 0)
198 if (codeFileName != NULL)
200 HLTWarning("Custom trigger code file was already specified."
201 " Will replace previous value given by -usecode."
206 HLTError("The custom trigger code filename was not specified." );
209 codeFileName = argv[i+1];
212 HLTError("The custom trigger class name was not specified." );
215 fClassName = argv[i+2];
220 if (strcmp(argv[i], "-skipctp") == 0)
222 HLTInfo("Skipping CTP counters in trigger decision");
227 if (strcmp(argv[i], "-forward-input") == 0)
229 HLTInfo("Forwarding input objects and trigger decisions");
230 SetBit(kForwardInput);
231 SetBit(kIncludeShort);
232 SetBit(kIncludeInput, false);
236 if (strstr(argv[i], "-include-input") == argv[i])
238 SetBit(kForwardInput,false);
239 TString param=argv[i];
240 param.ReplaceAll("-include-input", "");
241 if (param.CompareTo("=none")==0)
243 HLTInfo("skipping objects and trigger decisions");
244 SetBit(kIncludeShort, false);
245 SetBit(kIncludeInput, false);
247 else if (param.CompareTo("=short")==0)
249 HLTInfo("including short info on objects and trigger decisions");
250 SetBit(kIncludeShort);
251 SetBit(kIncludeInput, false);
253 else if (param.CompareTo("=both")==0)
255 HLTInfo("including input objects, trigger decisions and short info");
256 SetBit(kIncludeShort);
257 SetBit(kIncludeInput);
259 else if (param.CompareTo("=objects")==0 || param.IsNull())
261 HLTInfo("including input objects and trigger decisions");
262 SetBit(kIncludeShort, false);
263 SetBit(kIncludeInput);
267 HLTError("unknown parameter '%s' for argument '-include-input'", param.Data());
272 if (strcmp(argv[i], "-process-all-events") == 0)
274 fDataEventsOnly = false;
278 HLTError("Unknown option '%s'.", argv[i]);
282 const AliHLTTriggerMenu* menu = NULL;
283 if (configFileName != NULL)
286 cmd += configFileName;
287 gROOT->ProcessLine(cmd);
288 menu = AliHLTGlobalTriggerConfig::Menu();
291 // Try load the trigger menu from the CDB if it is not loaded yet with the
293 int result = -ENOENT;
296 result = LoadTriggerMenu(fgkTriggerMenuCDBPath, menu);
300 HLTError("No trigger menu configuration found or specified.");
304 if (codeFileName == NULL)
306 result = GenerateTrigger(menu, fClassName, fCodeFileName, fIncludePaths, fIncludeFiles);
307 if (result == 0) fDeleteCodeFile = true;
311 result = LoadTriggerClass(codeFileName, fIncludePaths);
312 if (result == 0) fCodeFileName = codeFileName;
314 if (result != 0) return result;
316 fTrigger = AliHLTGlobalTrigger::CreateNew(fClassName.Data());
317 if (fTrigger == NULL)
319 HLTError("Could not create a new instance of '%s'.", fClassName.Data());
323 fTrigger->FillFromMenu(*menu);
324 if (fTrigger->CallFailed()) return -EPROTO;
326 // setup the CTP accounting in AliHLTComponent
329 // Set the default values from the trigger menu.
330 SetDescription(menu->DefaultDescription());
331 SetTriggerDomain(menu->DefaultTriggerDomain());
337 Int_t AliHLTGlobalTriggerComponent::DoDeinit()
339 // Cleans up the global trigger component.
341 if (fTrigger != NULL)
348 fCTPDecisions->Delete();
349 delete fCTPDecisions;
353 Int_t result = UnloadTriggerClass(fCodeFileName);
354 if (result != 0) return result;
356 if (fDeleteCodeFile and !fCodeFileName.IsNull() && gSystem->AccessPathName(fCodeFileName)==0 && !fDebugMode) {
357 fCodeFileName.ReplaceAll(".cxx", "*");
358 TString command="rm "; command+=fCodeFileName;
359 gSystem->Exec(command);
362 fDeleteCodeFile=false;
368 AliHLTComponent* AliHLTGlobalTriggerComponent::Spawn()
370 // Creates a new object instance.
372 return new AliHLTGlobalTriggerComponent;
376 int AliHLTGlobalTriggerComponent::DoTrigger()
378 // This method will apply the global trigger decision.
380 if (fTrigger == NULL)
382 HLTFatal("Global trigger implementation object is NULL!");
386 AliHLTUInt32_t eventType=0;
387 if (!IsDataEvent(&eventType)) {
388 if (eventType==gkAliEventTypeEndOfRun) PrintStatistics(fTrigger, kHLTLogImportant, 0);
396 // Copy the trigger counters in case we need to set them back to their original
397 // value because the PushBack method fails with ENOSPC.
398 TArrayL64 originalCounters = fTrigger->GetCounters();
399 if (fTrigger->CallFailed()) return -EPROTO;
401 fTrigger->NewEvent();
402 if (fTrigger->CallFailed()) return -EPROTO;
404 // Fill in the input data.
405 const TObject* obj = GetFirstInputObject();
408 fTrigger->Add(obj, GetDataType(), GetSpecification());
409 if (fTrigger->CallFailed()) return -EPROTO;
410 obj = GetNextInputObject();
413 // add trigger decisions for every CTP class
414 const AliHLTCTPData* pCTPData=CTPData();
416 AddCTPDecisions(fTrigger, pCTPData, GetTriggerData());
419 // Calculate the global trigger result and trigger domain, then create and push
420 // back the new global trigger decision object.
422 AliHLTTriggerDomain triggerDomain;
423 bool triggerResult = fTrigger->CalculateTriggerDecision(triggerDomain, description);
424 if (fTrigger->CallFailed()) return -EPROTO;
425 AliHLTGlobalTriggerDecision decision(
427 // The following will cause the decision to be generated with default values
428 // (set in fTriggerDomain and fDescription) if the trigger result is false.
429 (triggerResult == true) ? triggerDomain : GetTriggerDomain(),
430 (triggerResult == true) ? description.Data() : GetDescription()
433 // mask the readout list according to the CTP trigger
434 // if the classes have been initialized (mask non-zero)
435 if (pCTPData && pCTPData->Mask()) {
436 AliHLTEventDDL eventDDL=pCTPData->ReadoutList(*GetTriggerData());
437 AliHLTReadoutList ctpreadout(eventDDL);
438 ctpreadout.Enable(AliHLTReadoutList::kHLT);
439 AliHLTReadoutList maskedList=decision.ReadoutList();
440 maskedList.AndEq(ctpreadout);
441 decision.ReadoutList(maskedList);
444 decision.SetCounters(fTrigger->GetCounters(), GetEventCount()+1);
445 if (fTrigger->CallFailed()) return -EPROTO;
447 static UInt_t lastTime=0;
449 if (time.Get()-lastTime>60) {
451 PrintStatistics(fTrigger, kHLTLogImportant);
454 // Add the input objects used to the global decision.
455 TClonesArray* pShortInfo=NULL;
456 if (TestBit(kIncludeShort)) {
457 pShortInfo=new TClonesArray(TNamed::Class(), GetNumberOfInputBlocks());
459 obj = GetFirstInputObject();
462 if (TestBit(kForwardInput)) {
465 if (TestBit(kIncludeInput)) {
466 if (obj->IsA() == AliHLTTriggerDecision::Class())
468 decision.AddTriggerInput( *static_cast<const AliHLTTriggerDecision*>(obj) );
472 decision.AddInputObject(obj);
476 if (TestBit(kIncludeShort)) {
477 int entries=pShortInfo->GetEntriesFast();
478 new ((*pShortInfo)[entries]) TNamed(obj->GetName(), obj->GetTitle());
479 if (obj->IsA() == AliHLTTriggerDecision::Class()) {
480 (*pShortInfo)[entries]->SetBit(BIT(16)); // indicate that this is a trigger decision
481 (*pShortInfo)[entries]->SetBit(BIT(15), ((AliHLTTriggerDecision*)obj)->Result());
485 obj = GetNextInputObject();
488 decision.AddInputObject(pShortInfo);
489 pShortInfo->Delete();
494 if (!TestBit(kSkipCTP) && CTPData()) decision.AddInputObject(CTPData());
496 // add readout filter to event done data
497 CreateEventDoneReadoutFilter(decision.TriggerDomain(), 3);
498 // add monitoring filter to event done data
499 CreateEventDoneReadoutFilter(decision.TriggerDomain(), 4);
500 if (decision.Result()) {
501 // add monitoring event command for triggered events
502 CreateEventDoneReadoutFilter(decision.TriggerDomain(), 5);
504 if (TriggerEvent(&decision) == -ENOSPC)
506 // Increase the estimated buffer space required if the PushBack methods in TriggerEvent
507 // returned the "no buffer space" error code. Also remember to set the trigger counters
508 // back to what they were, otherwise triggers will be double counted when we try to reprocess
509 // this event with larger buffers.
510 fBufferSizeConst += 1024*1024;
511 fBufferSizeMultiplier *= 2.;
512 fTrigger->SetCounters(originalCounters);
513 if (fTrigger->CallFailed()) return -EPROTO;
520 int AliHLTGlobalTriggerComponent::Reconfigure(const char* cdbEntry, const char* chainId)
522 // Reconfigure the component by loading the trigger menu and recreating the
523 // trigger logic class.
525 const char* path = fgkTriggerMenuCDBPath;
526 const char* id = "(unknown)";
527 if (cdbEntry != NULL) path = cdbEntry;
528 if (chainId != NULL and chainId[0] != '\0') id = chainId;
529 HLTInfo("Reconfiguring from '%s' for chain component '%s'.", path, id);
531 const AliHLTTriggerMenu* menu = NULL;
532 int result = LoadTriggerMenu(path, menu);
533 if (result != 0) return result;
536 TString codeFileName;
537 result = GenerateTrigger(menu, className, codeFileName, fIncludePaths, fIncludeFiles);
538 if (result != 0) return result;
540 AliHLTGlobalTrigger* trigger = AliHLTGlobalTrigger::CreateNew(className.Data());
543 HLTError("Could not create a new instance of '%s'.", className.Data());
544 // Make sure to cleanup after the new code file.
545 UnloadTriggerClass(codeFileName);
546 if (not codeFileName.IsNull() and gSystem->AccessPathName(codeFileName)==0 and not fDebugMode)
548 codeFileName.ReplaceAll(".cxx", "*");
549 TString command="rm "; command+=codeFileName;
550 gSystem->Exec(command);
555 if (fTrigger != NULL)
562 fTrigger->FillFromMenu(*menu);
563 if (fTrigger->CallFailed()) return -EPROTO;
565 // Set the default values from the trigger menu.
566 SetDescription(menu->DefaultDescription());
567 SetTriggerDomain(menu->DefaultTriggerDomain());
569 // Cleanup the old class code.
570 UnloadTriggerClass(fCodeFileName);
571 if (fDeleteCodeFile and not fCodeFileName.IsNull() and gSystem->AccessPathName(fCodeFileName)==0 and not fDebugMode)
573 fCodeFileName.ReplaceAll(".cxx", "*");
574 TString command="rm "; command+=fCodeFileName;
575 gSystem->Exec(command);
577 fCodeFileName = codeFileName;
578 fDeleteCodeFile = true; // Since we generated a new class.
584 int AliHLTGlobalTriggerComponent::LoadTriggerMenu(const char* cdbPath, const AliHLTTriggerMenu*& menu)
586 // Loads the trigger menu object from the CDB path.
588 HLTDebug("Trying to load trigger menu from '%s'.", cdbPath);
589 if (AliCDBManager::Instance() == NULL)
591 HLTError("CDB manager object not found.");
594 AliCDBStorage* store = AliCDBManager::Instance()->GetDefaultStorage();
597 HLTError("Could not get the the default storage for the CDB.");
600 Int_t version = store->GetLatestVersion(cdbPath, GetRunNo());
601 Int_t subVersion = store->GetLatestSubVersion(cdbPath, GetRunNo(), version);
602 AliCDBEntry* entry = AliCDBManager::Instance()->Get(cdbPath, GetRunNo(), version, subVersion);
605 HLTError("Could not get the CDB entry for \"%s\".", cdbPath);
608 TObject* obj = entry->GetObject();
611 HLTError("Configuration object for \"%s\" is missing.", cdbPath);
614 if (obj->IsA() != AliHLTTriggerMenu::Class())
616 HLTError("Wrong type for configuration object in \"%s\". Found a %s but we expect a AliHLTTriggerMenu.",
617 cdbPath, obj->ClassName()
621 menu = static_cast<AliHLTTriggerMenu*>(obj);
626 int AliHLTGlobalTriggerComponent::GenerateTrigger(
627 const AliHLTTriggerMenu* menu, TString& name, TString& filename,
628 const TClonesArray& includePaths, const TClonesArray& includeFiles
631 // Generates the global trigger class that will implement the specified trigger menu.
632 // See header for more details.
634 HLTDebug("Generating custom HLT trigger class named %s using trigger menu %p.", ((void*)menu), name.Data());
636 // Create a new UUID and replace the '-' characters with '_' to make it a valid
639 TString uuidstr = uuid.AsString();
640 for (Int_t i = 0; i < uuidstr.Length(); i++)
642 if (uuidstr[i] == '-') uuidstr[i] = '_';
645 // Create the name of the new class.
646 name = "AliHLTGlobalTriggerImpl_";
648 filename = name + ".cxx";
650 // Open a text file to write the code and generate the new class.
651 fstream code(filename.Data(), ios_base::out | ios_base::trunc);
654 HLTError("Could not open file '%s' for writing.", filename.Data());
658 TClonesArray symbols(AliHLTTriggerMenuSymbol::Class());
659 int result = BuildSymbolList(menu, symbols);
660 if (result != 0) return result;
662 code << "#if !defined(__CINT__) || defined(__MAKECINT__)" << endl;
663 code << "#include <cstring>" << endl;
664 code << "#include \"TString.h\"" << endl;
665 code << "#include \"TClonesArray.h\"" << endl;
666 code << "#include \"AliHLTLogging.h\"" << endl;
667 code << "#include \"AliHLTGlobalTrigger.h\"" << endl;
668 code << "#include \"AliHLTGlobalTriggerDecision.h\"" << endl;
669 code << "#include \"AliHLTDomainEntry.h\"" << endl;
670 code << "#include \"AliHLTTriggerDomain.h\"" << endl;
671 code << "#include \"AliHLTReadoutList.h\"" << endl;
672 code << "#include \"AliHLTTriggerMenu.h\"" << endl;
673 code << "#include \"AliHLTTriggerMenuItem.h\"" << endl;
674 code << "#include \"AliHLTTriggerMenuSymbol.h\"" << endl;
676 // Add any include files that were specified on the command line.
677 for (Int_t i = 0; i < includeFiles.GetEntriesFast(); i++)
679 TString file = static_cast<TObjString*>(includeFiles.UncheckedAt(i))->String();
680 code << "#include \"" << file.Data() << "\"" << endl;
685 code << "#else" << endl;
686 code << "const char* gFunctionName = \"???\";" << endl;
687 code << "#define HLTDebug(msg) if (CheckFilter(kHLTLogDebug) && CheckGroup(Class_Name())) SendMessage(kHLTLogDebug, Class_Name(), ::gFunctionName, __FILE__, __LINE__, msg)" << endl;
689 code << "#endif" << endl;
691 code << "class " << name << " :" << endl;
692 // Add appropriate #ifdef sections since we need to prevent inheritance from
693 // AliHLTGlobalTrigger. CINT does not seem to support multiple inheritance nor
694 // multiple levels of inheritance. Neither of the following schemes worked:
696 // 1) class AliHLTGlobalTrigger : public AliHLTLogging {};
697 // class AliHLTGlobalTriggerImpl_xyz : public AliHLTGlobalTrigger {};
699 // 2) class AliHLTGlobalTrigger {};
700 // class AliHLTGlobalTriggerImpl_xyz : public AliHLTGlobalTrigger, public AliHLTLogging {};
702 // Thus, we are forced to just inherit from AliHLTLogging when running in the CINT
703 // interpreter. But we anyway have to call the global trigger implementation class
704 // through the AliHLTGlobalTriggerWrapper so this is not such a problem.
705 code << "#if !defined(__CINT__) || defined(__MAKECINT__)" << endl;
706 code << " public AliHLTGlobalTrigger," << endl;
707 code << "#endif" << endl;
708 code << " public AliHLTLogging" << endl;
710 code << "public:" << endl;
712 // Generate constructor method.
713 code << " " << name << "() :" << endl;
714 code << "#if !defined(__CINT__) || defined(__MAKECINT__)" << endl;
715 code << " AliHLTGlobalTrigger()," << endl;
716 code << "#endif" << endl;
717 code << " AliHLTLogging()";
718 // Write the symbols in the trigger menu in the initialisation list.
719 for (Int_t i = 0; i < symbols.GetEntriesFast(); i++)
722 AliHLTTriggerMenuSymbol* symbol = static_cast<AliHLTTriggerMenuSymbol*>( symbols.UncheckedAt(i) );
723 code << " " << symbol->Name() << "()," << endl;
724 if (strcmp(symbol->ObjectClass(), "AliHLTTriggerDecision") == 0)
726 code << " " << symbol->Name() << "TriggerDomain()," << endl;
728 code << " " << symbol->Name() << "DomainEntry(kAliHLTAnyDataType)";
730 for (UInt_t i = 0; i < menu->NumberOfItems(); i++)
732 code << "," << endl << " fMenuItemDescription" << i << "()";
734 code << endl << " {" << endl;
737 code << "#ifdef __CINT__" << endl;
738 code << " gFunctionName = \"" << name.Data() <<"\";" << endl;
739 code << "#endif" << endl;
740 code << " SetLocalLoggingLevel(kHLTLogAll);" << endl;
741 code << " HLTDebug(Form(\"Creating new instance at %p.\", this));" << endl;
743 code << " }" << endl;
745 code << " virtual ~" << name << "() {" << endl;
748 code << "#ifdef __CINT__" << endl;
749 code << " gFunctionName = \"~" << name.Data() << "\";" << endl;
750 code << "#endif" << endl;
751 code << " HLTDebug(Form(\"Deleting instance at %p.\", this));" << endl;
753 code << " }" << endl;
755 // Generate the FillFromMenu method.
756 code << " virtual void FillFromMenu(const AliHLTTriggerMenu& menu) {" << endl;
759 code << "#ifdef __CINT__" << endl;
760 code << " gFunctionName = \"FillFromMenu\";" << endl;
761 code << "#endif" << endl;
762 code << " HLTDebug(Form(\"Filling description entries from trigger menu for global trigger %p.\", this));" << endl;
764 code << " fCounter.Set(menu.NumberOfItems());" << endl;
765 for (UInt_t i = 0; i < menu->NumberOfItems(); i++)
767 code << " fMenuItemDescription" << i << " = (menu.Item(" << i
768 << ") != NULL) ? menu.Item(" << i << ")->Description() : \"\";" << endl;
772 code << " HLTDebug(Form(\"Finished filling description entries from trigger menu.\"));" << endl;
773 code << " HLTDebug(Form(\"Filling domain entries from trigger menu symbols for global trigger %p.\", this));" << endl;
775 code << " for (Int_t i = 0; i < menu.SymbolArray().GetEntriesFast(); i++) {" << endl;
776 // 30 Oct 2009 - CINT sometimes evaluates the dynamic_cast incorrectly.
777 // Have to use the TClass system for extra protection.
778 code << " if (menu.SymbolArray().UncheckedAt(i) == NULL) continue;" << endl;
779 code << " if (menu.SymbolArray().UncheckedAt(i)->IsA() != AliHLTTriggerMenuSymbol::Class()) continue;" << endl;
780 code << " const AliHLTTriggerMenuSymbol* symbol = dynamic_cast<const"
781 " AliHLTTriggerMenuSymbol*>(menu.SymbolArray().UncheckedAt(i));" << endl;
782 code << " if (symbol == NULL) continue;" << endl;
783 for (Int_t i = 0; i < symbols.GetEntriesFast(); i++)
785 AliHLTTriggerMenuSymbol* symbol = static_cast<AliHLTTriggerMenuSymbol*>( symbols.UncheckedAt(i) );
786 code << " if (strcmp(symbol->RealName(), \"" << symbol->RealName() << "\") == 0) {" << endl;
789 code << " HLTDebug(Form(\"Assinging domain entry value corresponding with symbol '%s' to '%s'.\","
790 " symbol->RealName(), symbol->BlockType().AsString().Data()));" << endl;
792 code << " " << symbol->Name() << "DomainEntry = symbol->BlockType();" << endl;
793 code << " continue;" << endl;
794 code << " }" << endl;
796 code << " }" << endl;
799 code << " HLTDebug(Form(\"Finished filling domain entries from trigger menu symbols.\"));" << endl;
801 code << " }" << endl;
803 // Generate the NewEvent method.
804 code << " virtual void NewEvent() {" << endl;
807 code << "#ifdef __CINT__" << endl;
808 code << " gFunctionName = \"NewEvent\";" << endl;
809 code << "#endif" << endl;
810 code << " HLTDebug(Form(\"New event for global trigger object %p, initialising variables to default values.\", this));" << endl;
812 // Write code to initialise the symbols in the trigger menu to their default values.
813 for (Int_t i = 0; i < symbols.GetEntriesFast(); i++)
815 AliHLTTriggerMenuSymbol* symbol = static_cast<AliHLTTriggerMenuSymbol*>( symbols.UncheckedAt(i) );
816 // CINT has problems with the implicit equals operator for complex types, so if
817 // the type has a equals operater we need to write the operator call explicitly.
818 TClass* clas = TClass::GetClass(symbol->Type());
819 if (clas != NULL and clas->GetMethodAny("operator=") != NULL)
821 code << " " << symbol->Name() << ".operator = (" << symbol->DefaultValue() << ");" << endl;
825 code << " " << symbol->Name() << " = " << symbol->DefaultValue() << ";" << endl;
827 if (strcmp(symbol->ObjectClass(), "AliHLTTriggerDecision") == 0)
829 code << " " << symbol->Name() << "TriggerDomain.Clear();" << endl;
834 code << " HLTDebug(Form(\"Finished initialising variables.\"));" << endl;
836 code << " }" << endl;
838 // Generate the Add method.
839 code << " virtual void Add(const TObject* _object_, const AliHLTComponentDataType& _type_, AliHLTUInt32_t _spec_) {" << endl;
842 code << "#ifdef __CINT__" << endl;
843 code << " gFunctionName = \"Add\";" << endl;
844 code << "#endif" << endl;
846 code << " AliHLTDomainEntry _type_spec_(_type_, _spec_);" << endl;
849 code << " HLTDebug(Form(\"Adding TObject %p, with class name '%s' from data block"
850 " '%s', to global trigger object %p\", _object_, _object_->ClassName(),"
851 " _type_spec_.AsString().Data(), this));" << endl;
852 code << " _object_->Print();" << endl;
853 code << " bool _object_assigned_ = false;" << endl;
855 for (Int_t i = 0; i < symbols.GetEntriesFast(); i++)
857 // Write code to check if the block type, specification and class name is correct.
858 // Then write code to assign the variable from the input object.
859 AliHLTTriggerMenuSymbol* symbol = static_cast<AliHLTTriggerMenuSymbol*>( symbols.UncheckedAt(i) );
860 TString expr = symbol->AssignExpression();
861 if (expr == "") continue; // Skip entries that have no assignment expression.
862 bool isTrigDecision = strcmp(symbol->ObjectClass(), "AliHLTTriggerDecision") == 0;
867 code << " HLTDebug(Form(\"Trying to match input object to class '"
868 << symbol->ObjectClass() << "', trigger name '" << symbol->RealName()
869 << "' and block type '%s'\", " << symbol->Name()
870 << "DomainEntry.AsString().Data()));" << endl;
874 code << " HLTDebug(Form(\"Trying to match input object to class '"
875 << symbol->ObjectClass() << "' and block type '%s'\", "
876 << symbol->Name() << "DomainEntry.AsString().Data()));" << endl;
879 // 30 Oct 2009 - CINT sometimes evaluates the dynamic_cast incorrectly.
880 // Have to use the TClass system for extra protection.
881 code << " const " << symbol->ObjectClass() << "* " << symbol->Name() << "_object_ = NULL;" << endl;
882 code << " if (_object_->IsA() == " << symbol->ObjectClass() << "::Class()) " << symbol->Name()
883 << "_object_ = dynamic_cast<const " << symbol->ObjectClass()
884 << "*>(_object_);" << endl;
885 code << " if (" << symbol->Name() << "_object_ != NULL && ";
888 code << "strcmp(" << symbol->Name() << "_object_->Name(), \""
889 << symbol->RealName() << "\") == 0 && ";
891 code << symbol->Name() << "DomainEntry == _type_spec_) {" << endl;
892 TString fullname = symbol->Name();
893 fullname += "_object_";
894 expr.ReplaceAll("this", fullname);
895 code << " this->" << symbol->Name() << " = " << expr.Data() << ";" << endl;
898 code << " this->" << symbol->Name() << "TriggerDomain = "
899 << fullname.Data() << "->TriggerDomain();" << endl;
903 code << " HLTDebug(Form(\"Added TObject %p with class name '%s' to variable "
904 << symbol->Name() << "\", _object_, _object_->ClassName()));" << endl;
905 code << " _object_assigned_ = true;" << endl;
907 code << " }" << endl;
911 code << " if (! _object_assigned_) {" << endl;
912 code << " HLTDebug(Form(\"Did not assign TObject %p"
913 " with class name '%s' to any variable.\", _object_, _object_->ClassName()));"
915 code << " }" << endl;
917 code << " }" << endl;
919 // Generate the CalculateTriggerDecision method.
920 // This requires code to be generated that checks which items in the trigger menu
921 // have their conditions asserted and then the trigger domain is generated from
922 // those fired items.
923 // The processing will start from the highest priority trigger group and stop
924 // after at least one trigger from the current priority group being processed
925 // is positive. For each priority group all the trigger menu items are checked.
926 // Their combined trigger condition expression must be true for the trigger priority
927 // group to be triggered positive. The full condition expression is formed by
928 // concatenating the individual condition expressions. If no trailing operators are
929 // used in the individual expressions then the default condition operator is placed
930 // between two concatenated condition expressions.
931 // If a trigger priority group has at least one trigger fired then the trigger domain
932 // is calculated such that it will give the same result as the concatenated trigger
933 // domain merging expressions for all the individual trigger menu items with
934 // positive results. Again, if no trailing operators are used in the individual
935 // merging expressions then the default domain operator is placed between two
936 // expression fragments.
937 code << " virtual bool CalculateTriggerDecision(AliHLTTriggerDomain& _domain_, TString& _description_) {" << endl;
940 code << "#ifdef __CINT__" << endl;
941 code << " gFunctionName = \"CalculateTriggerDecision\";" << endl;
942 code << "#endif" << endl;
943 code << " HLTDebug(Form(\"Calculating global HLT trigger result with trigger object at %p.\", this));" << endl;
946 // Build a list of priorities used in the trigger menu.
947 std::vector<UInt_t> priorities;
948 for (UInt_t i = 0; i < menu->NumberOfItems(); i++)
950 const AliHLTTriggerMenuItem* item = menu->Item(i);
951 bool priorityNotInList = std::find(priorities.begin(), priorities.end(), item->Priority()) == priorities.end();
952 if (priorityNotInList) priorities.push_back(item->Priority());
954 std::sort(priorities.begin(), priorities.end(), AliHLTDescendingNumbers);
955 // From the priority list, build the priority groups in the correct order,
956 // i.e. highest priority first.
957 // The priority group is a list of vectors of integers. The integers are the
958 // index numbers into the trigger menu item list for the items which form part
959 // of the priority group.
960 std::vector<std::vector<Int_t> > priorityGroup;
961 priorityGroup.insert(priorityGroup.begin(), priorities.size(), std::vector<Int_t>());
962 for (size_t n = 0; n < priorities.size(); n++)
964 UInt_t priority = priorities[n];
965 for (UInt_t i = 0; i < menu->NumberOfItems(); i++)
967 const AliHLTTriggerMenuItem* item = menu->Item(i);
968 if (item->Priority() == priority) priorityGroup[n].push_back(i);
972 for (size_t n = 0; n < priorityGroup.size(); n++)
976 code << " HLTDebug(Form(\"Processing trigger priority group " << priorities[n] << "\"));" << endl;
979 if (n == 0) code << "UInt_t ";
980 code << "_previous_match_ = 0xFFFFFFFF;" << endl;
982 if (n == 0) code << "bool ";
983 code << "_trigger_matched_ = false;" << endl;
985 if (n == 0) code << "bool ";
986 code << "_group_result_ = false;" << endl;
987 std::vector<TString> conditionOperator;
988 conditionOperator.insert(conditionOperator.begin(), priorityGroup[n].size(), TString(""));
989 std::vector<TString> domainOperator;
990 domainOperator.insert(domainOperator.begin(), priorityGroup[n].size(), TString(""));
991 for (size_t m = 0; m < priorityGroup[n].size(); m++)
993 UInt_t i = priorityGroup[n][m];
994 const AliHLTTriggerMenuItem* item = menu->Item(i);
995 TString triggerCondition = item->TriggerCondition();
996 TString mergeExpr = item->MergeExpression();
997 // Replace the symbols found in the trigger condition and merging expressions
998 // with appropriate compilable versions.
999 for (Int_t j = 0; j < symbols.GetEntriesFast(); j++)
1001 AliHLTTriggerMenuSymbol* symbol = static_cast<AliHLTTriggerMenuSymbol*>( symbols.UncheckedAt(j) );
1002 bool symbolNamesDifferent = strcmp(symbol->RealName(), symbol->Name()) != 0;
1003 if (strcmp(symbol->ObjectClass(), "AliHLTTriggerDecision") == 0)
1005 TString newname = symbol->Name();
1006 newname += "TriggerDomain";
1007 mergeExpr.ReplaceAll(symbol->RealName(), newname);
1011 if (symbolNamesDifferent) mergeExpr.ReplaceAll(symbol->RealName(), symbol->Name());
1013 if (symbolNamesDifferent) triggerCondition.ReplaceAll(symbol->RealName(), symbol->Name());
1015 // We allow the trigger conditions and merging expressions to have trailing operators.
1016 // Thus, we need to extract the operators and cleanup the expressions so that they will
1017 // compile. This means that we silently ignore the trailing operator if not needed.
1018 if (ExtractedOperator(triggerCondition, conditionOperator[m]))
1020 // If the trailing operator is the same as the default operator then reset
1021 // the value in the operator list so that the default is used in the generated
1022 // code. This creates more compact code.
1023 if (conditionOperator[m] == menu->DefaultConditionOperator()) conditionOperator[m] = "";
1025 if (ExtractedOperator(mergeExpr, domainOperator[m]))
1027 if (domainOperator[m] == menu->DefaultDomainOperator()) domainOperator[m] = "";
1031 code << " HLTDebug(Form(\"Trying trigger condition " << i
1032 << " (Description = '%s').\", fMenuItemDescription" << i << ".Data()));"
1036 if (n == 0 and m == 0) code << "bool ";
1037 code << "_item_result_ = false;" << endl;
1038 code << " if (" << triggerCondition << ") {" << endl;
1039 code << " ++fCounter[" << i << "];" << endl;
1040 const char* indentation = "";
1041 if (item->PreScalar() != 0)
1044 code << " if ((fCounter[" << i << "] % " << item->PreScalar() << ") == 1) {" << endl;
1046 code << indentation << " _item_result_ = true;" << endl;
1049 code << indentation << " HLTDebug(Form(\"Matched trigger condition " << i
1050 << " (Description = '%s').\", fMenuItemDescription" << i << ".Data()));" << endl;
1052 if (item->PreScalar() != 0)
1054 code << " }" << endl;
1056 code << " }" << endl;
1059 // Since this is the first item of the trigger group,
1060 // the generated trigger logic can be simplified a little.
1061 code << " _group_result_ = _item_result_;" << endl;
1062 code << " if (_item_result_) {" << endl;
1063 code << " _domain_ = " << mergeExpr.Data() << ";" << endl;
1064 code << " _description_ = fMenuItemDescription" << i << ";" << endl;
1065 code << " _previous_match_ = " << i << ";" << endl;
1066 code << " _trigger_matched_ = true;" << endl;
1067 code << " }" << endl;
1071 if (conditionOperator[m-1] == "")
1073 code << " _group_result_ = _group_result_ "
1074 << menu->DefaultConditionOperator() << " _item_result_;" << endl;
1078 code << " _group_result_ = _group_result_ "
1079 << conditionOperator[m-1] << " _item_result_;" << endl;
1081 code << " if (_item_result_) {" << endl;
1082 code << " if (_trigger_matched_) {" << endl;
1083 bool switchWillBeEmpty = true;
1084 for (size_t k = 0; k < m; k++)
1086 if (domainOperator[k] == "") continue;
1087 switchWillBeEmpty = false;
1089 if (switchWillBeEmpty)
1091 code << " _domain_ = _domain_ " << menu->DefaultDomainOperator() << " "
1092 << mergeExpr.Data() << ";" << endl;
1096 code << " switch(_previous_match_) {" << endl;
1097 for (size_t k = 0; k < m; k++)
1099 if (domainOperator[k] == "") continue;
1100 code << " case " << k << ": _domain_ = _domain_ "
1101 << domainOperator[k] << " " << mergeExpr.Data() << "; break;" << endl;
1103 code << " default: _domain_ = _domain_ "
1104 << menu->DefaultDomainOperator() << " " << mergeExpr.Data() << ";" << endl;
1105 code << " }" << endl;
1107 code << " _description_ += \",\";" << endl;
1108 code << " _description_ += fMenuItemDescription" << i << ";" << endl;
1109 code << " } else {" << endl;
1110 code << " _domain_ = " << mergeExpr.Data() << ";" << endl;
1111 code << " _description_ = fMenuItemDescription" << i << ";" << endl;
1112 code << " }" << endl;
1113 code << " _previous_match_ = " << i << ";" << endl;
1114 code << " _trigger_matched_ = true;" << endl;
1115 code << " }" << endl;
1118 code << " if (_group_result_) {" << endl;
1121 if (n < priorities.size() - 1)
1123 code << " HLTDebug(Form(\"Matched triggers in trigger priority group " << priorities[n]
1124 << ". Stopping processing here because all other trigger groups have lower priority.\"));" << endl;
1128 code << " HLTDebug(Form(\"Matched triggers in trigger priority group " << priorities[n] << ".\"));" << endl;
1131 code << " return true;" << endl;
1132 code << " }" << endl;
1134 code << " _domain_.Clear();" << endl;
1135 code << " _description_ = \"\";" << endl;
1136 code << " return false;" << endl;
1137 code << " }" << endl;
1139 // Generate getter and setter methods for the counters.
1140 code << " const TArrayL64& GetCounters() const { return fCounter; }" << endl;
1141 code << " void SetCounters(const TArrayL64& counters) { fCounter = counters; }" << endl;
1143 code << "private:" << endl;
1144 // Add the symbols in the trigger menu to the list of private variables.
1145 for (Int_t i = 0; i < symbols.GetEntriesFast(); i++)
1147 AliHLTTriggerMenuSymbol* symbol = static_cast<AliHLTTriggerMenuSymbol*>( symbols.UncheckedAt(i) );
1148 code << " " << symbol->Type() << " " << symbol->Name() << ";" << endl;
1149 if (strcmp(symbol->ObjectClass(), "AliHLTTriggerDecision") == 0)
1151 code << " AliHLTTriggerDomain " << symbol->Name() << "TriggerDomain;" << endl;
1153 code << " AliHLTDomainEntry " << symbol->Name() << "DomainEntry;" << endl;
1155 for (UInt_t i = 0; i < menu->NumberOfItems(); i++)
1157 code << " TString fMenuItemDescription" << i << ";" << endl;
1159 code << " TArrayL64 fCounter;" << endl;
1160 code << "#if !defined(__CINT__) || defined(__MAKECINT__)" << endl;
1161 code << " ClassDef(" << name.Data() << ", 0)" << endl;
1162 code << "#else" << endl;
1163 code << " virtual const char* Class_Name() const { return \"" << name.Data() << "\"; }" << endl;
1164 code << "#endif" << endl;
1165 code << "};" << endl;
1166 code << "#if !defined(__CINT__) || defined(__MAKECINT__)" << endl;
1167 code << "ClassImp(" << name.Data() << ")" << endl;
1168 code << "#endif" << endl;
1172 // Now we need to compile and load the new class.
1173 result = LoadTriggerClass(filename, includePaths);
1178 int AliHLTGlobalTriggerComponent::LoadTriggerClass(
1179 const char* filename, const TClonesArray& includePaths
1182 // Loads the code for a custom global trigger class implementation on the fly.
1184 HLTDebug("Loading HLT trigger class from file '%s'.", filename);
1186 TString compiler = gSystem->GetBuildCompilerVersion();
1187 if (fRuntimeCompile && (compiler.Contains("gcc") or compiler.Contains("icc")))
1189 TString includePath;
1190 #if defined(PKGINCLUDEDIR)
1191 // this is especially for the HLT build system where the package is installed
1192 // in a specific directory including proper treatment of include files
1193 includePath.Form("-I%s", PKGINCLUDEDIR);
1195 // the default AliRoot behavior, all include files can be found in the
1196 // $ALICE_ROOT subfolders
1197 includePath = "-I${ALICE_ROOT}/include -I${ALICE_ROOT}/HLT/BASE -I${ALICE_ROOT}/HLT/trigger";
1199 // Add any include paths that were specified on the command line.
1200 for (Int_t i = 0; i < includePaths.GetEntriesFast(); i++)
1202 TString path = static_cast<TObjString*>(includePaths.UncheckedAt(i))->String();
1203 includePath += " -I";
1204 includePath += path;
1206 HLTDebug("using include settings: %s", includePath.Data());
1207 gSystem->SetIncludePath(includePath);
1208 gSystem->SetFlagsOpt("-O3 -DNDEBUG");
1209 gSystem->SetFlagsDebug("-g3 -DDEBUG -D__DEBUG");
1214 result = gSystem->CompileMacro(filename, "g");
1218 result = gSystem->CompileMacro(filename, "O");
1220 if (result != kTRUE)
1222 HLTFatal("Could not compile and load global trigger menu implementation.");
1228 // Store the library state to be checked later in UnloadTriggerClass.
1229 fLibStateAtLoad = gSystem->GetLibraries();
1231 // If we do not support the compiler then try interpret the class instead.
1232 TString cmd = ".L ";
1234 Int_t errorcode = TInterpreter::kNoError;
1235 gROOT->ProcessLine(cmd, &errorcode);
1236 if (errorcode != TInterpreter::kNoError)
1238 HLTFatal("Could not load interpreted global trigger menu implementation"
1239 " (Interpreter error code = %d).",
1250 int AliHLTGlobalTriggerComponent::UnloadTriggerClass(const char* filename)
1252 // Unloads the code previously loaded by LoadTriggerClass.
1254 HLTDebug("Unloading HLT trigger class in file '%s'.", filename);
1256 TString compiler = gSystem->GetBuildCompilerVersion();
1257 if (fRuntimeCompile && (compiler.Contains("gcc") or compiler.Contains("icc")))
1259 // Generate the library name.
1260 TString libname = filename;
1261 Ssiz_t dotpos = libname.Last('.');
1262 if (0 <= dotpos and dotpos < libname.Length()) libname[dotpos] = '_';
1264 libname += gSystem->GetSoExt();
1266 // This is a workaround for a problem with unloading shared libraries in ROOT.
1267 // If the trigger logic library is loaded before the libAliHLTHOMER.so library
1268 // or any other library is loaded afterwards, then during the gInterpreter->UnloadFile
1269 // call all the subsequent libraries get unloded. This means that any objects created
1270 // from classes implemented in the libAliHLTHOMER.so library will generate segfaults
1271 // since the executable code has been unloaded.
1272 // We need to check if there are any more libraries loaded after the class we
1273 // are unloading and in that case don't unload the class.
1274 TString libstring = gSystem->GetLibraries();
1275 TString token, lastlib;
1277 Int_t numOfLibs = 0, posOfLib = -1;
1278 while (libstring.Tokenize(token, from, " "))
1282 if (token.Contains(libname)) posOfLib = numOfLibs;
1284 if (numOfLibs != posOfLib)
1286 HLTWarning(Form("ROOT limitation! Cannot properly cleanup and unload the shared"
1287 " library '%s' since another library '%s' was loaded afterwards. Trying to"
1288 " unload this library will remove the others and lead to serious memory faults.",
1289 libname.Data(), lastlib.Data()
1296 if ((path = gSystem->DynamicPathName(libname)) != NULL)
1298 result = gInterpreter->UnloadFile(path);
1301 if (result != TInterpreter::kNoError) return -ENOENT;
1305 // This is again a workaround for the problem with unloading files in ROOT.
1306 // If the trigger logic class is loaded before the libAliHLTHOMER.so library
1307 // or any other library is loaded afterwards, then during the gInterpreter->UnloadFile
1308 // call all the subsequent libraries get unloded.
1309 // We need to check if the list of loaded libraries has changed since the last
1310 // call to LoadTriggerClass. If it has then don't unload the class.
1311 if (fLibStateAtLoad != gSystem->GetLibraries())
1313 TString libstring = gSystem->GetLibraries();
1316 while (libstring.Tokenize(token, from, " "))
1318 if (not fLibStateAtLoad.Contains(token)) break;
1320 HLTWarning(Form("ROOT limitation! Cannot properly cleanup and unload the file"
1321 " '%s' since another library '%s' was loaded afterwards. Trying to unload"
1322 " this file will remove the other library and lead to serious memory faults.",
1323 filename, token.Data()
1328 // If we did not compile the trigger logic then remove the interpreted class.
1329 TString cmd = ".U ";
1331 Int_t errorcode = TInterpreter::kNoError;
1332 gROOT->ProcessLine(cmd, &errorcode);
1333 if (errorcode != TInterpreter::kNoError)
1335 HLTFatal("Could not unload interpreted global trigger menu implementation"
1336 " (Interpreter error code = %d).",
1347 int AliHLTGlobalTriggerComponent::FindSymbol(const char* name, const TClonesArray& list)
1349 // Searches for the named symbol in the given list.
1350 // See header for more details.
1352 for (int i = 0; i < list.GetEntriesFast(); i++)
1354 const AliHLTTriggerMenuSymbol* symbol = dynamic_cast<const AliHLTTriggerMenuSymbol*>( list.UncheckedAt(i) );
1355 if (symbol == NULL) continue;
1356 if (strcmp(symbol->Name(), name) == 0) return i;
1362 int AliHLTGlobalTriggerComponent::BuildSymbolList(const AliHLTTriggerMenu* menu, TClonesArray& list)
1364 // Builds the list of symbols to use in the custom global trigger menu
1365 // implementation class.
1366 // See header for more details.
1368 // Note: when we build the symbol list we must use the symbol name as returned
1369 // by the Name() method and not the RealName() method when using FindSymbol.
1370 // This is so that we avoid problems with the generated code not compiling
1371 // because names like "abc-xyz" and "abc_xyz" are synonymous.
1372 // Name() returns the converted C++ symbol name as used in the generated code.
1374 for (UInt_t i = 0; i < menu->NumberOfSymbols(); i++)
1376 const AliHLTTriggerMenuSymbol* symbol = menu->Symbol(i);
1377 if (FindSymbol(symbol->Name(), list) != -1)
1379 HLTError("Multiple symbols with the name '%s' defined in the trigger menu.", symbol->Name());
1382 new (list[list.GetEntriesFast()]) AliHLTTriggerMenuSymbol(*symbol);
1385 TRegexp exp("[_a-zA-Z][-_a-zA-Z0-9]*");
1386 TRegexp hexexp("x[a-fA-F0-9]+");
1387 for (UInt_t i = 0; i < menu->NumberOfItems(); i++)
1389 const AliHLTTriggerMenuItem* item = menu->Item(i);
1390 TString str = item->TriggerCondition();
1395 Ssiz_t pos = exp.Index(str, &length, start);
1396 if (pos == kNPOS) break;
1399 // Check if there is a numerical character before the found
1400 // regular expression. If so, then the symbol is not a valid one
1401 // and should be skipped.
1404 bool notValid = false;
1407 case '0': case '1': case '2': case '3': case '4':
1408 case '5': case '6': case '7': case '8': case '9':
1415 if (notValid) continue;
1417 TString s = str(pos, length);
1419 if (s == "and" or s == "and_eq" or s == "bitand" or s == "bitor" or
1420 s == "compl" or s == "not" or s == "not_eq" or s == "or" or
1421 s == "or_eq" or s == "xor" or s == "xor_eq" or s == "true" or
1425 // Ignore iso646.h and other keywords.
1429 // Need to create the symbols first and check if its name is in the list
1430 // before actually adding it to the symbols list.
1431 AliHLTTriggerMenuSymbol newSymbol;
1432 newSymbol.Name(s.Data());
1433 newSymbol.Type("bool");
1434 newSymbol.ObjectClass("AliHLTTriggerDecision");
1435 newSymbol.AssignExpression("this->Result()");
1436 newSymbol.DefaultValue("false");
1437 if (FindSymbol(newSymbol.Name(), list) == -1)
1439 new (list[list.GetEntriesFast()]) AliHLTTriggerMenuSymbol(newSymbol);
1442 while (start < str.Length());
1449 bool AliHLTGlobalTriggerComponent::ExtractedOperator(TString& expr, TString& op)
1451 // Extracts the trailing operator from the expression.
1454 // First skip the trailing whitespace.
1455 bool whitespace = true;
1456 for (i = expr.Length()-1; i >= 0 and whitespace; i--)
1460 case ' ': case '\t': case '\r': case '\n':
1467 if (i < 0 or whitespace) return false;
1469 // Now find the first whitespace character before the trailing symbol.
1470 bool nonwhitespace = true;
1471 for (; i >= 0 and nonwhitespace; i--)
1475 case ' ': case '\t': case '\r': case '\n':
1476 nonwhitespace = false;
1479 nonwhitespace = true;
1482 if (i < 0 or nonwhitespace) return false;
1484 // Extract the last symbols and check if it is a valid operator.
1487 if (s == "and" or s == "and_eq" or s == "bitand" or s == "bitor" or
1488 s == "compl" or s == "not" or s == "not_eq" or s == "or" or
1489 s == "or_eq" or s == "xor" or s == "xor_eq" or s == "&&" or
1490 s == "&=" or s == "&" or s == "|" or s == "~" or s == "!" or
1491 s == "!=" or s == "||" or s == "|=" or s == "^" or s == "^=" or
1492 s == "==" or s == "+" or s == "-" or s == "*" or s == "/" or
1493 s == "%" or s == ">" or s == "<" or s == ">=" or s == "<="
1505 int AliHLTGlobalTriggerComponent::PrintStatistics(const AliHLTGlobalTrigger* pTrigger, AliHLTComponentLogSeverity level, int offset) const
1507 // print some statistics
1508 int totalEvents=GetEventCount()+offset;
1509 const TArrayL64& counters = pTrigger->GetCounters();
1510 if (pTrigger->CallFailed()) return -EPROTO;
1511 for (int i = 0; i < counters.GetSize(); i++) {
1512 ULong64_t count = counters[i];
1514 if (totalEvents>0) ratio=100*(float)count/totalEvents;
1515 HLTLog(level, "Item %d: total events: %d - counted events: %llu (%.1f%%)", i, totalEvents, count, ratio);
1520 int AliHLTGlobalTriggerComponent::AddCTPDecisions(AliHLTGlobalTrigger* pTrigger, const AliHLTCTPData* pCTPData, const AliHLTComponentTriggerData* trigData)
1522 // add trigger decisions for the valid CTP classes
1523 if (!pCTPData || !pTrigger) return 0;
1525 AliHLTUInt64_t triggerMask=pCTPData->Mask();
1526 AliHLTUInt64_t bit0=0x1;
1527 if (!fCTPDecisions) {
1528 fCTPDecisions=new TClonesArray(AliHLTTriggerDecision::Class(), gkNCTPTriggerClasses);
1529 if (!fCTPDecisions) return -ENOMEM;
1531 fCTPDecisions->ExpandCreate(gkNCTPTriggerClasses);
1532 for (int i=0; i<gkNCTPTriggerClasses; i++) {
1533 const char* name=pCTPData->Name(i);
1534 if (triggerMask&(bit0<<i) && name) {
1535 AliHLTTriggerDecision* pDecision=dynamic_cast<AliHLTTriggerDecision*>(fCTPDecisions->At(i));
1538 delete fCTPDecisions;
1542 pDecision->Name(name);
1547 for (int i=0; i<gkNCTPTriggerClasses; i++) {
1548 const char* name=pCTPData->Name(i);
1549 if ((triggerMask&(bit0<<i))==0 || name==NULL) continue;
1550 AliHLTTriggerDecision* pDecision=dynamic_cast<AliHLTTriggerDecision*>(fCTPDecisions->At(i));
1551 HLTDebug("updating CTP trigger decision %d %s (%p casted %p)", i, name, fCTPDecisions->At(i), pDecision);
1552 if (!pDecision) return -ENOENT;
1555 if (trigData) result=pCTPData->EvaluateCTPTriggerClass(name, *trigData);
1556 else result=pCTPData->EvaluateCTPTriggerClass(name);
1557 pDecision->Result(result);
1558 pDecision->TriggerDomain().Clear();
1559 if (trigData) pDecision->TriggerDomain().Add(pCTPData->ReadoutList(*trigData));
1560 else pDecision->TriggerDomain().Add(pCTPData->ReadoutList());
1562 pTrigger->Add(fCTPDecisions->At(i), kAliHLTDataTypeTriggerDecision, kAliHLTVoidDataSpec);
1563 if (pTrigger->CallFailed()) return -EPROTO;