Back to home page

sPhenix code displayed by LXR

 
 

    


File indexing completed on 2025-08-03 08:20:30

0001 #!/usr/bin/env perl
0002 
0003 use strict;
0004 use warnings;
0005 use File::Basename;
0006 use DBI;
0007 use Data::Dumper;
0008 
0009 if ($#ARGV < 1)
0010 {
0011     print "usage: CreateFileLists.pl <runnumber> <daqhost>\n";
0012     exit(0);
0013 }
0014 
0015 my $runnumber = $ARGV[0];
0016 my $daqhost = $ARGV[1];
0017 
0018 my $dbh;
0019 my $attempts = 0;
0020 
0021 CONNECTAGAIN:
0022 if ($attempts > 0)
0023 {
0024     sleep(int(rand(21) + 10)); # sleep 10-30 seconds before retrying
0025 }
0026 $attempts++;
0027 if ($attempts > 200)
0028 {
0029     print "giving up connecting to DB after $attempts attempts\n";
0030     exit(1);
0031 }
0032 $dbh = DBI->connect("dbi:ODBC:RawDataCatalog_read") || goto CONNECTAGAIN;
0033 if ($attempts > 0)
0034 {
0035     print "connections succeded after $attempts attempts\n";
0036 }
0037 $dbh->{LongReadLen}=2000; # full file paths need to fit in here
0038 
0039 my $getfiles = $dbh->prepare("select filename,daqhost from datasets where runnumber = $runnumber and (daqhost = '$daqhost' or daqhost = 'gl1daq') order by filename");
0040 
0041 $getfiles->execute();
0042 
0043 my %flist = ();
0044 while (my @res = $getfiles->fetchrow_array())
0045 {
0046     push @{$flist{$res[1]}}, $res[0];
0047 #    print "$res[0] on $res[1]\n";
0048 }
0049 #print Dumper(\%flist);
0050 foreach my $host (keys %flist)
0051 {
0052     my $listname = sprintf("%s.list",$host);
0053     open(F,">$listname");
0054     for my $i ( 0 .. $#{ $flist{$host} } )
0055     {
0056     print F "$flist{$host}[$i]\n";
0057     }
0058 #    print F "@{ $flist{$host} }\n";
0059     close(F);
0060 }