Example #1
0
AMBeamlineActionItem *VESPERSBeamline::createBeamChangeAction(VESPERS::Beam beam)
{
	// If we are already at the new beam position and the internal state of the beam is the same, then don't do anything.
	if (beam_ == beam && beamSelectionMotor_->withinTolerance(beamPositions_.value(beam)))
		return 0;

	// To change beams, it is either a two or three stage process.
	/*
		First: Turn off the ability to scan.  This ensures that the mono motor doesn't swing wildly around while switching between beams.
		Second: Move to the chosen beam.
		Third (if applicable): If the new beam is a monochromatic beam, turn on the ability to scan the energy.
	 */
	AMBeamlineParallelActionsList *changeBeamActionsList = new AMBeamlineParallelActionsList;
	AMBeamlineListAction *changeBeamAction = new AMBeamlineListAction(changeBeamActionsList);

	changeBeamActionsList->appendStage(new QList<AMBeamlineActionItem*>());
	changeBeamActionsList->appendAction(0, mono()->createAllowScanningAction(false));

	changeBeamActionsList->appendStage(new QList<AMBeamlineActionItem*>());
	AMBeamlineControlMoveAction *moveBeamAction = new AMBeamlineControlMoveAction(beamSelectionMotor());
	moveBeamAction->setSetpoint(beamPositions_.value(beam));
	changeBeamActionsList->appendAction(1, moveBeamAction);

	if (beam != VESPERS::Pink){

		changeBeamActionsList->appendStage(new QList<AMBeamlineActionItem*>());
		changeBeamActionsList->appendAction(2, mono()->createAllowScanningAction(true));
	}

	return changeBeamAction;
}
void VESPERSScanController::onCleanupActionFinished()
{
	if (cleanupAction_ == 0)
		return;

	// Disconnect all signals and return all memory.
	cleanupAction_->disconnect();
	AMBeamlineParallelActionsList *actionList = cleanupAction_->list();

	for (int i = 0; i < actionList->stageCount(); i++){

		while (actionList->stage(i)->size())
			actionList->stage(i)->takeAt(0)->deleteLater();
	}

	cleanupAction_->deleteLater();
	cleanupAction_ = 0;
}
void VESPERSScanController::buildCleanupAction(bool usingMono)
{
	// To cleanup the XAS scan, there is one stage.
	/*
		First: Only have the scalar running in the syncrhonized dwell time.
		Second: Set the dwell time to 1 second.  Disables the variable integration time.  Set the relative energy PV to 0.
		Third: Set the scan mode to continuous.  This starts the synchronized dwell time.
	 */
	AMBeamlineParallelActionsList *cleanupActionsList = new AMBeamlineParallelActionsList;

	if (!cleanupAction_)
		onCleanupActionFinished();

	cleanupAction_ = new AMBeamlineListAction(cleanupActionsList);

	// First stage.
	cleanupActionsList->appendStage(new QList<AMBeamlineActionItem*>());
	// Scalar
	cleanupActionsList->appendAction(0, VESPERSBeamline::vespers()->synchronizedDwellTime()->elementAt(0)->createEnableAction(true));
	// Single element vortex
	cleanupActionsList->appendAction(0, VESPERSBeamline::vespers()->synchronizedDwellTime()->elementAt(1)->createEnableAction(false));
	// CCD
	cleanupActionsList->appendAction(0, VESPERSBeamline::vespers()->synchronizedDwellTime()->elementAt(2)->createEnableAction(false));
	// Picoammeters
	cleanupActionsList->appendAction(0, VESPERSBeamline::vespers()->synchronizedDwellTime()->elementAt(3)->createEnableAction(false));
	// Four element vortex
	cleanupActionsList->appendAction(0, VESPERSBeamline::vespers()->synchronizedDwellTime()->elementAt(4)->createEnableAction(false));
	// Mar CCD
	cleanupActionsList->appendAction(0, VESPERSBeamline::vespers()->synchronizedDwellTime()->elementAt(5)->createEnableAction(false));

	// Second stage.
	cleanupActionsList->appendStage(new QList<AMBeamlineActionItem*>());
	// Synchronized dwell time.
	cleanupActionsList->appendAction(1, VESPERSBeamline::vespers()->synchronizedDwellTime()->createMasterTimeAction(1.0));

	if (usingMono){
		// Variable integration time.
		cleanupActionsList->appendAction(1, VESPERSBeamline::vespers()->variableIntegrationTime()->createModeAction(CLSVariableIntegrationTime::Disabled));
		// Energy.
		cleanupActionsList->appendAction(1, VESPERSBeamline::vespers()->mono()->createDelEAction(0));
	}

	// Third stage.
	cleanupActionsList->appendStage(new QList<AMBeamlineActionItem *>());
	// Start the synchronized dwell time.
	cleanupActionsList->appendAction(2, VESPERSBeamline::vespers()->synchronizedDwellTime()->createModeAction(CLSSynchronizedDwellTime::Continuous));
}
void VESPERSScanController::buildBaseInitializationAction(double timeStep)
{
	// To initialize the XAS scan, there are four stages.
	/*
		First: Enable/Disable all the pertinent detectors.  The scalar is ALWAYS enabled.
		Second: Set the mode to single shot,set the time on the synchronized dwell time.
	 */
	AMBeamlineParallelActionsList *setupActionsList = new AMBeamlineParallelActionsList;

	if (!initializationAction_)
		onInitializationActionFinished();

	initializationAction_ = new AMBeamlineListAction(setupActionsList);

	// First stage.
	setupActionsList->appendStage(new QList<AMBeamlineActionItem*>());
	// Scalar
	setupActionsList->appendAction(0, VESPERSBeamline::vespers()->synchronizedDwellTime()->elementByName("Scaler")->createEnableAction(true));
	// Single element vortex
	if ((config_->fluorescenceDetector() == VESPERS::SingleElement) || (config_->fluorescenceDetector() == (VESPERS::SingleElement | VESPERS::FourElement)))
		setupActionsList->appendAction(0, VESPERSBeamline::vespers()->synchronizedDwellTime()->elementByName("1-El Vortex")->createEnableAction(true));
	else
		setupActionsList->appendAction(0, VESPERSBeamline::vespers()->synchronizedDwellTime()->elementByName("1-El Vortex")->createEnableAction(false));
	// Roper CCD
	if (config_->ccdDetector() == VESPERS::Roper)
		setupActionsList->appendAction(0, VESPERSBeamline::vespers()->synchronizedDwellTime()->elementByName("Roper CCD")->createEnableAction(true));
	else
		setupActionsList->appendAction(0, VESPERSBeamline::vespers()->synchronizedDwellTime()->elementByName("Roper CCD")->createEnableAction(false));

	// Pilatus CCD
	if (config_->ccdDetector() == VESPERS::Pilatus)
		setupActionsList->appendAction(0, VESPERSBeamline::vespers()->synchronizedDwellTime()->elementByName("Pilatus CCD")->createEnableAction(true));
	else
		setupActionsList->appendAction(0, VESPERSBeamline::vespers()->synchronizedDwellTime()->elementByName("Pilatus CCD")->createEnableAction(false));

	// Four element vortex
	if ((config_->fluorescenceDetector() == VESPERS::FourElement) || (config_->fluorescenceDetector() == (VESPERS::SingleElement | VESPERS::FourElement)))
		setupActionsList->appendAction(0, VESPERSBeamline::vespers()->synchronizedDwellTime()->elementByName("4-El Vortex")->createEnableAction(true));
	else
		setupActionsList->appendAction(0, VESPERSBeamline::vespers()->synchronizedDwellTime()->elementByName("4-El Vortex")->createEnableAction(false));
	// Mar CCD
	if (config_->ccdDetector() == VESPERS::Mar)
		setupActionsList->appendAction(0, VESPERSBeamline::vespers()->synchronizedDwellTime()->elementByName("Mar CCD")->createEnableAction(true));
	else
		setupActionsList->appendAction(0, VESPERSBeamline::vespers()->synchronizedDwellTime()->elementByName("Mar CCD")->createEnableAction(false));

	// Second stage.
	setupActionsList->appendStage(new QList<AMBeamlineActionItem*>());
	setupActionsList->appendAction(1, VESPERSBeamline::vespers()->scaler()->createStartAction(false));
	setupActionsList->appendAction(1, VESPERSBeamline::vespers()->scaler()->createScansPerBufferAction(1));
	setupActionsList->appendAction(1, VESPERSBeamline::vespers()->scaler()->createTotalScansAction(1));
	setupActionsList->appendAction(1, VESPERSBeamline::vespers()->synchronizedDwellTime()->createModeAction(CLSSynchronizedDwellTime::SingleShot));
	setupActionsList->appendAction(1, VESPERSBeamline::vespers()->synchronizedDwellTime()->createMasterTimeAction(timeStep));
}
bool VESPERSEnergyDacqScanController::initializeImplementation()
{
    buildBaseInitializationAction(config_->regionTime(0));
    AMBeamlineParallelActionsList *setupActionsList = initializationAction_->list();

    // Third stage.  Changing the name and number of the CCD.
    if (config_->ccdDetector() == VESPERS::Roper) {

        VESPERSRoperCCDDetector *ccd = VESPERSBeamline::vespers()->roperCCD();
        QString name = getUniqueCCDName(ccd->ccdFilePath(), config_->name());

        if (name != config_->ccdFileName())
            config_->setCCDFileName(name);

        setupActionsList->appendStage(new QList<AMBeamlineActionItem *>());
        setupActionsList->appendAction(setupActionsList->stageCount()-1, ccd->createFileNameAction(config_->ccdFileName()));
        setupActionsList->appendAction(setupActionsList->stageCount()-1, ccd->createFileNumberAction(1));
    }

    else if (config_->ccdDetector() == VESPERS::Mar) {

        VESPERSMarCCDDetector *ccd = VESPERSBeamline::vespers()->marCCD();
        QString name = getUniqueCCDName(ccd->ccdFilePath(), config_->name());

        if (name != config_->ccdFileName())
            config_->setCCDFileName(name);

        setupActionsList->appendStage(new QList<AMBeamlineActionItem *>());
        setupActionsList->appendAction(setupActionsList->stageCount()-1, ccd->createFileNameAction(config_->ccdFileName()));
        setupActionsList->appendAction(setupActionsList->stageCount()-1, ccd->createFileNumberAction(1));
    }

    else if (config_->ccdDetector() == VESPERS::Pilatus) {

        VESPERSPilatusCCDDetector *ccd = VESPERSBeamline::vespers()->pilatusCCD();
        QString name = getUniqueCCDName(ccd->ccdFilePath(), config_->name());

        if (name != config_->ccdFileName())
            config_->setCCDFileName(name);

        setupActionsList->appendStage(new QList<AMBeamlineActionItem *>());
        QString dataFolder = AMUserSettings::userDataFolder;

        if (dataFolder.contains(QRegExp("\\d{2,2}-\\d{4,4}")))
            setupActionsList->appendAction(setupActionsList->stageCount()-1, ccd->createFilePathAction("/ramdisk/" % dataFolder.mid(dataFolder.indexOf(QRegExp("\\d{2,2}-\\d{4,4}")), 7)));

        setupActionsList->appendAction(setupActionsList->stageCount()-1, ccd->createFileNameAction(config_->ccdFileName()));
        setupActionsList->appendAction(setupActionsList->stageCount()-1, ccd->createFileNumberAction(1));
    }

    // Fourth stage.
    if (config_->goToPosition() && VESPERSBeamline::vespers()->experimentConfiguration()->sampleStageChoice()) {

        setupActionsList->appendStage(new QList<AMBeamlineActionItem *>());
        setupActionsList->appendAction(setupActionsList->stageCount()-1, VESPERSBeamline::vespers()->pseudoSampleStage()->createHorizontalMoveAction(config_->x()));
        setupActionsList->appendStage(new QList<AMBeamlineActionItem *>());
        setupActionsList->appendAction(setupActionsList->stageCount()-1, VESPERSBeamline::vespers()->pseudoSampleStage()->createVerticalMoveAction(config_->y()));
    }

    else if (config_->goToPosition() && !VESPERSBeamline::vespers()->experimentConfiguration()->sampleStageChoice()) {

        setupActionsList->appendStage(new QList<AMBeamlineActionItem *>());
        setupActionsList->appendAction(setupActionsList->stageCount()-1, VESPERSBeamline::vespers()->realSampleStage()->createHorizontalMoveAction(config_->x()));
        setupActionsList->appendStage(new QList<AMBeamlineActionItem *>());
        setupActionsList->appendAction(setupActionsList->stageCount()-1, VESPERSBeamline::vespers()->realSampleStage()->createVerticalMoveAction(config_->y()));
    }

    connect(initializationAction_, SIGNAL(succeeded()), this, SLOT(onInitializationActionsSucceeded()));
    connect(initializationAction_, SIGNAL(failed(int)), this, SLOT(onInitializationActionsFailed(int)));
    connect(initializationAction_, SIGNAL(progress(double,double)), this, SLOT(onInitializationActionsProgress(double,double)));
    initializationAction_->start();

    return true;
}