Back to home page

sPhenix code displayed by LXR

 
 

    


File indexing completed on 2026-04-06 08:08:19

0001 #!/usr/bin/perl
0002 
0003 use strict;
0004 use DBI; # Database interface 
0005 
0006 # Read file
0007 my $filename = 'RunList_golden.txt';
0008 open(my $fh,'<',$filename) or die "Could not open file '$filename' $!";
0009 
0010 # connect to the database Production_read
0011 my $dbh = DBI->connect("dbi:ODBC:RawdataCatalog_read","") || die $DBI::error;
0012 
0013 my @hostnames = ("seb00","seb01","seb02","seb03","seb04","seb05","seb06","seb07","seb08",
0014                  "seb09","seb10","seb11","seb12","seb13","seb14","seb15"); # Only check SEBs for the EMCal
0015 
0016 while (my $line = <$fh>) {
0017     chomp($line);
0018     my $feminfoname = "FEM_folder/fem_${line}.txt";
0019     open(my $feminfofile,'<',$feminfoname) or die "Could not open '$feminfoname' $!";
0020 
0021     # Determine whether a run is good or not wrt FEM Clock matching
0022     my $fem_matching = 1;
0023     
0024     # Common clock value (one per file)
0025     my $clock_value = -1;
0026 
0027     # Current scanned Sub Event Buffer
0028     my $current_seb = "sebXX";
0029     
0030     # equals to 1 if the current SEB is considered
0031     # equals to 0 if the current SEB is ignored
0032     my $checkClock = 0;
0033 
0034     while (my $rawline = <$feminfofile>) {
0035         if ($rawline =~ /^(seb\S+)/) {
0036             $current_seb = $1;
0037             # If seb is considered, check FEM Clock matching
0038             if ($current_seb ~~ @hostnames) {
0039                 # print "$current_seb\n";
0040                 $checkClock = 1;
0041             }
0042             # If SEB is not considered, ignore it until the next SEB or the end of the file;
0043             else {
0044                 $checkClock = 0;
0045             }
0046         }
0047 
0048         # Check Clock matching
0049         if ($checkClock) {
0050             # Check whether all lines agree between them
0051             if ($rawline =~ /^FEM Clock: \s+(\S+)./) {
0052                 # the first entry defines the clock value
0053                 if ($clock_value == -1) {
0054                     if (($current_seb eq "seb16") || ($current_seb eq "seb17") || ($current_seb eq "seb20")) {
0055                         $clock_value = $1 - 1;
0056                     }
0057                     else {
0058                         $clock_value = $1;
0059                     }
0060                 }
0061                 else {
0062                     if ((($current_seb eq "seb16") || ($current_seb eq "seb17") || ($current_seb eq "seb20")) && ($1 ne $clock_value + 1)) {
0063                         $fem_matching = 0;
0064                         last;
0065                     }
0066                     elsif ((($current_seb ne "seb16") && ($current_seb ne "seb17") || ($current_seb eq "seb20")) && ($1 ne $clock_value)) {
0067                         $fem_matching = 0;
0068                         last;
0069                     }
0070                 }
0071             }
0072 
0073             # Check whether all clock numbers on the same line agree.
0074             if ($rawline =~ /^FEM Clock:\s+(\S+)\s+(\S+)\s+(\S+)/) {
0075                 if (($1 ne $2) || ($1 ne $3) || ($2 ne $3)) {
0076                     $fem_matching = 0;
0077                     last;
0078                 }
0079             } 
0080             elsif ($rawline =~ /^FEM Clock: \s+(\S+)\s+(\S+)/) {
0081                 if ($1 ne $2) {
0082                     $fem_matching = 0;
0083                     last;
0084                 }
0085             }
0086         }
0087     }
0088     close($feminfofile);
0089     
0090     if ($fem_matching) {
0091         print "$line\n";
0092     }
0093 }
0094 
0095 close($fh); # Close the file handle.
0096 
0097 $dbh->disconnect;