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 G__set_errmsgcallback(reinterpret_cast<void*>(AliHLTOnErrorInCINT));
126 AliHLTGlobalTriggerWrapper::~AliHLTGlobalTriggerWrapper()
128 // Default destructor.
130 fClass->Destructor(fObject);
134 void AliHLTGlobalTriggerWrapper::FillFromMenu(const AliHLTTriggerMenu& menu)
136 // Fills internal values from the trigger menu.
143 params.fMenu = &menu;
144 fFillFromMenuCall.SetParamPtrs(¶ms, 1);
145 gCINTErrorMessage = "";
146 fFillFromMenuCall.Execute(fObject);
147 if (gCINTErrorMessage != "")
150 HLTError(gCINTErrorMessage.Data());
151 HLTFatal("Error interpreting the code for class '%s' at line %d.", fClass->GetName(), G__lasterror_linenum());
156 void AliHLTGlobalTriggerWrapper::NewEvent()
158 // Clears the internal buffers for a new event.
161 gCINTErrorMessage = "";
162 fNewEventCall.Execute(fObject);
163 if (gCINTErrorMessage != "")
166 HLTError(gCINTErrorMessage.Data());
167 HLTFatal("Error interpreting the code for class '%s' at line %d.", fClass->GetName(), G__lasterror_linenum());
172 void AliHLTGlobalTriggerWrapper::Add(
173 const TObject* object, const AliHLTComponentDataType& type,
177 // Adds parameters from the object to the internal buffers and variables.
186 params.fObj = object;
187 params.fType = &type;
189 fAddCall.SetParamPtrs(¶ms, 3);
190 gCINTErrorMessage = "";
191 fAddCall.Execute(fObject);
192 if (gCINTErrorMessage != "")
195 HLTError(gCINTErrorMessage.Data());
196 HLTFatal("Error interpreting the code for class '%s' at line %d.", fClass->GetName(), G__lasterror_linenum());
201 bool AliHLTGlobalTriggerWrapper::CalculateTriggerDecision(AliHLTTriggerDomain& domain, TString& description)
203 // Calculates the global trigger decision.
211 params.fDomain = &domain;
212 params.fDesc = &description;
213 fCalculateTriggerDecisionCall.SetParamPtrs(¶ms, 2);
215 gCINTErrorMessage = "";
216 fCalculateTriggerDecisionCall.Execute(fObject, retval);
217 if (gCINTErrorMessage != "")
220 HLTError(gCINTErrorMessage.Data());
221 HLTFatal("Error interpreting the code for class '%s' at line %d.", fClass->GetName(), G__lasterror_linenum());
228 const TArrayL64& AliHLTGlobalTriggerWrapper::GetCounters() const
230 // Returns the internal counter array.
233 gCINTErrorMessage = "";
234 fGetCountersCall.Execute(fObject, retval);
235 if (gCINTErrorMessage != "")
238 HLTError(gCINTErrorMessage.Data());
239 HLTFatal("Error interpreting the code for class '%s' at line %d.", fClass->GetName(), G__lasterror_linenum());
241 static const TArrayL64 emptyArray;
242 const TArrayL64* ptr = &emptyArray; // Make sure we do not return a NULL pointer.
243 if (retval != 0x0) ptr = reinterpret_cast<const TArrayL64*>(retval);
248 void AliHLTGlobalTriggerWrapper::SetCounters(const TArrayL64& counters)
250 // Fills the internal counter array with new values.
255 const void* fCounters;
257 params.fCounters = &counters;
258 fSetCountersCall.SetParamPtrs(¶ms, 1);
259 gCINTErrorMessage = "";
260 fSetCountersCall.Execute(fObject);
261 if (gCINTErrorMessage != "")
264 HLTError(gCINTErrorMessage.Data());
265 HLTFatal("Error interpreting the code for class '%s' at line %d.", fClass->GetName(), G__lasterror_linenum());
270 bool AliHLTGlobalTriggerWrapper::IsValid() const
272 // Checks if the wrapper class was initialised correctly.
274 return fClass != NULL and fObject != NULL and fFillFromMenuCall.IsValid()
275 and fNewEventCall.IsValid() and fAddCall.IsValid()
276 and fCalculateTriggerDecisionCall.IsValid();