]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - HLT/trigger/AliHLTGlobalTriggerComponent.cxx
print the GlobalTrigger statistics once every 60s
[u/mrichter/AliRoot.git] / HLT / trigger / AliHLTGlobalTriggerComponent.cxx
index d56c588bcb5770cedf64c7bf899df665422cb81d..7c577b64e55c3c360d0bb28ad03d48ed5d06bc65 100644 (file)
@@ -38,7 +38,7 @@
 #include "TRegexp.h"
 #include "TClonesArray.h"
 #include "TObjString.h"
-#include "TSystem.h"
+#include "TString.h"
 #include "TInterpreter.h"
 #include "TDatime.h"
 #include "TClass.h"
@@ -78,7 +78,8 @@ AliHLTGlobalTriggerComponent::AliHLTGlobalTriggerComponent() :
        fBufferSizeConst(2*(sizeof(AliHLTGlobalTriggerDecision) + sizeof(AliHLTReadoutList))),
        fBufferSizeMultiplier(1.),
        fIncludePaths(TObjString::Class()),
-       fIncludeFiles(TObjString::Class())
+       fIncludeFiles(TObjString::Class()),
+       fLibStateAtLoad()
 {
   // Default constructor.
   
@@ -99,6 +100,13 @@ AliHLTGlobalTriggerComponent::~AliHLTGlobalTriggerComponent()
 }
 
 
+void AliHLTGlobalTriggerComponent::GetOutputDataTypes(AliHLTComponentDataTypeList& list) const
+{
+  // Returns the kAliHLTDataTypeGlobalTrigger type as output.
+  list.push_back(kAliHLTDataTypeGlobalTrigger);
+}
+
+
 void AliHLTGlobalTriggerComponent::GetOutputDataSize(unsigned long& constBase, double& inputMultiplier)
 {
   // Returns the output data size estimate.
@@ -379,9 +387,9 @@ int AliHLTGlobalTriggerComponent::DoTrigger()
   
   static UInt_t lastTime=0;
   TDatime time;
-  if (time.Get()-lastTime>5) {
+  if (time.Get()-lastTime>60) {
     lastTime=time.Get();
-    PrintStatistics(fTrigger);
+    PrintStatistics(fTrigger, kHLTLogImportant);
   }
   
   // Add the input objects used to the global decision.
@@ -685,11 +693,11 @@ int AliHLTGlobalTriggerComponent::GenerateTrigger(
   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(Form(\"Assinging domain entry value corresponding with symbol '%s' to '%s'.\","
-              " symbol->Name(), symbol->BlockType().AsString().Data()));" << endl;
+              " symbol->RealName(), symbol->BlockType().AsString().Data()));" << endl;
     }
     code << "        " << symbol->Name() << "DomainEntry = symbol->BlockType();" << endl;
     code << "        continue;" << endl;
@@ -788,7 +796,7 @@ int AliHLTGlobalTriggerComponent::GenerateTrigger(
     if (isTrigDecision)
     {
       code << "strcmp(" << symbol->Name() << "_object_->Name(), \""
-           << symbol->Name() << "\") == 0 && ";
+           << symbol->RealName() << "\") == 0 && ";
     }
     code << symbol->Name() << "DomainEntry == _type_spec_) {" << endl;
     TString fullname = symbol->Name();
@@ -1127,6 +1135,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;
@@ -1155,12 +1166,41 @@ int AliHLTGlobalTriggerComponent::UnloadTriggerClass(const char* 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)
@@ -1172,7 +1212,30 @@ int AliHLTGlobalTriggerComponent::UnloadTriggerClass(const char* filename)
   }
   else
   {
-    // If we do not support the compiler then try interpret the class instead.
+    // 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;
@@ -1212,6 +1275,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);
@@ -1267,14 +1336,16 @@ 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);
       }
     }