/**
 * \class BDSwicMaskAccessor
 *
 * \ingroup BeamDataUtil
 *
 * \brief Access any SWIC channel weights (masks)
 *
 * 
 *
 * \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 12:08:17 2005
 *
 * $Id: BDSwicMaskAccessor.h,v 1.4 2005/05/05 21:11:12 minoscvs Exp $
 *
 */

#ifndef BDSWICMASKACCESSOR_H
#define BDSWICMASKACCESSOR_H

#include <DatabaseInterface/DbiResultPtr.h>

#include <Validity/VldContext.h>
#include <Validity/VldRange.h>
#include <vector>
#include <map>

class BeamMonSwicMask;
class BeamMonSwicRel;

class BDSwicMaskAccessor {
public:

    BDSwicMaskAccessor();
    
    ~BDSwicMaskAccessor();

    void AddDevice(const char* device_name);

    /// Update masks.  Should be called once per spill.  Return
    /// true if an update was needed.
    bool SetSpillTime(VldContext vc);

    /// Get the current masks for given device.  
    /// Return empty vector if device name is unknown.
    const std::vector<double>& GetMask(const char* device_name) const;

private:

    void Reset();

    struct Device {
	std::vector<double> mask;
	std::vector<double> rel;
	std::vector<double> prod;
    };
    typedef std::map<std::string,Device> SwicMap;
    SwicMap fSwicMap;

    DbiResultPtr<BeamMonSwicMask>* fMaskResPtr;
    DbiResultPtr<BeamMonSwicRel>* fRelResPtr;
    const DbiResultKey *fMaskResKey, *fRelResKey;
};

#endif  // BDSWICMASKACCESSOR_H
