]> git.uio.no Git - u/mrichter/AliRoot.git/blob - HLT/BASE/AliHLTGlobalTriggerDecision.cxx
- something went wrong with previous commit...
[u/mrichter/AliRoot.git] / HLT / BASE / AliHLTGlobalTriggerDecision.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   AliHLTGlobalTriggerDecision.cxx
19 /// @author Artur Szostak <artursz@iafrica.com>
20 /// @date   26 Nov 2008
21 /// @brief  Implementation of the AliHLTGlobalTriggerDecision class.
22 /// 
23 /// The global trigger decision class stores the global HLT decision.
24
25 #include "AliHLTGlobalTriggerDecision.h"
26 #include "Riostream.h"
27 #include "TClass.h"
28 #include "AliHLTMisc.h"
29 #include <cassert>
30
31 ClassImp(AliHLTGlobalTriggerDecision)
32
33
34 AliHLTGlobalTriggerDecision::AliHLTGlobalTriggerDecision() :
35 AliHLTTriggerDecision(0, "HLTGlobalTrigger"),
36   fContributingTriggers(AliHLTTriggerDecision::Class()),
37   fInputObjects(),
38   fCounters()
39 {
40   // Default constructor.
41   
42   // We set the ownership to false since the objects are deleted manually by this
43   // class in DeleteInputObjects().
44   fInputObjects.SetOwner(kFALSE);
45 }
46
47
48 AliHLTGlobalTriggerDecision::AliHLTGlobalTriggerDecision(
49     bool result, const AliHLTTriggerDomain& triggerDomain, const char* description
50   ) :
51   AliHLTTriggerDecision(result, "HLTGlobalTrigger", triggerDomain, description),
52   fContributingTriggers(AliHLTTriggerDecision::Class()),
53   fInputObjects(),
54   fCounters()
55 {
56   // Constructor specifying multiple information fields.
57   
58   Result(result);
59   // We set the ownership to false since the objects are deleted manually by this
60   // class in DeleteInputObjects().
61   fInputObjects.SetOwner(kFALSE);
62 }
63
64
65 AliHLTGlobalTriggerDecision::~AliHLTGlobalTriggerDecision()
66 {
67   // Default destructor.
68   
69   DeleteInputObjects();
70 }
71
72
73 void AliHLTGlobalTriggerDecision::Print(Option_t* option) const
74 {
75   // Prints the contents of the trigger decision.
76   
77   TString opt(option);
78   if (opt.Contains("compact"))
79   {
80     cout << "Global ";
81     AliHLTTriggerDecision::Print("");
82   }
83   else if (opt.Contains("short"))
84   {
85     cout << "Global ";
86     AliHLTTriggerDecision::Print(option);
87     cout << "#################### Input trigger decisions ####################" << endl;
88     for (Int_t i = 0; i < NumberOfTriggerInputs(); i++)
89     {
90       assert(TriggerInput(i) != NULL);
91       TriggerInput(i)->Print(option);
92     }
93     if (NumberOfTriggerInputs() == 0)
94     {
95       cout << "(none)" << endl;
96     }
97   }
98   else if (opt.Contains("counters"))
99   {
100     cout << "Counter\tValue" << endl;
101     for (Int_t i = 0; i < fCounters.GetSize(); i++)
102     {
103       cout << i << "\t" << fCounters[i] << endl;
104     }
105     if (fCounters.GetSize() == 0)
106     {
107       cout << "(none)" << endl;
108     }
109   }
110   else
111   {
112     cout << "Global ";
113     AliHLTTriggerDecision::Print(option);
114     cout << "#################### Input trigger decisions ####################" << endl;
115     for (Int_t i = 0; i < NumberOfTriggerInputs(); i++)
116     {
117       cout << "-------------------- Input trigger decision " << i << " --------------------" << endl;
118       assert(TriggerInput(i) != NULL);
119       TriggerInput(i)->Print(option);
120     }
121     if (NumberOfTriggerInputs() == 0)
122     {
123       cout << "(none)" << endl;
124     }
125     cout << "###################### Other input objects ######################" << endl;
126     for (Int_t i = 0; i < NumberOfInputObjects(); i++)
127     {
128       cout << "------------------------ Input object " << i << " ------------------------" << endl;
129       assert(InputObject(i) != NULL);
130       InputObject(i)->Print(option);
131     }
132     if (NumberOfInputObjects() == 0)
133     {
134       cout << "(none)" << endl;
135     }
136     cout << "#################### Event class counters ####################" << endl;
137     cout << "Counter\tValue" << endl;
138     for (Int_t i = 0; i < fCounters.GetSize(); i++)
139     {
140       cout << i << "\t" << fCounters[i] << endl;
141     }
142     if (fCounters.GetSize() == 0)
143     {
144       cout << "(none)" << endl;
145     }
146   }
147 }
148
149 void AliHLTGlobalTriggerDecision::Copy(TObject &object) const
150 {
151   // copy this to the specified object
152
153   if (object.IsA() == AliHLTMisc::Instance().IsAliESDHLTDecision()) {
154     AliHLTMisc::Instance().Copy(this, &object);
155     return;
156   }
157
158   AliHLTGlobalTriggerDecision* pDecision=dynamic_cast<AliHLTGlobalTriggerDecision*>(&object);
159   if (pDecision)
160   {
161     // copy members if target is a AliHLTGlobalTriggerDecision
162     *pDecision=*this;
163   }
164   // copy the base class
165   AliHLTTriggerDecision::Copy(object);
166 }
167
168 TObject *AliHLTGlobalTriggerDecision::Clone(const char */*newname*/) const
169 {
170   // create a new clone, classname is ignored
171
172   return new AliHLTGlobalTriggerDecision(*this);
173 }
174
175 AliHLTGlobalTriggerDecision::AliHLTGlobalTriggerDecision(const AliHLTGlobalTriggerDecision& src) :
176   AliHLTTriggerDecision(src),
177   fContributingTriggers(AliHLTTriggerDecision::Class()),
178   fInputObjects(),
179   fCounters()
180 {
181   // Copy constructor performs a deep copy.
182   
183   // We set the ownership to false since the objects are deleted manually by this
184   // class in DeleteInputObjects().
185   fInputObjects.SetOwner(kFALSE);
186   
187   *this=src;
188 }
189
190 AliHLTGlobalTriggerDecision& AliHLTGlobalTriggerDecision::operator=(const AliHLTGlobalTriggerDecision& src)
191 {
192   // assignment operator performs a deep copy.
193
194   fContributingTriggers.Delete();
195   for (int triggerInput=0; triggerInput<src.NumberOfTriggerInputs(); triggerInput++) {
196     const AliHLTTriggerDecision* pTriggerObject=src.TriggerInput(triggerInput);
197     assert(pTriggerObject != NULL);
198     // the AddTriggerInput function uses the copy constructor and
199     // makes a new object from the reference
200     AddTriggerInput(*pTriggerObject);
201   }
202
203   DeleteInputObjects();
204   for (int inputObject=0; inputObject<src.NumberOfTriggerInputs(); inputObject++) {
205     const TObject* pInputObject=src.InputObject(inputObject);
206     assert(pInputObject != NULL);
207     // the AddInputObject function uses Clone() and
208     // makes a new object from the reference
209     AddInputObject(pInputObject);
210   }
211   
212   SetCounters(src.Counters());
213
214   return *this;
215 }
216
217
218 void AliHLTGlobalTriggerDecision::AddInputObject(const TObject* object)
219 {
220   // Adds an object to the list of input objects considered in the global trigger.
221   
222   if (object == NULL) return;
223   TObject* obj = object->Clone();
224   obj->SetBit(kCanDelete);
225   fInputObjects.Add(obj);
226 }
227
228
229 void AliHLTGlobalTriggerDecision::AddInputObjectRef(TObject* object, bool own)
230 {
231   // Adds an object to the list of input objects considered in the global trigger.
232   
233   if (object == NULL) return;
234   if (own)
235   {
236     object->SetBit(kCanDelete);
237   }
238   else
239   {
240     object->ResetBit(kCanDelete);
241   }
242   fInputObjects.Add(object);
243 }
244
245
246 void AliHLTGlobalTriggerDecision::SetCounters(const TArrayL64& counters, Long64_t eventCount)
247 {
248   // Sets the counter array.
249   // If the number of events is specified, an additional counter is added at the end.
250   fCounters = counters;
251   if (eventCount>=0) {
252     int size=fCounters.GetSize();
253     fCounters.Set(size+1);
254     fCounters[size]=eventCount;
255   }
256 }
257
258
259 void AliHLTGlobalTriggerDecision::Clear(Option_t* option)
260 {
261   // Clears the trigger domain and resets the decision result.
262   
263   AliHLTTriggerDecision::Clear(option);
264   fContributingTriggers.Clear(option);
265   DeleteInputObjects();
266   fCounters.Set(0);
267 }
268
269
270 void AliHLTGlobalTriggerDecision::DeleteInputObjects()
271 {
272   // Deletes the objects marked with kCanDelete in fInputObjects and clears the array.
273   
274   for (Int_t i = 0; i < NumberOfInputObjects(); i++)
275   {
276     TObject* obj = fInputObjects.UncheckedAt(i);
277     assert(obj != NULL);
278     if (obj->TestBit(kCanDelete)) delete obj;
279   }
280   fInputObjects.Clear();
281 }
282
283
284 void AliHLTGlobalTriggerDecision::Streamer(TBuffer &b)
285 {
286    // Stream an object of class AliHLTGlobalTriggerDecision.
287
288    if (b.IsReading())
289    {
290      b.ReadClassBuffer(AliHLTGlobalTriggerDecision::Class(), this);
291      // We must mark all the objects that were read into fInputObjects as owned.
292      // Otherwise we will have a memory leak in DeleteInputObjects.
293      for (Int_t i = 0; i < fInputObjects.GetEntriesFast(); i++)
294      {
295        TObject* obj = fInputObjects.UncheckedAt(i);
296        assert(obj != NULL);
297        obj->SetBit(kCanDelete);
298      }
299    }
300    else
301    {
302      b.WriteClassBuffer(AliHLTGlobalTriggerDecision::Class(), this);
303    }
304 }