/**
 * \class BDSwicPeds
 *
 * \ingroup BeamDataUtil
 *
 * \brief Calculate pedestals for swic scanner channels using raw beam data.
 *
 * This class maintains one UtilRunningAverageVector object for each
 * SWIC scanner worth of channels.
 *
 * \note There is no attempt to determine if a SWIC channel is bad!  A
 * pedestal will be happily calculated even if there are noisy
 * channels.
 *
 * \author (last to touch it) $Author: bv $
 *
 * \version $Revision: 1.8 $
 *
 * \date $Date: 2005/05/12 18:48:31 $
 *
 * Contact: bv@bnl.gov
 *
 * Created on: Fri Apr 15 10:00:54 2005
 *
 * $Id: BDSwicPeds.h,v 1.8 2005/05/12 18:48:31 bv Exp $
 *
 */

#ifndef BDSWICPEDS_H
#define BDSWICPEDS_H

#include <BeamDataUtil/BDProcessor.h>

#include <RawData/RawBeamSwicData.h>
#include <Validity/VldTimeStamp.h>

#include <Util/UtilRunningAverageVector.h>

#include <map>
#include <string>

class RawBeamMonHeaderBlock;
class RawBeamMonBlock;

class BDSwicPeds : public BDProcessor {
public:

    typedef std::map<std::string,UtilRunningAverageVector*> SwicMap;

    /// Create default BDSwicPeds.  This will use
    /// BDDevices::SwicDevices() to form a ChannelsList
    BDSwicPeds();

    /// Create a BDSwicPeds with pre-existing swic map.  The map will
    /// be shallow copied.  This transfers ownership of the URAV's.
    BDSwicPeds(const SwicMap& map);
    ~BDSwicPeds();

    /// Reset object to initial conditions, as if it was reconstructed
    void Clear();

    /// Call once per spill if filling from data files
    void SetSpill(const RawBeamMonHeaderBlock& rbmhb,
		  const RawBeamMonBlock& rbmb);

    /// Return true if this spill would be suitable for use as a
    /// pedestal.  This is called internally by SetSpill
    static bool IsPedSpill(const RawBeamMonBlock& rbmb);

    /// Access the Channels object corresponding to the given name.
    /// Returns 0 if there is no such channel name.
    const UtilRunningAverageVector* GetChannels(const char* name) const;

    /// Access vector of Channels.
    const SwicMap& GetAllChannels() const;
    SwicMap& GetAllChannels();

    /// Return the earliest spill seen or VldtimeStamp::GetEOT() if
    /// not yet seen any spill.
    VldTimeStamp GetStart() { return fBeginTS; }
    /// Return the latest spill seen or VldTimeStamp::GetBOT() if not
    /// yet seen any spill.
    VldTimeStamp GetStop() { return fEndTS; }

private:    
    SwicMap fSwicMap;
    VldTimeStamp fBeginTS, fEndTS;
};
#endif  // BDSWICPEDS_H
