Back to home page

sPhenix code displayed by LXR

 
 

    


File indexing completed on 2026-04-04 08:16:07

0001 #!/usr/bin/perl
0002 
0003 use strict;
0004 use warnings;
0005 
0006 sub findruns;
0007 
0008 my $maxrun=80000; # tpc/tpoc create large runnumbers, only look up to this run
0009 my $stopthis = sprintf("stopthis");
0010 my $histodir = sprintf("/sphenix/lustre01/sphnxpro/commissioning/online_monitoring/histograms");
0011 my @subsystems = ("BBCMON", "CEMCMON", "DAQMON", "GL1MON", "IHCALMON", "INTTMON", "LL1MON", "MVTXMON", "OHCALMON", "SEPDMON", "SPINMON", "TPCMON", "TPOTMON", "ZDCMON");
0012 #my @subsystems = ("BBCMON", "CEMCMON", "INTTMON", "LL1MON", "TPOTMON", "TPCMON");
0013 
0014 for my $subsys (@subsystems)
0015 {
0016     if (-e $stopthis)
0017     {
0018     last;
0019     }
0020     my %donehash = ();
0021     my $rundone = sprintf("%s.done",$subsys);
0022     if (-f $rundone)
0023     {
0024     open(F,"$rundone");
0025     while (my $run = <F>)
0026     {
0027             chomp $run;
0028         $donehash{$run} = 1;
0029     }
0030     close(F); 
0031     }
0032     my $subsysdir = sprintf("%s/%s",$histodir,$subsys);
0033     my %todoruns = findruns($subsysdir,$subsys, \%donehash );
0034 # store the last run and exclude from run done list so
0035 # we process it again in the next round, just in case we
0036 # transferred the histo files before the last one arrived
0037     my $lastrun = 0;
0038     for my $run (sort { $a <=> $b } keys %todoruns)
0039     {
0040     if ($run < $maxrun) # tpot/intt creates large bad runnumbers
0041     {
0042         my $listfile = sprintf("%s.list",$subsys);
0043         my $cmd = sprintf("ls -1 /sphenix/lustre01/sphnxpro/commissioning/online_monitoring/histograms/%s/Run_%d-* > %s.list",$subsys,$run,$subsys);
0044         print "$cmd\n";
0045         system($cmd);
0046         my $rootcmd = sprintf("root.exe -q makehtml.C\\\(\\\"%s.list\\\",\\\"%s\\\"\\\)",$subsys,$subsys);
0047         print "$rootcmd\n";
0048         system($rootcmd);
0049         print "handled $run for $subsys\n";
0050         $lastrun = $run; #process the last run again next time
0051     }
0052     if (-e $stopthis)
0053     {
0054         last;
0055     }
0056     }
0057     for my $run (sort { $a <=> $b } keys %todoruns)
0058     {
0059     if ($lastrun == $run)
0060     {
0061         next;
0062     }
0063     my $updatedone = sprintf("echo %d >> %s",$run,$rundone);
0064     system($updatedone);
0065     }
0066     if (-e $stopthis)
0067     {
0068     unlink $stopthis;
0069     exit(0);
0070     }
0071 }
0072 
0073 sub findruns
0074 {
0075     my $subsysdir = shift;
0076     my $subsys = shift;
0077     my %donehash = %{$_[0]};
0078     opendir my $dir, $subsysdir  or die "Cannot open directory: $!";
0079     my @files = readdir $dir;
0080     closedir $dir;
0081     my %todoruns = ();
0082     for my $file (@files)
0083     {
0084     if ($file =~ /$subsys/)
0085     {
0086 #       print "found $file\n";
0087         if ($file =~ /(\S+)_(\d+)-(\S+).*\..*/ )
0088         {
0089         my $run = int($2);
0090 #       print "found run $run\n";
0091         if (exists $donehash{$run})
0092         {
0093             next;
0094         }
0095         if ($run > $maxrun)
0096         {
0097             next;
0098         }
0099         $todoruns{$run} = 1;
0100         }
0101     }
0102     }
0103     return %todoruns;
0104 }
0105