Back to home page

sPhenix code displayed by LXR

 
 

    


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

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 < 2)
0010 {
0011     print "\nCreateFileLists.pl will produce a list file which can be read into\n";
0012     print "the Fun4All_New_Year2_Fitting.C macro\n";
0013     print "usage: CreateFileLists.pl <runnumber> <segment> <tag>\n";
0014     print "tag is e.g. new_nocdbtag_v003\n";
0015     exit(0);
0016 }
0017 
0018 my $runnumber = $ARGV[0];
0019 my $segment = $ARGV[1];
0020 my $dsttag = $ARGV[2];
0021 
0022 my $dbh;
0023 my $attempts = 0;
0024 
0025 CONNECTAGAIN:
0026 if ($attempts > 0)
0027 {
0028     sleep(int(rand(21) + 10)); # sleep 10-30 seconds before retrying
0029 }
0030 $attempts++;
0031 if ($attempts > 200)
0032 {
0033     print "giving up connecting to DB after $attempts attempts\n";
0034     exit(1);
0035 }
0036 $dbh = DBI->connect("dbi:ODBC:FileCatalog_read") || goto CONNECTAGAIN;
0037 #if ($attempts > 0)
0038 #{
0039 #    print "connections succeded at $attempts attempt\n";
0040 #}
0041 $dbh->{LongReadLen}=2000; # full file paths need to fit in here
0042 
0043 my $getfiles = $dbh->prepare("select filename from datasets where runnumber = $runnumber and segment = $segment order by filename");
0044 
0045 $getfiles->execute();
0046 unlink "files.list";
0047 my $inlist = sprintf("files.list");
0048 open(F,">$inlist");
0049 my $nfiles = 0;
0050 my %tags = ();
0051 if ($getfiles->rows == 0)
0052 {
0053     print "no files for run $runnumber and segment $segment\n";
0054     exit(1);
0055 }
0056 while (my @res = $getfiles->fetchrow_array())
0057 {
0058     my @sp1 = split(/-/,$res[0]);
0059     my @sp2 = split(/_/,$sp1[0]);
0060     my $foundtag = sprintf("%s_%s_%s",$sp2[$#sp2-2],$sp2[$#sp2-1],$sp2[$#sp2]);
0061     $tags{$foundtag} = 1;
0062     if ($res[0] =~ /DST_TRIGGERED_EVENT/ && $res[0] =~ /$dsttag/)
0063     {
0064     print F "$res[0]\n";
0065     $nfiles++;
0066     }
0067 }
0068 close(F);
0069 if ($nfiles == 0)
0070 {
0071     print "\nno file found for $dsttag\n";
0072     print "here is a list of existing ones:\n";
0073     foreach my $tag (sort keys %tags)
0074     {
0075     print "$tag\n";
0076     }
0077 }
0078 $getfiles->finish();
0079 $dbh->disconnect;