]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - HLT/trigger/AliHLTGlobalTriggerComponent.cxx
Fixing bug caused by UUID not being generated properly.
[u/mrichter/AliRoot.git] / HLT / trigger / AliHLTGlobalTriggerComponent.cxx
index 7cd1bc802ef4d029f2da0db2e2df24e7b03bf78e..ee37cc5345a42d1d9a38303b920fe268b84afb40 100644 (file)
 #include "AliCDBStorage.h"
 #include "AliCDBEntry.h"
 #include "TUUID.h"
+#include "TMD5.h"
+#include "TRandom3.h"
 #include "TROOT.h"
 #include "TSystem.h"
 #include "TRegexp.h"
 #include "TClonesArray.h"
 #include "TObjString.h"
-#include "TSystem.h"
+#include "TString.h"
 #include "TInterpreter.h"
 #include "TDatime.h"
+#include "TClass.h"
+#include "TNamed.h"
 #include <fstream>
 #include <cerrno>
+#include <cassert>
+#include <vector>
+#include <algorithm>
 
 ClassImp(AliHLTGlobalTriggerComponent)
 
 const char* AliHLTGlobalTriggerComponent::fgkTriggerMenuCDBPath = "HLT/ConfigHLT/HLTGlobalTrigger";
 
 
+namespace
+{
+  /**
+   * This method is used as a comparison functor with the STL sort routines.
+   */
+  bool AliHLTDescendingNumbers(UInt_t a, UInt_t b)
+  {
+    return a > b;
+  }
+} // end of namespace
+
+
 AliHLTGlobalTriggerComponent::AliHLTGlobalTriggerComponent() :
        AliHLTTrigger(),
        fTrigger(NULL),
        fDebugMode(false),
-       fCodeFileName()
+       fRuntimeCompile(true),
+       fDeleteCodeFile(false),
+       fCodeFileName(),
+       fClassName(),
+       fCTPDecisions(NULL),
+       fBufferSizeConst(2*(sizeof(AliHLTGlobalTriggerDecision) + sizeof(AliHLTReadoutList))),
+       fBufferSizeMultiplier(1.),
+       fIncludePaths(TObjString::Class()),
+       fIncludeFiles(TObjString::Class()),
+       fLibStateAtLoad(),
+       fBits(0),
+       fDataEventsOnly(true)
 {
   // Default constructor.
   
@@ -66,6 +96,18 @@ AliHLTGlobalTriggerComponent::~AliHLTGlobalTriggerComponent()
   // Default destructor.
   
   if (fTrigger != NULL) delete fTrigger;
+
+  if (fCTPDecisions) {
+    fCTPDecisions->Delete();
+    delete fCTPDecisions;
+  }
+}
+
+
+void AliHLTGlobalTriggerComponent::GetOutputDataTypes(AliHLTComponentDataTypeList& list) const
+{
+  // Returns the kAliHLTDataTypeGlobalTrigger type as output.
+  list.push_back(kAliHLTDataTypeGlobalTrigger);
 }
 
 
@@ -73,8 +115,8 @@ void AliHLTGlobalTriggerComponent::GetOutputDataSize(unsigned long& constBase, d
 {
   // Returns the output data size estimate.
 
-  constBase = sizeof(AliHLTGlobalTriggerDecision);
-  inputMultiplier = 1;
+  constBase = fBufferSizeConst;
+  inputMultiplier = fBufferSizeMultiplier;
 }
 
 
@@ -83,12 +125,15 @@ Int_t AliHLTGlobalTriggerComponent::DoInit(int argc, const char** argv)
   // Initialises the global trigger component.
   
   fDebugMode = false;
-  bool bSkipCTPCounters=false;
+  fClassName = "";
+  fCodeFileName = "";
+  fDeleteCodeFile = false;
   const char* configFileName = NULL;
   const char* codeFileName = NULL;
-  TString classname;
-  TClonesArray includePaths(TObjString::Class());
-  TClonesArray includeFiles(TObjString::Class());
+  fIncludePaths.Clear();
+  fIncludeFiles.Clear();
+  SetBit(kIncludeInput);
+  fDataEventsOnly = true;
   
   for (int i = 0; i < argc; i++)
   {
@@ -117,7 +162,15 @@ Int_t AliHLTGlobalTriggerComponent::DoInit(int argc, const char** argv)
         HLTError("The include path was not specified." );
         return -EINVAL;
       }
-      new (includePaths[includePaths.GetEntriesFast()]) TObjString(argv[i+1]);
+      try
+      {
+        new (fIncludePaths[fIncludePaths.GetEntriesFast()]) TObjString(argv[i+1]);
+      }
+      catch (const std::bad_alloc&)
+      {
+        HLTError("Could not allocate more memory for the fIncludePaths array.");
+        return -ENOMEM;
+      }
       i++;
       continue;
     }
@@ -129,7 +182,15 @@ Int_t AliHLTGlobalTriggerComponent::DoInit(int argc, const char** argv)
         HLTError("The include file name was not specified." );
         return -EINVAL;
       }
-      new (includeFiles[includeFiles.GetEntriesFast()]) TObjString(argv[i+1]);
+      try
+      {
+        new (fIncludeFiles[fIncludeFiles.GetEntriesFast()]) TObjString(argv[i+1]);
+      }
+      catch (const std::bad_alloc&)
+      {
+        HLTError("Could not allocate more memory for the fIncludeFiles array.");
+        return -ENOMEM;
+      }
       i++;
       continue;
     }
@@ -141,7 +202,12 @@ Int_t AliHLTGlobalTriggerComponent::DoInit(int argc, const char** argv)
         HLTWarning("The debug flag was already specified. Ignoring this instance.");
       }
       fDebugMode = true;
-      i++;
+      continue;
+    }
+    
+    if (strcmp(argv[i], "-cint") == 0)
+    {
+      fRuntimeCompile = false;
       continue;
     }
     
@@ -164,7 +230,7 @@ Int_t AliHLTGlobalTriggerComponent::DoInit(int argc, const char** argv)
         HLTError("The custom trigger class name was not specified." );
         return -EINVAL;
       }
-      classname = argv[i+2];
+      fClassName = argv[i+2];
       i += 2;
       continue;
     }
@@ -172,10 +238,61 @@ Int_t AliHLTGlobalTriggerComponent::DoInit(int argc, const char** argv)
     if (strcmp(argv[i], "-skipctp") == 0)
     {
       HLTInfo("Skipping CTP counters in trigger decision");
-      bSkipCTPCounters=true;
+      SetBit(kSkipCTP);
+      continue;
+    }
+
+    if (strcmp(argv[i], "-forward-input") == 0)
+    {
+      HLTInfo("Forwarding input objects and trigger decisions");
+      SetBit(kForwardInput);
+      SetBit(kIncludeShort);
+      SetBit(kIncludeInput, false);
+      continue;
+    }
+
+    if (strstr(argv[i], "-include-input") == argv[i])
+    {
+      SetBit(kForwardInput,false);
+      TString param=argv[i];
+      param.ReplaceAll("-include-input", "");
+      if (param.CompareTo("=none")==0) 
+      {
+        HLTInfo("skipping objects and trigger decisions");
+        SetBit(kIncludeShort, false);
+        SetBit(kIncludeInput, false);
+      }
+      else if (param.CompareTo("=short")==0) 
+      {
+        HLTInfo("including short info on objects and trigger decisions");
+        SetBit(kIncludeShort);
+        SetBit(kIncludeInput, false);
+      }
+      else if (param.CompareTo("=both")==0) 
+      {
+        HLTInfo("including input objects, trigger decisions and short info");
+        SetBit(kIncludeShort);
+        SetBit(kIncludeInput);
+      }
+      else if (param.CompareTo("=objects")==0 || param.IsNull())
+      {
+        HLTInfo("including input objects and trigger decisions");
+        SetBit(kIncludeShort, false);
+        SetBit(kIncludeInput);
+      }
+      else
+      {
+        HLTError("unknown parameter '%s' for argument '-include-input'", param.Data());
+      }
+      continue;
+    }
+
+    if (strcmp(argv[i], "-process-all-events") == 0)
+    {
+      fDataEventsOnly = false;
       continue;
     }
-        
+    
     HLTError("Unknown option '%s'.", argv[i]);
     return -EINVAL;
   } // for loop
@@ -191,69 +308,49 @@ Int_t AliHLTGlobalTriggerComponent::DoInit(int argc, const char** argv)
   
   // Try load the trigger menu from the CDB if it is not loaded yet with the
   // -config option
-  if (menu == NULL and AliCDBManager::Instance() != NULL)
+  int result = -ENOENT;
+  if (menu == NULL)
   {
-    AliCDBStorage* store = AliCDBManager::Instance()->GetDefaultStorage();
-    if (store == NULL)
-    {
-      HLTError("Could not get the the default storage for the CDB.");
-      return -EIO;
-    }
-    Int_t version = store->GetLatestVersion(fgkTriggerMenuCDBPath, GetRunNo());
-    Int_t subVersion = store->GetLatestSubVersion(fgkTriggerMenuCDBPath, GetRunNo(), version);
-    AliCDBEntry* entry = AliCDBManager::Instance()->Get(fgkTriggerMenuCDBPath, GetRunNo(), version, subVersion);
-    if (entry == NULL)
-    {
-      HLTError("Could not get the CDB entry for \"%s\".", fgkTriggerMenuCDBPath);
-      return -EIO;
-    }
-    TObject* obj = entry->GetObject();
-    if (obj == NULL)
-    {
-      HLTError("Configuration object for \"%s\" is missing.", fgkTriggerMenuCDBPath);
-      return -ENOENT;
-    }
-    if (obj->IsA() != AliHLTTriggerMenu::Class())
-    {
-      HLTError("Wrong type for configuration object in \"%s\". Found a %s but we expect a AliHLTTriggerMenu.",
-               fgkTriggerMenuCDBPath, obj->ClassName()
-      );
-      return -EPROTO;
-    }
-    menu = dynamic_cast<AliHLTTriggerMenu*>(obj);
+    result = LoadTriggerMenu(fgkTriggerMenuCDBPath, menu);
   }
-  
   if (menu == NULL)
   {
     HLTError("No trigger menu configuration found or specified.");
-    return -ENOENT;
+    return result;
   }
   
-  int result = 0;
   if (codeFileName == NULL)
   {
-    HLTDebug("Generating custom HLT trigger class.");
-    result = GenerateTrigger(menu, classname, includePaths, includeFiles);
+    result = GenerateTrigger(menu, fClassName, fCodeFileName, fIncludePaths, fIncludeFiles);
+    if (result == 0) fDeleteCodeFile = true;
   }
   else
   {
-    HLTDebug("Loading HLT trigger class from file '%s'.", codeFileName);
-    result = LoadTriggerClass(codeFileName, includePaths);
+    result = LoadTriggerClass(codeFileName, fIncludePaths);
+    if (result == 0) fCodeFileName = codeFileName;
   }
   if (result != 0) return result;
   
-  fTrigger = AliHLTGlobalTrigger::CreateNew(classname.Data());
+  try
+  {
+    fTrigger = AliHLTGlobalTrigger::CreateNew(fClassName.Data());
+  }
+  catch (const std::bad_alloc&)
+  {
+    HLTError("Could not allocate memory for the AliHLTGlobalTrigger instance.");
+    return -ENOMEM;
+  }
   if (fTrigger == NULL)
   {
-    HLTError("Could not create a new instance of '%s'.", classname.Data());
+    HLTError("Could not create a new instance of '%s'.", fClassName.Data());
     return -EIO;
   }
   
   fTrigger->FillFromMenu(*menu);
-  fTrigger->ResetCounters(menu->NumberOfItems());
+  if (fTrigger->CallFailed()) return -EPROTO;
 
   // setup the CTP accounting in AliHLTComponent
-  if (!bSkipCTPCounters) SetupCTPData();
+  SetupCTPData();
 
   // Set the default values from the trigger menu.
   SetDescription(menu->DefaultDescription());
@@ -272,14 +369,24 @@ Int_t AliHLTGlobalTriggerComponent::DoDeinit()
     delete fTrigger;
     fTrigger = NULL;
   }
-
-  if (!fCodeFileName.IsNull() && gSystem->AccessPathName(fCodeFileName)==0 && !fDebugMode) {
+  
+  if (fCTPDecisions) {
+    fCTPDecisions->Delete();
+    delete fCTPDecisions;
+  }
+  fCTPDecisions=NULL;
+  
+  Int_t result = UnloadTriggerClass(fCodeFileName);
+  if (result != 0) return result;
+  
+  if (fDeleteCodeFile and !fCodeFileName.IsNull() && gSystem->AccessPathName(fCodeFileName)==0 && !fDebugMode) {
     fCodeFileName.ReplaceAll(".cxx", "*");
     TString command="rm "; command+=fCodeFileName;
     gSystem->Exec(command);
   }
   fCodeFileName="";
-  
+  fDeleteCodeFile=false;
+
   return 0;
 }
 
@@ -287,8 +394,17 @@ Int_t AliHLTGlobalTriggerComponent::DoDeinit()
 AliHLTComponent* AliHLTGlobalTriggerComponent::Spawn()
 {
   // Creates a new object instance.
-  
-  return new AliHLTGlobalTriggerComponent;
+  AliHLTComponent* comp = NULL;
+  try
+  {
+    comp = new AliHLTGlobalTriggerComponent;
+  }
+  catch (const std::bad_alloc&)
+  {
+    HLTError("Could not allocate memory for a new instance of AliHLTGlobalTriggerComponent.");
+    return NULL;
+  }
+  return comp;
 }
 
 
@@ -305,23 +421,34 @@ int AliHLTGlobalTriggerComponent::DoTrigger()
   AliHLTUInt32_t eventType=0;
   if (!IsDataEvent(&eventType)) {
     if (eventType==gkAliEventTypeEndOfRun) PrintStatistics(fTrigger, kHLTLogImportant, 0);
-    return 0;
+    if (fDataEventsOnly)
+    {
+      IgnoreEvent();  // dont generate any trigger decision.
+      return 0;
+    }
   }
 
+  // Copy the trigger counters in case we need to set them back to their original
+  // value because the PushBack method fails with ENOSPC.
+  TArrayL64 originalCounters = fTrigger->GetCounters();
+  if (fTrigger->CallFailed()) return -EPROTO;
+  
   fTrigger->NewEvent();
+  if (fTrigger->CallFailed()) return -EPROTO;
   
   // Fill in the input data.
   const TObject* obj = GetFirstInputObject();
   while (obj != NULL)
   {
     fTrigger->Add(obj, GetDataType(), GetSpecification());
+    if (fTrigger->CallFailed()) return -EPROTO;
     obj = GetNextInputObject();
   }
 
   // add trigger decisions for every CTP class
   const AliHLTCTPData* pCTPData=CTPData();
   if (pCTPData) {
-    fTrigger->AddCTPDecisions(pCTPData, GetTriggerData());
+    AddCTPDecisions(fTrigger, pCTPData, GetTriggerData());
   }
 
   // Calculate the global trigger result and trigger domain, then create and push
@@ -329,7 +456,7 @@ int AliHLTGlobalTriggerComponent::DoTrigger()
   TString description;
   AliHLTTriggerDomain triggerDomain;
   bool triggerResult = fTrigger->CalculateTriggerDecision(triggerDomain, description);
-  
+  if (fTrigger->CallFailed()) return -EPROTO;
   AliHLTGlobalTriggerDecision decision(
       triggerResult,
       // The following will cause the decision to be generated with default values
@@ -338,79 +465,283 @@ int AliHLTGlobalTriggerComponent::DoTrigger()
       (triggerResult == true) ? description.Data() : GetDescription()
     );
 
-  // mask the readout list according to the CTP trigger
-  // if the classes have been initialized (mask non-zero)
-  if (pCTPData && pCTPData->Mask()) {
-    AliHLTEventDDL eventDDL=pCTPData->ReadoutList(*GetTriggerData());
-    AliHLTReadoutList ctpreadout(eventDDL);
-    ctpreadout.Enable(AliHLTReadoutList::kHLT);
-    AliHLTReadoutList maskedList=decision.ReadoutList();
-    maskedList.AndEq(ctpreadout);
-    decision.ReadoutList(maskedList);
-  }
-
-  const TArrayL64* counters=fTrigger->Counters();
-  if (counters) {
-    decision.SetCounters(*counters, GetEventCount()+1);
-  }
-  static UInt_t lastTime=0;
-  TDatime time;
-  if (time.Get()-lastTime>5) {
-    lastTime=time.Get();
-    PrintStatistics(fTrigger);
-  }
+  decision.SetCounters(fTrigger->GetCounters(), GetEventCount()+1);
+  if (fTrigger->CallFailed()) return -EPROTO;
   
-  // Add the input objects used to the global decision.
+  TClonesArray shortInfo(TNamed::Class(), GetNumberOfInputBlocks());
+  
+  // Add the input objects used to make the global decision.
   obj = GetFirstInputObject();
   while (obj != NULL)
   {
-    if (obj->IsA() == AliHLTTriggerDecision::Class())
+    const AliHLTTriggerDecision* intrig = dynamic_cast<const AliHLTTriggerDecision*>(obj);
+    
+    if (TestBit(kForwardInput)) Forward(obj);
+    
+    if (TestBit(kIncludeInput))
     {
-      decision.AddTriggerInput( *static_cast<const AliHLTTriggerDecision*>(obj) );
+      if (intrig != NULL)
+      {
+         decision.AddTriggerInput(*intrig);
+      }
+      else
+      {
+        // The const_cast should be safe in this case because the list of inputObjects
+        // will be added to the global decision with AddInputObjectRef, which only
+        // modifies the kCanDelete bit and nothing else.
+        // This is necessary since GetFirstInputObject only returns const objects.
+        decision.AddInputObjectRef( const_cast<TObject*>(obj) );
+      }
     }
-    else
+    
+    if (TestBit(kIncludeShort))
     {
-      decision.AddInputObject(obj);
+      int entries = shortInfo.GetEntriesFast();
+      try
+      {
+        new (shortInfo[entries]) TNamed(obj->GetName(), obj->GetTitle());
+      }
+      catch (const std::bad_alloc&)
+      {
+        HLTError("Could not allocate more memory for the short list of input objects.");
+        return -ENOMEM;
+      }
+      if (intrig != NULL)
+      {
+        shortInfo[entries]->SetBit(BIT(16)); // indicate that this is a trigger decision
+        shortInfo[entries]->SetBit(BIT(15), intrig->Result());
+      }
     }
+
     obj = GetNextInputObject();
   }
+  if (TestBit(kIncludeShort)) decision.AddInputObjectRef(&shortInfo);
+  
+  // The const_cast should be safe in this case because AddInputObjectRef just
+  // modifies the kCanDelete bit and nothing else.
+  if (!TestBit(kSkipCTP) && CTPData()) decision.AddInputObjectRef(const_cast<AliHLTCTPData*>(CTPData()));
+  
+  static UInt_t lastTime=0;
+  TDatime time;
+  if (time.Get()-lastTime>60) {
+    lastTime=time.Get();
+    PrintStatistics(fTrigger, kHLTLogImportant);
+  }
 
-  if (CTPData()) decision.AddInputObject(CTPData());
-
+  // add readout filter to event done data
   CreateEventDoneReadoutFilter(decision.TriggerDomain(), 3);
+  // add monitoring filter to event done data
   CreateEventDoneReadoutFilter(decision.TriggerDomain(), 4);
-  TriggerEvent(&decision);
+  if (decision.Result()) {
+    // add monitoring event command for triggered events
+    CreateEventDoneReadoutFilter(decision.TriggerDomain(), 5);
+  }
+  if (TriggerEvent(&decision) == -ENOSPC)
+  {
+    // Increase the estimated buffer space required if the PushBack methods in TriggerEvent
+    // returned the "no buffer space" error code. Also remember to set the trigger counters
+    // back to what they were, otherwise triggers will be double counted when we try to reprocess
+    // this event with larger buffers.
+    fBufferSizeConst += 1024*1024;
+    fBufferSizeMultiplier *= 2.;
+    fTrigger->SetCounters(originalCounters);
+    if (fTrigger->CallFailed()) return -EPROTO;
+    return -ENOSPC;
+  }
   return 0;
 }
 
 
-int AliHLTGlobalTriggerComponent::GenerateTrigger(
-    const AliHLTTriggerMenu* menu, TString& name,
-    const TClonesArray& includePaths, const TClonesArray& includeFiles
-  )
+int AliHLTGlobalTriggerComponent::Reconfigure(const char* cdbEntry, const char* chainId)
 {
-  // Generates the global trigger class that will implement the specified trigger menu.
-  // See header for more details.
+  // Reconfigure the component by loading the trigger menu and recreating the
+  // trigger logic class.
   
-  // Create a new UUID and replace the '-' characters with '_' to make it a valid
-  // C++ symbol name.
-  TUUID uuid;
-  TString uuidstr = uuid.AsString();
-  for (Int_t i = 0; i < uuidstr.Length(); i++)
+  const char* path = fgkTriggerMenuCDBPath;
+  const char* id = "(unknown)";
+  if (cdbEntry != NULL) path = cdbEntry;
+  if (chainId != NULL and chainId[0] != '\0') id = chainId;
+  HLTInfo("Reconfiguring from '%s' for chain component '%s'.", path, id);
+  
+  const AliHLTTriggerMenu* menu = NULL;
+  int result = LoadTriggerMenu(path, menu);
+  if (result != 0) return result;
+  
+  TString className;
+  TString codeFileName;
+  result = GenerateTrigger(menu, className, codeFileName, fIncludePaths, fIncludeFiles);
+  if (result != 0) return result;
+  
+  AliHLTGlobalTrigger* trigger = NULL;
+  try
+  {
+    trigger = AliHLTGlobalTrigger::CreateNew(className.Data());
+  }
+  catch (const std::bad_alloc&)
+  {
+    HLTError("Could not allocate memory for the AliHLTGlobalTrigger instance.");
+    return -ENOMEM;
+  }
+  if (trigger == NULL)
+  {
+    HLTError("Could not create a new instance of '%s'.", className.Data());
+    // Make sure to cleanup after the new code file.
+    UnloadTriggerClass(codeFileName);
+    if (not codeFileName.IsNull() and gSystem->AccessPathName(codeFileName)==0 and not fDebugMode)
+    {
+      codeFileName.ReplaceAll(".cxx", "*");
+      TString command="rm "; command+=codeFileName;
+      gSystem->Exec(command);
+    }
+    return -EIO;
+  }
+  
+  if (fTrigger != NULL)
+  {
+    delete fTrigger;
+    fTrigger = NULL;
+  }
+  
+  fTrigger = trigger;
+  fTrigger->FillFromMenu(*menu);
+  if (fTrigger->CallFailed()) return -EPROTO;
+
+  // Set the default values from the trigger menu.
+  SetDescription(menu->DefaultDescription());
+  SetTriggerDomain(menu->DefaultTriggerDomain());
+  
+  // Cleanup the old class code.
+  UnloadTriggerClass(fCodeFileName);
+  if (fDeleteCodeFile and not fCodeFileName.IsNull() and gSystem->AccessPathName(fCodeFileName)==0 and not fDebugMode)
   {
-    if (uuidstr[i] == '-') uuidstr[i] = '_';
+    fCodeFileName.ReplaceAll(".cxx", "*");
+    TString command="rm "; command+=fCodeFileName;
+    gSystem->Exec(command);
   }
+  fCodeFileName = codeFileName;
+  fDeleteCodeFile = true;  // Since we generated a new class.
+  
+  return 0;
+}
+
+
+int AliHLTGlobalTriggerComponent::LoadTriggerMenu(const char* cdbPath, const AliHLTTriggerMenu*& menu)
+{
+  // Loads the trigger menu object from the CDB path.
   
-  // Create the name of the new class.
+  HLTDebug("Trying to load trigger menu from '%s'.", cdbPath);
+  if (AliCDBManager::Instance() == NULL)
+  {
+    HLTError("CDB manager object not found.");
+    return -EIO;
+  }
+  AliCDBStorage* store = AliCDBManager::Instance()->GetDefaultStorage();
+  if (store == NULL)
+  {
+    HLTError("Could not get the the default storage for the CDB.");
+    return -EIO;
+  }
+  Int_t version = store->GetLatestVersion(cdbPath, GetRunNo());
+  Int_t subVersion = store->GetLatestSubVersion(cdbPath, GetRunNo(), version);
+  AliCDBEntry* entry = AliCDBManager::Instance()->Get(cdbPath, GetRunNo(), version, subVersion);
+  if (entry == NULL)
+  {
+    HLTError("Could not get the CDB entry for \"%s\".", cdbPath);
+    return -EIO;
+  }
+  TObject* obj = entry->GetObject();
+  if (obj == NULL)
+  {
+    HLTError("Configuration object for \"%s\" is missing.", cdbPath);
+    return -ENOENT;
+  }
+  if (obj->IsA() != AliHLTTriggerMenu::Class())
+  {
+    HLTError("Wrong type for configuration object in \"%s\". Found a %s but we expect a AliHLTTriggerMenu.",
+             cdbPath, obj->ClassName()
+    );
+    return -EPROTO;
+  }
+  menu = static_cast<AliHLTTriggerMenu*>(obj);
+  return 0;
+}
+
+
+void AliHLTGlobalTriggerComponent::GenerateFileName(TString& name, TString& filename) const
+{
+  // Creates a unique file name for the generated code.
+  
+  // Start by creating a new UUID. We cannot use the one automatically generated
+  // by ROOT because the algorithm used will not guarantee unique IDs when generating
+  // these UUIDs at a high rate in parallel.
+  TUUID uuid;
+  // We then use the generated UUID to form part of the random number seeds which
+  // will be used to generate a proper random UUID. For good measure we use a MD5
+  // hash also. Note that we want to use the TUUID class because it will combine the
+  // host address information into the UUID. Using gSystem->GetHostByName() apparently
+  // can cause problems on Windows machines with a firewall, because it always tries
+  // to contact a DNS. The TUUID class handles this case appropriately.
+  union
+  {
+    UChar_t buf[16];
+    UShort_t word[8];
+    UInt_t dword[4];
+  };
+  uuid.GetUUID(buf);
+  TMD5 md5;
+  md5.Update(buf, sizeof(buf));
+  md5.Final(buf);
+  dword[0] += gSystem->GetUid();
+  dword[1] += gSystem->GetGid();
+  dword[2] += gSystem->GetPid();
+  for (int i = 0; i < 4; ++i)
+  {
+    gRandom->SetSeed(dword[i]);
+    dword[i] = gRandom->Integer(0xFFFFFFFF);
+  }
+  md5.Update(buf, sizeof(buf));
+  md5.Final(buf);
+  // To keep to the standard we need to set the version and reserved bits.
+  word[3] = (word[3] & 0x0FFF) | 0x4000;
+  buf[8] = (buf[8] & 0x3F) | 0x80;
+
+  // Create the name of the new class and file.
+  char uuidstr[64];
+  sprintf(uuidstr, "%08x_%04x_%04x_%02x%02x_%02x%02x%02x%02x%02x%02x",
+    dword[0], word[2], word[3], buf[8], buf[9], buf[10], buf[11], buf[12], buf[13], buf[14], buf[15]
+  );
   name = "AliHLTGlobalTriggerImpl_";
   name += uuidstr;
-  fCodeFileName = name + ".cxx";
+  filename = name + ".cxx";
+
+  // For good measure, check that the file names are not used. If they are then regenerate.
+  fstream file(filename.Data(), ios_base::in);
+  if (file.good())
+  {
+    file.close();
+    GenerateFileName(name, filename);
+  }
+}
+
+
+int AliHLTGlobalTriggerComponent::GenerateTrigger(
+    const AliHLTTriggerMenu* menu, TString& name, TString& filename,
+    const TClonesArray& includePaths, const TClonesArray& includeFiles
+  )
+{
+  // Generates the global trigger class that will implement the specified trigger menu.
+  // See header for more details.
+  
+  GenerateFileName(name, filename);
+  HLTDebug("Generating custom HLT trigger class named %s, in file %s, using trigger menu %p.",
+    name.Data(), filename.Data(), ((void*)menu)
+  );
   
   // Open a text file to write the code and generate the new class.
-  fstream code(fCodeFileName.Data(), ios_base::out | ios_base::trunc);
+  fstream code(filename.Data(), ios_base::out | ios_base::trunc);
   if (not code.good())
   {
-    HLTError("Could not open file '%s' for writing.", fCodeFileName.Data());
+    HLTError("Could not open file '%s' for writing.", filename.Data());
     return -EIO;
   }
   
@@ -418,9 +749,12 @@ int AliHLTGlobalTriggerComponent::GenerateTrigger(
   int result = BuildSymbolList(menu, symbols);
   if (result != 0) return result;
   
+  code << "#if !defined(__CINT__) || defined(__MAKECINT__)" << endl;
   code << "#include <cstring>" << endl;
+  code << "#include \"TClass.h\"" << endl;
   code << "#include \"TString.h\"" << endl;
   code << "#include \"TClonesArray.h\"" << endl;
+  code << "#include \"AliHLTLogging.h\"" << endl;
   code << "#include \"AliHLTGlobalTrigger.h\"" << endl;
   code << "#include \"AliHLTGlobalTriggerDecision.h\"" << endl;
   code << "#include \"AliHLTDomainEntry.h\"" << endl;
@@ -437,11 +771,41 @@ int AliHLTGlobalTriggerComponent::GenerateTrigger(
     code << "#include \"" << file.Data() << "\"" << endl;
   }
   
-  code << "class " << name << " : public AliHLTGlobalTrigger" << endl;
+  if (fDebugMode)
+  {
+    code << "#else" << endl;
+    code << "const char* gFunctionName = \"???\";" << endl;
+    code << "#define HLTDebug(msg) if (CheckFilter(kHLTLogDebug) && CheckGroup(Class_Name())) SendMessage(kHLTLogDebug, Class_Name(), ::gFunctionName, __FILE__, __LINE__, msg)" << endl;
+  }
+  code << "#endif" << endl;
+  
+  code << "class " << name << " :" << endl;
+  // Add appropriate #ifdef sections since we need to prevent inheritance from
+  // AliHLTGlobalTrigger. CINT does not seem to support multiple inheritance nor
+  // multiple levels of inheritance. Neither of the following schemes worked:
+  //
+  // 1)  class AliHLTGlobalTrigger : public AliHLTLogging {};
+  //     class AliHLTGlobalTriggerImpl_xyz : public AliHLTGlobalTrigger {};
+  //
+  // 2)  class AliHLTGlobalTrigger {};
+  //     class AliHLTGlobalTriggerImpl_xyz : public AliHLTGlobalTrigger, public AliHLTLogging {};
+  //
+  // Thus, we are forced to just inherit from AliHLTLogging when running in the CINT
+  // interpreter. But we anyway have to call the global trigger implementation class
+  // through the AliHLTGlobalTriggerWrapper so this is not such a problem.
+  code << "#if !defined(__CINT__) || defined(__MAKECINT__)" << endl;
+  code << "  public AliHLTGlobalTrigger," << endl;
+  code << "#endif" << endl;
+  code << "  public AliHLTLogging" << endl;
   code << "{" << endl;
   code << "public:" << endl;
   
-  code << "  " << name << "() : AliHLTGlobalTrigger()";
+  // Generate constructor method.
+  code << "  " << name << "() :" << endl;
+  code << "#if !defined(__CINT__) || defined(__MAKECINT__)" << endl;
+  code << "    AliHLTGlobalTrigger()," << endl;
+  code << "#endif" << endl;
+  code << "    AliHLTLogging()";
   // Write the symbols in the trigger menu in the initialisation list.
   for (Int_t i = 0; i < symbols.GetEntriesFast(); i++)
   {
@@ -461,15 +825,21 @@ int AliHLTGlobalTriggerComponent::GenerateTrigger(
   code << endl << "  {" << endl;
   if (fDebugMode)
   {
+    code << "#ifdef __CINT__" << endl;
+    code << "    gFunctionName = \"" << name.Data() <<"\";" << endl;
+    code << "#endif" << endl;
     code << "    SetLocalLoggingLevel(kHLTLogAll);" << endl;
-    code << "    HLTInfo(\"Creating new instance at %p.\", this);" << endl;
+    code << "    HLTDebug(Form(\"Creating new instance at %p.\", this));" << endl;
   }
   code << "  }" << endl;
   
   code << "  virtual ~" << name << "() {" << endl;
   if (fDebugMode)
   {
-    code << "    HLTInfo(\"Deleting instance at %p.\", this);" << endl;
+    code << "#ifdef __CINT__" << endl;
+    code << "    gFunctionName = \"~" << name.Data() << "\";" << endl;
+    code << "#endif" << endl;
+    code << "    HLTDebug(Form(\"Deleting instance at %p.\", this));" << endl;
   }
   code << "  }" << endl;
   
@@ -477,8 +847,12 @@ int AliHLTGlobalTriggerComponent::GenerateTrigger(
   code << "  virtual void FillFromMenu(const AliHLTTriggerMenu& menu) {" << endl;
   if (fDebugMode)
   {
-    code << "    HLTDebug(\"Filling description entries from trigger menu for global trigger %p.\", this);" << endl;
+    code << "#ifdef __CINT__" << endl;
+    code << "    gFunctionName = \"FillFromMenu\";" << endl;
+    code << "#endif" << endl;
+    code << "    HLTDebug(Form(\"Filling description entries from trigger menu for global trigger %p.\", this));" << endl;
   }
+  code << "    fCounter.Set(menu.NumberOfItems());" << endl;
   for (UInt_t i = 0; i < menu->NumberOfItems(); i++)
   {
     code << "    fMenuItemDescription" << i << " = (menu.Item(" << i
@@ -486,30 +860,56 @@ int AliHLTGlobalTriggerComponent::GenerateTrigger(
   }
   if (fDebugMode)
   {
-    code << "    HLTDebug(\"Finished filling description entries from trigger menu.\");" << endl;
-    code << "    HLTDebug(\"Filling domain entries from trigger menu symbols for global trigger %p.\", this);" << endl;
+    code << "    HLTDebug(Form(\"Finished filling description entries from trigger menu.\"));" << endl;
+    code << "    HLTDebug(Form(\"Filling domain entries from trigger menu symbols for global trigger %p.\", this));" << endl;
   }
   code << "    for (Int_t i = 0; i < menu.SymbolArray().GetEntriesFast(); i++) {" << endl;
+  // 30 Oct 2009 - CINT sometimes evaluates the dynamic_cast incorrectly.
+  // Have to use the TClass system for extra protection.
+  code << "      if (menu.SymbolArray().UncheckedAt(i) == NULL) continue;" << endl;
+  code << "      if (menu.SymbolArray().UncheckedAt(i)->IsA() != AliHLTTriggerMenuSymbol::Class()) continue;" << endl;
   code << "      const AliHLTTriggerMenuSymbol* symbol = dynamic_cast<const"
            " AliHLTTriggerMenuSymbol*>(menu.SymbolArray().UncheckedAt(i));" << endl;
   code << "      if (symbol == NULL) continue;" << endl;
   for (Int_t i = 0; i < symbols.GetEntriesFast(); i++)
   {
     AliHLTTriggerMenuSymbol* symbol = static_cast<AliHLTTriggerMenuSymbol*>( symbols.UncheckedAt(i) );
-    code << "      if (strcmp(symbol->Name(), \"" << symbol->Name() << "\") == 0) {" << endl;
+    code << "      if (strcmp(symbol->RealName(), \"" << symbol->RealName() << "\") == 0) {" << endl;
     if (fDebugMode)
     {
-      code << "        HLTDebug(\"Assinging domain entry value to match for symbol '%s' to '%s'.\","
-              " symbol->Name(), symbol->BlockType().AsString().Data());" << endl;
+      code << "        HLTDebug(Form(\"Assinging domain entry value corresponding with symbol '%s' to '%s'.\","
+              " symbol->RealName(), symbol->BlockType().AsString().Data()));" << endl;
     }
     code << "        " << symbol->Name() << "DomainEntry = symbol->BlockType();" << endl;
     code << "        continue;" << endl;
     code << "      }" << endl;
   }
   code << "    }" << endl;
+  // The following is an optimisation where symbols without any assignment operators
+  // are treated as constant and only initialised in FillFromMenu rather than reseting
+  // them in the NewEvent method.
+  // Note: we putting this initialisation into the constructor can lead to seg faults
+  // under CINT interpretation. Thus we must put it into the FillFromMenu method instead.
+  for (Int_t i = 0; i < symbols.GetEntriesFast(); i++)
+  {
+    AliHLTTriggerMenuSymbol* symbol = static_cast<AliHLTTriggerMenuSymbol*>( symbols.UncheckedAt(i) );
+    if (TString(symbol->AssignExpression()) != "") continue;
+    if (strcmp(symbol->ObjectClass(), "AliHLTTriggerDecision") == 0) continue;
+    // CINT has problems with the implicit equals operator for complex types, so if
+    // the type has an equals operater we need to write the operator call explicitly.
+    TClass* clas = TClass::GetClass(symbol->Type());
+    if (clas != NULL and clas->GetMethodAny("operator=") != NULL)
+    {
+      code << "    " << symbol->Name() << ".operator = (" << symbol->DefaultValue() << ");" << endl;
+    }
+    else
+    {
+      code << "    " << symbol->Name() << " = " << symbol->DefaultValue() << ";" << endl;
+    }
+  }
   if (fDebugMode)
   {
-    code << "    HLTDebug(\"Finished filling domain entries from trigger menu symbols.\");" << endl;
+    code << "    HLTDebug(Form(\"Finished filling domain entries from trigger menu symbols.\"));" << endl;
   }
   code << "  }" << endl;
   
@@ -517,13 +917,30 @@ int AliHLTGlobalTriggerComponent::GenerateTrigger(
   code << "  virtual void NewEvent() {" << endl;
   if (fDebugMode)
   {
-    code << "    HLTDebug(\"New event for global trigger object %p, initialising variables to default values.\", this);" << endl;
+    code << "#ifdef __CINT__" << endl;
+    code << "    gFunctionName = \"NewEvent\";" << endl;
+    code << "#endif" << endl;
+    code << "    HLTDebug(Form(\"New event for global trigger object %p, initialising variables to default values.\", this));" << endl;
   }
   // Write code to initialise the symbols in the trigger menu to their default values.
   for (Int_t i = 0; i < symbols.GetEntriesFast(); i++)
   {
     AliHLTTriggerMenuSymbol* symbol = static_cast<AliHLTTriggerMenuSymbol*>( symbols.UncheckedAt(i) );
-    code << "    " << symbol->Name() << " = " << symbol->DefaultValue() << ";" << endl;
+    // The following is an optimisation. If the symbol does not have an assignment expression
+    // then it is effectively a constant symbol and can be initialised earlier and only once.
+    // In this case we initialise it in the FillFromMenu method instead.
+    if (TString(symbol->AssignExpression()) == "") continue;
+    // CINT has problems with the implicit equals operator for complex types, so if
+    // the type has an equals operater we need to write the operator call explicitly.
+    TClass* clas = TClass::GetClass(symbol->Type());
+    if (clas != NULL and clas->GetMethodAny("operator=") != NULL)
+    {
+      code << "    " << symbol->Name() << ".operator = (" << symbol->DefaultValue() << ");" << endl;
+    }
+    else
+    {
+      code << "    " << symbol->Name() << " = " << symbol->DefaultValue() << ";" << endl;
+    }
     if (strcmp(symbol->ObjectClass(), "AliHLTTriggerDecision") == 0)
     {
       code << "    " << symbol->Name() << "TriggerDomain.Clear();" << endl;
@@ -531,18 +948,42 @@ int AliHLTGlobalTriggerComponent::GenerateTrigger(
   }
   if (fDebugMode)
   {
-    code << "    HLTDebug(\"Finished initialising variables.\");" << endl;
+    code << "    HLTDebug(Form(\"Finished initialising variables.\"));" << endl;
   }
   code << "  }" << endl;
   
   // Generate the Add method.
-  code << "  virtual void Add(const TObject* _object_, const AliHLTComponentDataType& _type_, AliHLTUInt32_t _spec_) {" << endl;
+  bool haveAssignments = false;
+  for (Int_t i = 0; i < symbols.GetEntriesFast(); i++)
+  {
+    // First check if we have any symbols with assignment expressions.
+    // This is needed to get rid of the on the fly compilation warning about '_object_' not being used.
+    AliHLTTriggerMenuSymbol* symbol = static_cast<AliHLTTriggerMenuSymbol*>( symbols.UncheckedAt(i) );
+    TString expr = symbol->AssignExpression();
+    if (expr == "") continue; // Skip entries that have no assignment expression.
+    haveAssignments = true;
+    break;
+  }
+  if (haveAssignments or fDebugMode)
+  {
+    code << "  virtual void Add(const TObject* _object_, const AliHLTComponentDataType& _type_, AliHLTUInt32_t _spec_) {" << endl;
+  }
+  else
+  {
+    code << "  virtual void Add(const TObject* /*_object_*/, const AliHLTComponentDataType& _type_, AliHLTUInt32_t _spec_) {" << endl;
+  }
+  if (fDebugMode)
+  {
+    code << "#ifdef __CINT__" << endl;
+    code << "    gFunctionName = \"Add\";" << endl;
+    code << "#endif" << endl;
+  }
   code << "    AliHLTDomainEntry _type_spec_(_type_, _spec_);" << endl;
   if (fDebugMode)
   {
-    code << "    HLTDebug(\"Adding TObject %p, with class name '%s' from data block"
+    code << "    HLTDebug(Form(\"Adding TObject %p, with class name '%s' from data block"
             " '%s', to global trigger object %p\", _object_, _object_->ClassName(),"
-            " _type_spec_.AsString().Data(), this);" << endl;
+            " _type_spec_.AsString().Data(), this));" << endl;
     code << "    _object_->Print();" << endl;
     code << "    bool _object_assigned_ = false;" << endl;
   }
@@ -558,26 +999,29 @@ int AliHLTGlobalTriggerComponent::GenerateTrigger(
     {
       if (isTrigDecision)
       {
-        code << "    HLTDebug(\"Trying to match input object to class '"
-             << symbol->ObjectClass() << "', trigger name '" << symbol->Name()
+        code << "    HLTDebug(Form(\"Trying to match input object to class '"
+             << symbol->ObjectClass() << "', trigger name '" << symbol->RealName()
              << "' and block type '%s'\", " << symbol->Name()
-             << "DomainEntry.AsString().Data());" << endl;
+             << "DomainEntry.AsString().Data()));" << endl;
       }
       else
       {
-        code << "    HLTDebug(\"Trying to match input object to class '"
+        code << "    HLTDebug(Form(\"Trying to match input object to class '"
              << symbol->ObjectClass() << "' and block type '%s'\", "
-             << symbol->Name() << "DomainEntry.AsString().Data());" << endl;
+             << symbol->Name() << "DomainEntry.AsString().Data()));" << endl;
       }
     }
-    code << "    const " << symbol->ObjectClass() << "* " << symbol->Name()
+    // 30 Oct 2009 - CINT sometimes evaluates the dynamic_cast incorrectly.
+    // Have to use the TClass system for extra protection.
+    code << "    const " << symbol->ObjectClass() << "* " << symbol->Name() << "_object_ = NULL;" << endl;
+    code << "    if (_object_->InheritsFrom(" << symbol->ObjectClass() << "::Class())) " << symbol->Name()
          << "_object_ = dynamic_cast<const " << symbol->ObjectClass()
          << "*>(_object_);" << endl;
-    code << "    if (" << symbol->Name() << "_object_ != NULL and ";
+    code << "    if (" << symbol->Name() << "_object_ != NULL && ";
     if (isTrigDecision)
     {
       code << "strcmp(" << symbol->Name() << "_object_->Name(), \""
-           << symbol->Name() << "\") == 0 and ";
+           << symbol->RealName() << "\") == 0 && ";
     }
     code << symbol->Name() << "DomainEntry == _type_spec_) {" << endl;
     TString fullname = symbol->Name();
@@ -591,80 +1035,245 @@ int AliHLTGlobalTriggerComponent::GenerateTrigger(
     }
     if (fDebugMode)
     {
-      code << "      HLTDebug(\"Added TObject %p with class name '%s' to variable "
-           << symbol->Name() << "\", _object_, _object_->ClassName());" << endl;
+      code << "      HLTDebug(Form(\"Added TObject %p with class name '%s' to variable "
+           << symbol->Name() << "\", _object_, _object_->ClassName()));" << endl;
       code << "      _object_assigned_ = true;" << endl;
     }
     code << "    }" << endl;
   }
   if (fDebugMode)
   {
-    code << "    if (not _object_assigned_) HLTDebug(\"Did not assign TObject %p"
-            " with class name '%s' to any variable.\", _object_, _object_->ClassName());"
+    code << "    if (! _object_assigned_) {" << endl;
+    code << "      HLTDebug(Form(\"Did not assign TObject %p"
+            " with class name '%s' to any variable.\", _object_, _object_->ClassName()));"
          << endl;
+    code << "    }" << endl;
   }
   code << "  }" << endl;
   
   // Generate the CalculateTriggerDecision method.
+  // This requires code to be generated that checks which items in the trigger menu
+  // have their conditions asserted and then the trigger domain is generated from
+  // those fired items.
+  // The processing will start from the highest priority trigger group and stop
+  // after at least one trigger from the current priority group being processed
+  // is positive. For each priority group all the trigger menu items are checked.
+  // Their combined trigger condition expression must be true for the trigger priority
+  // group to be triggered positive. The full condition expression is formed by
+  // concatenating the individual condition expressions. If no trailing operators are
+  // used in the individual expressions then the default condition operator is placed
+  // between two concatenated condition expressions.
+  // If a trigger priority group has at least one trigger fired then the trigger domain
+  // is calculated such that it will give the same result as the concatenated trigger
+  // domain merging expressions for all the individual trigger menu items with
+  // positive results. Again, if no trailing operators are used in the individual
+  // merging expressions then the default domain operator is placed between two
+  // expression fragments.
   code << "  virtual bool CalculateTriggerDecision(AliHLTTriggerDomain& _domain_, TString& _description_) {" << endl;
   if (fDebugMode)
   {
-    code << "    HLTDebug(\"Calculating global HLT trigger result with trigger object at %p.\", this);" << endl;
+    code << "#ifdef __CINT__" << endl;
+    code << "    gFunctionName = \"CalculateTriggerDecision\";" << endl;
+    code << "#endif" << endl;
+    code << "    HLTDebug(Form(\"Calculating global HLT trigger result with trigger object at %p.\", this));" << endl;
   }
+  
+  // Build a list of priorities used in the trigger menu.
+  std::vector<UInt_t> priorities;
   for (UInt_t i = 0; i < menu->NumberOfItems(); i++)
   {
     const AliHLTTriggerMenuItem* item = menu->Item(i);
-    TString mergeExpr = item->MergeExpression();
-    for (Int_t j = 0; j < symbols.GetEntriesFast(); j++)
+    bool priorityNotInList = std::find(priorities.begin(), priorities.end(), item->Priority()) == priorities.end();
+    if (priorityNotInList) priorities.push_back(item->Priority());
+  }
+  std::sort(priorities.begin(), priorities.end(), AliHLTDescendingNumbers);
+  // From the priority list, build the priority groups in the correct order,
+  // i.e. highest priority first.
+  // The priority group is a list of vectors of integers. The integers are the
+  // index numbers into the trigger menu item list for the items which form part
+  // of the priority group.
+  std::vector<std::vector<Int_t> > priorityGroup;
+  priorityGroup.insert(priorityGroup.begin(), priorities.size(), std::vector<Int_t>());
+  for (size_t n = 0; n < priorities.size(); n++)
+  {
+    UInt_t priority = priorities[n];
+    for (UInt_t i = 0; i < menu->NumberOfItems(); i++)
     {
-      AliHLTTriggerMenuSymbol* symbol = static_cast<AliHLTTriggerMenuSymbol*>( symbols.UncheckedAt(j) );
-      if (strcmp(symbol->ObjectClass(), "AliHLTTriggerDecision") != 0) continue;
-      TString newname = symbol->Name();
-      newname += "TriggerDomain";
-      mergeExpr.ReplaceAll(symbol->Name(), newname);
+      const AliHLTTriggerMenuItem* item = menu->Item(i);
+      if (item->Priority() == priority) priorityGroup[n].push_back(i);
     }
+  }
+  
+  for (size_t n = 0; n < priorityGroup.size(); n++)
+  {
     if (fDebugMode)
     {
-      code << "    HLTDebug(\"Trying trigger condition " << i
-           << " (Description = '%s').\", fMenuItemDescription" << i << ".Data());"
-           << endl;
+      code << "    HLTDebug(Form(\"Processing trigger priority group " << priorities[n] << "\"));" << endl;
     }
-    code << "    if (" << item->TriggerCondision() << ") {" << endl;
-    code << "      IncrementCounter(" << i << ");" << endl;
-    const char* indentation = "";
-    if (item->PreScalar() != 0)
+    code << "    ";
+    if (n == 0) code << "UInt_t ";
+    code << "_previous_match_ = 0xFFFFFFFF;" << endl;
+    code << "    ";
+    if (n == 0) code << "bool ";
+    code << "_trigger_matched_ = false;" << endl;
+    code << "    ";
+    if (n == 0) code << "bool ";
+    code << "_group_result_ = false;" << endl;
+    std::vector<TString> conditionOperator;
+    conditionOperator.insert(conditionOperator.begin(), priorityGroup[n].size(), TString(""));
+    std::vector<TString> domainOperator;
+    domainOperator.insert(domainOperator.begin(), priorityGroup[n].size(), TString(""));
+    for (size_t m = 0; m < priorityGroup[n].size(); m++)
     {
-      indentation = "  ";
-      code << "      if ((GetCounter(" << i << ") % " << item->PreScalar() << ") == 1) {" << endl;
+      UInt_t i = priorityGroup[n][m];
+      const AliHLTTriggerMenuItem* item = menu->Item(i);
+      TString triggerCondition = item->TriggerCondition();
+      TString mergeExpr = item->MergeExpression();
+      // Replace the symbols found in the trigger condition and merging expressions
+      // with appropriate compilable versions.
+      for (Int_t j = 0; j < symbols.GetEntriesFast(); j++)
+      {
+        AliHLTTriggerMenuSymbol* symbol = static_cast<AliHLTTriggerMenuSymbol*>( symbols.UncheckedAt(j) );
+        bool symbolNamesDifferent = strcmp(symbol->RealName(), symbol->Name()) != 0;
+        if (strcmp(symbol->ObjectClass(), "AliHLTTriggerDecision") == 0)
+        {
+          TString newname = symbol->Name();
+          newname += "TriggerDomain";
+          mergeExpr.ReplaceAll(symbol->RealName(), newname);
+        }
+        else
+        {
+          if (symbolNamesDifferent) mergeExpr.ReplaceAll(symbol->RealName(), symbol->Name());
+        }
+        if (symbolNamesDifferent) triggerCondition.ReplaceAll(symbol->RealName(), symbol->Name());
+      }
+      // We allow the trigger conditions and merging expressions to have trailing operators.
+      // Thus, we need to extract the operators and cleanup the expressions so that they will
+      // compile. This means that we silently ignore the trailing operator if not needed.
+      if (ExtractedOperator(triggerCondition, conditionOperator[m]))
+      {
+        // If the trailing operator is the same as the default operator then reset
+        // the value in the operator list so that the default is used in the generated
+        // code. This creates more compact code.
+        if (conditionOperator[m] == menu->DefaultConditionOperator()) conditionOperator[m] = "";
+      }
+      if (ExtractedOperator(mergeExpr, domainOperator[m]))
+      {
+        if (domainOperator[m] == menu->DefaultDomainOperator()) domainOperator[m] = "";
+      }
+      if (fDebugMode)
+      {
+        code << "    HLTDebug(Form(\"Trying trigger condition " << i
+             << " (Description = '%s').\", fMenuItemDescription" << i << ".Data()));"
+             << endl;
+      }
+      code << "    ";
+      if (n == 0 and m == 0) code << "bool ";
+      code << "_item_result_ = false;" << endl;
+      code << "    if (" << triggerCondition << ") {" << endl;
+      code << "      ++fCounter[" << i << "];" << endl;
+      const char* indentation = "";
+      if (item->PreScalar() != 0)
+      {
+        indentation = "  ";
+        code << "      if ((fCounter[" << i << "] % " << item->PreScalar() << ") == 1) {" << endl;
+      }
+      code << indentation << "      _item_result_ = true;" << endl;
+      if (fDebugMode)
+      {
+        code << indentation << "      HLTDebug(Form(\"Matched trigger condition " << i
+             << " (Description = '%s').\", fMenuItemDescription" << i << ".Data()));" << endl;
+      }
+      if (item->PreScalar() != 0)
+      {
+        code << "      }" << endl;
+      }
+      code << "    }" << endl;
+      if (m == 0)
+      {
+        // Since this is the first item of the trigger group,
+        // the generated trigger logic can be simplified a little.
+        code << "    _group_result_ = _item_result_;" << endl;
+        code << "    if (_item_result_) {" << endl;
+        code << "      _domain_ = " << mergeExpr.Data() << ";" << endl;
+        code << "      _description_ = fMenuItemDescription" << i << ";" << endl;
+        code << "      _previous_match_ = " << i << ";" << endl;
+        code << "      _trigger_matched_ = true;" << endl;
+        code << "    }" << endl;
+      }
+      else
+      {
+        if (conditionOperator[m-1] == "")
+        {
+          code << "    _group_result_ = _group_result_ "
+               << menu->DefaultConditionOperator() << " _item_result_;" << endl;
+        }
+        else
+        {
+          code << "    _group_result_ = _group_result_ "
+               << conditionOperator[m-1] << " _item_result_;" << endl;
+        }
+        code << "    if (_item_result_) {" << endl;
+        code << "      if (_trigger_matched_) {" << endl;
+        bool switchWillBeEmpty = true;
+        for (size_t k = 0; k < m; k++)
+        {
+          if (domainOperator[k] == "") continue;
+          switchWillBeEmpty = false;
+        }
+        if (switchWillBeEmpty)
+        {
+          code << "        _domain_ = _domain_ " << menu->DefaultDomainOperator() << " "
+               << mergeExpr.Data() << ";" << endl;
+        }
+        else
+        {
+          code << "        switch(_previous_match_) {" << endl;
+          for (size_t k = 0; k < m; k++)
+          {
+            if (domainOperator[k] == "") continue;
+            code << "        case " << k << ": _domain_ = _domain_ "
+                 << domainOperator[k] << " " << mergeExpr.Data() << "; break;" << endl;
+          }
+          code << "        default: _domain_ = _domain_ "
+               << menu->DefaultDomainOperator() << " " << mergeExpr.Data() << ";" << endl;
+          code << "        }" << endl;
+        }
+        code << "        _description_ += \",\";" << endl;
+        code << "        _description_ += fMenuItemDescription" << i << ";" << endl;
+        code << "      } else {" << endl;
+        code << "        _domain_ = " << mergeExpr.Data() << ";" << endl;
+        code << "        _description_ = fMenuItemDescription" << i << ";" << endl;
+        code << "      }" << endl;
+        code << "      _previous_match_ = " << i << ";" << endl;
+        code << "      _trigger_matched_ = true;" << endl;
+        code << "    }" << endl;
+      }
     }
-    code << indentation << "      _domain_ = " << mergeExpr.Data() << ";" << endl;
-    code << indentation << "      _description_ = fMenuItemDescription" << i << ";" << endl;
+    code << "    if (_group_result_) {" << endl;
     if (fDebugMode)
     {
-      code << indentation << "      HLTDebug(\"Matched trigger condition " << i
-           << " (Description = '%s').\", fMenuItemDescription" << i << ".Data());" << endl;
-    }
-    code << indentation << "      return true;" << endl;
-    if (item->PreScalar() != 0)
-    {
-      code << "      }" << endl;
+      if (n < priorities.size() - 1)
+      {
+        code << "      HLTDebug(Form(\"Matched triggers in trigger priority group " << priorities[n]
+             << ". Stopping processing here because all other trigger groups have lower priority.\"));" << endl;
+      }
+      else
+      {
+        code << "      HLTDebug(Form(\"Matched triggers in trigger priority group " << priorities[n] << ".\"));" << endl;
+      }
     }
+    code << "      return true;" << endl;
     code << "    }" << endl;
   }
+  code << "    _domain_.Clear();" << endl;
+  code << "    _description_ = \"\";" << endl;
   code << "    return false;" << endl;
   code << "  }" << endl;
   
-  // Generate the custom Factory class.
-  code << "  class FactoryImpl : public AliHLTGlobalTrigger::Factory" << endl;
-  code << "  {" << endl;
-  code << "  public:" << endl;
-  code << "    virtual const char* ClassName() const {" << endl;
-  code << "      return \"" << name << "\";" << endl;
-  code << "    }" << endl;
-  code << "    virtual AliHLTGlobalTrigger* New() const {" << endl;
-  code << "      return new " << name << "();" << endl;
-  code << "    }" << endl;
-  code << "  };" << endl;
+  // Generate getter and setter methods for the counters.
+  code << "  const TArrayL64& GetCounters() const { return fCounter; }" << endl;
+  code << "  void SetCounters(const TArrayL64& counters) { fCounter = counters; }" << endl;
   
   code << "private:" << endl;
   // Add the symbols in the trigger menu to the list of private variables.
@@ -682,17 +1291,21 @@ int AliHLTGlobalTriggerComponent::GenerateTrigger(
   {
     code << "  TString fMenuItemDescription" << i << ";" << endl;
   }
+  code << "  TArrayL64 fCounter;" << endl;
+  code << "#if !defined(__CINT__) || defined(__MAKECINT__)" << endl;
+  code << "  ClassDef(" << name.Data() << ", 0)" << endl;
+  code << "#else" << endl;
+  code << "  virtual const char* Class_Name() const { return \"" << name.Data() << "\"; }" << endl;
+  code << "#endif" << endl;
   code << "};" << endl;
-  
-  // Write a global object for the Factory class for automatic registration.
-  code << "namespace {" << endl;
-  code << "  const " << name << "::FactoryImpl gkFactoryImpl;" << endl;
-  code << "};" << endl;
+  code << "#if !defined(__CINT__) || defined(__MAKECINT__)" << endl;
+  code << "ClassImp(" << name.Data() << ")" << endl;
+  code << "#endif" << endl;
   
   code.close();
   
   // Now we need to compile and load the new class.
-  result = LoadTriggerClass(fCodeFileName, includePaths);
+  result = LoadTriggerClass(filename, includePaths);
   return result;
 }
 
@@ -703,17 +1316,29 @@ int AliHLTGlobalTriggerComponent::LoadTriggerClass(
 {
   // Loads the code for a custom global trigger class implementation on the fly.
   
+  HLTDebug("Loading HLT trigger class from file '%s'.", filename);
+  
   TString compiler = gSystem->GetBuildCompilerVersion();
-  if (compiler.Contains("gcc") or compiler.Contains("icc"))
+  if (fRuntimeCompile && (compiler.Contains("gcc") or compiler.Contains("icc")))
   {
-    TString includePath = "-I${ALIHLT_TOPDIR}/BASE -I${ALIHLT_TOPDIR}/trigger -I${ALICE_ROOT}/include -I${ALICE_ROOT}/HLT/BASE -I${ALICE_ROOT}/HLT/trigger";
+    TString includePath;
+#if defined(PKGINCLUDEDIR)
+    // this is especially for the HLT build system where the package is installed
+    // in a specific directory including proper treatment of include files
+    includePath.Form("-I%s", PKGINCLUDEDIR);
+#else
+    // the default AliRoot behavior, all include files can be found in the
+    // $ALICE_ROOT subfolders
+    includePath = "-I${ALICE_ROOT}/include -I${ALICE_ROOT}/HLT/BASE -I${ALICE_ROOT}/HLT/trigger";
+#endif
     // Add any include paths that were specified on the command line.
     for (Int_t i = 0; i < includePaths.GetEntriesFast(); i++)
     {
       TString path = static_cast<TObjString*>(includePaths.UncheckedAt(i))->String();
-      includePath += " ";
+      includePath += " -I";
       includePath += path;
     }
+    HLTDebug("using include settings: %s", includePath.Data());
     gSystem->SetIncludePath(includePath);
     gSystem->SetFlagsOpt("-O3 -DNDEBUG");
     gSystem->SetFlagsDebug("-g3 -DDEBUG -D__DEBUG");
@@ -735,6 +1360,9 @@ int AliHLTGlobalTriggerComponent::LoadTriggerClass(
   }
   else
   {
+    // Store the library state to be checked later in UnloadTriggerClass.
+    fLibStateAtLoad = gSystem->GetLibraries();
+    
     // If we do not support the compiler then try interpret the class instead.
     TString cmd = ".L ";
     cmd += filename;
@@ -754,6 +1382,103 @@ int AliHLTGlobalTriggerComponent::LoadTriggerClass(
 }
 
 
+int AliHLTGlobalTriggerComponent::UnloadTriggerClass(const char* filename)
+{
+  // Unloads the code previously loaded by LoadTriggerClass.
+  
+  HLTDebug("Unloading HLT trigger class in file '%s'.", filename);
+  
+  TString compiler = gSystem->GetBuildCompilerVersion();
+  if (fRuntimeCompile && (compiler.Contains("gcc") or compiler.Contains("icc")))
+  {
+    // Generate the library name.
+    TString libname = filename;
+    Ssiz_t dotpos = libname.Last('.');
+    if (0 <= dotpos and dotpos < libname.Length()) libname[dotpos] = '_';
+    libname += ".";
+    libname += gSystem->GetSoExt();
+    
+    // This is a workaround for a problem with unloading shared libraries in ROOT.
+    // If the trigger logic library is loaded before the libAliHLTHOMER.so library
+    // or any other library is loaded afterwards, then during the gInterpreter->UnloadFile
+    // call all the subsequent libraries get unloded. This means that any objects created
+    // from classes implemented in the libAliHLTHOMER.so library will generate segfaults
+    // since the executable code has been unloaded.
+    // We need to check if there are any more libraries loaded after the class we
+    // are unloading and in that case don't unload the class.
+    TString libstring = gSystem->GetLibraries();
+    TString token, lastlib;
+    Ssiz_t from = 0;
+    Int_t numOfLibs = 0, posOfLib = -1;
+    while (libstring.Tokenize(token, from, " "))
+    {
+      ++numOfLibs;
+      lastlib = token;
+      if (token.Contains(libname)) posOfLib = numOfLibs;
+    }
+    if (numOfLibs != posOfLib)
+    {
+      HLTWarning(Form("ROOT limitation! Cannot properly cleanup and unload the shared"
+          " library '%s' since another library '%s' was loaded afterwards. Trying to"
+          " unload this library will remove the others and lead to serious memory faults.",
+          libname.Data(), lastlib.Data()
+      ));
+      return 0;
+    }
+    
+    char* path = NULL;
+    int result = 0;
+    if ((path = gSystem->DynamicPathName(libname)) != NULL)
+    {
+      result = gInterpreter->UnloadFile(path);
+      delete [] path;
+    }
+    if (result != TInterpreter::kNoError) return -ENOENT;
+  }
+  else
+  {
+    // This is again a workaround for the problem with unloading files in ROOT.
+    // If the trigger logic class is loaded before the libAliHLTHOMER.so library
+    // or any other library is loaded afterwards, then during the gInterpreter->UnloadFile
+    // call all the subsequent libraries get unloded.
+    // We need to check if the list of loaded libraries has changed since the last
+    // call to LoadTriggerClass. If it has then don't unload the class.
+    if (fLibStateAtLoad != gSystem->GetLibraries())
+    {
+      TString libstring = gSystem->GetLibraries();
+      TString token;
+      Ssiz_t from = 0;
+      while (libstring.Tokenize(token, from, " "))
+      {
+        if (not fLibStateAtLoad.Contains(token)) break;
+      }
+      HLTWarning(Form("ROOT limitation! Cannot properly cleanup and unload the file"
+          " '%s' since another library '%s' was loaded afterwards. Trying to unload"
+          " this file will remove the other library and lead to serious memory faults.",
+          filename, token.Data()
+      ));
+      return 0;
+    }
+  
+    // If we did not compile the trigger logic then remove the interpreted class.
+    TString cmd = ".U ";
+    cmd += filename;
+    Int_t errorcode = TInterpreter::kNoError;
+    gROOT->ProcessLine(cmd, &errorcode);
+    if (errorcode != TInterpreter::kNoError)
+    {
+      HLTFatal("Could not unload interpreted global trigger menu implementation"
+               " (Interpreter error code = %d).",
+               errorcode
+      );
+      return -ENOENT;
+    }
+  }
+  
+  return 0;
+}
+
+
 int AliHLTGlobalTriggerComponent::FindSymbol(const char* name, const TClonesArray& list)
 {
   // Searches for the named symbol in the given list.
@@ -775,6 +1500,12 @@ int AliHLTGlobalTriggerComponent::BuildSymbolList(const AliHLTTriggerMenu* menu,
   // implementation class.
   // See header for more details.
   
+  // Note: when we build the symbol list we must use the symbol name as returned
+  // by the Name() method and not the RealName() method when using FindSymbol.
+  // This is so that we avoid problems with the generated code not compiling
+  // because names like "abc-xyz" and "abc_xyz" are synonymous.
+  // Name() returns the converted C++ symbol name as used in the generated code.
+  
   for (UInt_t i = 0; i < menu->NumberOfSymbols(); i++)
   {
     const AliHLTTriggerMenuSymbol* symbol = menu->Symbol(i);
@@ -783,15 +1514,23 @@ int AliHLTGlobalTriggerComponent::BuildSymbolList(const AliHLTTriggerMenu* menu,
       HLTError("Multiple symbols with the name '%s' defined in the trigger menu.", symbol->Name());
       return -EIO;
     }
-    new (list[list.GetEntriesFast()]) AliHLTTriggerMenuSymbol(*symbol);
+    try
+    {
+      new (list[list.GetEntriesFast()]) AliHLTTriggerMenuSymbol(*symbol);
+    }
+    catch (const std::bad_alloc&)
+    {
+      HLTError("Could not allocate more memory for the symbols list when adding a trigger menu symbol.");
+      return -ENOMEM;
+    }
   }
   
-  TRegexp exp("[_a-zA-Z][_a-zA-Z0-9]*");
+  TRegexp exp("[_a-zA-Z][-_a-zA-Z0-9]*");
   TRegexp hexexp("x[a-fA-F0-9]+");
   for (UInt_t i = 0; i < menu->NumberOfItems(); i++)
   {
     const AliHLTTriggerMenuItem* item = menu->Item(i);
-    TString str = item->TriggerCondision();
+    TString str = item->TriggerCondition();
     Ssiz_t start = 0;
     do
     {
@@ -830,15 +1569,25 @@ int AliHLTGlobalTriggerComponent::BuildSymbolList(const AliHLTTriggerMenu* menu,
         continue;
       }
 
-      if (FindSymbol(s.Data(), list) == -1)
+      // Need to create the symbols first and check if its name is in the list
+      // before actually adding it to the symbols list.
+      AliHLTTriggerMenuSymbol newSymbol;
+      newSymbol.Name(s.Data());
+      newSymbol.Type("bool");
+      newSymbol.ObjectClass("AliHLTTriggerDecision");
+      newSymbol.AssignExpression("this->Result()");
+      newSymbol.DefaultValue("false");
+      if (FindSymbol(newSymbol.Name(), list) == -1)
       {
-        AliHLTTriggerMenuSymbol newSymbol;
-        newSymbol.Name(s.Data());
-        newSymbol.Type("bool");
-        newSymbol.ObjectClass("AliHLTTriggerDecision");
-        newSymbol.AssignExpression("this->Result()");
-        newSymbol.DefaultValue("false");
-        new (list[list.GetEntriesFast()]) AliHLTTriggerMenuSymbol(newSymbol);
+        try
+        {
+          new (list[list.GetEntriesFast()]) AliHLTTriggerMenuSymbol(newSymbol);
+        }
+        catch (const std::bad_alloc&)
+        {
+          HLTError("Could not allocate more memory for the symbols list when adding a trigger name symbol.");
+          return -ENOMEM;
+        }
       }
     }
     while (start < str.Length());
@@ -847,17 +1596,145 @@ int AliHLTGlobalTriggerComponent::BuildSymbolList(const AliHLTTriggerMenu* menu,
   return 0;
 }
 
+
+bool AliHLTGlobalTriggerComponent::ExtractedOperator(TString& expr, TString& op)
+{
+  // Extracts the trailing operator from the expression.
+  
+  Ssiz_t i = 0;
+  // First skip the trailing whitespace.
+  bool whitespace = true;
+  for (i = expr.Length()-1; i >= 0 and whitespace; i--)
+  {
+    switch (expr[i])
+    {
+    case ' ': case '\t': case '\r': case '\n':
+      whitespace = true;
+      break;
+    default:
+      whitespace = false;
+    }
+  }
+  if (i < 0 or whitespace) return false;
+  
+  // Now find the first whitespace character before the trailing symbol.
+  bool nonwhitespace = true;
+  for (; i >= 0 and nonwhitespace; i--)
+  {
+    switch (expr[i])
+    {
+    case ' ': case '\t': case '\r': case '\n':
+      nonwhitespace = false;
+      break;
+    default:
+      nonwhitespace = true;
+    }
+  }
+  if (i < 0 or nonwhitespace) return false;
+  
+  // Extract the last symbols and check if it is a valid operator.
+  TString s = expr;
+  s.Remove(0, i+2);
+  if (s == "and" or s == "and_eq" or s == "bitand" or s == "bitor" or
+      s == "compl" or s == "not" or s == "not_eq" or s == "or" or
+      s == "or_eq" or s == "xor" or s == "xor_eq" or s == "&&" or
+      s == "&=" or s == "&" or s == "|" or s == "~" or s == "!" or
+      s == "!=" or s == "||" or s == "|=" or s == "^" or s == "^=" or
+      s == "==" or s == "+" or s == "-" or s == "*" or s == "/" or
+      s == "%" or s == ">" or s == "<" or s == ">=" or s == "<="
+     )
+  {
+    expr.Remove(i+1);
+    op = s;
+    return true;
+  }
+  
+  return false;
+}
+
+
 int AliHLTGlobalTriggerComponent::PrintStatistics(const AliHLTGlobalTrigger* pTrigger, AliHLTComponentLogSeverity level, int offset) const
 {
   // print some statistics
-  ULong64_t count=0;
-  const TArrayL64* counters=pTrigger->Counters();
-  for (int i=0; counters!=NULL && i<counters->GetSize(); i++) {
-    count+=(*counters)[i];
-  }
   int totalEvents=GetEventCount()+offset;
-  float ratio=0;
-  if (totalEvents>0) ratio=100*(float)count/totalEvents;
-  HLTLog(level, "total events: %d - triggered events: %llu (%.1f%%)", totalEvents, count, ratio);
+  const TArrayL64& counters = pTrigger->GetCounters();
+  if (pTrigger->CallFailed()) return -EPROTO;
+  for (int i = 0; i < counters.GetSize(); i++) {
+    ULong64_t count = counters[i];
+    float ratio=0;
+    if (totalEvents>0) ratio=100*(float)count/totalEvents;
+    HLTLog(level, "Item %d: total events: %d - counted events: %llu (%.1f%%)", i, totalEvents, count, ratio);
+  }
+  return 0;
+}
+
+int AliHLTGlobalTriggerComponent::AddCTPDecisions(AliHLTGlobalTrigger* pTrigger, const AliHLTCTPData* pCTPData, const AliHLTComponentTriggerData* trigData)
+{
+  // add trigger decisions for the valid CTP classes
+  if (!pCTPData || !pTrigger) return 0;
+
+  AliHLTUInt64_t triggerMask=pCTPData->Mask();
+  AliHLTUInt64_t bit0=0x1;
+  if (!fCTPDecisions) {
+    try
+    {
+      fCTPDecisions=new TClonesArray(AliHLTTriggerDecision::Class(), gkNCTPTriggerClasses);
+    }
+    catch (const std::bad_alloc&)
+    {
+      HLTError("Could not allocate memory for the CTP decisions array.");
+      return -ENOMEM;
+    }
+    if (!fCTPDecisions) return -ENOMEM;
+
+    try
+    {
+      fCTPDecisions->ExpandCreate(gkNCTPTriggerClasses);
+    }
+    catch (const std::bad_alloc&)
+    {
+      HLTError("Could not allocate more memory for the CTP decisions array.");
+      return -ENOMEM;
+    }
+    for (int i=0; i<gkNCTPTriggerClasses; i++) {
+      const char* name=pCTPData->Name(i);
+      if (triggerMask&(bit0<<i) && name) {
+       AliHLTTriggerDecision* pDecision=dynamic_cast<AliHLTTriggerDecision*>(fCTPDecisions->At(i));
+       assert(pDecision);
+       if (!pDecision) {
+         delete fCTPDecisions;
+         fCTPDecisions=NULL;
+         return -ENOENT;
+       }
+       pDecision->Name(name);
+      }
+    }
+  }
+
+  for (int i=0; i<gkNCTPTriggerClasses; i++) {
+    const char* name=pCTPData->Name(i);
+    if ((triggerMask&(bit0<<i))==0 || name==NULL) continue;
+    AliHLTTriggerDecision* pDecision=dynamic_cast<AliHLTTriggerDecision*>(fCTPDecisions->At(i));
+    HLTDebug("updating CTP trigger decision %d %s (%p casted %p)", i, name, fCTPDecisions->At(i), pDecision);
+    if (!pDecision) return -ENOENT;
+
+    bool result=false;
+    // 13 March 2010 - Optimisation:
+    // Dont use the EvaluateCTPTriggerClass method, which uses slow TFormula objects.
+    AliHLTUInt64_t triggers = 0;
+    if (trigData) triggers = pCTPData->ActiveTriggers(*trigData);
+    else triggers = pCTPData->Triggers();
+    result = (triggers&((AliHLTUInt64_t)0x1<<i)) ? true : false;
+    //if (trigData) result=pCTPData->EvaluateCTPTriggerClass(name, *trigData);
+    //else result=pCTPData->EvaluateCTPTriggerClass(name);
+    pDecision->Result(result);
+    pDecision->TriggerDomain().Clear();
+    if (trigData) pDecision->TriggerDomain().Add(pCTPData->ReadoutList(*trigData));
+    else pDecision->TriggerDomain().Add(pCTPData->ReadoutList());
+
+    pTrigger->Add(fCTPDecisions->At(i), kAliHLTDataTypeTriggerDecision, kAliHLTVoidDataSpec);
+    if (pTrigger->CallFailed()) return -EPROTO;
+  }
+
   return 0;
 }