////////////////////////////////////////////////////////////////////////
// $Id: AlgSuperSliceList.cxx,v 1.3 2002/12/15 16:08:06 rhatcher Exp $
//
// AlgSuperSliceList
//
// Begin_Html<img src="../../pedestrians.gif" align=center>
// <a href="../source_warning.html">Warning for beginners</a>.<br> 
//
// This is an Algorithm class to fill a CandSliceList with
// CandSliceHandles. The CandSliceHandles point to CandSlices
// that are constructed by matching CandDigits that are in the same time
// slice.
//
// Author:  P.S. Miyagawa 3/2001
//
// Also see <a href="../../root_crib/index.html">The ROOT Crib</a> and 
// <a href="../ALG_Classes.html"> Algorithm Classes</a> (part of
// <a href="../index.html">The MINOS Class User Guide</a>)End_Html
////////////////////////////////////////////////////////////////////////

#include <cassert>

#include "Algorithm/AlgFactory.h"
#include "Algorithm/AlgHandle.h"
#include "Candidate/CandContext.h"
#include "MessageService/MsgService.h"
#include "RecoBase/CandSlice.h"
#include "RecoBase/CandSliceHandle.h"
#include "RecoBase/CandStripListHandle.h"
#include "BubbleSpeak/AlgSuperSliceList.h"

ClassImp(AlgSuperSliceList)

//......................................................................

CVSID("$Id: AlgSuperSliceList.cxx,v 1.3 2002/12/15 16:08:06 rhatcher Exp $");

//......................................................................

AlgSuperSliceList::AlgSuperSliceList()
{
//
//  Purpose:    Default constructor.
//
//  Arguments:  n/a
//
//  Return:     n/a
//
}

//......................................................................

AlgSuperSliceList::~AlgSuperSliceList()
{
//
//  Purpose:    Default destructor.
//
//  Arguments:  n/a
//
//  Return:     n/a
//
}

//......................................................................

void AlgSuperSliceList::RunAlg(AlgConfig & /* ac */, CandHandle &ch,
                                              CandContext &cx)
{
//
//  Purpose:  Fills the CandSliceList with CandSlices constructed
//            using the supplied CandStripList.
//
//  Argument:
//    ac        in    AlgConfig (not used).
//    ch        in    Handle to the CandSliceList to fill.
//    cx        in    CandContext containing a CandStripList.
//
//  Return:   n/a
//

   MSG("BubAlg", Msg::kVerbose)
      << "Starting AlgSuperSliceList::RunAlg()" << endl;

   assert(cx.GetDataIn());

// Check for CandStripListHandle input.
   assert(cx.GetDataIn()->InheritsFrom("CandStripListHandle"));
   MSG("BubAlg", Msg::kVerbose)
      << "Recover CandStripListHandle." << endl;
   const CandStripListHandle *chlh =
               dynamic_cast<const CandStripListHandle*>(cx.GetDataIn());

// General setup.
   // Get singleton instance of AlgFactory.
   MSG("BubAlg", Msg::kVerbose)
      << "AlgFactory &af = AlgFactory::GetInstance();" << endl;
   AlgFactory &af = AlgFactory::GetInstance();

   // Get an AlgHandle to AlgSuperSlice with "default" AlgConfig.
   MSG("BubAlg", Msg:: kVerbose) <<
     "AlgHandle ah = af.GetAlgHandle(\"AlgSuperSlice\", \"default\");"
                                                            << endl;
   AlgHandle ah = af.GetAlgHandle("AlgSuperSlice", "default");

   MSG("BubAlg", Msg::kVerbose)
      << "Create CandContext instance." << endl;
   CandContext cxx(this, cx.GetMom());
   cxx.SetCandRecord(cx.GetCandRecord());

// Create a new CandSlice using all CandStrips in CandStripList.
   cxx.SetDataIn(const_cast<CandStripListHandle *>(chlh));
   CandSliceHandle csh = CandSlice::MakeCandidate(ah, cxx);
   ch.AddDaughterLink(csh);
}

//......................................................................

void AlgSuperSliceList::Trace(const char *c) const
{
//
//  Purpose:  Trace the AlgSuperSliceList.
//
//  Arguments:
//    c          in    String tag for the trace.
//
//  Return:   n/a
//

  MSG("BubCand", Msg::kDebug)
  << "**********Begin AlgSuperSliceList::Trace(\"" << c << "\")" << endl
  << "**********End AlgSuperSliceList::Trace(\"" << c << "\")" << endl;
}
