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." );
165 new (fIncludePaths[fIncludePaths.GetEntriesFast()]) TObjString(argv[i+1]);
167 catch (const std::bad_alloc&)
169 HLTError("Could not allocate more memory for the fIncludePaths array.");
176 if (strcmp(argv[i], "-include") == 0)
180 HLTError("The include file name was not specified." );
185 new (fIncludeFiles[fIncludeFiles.GetEntriesFast()]) TObjString(argv[i+1]);
187 catch (const std::bad_alloc&)
189 HLTError("Could not allocate more memory for the fIncludeFiles array.");
196 if (strcmp(argv[i], "-debug") == 0)
198 if (fDebugMode == true)
200 HLTWarning("The debug flag was already specified. Ignoring this instance.");
206 if (strcmp(argv[i], "-cint") == 0)
208 fRuntimeCompile = false;
212 if (strcmp(argv[i], "-usecode") == 0)
214 if (codeFileName != NULL)
216 HLTWarning("Custom trigger code file was already specified."
217 " Will replace previous value given by -usecode."
222 HLTError("The custom trigger code filename was not specified." );
225 codeFileName = argv[i+1];
228 HLTError("The custom trigger class name was not specified." );
231 fClassName = argv[i+2];
236 if (strcmp(argv[i], "-skipctp") == 0)
238 HLTInfo("Skipping CTP counters in trigger decision");
243 if (strcmp(argv[i], "-forward-input") == 0)
245 HLTInfo("Forwarding input objects and trigger decisions");
246 SetBit(kForwardInput);
247 SetBit(kIncludeShort);
248 SetBit(kIncludeInput, false);
252 if (strstr(argv[i], "-include-input") == argv[i])
254 SetBit(kForwardInput,false);
255 TString param=argv[i];
256 param.ReplaceAll("-include-input", "");
257 if (param.CompareTo("=none")==0)
259 HLTInfo("skipping objects and trigger decisions");
260 SetBit(kIncludeShort, false);
261 SetBit(kIncludeInput, false);
263 else if (param.CompareTo("=short")==0)
265 HLTInfo("including short info on objects and trigger decisions");
266 SetBit(kIncludeShort);
267 SetBit(kIncludeInput, false);
269 else if (param.CompareTo("=both")==0)
271 HLTInfo("including input objects, trigger decisions and short info");
272 SetBit(kIncludeShort);
273 SetBit(kIncludeInput);
275 else if (param.CompareTo("=objects")==0 || param.IsNull())
277 HLTInfo("including input objects and trigger decisions");
278 SetBit(kIncludeShort, false);
279 SetBit(kIncludeInput);
283 HLTError("unknown parameter '%s' for argument '-include-input'", param.Data());
288 if (strcmp(argv[i], "-process-all-events") == 0)
290 fDataEventsOnly = false;
294 HLTError("Unknown option '%s'.", argv[i]);
298 const AliHLTTriggerMenu* menu = NULL;
299 if (configFileName != NULL)
302 cmd += configFileName;
303 gROOT->ProcessLine(cmd);
304 menu = AliHLTGlobalTriggerConfig::Menu();
307 // Try load the trigger menu from the CDB if it is not loaded yet with the
309 int result = -ENOENT;
312 result = LoadTriggerMenu(fgkTriggerMenuCDBPath, menu);
316 HLTError("No trigger menu configuration found or specified.");
320 if (codeFileName == NULL)
322 result = GenerateTrigger(menu, fClassName, fCodeFileName, fIncludePaths, fIncludeFiles);
323 if (result == 0) fDeleteCodeFile = true;
327 result = LoadTriggerClass(codeFileName, fIncludePaths);
328 if (result == 0) fCodeFileName = codeFileName;
330 if (result != 0) return result;
334 fTrigger = AliHLTGlobalTrigger::CreateNew(fClassName.Data());
336 catch (const std::bad_alloc&)
338 HLTError("Could not allocate memory for the AliHLTGlobalTrigger instance.");
341 if (fTrigger == NULL)
343 HLTError("Could not create a new instance of '%s'.", fClassName.Data());
347 fTrigger->FillFromMenu(*menu);
348 if (fTrigger->CallFailed()) return -EPROTO;
350 // setup the CTP accounting in AliHLTComponent
353 // Set the default values from the trigger menu.
354 SetDescription(menu->DefaultDescription());
355 SetTriggerDomain(menu->DefaultTriggerDomain());
361 Int_t AliHLTGlobalTriggerComponent::DoDeinit()
363 // Cleans up the global trigger component.
365 if (fTrigger != NULL)
372 fCTPDecisions->Delete();
373 delete fCTPDecisions;
377 Int_t result = UnloadTriggerClass(fCodeFileName);
378 if (result != 0) return result;
380 if (fDeleteCodeFile and !fCodeFileName.IsNull() && gSystem->AccessPathName(fCodeFileName)==0 && !fDebugMode) {
381 fCodeFileName.ReplaceAll(".cxx", "*");
382 TString command="rm "; command+=fCodeFileName;
383 gSystem->Exec(command);
386 fDeleteCodeFile=false;
392 AliHLTComponent* AliHLTGlobalTriggerComponent::Spawn()
394 // Creates a new object instance.
395 AliHLTComponent* comp = NULL;
398 comp = new AliHLTGlobalTriggerComponent;
400 catch (const std::bad_alloc&)
402 HLTError("Could not allocate memory for a new instance of AliHLTGlobalTriggerComponent.");
409 int AliHLTGlobalTriggerComponent::DoTrigger()
411 // This method will apply the global trigger decision.
413 if (fTrigger == NULL)
415 HLTFatal("Global trigger implementation object is NULL!");
419 AliHLTUInt32_t eventType=0;
420 if (!IsDataEvent(&eventType)) {
421 if (eventType==gkAliEventTypeEndOfRun) PrintStatistics(fTrigger, kHLTLogImportant, 0);
429 // Copy the trigger counters in case we need to set them back to their original
430 // value because the PushBack method fails with ENOSPC.
431 TArrayL64 originalCounters = fTrigger->GetCounters();
432 if (fTrigger->CallFailed()) return -EPROTO;
434 fTrigger->NewEvent();
435 if (fTrigger->CallFailed()) return -EPROTO;
437 // Fill in the input data.
438 const TObject* obj = GetFirstInputObject();
441 fTrigger->Add(obj, GetDataType(), GetSpecification());
442 if (fTrigger->CallFailed()) return -EPROTO;
443 obj = GetNextInputObject();
446 // add trigger decisions for every CTP class
447 const AliHLTCTPData* pCTPData=CTPData();
449 AddCTPDecisions(fTrigger, pCTPData, GetTriggerData());
452 // Calculate the global trigger result and trigger domain, then create and push
453 // back the new global trigger decision object.
455 AliHLTTriggerDomain triggerDomain;
456 bool triggerResult = fTrigger->CalculateTriggerDecision(triggerDomain, description);
457 if (fTrigger->CallFailed()) return -EPROTO;
458 AliHLTGlobalTriggerDecision decision(
460 // The following will cause the decision to be generated with default values
461 // (set in fTriggerDomain and fDescription) if the trigger result is false.
462 (triggerResult == true) ? triggerDomain : GetTriggerDomain(),
463 (triggerResult == true) ? description.Data() : GetDescription()
466 // mask the readout list according to the CTP trigger
467 // if the classes have been initialized (mask non-zero)
468 if (pCTPData && pCTPData->Mask()) {
469 AliHLTEventDDL eventDDL=pCTPData->ReadoutList(*GetTriggerData());
470 AliHLTReadoutList ctpreadout(eventDDL);
471 ctpreadout.Enable(AliHLTReadoutList::kHLT);
472 AliHLTReadoutList maskedList=decision.ReadoutList();
473 maskedList.AndEq(ctpreadout);
474 decision.ReadoutList(maskedList);
477 decision.SetCounters(fTrigger->GetCounters(), GetEventCount()+1);
478 if (fTrigger->CallFailed()) return -EPROTO;
480 static UInt_t lastTime=0;
482 if (time.Get()-lastTime>60) {
484 PrintStatistics(fTrigger, kHLTLogImportant);
487 // Add the input objects used to the global decision.
488 TClonesArray* pShortInfo=NULL;
489 if (TestBit(kIncludeShort)) {
492 pShortInfo=new TClonesArray(TNamed::Class(), GetNumberOfInputBlocks());
494 catch (const std::bad_alloc&)
496 HLTError("Could not allocate memory for a short list of input objects.");
501 obj = GetFirstInputObject();
504 if (TestBit(kForwardInput)) {
507 if (TestBit(kIncludeInput)) {
508 if (obj->IsA() == AliHLTTriggerDecision::Class())
510 decision.AddTriggerInput( *static_cast<const AliHLTTriggerDecision*>(obj) );
514 decision.AddInputObject(obj);
518 if (TestBit(kIncludeShort)) {
519 int entries=pShortInfo->GetEntriesFast();
522 new ((*pShortInfo)[entries]) TNamed(obj->GetName(), obj->GetTitle());
524 catch (const std::bad_alloc&)
526 HLTError("Could not allocate more memory for the short list of input objects.");
530 if (obj->IsA() == AliHLTTriggerDecision::Class()) {
531 (*pShortInfo)[entries]->SetBit(BIT(16)); // indicate that this is a trigger decision
532 (*pShortInfo)[entries]->SetBit(BIT(15), ((AliHLTTriggerDecision*)obj)->Result());
536 obj = GetNextInputObject();
539 decision.AddInputObject(pShortInfo);
540 pShortInfo->Delete();
545 if (!TestBit(kSkipCTP) && CTPData()) decision.AddInputObject(CTPData());
547 // add readout filter to event done data
548 CreateEventDoneReadoutFilter(decision.TriggerDomain(), 3);
549 // add monitoring filter to event done data
550 CreateEventDoneReadoutFilter(decision.TriggerDomain(), 4);
551 if (decision.Result()) {
552 // add monitoring event command for triggered events
553 CreateEventDoneReadoutFilter(decision.TriggerDomain(), 5);
555 if (TriggerEvent(&decision) == -ENOSPC)
557 // Increase the estimated buffer space required if the PushBack methods in TriggerEvent
558 // returned the "no buffer space" error code. Also remember to set the trigger counters
559 // back to what they were, otherwise triggers will be double counted when we try to reprocess
560 // this event with larger buffers.
561 fBufferSizeConst += 1024*1024;
562 fBufferSizeMultiplier *= 2.;
563 fTrigger->SetCounters(originalCounters);
564 if (fTrigger->CallFailed()) return -EPROTO;
571 int AliHLTGlobalTriggerComponent::Reconfigure(const char* cdbEntry, const char* chainId)
573 // Reconfigure the component by loading the trigger menu and recreating the
574 // trigger logic class.
576 const char* path = fgkTriggerMenuCDBPath;
577 const char* id = "(unknown)";
578 if (cdbEntry != NULL) path = cdbEntry;
579 if (chainId != NULL and chainId[0] != '\0') id = chainId;
580 HLTInfo("Reconfiguring from '%s' for chain component '%s'.", path, id);
582 const AliHLTTriggerMenu* menu = NULL;
583 int result = LoadTriggerMenu(path, menu);
584 if (result != 0) return result;
587 TString codeFileName;
588 result = GenerateTrigger(menu, className, codeFileName, fIncludePaths, fIncludeFiles);
589 if (result != 0) return result;
591 AliHLTGlobalTrigger* trigger = NULL;
594 trigger = AliHLTGlobalTrigger::CreateNew(className.Data());
596 catch (const std::bad_alloc&)
598 HLTError("Could not allocate memory for the AliHLTGlobalTrigger instance.");
603 HLTError("Could not create a new instance of '%s'.", className.Data());
604 // Make sure to cleanup after the new code file.
605 UnloadTriggerClass(codeFileName);
606 if (not codeFileName.IsNull() and gSystem->AccessPathName(codeFileName)==0 and not fDebugMode)
608 codeFileName.ReplaceAll(".cxx", "*");
609 TString command="rm "; command+=codeFileName;
610 gSystem->Exec(command);
615 if (fTrigger != NULL)
622 fTrigger->FillFromMenu(*menu);
623 if (fTrigger->CallFailed()) return -EPROTO;
625 // Set the default values from the trigger menu.
626 SetDescription(menu->DefaultDescription());
627 SetTriggerDomain(menu->DefaultTriggerDomain());
629 // Cleanup the old class code.
630 UnloadTriggerClass(fCodeFileName);
631 if (fDeleteCodeFile and not fCodeFileName.IsNull() and gSystem->AccessPathName(fCodeFileName)==0 and not fDebugMode)
633 fCodeFileName.ReplaceAll(".cxx", "*");
634 TString command="rm "; command+=fCodeFileName;
635 gSystem->Exec(command);
637 fCodeFileName = codeFileName;
638 fDeleteCodeFile = true; // Since we generated a new class.
644 int AliHLTGlobalTriggerComponent::LoadTriggerMenu(const char* cdbPath, const AliHLTTriggerMenu*& menu)
646 // Loads the trigger menu object from the CDB path.
648 HLTDebug("Trying to load trigger menu from '%s'.", cdbPath);
649 if (AliCDBManager::Instance() == NULL)
651 HLTError("CDB manager object not found.");
654 AliCDBStorage* store = AliCDBManager::Instance()->GetDefaultStorage();
657 HLTError("Could not get the the default storage for the CDB.");
660 Int_t version = store->GetLatestVersion(cdbPath, GetRunNo());
661 Int_t subVersion = store->GetLatestSubVersion(cdbPath, GetRunNo(), version);
662 AliCDBEntry* entry = AliCDBManager::Instance()->Get(cdbPath, GetRunNo(), version, subVersion);
665 HLTError("Could not get the CDB entry for \"%s\".", cdbPath);
668 TObject* obj = entry->GetObject();
671 HLTError("Configuration object for \"%s\" is missing.", cdbPath);
674 if (obj->IsA() != AliHLTTriggerMenu::Class())
676 HLTError("Wrong type for configuration object in \"%s\". Found a %s but we expect a AliHLTTriggerMenu.",
677 cdbPath, obj->ClassName()
681 menu = static_cast<AliHLTTriggerMenu*>(obj);
686 int AliHLTGlobalTriggerComponent::GenerateTrigger(
687 const AliHLTTriggerMenu* menu, TString& name, TString& filename,
688 const TClonesArray& includePaths, const TClonesArray& includeFiles
691 // Generates the global trigger class that will implement the specified trigger menu.
692 // See header for more details.
694 HLTDebug("Generating custom HLT trigger class named %s using trigger menu %p.", ((void*)menu), name.Data());
696 // Create a new UUID and replace the '-' characters with '_' to make it a valid
699 TString uuidstr = uuid.AsString();
700 for (Int_t i = 0; i < uuidstr.Length(); i++)
702 if (uuidstr[i] == '-') uuidstr[i] = '_';
705 // Create the name of the new class.
706 name = "AliHLTGlobalTriggerImpl_";
708 filename = name + ".cxx";
710 // Open a text file to write the code and generate the new class.
711 fstream code(filename.Data(), ios_base::out | ios_base::trunc);
714 HLTError("Could not open file '%s' for writing.", filename.Data());
718 TClonesArray symbols(AliHLTTriggerMenuSymbol::Class());
719 int result = BuildSymbolList(menu, symbols);
720 if (result != 0) return result;
722 code << "#if !defined(__CINT__) || defined(__MAKECINT__)" << endl;
723 code << "#include <cstring>" << endl;
724 code << "#include \"TString.h\"" << endl;
725 code << "#include \"TClonesArray.h\"" << endl;
726 code << "#include \"AliHLTLogging.h\"" << endl;
727 code << "#include \"AliHLTGlobalTrigger.h\"" << endl;
728 code << "#include \"AliHLTGlobalTriggerDecision.h\"" << endl;
729 code << "#include \"AliHLTDomainEntry.h\"" << endl;
730 code << "#include \"AliHLTTriggerDomain.h\"" << endl;
731 code << "#include \"AliHLTReadoutList.h\"" << endl;
732 code << "#include \"AliHLTTriggerMenu.h\"" << endl;
733 code << "#include \"AliHLTTriggerMenuItem.h\"" << endl;
734 code << "#include \"AliHLTTriggerMenuSymbol.h\"" << endl;
736 // Add any include files that were specified on the command line.
737 for (Int_t i = 0; i < includeFiles.GetEntriesFast(); i++)
739 TString file = static_cast<TObjString*>(includeFiles.UncheckedAt(i))->String();
740 code << "#include \"" << file.Data() << "\"" << endl;
745 code << "#else" << endl;
746 code << "const char* gFunctionName = \"???\";" << endl;
747 code << "#define HLTDebug(msg) if (CheckFilter(kHLTLogDebug) && CheckGroup(Class_Name())) SendMessage(kHLTLogDebug, Class_Name(), ::gFunctionName, __FILE__, __LINE__, msg)" << endl;
749 code << "#endif" << endl;
751 code << "class " << name << " :" << endl;
752 // Add appropriate #ifdef sections since we need to prevent inheritance from
753 // AliHLTGlobalTrigger. CINT does not seem to support multiple inheritance nor
754 // multiple levels of inheritance. Neither of the following schemes worked:
756 // 1) class AliHLTGlobalTrigger : public AliHLTLogging {};
757 // class AliHLTGlobalTriggerImpl_xyz : public AliHLTGlobalTrigger {};
759 // 2) class AliHLTGlobalTrigger {};
760 // class AliHLTGlobalTriggerImpl_xyz : public AliHLTGlobalTrigger, public AliHLTLogging {};
762 // Thus, we are forced to just inherit from AliHLTLogging when running in the CINT
763 // interpreter. But we anyway have to call the global trigger implementation class
764 // through the AliHLTGlobalTriggerWrapper so this is not such a problem.
765 code << "#if !defined(__CINT__) || defined(__MAKECINT__)" << endl;
766 code << " public AliHLTGlobalTrigger," << endl;
767 code << "#endif" << endl;
768 code << " public AliHLTLogging" << endl;
770 code << "public:" << endl;
772 // Generate constructor method.
773 code << " " << name << "() :" << endl;
774 code << "#if !defined(__CINT__) || defined(__MAKECINT__)" << endl;
775 code << " AliHLTGlobalTrigger()," << endl;
776 code << "#endif" << endl;
777 code << " AliHLTLogging()";
778 // Write the symbols in the trigger menu in the initialisation list.
779 for (Int_t i = 0; i < symbols.GetEntriesFast(); i++)
782 AliHLTTriggerMenuSymbol* symbol = static_cast<AliHLTTriggerMenuSymbol*>( symbols.UncheckedAt(i) );
783 code << " " << symbol->Name() << "()," << endl;
784 if (strcmp(symbol->ObjectClass(), "AliHLTTriggerDecision") == 0)
786 code << " " << symbol->Name() << "TriggerDomain()," << endl;
788 code << " " << symbol->Name() << "DomainEntry(kAliHLTAnyDataType)";
790 for (UInt_t i = 0; i < menu->NumberOfItems(); i++)
792 code << "," << endl << " fMenuItemDescription" << i << "()";
794 code << endl << " {" << endl;
797 code << "#ifdef __CINT__" << endl;
798 code << " gFunctionName = \"" << name.Data() <<"\";" << endl;
799 code << "#endif" << endl;
800 code << " SetLocalLoggingLevel(kHLTLogAll);" << endl;
801 code << " HLTDebug(Form(\"Creating new instance at %p.\", this));" << endl;
803 code << " }" << endl;
805 code << " virtual ~" << name << "() {" << endl;
808 code << "#ifdef __CINT__" << endl;
809 code << " gFunctionName = \"~" << name.Data() << "\";" << endl;
810 code << "#endif" << endl;
811 code << " HLTDebug(Form(\"Deleting instance at %p.\", this));" << endl;
813 code << " }" << endl;
815 // Generate the FillFromMenu method.
816 code << " virtual void FillFromMenu(const AliHLTTriggerMenu& menu) {" << endl;
819 code << "#ifdef __CINT__" << endl;
820 code << " gFunctionName = \"FillFromMenu\";" << endl;
821 code << "#endif" << endl;
822 code << " HLTDebug(Form(\"Filling description entries from trigger menu for global trigger %p.\", this));" << endl;
824 code << " fCounter.Set(menu.NumberOfItems());" << endl;
825 for (UInt_t i = 0; i < menu->NumberOfItems(); i++)
827 code << " fMenuItemDescription" << i << " = (menu.Item(" << i
828 << ") != NULL) ? menu.Item(" << i << ")->Description() : \"\";" << endl;
832 code << " HLTDebug(Form(\"Finished filling description entries from trigger menu.\"));" << endl;
833 code << " HLTDebug(Form(\"Filling domain entries from trigger menu symbols for global trigger %p.\", this));" << endl;
835 code << " for (Int_t i = 0; i < menu.SymbolArray().GetEntriesFast(); i++) {" << endl;
836 // 30 Oct 2009 - CINT sometimes evaluates the dynamic_cast incorrectly.
837 // Have to use the TClass system for extra protection.
838 code << " if (menu.SymbolArray().UncheckedAt(i) == NULL) continue;" << endl;
839 code << " if (menu.SymbolArray().UncheckedAt(i)->IsA() != AliHLTTriggerMenuSymbol::Class()) continue;" << endl;
840 code << " const AliHLTTriggerMenuSymbol* symbol = dynamic_cast<const"
841 " AliHLTTriggerMenuSymbol*>(menu.SymbolArray().UncheckedAt(i));" << endl;
842 code << " if (symbol == NULL) continue;" << endl;
843 for (Int_t i = 0; i < symbols.GetEntriesFast(); i++)
845 AliHLTTriggerMenuSymbol* symbol = static_cast<AliHLTTriggerMenuSymbol*>( symbols.UncheckedAt(i) );
846 code << " if (strcmp(symbol->RealName(), \"" << symbol->RealName() << "\") == 0) {" << endl;
849 code << " HLTDebug(Form(\"Assinging domain entry value corresponding with symbol '%s' to '%s'.\","
850 " symbol->RealName(), symbol->BlockType().AsString().Data()));" << endl;
852 code << " " << symbol->Name() << "DomainEntry = symbol->BlockType();" << endl;
853 code << " continue;" << endl;
854 code << " }" << endl;
856 code << " }" << endl;
859 code << " HLTDebug(Form(\"Finished filling domain entries from trigger menu symbols.\"));" << endl;
861 code << " }" << endl;
863 // Generate the NewEvent method.
864 code << " virtual void NewEvent() {" << endl;
867 code << "#ifdef __CINT__" << endl;
868 code << " gFunctionName = \"NewEvent\";" << endl;
869 code << "#endif" << endl;
870 code << " HLTDebug(Form(\"New event for global trigger object %p, initialising variables to default values.\", this));" << endl;
872 // Write code to initialise the symbols in the trigger menu to their default values.
873 for (Int_t i = 0; i < symbols.GetEntriesFast(); i++)
875 AliHLTTriggerMenuSymbol* symbol = static_cast<AliHLTTriggerMenuSymbol*>( symbols.UncheckedAt(i) );
876 // CINT has problems with the implicit equals operator for complex types, so if
877 // the type has a equals operater we need to write the operator call explicitly.
878 TClass* clas = TClass::GetClass(symbol->Type());
879 if (clas != NULL and clas->GetMethodAny("operator=") != NULL)
881 code << " " << symbol->Name() << ".operator = (" << symbol->DefaultValue() << ");" << endl;
885 code << " " << symbol->Name() << " = " << symbol->DefaultValue() << ";" << endl;
887 if (strcmp(symbol->ObjectClass(), "AliHLTTriggerDecision") == 0)
889 code << " " << symbol->Name() << "TriggerDomain.Clear();" << endl;
894 code << " HLTDebug(Form(\"Finished initialising variables.\"));" << endl;
896 code << " }" << endl;
898 // Generate the Add method.
899 bool haveAssignments = false;
900 for (Int_t i = 0; i < symbols.GetEntriesFast(); i++)
902 // First check if we have any symbols with assignment expressions.
903 // This is needed to get rid of the on the fly compilation warning about '_object_' not being used.
904 AliHLTTriggerMenuSymbol* symbol = static_cast<AliHLTTriggerMenuSymbol*>( symbols.UncheckedAt(i) );
905 TString expr = symbol->AssignExpression();
906 if (expr == "") continue; // Skip entries that have no assignment expression.
907 haveAssignments = true;
910 if (haveAssignments or fDebugMode)
912 code << " virtual void Add(const TObject* _object_, const AliHLTComponentDataType& _type_, AliHLTUInt32_t _spec_) {" << endl;
916 code << " virtual void Add(const TObject* /*_object_*/, const AliHLTComponentDataType& _type_, AliHLTUInt32_t _spec_) {" << endl;
920 code << "#ifdef __CINT__" << endl;
921 code << " gFunctionName = \"Add\";" << endl;
922 code << "#endif" << endl;
924 code << " AliHLTDomainEntry _type_spec_(_type_, _spec_);" << endl;
927 code << " HLTDebug(Form(\"Adding TObject %p, with class name '%s' from data block"
928 " '%s', to global trigger object %p\", _object_, _object_->ClassName(),"
929 " _type_spec_.AsString().Data(), this));" << endl;
930 code << " _object_->Print();" << endl;
931 code << " bool _object_assigned_ = false;" << endl;
933 for (Int_t i = 0; i < symbols.GetEntriesFast(); i++)
935 // Write code to check if the block type, specification and class name is correct.
936 // Then write code to assign the variable from the input object.
937 AliHLTTriggerMenuSymbol* symbol = static_cast<AliHLTTriggerMenuSymbol*>( symbols.UncheckedAt(i) );
938 TString expr = symbol->AssignExpression();
939 if (expr == "") continue; // Skip entries that have no assignment expression.
940 bool isTrigDecision = strcmp(symbol->ObjectClass(), "AliHLTTriggerDecision") == 0;
945 code << " HLTDebug(Form(\"Trying to match input object to class '"
946 << symbol->ObjectClass() << "', trigger name '" << symbol->RealName()
947 << "' and block type '%s'\", " << symbol->Name()
948 << "DomainEntry.AsString().Data()));" << endl;
952 code << " HLTDebug(Form(\"Trying to match input object to class '"
953 << symbol->ObjectClass() << "' and block type '%s'\", "
954 << symbol->Name() << "DomainEntry.AsString().Data()));" << endl;
957 // 30 Oct 2009 - CINT sometimes evaluates the dynamic_cast incorrectly.
958 // Have to use the TClass system for extra protection.
959 code << " const " << symbol->ObjectClass() << "* " << symbol->Name() << "_object_ = NULL;" << endl;
960 code << " if (_object_->IsA() == " << symbol->ObjectClass() << "::Class()) " << symbol->Name()
961 << "_object_ = dynamic_cast<const " << symbol->ObjectClass()
962 << "*>(_object_);" << endl;
963 code << " if (" << symbol->Name() << "_object_ != NULL && ";
966 code << "strcmp(" << symbol->Name() << "_object_->Name(), \""
967 << symbol->RealName() << "\") == 0 && ";
969 code << symbol->Name() << "DomainEntry == _type_spec_) {" << endl;
970 TString fullname = symbol->Name();
971 fullname += "_object_";
972 expr.ReplaceAll("this", fullname);
973 code << " this->" << symbol->Name() << " = " << expr.Data() << ";" << endl;
976 code << " this->" << symbol->Name() << "TriggerDomain = "
977 << fullname.Data() << "->TriggerDomain();" << endl;
981 code << " HLTDebug(Form(\"Added TObject %p with class name '%s' to variable "
982 << symbol->Name() << "\", _object_, _object_->ClassName()));" << endl;
983 code << " _object_assigned_ = true;" << endl;
985 code << " }" << endl;
989 code << " if (! _object_assigned_) {" << endl;
990 code << " HLTDebug(Form(\"Did not assign TObject %p"
991 " with class name '%s' to any variable.\", _object_, _object_->ClassName()));"
993 code << " }" << endl;
995 code << " }" << endl;
997 // Generate the CalculateTriggerDecision method.
998 // This requires code to be generated that checks which items in the trigger menu
999 // have their conditions asserted and then the trigger domain is generated from
1000 // those fired items.
1001 // The processing will start from the highest priority trigger group and stop
1002 // after at least one trigger from the current priority group being processed
1003 // is positive. For each priority group all the trigger menu items are checked.
1004 // Their combined trigger condition expression must be true for the trigger priority
1005 // group to be triggered positive. The full condition expression is formed by
1006 // concatenating the individual condition expressions. If no trailing operators are
1007 // used in the individual expressions then the default condition operator is placed
1008 // between two concatenated condition expressions.
1009 // If a trigger priority group has at least one trigger fired then the trigger domain
1010 // is calculated such that it will give the same result as the concatenated trigger
1011 // domain merging expressions for all the individual trigger menu items with
1012 // positive results. Again, if no trailing operators are used in the individual
1013 // merging expressions then the default domain operator is placed between two
1014 // expression fragments.
1015 code << " virtual bool CalculateTriggerDecision(AliHLTTriggerDomain& _domain_, TString& _description_) {" << endl;
1018 code << "#ifdef __CINT__" << endl;
1019 code << " gFunctionName = \"CalculateTriggerDecision\";" << endl;
1020 code << "#endif" << endl;
1021 code << " HLTDebug(Form(\"Calculating global HLT trigger result with trigger object at %p.\", this));" << endl;
1024 // Build a list of priorities used in the trigger menu.
1025 std::vector<UInt_t> priorities;
1026 for (UInt_t i = 0; i < menu->NumberOfItems(); i++)
1028 const AliHLTTriggerMenuItem* item = menu->Item(i);
1029 bool priorityNotInList = std::find(priorities.begin(), priorities.end(), item->Priority()) == priorities.end();
1030 if (priorityNotInList) priorities.push_back(item->Priority());
1032 std::sort(priorities.begin(), priorities.end(), AliHLTDescendingNumbers);
1033 // From the priority list, build the priority groups in the correct order,
1034 // i.e. highest priority first.
1035 // The priority group is a list of vectors of integers. The integers are the
1036 // index numbers into the trigger menu item list for the items which form part
1037 // of the priority group.
1038 std::vector<std::vector<Int_t> > priorityGroup;
1039 priorityGroup.insert(priorityGroup.begin(), priorities.size(), std::vector<Int_t>());
1040 for (size_t n = 0; n < priorities.size(); n++)
1042 UInt_t priority = priorities[n];
1043 for (UInt_t i = 0; i < menu->NumberOfItems(); i++)
1045 const AliHLTTriggerMenuItem* item = menu->Item(i);
1046 if (item->Priority() == priority) priorityGroup[n].push_back(i);
1050 for (size_t n = 0; n < priorityGroup.size(); n++)
1054 code << " HLTDebug(Form(\"Processing trigger priority group " << priorities[n] << "\"));" << endl;
1057 if (n == 0) code << "UInt_t ";
1058 code << "_previous_match_ = 0xFFFFFFFF;" << endl;
1060 if (n == 0) code << "bool ";
1061 code << "_trigger_matched_ = false;" << endl;
1063 if (n == 0) code << "bool ";
1064 code << "_group_result_ = false;" << endl;
1065 std::vector<TString> conditionOperator;
1066 conditionOperator.insert(conditionOperator.begin(), priorityGroup[n].size(), TString(""));
1067 std::vector<TString> domainOperator;
1068 domainOperator.insert(domainOperator.begin(), priorityGroup[n].size(), TString(""));
1069 for (size_t m = 0; m < priorityGroup[n].size(); m++)
1071 UInt_t i = priorityGroup[n][m];
1072 const AliHLTTriggerMenuItem* item = menu->Item(i);
1073 TString triggerCondition = item->TriggerCondition();
1074 TString mergeExpr = item->MergeExpression();
1075 // Replace the symbols found in the trigger condition and merging expressions
1076 // with appropriate compilable versions.
1077 for (Int_t j = 0; j < symbols.GetEntriesFast(); j++)
1079 AliHLTTriggerMenuSymbol* symbol = static_cast<AliHLTTriggerMenuSymbol*>( symbols.UncheckedAt(j) );
1080 bool symbolNamesDifferent = strcmp(symbol->RealName(), symbol->Name()) != 0;
1081 if (strcmp(symbol->ObjectClass(), "AliHLTTriggerDecision") == 0)
1083 TString newname = symbol->Name();
1084 newname += "TriggerDomain";
1085 mergeExpr.ReplaceAll(symbol->RealName(), newname);
1089 if (symbolNamesDifferent) mergeExpr.ReplaceAll(symbol->RealName(), symbol->Name());
1091 if (symbolNamesDifferent) triggerCondition.ReplaceAll(symbol->RealName(), symbol->Name());
1093 // We allow the trigger conditions and merging expressions to have trailing operators.
1094 // Thus, we need to extract the operators and cleanup the expressions so that they will
1095 // compile. This means that we silently ignore the trailing operator if not needed.
1096 if (ExtractedOperator(triggerCondition, conditionOperator[m]))
1098 // If the trailing operator is the same as the default operator then reset
1099 // the value in the operator list so that the default is used in the generated
1100 // code. This creates more compact code.
1101 if (conditionOperator[m] == menu->DefaultConditionOperator()) conditionOperator[m] = "";
1103 if (ExtractedOperator(mergeExpr, domainOperator[m]))
1105 if (domainOperator[m] == menu->DefaultDomainOperator()) domainOperator[m] = "";
1109 code << " HLTDebug(Form(\"Trying trigger condition " << i
1110 << " (Description = '%s').\", fMenuItemDescription" << i << ".Data()));"
1114 if (n == 0 and m == 0) code << "bool ";
1115 code << "_item_result_ = false;" << endl;
1116 code << " if (" << triggerCondition << ") {" << endl;
1117 code << " ++fCounter[" << i << "];" << endl;
1118 const char* indentation = "";
1119 if (item->PreScalar() != 0)
1122 code << " if ((fCounter[" << i << "] % " << item->PreScalar() << ") == 1) {" << endl;
1124 code << indentation << " _item_result_ = true;" << endl;
1127 code << indentation << " HLTDebug(Form(\"Matched trigger condition " << i
1128 << " (Description = '%s').\", fMenuItemDescription" << i << ".Data()));" << endl;
1130 if (item->PreScalar() != 0)
1132 code << " }" << endl;
1134 code << " }" << endl;
1137 // Since this is the first item of the trigger group,
1138 // the generated trigger logic can be simplified a little.
1139 code << " _group_result_ = _item_result_;" << endl;
1140 code << " if (_item_result_) {" << endl;
1141 code << " _domain_ = " << mergeExpr.Data() << ";" << endl;
1142 code << " _description_ = fMenuItemDescription" << i << ";" << endl;
1143 code << " _previous_match_ = " << i << ";" << endl;
1144 code << " _trigger_matched_ = true;" << endl;
1145 code << " }" << endl;
1149 if (conditionOperator[m-1] == "")
1151 code << " _group_result_ = _group_result_ "
1152 << menu->DefaultConditionOperator() << " _item_result_;" << endl;
1156 code << " _group_result_ = _group_result_ "
1157 << conditionOperator[m-1] << " _item_result_;" << endl;
1159 code << " if (_item_result_) {" << endl;
1160 code << " if (_trigger_matched_) {" << endl;
1161 bool switchWillBeEmpty = true;
1162 for (size_t k = 0; k < m; k++)
1164 if (domainOperator[k] == "") continue;
1165 switchWillBeEmpty = false;
1167 if (switchWillBeEmpty)
1169 code << " _domain_ = _domain_ " << menu->DefaultDomainOperator() << " "
1170 << mergeExpr.Data() << ";" << endl;
1174 code << " switch(_previous_match_) {" << endl;
1175 for (size_t k = 0; k < m; k++)
1177 if (domainOperator[k] == "") continue;
1178 code << " case " << k << ": _domain_ = _domain_ "
1179 << domainOperator[k] << " " << mergeExpr.Data() << "; break;" << endl;
1181 code << " default: _domain_ = _domain_ "
1182 << menu->DefaultDomainOperator() << " " << mergeExpr.Data() << ";" << endl;
1183 code << " }" << endl;
1185 code << " _description_ += \",\";" << endl;
1186 code << " _description_ += fMenuItemDescription" << i << ";" << endl;
1187 code << " } else {" << endl;
1188 code << " _domain_ = " << mergeExpr.Data() << ";" << endl;
1189 code << " _description_ = fMenuItemDescription" << i << ";" << endl;
1190 code << " }" << endl;
1191 code << " _previous_match_ = " << i << ";" << endl;
1192 code << " _trigger_matched_ = true;" << endl;
1193 code << " }" << endl;
1196 code << " if (_group_result_) {" << endl;
1199 if (n < priorities.size() - 1)
1201 code << " HLTDebug(Form(\"Matched triggers in trigger priority group " << priorities[n]
1202 << ". Stopping processing here because all other trigger groups have lower priority.\"));" << endl;
1206 code << " HLTDebug(Form(\"Matched triggers in trigger priority group " << priorities[n] << ".\"));" << endl;
1209 code << " return true;" << endl;
1210 code << " }" << endl;
1212 code << " _domain_.Clear();" << endl;
1213 code << " _description_ = \"\";" << endl;
1214 code << " return false;" << endl;
1215 code << " }" << endl;
1217 // Generate getter and setter methods for the counters.
1218 code << " const TArrayL64& GetCounters() const { return fCounter; }" << endl;
1219 code << " void SetCounters(const TArrayL64& counters) { fCounter = counters; }" << endl;
1221 code << "private:" << endl;
1222 // Add the symbols in the trigger menu to the list of private variables.
1223 for (Int_t i = 0; i < symbols.GetEntriesFast(); i++)
1225 AliHLTTriggerMenuSymbol* symbol = static_cast<AliHLTTriggerMenuSymbol*>( symbols.UncheckedAt(i) );
1226 code << " " << symbol->Type() << " " << symbol->Name() << ";" << endl;
1227 if (strcmp(symbol->ObjectClass(), "AliHLTTriggerDecision") == 0)
1229 code << " AliHLTTriggerDomain " << symbol->Name() << "TriggerDomain;" << endl;
1231 code << " AliHLTDomainEntry " << symbol->Name() << "DomainEntry;" << endl;
1233 for (UInt_t i = 0; i < menu->NumberOfItems(); i++)
1235 code << " TString fMenuItemDescription" << i << ";" << endl;
1237 code << " TArrayL64 fCounter;" << endl;
1238 code << "#if !defined(__CINT__) || defined(__MAKECINT__)" << endl;
1239 code << " ClassDef(" << name.Data() << ", 0)" << endl;
1240 code << "#else" << endl;
1241 code << " virtual const char* Class_Name() const { return \"" << name.Data() << "\"; }" << endl;
1242 code << "#endif" << endl;
1243 code << "};" << endl;
1244 code << "#if !defined(__CINT__) || defined(__MAKECINT__)" << endl;
1245 code << "ClassImp(" << name.Data() << ")" << endl;
1246 code << "#endif" << endl;
1250 // Now we need to compile and load the new class.
1251 result = LoadTriggerClass(filename, includePaths);
1256 int AliHLTGlobalTriggerComponent::LoadTriggerClass(
1257 const char* filename, const TClonesArray& includePaths
1260 // Loads the code for a custom global trigger class implementation on the fly.
1262 HLTDebug("Loading HLT trigger class from file '%s'.", filename);
1264 TString compiler = gSystem->GetBuildCompilerVersion();
1265 if (fRuntimeCompile && (compiler.Contains("gcc") or compiler.Contains("icc")))
1267 TString includePath;
1268 #if defined(PKGINCLUDEDIR)
1269 // this is especially for the HLT build system where the package is installed
1270 // in a specific directory including proper treatment of include files
1271 includePath.Form("-I%s", PKGINCLUDEDIR);
1273 // the default AliRoot behavior, all include files can be found in the
1274 // $ALICE_ROOT subfolders
1275 includePath = "-I${ALICE_ROOT}/include -I${ALICE_ROOT}/HLT/BASE -I${ALICE_ROOT}/HLT/trigger";
1277 // Add any include paths that were specified on the command line.
1278 for (Int_t i = 0; i < includePaths.GetEntriesFast(); i++)
1280 TString path = static_cast<TObjString*>(includePaths.UncheckedAt(i))->String();
1281 includePath += " -I";
1282 includePath += path;
1284 HLTDebug("using include settings: %s", includePath.Data());
1285 gSystem->SetIncludePath(includePath);
1286 gSystem->SetFlagsOpt("-O3 -DNDEBUG");
1287 gSystem->SetFlagsDebug("-g3 -DDEBUG -D__DEBUG");
1292 result = gSystem->CompileMacro(filename, "g");
1296 result = gSystem->CompileMacro(filename, "O");
1298 if (result != kTRUE)
1300 HLTFatal("Could not compile and load global trigger menu implementation.");
1306 // Store the library state to be checked later in UnloadTriggerClass.
1307 fLibStateAtLoad = gSystem->GetLibraries();
1309 // If we do not support the compiler then try interpret the class instead.
1310 TString cmd = ".L ";
1312 Int_t errorcode = TInterpreter::kNoError;
1313 gROOT->ProcessLine(cmd, &errorcode);
1314 if (errorcode != TInterpreter::kNoError)
1316 HLTFatal("Could not load interpreted global trigger menu implementation"
1317 " (Interpreter error code = %d).",
1328 int AliHLTGlobalTriggerComponent::UnloadTriggerClass(const char* filename)
1330 // Unloads the code previously loaded by LoadTriggerClass.
1332 HLTDebug("Unloading HLT trigger class in file '%s'.", filename);
1334 TString compiler = gSystem->GetBuildCompilerVersion();
1335 if (fRuntimeCompile && (compiler.Contains("gcc") or compiler.Contains("icc")))
1337 // Generate the library name.
1338 TString libname = filename;
1339 Ssiz_t dotpos = libname.Last('.');
1340 if (0 <= dotpos and dotpos < libname.Length()) libname[dotpos] = '_';
1342 libname += gSystem->GetSoExt();
1344 // This is a workaround for a problem with unloading shared libraries in ROOT.
1345 // If the trigger logic library is loaded before the libAliHLTHOMER.so library
1346 // or any other library is loaded afterwards, then during the gInterpreter->UnloadFile
1347 // call all the subsequent libraries get unloded. This means that any objects created
1348 // from classes implemented in the libAliHLTHOMER.so library will generate segfaults
1349 // since the executable code has been unloaded.
1350 // We need to check if there are any more libraries loaded after the class we
1351 // are unloading and in that case don't unload the class.
1352 TString libstring = gSystem->GetLibraries();
1353 TString token, lastlib;
1355 Int_t numOfLibs = 0, posOfLib = -1;
1356 while (libstring.Tokenize(token, from, " "))
1360 if (token.Contains(libname)) posOfLib = numOfLibs;
1362 if (numOfLibs != posOfLib)
1364 HLTWarning(Form("ROOT limitation! Cannot properly cleanup and unload the shared"
1365 " library '%s' since another library '%s' was loaded afterwards. Trying to"
1366 " unload this library will remove the others and lead to serious memory faults.",
1367 libname.Data(), lastlib.Data()
1374 if ((path = gSystem->DynamicPathName(libname)) != NULL)
1376 result = gInterpreter->UnloadFile(path);
1379 if (result != TInterpreter::kNoError) return -ENOENT;
1383 // This is again a workaround for the problem with unloading files in ROOT.
1384 // If the trigger logic class is loaded before the libAliHLTHOMER.so library
1385 // or any other library is loaded afterwards, then during the gInterpreter->UnloadFile
1386 // call all the subsequent libraries get unloded.
1387 // We need to check if the list of loaded libraries has changed since the last
1388 // call to LoadTriggerClass. If it has then don't unload the class.
1389 if (fLibStateAtLoad != gSystem->GetLibraries())
1391 TString libstring = gSystem->GetLibraries();
1394 while (libstring.Tokenize(token, from, " "))
1396 if (not fLibStateAtLoad.Contains(token)) break;
1398 HLTWarning(Form("ROOT limitation! Cannot properly cleanup and unload the file"
1399 " '%s' since another library '%s' was loaded afterwards. Trying to unload"
1400 " this file will remove the other library and lead to serious memory faults.",
1401 filename, token.Data()
1406 // If we did not compile the trigger logic then remove the interpreted class.
1407 TString cmd = ".U ";
1409 Int_t errorcode = TInterpreter::kNoError;
1410 gROOT->ProcessLine(cmd, &errorcode);
1411 if (errorcode != TInterpreter::kNoError)
1413 HLTFatal("Could not unload interpreted global trigger menu implementation"
1414 " (Interpreter error code = %d).",
1425 int AliHLTGlobalTriggerComponent::FindSymbol(const char* name, const TClonesArray& list)
1427 // Searches for the named symbol in the given list.
1428 // See header for more details.
1430 for (int i = 0; i < list.GetEntriesFast(); i++)
1432 const AliHLTTriggerMenuSymbol* symbol = dynamic_cast<const AliHLTTriggerMenuSymbol*>( list.UncheckedAt(i) );
1433 if (symbol == NULL) continue;
1434 if (strcmp(symbol->Name(), name) == 0) return i;
1440 int AliHLTGlobalTriggerComponent::BuildSymbolList(const AliHLTTriggerMenu* menu, TClonesArray& list)
1442 // Builds the list of symbols to use in the custom global trigger menu
1443 // implementation class.
1444 // See header for more details.
1446 // Note: when we build the symbol list we must use the symbol name as returned
1447 // by the Name() method and not the RealName() method when using FindSymbol.
1448 // This is so that we avoid problems with the generated code not compiling
1449 // because names like "abc-xyz" and "abc_xyz" are synonymous.
1450 // Name() returns the converted C++ symbol name as used in the generated code.
1452 for (UInt_t i = 0; i < menu->NumberOfSymbols(); i++)
1454 const AliHLTTriggerMenuSymbol* symbol = menu->Symbol(i);
1455 if (FindSymbol(symbol->Name(), list) != -1)
1457 HLTError("Multiple symbols with the name '%s' defined in the trigger menu.", symbol->Name());
1462 new (list[list.GetEntriesFast()]) AliHLTTriggerMenuSymbol(*symbol);
1464 catch (const std::bad_alloc&)
1466 HLTError("Could not allocate more memory for the symbols list when adding a trigger menu symbol.");
1471 TRegexp exp("[_a-zA-Z][-_a-zA-Z0-9]*");
1472 TRegexp hexexp("x[a-fA-F0-9]+");
1473 for (UInt_t i = 0; i < menu->NumberOfItems(); i++)
1475 const AliHLTTriggerMenuItem* item = menu->Item(i);
1476 TString str = item->TriggerCondition();
1481 Ssiz_t pos = exp.Index(str, &length, start);
1482 if (pos == kNPOS) break;
1485 // Check if there is a numerical character before the found
1486 // regular expression. If so, then the symbol is not a valid one
1487 // and should be skipped.
1490 bool notValid = false;
1493 case '0': case '1': case '2': case '3': case '4':
1494 case '5': case '6': case '7': case '8': case '9':
1501 if (notValid) continue;
1503 TString s = str(pos, length);
1505 if (s == "and" or s == "and_eq" or s == "bitand" or s == "bitor" or
1506 s == "compl" or s == "not" or s == "not_eq" or s == "or" or
1507 s == "or_eq" or s == "xor" or s == "xor_eq" or s == "true" or
1511 // Ignore iso646.h and other keywords.
1515 // Need to create the symbols first and check if its name is in the list
1516 // before actually adding it to the symbols list.
1517 AliHLTTriggerMenuSymbol newSymbol;
1518 newSymbol.Name(s.Data());
1519 newSymbol.Type("bool");
1520 newSymbol.ObjectClass("AliHLTTriggerDecision");
1521 newSymbol.AssignExpression("this->Result()");
1522 newSymbol.DefaultValue("false");
1523 if (FindSymbol(newSymbol.Name(), list) == -1)
1527 new (list[list.GetEntriesFast()]) AliHLTTriggerMenuSymbol(newSymbol);
1529 catch (const std::bad_alloc&)
1531 HLTError("Could not allocate more memory for the symbols list when adding a trigger name symbol.");
1536 while (start < str.Length());
1543 bool AliHLTGlobalTriggerComponent::ExtractedOperator(TString& expr, TString& op)
1545 // Extracts the trailing operator from the expression.
1548 // First skip the trailing whitespace.
1549 bool whitespace = true;
1550 for (i = expr.Length()-1; i >= 0 and whitespace; i--)
1554 case ' ': case '\t': case '\r': case '\n':
1561 if (i < 0 or whitespace) return false;
1563 // Now find the first whitespace character before the trailing symbol.
1564 bool nonwhitespace = true;
1565 for (; i >= 0 and nonwhitespace; i--)
1569 case ' ': case '\t': case '\r': case '\n':
1570 nonwhitespace = false;
1573 nonwhitespace = true;
1576 if (i < 0 or nonwhitespace) return false;
1578 // Extract the last symbols and check if it is a valid operator.
1581 if (s == "and" or s == "and_eq" or s == "bitand" or s == "bitor" or
1582 s == "compl" or s == "not" or s == "not_eq" or s == "or" or
1583 s == "or_eq" or s == "xor" or s == "xor_eq" or s == "&&" or
1584 s == "&=" or s == "&" or s == "|" or s == "~" or s == "!" or
1585 s == "!=" or s == "||" or s == "|=" or s == "^" or s == "^=" or
1586 s == "==" or s == "+" or s == "-" or s == "*" or s == "/" or
1587 s == "%" or s == ">" or s == "<" or s == ">=" or s == "<="
1599 int AliHLTGlobalTriggerComponent::PrintStatistics(const AliHLTGlobalTrigger* pTrigger, AliHLTComponentLogSeverity level, int offset) const
1601 // print some statistics
1602 int totalEvents=GetEventCount()+offset;
1603 const TArrayL64& counters = pTrigger->GetCounters();
1604 if (pTrigger->CallFailed()) return -EPROTO;
1605 for (int i = 0; i < counters.GetSize(); i++) {
1606 ULong64_t count = counters[i];
1608 if (totalEvents>0) ratio=100*(float)count/totalEvents;
1609 HLTLog(level, "Item %d: total events: %d - counted events: %llu (%.1f%%)", i, totalEvents, count, ratio);
1614 int AliHLTGlobalTriggerComponent::AddCTPDecisions(AliHLTGlobalTrigger* pTrigger, const AliHLTCTPData* pCTPData, const AliHLTComponentTriggerData* trigData)
1616 // add trigger decisions for the valid CTP classes
1617 if (!pCTPData || !pTrigger) return 0;
1619 AliHLTUInt64_t triggerMask=pCTPData->Mask();
1620 AliHLTUInt64_t bit0=0x1;
1621 if (!fCTPDecisions) {
1624 fCTPDecisions=new TClonesArray(AliHLTTriggerDecision::Class(), gkNCTPTriggerClasses);
1626 catch (const std::bad_alloc&)
1628 HLTError("Could not allocate memory for the CTP decisions array.");
1631 if (!fCTPDecisions) return -ENOMEM;
1635 fCTPDecisions->ExpandCreate(gkNCTPTriggerClasses);
1637 catch (const std::bad_alloc&)
1639 HLTError("Could not allocate more memory for the CTP decisions array.");
1642 for (int i=0; i<gkNCTPTriggerClasses; i++) {
1643 const char* name=pCTPData->Name(i);
1644 if (triggerMask&(bit0<<i) && name) {
1645 AliHLTTriggerDecision* pDecision=dynamic_cast<AliHLTTriggerDecision*>(fCTPDecisions->At(i));
1648 delete fCTPDecisions;
1652 pDecision->Name(name);
1657 for (int i=0; i<gkNCTPTriggerClasses; i++) {
1658 const char* name=pCTPData->Name(i);
1659 if ((triggerMask&(bit0<<i))==0 || name==NULL) continue;
1660 AliHLTTriggerDecision* pDecision=dynamic_cast<AliHLTTriggerDecision*>(fCTPDecisions->At(i));
1661 HLTDebug("updating CTP trigger decision %d %s (%p casted %p)", i, name, fCTPDecisions->At(i), pDecision);
1662 if (!pDecision) return -ENOENT;
1665 if (trigData) result=pCTPData->EvaluateCTPTriggerClass(name, *trigData);
1666 else result=pCTPData->EvaluateCTPTriggerClass(name);
1667 pDecision->Result(result);
1668 pDecision->TriggerDomain().Clear();
1669 if (trigData) pDecision->TriggerDomain().Add(pCTPData->ReadoutList(*trigData));
1670 else pDecision->TriggerDomain().Add(pCTPData->ReadoutList());
1672 pTrigger->Add(fCTPDecisions->At(i), kAliHLTDataTypeTriggerDecision, kAliHLTVoidDataSpec);
1673 if (pTrigger->CallFailed()) return -EPROTO;