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"
33 #ifdef R__BUILDING_CINT7
34 #include "cint7/Api.h"
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", "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 // Matthias 2009-11-03: temporarily disabled, on some systems the warning
123 // is interpreted an an error, so we have a litle problem with root
124 // HLT/trigger/AliHLTGlobalTriggerWrapper.cxx:122: error: ISO C++ forbids
125 // casting between pointer-to-function and pointer-to-object
126 //G__set_errmsgcallback(reinterpret_cast<void*>(AliHLTOnErrorInCINT));
130 AliHLTGlobalTriggerWrapper::~AliHLTGlobalTriggerWrapper()
132 // Default destructor.
134 fClass->Destructor(fObject);
138 void AliHLTGlobalTriggerWrapper::FillFromMenu(const AliHLTTriggerMenu& menu)
140 // Fills internal values from the trigger menu.
147 params.fMenu = &menu;
148 fFillFromMenuCall.SetParamPtrs(¶ms, 1);
149 gCINTErrorMessage = "";
150 fFillFromMenuCall.Execute(fObject);
151 if (gCINTErrorMessage != "")
154 HLTError(gCINTErrorMessage.Data());
155 HLTFatal("Error interpreting the code for class '%s' at line %d.", fClass->GetName(), G__lasterror_linenum());
160 void AliHLTGlobalTriggerWrapper::NewEvent()
162 // Clears the internal buffers for a new event.
165 gCINTErrorMessage = "";
166 fNewEventCall.Execute(fObject);
167 if (gCINTErrorMessage != "")
170 HLTError(gCINTErrorMessage.Data());
171 HLTFatal("Error interpreting the code for class '%s' at line %d.", fClass->GetName(), G__lasterror_linenum());
176 void AliHLTGlobalTriggerWrapper::Add(
177 const TObject* object, const AliHLTComponentDataType& type,
181 // Adds parameters from the object to the internal buffers and variables.
190 params.fObj = object;
191 params.fType = &type;
193 fAddCall.SetParamPtrs(¶ms, 3);
194 gCINTErrorMessage = "";
195 fAddCall.Execute(fObject);
196 if (gCINTErrorMessage != "")
199 HLTError(gCINTErrorMessage.Data());
200 HLTFatal("Error interpreting the code for class '%s' at line %d.", fClass->GetName(), G__lasterror_linenum());
205 bool AliHLTGlobalTriggerWrapper::CalculateTriggerDecision(AliHLTTriggerDomain& domain, TString& description)
207 // Calculates the global trigger decision.
215 params.fDomain = &domain;
216 params.fDesc = &description;
217 fCalculateTriggerDecisionCall.SetParamPtrs(¶ms, 2);
219 gCINTErrorMessage = "";
220 fCalculateTriggerDecisionCall.Execute(fObject, retval);
221 if (gCINTErrorMessage != "")
224 HLTError(gCINTErrorMessage.Data());
225 HLTFatal("Error interpreting the code for class '%s' at line %d.", fClass->GetName(), G__lasterror_linenum());
232 const TArrayL64& AliHLTGlobalTriggerWrapper::GetCounters() const
234 // Returns the internal counter array.
237 gCINTErrorMessage = "";
238 fGetCountersCall.Execute(fObject, retval);
239 if (gCINTErrorMessage != "")
242 HLTError(gCINTErrorMessage.Data());
243 HLTFatal("Error interpreting the code for class '%s' at line %d.", fClass->GetName(), G__lasterror_linenum());
245 static const TArrayL64 emptyArray;
246 const TArrayL64* ptr = &emptyArray; // Make sure we do not return a NULL pointer.
247 if (retval != 0x0) ptr = reinterpret_cast<const TArrayL64*>(retval);
252 void AliHLTGlobalTriggerWrapper::SetCounters(const TArrayL64& counters)
254 // Fills the internal counter array with new values.
259 const void* fCounters;
261 params.fCounters = &counters;
262 fSetCountersCall.SetParamPtrs(¶ms, 1);
263 gCINTErrorMessage = "";
264 fSetCountersCall.Execute(fObject);
265 if (gCINTErrorMessage != "")
268 HLTError(gCINTErrorMessage.Data());
269 HLTFatal("Error interpreting the code for class '%s' at line %d.", fClass->GetName(), G__lasterror_linenum());
274 bool AliHLTGlobalTriggerWrapper::IsValid() const
276 // Checks if the wrapper class was initialised correctly.
278 return fClass != NULL and fObject != NULL and fFillFromMenuCall.IsValid()
279 and fNewEventCall.IsValid() and fAddCall.IsValid()
280 and fCalculateTriggerDecisionCall.IsValid();