AliPhysics  63e47e1 (63e47e1)
AliEmcalTrackSelResultPtr.cxx
Go to the documentation of this file.
1 /************************************************************************************
2  * Copyright (C) 2017, Copyright Holders of the ALICE Collaboration *
3  * All rights reserved. *
4  * *
5  * Redistribution and use in source and binary forms, with or without *
6  * modification, are permitted provided that the following conditions are met: *
7  * * Redistributions of source code must retain the above copyright *
8  * notice, this list of conditions and the following disclaimer. *
9  * * Redistributions in binary form must reproduce the above copyright *
10  * notice, this list of conditions and the following disclaimer in the *
11  * documentation and/or other materials provided with the distribution. *
12  * * Neither the name of the <organization> nor the *
13  * names of its contributors may be used to endorse or promote products *
14  * derived from this software without specific prior written permission. *
15  * *
16  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND *
17  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED *
18  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE *
19  * DISCLAIMED. IN NO EVENT SHALL ALICE COLLABORATION BE LIABLE FOR ANY *
20  * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES *
21  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; *
22  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND *
23  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT *
24  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS *
25  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. *
26  ************************************************************************************/
27 #include <iostream>
28 #include <TNamed.h> // for user object
29 #include <TClass.h>
31 #include "AliVTrack.h"
32 
39 
40 using namespace PWG::EMCAL;
41 
43  TObject(),
44  fTrack(nullptr),
45  fSelectionResult(false),
46  fUserInfo()
47 {
48 
49 }
50 
51 AliEmcalTrackSelResultPtr::AliEmcalTrackSelResultPtr(AliVTrack *trk, Bool_t selectionStatus, TObject * userinfo) :
52  TObject(),
53  fTrack(trk),
54  fSelectionResult(selectionStatus),
55  fUserInfo(userinfo)
56 {
57 
58 }
59 
61  TObject(ref),
62  fTrack(ref.fTrack),
64  fUserInfo(ref.fUserInfo)
65 {
66 
67 }
68 
70  TObject(ref),
71  fTrack(ref.fTrack),
73  fUserInfo()
74 {
75  ref.fTrack = nullptr;
76  fUserInfo = std::move(ref.fUserInfo);
77 }
78 
80  TObject::operator =(ref);
81  if(this != &ref){
82  fTrack = ref.fTrack;
84  fUserInfo = ref.fUserInfo;
85  }
86  return *this;
87 }
88 
90  TObject::operator =(ref);
91  if(this != &ref){
92  fTrack = ref.fTrack;
93  fSelectionResult = ref.fSelectionResult;
94  fUserInfo = std::move(ref.fUserInfo);
95 
96  ref.fTrack = nullptr;
97  }
98  return *this;
99 }
100 
102  return fTrack == other.fTrack;
103 }
104 
106  return fTrack < other.fTrack;
107 }
108 
110  const AliEmcalTrackSelResultPtr *otherobj = static_cast<const AliEmcalTrackSelResultPtr *>(o);
111  if(!otherobj) return false;
112  return *this == *otherobj;
113 }
114 
116  const AliEmcalTrackSelResultPtr *otherobj = static_cast<const AliEmcalTrackSelResultPtr *>(o);
117  if(!otherobj) return 1;
118  if (*this == *otherobj) return 0;
119  if (*this < *otherobj) return -1;
120  return 1;
121 }
122 
124  return fTrack;
125 }
126 
128  return fTrack;
129 }
130 
131 void AliEmcalTrackSelResultPtr::PrintStream(std::ostream &stream) const {
132  stream << "Track selection result for track with address " << fTrack
133  << ": Selection status: " << (fSelectionResult ? "true" : "false")
134  << ", HasUserInfo: " << (fUserInfo.GetData() ? "Yes" : "No");
135 }
136 
137 std::ostream &PWG::EMCAL::operator<<(std::ostream &stream, const PWG::EMCAL::AliEmcalTrackSelResultPtr &o){
138  o.PrintStream(stream);
139  return stream;
140 }
141 
142 /*************************************************************
143  * *
144  * Content of class AliEmcalTrackSelResultUserStorage *
145  * *
146  *************************************************************/
147 
149  TObject(),
150  fData(nullptr),
151  fReferenceCount(0)
152 {
153 
154 }
155 
157  TObject(),
158  fData(data),
159  fReferenceCount(1)
160 {
161 }
162 
164  //std::cout << "Destructing user storage with reference count 0" << std::endl;
165  if(fData) delete fData;
166 }
167 
169  fReferenceCount++;
170 }
171 
173  fReferenceCount--;
174  if(!fReferenceCount) delete this;
175 }
176 
177 /*************************************************************
178  * *
179  * Content of class AliEmcalTrackSelResultUserPtr *
180  * *
181  *************************************************************/
182 
184  TObject(),
185  fUserStorage(nullptr)
186 {
187 
188 }
189 
191  TObject(),
193 {
194  if(data) fUserStorage = new AliEmcalTrackSelResultUserStorage(data);
195 }
196 
198  TObject(ref),
200 {
201  if(ref.fUserStorage) {
204  }
205 }
206 
208  TObject(ref),
210 {
211  if(ref.fUserStorage) {
212  // reference count does not change in case of move semantics
213  fUserStorage = ref.fUserStorage;
214  ref.fUserStorage = nullptr;
215  }
216 }
217 
219  TObject::operator=(ref);
220 
221  if(&ref != this){
222  if(fUserStorage) {
224  // if(fUserStorage->GetReferenceCount() < 1) delete fUserStorage;
225  }
226 
227  if(ref.fUserStorage) {
230  }
231  }
232  return *this;
233 }
234 
236  TObject::operator=(ref);
237 
238  if(&ref != this){
239  if(fUserStorage) {
241  //if(fUserStorage->GetReferenceCount() < 1) delete fUserStorage;
242  }
243 
244  if(ref.fUserStorage) {
245  // reference count does not change in case of move semantics
246  fUserStorage = ref.fUserStorage;
247  ref.fUserStorage = nullptr;
248  }
249  }
250  return *this;
251 }
252 
254  if(fUserStorage) {
256  // The last pointer connected to the storage deletes it
257  //if(fUserStorage->GetReferenceCount() < 1) delete fUserStorage;
258  }
259 }
260 
262  return TestOperatorBool() && TestUserInfo() && TestCopyConstructor() && TestOperatorAssign();
263 }
264 
266  AliEmcalTrackSelResultPtr testtrue(nullptr, true), testfalse(nullptr, false);
267 
268  bool testresult(true);
269  if(!(testtrue == true)) testresult = false;
270  if(testfalse == true) testresult = false;
271  return testresult;
272 }
273 
275  int failure(0);
276  for(int i = 0; i < 10; i++) {
277  TNamed *payloadTrue = new TNamed("truewith", "true, with object"),
278  *payloadFalse = new TNamed("falsewith", "false, with user object");
279  AliEmcalTrackSelResultPtr truewith(nullptr, true, payloadTrue),
280  truewithout(nullptr, true),
281  falsewith(nullptr, false, payloadFalse),
282  falsewithout(nullptr, false);
283  // make copies
284  AliEmcalTrackSelResultPtr cpytruewith(truewith), cpyfalsewith(falsewith), cpytruewithout(truewithout), cpyfalsewithout(falsewithout);
285  if(!(AssertBool(cpytruewith, true) && AssertBool(cpytruewithout, true) && AssertBool(cpyfalsewith, false) && AssertBool(cpyfalsewithout, false))) failure++;
286  if(!(AssertPayload(cpytruewith, payloadTrue) && AssertPayload(cpytruewithout, nullptr) && AssertPayload(cpyfalsewith, payloadFalse) && AssertPayload(cpyfalsewithout, nullptr))) failure++;
287  }
288  return failure == 0;
289 }
290 
292  int failure(0);
293  for(int i = 0; i < 10; i++) {
294  TNamed *payloadTrue = new TNamed("truewith", "true, with object"),
295  *payloadFalse = new TNamed("falsewith", "false, with user object");
296  AliEmcalTrackSelResultPtr truewith(nullptr, true, payloadTrue),
297  truewithout(nullptr, true),
298  falsewith(nullptr, false, payloadFalse),
299  falsewithout(nullptr, false);
300  // make assignments
301  AliEmcalTrackSelResultPtr asgtruewith = truewith, asgfalsewith = falsewith, asgtruewithout = truewithout, asgfalsewithout = falsewithout;
302  if(!(AssertBool(asgtruewith, true) && AssertBool(asgtruewithout, true) && AssertBool(asgfalsewith, false) && AssertBool(asgfalsewithout, false))) failure++;
303  if(!(AssertPayload(asgtruewith, payloadTrue) && AssertPayload(asgtruewithout, nullptr) && AssertPayload(asgfalsewith, payloadFalse) && AssertPayload(asgfalsewithout, nullptr))) failure++;
304  }
305  return failure == 0;
306 }
307 
309  int failure(0);
310  for(int i = 0; i < 10; i++) {
311  AliEmcalTrackSelResultPtr testwith(nullptr, true, new TNamed("testuserobject", "Test userobject"));
312  if(!testwith.GetUserInfo()) failure++;
313 
314  AliEmcalTrackSelResultPtr testwithout(nullptr, true);
315  if(testwithout.GetUserInfo()) failure++;
316  }
317  return failure == 0;
318 }
319 
321  return test.GetSelectionResult() == assertval;
322 }
323 
325  return test.GetUserInfo() == reinterpret_cast<const TObject *>(payload);
326 }
Bool_t fSelectionResult
Result of the track selection (true - selected, false - rejected)
Bool_t operator<(const AliEmcalTrackSelResultPtr &other) const
bool TestOperatorBool() const
Test for operator bool.
AliEmcalTrackSelResultPtr & operator=(const AliEmcalTrackSelResultPtr &ref)
AliEmcalTrackSelResultUserStorage * fUserStorage
Underlying user storage for reference counting.
bool TestCopyConstructor() const
Test copy constructor with user information.
Structure containing the result of a given track selection step.
TObject * GetData() const
Get the object handled by the storage.
Namespace for EMCAL framework classes and task.
Helper class handling the lifetime of the user object handled by AliEmcalTrackSelResultUserPtr.
bool TestOperatorAssign() const
Tests assignment operatator with user info.
virtual Bool_t IsEqual(const TObject *o) const
virtual Int_t Compare(const TObject *o) const
int Int_t
Definition: External.C:63
Unit test for class AliEmcalTrackSelResultPtr.
Namespace for PWG framework classes.
void Release()
Release user pointer from the storage.
void Connect()
Connect new user pointer instance to the storage.
bool TestUserInfo() const
Test handling of user storage.
std::ostream & operator<<(std::ostream &stream, const AliEmcalTrackSelResultPtr &ref)
Bool_t operator==(const AliEmcalTrackSelResultPtr &other) const
bool AssertBool(const AliEmcalTrackSelResultPtr &test, bool testvalue) const
AliEmcalTrackSelResultUserPtr fUserInfo
Selection flag (optional)
void test(int runnumber=195345)
bool Bool_t
Definition: External.C:53
AliEmcalTrackSelResultUserPtr & operator=(const AliEmcalTrackSelResultUserPtr &ref)
Assignment operator.
bool AssertPayload(const AliEmcalTrackSelResultPtr &test, void *payload) const
Handler for user objects attached to the track selection result ptr.
AliVTrack * fTrack
Pointer to selected track.
void PrintStream(std::ostream &stream) const