////////////////////////////////////////////////////////////////////////
// $Id: CandFitTrackMSList.cxx,v 1.1 2001/11/16 21:35:12 rhbob Exp $
//
// This is a concrete Event Candidate (Reconstruction) object.
// CandFitTrackMSList is descended from CandFitTrackList.
//
// Each concrete CandBase must define a Dup function.
// CandBase must grant friendship to class CandRefer.
//
// Tom Bringley
// ttb2@duke.edu
// 6/13/2001
////////////////////////////////////////////////////////////////////////

#include "Algorithm/AlgHandle.h"
#include "CandFitTrackMS/CandFitTrackMSList.h"
#include "CandFitTrackMS/CandFitTrackMSListHandle.h"
#include "MessageService/MsgService.h"

ClassImp(CandFitTrackMSList)

//______________________________________________________________________
CVSID("$Id: CandFitTrackMSList.cxx,v 1.1 2001/11/16 21:35:12 rhbob Exp $");

//______________________________________________________________________
CandFitTrackMSList::CandFitTrackMSList()
{
  MSG("Cand", Msg::kDebug)
                        << "Begin CandFitTrackMSList::CandFitTrackMSList() ctor: " << endl
                                           << "UidInt = " << GetUidInt()
                           << ", ArchUidInt " << GetArchUidInt() << endl
                             << "No. of links = " << GetNLinks() << endl
                          << "End CandFitTrackMSList::CandFitTrackMSList() ctor." << endl;
}

//______________________________________________________________________
CandFitTrackMSList::CandFitTrackMSList(AlgHandle &ah) :
  CandFitTrackList(ah)  // Should be the next class up on inheritance chain
{

// The sole purpose of this constructor is to transmit the AlgHandle
// up the inheritance chain to CandBase without having to invoke the
// full constructor of an intermediate Candidate type which the highest
// level Candidate might inherit from.  One only wants to create the
// LocalHandle and invoke the RunAlg() method in the lowest level class.

}

//______________________________________________________________________
CandFitTrackMSList::CandFitTrackMSList(AlgHandle &ah, CandHandle &ch, CandContext &cx) :
  CandFitTrackList(ah)  // Should be the next class up on inheritance chain
{
  CreateLocalHandle();
  MSG("Cand", Msg::kDebug)
             << "Begin CandFitTrackMSList::CandFitTrackMSList(AlgHandle &, CandHandle &, "
                                      << "CandContext &) ctor: " << endl
                                           << "UidInt = " << GetUidInt()
                           << ", ArchUidInt " << GetArchUidInt() << endl
                             << "No. of links = " << GetNLinks() << endl
               << "End CandFitTrackMSList::CandFitTrackMSList(AlgHandle &, CandHandle &, "
                                      << "CandContext &) ctor." << endl;

// Run Algorithm to construct Candidate
   {                                         // Start of scope.
     CandFitTrackMSListHandle cshl(this);              // cshl will go out of scope
     ch = cshl;                               // after setting ch.
   }                                         // End of scope.
   ah.RunAlg(ch, cx);
}

//______________________________________________________________________
CandFitTrackMSList::CandFitTrackMSList(const CandFitTrackMSList &rhs) :
  CandFitTrackList(rhs) // Should be the next class up on inheritance chain
{
//CreateLocalHandle(); // Moved to Dup function following copy-ctor call
  MSG("Cand", Msg::kDebug)
    << "Begin CandFitTrackMSList::CandFitTrackMSList(const CandFitTrackMSList &rhs) ctor: " << endl
                                           << "UidInt = " << GetUidInt()
                           << ", ArchUidInt " << GetArchUidInt() << endl
                             << "No. of links = " << GetNLinks() << endl
      << "End CandFitTrackMSList::CandFitTrackMSList(const CandFitTrackMSList &rhs) ctor." << endl;
}

//______________________________________________________________________
CandFitTrackMSList::~CandFitTrackMSList()
{
  MSG("Cand", Msg::kDebug)
                       << "Begin CandFitTrackMSList::~CandFitTrackMSList() dtor: " << endl
                                           << "UidInt = " << GetUidInt()
                           << ", ArchUidInt " << GetArchUidInt() << endl
                             << "No. of links = " << GetNLinks() << endl
                         << "End CandFitTrackMSList::~CandFitTrackMSList() dtor." << endl;
}

//______________________________________________________________________
void CandFitTrackMSList::CreateLocalHandle()
{
  SetLocalHandle(new CandFitTrackMSListHandle(this));
}

//______________________________________________________________________
CandFitTrackMSList *CandFitTrackMSList::Dup() const
{

// Base copy ctor dups owned pointers, but defers copying Daughter List.
// Daughter List copy is made in the derived class Dup() function.
// This is because base class copy constructor hasn't yet created
// fLocalHandle with a CandHandle* of the full derived type.
  CandFitTrackMSList *cb = new CandFitTrackMSList(*this);         // Copy-ctor
  cb->CreateLocalHandle();   // Initializes fLocalHandle after copy-ctor
  TIter iterdau = GetDaughterIterator();
  CandHandle *dau;
  while ((dau=(CandHandle *) iterdau())) cb->AddDaughterLink(*dau);
  return cb;
}

//______________________________________________________________________
CandFitTrackMSListHandle CandFitTrackMSList::MakeCandidate(AlgHandle &ah, CandContext &cx)
{
  CandFitTrackMSListHandle cshl;
  new CandFitTrackMSList(ah, cshl, cx); //cshl owns the new CandFitTrackMSList
  return cshl;
}
