Back to home page

sPhenix code displayed by LXR

 
 

    


File indexing completed on 2026-04-04 08:11:55

0001 #!/usr/bin/env perl
0002 
0003 #WJL version - just commented out some printfs
0004 
0005 #located in offline/framework/frog/
0006 
0007 use DBI;
0008 use strict;
0009 use Getopt::Long;
0010 use Data::Dumper;
0011 
0012 sub creatfilelists;
0013 sub printtags;
0014 sub printruns;
0015 
0016 my $tag;
0017 my $verbose;
0018 my $runnumber;
0019 my $runlist;
0020 my $printruns;
0021 my $printtags;
0022 my $hpss;
0023 my $noprint;
0024 my $dataset;
0025 
0026 GetOptions('dataset:s' => \$dataset, 'hpss' =>\$hpss, 'list:s' => \$runlist, 'printruns' => \$printruns, 'printtags' => \$printtags, 'run:i' => \$runnumber, 'tag:s' => \$tag, "verbose" =>\$verbose);
0027 
0028 my %ignore_datasets = (
0029     "mdc2" => 1,
0030     );
0031 
0032 my $dbh = DBI->connect("dbi:ODBC:FileCatalog_read") || die $DBI::error;
0033 $dbh->{LongReadLen}=2000; # full file paths need to fit in here
0034 
0035 if (defined $printtags)
0036 {
0037     printtags();
0038 }
0039 
0040 if (defined $printruns)
0041 {
0042     printruns();
0043 }
0044 if ($#ARGV < 0)
0045 {
0046     if (! defined $noprint)
0047     {
0048     print "usage:\n";
0049     print "CreateDstList.pl <dsttype1> <dsttype2> ...\n";
0050     print "parameters:\n";
0051     print "--hpss <print files in hpss>\n";
0052     print "--list <file with list of runs>\n";
0053     print "--printruns: print existing runs (for piping into a runlist)\n";
0054     print "--printtags: print existing tags\n";
0055     print "--run <run number>\n";
0056     print "--tag <tag (build_cdb_version)> (mandatory)\n";
0057     print "--version <version> (only if we have multiple versions for same build/cdb tag)\n";
0058     print "--verbose print stuff\n";
0059     print "\nfor use with --printruns or --printtags\n";
0060         print "--dataset <dataset (run2pp, run2auau, run3auau, run3cosmics,...)\n"; 
0061     }
0062     exit(0);
0063 }
0064 my %dsttype = ();
0065 while($#ARGV >= 0)
0066 {
0067     $dsttype{$ARGV[0]} = 1;
0068     shift (@ARGV);
0069 }
0070 
0071 if (! defined $tag)
0072 {
0073     print "set tag with --tag <tag>\n";
0074     exit(1);
0075 }
0076 if (! defined $runnumber && ! defined $runlist)
0077 {
0078     print "set run number with --run <run number>\n";
0079     exit(1);
0080 }
0081 
0082 my $sqlcmd = sprintf("select filename,dsttype,segment from datasets where runnumber=? and tag = '$tag'");
0083 if (defined $hpss)
0084 {
0085     $sqlcmd = sprintf("%s and status = 0",$sqlcmd)
0086 }
0087 else
0088 {
0089     $sqlcmd = sprintf("%s and status > 0",$sqlcmd)
0090 }
0091 my $getfiles =  $dbh->prepare($sqlcmd);
0092 if (defined $runlist)
0093 {
0094     if (! -f $runlist)
0095     {
0096     print "$runlist does not exist\n";
0097     exit(1);
0098     }
0099     open(F2,"$runlist");
0100     {
0101     while (my $run = <F2>)
0102     {
0103         creatfilelists($run);
0104     }
0105     }
0106 }
0107 else
0108 {
0109     creatfilelists($runnumber);
0110 }
0111 
0112 sub creatfilelists
0113 {
0114     my %files = ();
0115     my $run = shift;
0116     $getfiles->execute($run);
0117     while(my @res = $getfiles->fetchrow_array)
0118     {
0119     $files{$res[2]}{$res[1]}{$res[0]} = $res[1];
0120     }
0121     foreach my $dsttyp (keys %dsttype)
0122     {
0123     my $filename = sprintf("%s-%08d.list",lc $dsttyp, $run);
0124     open(F,">$filename");
0125     my $fcnt = 0;
0126     foreach my $segment (sort { $a <=> $b } keys %files)
0127     {
0128         foreach my $file (keys %{$files{$segment}{$dsttyp}})
0129         {
0130         print F "$file\n";
0131         $fcnt++;
0132         }
0133     }
0134     close(F);
0135     if ($fcnt == 0)
0136     {
0137         #print "no dsts for type $dsttyp for run $run\n";
0138         unlink $filename;
0139     }
0140     }
0141     #x  print Dumper(\%files);
0142 }
0143 
0144 sub printtags
0145 {
0146     my $sqlcmd = sprintf("select distinct(tag) from datasets where ");
0147     my $icnt = 0;
0148     if (defined $dataset)
0149     {
0150     $sqlcmd = sprintf("%s dataset = \'\%s\'",$sqlcmd,$dataset);
0151     }
0152     else
0153     {
0154     foreach my $ignore (sort keys %ignore_datasets)
0155     {
0156         if ($icnt > 0)
0157         {
0158         $sqlcmd = sprintf("%s and ",$sqlcmd);
0159         }
0160         $sqlcmd = sprintf("%s dataset <> \'\%s\'",$sqlcmd,$ignore);
0161         $icnt++;
0162     }
0163     }
0164     $sqlcmd = sprintf("%s and tag is not null order by tag",$sqlcmd);
0165     if (defined $verbose)
0166     {
0167     print "sql cmd: $sqlcmd\n";
0168     }
0169     my $gettags = $dbh->prepare($sqlcmd);
0170     $gettags->execute();
0171     while (my @res = $gettags->fetchrow_array)
0172     {
0173     print "$res[0]\n";
0174     }
0175     exit(0);
0176 }
0177 
0178 sub printruns
0179 {
0180     my $sqlcmd = sprintf("select distinct(runnumber) from datasets where ");
0181     my $icnt = 0;
0182     if (defined $dataset)
0183     {
0184     $sqlcmd = sprintf("%s dataset = \'\%s\'",$sqlcmd,$dataset);
0185     }
0186     else
0187     {
0188     foreach my $ignore (sort keys %ignore_datasets)
0189     {
0190         if ($icnt > 0)
0191         {
0192         $sqlcmd = sprintf("%s and ",$sqlcmd);
0193         }
0194         $sqlcmd = sprintf("%s dataset <> \'\%s\'",$sqlcmd,$ignore);
0195         $icnt++;
0196     }
0197     }
0198     $sqlcmd = sprintf("%s and tag = '$tag' and dsttype='$ARGV[0]'order by runnumber",$sqlcmd);
0199     my $getruns =  $dbh->prepare($sqlcmd);
0200     $getruns->execute();
0201     if ($getruns->rows == 0)
0202     {
0203         #print "no run found for tag $tag and dst type $ARGV[0]\n";
0204     }
0205     else
0206     {
0207     while (my @res = $getruns->fetchrow_array())
0208     {
0209         print "$res[0]\n";
0210     }
0211     }
0212     exit(0);
0213 }
0214