/**
 * \class BDSwicCalibrator
 *
 * \ingroup BeamDataUtil
 *
 * \brief Object to calibrate devices read out by SWIC scanners.
 *
 * It holds, but does not own, a collection of BDSwicDevice objects.
 * Each spill it should be given a chance to calibrate any that need
 * it.  Depending on the device type different calibrations are
 * applied.
 *
 * - pedestal subtraction
 * - any channel weights (masks)
 * - mV/ADC
 * - pC/mV
 * - gain corrections
 *
 * This object is best kept alive to maximize DB caching.
 *
 * \author (last to touch it) $Author: minoscvs $
 *
 * \version $Revision: 1.4 $
 *
 * \date $Date: 2005/05/05 21:11:12 $
 *
 * Contact: bv@bnl.gov
 *
 * Created on: Mon Apr 25 15:52:38 2005
 *
 * $Id: BDSwicCalibrator.h,v 1.4 2005/05/05 21:11:12 minoscvs Exp $
 *
 */

#ifndef BDSWICCALIBRATOR_H
#define BDSWICCALIBRATOR_H

#include <BeamDataUtil/BDSwicPedAccessor.h>
#include <BeamDataUtil/BDSwicMaskAccessor.h>

#include <list>

class BDSwicDevice;
class RawBeamMonHeaderBlock;
class RawBeamMonBlock;


class BDSwicCalibrator {

    static BDSwicCalibrator* fInstance;
    BDSwicCalibrator();

public:

    ~BDSwicCalibrator();
    static BDSwicCalibrator& Get();
    
    typedef std::list<BDSwicDevice*> DevList;

    /** Calibrate all devices using current spill info */
    void Calibrate(const RawBeamMonHeaderBlock& rbmhb,
		   const RawBeamMonBlock& rbmb);

    /** Access device list in read-only manner */
    const DevList& GetDevices() { return fDevList; }

    /** Add device with the given name to list.  If this device is not
     *	valid, it will be rejected, and false will be returned.
     */
    bool AddDevice(BDSwicDevice& dev);

    /** Remove device from list */
    void RemoveDevice(BDSwicDevice& dev);

    /** Drop all devices */
    void Clear() { fDevList.clear(); }

    /** Called by Calibrate, but externally useable */
    void CalibrateOne(const RawBeamMonHeaderBlock& rbmhb,
		      const RawBeamMonBlock& rbmb, BDSwicDevice& sd);


private:

    BDSwicPedAccessor fPeds;
    BDSwicMaskAccessor fMask;

    DevList fDevList;
    
};
#endif  // BDSWICCALIBRATOR_H
