#! /usr/bin/perl

use Time::HiRes qw (usleep);
require "_setup.pl";

if( $#ARGV != 0 ) {
    printf( "Please give tag number as argument.\n");
    system( "wing_showtags" );
    exit(0);
}

$tag  = $ARGV[0];
$DATE = `/bin/date +%Y%m%d-%H%M`;
chop( $DATE );

# @TRD_FEE = ( "TRD-FEE_1_0_0", "TRD-FEE_1_1_0", "TRD-FEE_1_2_0", "TRD-FEE_1_3_0", "TRD-FEE_1_4_0" );

$testname = "N/A";
if    ( $tag == 2  ) { $testname = "ce-ni"; }
elsif ( $tag == 3  ) { $testname = "ce-ori"; }
elsif ( $tag == 4  ) { $testname = "ce-bridge"; }
elsif ( $tag == 5  ) { $testname = "ce-reset"; }
elsif ( $tag == 6  ) { $testname = "ce-shutdown"; }
elsif ( $tag == 7  ) { $testname = "ce-laser-ids"; }
elsif ( $tag == 8  ) { $testname = "ce-nifast"; }
elsif ( $tag == 10 ) { $testname = "ce-only_pedestal"; }

die "Unknown tag $tag" if $testname eq "N/A";

$pwd = `pwd`; chop $pwd;

foreach $FEE ( @POS_LIST ) {
    $FEE = "TRD-FEE_".$FEE;
    $logfile = "$pwd/logs/$testname-$DATE-$FEE.log";
    $logfile =~ s/^\/home\/trd//;
    print  "Set logfile to $logfile\n";
    system "pvss_inject ControlFero $FEE 'LOGFILE $logfile'";
}

$FEE = "TRD-FEE_1_*_*";

printf("Injecting tag=$tag to \"$FEE\"\n");
system( "pvss_inject ConfigureFero \'$FEE\' $tag" );

exit(1);

# EOF
