]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - HLT/trigger/AliHLTGlobalTriggerWrapper.cxx
Updating documentation
[u/mrichter/AliRoot.git] / HLT / trigger / AliHLTGlobalTriggerWrapper.cxx
index 22eae9045814c74d7a7a1e5056dafe8e7bbfe97b..db797afe1de18336930e4efc5ecc113a3b0dc316 100644 (file)
 #include "TArrayL64.h"
 #include "TClass.h"
 #include "TInterpreter.h"
-
-#ifdef R__BUILDING_CINT7
-#include "cint7/Api.h"
-#else
-#include "Api.h"
-#endif
+#include "TCint.h"
 
 ClassImp(AliHLTGlobalTriggerWrapper)
 
 
+namespace
+{
+  /// Variable to store the error message if an error occured in CINT when interpreting code.
+  TString gCINTErrorMessage = "";
+  
+  /**
+   * This routine is the callback for the CINT interpreter when it finds a syntax error
+   * in the source code generated by the AliHLTGlobalTriggerComponent class.
+   */
+  void AliHLTOnErrorInCINT(char* message)
+  {
+    gCINTErrorMessage += message;
+  }
+
+} // end of namespace
+
+
 AliHLTGlobalTriggerWrapper::AliHLTGlobalTriggerWrapper(const char* classname) :
   AliHLTGlobalTrigger(),
   AliHLTLogging(),
@@ -49,7 +61,8 @@ AliHLTGlobalTriggerWrapper::AliHLTGlobalTriggerWrapper(const char* classname) :
   fAddCall(),
   fCalculateTriggerDecisionCall(),
   fGetCountersCall(),
-  fSetCountersCall()
+  fSetCountersCall(),
+  fCallFailed(false)
 {
   // The default constructor.
   
@@ -100,6 +113,29 @@ AliHLTGlobalTriggerWrapper::AliHLTGlobalTriggerWrapper(const char* classname) :
   {
     HLTError("Could not create a new object of type '%s'.", classname);
   }
+  
+  // The following is a workaround for casting void* to void (*)(), i.e. a pointer to object to
+  // a pointer to function. Unfortunately the G__set_errmsgcallback routine interface is defined
+  // using a pointer to object so this workaround is necessary.
+  // We check that the two types are the same size. If they are not then such an operation is
+  // unsafe on the platform on which we are running and will not be performed.
+  union
+  {
+    void* fPtr;
+    void (*fFuncPtr)(char*);
+  };
+  fFuncPtr = AliHLTOnErrorInCINT;
+  if (sizeof(fPtr) == sizeof(fFuncPtr))
+  {
+    gInterpreter->SetErrmsgcallback(fPtr);
+  }
+  else
+  {
+    HLTWarning("On this platform a pointer to function and pointer to object are different sizes."
+      " For this reason we cannot use the G__set_errmsgcallback CINT API call in a safe way so all"
+      " error messages generated by CINT will not be captured or logged in the HLT system."
+    );
+  }
 }
 
 
@@ -108,6 +144,7 @@ AliHLTGlobalTriggerWrapper::~AliHLTGlobalTriggerWrapper()
   // Default destructor.
   
   fClass->Destructor(fObject);
+  G__set_errmsgcallback(NULL);
 }
 
 
@@ -115,24 +152,20 @@ void AliHLTGlobalTriggerWrapper::FillFromMenu(const AliHLTTriggerMenu& menu)
 {
   // Fills internal values from the trigger menu.
   
+  fCallFailed = false;
   struct Params
   {
     const void* fMenu;
   } params;
   params.fMenu = &menu;
   fFillFromMenuCall.SetParamPtrs(&params, 1);
+  gCINTErrorMessage = "";
   fFillFromMenuCall.Execute(fObject);
-  int error = G__lasterror();
-  if (error != TInterpreter::kNoError)
+  if (gCINTErrorMessage != "")
   {
-    if (error == TInterpreter::kFatal)
-    {
-      HLTFatal("Error interpreting the code for class '%s' at line %d.", fClass->GetName(), G__lasterror_linenum());
-    }
-    else
-    {
-      HLTError("Error interpreting the code for class '%s' at line %d.", fClass->GetName(), G__lasterror_linenum());
-    }
+    fCallFailed = true;
+    HLTError(gCINTErrorMessage.Data());
+    HLTFatal("Error interpreting the code for class '%s' at line %d.", fClass->GetName(), G__lasterror_linenum());
   }
 }
 
@@ -141,18 +174,14 @@ void AliHLTGlobalTriggerWrapper::NewEvent()
 {
   // Clears the internal buffers for a new event.
 
+  fCallFailed = false;
+  gCINTErrorMessage = "";
   fNewEventCall.Execute(fObject);
-  int error = G__lasterror();
-  if (error != TInterpreter::kNoError)
+  if (gCINTErrorMessage != "")
   {
-    if (error == TInterpreter::kFatal)
-    {
-      HLTFatal("Error interpreting the code for class '%s' at line %d.", fClass->GetName(), G__lasterror_linenum());
-    }
-    else
-    {
-      HLTError("Error interpreting the code for class '%s' at line %d.", fClass->GetName(), G__lasterror_linenum());
-    }
+    fCallFailed = true;
+    HLTError(gCINTErrorMessage.Data());
+    HLTFatal("Error interpreting the code for class '%s' at line %d.", fClass->GetName(), G__lasterror_linenum());
   }
 }
 
@@ -164,6 +193,7 @@ void AliHLTGlobalTriggerWrapper::Add(
 {
   // Adds parameters from the object to the internal buffers and variables.
   
+  fCallFailed = false;
   struct Params
   {
     const void* fObj;
@@ -174,18 +204,13 @@ void AliHLTGlobalTriggerWrapper::Add(
   params.fType = &type;
   params.fSpec = spec;
   fAddCall.SetParamPtrs(&params, 3);
+  gCINTErrorMessage = "";
   fAddCall.Execute(fObject);
-  int error = G__lasterror();
-  if (error != TInterpreter::kNoError)
+  if (gCINTErrorMessage != "")
   {
-    if (error == TInterpreter::kFatal)
-    {
-      HLTFatal("Error interpreting the code for class '%s' at line %d.", fClass->GetName(), G__lasterror_linenum());
-    }
-    else
-    {
-      HLTError("Error interpreting the code for class '%s' at line %d.", fClass->GetName(), G__lasterror_linenum());
-    }
+    fCallFailed = true;
+    HLTError(gCINTErrorMessage.Data());
+    HLTFatal("Error interpreting the code for class '%s' at line %d.", fClass->GetName(), G__lasterror_linenum());
   }
 }
 
@@ -194,6 +219,7 @@ bool AliHLTGlobalTriggerWrapper::CalculateTriggerDecision(AliHLTTriggerDomain& d
 {
   // Calculates the global trigger decision.
 
+  fCallFailed = false;
   struct Params
   {
     const void* fDomain;
@@ -203,18 +229,14 @@ bool AliHLTGlobalTriggerWrapper::CalculateTriggerDecision(AliHLTTriggerDomain& d
   params.fDesc = &description;
   fCalculateTriggerDecisionCall.SetParamPtrs(&params, 2);
   Long_t retval;
+  gCINTErrorMessage = "";
   fCalculateTriggerDecisionCall.Execute(fObject, retval);
-  int error = G__lasterror();
-  if (error != TInterpreter::kNoError)
+  if (gCINTErrorMessage != "")
   {
-    if (error == TInterpreter::kFatal)
-    {
-      HLTFatal("Error interpreting the code for class '%s' at line %d.", fClass->GetName(), G__lasterror_linenum());
-    }
-    else
-    {
-      HLTError("Error interpreting the code for class '%s' at line %d.", fClass->GetName(), G__lasterror_linenum());
-    }
+    fCallFailed = true;
+    HLTError(gCINTErrorMessage.Data());
+    HLTFatal("Error interpreting the code for class '%s' at line %d.", fClass->GetName(), G__lasterror_linenum());
+    return false;
   }
   return bool(retval);
 }
@@ -225,18 +247,13 @@ const TArrayL64& AliHLTGlobalTriggerWrapper::GetCounters() const
   // Returns the internal counter array.
 
   Long_t retval = 0x0;
+  gCINTErrorMessage = "";
   fGetCountersCall.Execute(fObject, retval);
-  int error = G__lasterror();
-  if (error != TInterpreter::kNoError)
+  if (gCINTErrorMessage != "")
   {
-    if (error == TInterpreter::kFatal)
-    {
-      HLTFatal("Error interpreting the code for class '%s' at line %d.", fClass->GetName(), G__lasterror_linenum());
-    }
-    else
-    {
-      HLTError("Error interpreting the code for class '%s' at line %d.", fClass->GetName(), G__lasterror_linenum());
-    }
+    fCallFailed = true;
+    HLTError(gCINTErrorMessage.Data());
+    HLTFatal("Error interpreting the code for class '%s' at line %d.", fClass->GetName(), G__lasterror_linenum());
   }
   static const TArrayL64 emptyArray;
   const TArrayL64* ptr = &emptyArray; // Make sure we do not return a NULL pointer.
@@ -249,24 +266,20 @@ void AliHLTGlobalTriggerWrapper::SetCounters(const TArrayL64& counters)
 {
   // Fills the internal counter array with new values.
   
+  fCallFailed = false;
   struct Params
   {
     const void* fCounters;
   } params;
   params.fCounters = &counters;
   fSetCountersCall.SetParamPtrs(&params, 1);
+  gCINTErrorMessage = "";
   fSetCountersCall.Execute(fObject);
-  int error = G__lasterror();
-  if (error != TInterpreter::kNoError)
+  if (gCINTErrorMessage != "")
   {
-    if (error == TInterpreter::kFatal)
-    {
-      HLTFatal("Error interpreting the code for class '%s' at line %d.", fClass->GetName(), G__lasterror_linenum());
-    }
-    else
-    {
-      HLTError("Error interpreting the code for class '%s' at line %d.", fClass->GetName(), G__lasterror_linenum());
-    }
+    fCallFailed = true;
+    HLTError(gCINTErrorMessage.Data());
+    HLTFatal("Error interpreting the code for class '%s' at line %d.", fClass->GetName(), G__lasterror_linenum());
   }
 }