1 /**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
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 **************************************************************************/
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
24 #include "CorrelList.h"
28 CorrelListNode_t::CorrelListNode_t() : fPart(NULL), fNext(NULL) {
31 CorrelListNode_t::CorrelListNode_t(CorrelParticle_t* p, CorrelListNode_t* n) : fPart(p), fNext(n) {
34 CorrelListNode_t::CorrelListNode_t(const CorrelListNode_t& rhs) : fPart(rhs.fPart), fNext(rhs.fNext) {
37 CorrelListNode_t::~CorrelListNode_t() {
38 if(fPart) delete fPart;
42 const CorrelListNode_t& CorrelListNode_t::operator=(const CorrelListNode_t& rhs){
48 CorrelListIter_t::CorrelListIter_t() : fCurr(NULL) {
51 CorrelListIter_t::CorrelListIter_t(CorrelListNode_t* theNode) : fCurr(theNode) {
54 CorrelListIter_t::CorrelListIter_t(const CorrelListIter_t& rhs) : fCurr(rhs.fCurr) {
57 CorrelListIter_t::~CorrelListIter_t(){
60 void CorrelListIter_t::Check(){
61 // performs bounds check
63 std::cerr<<"CorrelListIter_t::Check() - ERROR: attempt to access null iterator!"<<std::endl;
68 const CorrelListIter_t& CorrelListIter_t::operator=(const CorrelListIter_t& rhs){
73 CorrelList_t::CorrelList_t() :
74 fSize(0), fEvtID(0), fFilled(kFALSE), fPartID(unknown), fPoolID(assocs), fHead(NULL) {
78 const CorrelList_t& CorrelList_t::operator=(const CorrelList_t& rhs){
81 fFilled = rhs.Filled();
82 fPartID = rhs.PartID();
83 fPoolID = rhs.PoolID();
84 fHead = rhs.Head().Node();
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.
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);
98 CorrelList_t* CorrelList_t::DeepCopy(){
99 // returns deep copy of caller list
100 // use it to store lists in memory for mixing pools
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
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());
116 } // iterator loop over caller list
121 void CorrelList_t::Reset(){
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
140 void CorrelList_t::ShowHead(){
142 std::cout<<" CorrelList_t("<<this<<") head="<<fHead<<" size="<<Size()<<" filled="<<Filled()<<" evt="<<EvtID()<<" part="<<PartID()<<" pool="<<PoolID()<<std::endl;
145 void CorrelList_t::Show(){
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;