]> git.uio.no Git - u/mrichter/AliRoot.git/blob - PWG4/JetCorrel/CorrelList.cxx
pass 5 histos and selections
[u/mrichter/AliRoot.git] / PWG4 / JetCorrel / CorrelList.cxx
1 /**************************************************************************
2  * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
3  *                                                                        *
4  * Author: The ALICE Off-line Project.                                    *
5  * Contributors are mentioned in the code where appropriate.              *
6  *                                                                        *
7  * Permission to use, copy, modify and distribute this software and its   *
8  * documentation strictly for non-commercial purposes is hereby granted   *
9  * without fee, provided that the above copyright notice appears in all   *
10  * copies and that both the copyright notice and this permission notice   *
11  * appear in the supporting documentation. The authors make no claims     *
12  * about the suitability of this software for any purpose. It is          *
13  * provided "as is" without express or implied warranty.                  *
14  **************************************************************************/
15 /* $Id: $ */
16
17 //__________________________________________
18 // The particle list class CorrelList_t: implements a single-linked list
19 // Supporting classes:
20 // list node defined by class CorrelListNode_t and 
21 // list iterator defined by class CorrelListIter_t
22 //-- Author: Paul Constantin
23
24 #include "CorrelList.h"
25
26 using namespace std;
27
28 CorrelListNode_t::CorrelListNode_t() : fPart(NULL), fNext(NULL) {
29 }
30
31 CorrelListNode_t::CorrelListNode_t(CorrelParticle_t* p, CorrelListNode_t* n) : fPart(p), fNext(n) {
32 }
33
34 CorrelListNode_t::CorrelListNode_t(const CorrelListNode_t& rhs) : fPart(rhs.fPart), fNext(rhs.fNext) {
35 }
36
37 CorrelListNode_t::~CorrelListNode_t() {
38   if(fPart) delete fPart;
39   fNext = NULL;
40 }
41
42 const CorrelListNode_t& CorrelListNode_t::operator=(const CorrelListNode_t& rhs){
43   fPart = rhs.fPart;
44   fNext = rhs.fNext;
45   return *this;
46 }
47
48 CorrelListIter_t::CorrelListIter_t() : fCurr(NULL) {
49 }
50
51 CorrelListIter_t::CorrelListIter_t(CorrelListNode_t* theNode) : fCurr(theNode) {
52 }
53
54 CorrelListIter_t::CorrelListIter_t(const CorrelListIter_t& rhs) : fCurr(rhs.fCurr) {
55 }
56
57 CorrelListIter_t::~CorrelListIter_t(){
58 }
59
60 void CorrelListIter_t::Check(){
61   // performs bounds check
62   if(HasEnded()){
63     std::cerr<<"CorrelListIter_t::Check() - ERROR: attempt to access null iterator!"<<std::endl; 
64     exit(-1);
65   }
66 }  
67
68 const CorrelListIter_t& CorrelListIter_t::operator=(const CorrelListIter_t& rhs){
69   fCurr = rhs.fCurr;
70   return *this;
71 }
72
73 CorrelList_t::CorrelList_t() : 
74   fSize(0), fEvtID(0), fFilled(kFALSE), fPartID(unknown), fPoolID(assocs), fHead(NULL) {
75   // constructor
76 }
77
78 const CorrelList_t& CorrelList_t::operator=(const CorrelList_t& rhs){
79   fSize   = rhs.Size();
80   fEvtID  = rhs.EvtID();
81   fFilled = rhs.Filled();
82   fPartID = rhs.PartID();
83   fPoolID = rhs.PoolID();
84   fHead   = rhs.Head().Node();
85   return *this;
86 }
87
88 void CorrelList_t::Push(CorrelParticle_t* p){
89   // Push method creates new node, fills it with data object, hangs list to current fHead
90   // (NULL on first insertion), then moves the fHead to this new node.
91
92   if(!p){std::cerr<<"CorrelList_t::Push() - ERROR: cannot push undefined object!"<<std::endl; exit(-1);}
93   CorrelListNode_t* newNode = new CorrelListNode_t(p,fHead);
94   fHead = newNode;
95   fSize++;
96 }
97
98 CorrelList_t* CorrelList_t::DeepCopy(){
99   // returns deep copy of caller list
100   // use it to store lists in memory for mixing pools 
101   
102   CorrelList_t *copy = new CorrelList_t;
103   copy->Label(this->PartID(), this->PoolID(), this->EvtID());
104   copy->SetFilled(this->Filled());
105   // fHead and fSize are set by Push() below
106
107   CorrelListIter_t iter = this->Head();
108   while(!iter.HasEnded()){
109     CorrelParticle_t*   gener = iter.Data();
110     CorrelTrack_t*      track = dynamic_cast<CorrelTrack_t*>(gener);
111     CorrelRecoParent_t* recon = dynamic_cast<CorrelRecoParent_t*>(gener);
112     if(track)      copy->Push(track->Copy());
113     else if(recon) copy->Push(recon->Copy());
114     else           copy->Push(gener->Copy());
115     iter.Move();
116   } // iterator loop over caller list
117
118   return copy;
119 }
120
121 void CorrelList_t::Reset(){
122   // deep delete
123   if(fSize>0){
124     CorrelListIter_t iter = Head();
125     while(!iter.HasEnded()){
126       CorrelListIter_t current = iter; // get current node
127       iter.Move();                     // move iterator to next node
128       if(current.Node())               // redundant deletes happen in same part corr (dihadron)
129         delete current.Node();         // with overlapping pT bins
130       fSize--;
131     }
132   }
133   fEvtID = 0;
134   fFilled = kFALSE;
135   fPartID = unknown;
136   fPoolID = assocs;
137   fHead = NULL;
138 }
139
140 void CorrelList_t::ShowHead(){
141   // top printout
142   std::cout<<" CorrelList_t("<<this<<") head="<<fHead<<" size="<<Size()<<" filled="<<Filled()<<" evt="<<EvtID()<<" part="<<PartID()<<" pool="<<PoolID()<<std::endl;
143 }
144
145 void CorrelList_t::Show(){
146   // full printout
147   ShowHead();
148   CorrelListIter_t iter = Head();
149   while(!iter.HasEnded()){
150     std::cout<<"At node("<<iter.Node()<<")";
151     CorrelParticle_t* part = iter.Data();
152     std::cout<<" is particle("<<part<<"):";
153     if(part) part->Show(); else std::cout<<std::endl;
154     iter.Move();
155   }
156 }