VESPERSSingleElementVortexDetector::VESPERSSingleElementVortexDetector(const QString &name, const QString &description, QObject *parent)
	: AMXRFDetector(name, description, parent)
{
	units_ = "Counts";

	AMAxisInfo ai("Energy", 2048, "Energy", "eV");
	ai.start = AMNumber(0);
	ai.increment = 10;
	ai.isUniform = true;
	axes_ << ai;

	// Stuff required by AMXRFDetector.
	acquireControl_ = new AMPVControl("Acquisition Time", "IOC1607-004:mca1EraseStart", "IOC1607-004:mca1EraseStart", "IOC1607-004:mca1Stop", this, 0.5);
	acquisitionStatusControl_ = new AMReadOnlyPVControl("Status", "IOC1607-004:mca1.ACQG", this);
	acquireTimeControl_ = new AMSinglePVControl("Integration Time", "IOC1607-004:mca1.PRTM", this, 0.001);
	elapsedTimeControl_ = new AMReadOnlyPVControl("Elapsed Time", "IOC1607-004:mca1.ERTM", this);

	icrControls_.append(new AMReadOnlyPVControl("Input Counts", "IOC1607-004:dxp1.ICR", this, "The input counts for the single element."));
	ocrControls_.append(new AMReadOnlyPVControl("Output Counts", "IOC1607-004:dxp1.OCR", this, "The output counts for the single element."));
	spectraControls_.append(new AMReadOnlyPVControl("Raw Spectrum", "IOC1607-004:mca1", this));

	allControlsCreated();

	// Our own stuff.
	maximumEnergyControl_ = new AMSinglePVControl("Maximum Energy", "IOC1607-004:dxp1.EMAX", this, 0.01);
	peakingTimeControl_ = new AMSinglePVControl("Peaking Time", "IOC1607-004:dxp1.PKTIM", this, 0.01);

	connect(maximumEnergyControl_, SIGNAL(valueChanged(double)), this, SLOT(onMaximumEnergyChanged(double)));
	connect(peakingTimeControl_, SIGNAL(valueChanged(double)), this, SIGNAL(peakingTimeChanged(double)));
}
SXRMBFourElementVortexDetector::SXRMBFourElementVortexDetector(const QString &name, const QString &description, QObject *parent)
	: AMXRFDetector(name, description, parent)
{
	units_ = "Counts";

	AMAxisInfo ai("Energy", 2048, "Energy", "eV");
	ai.start = AMNumber(0);
	ai.increment = 10;
	ai.isUniform = true;
	axes_ << ai;

	// Stuff required by AMXRFDetector.
	acquireControl_ = new AMPVControl("Acquisition Time", "dxp1606-B10-02:EraseStart", "dxp1606-B10-02:EraseStart", "dxp1606-B10-02:StopAll", this, 0.5);
	acquisitionStatusControl_ = new AMReadOnlyPVControl("Status", "dxp1606-B10-02:Acquiring", this);
	acquireTimeControl_ = new AMSinglePVControl("Integration Time", "dxp1606-B10-02:PresetReal", this, 0.001);
	elapsedTimeControl_ = new AMReadOnlyPVControl("Elapsed Time", "dxp1606-B10-02:ElapsedReal", this);

	for (int i = 0; i < 4; i++){

		icrControls_.append(new AMReadOnlyPVControl(QString("Input Counts %1").arg(i+1), QString("dxp1606-B10-02:dxp%1.ICR").arg(i+1), this, QString("The input counts for element %1 of the four element.").arg(i+1)));
		ocrControls_.append(new AMReadOnlyPVControl(QString("Output Counts %1").arg(i+1), QString("dxp1606-B10-02:dxp%1.OCR").arg(i+1), this, QString("The output counts for element %1 of the four element.").arg(i+1)));
		spectraControls_.append(new AMReadOnlyPVControl(QString("Raw Spectrum %1").arg(i+1), QString("dxp1606-B10-02:mca%1").arg(i+1), this));
	}

	allControlsCreated();

	// Our own stuff.
	maximumEnergyControl_ = new AMSinglePVControl("Maximum Energy", "dxp1606-B10-02:mcaEMax", this, 0.01);
	peakingTimeControl_ = new AMSinglePVControl("Peaking Time", "dxp1606-B10-02:EnergyPkTime", this, 0.01);

	connect(maximumEnergyControl_, SIGNAL(valueChanged(double)), this, SLOT(onMaximumEnergyChanged(double)));
	connect(peakingTimeControl_, SIGNAL(valueChanged(double)), this, SIGNAL(peakingTimeChanged(double)));
}
IDEAS13ElementGeDetector::IDEAS13ElementGeDetector(const QString &name, const QString &description, QObject *parent)
	: AMXRFDetector(name, description, parent)
{
	units_ = "Counts";

	AMAxisInfo ai("Energy", 2048, "Energy", "eV");
	ai.start = AMNumber(0);
	ai.increment = 10;
	ai.isUniform = true;
	axes_ << ai;

	// Stuff required by AMXRFDetector.
	acquireControl_ = new AMPVControl("Acquisition Time", "dxp1608-B21-13:EraseStart", "dxp1608-B21-13:EraseStart", "dxp1608-B21-13:StopAll", this, 0.5);
	acquisitionStatusControl_ = new AMReadOnlyPVControl("Status", "dxp1608-B21-13:Acquiring", this);
	acquireTimeControl_ = new AMSinglePVControl("Integration Time", "dxp1608-B21-13:PresetReal", this, 0.001);
	elapsedTimeControl_ = new AMReadOnlyPVControl("Elapsed Time", "dxp1608-B21-13:ElapsedReal", this);

	// Detector functionality
	ge13ElementRealTimeControl_ = new AMReadOnlyPVControl("13-el Ge Real Time", "dxp1608-B21-13:ElapsedReal", this);
	ge13ElementRealTime_ = new AMBasicControlDetectorEmulator("13E_dwellTime", "13-element Ge dwell time", ge13ElementRealTimeControl_, 0, 0, 0, AMDetectorDefinitions::ImmediateRead, this);

    // Energy Peaking Time
    peakingTimeControl_ = new AMSinglePVControl("Peaking Time", "dxp1608-B21-13:EnergyPkTime", this, 0.01);

    // preamp Gain controls for elements 1-12
    for(int i = 0; i < 12; i++){
        preampGainControls_ << new AMPVControl(QString("13-el Ge Preamp Gain %1").arg(i+1),QString("dxp1608-B12-13:dxp%1:PreampGain_RBV").arg(i+1), "dxp1608-B12-13:dxp%1:PreampGain", QString(), this);
    }

	// Currently only using 12 due to lack of electronics.
	for (int i = 0; i < 12; i++){

		icrControls_.append(new AMReadOnlyPVControl(QString("Input Counts %1").arg(i+1), QString("dxp1608-B21-13:dxp%1:InputCountRate").arg(i+1), this, QString("The input counts for element %1 of the four element.").arg(i+1)));
		ocrControls_.append(new AMReadOnlyPVControl(QString("Output Counts %1").arg(i+1), QString("dxp1608-B21-13:dxp%1:OutputCountRate").arg(i+1), this, QString("The output counts for element %1 of the four element.").arg(i+1)));
		spectraControls_.append(new AMReadOnlyPVControl(QString("Raw Spectrum %1").arg(i+1), QString("dxp1608-B21-13:mca%1").arg(i+1), this));
	}

	allControlsCreated();

	foreach (AMDataSource *source, rawSpectraSources_)
		((AM1DProcessVariableDataSource *)source)->setScale(10);

}
CLSAmptekSDD123DetectorNew::CLSAmptekSDD123DetectorNew(const QString &name, const QString &description, const QString &baseName, QObject *parent) :
	AMXRFDetector(name, description, parent)
{	
	baseName_ = baseName;

	units_ = "Counts";

	eVPerBin_ = 8.25;

	// This can be done in the constructor because it doesn't depend on anything.
	axes_ = QList<AMAxisInfo>();
	AMAxisInfo ai("Energy", 1024, "Energy", "eV");
	ai.start = AMNumber(0);
	ai.isUniform = true;
	ai.increment = eVPerBin_;
	axes_ << ai;

	acquireControl_ = new AMPVControl(name+"StartAcquisition", baseName+":spectrum:start", baseName+":spectrum:start", baseName+":spectrum:stop", this, 0.5);
	acquireControl_->setAllowsMovesWhileMoving(true);
	acquisitionStatusControl_ = new AMReadOnlyPVControl(name+"Status", baseName+":spectrum:dwellState", this);
	acquireTimeControl_ = new AMPVControl(name+"IntegrationTime", baseName+":spectrum:dwellTime", baseName+":spectrum:dwellTime", QString() , this, 0.05);
	elapsedTimeControl_ = new AMReadOnlyPVControl(name+"Elapsed Time", baseName+":spectrum:elapsedTime", this);

	fastCountsControl_ = new AMReadOnlyPVControl("FastCounts", QString("%1:spectrum:fastCounts").arg(baseName_), this);
	averageFastCountsControl_ = new AMReadOnlyPVControl("AverageFastCounts", QString("%1:spectrum:average:fastCounts").arg(baseName_), this);
	slowCountsControl_ = new AMReadOnlyPVControl("SlowCounts", QString("%1:spectrum:slowCounts").arg(baseName_), this);
	averageSlowCountsControl_ = new AMReadOnlyPVControl("AverageSlowCounts", QString("%1:spectrum:average:slowCounts").arg(baseName_), this);

	icrControls_.append(fastCountsControl_);
	ocrControls_.append(slowCountsControl_);
	spectraControls_.append(new AMReadOnlyPVControl("Raw Spectrum", baseName+":spectrum", this));

	lowIndicesSignalMapper_ = new QSignalMapper();
	highIndicesSignalMapper_ = new QSignalMapper();
	AMSinglePVControl *oneLowIndex;
	AMSinglePVControl *oneHighIndex;
	for(int x = 0; x < 8; x++){
		oneLowIndex = new AMSinglePVControl(QString("ROI%1Low").arg(x+1), QString("%1:ROI:%2:lowChannel").arg(baseName_).arg(x+1), this, 0.5);
		oneHighIndex = new AMSinglePVControl(QString("ROI%1Low").arg(x+1), QString("%1:ROI:%2:highChannel").arg(baseName_).arg(x+1), this, 0.5);

		roiLowIndices_.append(oneLowIndex);
		roiHighIndices_.append(oneHighIndex);

		lowIndicesSignalMapper_->setMapping(oneLowIndex, x);
		highIndicesSignalMapper_->setMapping(oneHighIndex, x);

		connect(oneLowIndex, SIGNAL(valueChanged(double)), lowIndicesSignalMapper_, SLOT(map()));
		connect(oneHighIndex, SIGNAL(valueChanged(double)), highIndicesSignalMapper_, SLOT(map()));
	}


	accumulationTimeControl_ = new AMReadOnlyPVControl("AccumulationTime", QString("%1:spectrum:accumulationTime").arg(baseName_), this);
	averageAccumulationTimeControl_ = new AMReadOnlyPVControl("AverageAccumulationTime", QString("%1:spectrum:average:accumulationTime").arg(baseName_), this);
	liveTimeControl_ = new AMReadOnlyPVControl("LiveTime", QString("%1:spectrum:liveTime").arg(baseName_), this);
	averageLiveTimeControl_ = new AMReadOnlyPVControl("AverageLiveTime", QString("%1:spectrum:average:liveTime").arg(baseName_), this);
	realTimeControl_ = new AMReadOnlyPVControl("RealTime", QString("%1:spectrum:realTime").arg(baseName_), this);
	averageRealTimeControl_ = new AMReadOnlyPVControl("AverageRealTime", QString("%1:spectrum:average:realTime").arg(baseName_), this);

	mcaChannelsControl_ = new AMReadOnlyPVControl(name+"MCAChannels", baseName+":parameters:MCAChannelCount", this);
	detectorTemperatureControl_ = new AMReadOnlyPVControl(name+"DetectorTemperature", baseName+":parameters:temperature", this);

	totalGainControl_ = new AMSinglePVControl(QString("TotalGain"), QString("%1:parameters:totalGain").arg(baseName_), this, 0.1);
	pileUpRejectionControl_ = new AMSinglePVControl(QString("PileUpRejection"), QString("%1:parameters:pileUpRejection").arg(baseName_), this, 0.5);
	thermoelectricCoolerControl_ = new AMSinglePVControl(QString("ThermoelectricCooler"), QString("%1:parameters:thermoelectricCooler").arg(baseName_), this, 0.1);
	fastThresholdControl_ = new AMSinglePVControl(QString("FastThreshold"), QString("%1:parameters:fastThreshold").arg(baseName_), this, 0.1);
	slowThresholdControl_ = new AMSinglePVControl(QString("SlowThreshold"), QString("%1:parameters:slowThreshold").arg(baseName_), this, 0.1);
	peakingTimeControl_ = new AMSinglePVControl(QString("PeakingTime"), QString("%1:parameters:peakingTime").arg(baseName_), this, 0.1);
	fastChannelPeakingTimeControl_ = new AMSinglePVControl(QString("FastChannelPeakingTime"), QString("%1:parameters:fastChannelPeakingTime").arg(baseName_), this, 0.1);

	isRequestedControl_ = new AMPVControl(name+"IsRequested", baseName+":spectrum:isRequested", baseName+":spectrum:isRequested", QString(), this, 0.5);

	connect(lowIndicesSignalMapper_, SIGNAL(mapped(int)), this, SLOT(onLowIndexValueChanged(int)));
	connect(highIndicesSignalMapper_, SIGNAL(mapped(int)), this, SLOT(onHighIndexValueChanged(int)));

	connect(detectorTemperatureControl_, SIGNAL(valueChanged(double)), this, SIGNAL(detectorTemperatureChanged(double)));

	allControlsCreated();	// This is very important.  It does a lot of work for you building data sources and the like.

	((AM1DProcessVariableDataSource *)rawSpectraSources_.first())->setScale(ai.increment);
	primarySpectrumDataSource_ = rawSpectraSources_.first();
}