#! /usr/bin/perl
#
# Show all logs of specified chamber or current chamber
#
# Usage: showlog.pl [CHAMBER]
# Chamber is specified like "L1C1-020"

require "modules/read_setup.pl";

# get current chamber
( $DIR_NAME, $DATE, $ROC_SERIAL, $ROC_LAYER, $ROC_TYPE, $DCS_SERIAL, $WITH_PIPES, $INITIAL, $TRD_FEE ) = read_setup();

if( defined( $ARGV[0] )) {
    $CHAMBER = $ARGV[0];
} else {
    $CHAMBER = sprintf("L%dC%d-%03d", $ROC_LAYER, $ROC_TYPE, $ROC_SERIAL );
}

printf("\nAll log concerning ROC: %s \n", $CHAMBER );

@DirListTemp = `ls -1`;
foreach( @DirListTemp ) {
    chop;
    if( /^$CHAMBER/ ) {
	@DirList = ( @DirList, $_ );
    }
}
undef( @DirListTemp );

printf("%d directories found.\n\n", $#DirList + 1 );

foreach( @DirList ) {
    $CUR_DIR = $_;
    printf("Directory %s\n", $CUR_DIR );

    ( $DIR_NAME, $DATE, $ROC_SERIAL, $ROC_LAYER, $ROC_TYPE, $DCS_SERIAL, $WITH_PIPES, $INITIAL, $TRD_FEE ) = read_setup( $CUR_DIR );

    if( $WITH_PIPES eq "-wcp" ) { $WITH_PIPES = "YES"; } else { $WITH_PIPES = "NO"; }

    printf("  Start Time  : %s\n", $DATE );
    printf("  By          : %s\n", $INITIAL );
    printf("  Pipes Glued : %s\n", $WITH_PIPES );
    printf("  ----\n");

    open( F, "$CUR_DIR/MAINLOG.txt" ) || printf("  No logfile found.\n");
    while( <F> ) {
	chop;
	printf("  %s\n", $_ );
    }

    printf("\n");
}

# EOF
