AliPhysics  4ef2867 (4ef2867)
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
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
30 #include "AliVTrack.h"
31 
34 ClassImp(PWG::EMCAL::AliEmcalTrackSelResultUserPtr)
35 ClassImp(PWG::EMCAL::AliEmcalTrackSelResultUserStorage)
36 ClassImp(PWG::EMCAL::TestAliEmcalTrackSelResultPtr)
38 
39 using namespace PWG::EMCAL;
40 
42  TObject(),
43  fTrack(nullptr),
44  fSelectionResult(false),
45  fUserInfo()
46 {
47 
48 }
49 
50 AliEmcalTrackSelResultPtr::AliEmcalTrackSelResultPtr(AliVTrack *trk, Bool_t selectionStatus, TObject * userinfo) :
51  TObject(),
52  fTrack(trk),
53  fSelectionResult(selectionStatus),
54  fUserInfo(userinfo)
55 {
56 
57 }
58 
60  TObject(ref),
61  fTrack(ref.fTrack),
62  fSelectionResult(ref.fSelectionResult),
63  fUserInfo(ref.fUserInfo)
64 {
65 
66 }
67 
69  TObject(ref),
70  fTrack(ref.fTrack),
71  fSelectionResult(ref.fSelectionResult),
72  fUserInfo()
73 {
74  ref.fTrack = nullptr;
75  fUserInfo = std::move(ref.fUserInfo);
76 }
77 
79  TObject::operator =(ref);
80  if(this != &ref){
81  fTrack = ref.fTrack;
83  fUserInfo = ref.fUserInfo;
84  }
85  return *this;
86 }
87 
89  TObject::operator =(ref);
90  if(this != &ref){
91  fTrack = ref.fTrack;
92  fSelectionResult = ref.fSelectionResult;
93  fUserInfo = std::move(ref.fUserInfo);
94 
95  ref.fTrack = nullptr;
96  }
97  return *this;
98 }
99 
101  return fTrack == other.fTrack;
102 }
103 
105  return fTrack < other.fTrack;
106 }
107 
109  const AliEmcalTrackSelResultPtr *otherobj = static_cast<const AliEmcalTrackSelResultPtr *>(o);
110  if(!otherobj) return false;
111  return *this == *otherobj;
112 }
113 
115  const AliEmcalTrackSelResultPtr *otherobj = static_cast<const AliEmcalTrackSelResultPtr *>(o);
116  if(!otherobj) return 1;
117  if (*this == *otherobj) return 0;
118  if (*this < *otherobj) return -1;
119  return 1;
120 }
121 
123  return fTrack;
124 }
125 
127  return fTrack;
128 }
129 
130 void AliEmcalTrackSelResultPtr::PrintStream(std::ostream &stream) const {
131  stream << "Track selection result for track with address " << fTrack
132  << ": Selection status: " << (fSelectionResult ? "true" : "false")
133  << ", HasUserInfo: " << (fUserInfo.GetData() ? "Yes" : "No");
134 }
135 
136 std::ostream &PWG::EMCAL::operator<<(std::ostream &stream, const PWG::EMCAL::AliEmcalTrackSelResultPtr &o){
137  o.PrintStream(stream);
138  return stream;
139 }
140 
141 
143  TObject(),
144  fData(nullptr),
145  fReferenceCount(0)
146 {
147 
148 }
149 
151  TObject(),
152  fData(data),
153  fReferenceCount(1)
154 {
155 
156 }
157 
159  if(fData) delete fData;
160 }
161 
163  fReferenceCount++;
164 }
165 
167  fReferenceCount--;
168 }
169 
171  TObject(),
172  fUserStorage(nullptr)
173 {
174 
175 }
176 
178  TObject(),
179  fUserStorage(new AliEmcalTrackSelResultUserStorage(data))
180 {
181 
182 }
183 
185  TObject(ref),
186  fUserStorage(nullptr)
187 {
188  if(ref.fUserStorage) {
191  }
192 }
193 
195  TObject(ref),
196  fUserStorage(nullptr)
197 {
198  if(ref.fUserStorage) {
199  // reference count does not change in case of move semantics
200  fUserStorage = ref.fUserStorage;
201  ref.fUserStorage = nullptr;
202  }
203 }
204 
206  TObject::operator=(ref);
207 
208  if(&ref != this){
209  if(fUserStorage) {
211  if(fUserStorage->GetReferenceCount() < 1) delete fUserStorage;
212  }
213 
214  if(ref.fUserStorage) {
217  }
218  }
219  return *this;
220 }
221 
223  TObject::operator=(ref);
224 
225  if(&ref != this){
226  if(fUserStorage) {
228  if(fUserStorage->GetReferenceCount() < 1) delete fUserStorage;
229  }
230 
231  if(ref.fUserStorage) {
232  // reference count does not change in case of move semantics
233  fUserStorage = ref.fUserStorage;
234  ref.fUserStorage = nullptr;
235  }
236  }
237  return *this;
238 }
239 
241  if(fUserStorage) {
243  // The last pointer connected to the storage deletes it
244  if(fUserStorage->GetReferenceCount() < 1) delete fUserStorage;
245  }
246 }
247 
250 }
251 
253  AliEmcalTrackSelResultPtr testtrue(nullptr, true), testfalse(nullptr, false);
254 
255  bool testresult(true);
256  if(!(testtrue == true)) testresult = false;
257  if(testfalse == true) testresult = false;
258  return testresult;
259 }
260 
262  int failure(0);
263  for(int i = 0; i < 10; i++) {
264  TNamed *payloadTrue = new TNamed("truewith", "true, with object"),
265  *payloadFalse = new TNamed("falsewith", "false, with user object");
266  AliEmcalTrackSelResultPtr truewith(nullptr, true, payloadTrue),
267  truewithout(nullptr, true),
268  falsewith(nullptr, false, payloadFalse),
269  falsewithout(nullptr, false);
270  // make copies
271  AliEmcalTrackSelResultPtr cpytruewith(truewith), cpyfalsewith(falsewith), cpytruewithout(truewithout), cpyfalsewithout(falsewithout);
272  if(!(AssertBool(cpytruewith, true) && AssertBool(cpytruewithout, true) && AssertBool(cpyfalsewith, false) && AssertBool(cpyfalsewithout, false))) failure++;
273  if(!(AssertPayload(cpytruewith, payloadTrue) && AssertPayload(cpytruewithout, nullptr) && AssertPayload(cpyfalsewith, payloadFalse) && AssertPayload(cpyfalsewithout, nullptr))) failure++;
274  }
275  return failure == 0;
276 }
277 
279  int failure(0);
280  for(int i = 0; i < 10; i++) {
281  TNamed *payloadTrue = new TNamed("truewith", "true, with object"),
282  *payloadFalse = new TNamed("falsewith", "false, with user object");
283  AliEmcalTrackSelResultPtr truewith(nullptr, true, payloadTrue),
284  truewithout(nullptr, true),
285  falsewith(nullptr, false, payloadFalse),
286  falsewithout(nullptr, false);
287  // make assignments
288  AliEmcalTrackSelResultPtr asgtruewith = truewith, asgfalsewith = falsewith, asgtruewithout = truewithout, asgfalsewithout = falsewithout;
289  if(!(AssertBool(asgtruewith, true) && AssertBool(asgtruewithout, true) && AssertBool(asgfalsewith, false) && AssertBool(asgfalsewithout, false))) failure++;
290  if(!(AssertPayload(asgtruewith, payloadTrue) && AssertPayload(asgtruewithout, nullptr) && AssertPayload(asgfalsewith, payloadFalse) && AssertPayload(asgfalsewithout, nullptr))) failure++;
291  }
292  return failure == 0;
293 }
294 
296  int failure(0);
297  for(int i = 0; i < 10; i++) {
298  AliEmcalTrackSelResultPtr testwith(nullptr, true, new TNamed("testuserobject", "Test userobject"));
299  if(!testwith.GetUserInfo()) failure++;
300 
301  AliEmcalTrackSelResultPtr testwithout(nullptr, true);
302  if(testwithout.GetUserInfo()) failure++;
303  }
304  return failure == 0;
305 }
306 
308  return test.GetSelectionResult() == assertval;
309 }
310 
312  return test.GetUserInfo() == reinterpret_cast<const TObject *>(payload);
313 }
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.
Int_t GetReferenceCount() const
Get the number of pointer instances connected to the storage.
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.
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