]> git.uio.no Git - u/mrichter/AliRoot.git/blob - HLT/trigger/AliHLTGlobalTriggerWrapper.cxx
* Adding explicit priority settings for the global trigger menu items.
[u/mrichter/AliRoot.git] / HLT / trigger / AliHLTGlobalTriggerWrapper.cxx
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
39 ClassImp(AliHLTGlobalTriggerWrapper)
40
41
42 AliHLTGlobalTriggerWrapper::AliHLTGlobalTriggerWrapper(const char* classname) :
43   AliHLTGlobalTrigger(),
44   AliHLTLogging(),
45   fClass(NULL),
46   fObject(NULL),
47   fFillFromMenuCall(),
48   fNewEventCall(),
49   fAddCall(),
50   fCalculateTriggerDecisionCall(),
51   fGetCountersCall(),
52   fSetCountersCall()
53 {
54   // The default constructor.
55   
56   fClass = TClass::GetClass(classname);
57   if (fClass == NULL)
58   {
59     HLTError("Could not find class information for '%s'.", classname);
60     return;
61   }
62   fFillFromMenuCall.InitWithPrototype(fClass, "FillFromMenu", "const AliHLTTriggerMenu&");
63   if (not fFillFromMenuCall.IsValid())
64   {
65     HLTError("Could not initialise method call object for class '%s' and method FillFromMenu.", classname);
66     return;
67   }
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())
70   {
71     HLTError("Could not initialise method call object for class '%s' and method NewEvent.", classname);
72     return;
73   }
74   fAddCall.InitWithPrototype(fClass, "Add", "const TObject*, const AliHLTComponentDataType&, AliHLTUInt32_t");
75   if (not fAddCall.IsValid())
76   {
77     HLTError("Could not initialise method call object for class '%s' and method Add.", classname);
78     return;
79   }
80   fCalculateTriggerDecisionCall.InitWithPrototype(fClass, "CalculateTriggerDecision", "AliHLTTriggerDomain&, TString&");
81   if (not fCalculateTriggerDecisionCall.IsValid())
82   {
83     HLTError("Could not initialise method call object for class '%s' and method CalculateTriggerDecision.", classname);
84     return;
85   }
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())
88   {
89     HLTError("Could not initialise method call object for class '%s' and method GetCounters.", classname);
90     return;
91   }
92   fSetCountersCall.InitWithPrototype(fClass, "SetCounters", "TArrayL64&");
93   if (not fSetCountersCall.IsValid())
94   {
95     HLTError("Could not initialise method call object for class '%s' and method SetCounters.", classname);
96     return;
97   }
98   fObject = fClass->New();
99   if (fObject == NULL)
100   {
101     HLTError("Could not create a new object of type '%s'.", classname);
102   }
103 }
104
105
106 AliHLTGlobalTriggerWrapper::~AliHLTGlobalTriggerWrapper()
107 {
108   // Default destructor.
109   
110   fClass->Destructor(fObject);
111 }
112
113
114 void AliHLTGlobalTriggerWrapper::FillFromMenu(const AliHLTTriggerMenu& menu)
115 {
116   // Fills internal values from the trigger menu.
117   
118   struct Params
119   {
120     const void* fMenu;
121   } params;
122   params.fMenu = &menu;
123   fFillFromMenuCall.SetParamPtrs(&params, 1);
124   fFillFromMenuCall.Execute(fObject);
125   int error = G__lasterror();
126   if (error != TInterpreter::kNoError)
127   {
128     if (error == TInterpreter::kFatal)
129     {
130       HLTFatal("Error interpreting the code for class '%s' at line %d.", fClass->GetName(), G__lasterror_linenum());
131     }
132     else
133     {
134       HLTError("Error interpreting the code for class '%s' at line %d.", fClass->GetName(), G__lasterror_linenum());
135     }
136   }
137 }
138
139
140 void AliHLTGlobalTriggerWrapper::NewEvent()
141 {
142   // Clears the internal buffers for a new event.
143
144   fNewEventCall.Execute(fObject);
145   int error = G__lasterror();
146   if (error != TInterpreter::kNoError)
147   {
148     if (error == TInterpreter::kFatal)
149     {
150       HLTFatal("Error interpreting the code for class '%s' at line %d.", fClass->GetName(), G__lasterror_linenum());
151     }
152     else
153     {
154       HLTError("Error interpreting the code for class '%s' at line %d.", fClass->GetName(), G__lasterror_linenum());
155     }
156   }
157 }
158
159
160 void AliHLTGlobalTriggerWrapper::Add(
161       const TObject* object, const AliHLTComponentDataType& type,
162       AliHLTUInt32_t spec
163     )
164 {
165   // Adds parameters from the object to the internal buffers and variables.
166   
167   struct Params
168   {
169     const void* fObj;
170     const void* fType;
171     long fSpec;
172   } params;
173   params.fObj = object;
174   params.fType = &type;
175   params.fSpec = spec;
176   fAddCall.SetParamPtrs(&params, 3);
177   fAddCall.Execute(fObject);
178   int error = G__lasterror();
179   if (error != TInterpreter::kNoError)
180   {
181     if (error == TInterpreter::kFatal)
182     {
183       HLTFatal("Error interpreting the code for class '%s' at line %d.", fClass->GetName(), G__lasterror_linenum());
184     }
185     else
186     {
187       HLTError("Error interpreting the code for class '%s' at line %d.", fClass->GetName(), G__lasterror_linenum());
188     }
189   }
190 }
191
192
193 bool AliHLTGlobalTriggerWrapper::CalculateTriggerDecision(AliHLTTriggerDomain& domain, TString& description)
194 {
195   // Calculates the global trigger decision.
196
197   struct Params
198   {
199     const void* fDomain;
200     const void* fDesc;
201   } params;
202   params.fDomain = &domain;
203   params.fDesc = &description;
204   fCalculateTriggerDecisionCall.SetParamPtrs(&params, 2);
205   Long_t retval;
206   fCalculateTriggerDecisionCall.Execute(fObject, retval);
207   int error = G__lasterror();
208   if (error != TInterpreter::kNoError)
209   {
210     if (error == TInterpreter::kFatal)
211     {
212       HLTFatal("Error interpreting the code for class '%s' at line %d.", fClass->GetName(), G__lasterror_linenum());
213     }
214     else
215     {
216       HLTError("Error interpreting the code for class '%s' at line %d.", fClass->GetName(), G__lasterror_linenum());
217     }
218   }
219   return bool(retval);
220 }
221
222
223 const TArrayL64& AliHLTGlobalTriggerWrapper::GetCounters() const
224 {
225   // Returns the internal counter array.
226
227   Long_t retval = 0x0;
228   fGetCountersCall.Execute(fObject, retval);
229   int error = G__lasterror();
230   if (error != TInterpreter::kNoError)
231   {
232     if (error == TInterpreter::kFatal)
233     {
234       HLTFatal("Error interpreting the code for class '%s' at line %d.", fClass->GetName(), G__lasterror_linenum());
235     }
236     else
237     {
238       HLTError("Error interpreting the code for class '%s' at line %d.", fClass->GetName(), G__lasterror_linenum());
239     }
240   }
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);
244   return *ptr;
245 }
246
247
248 void AliHLTGlobalTriggerWrapper::SetCounters(const TArrayL64& counters)
249 {
250   // Fills the internal counter array with new values.
251   
252   struct Params
253   {
254     const void* fCounters;
255   } params;
256   params.fCounters = &counters;
257   fSetCountersCall.SetParamPtrs(&params, 1);
258   fSetCountersCall.Execute(fObject);
259   int error = G__lasterror();
260   if (error != TInterpreter::kNoError)
261   {
262     if (error == TInterpreter::kFatal)
263     {
264       HLTFatal("Error interpreting the code for class '%s' at line %d.", fClass->GetName(), G__lasterror_linenum());
265     }
266     else
267     {
268       HLTError("Error interpreting the code for class '%s' at line %d.", fClass->GetName(), G__lasterror_linenum());
269     }
270   }
271 }
272
273
274 bool 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