Download

package ExpChooser;
use strict;
use English;
use Carp;
use vars
  qw(@ISA $VERSION $name $author $date $version @instList $numberOfStreams);
@ISA = qw(Module);
use ModuleResources;

# Declare identity, version, author, date, etc.
$name    = __PACKAGE__;
$VERSION = '1.38';
$version = $VERSION;
$author="Richard West,Dean Hinshaw,Duncan John Fyfe,Ed Chapin, Jose Vicente Perea";
$date="2018-07-26";

#
# ChangeLog
# =========
#
# Version 1.38 - 2018-07-26 (JVP)
# ------------
#
# + Warning message ('errortext') modified
#
# Version 1.37 - 2018-07-26 (JVP)
# ------------
#
# + Insert 'errortext' in DB table 'mainprocesstime' if Filter or Mode is UNDEFINED or Unknown
#   EPIC:	Filter or Mode is UNDEFINED or Unknown
#   RGS :	Mode is UNDEFINED or Unknown
#
# Version 1.36 - 2013-06-11 (EC)
# ------------
#
# + Merge changes from SOC version.
#
# Version 1.35 - 2007-02-08
# ------------
#
# OM should look at all DATA_MODE_x values.  This is a work around for odfingest failing to do this when setting the MODE value.
#
# Version 1.34 - 2006-09-21
# ------------
#
# Change datamode to mode in accordance with infrastructure name changes.
#
# Version 1.33 - 2006-03-10
# ------------
#
# + Added checking and recording of manual intervention to prevent processing selected instrumnets and their exposures.
#
# Version 1.32 - 2004-09-12
# ------------
#
# + no longer ignore the OM grism
#
# Version 1.31 - 2002-05-07 (DH)
# ------------
#
# + Correct typo in info message so that it says 1000 seconds, 
#   not 100.
#
# Version 1.29 - 2002-03-22 (DH)
# ------------
#
# + Restrict exposure time cut to epic exposures only.
#
# Version 1.28 - 2002-03-22 (DH)
# ------------
#
# + Ignore exposures with a duration of less than 1000 seconds.
#
# Version 1.27 - 2002-03-01 (DH)
# ------------
#
# + Add 'NoTranslation' to the list of filters to be ignored.
#
# Version 1.26 - 2001-12-03 (DH)
# ------------
#
# + Add UNDEFINED to the list of filters to be ignored.
#
# Version 1.25 - 2001-07-31 (DH)
# ------------
#
# + Ignore HighTimeResolution mode (for the RGS).
#
# Version 1.24 - 2001-03-16 (DH)
# ------------
#
# + Print out version number in performAction() for
#   tracking purposes.
#
# Version 1.23 - 2001-03-08 (DH)
# ------------
#
# + Ingore filters containing the string 'Closed'.  Previously
#   were ignoring only those containing 'Cal'.
#
# Version 1.22 - 2001-01-26 (DH)
# ------------
#
# + Add Magnifier to the list of ignored filters.
#
# Version 1.21 - 2001-01-23 (DH)
# ------------
#
# + Correct typo which prevented info message from being printed.
#
# Version 1.20 - 2001-01-09 (DH)
# ------------
#
# + Add Grism to list of ignored filters.
# + Add info message about ignoring when there are no event lists.
#
# Version 1.19 - 2000-12-04 (DH)
# ------------
#
# + First production version.
#

@instList=qw(emos1 emos2 epn rgs1 rgs2 om);

# Number of streams
sub numberOfStreams {
    return numberOfExposures();
}

# Start conditions
sub evaluateRules {

# ignore for slew processing
    return ignore() if ($ENV{'PCMS_ISSLEW'});
    #
    start() if complete(module => 'MakeCIF', instrument => 'all',
			stream => 1);
}

# Action procedure
sub performAction {
    info("Module version number: $version");
    # Work out which exposure this stream maps on to
    my $exp_id=exposureID(instrument => thisInstrument,
			  stream => thisStream);

    #
    info("Checking exposure $exp_id for processability");

	if (manualintervention( instrument => thisInstrument , exposure => $exp_id ) )
	{
		info("Manual Intervention. Exposure ignored");
		return ignore();
	}

    # Find event files for this exposure
    my @evFiles=findFile(class => 'ODF',
			 instrument => thisInstrument,
			 exp_id => $exp_id,
			 content => '*events');

    # Return immediately if there are no event lists
    unless (@evFiles || thisInstrument eq 'om')
	{
		info("Exposure ignored due to lack of event files");
		ppd("000001");
		return ignore();
    };


    # Fetch info.
    my $filter=getExposureProperty(instrument => thisInstrument,
				   exp_id => $exp_id,
				   name => 'filter');
    my $mode=getExposureProperty(instrument => thisInstrument,
				 exp_id => $exp_id,
				 name => 'mode');
    my $duration=getExposureProperty(instrument => thisInstrument,
				     exp_id => $exp_id,
				     name => 'exp_duration');
    info("Filter: $filter");
    info("Instrument mode: $mode");
    info("Exposure duration: $duration");

    ###################################
    #  Warning message to Pipeline DB
    my $errortext;
    my $seqid = thisSequence;

    if( $duration > 1000 ){

	if ( thisInstrument=~/^e/ ){		# thisInstrument = EPIC (epn || emos1/2)

	    if( $filter=~/UNDEFINED|Unknown/i || $mode=~/UNDEFINED|Unknown/i ){
	       $errortext = "Warning: Filter/Mode: $filter/$mode. expTime: $duration s";
            }
	}

	if ( thisInstrument=~/^r/ ){		# thisInstrument = RGS1/2

	    if( $mode=~/UNDEFINED|Unknown/i ){
	       $errortext = "Warning: Mode: $mode. expTime: $duration s";
            }
	}
    }

    if ( $errortext ){
       info("Warning to DB: $errortext");
       my $chk = insertErrortextinDB( $seqid, $errortext );
    }
    ###################################

    # Check instrument filter
    if($filter=~/UNDEFINED|Cal|Unknown|Blocked|Magnifier|Closed|NoTranslation/i) 
	{
		info("Exposure ignored due to invalid or unsupported filter");
		ppd( id => "000002" , data => { filter => $filter } );
		return ignore();
    }

    # Check instrument mode
	
	my $valid_mode = 1;
	if( thisInstrument eq 'om' )
	{
		# For OM defer to DATA_MODE if MODE is undefined.
		# This is a work around for odfingest relying on window 0 for this information.
		# Telemetry drops means window 0 can be missing while other valid windows are processable.
		if ( $mode=~/UNDEFINED/i )
		{
			my $datamode=getExposureProperty(instrument => thisInstrument
				,exp_id => $exp_id
				,name => 'datamode'
			);
			info("OM datamode=$datamode");
			$valid_mode = 0
				unless ( $datamode =~ /Imaging|Fast/i )
			;
		}
	}
    elsif ($mode=~/UNDEFINED|HighTimeResolution/i) 
	{
		$valid_mode = 0;
    }

	if (!$valid_mode)
	{
		info("Exposure ignored due to invalid or unsupported instrument mode");
		ppd( id => "000003" , data => { mode => $mode } );
		return ignore();
	}

    # Check exposure time
    if($duration < 1000 && thisInstrument=~/^e/)
	{
		info("Exposure less than 1000 seconds. Exposure ignored.");
		ppd( id => "000004" , data => { duration => $duration , threshold => 1000 } );
		return ignore();
    }

    #
    return success();
}

1;