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 AliHLTGlobalTriggerWrapper.cxx
19 /// @author Artur Szostak <artursz@iafrica.com>
21 /// @brief Implementation of the AliHLTGlobalTriggerWrapper interface class.
23 /// The AliHLTGlobalTriggerWrapper class is used to interface with an interpreted
24 /// class deriving from AliHLTGlobalTrigger. This is used when the global trigger
25 /// component is using CINT to interpret the trigger logic. The wrapper is necessary
26 /// to be able to call interpreted code from compiled code.
28 #include "AliHLTGlobalTriggerWrapper.h"
29 #include "TArrayL64.h"
31 #include "TInterpreter.h"
32 #if ROOT_VERSION_CODE < ROOT_VERSION(5,99,0)
34 # define LAST_ERR_LINENO G__lasterror_linenum()
36 # define LAST_ERR_LINENO 0
39 ClassImp(AliHLTGlobalTriggerWrapper)
44 /// Variable to store the error message if an error occured in CINT when interpreting code.
45 TString gCINTErrorMessage = "";
48 * This routine is the callback for the CINT interpreter when it finds a syntax error
49 * in the source code generated by the AliHLTGlobalTriggerComponent class.
51 void AliHLTOnErrorInCINT(char* message)
53 gCINTErrorMessage += message;
59 AliHLTGlobalTriggerWrapper::AliHLTGlobalTriggerWrapper(const char* classname) :
60 AliHLTGlobalTrigger(),
67 fCalculateTriggerDecisionCall(),
72 // The default constructor.
74 fClass = TClass::GetClass(classname);
77 HLTError("Could not find class information for '%s'.", classname);
80 fFillFromMenuCall.InitWithPrototype(fClass, "FillFromMenu", "const AliHLTTriggerMenu&");
81 if (not fFillFromMenuCall.IsValid())
83 HLTError("Could not initialise method call object for class '%s' and method FillFromMenu.", classname);
86 fNewEventCall.InitWithPrototype(fClass, "NewEvent", " "); // Must have single whitespace in last parameter or we get a segfault in G__interpret_func.
87 if (not fNewEventCall.IsValid())
89 HLTError("Could not initialise method call object for class '%s' and method NewEvent.", classname);
92 fAddCall.InitWithPrototype(fClass, "Add", "const TObject*, const AliHLTComponentDataType&, AliHLTUInt32_t");
93 if (not fAddCall.IsValid())
95 HLTError("Could not initialise method call object for class '%s' and method Add.", classname);
98 fCalculateTriggerDecisionCall.InitWithPrototype(fClass, "CalculateTriggerDecision", "bool&, AliHLTTriggerDomain&, TString&");
99 if (not fCalculateTriggerDecisionCall.IsValid())
101 HLTError("Could not initialise method call object for class '%s' and method CalculateTriggerDecision.", classname);
104 fGetCountersCall.InitWithPrototype(fClass, "GetCounters", " "); // Must have single whitespace in last parameter or we get a segfault in G__interpret_func.
105 if (not fGetCountersCall.IsValid())
107 HLTError("Could not initialise method call object for class '%s' and method GetCounters.", classname);
110 fSetCountersCall.InitWithPrototype(fClass, "SetCounters", "TArrayL64&");
111 if (not fSetCountersCall.IsValid())
113 HLTError("Could not initialise method call object for class '%s' and method SetCounters.", classname);
116 fObject = fClass->New();
119 HLTError("Could not create a new object of type '%s'.", classname);
122 // The following is a workaround for casting void* to void (*)(), i.e. a pointer to object to
123 // a pointer to function. Unfortunately the G__set_errmsgcallback routine interface is defined
124 // using a pointer to object so this workaround is necessary.
125 // We check that the two types are the same size. If they are not then such an operation is
126 // unsafe on the platform on which we are running and will not be performed.
130 void (*fFuncPtr)(char*);
132 fFuncPtr = AliHLTOnErrorInCINT;
133 if (sizeof(fPtr) == sizeof(fFuncPtr))
135 gInterpreter->SetErrmsgcallback(fPtr);
139 HLTWarning("On this platform a pointer to function and pointer to object are different sizes."
140 " For this reason we cannot use the G__set_errmsgcallback CINT API call in a safe way so all"
141 " error messages generated by CINT will not be captured or logged in the HLT system."
147 AliHLTGlobalTriggerWrapper::~AliHLTGlobalTriggerWrapper()
149 // Default destructor.
151 fClass->Destructor(fObject);
152 #if ROOT_VERSION_CODE < ROOT_VERSION(5,99,0)
153 G__set_errmsgcallback(NULL);
158 void AliHLTGlobalTriggerWrapper::FillFromMenu(const AliHLTTriggerMenu& menu)
160 // Fills internal values from the trigger menu.
167 params.fMenu = &menu;
168 fFillFromMenuCall.SetParamPtrs(¶ms, 1);
169 gCINTErrorMessage = "";
170 fFillFromMenuCall.Execute(fObject);
171 if (gCINTErrorMessage != "")
174 HLTError(gCINTErrorMessage.Data());
175 HLTFatal("Error interpreting the code for class '%s' at line %d.", fClass->GetName(), LAST_ERR_LINENO);
180 void AliHLTGlobalTriggerWrapper::NewEvent()
182 // Clears the internal buffers for a new event.
185 gCINTErrorMessage = "";
186 fNewEventCall.Execute(fObject);
187 if (gCINTErrorMessage != "")
190 HLTError(gCINTErrorMessage.Data());
191 HLTFatal("Error interpreting the code for class '%s' at line %d.", fClass->GetName(), LAST_ERR_LINENO);
196 void AliHLTGlobalTriggerWrapper::Add(
197 const TObject* object, const AliHLTComponentDataType& type,
201 // Adds parameters from the object to the internal buffers and variables.
210 params.fObj = object;
211 params.fType = &type;
213 fAddCall.SetParamPtrs(¶ms, 3);
214 gCINTErrorMessage = "";
215 fAddCall.Execute(fObject);
216 if (gCINTErrorMessage != "")
219 HLTError(gCINTErrorMessage.Data());
220 HLTFatal("Error interpreting the code for class '%s' at line %d.", fClass->GetName(), LAST_ERR_LINENO);
225 bool AliHLTGlobalTriggerWrapper::CalculateTriggerDecision(bool& triggerResult, AliHLTTriggerDomain& domain, TString& description)
227 // Calculates the global trigger decision.
236 params.fResult = &triggerResult;
237 params.fDomain = &domain;
238 params.fDesc = &description;
239 fCalculateTriggerDecisionCall.SetParamPtrs(¶ms, 3);
241 gCINTErrorMessage = "";
242 fCalculateTriggerDecisionCall.Execute(fObject, retval);
243 if (gCINTErrorMessage != "")
246 HLTError(gCINTErrorMessage.Data());
247 HLTFatal("Error interpreting the code for class '%s' at line %d.", fClass->GetName(), LAST_ERR_LINENO);
254 const TArrayL64& AliHLTGlobalTriggerWrapper::GetCounters() const
256 // Returns the internal counter array.
259 gCINTErrorMessage = "";
260 fGetCountersCall.Execute(fObject, retval);
261 if (gCINTErrorMessage != "")
264 HLTError(gCINTErrorMessage.Data());
265 HLTFatal("Error interpreting the code for class '%s' at line %d.", fClass->GetName(), LAST_ERR_LINENO);
267 static const TArrayL64 emptyArray;
268 const TArrayL64* ptr = &emptyArray; // Make sure we do not return a NULL pointer.
269 if (retval != 0x0) ptr = reinterpret_cast<const TArrayL64*>(retval);
274 void AliHLTGlobalTriggerWrapper::SetCounters(const TArrayL64& counters)
276 // Fills the internal counter array with new values.
281 const void* fCounters;
283 params.fCounters = &counters;
284 fSetCountersCall.SetParamPtrs(¶ms, 1);
285 gCINTErrorMessage = "";
286 fSetCountersCall.Execute(fObject);
287 if (gCINTErrorMessage != "")
290 HLTError(gCINTErrorMessage.Data());
291 HLTFatal("Error interpreting the code for class '%s' at line %d.", fClass->GetName(), LAST_ERR_LINENO);
296 bool AliHLTGlobalTriggerWrapper::IsValid() const
298 // Checks if the wrapper class was initialised correctly.
300 return fClass != NULL and fObject != NULL and fFillFromMenuCall.IsValid()
301 and fNewEventCall.IsValid() and fAddCall.IsValid()
302 and fCalculateTriggerDecisionCall.IsValid();