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)
42 AliHLTGlobalTriggerWrapper::AliHLTGlobalTriggerWrapper(const char* classname) :
43 AliHLTGlobalTrigger(),
50 fCalculateTriggerDecisionCall(),
54 // The default constructor.
56 fClass = TClass::GetClass(classname);
59 HLTError("Could not find class information for '%s'.", classname);
62 fFillFromMenuCall.InitWithPrototype(fClass, "FillFromMenu", "const AliHLTTriggerMenu&");
63 if (not fFillFromMenuCall.IsValid())
65 HLTError("Could not initialise method call object for class '%s' and method FillFromMenu.", classname);
68 fNewEventCall.InitWithPrototype(fClass, "NewEvent", " "); // Must have single whitespace in last parameter or we get a segfault in G__interpret_func.
69 if (not fNewEventCall.IsValid())
71 HLTError("Could not initialise method call object for class '%s' and method NewEvent.", classname);
74 fAddCall.InitWithPrototype(fClass, "Add", "const TObject*, const AliHLTComponentDataType&, AliHLTUInt32_t");
75 if (not fAddCall.IsValid())
77 HLTError("Could not initialise method call object for class '%s' and method Add.", classname);
80 fCalculateTriggerDecisionCall.InitWithPrototype(fClass, "CalculateTriggerDecision", "AliHLTTriggerDomain&, TString&");
81 if (not fCalculateTriggerDecisionCall.IsValid())
83 HLTError("Could not initialise method call object for class '%s' and method CalculateTriggerDecision.", classname);
86 fGetCountersCall.InitWithPrototype(fClass, "GetCounters", " "); // Must have single whitespace in last parameter or we get a segfault in G__interpret_func.
87 if (not fGetCountersCall.IsValid())
89 HLTError("Could not initialise method call object for class '%s' and method GetCounters.", classname);
92 fSetCountersCall.InitWithPrototype(fClass, "SetCounters", "TArrayL64&");
93 if (not fSetCountersCall.IsValid())
95 HLTError("Could not initialise method call object for class '%s' and method SetCounters.", classname);
98 fObject = fClass->New();
101 HLTError("Could not create a new object of type '%s'.", classname);
106 AliHLTGlobalTriggerWrapper::~AliHLTGlobalTriggerWrapper()
108 // Default destructor.
110 fClass->Destructor(fObject);
114 void AliHLTGlobalTriggerWrapper::FillFromMenu(const AliHLTTriggerMenu& menu)
116 // Fills internal values from the trigger menu.
122 params.fMenu = &menu;
123 fFillFromMenuCall.SetParamPtrs(¶ms, 1);
124 fFillFromMenuCall.Execute(fObject);
125 int error = G__lasterror();
126 if (error != TInterpreter::kNoError)
128 if (error == TInterpreter::kFatal)
130 HLTFatal("Error interpreting the code for class '%s' at line %d.", fClass->GetName(), G__lasterror_linenum());
134 HLTError("Error interpreting the code for class '%s' at line %d.", fClass->GetName(), G__lasterror_linenum());
140 void AliHLTGlobalTriggerWrapper::NewEvent()
142 // Clears the internal buffers for a new event.
144 fNewEventCall.Execute(fObject);
145 int error = G__lasterror();
146 if (error != TInterpreter::kNoError)
148 if (error == TInterpreter::kFatal)
150 HLTFatal("Error interpreting the code for class '%s' at line %d.", fClass->GetName(), G__lasterror_linenum());
154 HLTError("Error interpreting the code for class '%s' at line %d.", fClass->GetName(), G__lasterror_linenum());
160 void AliHLTGlobalTriggerWrapper::Add(
161 const TObject* object, const AliHLTComponentDataType& type,
165 // Adds parameters from the object to the internal buffers and variables.
173 params.fObj = object;
174 params.fType = &type;
176 fAddCall.SetParamPtrs(¶ms, 3);
177 fAddCall.Execute(fObject);
178 int error = G__lasterror();
179 if (error != TInterpreter::kNoError)
181 if (error == TInterpreter::kFatal)
183 HLTFatal("Error interpreting the code for class '%s' at line %d.", fClass->GetName(), G__lasterror_linenum());
187 HLTError("Error interpreting the code for class '%s' at line %d.", fClass->GetName(), G__lasterror_linenum());
193 bool AliHLTGlobalTriggerWrapper::CalculateTriggerDecision(AliHLTTriggerDomain& domain, TString& description)
195 // Calculates the global trigger decision.
202 params.fDomain = &domain;
203 params.fDesc = &description;
204 fCalculateTriggerDecisionCall.SetParamPtrs(¶ms, 2);
206 fCalculateTriggerDecisionCall.Execute(fObject, retval);
207 int error = G__lasterror();
208 if (error != TInterpreter::kNoError)
210 if (error == TInterpreter::kFatal)
212 HLTFatal("Error interpreting the code for class '%s' at line %d.", fClass->GetName(), G__lasterror_linenum());
216 HLTError("Error interpreting the code for class '%s' at line %d.", fClass->GetName(), G__lasterror_linenum());
223 const TArrayL64& AliHLTGlobalTriggerWrapper::GetCounters() const
225 // Returns the internal counter array.
228 fGetCountersCall.Execute(fObject, retval);
229 int error = G__lasterror();
230 if (error != TInterpreter::kNoError)
232 if (error == TInterpreter::kFatal)
234 HLTFatal("Error interpreting the code for class '%s' at line %d.", fClass->GetName(), G__lasterror_linenum());
238 HLTError("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.
254 const void* fCounters;
256 params.fCounters = &counters;
257 fSetCountersCall.SetParamPtrs(¶ms, 1);
258 fSetCountersCall.Execute(fObject);
259 int error = G__lasterror();
260 if (error != TInterpreter::kNoError)
262 if (error == TInterpreter::kFatal)
264 HLTFatal("Error interpreting the code for class '%s' at line %d.", fClass->GetName(), G__lasterror_linenum());
268 HLTError("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();