small corrections
[u/mrichter/AliRoot.git] / HLT / trigger / AliHLTGlobalTriggerWrapper.cxx
CommitLineData
81d62bb4 1// $Id: $
2/**************************************************************************
3 * This file is property of and copyright by the ALICE HLT Project *
4 * ALICE Experiment at CERN, All rights reserved. *
5 * *
6 * Primary Authors: Artur Szostak <artursz@iafrica.com> *
7 * for The ALICE HLT Project. *
8 * *
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 **************************************************************************/
17
18/// @file AliHLTGlobalTriggerWrapper.cxx
19/// @author Artur Szostak <artursz@iafrica.com>
20/// @date 28 Oct 2009
21/// @brief Implementation of the AliHLTGlobalTriggerWrapper interface class.
22///
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.
27
28#include "AliHLTGlobalTriggerWrapper.h"
29#include "TArrayL64.h"
30#include "TClass.h"
31#include "TInterpreter.h"
32
33#ifdef R__BUILDING_CINT7
34#include "cint7/Api.h"
35#else
36#include "Api.h"
37#endif
38
39ClassImp(AliHLTGlobalTriggerWrapper)
40
41
325e5e42 42namespace
43{
44 /// Variable to store the error message if an error occured in CINT when interpreting code.
45 TString gCINTErrorMessage = "";
46
47 /**
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.
50 */
51 void AliHLTOnErrorInCINT(char* message)
52 {
53 gCINTErrorMessage += message;
54 }
55
56} // end of namespace
57
58
81d62bb4 59AliHLTGlobalTriggerWrapper::AliHLTGlobalTriggerWrapper(const char* classname) :
60 AliHLTGlobalTrigger(),
61 AliHLTLogging(),
62 fClass(NULL),
63 fObject(NULL),
64 fFillFromMenuCall(),
65 fNewEventCall(),
66 fAddCall(),
67 fCalculateTriggerDecisionCall(),
68 fGetCountersCall(),
325e5e42 69 fSetCountersCall(),
70 fCallFailed(false)
81d62bb4 71{
72 // The default constructor.
73
74 fClass = TClass::GetClass(classname);
75 if (fClass == NULL)
76 {
77 HLTError("Could not find class information for '%s'.", classname);
78 return;
79 }
80 fFillFromMenuCall.InitWithPrototype(fClass, "FillFromMenu", "const AliHLTTriggerMenu&");
81 if (not fFillFromMenuCall.IsValid())
82 {
83 HLTError("Could not initialise method call object for class '%s' and method FillFromMenu.", classname);
84 return;
85 }
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())
88 {
89 HLTError("Could not initialise method call object for class '%s' and method NewEvent.", classname);
90 return;
91 }
92 fAddCall.InitWithPrototype(fClass, "Add", "const TObject*, const AliHLTComponentDataType&, AliHLTUInt32_t");
93 if (not fAddCall.IsValid())
94 {
95 HLTError("Could not initialise method call object for class '%s' and method Add.", classname);
96 return;
97 }
98 fCalculateTriggerDecisionCall.InitWithPrototype(fClass, "CalculateTriggerDecision", "AliHLTTriggerDomain&, TString&");
99 if (not fCalculateTriggerDecisionCall.IsValid())
100 {
101 HLTError("Could not initialise method call object for class '%s' and method CalculateTriggerDecision.", classname);
102 return;
103 }
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())
106 {
107 HLTError("Could not initialise method call object for class '%s' and method GetCounters.", classname);
108 return;
109 }
110 fSetCountersCall.InitWithPrototype(fClass, "SetCounters", "TArrayL64&");
111 if (not fSetCountersCall.IsValid())
112 {
113 HLTError("Could not initialise method call object for class '%s' and method SetCounters.", classname);
114 return;
115 }
116 fObject = fClass->New();
117 if (fObject == NULL)
118 {
119 HLTError("Could not create a new object of type '%s'.", classname);
120 }
325e5e42 121
08ec385d 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));
81d62bb4 127}
128
129
130AliHLTGlobalTriggerWrapper::~AliHLTGlobalTriggerWrapper()
131{
132 // Default destructor.
133
134 fClass->Destructor(fObject);
135}
136
137
138void AliHLTGlobalTriggerWrapper::FillFromMenu(const AliHLTTriggerMenu& menu)
139{
140 // Fills internal values from the trigger menu.
141
325e5e42 142 fCallFailed = false;
81d62bb4 143 struct Params
144 {
145 const void* fMenu;
146 } params;
147 params.fMenu = &menu;
148 fFillFromMenuCall.SetParamPtrs(&params, 1);
325e5e42 149 gCINTErrorMessage = "";
81d62bb4 150 fFillFromMenuCall.Execute(fObject);
325e5e42 151 if (gCINTErrorMessage != "")
81d62bb4 152 {
325e5e42 153 fCallFailed = true;
154 HLTError(gCINTErrorMessage.Data());
155 HLTFatal("Error interpreting the code for class '%s' at line %d.", fClass->GetName(), G__lasterror_linenum());
81d62bb4 156 }
157}
158
159
160void AliHLTGlobalTriggerWrapper::NewEvent()
161{
162 // Clears the internal buffers for a new event.
163
325e5e42 164 fCallFailed = false;
165 gCINTErrorMessage = "";
81d62bb4 166 fNewEventCall.Execute(fObject);
325e5e42 167 if (gCINTErrorMessage != "")
81d62bb4 168 {
325e5e42 169 fCallFailed = true;
170 HLTError(gCINTErrorMessage.Data());
171 HLTFatal("Error interpreting the code for class '%s' at line %d.", fClass->GetName(), G__lasterror_linenum());
81d62bb4 172 }
173}
174
175
176void AliHLTGlobalTriggerWrapper::Add(
177 const TObject* object, const AliHLTComponentDataType& type,
178 AliHLTUInt32_t spec
179 )
180{
181 // Adds parameters from the object to the internal buffers and variables.
182
325e5e42 183 fCallFailed = false;
81d62bb4 184 struct Params
185 {
186 const void* fObj;
187 const void* fType;
188 long fSpec;
189 } params;
190 params.fObj = object;
191 params.fType = &type;
192 params.fSpec = spec;
193 fAddCall.SetParamPtrs(&params, 3);
325e5e42 194 gCINTErrorMessage = "";
81d62bb4 195 fAddCall.Execute(fObject);
325e5e42 196 if (gCINTErrorMessage != "")
81d62bb4 197 {
325e5e42 198 fCallFailed = true;
199 HLTError(gCINTErrorMessage.Data());
200 HLTFatal("Error interpreting the code for class '%s' at line %d.", fClass->GetName(), G__lasterror_linenum());
81d62bb4 201 }
202}
203
204
205bool AliHLTGlobalTriggerWrapper::CalculateTriggerDecision(AliHLTTriggerDomain& domain, TString& description)
206{
207 // Calculates the global trigger decision.
208
325e5e42 209 fCallFailed = false;
81d62bb4 210 struct Params
211 {
212 const void* fDomain;
213 const void* fDesc;
214 } params;
215 params.fDomain = &domain;
216 params.fDesc = &description;
217 fCalculateTriggerDecisionCall.SetParamPtrs(&params, 2);
218 Long_t retval;
325e5e42 219 gCINTErrorMessage = "";
81d62bb4 220 fCalculateTriggerDecisionCall.Execute(fObject, retval);
325e5e42 221 if (gCINTErrorMessage != "")
81d62bb4 222 {
325e5e42 223 fCallFailed = true;
224 HLTError(gCINTErrorMessage.Data());
225 HLTFatal("Error interpreting the code for class '%s' at line %d.", fClass->GetName(), G__lasterror_linenum());
226 return false;
81d62bb4 227 }
228 return bool(retval);
229}
230
231
232const TArrayL64& AliHLTGlobalTriggerWrapper::GetCounters() const
233{
234 // Returns the internal counter array.
235
236 Long_t retval = 0x0;
325e5e42 237 gCINTErrorMessage = "";
81d62bb4 238 fGetCountersCall.Execute(fObject, retval);
325e5e42 239 if (gCINTErrorMessage != "")
81d62bb4 240 {
325e5e42 241 fCallFailed = true;
242 HLTError(gCINTErrorMessage.Data());
243 HLTFatal("Error interpreting the code for class '%s' at line %d.", fClass->GetName(), G__lasterror_linenum());
81d62bb4 244 }
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);
248 return *ptr;
249}
250
251
252void AliHLTGlobalTriggerWrapper::SetCounters(const TArrayL64& counters)
253{
254 // Fills the internal counter array with new values.
255
325e5e42 256 fCallFailed = false;
81d62bb4 257 struct Params
258 {
259 const void* fCounters;
260 } params;
261 params.fCounters = &counters;
262 fSetCountersCall.SetParamPtrs(&params, 1);
325e5e42 263 gCINTErrorMessage = "";
81d62bb4 264 fSetCountersCall.Execute(fObject);
325e5e42 265 if (gCINTErrorMessage != "")
81d62bb4 266 {
325e5e42 267 fCallFailed = true;
268 HLTError(gCINTErrorMessage.Data());
269 HLTFatal("Error interpreting the code for class '%s' at line %d.", fClass->GetName(), G__lasterror_linenum());
81d62bb4 270 }
271}
272
273
274bool AliHLTGlobalTriggerWrapper::IsValid() const
275{
276 // Checks if the wrapper class was initialised correctly.
277
278 return fClass != NULL and fObject != NULL and fFillFromMenuCall.IsValid()
279 and fNewEventCall.IsValid() and fAddCall.IsValid()
280 and fCalculateTriggerDecisionCall.IsValid();
281}
282