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 AliHLTGlobalTriggerDecision.cxx
19 /// @author Artur Szostak <artursz@iafrica.com>
21 /// @brief Implementation of the AliHLTGlobalTriggerDecision class.
23 /// The global trigger decision class stores the global HLT decision.
25 #include "AliHLTGlobalTriggerDecision.h"
26 #include "Riostream.h"
28 #include "AliHLTMisc.h"
31 ClassImp(AliHLTGlobalTriggerDecision)
34 AliHLTGlobalTriggerDecision::AliHLTGlobalTriggerDecision() :
35 AliHLTTriggerDecision(0, "HLTGlobalTrigger"),
36 fContributingTriggers(AliHLTTriggerDecision::Class()),
40 // Default constructor.
42 // We set the ownership to false since the objects are deleted manually by this
43 // class in DeleteInputObjects().
44 fInputObjects.SetOwner(kFALSE);
48 AliHLTGlobalTriggerDecision::AliHLTGlobalTriggerDecision(
49 bool result, const AliHLTTriggerDomain& triggerDomain, const char* description
51 AliHLTTriggerDecision(result, "HLTGlobalTrigger", triggerDomain, description),
52 fContributingTriggers(AliHLTTriggerDecision::Class()),
56 // Constructor specifying multiple information fields.
59 // We set the ownership to false since the objects are deleted manually by this
60 // class in DeleteInputObjects().
61 fInputObjects.SetOwner(kFALSE);
65 AliHLTGlobalTriggerDecision::~AliHLTGlobalTriggerDecision()
67 // Default destructor.
73 void AliHLTGlobalTriggerDecision::Print(Option_t* option) const
75 // Prints the contents of the trigger decision.
78 if (opt.Contains("compact"))
81 AliHLTTriggerDecision::Print("");
83 else if (opt.Contains("short"))
86 AliHLTTriggerDecision::Print(option);
87 cout << "#################### Input trigger decisions ####################" << endl;
88 for (Int_t i = 0; i < NumberOfTriggerInputs(); i++)
90 assert(TriggerInput(i) != NULL);
91 TriggerInput(i)->Print(option);
93 if (NumberOfTriggerInputs() == 0)
95 cout << "(none)" << endl;
98 else if (opt.Contains("counters"))
100 cout << "Counter\tValue" << endl;
101 for (Int_t i = 0; i < fCounters.GetSize(); i++)
103 cout << i << "\t" << fCounters[i] << endl;
105 if (fCounters.GetSize() == 0)
107 cout << "(none)" << endl;
113 AliHLTTriggerDecision::Print(option);
114 cout << "#################### Input trigger decisions ####################" << endl;
115 for (Int_t i = 0; i < NumberOfTriggerInputs(); i++)
117 cout << "-------------------- Input trigger decision " << i << " --------------------" << endl;
118 assert(TriggerInput(i) != NULL);
119 TriggerInput(i)->Print(option);
121 if (NumberOfTriggerInputs() == 0)
123 cout << "(none)" << endl;
125 cout << "###################### Other input objects ######################" << endl;
126 for (Int_t i = 0; i < NumberOfInputObjects(); i++)
128 cout << "------------------------ Input object " << i << " ------------------------" << endl;
129 assert(InputObject(i) != NULL);
130 InputObject(i)->Print(option);
132 if (NumberOfInputObjects() == 0)
134 cout << "(none)" << endl;
136 cout << "#################### Event class counters ####################" << endl;
137 cout << "Counter\tValue" << endl;
138 for (Int_t i = 0; i < fCounters.GetSize(); i++)
140 cout << i << "\t" << fCounters[i] << endl;
142 if (fCounters.GetSize() == 0)
144 cout << "(none)" << endl;
149 void AliHLTGlobalTriggerDecision::Copy(TObject &object) const
151 // copy this to the specified object
153 if (object.IsA() == AliHLTMisc::Instance().IsAliESDHLTDecision()) {
154 AliHLTMisc::Instance().Copy(this, &object);
158 AliHLTGlobalTriggerDecision* pDecision=dynamic_cast<AliHLTGlobalTriggerDecision*>(&object);
161 // copy members if target is a AliHLTGlobalTriggerDecision
164 // copy the base class
165 AliHLTTriggerDecision::Copy(object);
168 TObject *AliHLTGlobalTriggerDecision::Clone(const char */*newname*/) const
170 // create a new clone, classname is ignored
172 return new AliHLTGlobalTriggerDecision(*this);
175 AliHLTGlobalTriggerDecision::AliHLTGlobalTriggerDecision(const AliHLTGlobalTriggerDecision& src) :
176 AliHLTTriggerDecision(src),
177 fContributingTriggers(AliHLTTriggerDecision::Class()),
181 // Copy constructor performs a deep copy.
183 // We set the ownership to false since the objects are deleted manually by this
184 // class in DeleteInputObjects().
185 fInputObjects.SetOwner(kFALSE);
190 AliHLTGlobalTriggerDecision& AliHLTGlobalTriggerDecision::operator=(const AliHLTGlobalTriggerDecision& src)
192 // assignment operator performs a deep copy.
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);
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);
212 SetCounters(src.Counters());
218 void AliHLTGlobalTriggerDecision::AddInputObject(const TObject* object)
220 // Adds an object to the list of input objects considered in the global trigger.
222 if (object == NULL) return;
223 TObject* obj = object->Clone();
224 obj->SetBit(kCanDelete);
225 fInputObjects.Add(obj);
229 void AliHLTGlobalTriggerDecision::AddInputObjectRef(TObject* object, bool own)
231 // Adds an object to the list of input objects considered in the global trigger.
233 if (object == NULL) return;
236 object->SetBit(kCanDelete);
240 object->ResetBit(kCanDelete);
242 fInputObjects.Add(object);
246 void AliHLTGlobalTriggerDecision::SetCounters(const TArrayL64& counters, Long64_t eventCount)
248 // Sets the counter array.
249 // If the number of events is specified, an additional counter is added at the end.
250 fCounters = counters;
252 int size=fCounters.GetSize();
253 fCounters.Set(size+1);
254 fCounters[size]=eventCount;
259 void AliHLTGlobalTriggerDecision::Clear(Option_t* option)
261 // Clears the trigger domain and resets the decision result.
263 AliHLTTriggerDecision::Clear(option);
264 fContributingTriggers.Clear(option);
265 DeleteInputObjects();
270 void AliHLTGlobalTriggerDecision::DeleteInputObjects()
272 // Deletes the objects marked with kCanDelete in fInputObjects and clears the array.
274 for (Int_t i = 0; i < NumberOfInputObjects(); i++)
276 TObject* obj = fInputObjects.UncheckedAt(i);
278 if (obj->TestBit(kCanDelete)) delete obj;
280 fInputObjects.Clear();
284 void AliHLTGlobalTriggerDecision::Streamer(TBuffer &b)
286 // Stream an object of class AliHLTGlobalTriggerDecision.
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++)
295 TObject* obj = fInputObjects.UncheckedAt(i);
297 obj->SetBit(kCanDelete);
302 b.WriteClassBuffer(AliHLTGlobalTriggerDecision::Class(), this);