]> git.uio.no Git - u/mrichter/AliRoot.git/blob - HLT/BASE/AliHLTGlobalTriggerDecision.cxx
Bug fix for potencial memory leak.
[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
30 ClassImp(AliHLTGlobalTriggerDecision)
31
32
33 AliHLTGlobalTriggerDecision::AliHLTGlobalTriggerDecision() :
34   AliHLTTriggerDecision(0, "HLTGlobalTrigger"),
35   fContributingTriggers(AliHLTTriggerDecision::Class()),
36   fInputObjects(),
37   fCounters()
38 {
39   // Default constructor.
40   
41   fInputObjects.SetOwner(kTRUE);
42 }
43
44
45 AliHLTGlobalTriggerDecision::AliHLTGlobalTriggerDecision(
46     bool result, const AliHLTTriggerDomain& triggerDomain, const char* description
47   ) :
48   AliHLTTriggerDecision(result, "HLTGlobalTrigger", triggerDomain, description),
49   fContributingTriggers(AliHLTTriggerDecision::Class()),
50   fInputObjects(),
51   fCounters()
52 {
53   // Constructor specifying multiple information fields.
54   
55   Result(result);
56   fInputObjects.SetOwner(kTRUE);
57 }
58
59
60 AliHLTGlobalTriggerDecision::~AliHLTGlobalTriggerDecision()
61 {
62   // Default destructor.
63 }
64
65
66 void AliHLTGlobalTriggerDecision::Print(Option_t* option) const
67 {
68   // Prints the contents of the trigger decision.
69   
70   TString opt(option);
71   if (opt.Contains("compact"))
72   {
73     cout << "Global ";
74     AliHLTTriggerDecision::Print("");
75   }
76   else if (opt.Contains("short"))
77   {
78     cout << "Global ";
79     AliHLTTriggerDecision::Print(option);
80     cout << "#################### Input trigger decisions ####################" << endl;
81     for (Int_t i = 0; i < NumberOfTriggerInputs(); i++)
82     {
83       if (TriggerInput(i)) TriggerInput(i)->Print(option);
84     }
85     if (NumberOfTriggerInputs() == 0)
86     {
87       cout << "(none)" << endl;
88     }
89   }
90   else if (opt.Contains("counters"))
91   {
92     cout << "Counter\tValue" << endl;
93     for (Int_t i = 0; i < fCounters.GetSize(); i++)
94     {
95       cout << i << "\t" << fCounters[i] << endl;
96     }
97     if (fCounters.GetSize() == 0)
98     {
99       cout << "(none)" << endl;
100     }
101   }
102   else
103   {
104     cout << "Global ";
105     AliHLTTriggerDecision::Print(option);
106     cout << "#################### Input trigger decisions ####################" << endl;
107     for (Int_t i = 0; i < NumberOfTriggerInputs(); i++)
108     {
109       cout << "-------------------- Input trigger decision " << i << " --------------------" << endl;
110       if (TriggerInput(i)) TriggerInput(i)->Print(option);
111     }
112     if (NumberOfTriggerInputs() == 0)
113     {
114       cout << "(none)" << endl;
115     }
116     cout << "###################### Other input objects ######################" << endl;
117     for (Int_t i = 0; i < NumberOfInputObjects(); i++)
118     {
119       cout << "------------------------ Input object " << i << " ------------------------" << endl;
120       if (InputObject(i)) InputObject(i)->Print(option);
121     }
122     if (NumberOfInputObjects() == 0)
123     {
124       cout << "(none)" << endl;
125     }
126     cout << "#################### Event class counters ####################" << endl;
127     cout << "Counter\tValue" << endl;
128     for (Int_t i = 0; i < fCounters.GetSize(); i++)
129     {
130       cout << i << "\t" << fCounters[i] << endl;
131     }
132     if (fCounters.GetSize() == 0)
133     {
134       cout << "(none)" << endl;
135     }
136   }
137 }
138
139 void AliHLTGlobalTriggerDecision::Copy(TObject &object) const
140 {
141   // copy this to the specified object
142
143   if (object.IsA() == AliHLTMisc::Instance().IsAliESDHLTDecision()) {
144     AliHLTMisc::Instance().Copy(this, &object);
145     return;
146   }
147
148   AliHLTGlobalTriggerDecision* pDecision=dynamic_cast<AliHLTGlobalTriggerDecision*>(&object);
149   if (pDecision)
150   {
151     // copy members if target is a AliHLTGlobalTriggerDecision
152     *pDecision=*this;
153   }
154   // copy the base class
155   AliHLTTriggerDecision::Copy(object);
156 }
157
158 TObject *AliHLTGlobalTriggerDecision::Clone(const char */*newname*/) const
159 {
160   // create a new clone, classname is ignored
161
162   return new AliHLTGlobalTriggerDecision(*this);
163 }
164
165 AliHLTGlobalTriggerDecision::AliHLTGlobalTriggerDecision(const AliHLTGlobalTriggerDecision& src) :
166   AliHLTTriggerDecision(src),
167   fContributingTriggers(AliHLTTriggerDecision::Class()),
168   fInputObjects(),
169   fCounters()
170 {
171   // copy constructor
172   fInputObjects.SetOwner(kTRUE);
173   *this=src;
174 }
175
176 AliHLTGlobalTriggerDecision& AliHLTGlobalTriggerDecision::operator=(const AliHLTGlobalTriggerDecision& src)
177 {
178   // assignment operator
179
180   fContributingTriggers.Delete();
181   for (int triggerInput=0; triggerInput<src.NumberOfTriggerInputs(); triggerInput++) {
182     const AliHLTTriggerDecision* pTriggerObject=src.TriggerInput(triggerInput);
183     if (pTriggerObject) {
184       // the AddTriggerInput function uses the copy constructor and
185       // makes a new object from the reference
186       AddTriggerInput(*pTriggerObject);
187     } else {
188       //Error("failed to get trigger input #%d", triggerInput);
189     }
190   }
191
192   fInputObjects.Delete();
193   for (int inputObject=0; inputObject<src.NumberOfTriggerInputs(); inputObject++) {
194     const TObject* pInputObject=src.InputObject(inputObject);
195     if (pInputObject) {
196       // the AddInputObject function uses Clone() and
197       // makes a new object from the reference
198       AddInputObject(pInputObject);
199     } else {
200       //Error("failed to get trigger input #%d", inputObject);
201     }
202   }
203   
204   SetCounters(src.Counters());
205
206   return *this;
207 }
208
209 void AliHLTGlobalTriggerDecision::SetCounters(const TArrayL64& counters, Long64_t eventCount)
210 {
211   // Sets the counter array.
212   // If the number of events is specified, an additional counter is added at the end.
213   fCounters = counters;
214   if (eventCount>=0) {
215     int size=fCounters.GetSize();
216     fCounters.Set(size+1);
217     fCounters[size]=eventCount;
218   }
219 }