Back to home page

sPhenix code displayed by LXR

 
 

    


File indexing completed on 2025-12-17 09:19:41

0001 #!/usr/bin/env perl
0002 
0003 #located in offline/framework/frog/
0004 
0005 use DBI;
0006 use strict;
0007 use Getopt::Long;
0008 use Data::Dumper;
0009 use List::Util qw(shuffle);
0010 
0011 sub commonfiletypes;
0012 sub fill_nocombine_files;
0013 sub print_single_types;
0014 sub print_runs;
0015 
0016 my $dbh = DBI->connect("dbi:ODBC:FileCatalog_read") || die $DBI::error;
0017 $dbh->{LongReadLen}=2000; # full file paths need to fit in here
0018 
0019 # old way - dealing with disorganized datasets
0020 #my $getdsttypes = $dbh->prepare("select distinct(dsttype) from datasets where dsttype not like '%\_pi\_%' ESCAPE '\' and dsttype <> 'beam' and dsttype <> 'cosmic' and dataset = 'mdc2'");
0021 my $getdsttypes = $dbh->prepare("select distinct(dsttype) from datasets where dataset = 'mdc2'");
0022 $getdsttypes->execute();
0023 
0024 my %dsttype = ();
0025 while(my @res = $getdsttypes->fetchrow_array())
0026 {
0027     my $listfile = sprintf("%s.list",lc $res[0]);
0028     $dsttype{$res[0]} = $listfile;
0029     if (-f $listfile)
0030     {
0031     unlink $listfile;
0032     }
0033 }
0034 my %exclude_these = (
0035     "DST_JOBA" => "Test PanDa",
0036     "DST_MDC2_GLOBAL" => "Test PanDa",
0037     "DST_PASS1_CLUSTERS" => "Test PanDa",
0038     "DST_RECO_CLUSTER" => "Test PanDa"
0039     );
0040 
0041 my %proddesc = (
0042 #    "1" => "hijing (0-12fm) pileup 0-12fm DELETED",
0043 #    "2" => "hijing (0-4.88fm) pileup 0-12fm DELETED",
0044     "3" => "pythia8 pp MB",
0045     "4" => "hijing (0-20fm) pileup 0-20fm",
0046 #    "5" => "hijing (0-12fm) pileup 0-20fm DELETED",
0047     "6" => "hijing (0-4.88fm) pileup 0-20fm",
0048     "7" => "HF pythia8 Charm",
0049     "8" => "HF pythia8 Bottom",
0050     "9" => "HF pythia8 Charm D0",
0051     "10" => "HF pythia8 Bottom D0",
0052     "11" => "JS pythia8 Jet ptmin = 30GeV",
0053     "12" => "JS pythia8 Jet ptmin = 10GeV",
0054     "13" => "JS pythia8 Photon Jet",
0055     "14" => "Single Particles",
0056     "15" => "Special Productions",
0057     "16" => "HF pythia8 D0 Jets",
0058     "17" => "HF pythia8 D0 pi-k Jets ptmin = 5GeV ",
0059     "18" => "HF pythia8 D0 pi-k Jets ptmin = 12GeV",
0060     "19" => "JS pythia8 Jet ptmin = 40GeV",
0061     "20" => "hijing pAu (0-10fm) pileup 0-10fm",
0062     "21" => "JS pythia8 Jet ptmin = 20GeV",
0063     "22" => "cosmic field on",
0064     "23" => "cosmic field off",
0065     "24" => "AMPT",
0066     "25" => "EPOS",
0067     "26" => "JS pythia8 Detroit",
0068     "27" => "JS pythia8 Photonjet ptmin = 5GeV",
0069     "28" => "JS pythia8 Photonjet ptmin = 10GeV",
0070     "29" => "JS pythia8 Photonjet ptmin = 20GeV",
0071     "30" => "Herwig MB",
0072     "31" => "Herwig Jet ptmin = 10 GeV",
0073     "32" => "Herwig Jet ptmin = 30 GeV",
0074     "33" => "JS pythia8 Jet ptmin = 15GeV",
0075     "34" => "JS pythia8 Jet ptmin = 50GeV",
0076     "35" => "JS pythia8 Jet ptmin = 70GeV",
0077     "36" => "JS pythia8 Jet ptmin = 5GeV"
0078     );
0079 
0080 my %pileupdesc = (
0081     "1" => "50kHz for Au+Au, 3MHz for p+p (default)",
0082     "2" => "25kHz for Au+Au",
0083     "3" => "10kHz for Au+Au",
0084     "4" => "1MHz for pp 100us streaming",
0085     "5" => "2MHz for pp 20us streaming",
0086     ">5" => "pileup rate in kHz"
0087     );
0088 
0089 my $nEvents;
0090 my $start_segment;
0091 my $last_segment;
0092 my $randomize;
0093 my $prodtype;
0094 my $runnumber;
0095 my $verbose;
0096 my $nopileup;
0097 my $nobkgpileup;
0098 my $embed;
0099 my $pileup = 1;
0100 my $particle;
0101 my $pmin;
0102 my $pmax;
0103 my $production;
0104 my $momentum;
0105 # that should teach me a lesson to not give a flag an optional string value
0106 # just using embed:s leads to the next ARGV to be used as argument, even if it
0107 # is the next option. Sadly getopt swallows the - so parsing this becomes
0108 # quickly a nightmare, The only solution I see is to read the ARGV's - check for
0109 # the argument in question with a string compare (=~/em/) and then have a look
0110 # at the next argument (if it exists) and check if is is another option (=~/-/)
0111 # and if so use "auau" as default for $embed and push the modified option
0112 # into the new command line ARGV. It defaults to auau if -emb is set but
0113 # neither pau nor auau is given
0114 my @newargs = ();
0115 my $iarg = 0;
0116 foreach my $argument (@ARGV)
0117 {
0118     if (substr($argument,1,2) eq "em")
0119     {
0120     my $firstchar = substr($ARGV[$iarg+1],0,1);
0121     if (! exists $ARGV[$iarg+1] || substr($ARGV[$iarg+1],0,1) eq "-")
0122     {
0123         push(@newargs, $argument);
0124         push(@newargs,"auau");
0125     }
0126     else
0127     {
0128         push(@newargs, $argument);
0129         if ($ARGV[$iarg+1] ne "pau" && $ARGV[$iarg+1] ne "auau" && $ARGV[$iarg+1] ne "central")
0130         {
0131         push(@newargs,"auau");
0132         }
0133     }
0134     }
0135     else
0136     {
0137     push(@newargs,$argument);
0138     }
0139     $iarg++;
0140 }
0141 @ARGV=@newargs;
0142 GetOptions('embed:s' => \$embed, 'l:i' => \$last_segment, 'momentum:s' => \$momentum, 'n:i' => \$nEvents, "nobkgpileup" => \$nobkgpileup, "nopileup" => \$nopileup, "particle:s" => \$particle, 'pileup:i' => \$pileup, "pmin:i" => \$pmin, "pmax:i"=>\$pmax, "production:s"=>\$production, 'rand' => \$randomize, 'run:i' => \$runnumber, 's:i' => \$start_segment, 'type:i' =>\$prodtype, "verbose" =>\$verbose);
0143 my $filenamestring;
0144 my %filetypes = ();
0145 my %notlike = ();
0146 
0147 my $AuAu_pileupstring;
0148 my $pp_pileupstring;
0149 my $pAu_pileupstring;
0150 my $pileupstring;
0151 
0152 if (! defined $runnumber && $#newargs >= 0)
0153 {
0154     print "\nyou need to give a runnumber with -run <runnumber>\n";
0155     print_runs();
0156     exit(1);
0157 }
0158 if (defined $embed && defined $nopileup)
0159 {
0160     print "--embed and --nopileup flags do not work together, it does not make sense\n";
0161     exit(1);
0162 }
0163 if (!defined $embed && defined $nobkgpileup)
0164 {
0165     print "--nobkgpileup flag only valid for embedding (use also --embed)\n";
0166     exit(1);
0167 }
0168 my $pAu_bkgpileup = sprintf("_bkg_0_20fm");
0169 my $AuAu_bkgpileup = sprintf("_bkg_0_10fm");
0170 if ($pileup == 1)
0171 {
0172     $AuAu_pileupstring = sprintf("_50kHz%s",$AuAu_bkgpileup);
0173     $pp_pileupstring = sprintf("_3MHz");
0174     $pAu_pileupstring = sprintf("_500kHz%s",$pAu_bkgpileup);
0175 }
0176 elsif ($pileup == 2)
0177 {
0178     $AuAu_pileupstring = sprintf("_25kHz%s",$AuAu_bkgpileup);
0179 }
0180 elsif ($pileup == 3)
0181 {
0182     $AuAu_pileupstring = sprintf("_10kHz%s",$AuAu_bkgpileup);
0183 }
0184 elsif ($pileup == 4)
0185 {
0186     $pp_pileupstring = sprintf("_1MHz");
0187 }
0188 elsif ($pileup == 5)
0189 {
0190     $pp_pileupstring = sprintf("_2MHz");
0191 }
0192 else
0193 {
0194     $pp_pileupstring = sprintf("_%dkHz",$pileup);
0195     $AuAu_pileupstring = sprintf("_%dkHz%s",$AuAu_bkgpileup);
0196 }
0197 if (defined $nobkgpileup)
0198 {
0199     $pp_pileupstring = sprintf("");
0200     $AuAu_pileupstring = sprintf("");
0201 }
0202 
0203 my $embedok = 0;
0204 
0205 if (defined $prodtype)
0206 {
0207     if ($prodtype == 1)
0208     {
0209         die "This dataset has been deleted\n";
0210     &commonfiletypes();
0211     }
0212     elsif ($prodtype == 2)
0213     {
0214         die "Dataset $prodtype has been deleted\n";
0215     &commonfiletypes();
0216     }
0217     elsif ($prodtype == 3)
0218     {
0219     $filenamestring = "pythia8_pp_mb";
0220     if (! defined $nopileup)
0221     {
0222         $filenamestring = sprintf("%s%s",$filenamestring,$pp_pileupstring);
0223     }
0224         $pileupstring = $pp_pileupstring;
0225     &commonfiletypes();
0226     }
0227     elsif ($prodtype == 4)
0228     {
0229     if (defined $nopileup)
0230     {
0231         $filenamestring = sprintf("sHijing_0_20fm");
0232     }
0233     else
0234     {
0235         $filenamestring = sprintf("sHijing_0_20fm%s",$AuAu_pileupstring);
0236     }
0237         $notlike{$filenamestring} = ["pythia8" ,"single", "special"];
0238         $pileupstring = $AuAu_pileupstring;
0239     &commonfiletypes();
0240     }
0241     elsif ($prodtype == 5)
0242     {
0243     $filenamestring = sprintf("sHijing_0_12fm%s",$AuAu_pileupstring);
0244         die "Dataset $prodtype has been deleted\n";
0245     &commonfiletypes();
0246     }
0247     elsif ($prodtype == 6)
0248     {
0249     if (defined $nopileup)
0250     {
0251         $filenamestring = sprintf("sHijing_0_488fm");
0252     }
0253     else
0254     {
0255       $filenamestring = sprintf("sHijing_0_488fm%s",$AuAu_pileupstring);
0256     }
0257         $notlike{$filenamestring} = ["pythia8" ,"single", "special"];
0258         $pileupstring = $AuAu_pileupstring;
0259     &commonfiletypes();
0260     }
0261     elsif ($prodtype == 7)
0262     {
0263     $filenamestring = "pythia8_Charm";
0264     if (! defined $nopileup)
0265     {
0266         $filenamestring = sprintf("%s%s",$filenamestring,$pp_pileupstring);
0267     }
0268         $pileupstring = $pp_pileupstring;
0269     &commonfiletypes();
0270     }
0271     elsif ($prodtype == 8)
0272     {
0273     $filenamestring = "pythia8_Bottom";
0274     if (! defined $nopileup)
0275     {
0276         $filenamestring = sprintf("%s%s",$filenamestring,$pp_pileupstring);
0277     }
0278         $pileupstring = $pp_pileupstring;
0279     &commonfiletypes();
0280     }
0281     elsif ($prodtype == 9)
0282     {
0283     $filenamestring = "pythia8_CharmD0";
0284     if (! defined $nopileup)
0285     {
0286         $filenamestring = sprintf("%s%s",$filenamestring,$pp_pileupstring);
0287     }
0288         $pileupstring = $pp_pileupstring;
0289     &commonfiletypes();
0290     }
0291     elsif ($prodtype == 10)
0292     {
0293     $filenamestring = "pythia8_BottomD0";
0294     if (! defined $nopileup)
0295     {
0296         $filenamestring = sprintf("%s%s",$filenamestring,$pp_pileupstring);
0297     }
0298         $pileupstring = $pp_pileupstring;
0299     &commonfiletypes();
0300     }
0301     elsif ($prodtype == 11)
0302     {
0303         $embedok = 1;
0304     $filenamestring = "pythia8_Jet30";
0305     if (! defined $nopileup)
0306     {
0307         if (defined $embed)
0308         {
0309         if ($embed eq "pau")
0310         {
0311             $filenamestring = sprintf("%s_sHijing_pAu_0_10fm%s",$filenamestring, $pAu_pileupstring);
0312         }
0313         elsif ($embed eq "central")
0314         {
0315             $filenamestring = sprintf("%s_sHijing_0_488fm%s",$filenamestring, $AuAu_pileupstring);
0316         }
0317         else
0318         {
0319             $filenamestring = sprintf("%s_sHijing_0_20fm%s",$filenamestring, $AuAu_pileupstring);
0320         }
0321         }
0322         else
0323         {
0324         $filenamestring = sprintf("%s%s",$filenamestring,$pp_pileupstring);
0325         }
0326     }
0327         $pileupstring = $pp_pileupstring;
0328     &commonfiletypes();
0329     }
0330     elsif ($prodtype == 12)
0331     {
0332         $embedok = 1;
0333     $filenamestring = "pythia8_Jet10";
0334     if (! defined $nopileup)
0335     {
0336         if (defined $embed)
0337         {
0338         if ($embed eq "pau")
0339         {
0340             $filenamestring = sprintf("%s_sHijing_pAu_0_10fm%s",$filenamestring, $pAu_pileupstring);
0341         }
0342         elsif ($embed eq "central")
0343         {
0344             $filenamestring = sprintf("%s_sHijing_0_488fm%s",$filenamestring, $AuAu_pileupstring);
0345         }
0346         else
0347         {
0348             $filenamestring = sprintf("%s_sHijing_0_20fm%s",$filenamestring, $AuAu_pileupstring);
0349         }
0350         }
0351         else
0352         {
0353         $filenamestring = sprintf("%s%s",$filenamestring,$pp_pileupstring);
0354         }
0355     }
0356         $pileupstring = $pp_pileupstring;
0357     &commonfiletypes();
0358     }
0359     elsif ($prodtype == 13)
0360     {
0361         $embedok = 1;
0362     $filenamestring = "pythia8_PhotonJet";
0363     if (! defined $nopileup)
0364     {
0365         if (defined $embed)
0366         {
0367         if ($embed eq "pau")
0368         {
0369             $filenamestring = sprintf("%s_sHijing_pAu_0_10fm%s",$filenamestring, $pAu_pileupstring);
0370         }
0371         elsif ($embed eq "central")
0372         {
0373             $filenamestring = sprintf("%s_sHijing_0_488fm%s",$filenamestring, $AuAu_pileupstring);
0374         }
0375         else
0376         {
0377             $filenamestring = sprintf("%s_sHijing_0_20fm%s",$filenamestring, $AuAu_pileupstring);
0378         }
0379         }
0380         else
0381         {
0382         $filenamestring = sprintf("%s%s",$filenamestring,$pp_pileupstring);
0383         }
0384     }
0385         $pileupstring = $pp_pileupstring;
0386     &commonfiletypes();
0387     }
0388     elsif ($prodtype == 14)
0389     {
0390         $embedok = 1;
0391         $nopileup = 1;
0392         my $bad = 0;
0393     $filenamestring = "single";
0394     if (!defined $particle)
0395     {
0396         print "-particle: G4 particle name needs to be set for single particle sims\n";
0397         $bad = 1;
0398     }
0399     if ($bad > 0)
0400     {
0401             print "\nExisting single particle sims, use:\n";
0402             print_single_types();
0403         exit(1);
0404     }
0405     if (defined $pmin && defined $pmax)
0406     {
0407         if (defined $momentum)
0408         {
0409         $filenamestring = sprintf("%s_%s_%s_%d_%dMeV",$filenamestring, $particle, $momentum, $pmin, $pmax);
0410         }
0411         else
0412         {
0413         $filenamestring = sprintf("%s_%s_%d_%dMeV",$filenamestring, $particle, $pmin, $pmax);
0414         }
0415 
0416         if (defined $embed)
0417         {
0418         if ($embed eq "pau")
0419         {
0420             $filenamestring = sprintf("%s_sHijing_pAu_0_10fm%s",$filenamestring, $pAu_pileupstring);
0421         }
0422         else
0423         {
0424             $filenamestring = sprintf("%s_sHijing_0_20fm%s",$filenamestring, $AuAu_pileupstring);
0425         }
0426         }
0427     }
0428     else
0429     {
0430         if (defined $embed)
0431         {
0432         if ($embed eq "pau")
0433         {
0434             $filenamestring = sprintf("%s_sHijing_pAu_0_10fm%s",$filenamestring, $pAu_pileupstring);
0435         }
0436         else
0437         {
0438             $filenamestring = sprintf("%s_sHijing_0_20fm%s",$filenamestring, $AuAu_pileupstring);
0439         }
0440         }
0441         else
0442         {
0443         $filenamestring = sprintf("%s_%s",$filenamestring, $particle, $pmin, $pmax);
0444         }
0445     }
0446     &commonfiletypes();
0447     }
0448     elsif ($prodtype == 15)
0449     {
0450         $nopileup = 1;
0451         my $bad = 0;
0452     $filenamestring = "special";
0453     if (! defined $production)
0454     {
0455         $bad = 1;
0456     }
0457     if ($bad > 0)
0458     {
0459             print "\nExisting special sims, use:\n";
0460             print_special_types();
0461         exit(1);
0462     }
0463     $filenamestring = sprintf("%s_%s",$filenamestring, $production);
0464     &commonfiletypes();
0465     }
0466     elsif ($prodtype == 16)
0467     {
0468     $filenamestring = "pythia8_JetD0";
0469     if (! defined $nopileup)
0470     {
0471         $filenamestring = sprintf("%s%s",$filenamestring,$pp_pileupstring);
0472     }
0473         $pileupstring = $pp_pileupstring;
0474     &commonfiletypes();
0475     }
0476     elsif ($prodtype == 17)
0477     {
0478     $filenamestring = "pythia8_CharmD0piKJet5";
0479     if (! defined $nopileup)
0480     {
0481         $filenamestring = sprintf("%s%s",$filenamestring,$pp_pileupstring);
0482     }
0483         $pileupstring = $pp_pileupstring;
0484     &commonfiletypes();
0485     }
0486     elsif ($prodtype == 18)
0487     {
0488     $filenamestring = "pythia8_CharmD0piKJet12";
0489     if (! defined $nopileup)
0490     {
0491         $filenamestring = sprintf("%s%s",$filenamestring,$pp_pileupstring);
0492     }
0493         $pileupstring = $pp_pileupstring;
0494     &commonfiletypes();
0495     }
0496     elsif ($prodtype == 19)
0497     {
0498         $embedok = 1;
0499     $filenamestring = "pythia8_Jet40";
0500     if (! defined $nopileup)
0501     {
0502         if (defined $embed)
0503         {
0504         if ($embed eq "pau")
0505         {
0506             $filenamestring = sprintf("%s_sHijing_pAu_0_10fm%s",$filenamestring, $pAu_pileupstring);
0507         }
0508         elsif ($embed eq "central")
0509         {
0510             $filenamestring = sprintf("%s_sHijing_0_488fm%s",$filenamestring, $AuAu_pileupstring);
0511         }
0512         else
0513         {
0514             $filenamestring = sprintf("%s_sHijing_0_20fm%s",$filenamestring, $AuAu_pileupstring);
0515         }
0516         }
0517         else
0518         {
0519         $filenamestring = sprintf("%s%s",$filenamestring,$pp_pileupstring);
0520         }
0521     }
0522         $pileupstring = $pp_pileupstring;
0523     &commonfiletypes();
0524     }
0525     elsif ($prodtype == 20)
0526     {
0527     if (defined $nopileup)
0528     {
0529         $filenamestring = sprintf("sHijing_pAu_0_10fm");
0530     }
0531     else
0532     {
0533         $filenamestring = sprintf("sHijing_pAu_0_10fm%s",$pAu_pileupstring);
0534     }
0535         $notlike{$filenamestring} = ["pythia8" ,"single", "special"];
0536         $pileupstring = $pAu_pileupstring;
0537     &commonfiletypes();
0538     }
0539     elsif ($prodtype == 21)
0540     {
0541         $embedok = 1;
0542     $filenamestring = "pythia8_Jet20";
0543     if (! defined $nopileup)
0544     {
0545         if (defined $embed)
0546         {
0547         if ($embed eq "pau")
0548         {
0549             $filenamestring = sprintf("%s_sHijing_pAu_0_10fm%s",$filenamestring, $pAu_pileupstring);
0550         }
0551         elsif ($embed eq "central")
0552         {
0553             $filenamestring = sprintf("%s_sHijing_0_488fm%s",$filenamestring, $AuAu_pileupstring);
0554         }
0555         else
0556         {
0557             $filenamestring = sprintf("%s_sHijing_0_20fm%s",$filenamestring, $AuAu_pileupstring);
0558         }
0559         }
0560         else
0561         {
0562         $filenamestring = sprintf("%s%s",$filenamestring,$pp_pileupstring);
0563         }
0564     }
0565         $pileupstring = $pp_pileupstring;
0566     &commonfiletypes();
0567     }
0568     elsif ($prodtype == 22)
0569     {
0570     $filenamestring = "cosmic_magnet_on";
0571         $filenamestring = sprintf("%s",$filenamestring);
0572     $nopileup = 1; # it is no pileup only - no need to require it
0573     &commonfiletypes();
0574     }
0575     elsif ($prodtype == 23)
0576     {
0577     $filenamestring = "cosmic_magnet_off";
0578         $filenamestring = sprintf("%s",$filenamestring);
0579     $nopileup = 1; # it is no pileup only - no need to require it
0580     &commonfiletypes();
0581     }
0582     elsif ($prodtype == 24)
0583     {
0584     if (defined $nopileup)
0585     {
0586         $filenamestring = sprintf("ampt_0_20fm");
0587     }
0588     else
0589     {
0590         $filenamestring = sprintf("ampt_0_20fm%s",$AuAu_pileupstring);
0591     }
0592         $notlike{$filenamestring} = ["pythia8" ,"single", "special"];
0593         $pileupstring = $AuAu_pileupstring;
0594     &commonfiletypes();
0595     }
0596     elsif ($prodtype == 25)
0597     {
0598     if (defined $nopileup)
0599     {
0600         $filenamestring = sprintf("epos_0_153fm");
0601     }
0602     else
0603     {
0604         $filenamestring = sprintf("epos_0_153fm_%s_bkg_0_153fm",$AuAu_pileupstring);
0605     }
0606         $notlike{$filenamestring} = ["pythia8" ,"single", "special"];
0607         $pileupstring = $pAu_pileupstring;
0608     &commonfiletypes();
0609     }
0610     elsif ($prodtype == 26)
0611     {
0612         $embedok = 1;
0613     $filenamestring = "pythia8_Detroit";
0614     if (! defined $nopileup)
0615     {
0616         if (defined $embed)
0617         {
0618         if ($embed eq "pau")
0619         {
0620             $filenamestring = sprintf("%s_sHijing_pAu_0_10fm%s",$filenamestring, $pAu_pileupstring);
0621         }
0622         elsif ($embed eq "central")
0623         {
0624             $filenamestring = sprintf("%s_sHijing_0_488fm%s",$filenamestring, $AuAu_pileupstring);
0625         }
0626         else
0627         {
0628             $filenamestring = sprintf("%s_sHijing_0_20fm%s",$filenamestring, $AuAu_pileupstring);
0629         }
0630         }
0631         else
0632         {
0633         $filenamestring = sprintf("%s%s",$filenamestring,$pp_pileupstring);
0634         }
0635     }
0636         $pileupstring = $pp_pileupstring;
0637     &commonfiletypes();
0638     }
0639     elsif ($prodtype == 27)
0640     {
0641         $embedok = 1;
0642     $filenamestring = "pythia8_PhotonJet5";
0643     if (! defined $nopileup)
0644     {
0645         if (defined $embed)
0646         {
0647         if ($embed eq "pau")
0648         {
0649             $filenamestring = sprintf("%s_sHijing_pAu_0_10fm%s",$filenamestring, $pAu_pileupstring);
0650         }
0651         elsif ($embed eq "central")
0652         {
0653             $filenamestring = sprintf("%s_sHijing_0_488fm%s",$filenamestring, $AuAu_pileupstring);
0654         }
0655         else
0656         {
0657             $filenamestring = sprintf("%s_sHijing_0_20fm%s",$filenamestring, $AuAu_pileupstring);
0658         }
0659         }
0660         else
0661         {
0662         $filenamestring = sprintf("%s%s",$filenamestring,$pp_pileupstring);
0663         }
0664     }
0665         $pileupstring = $pp_pileupstring;
0666     &commonfiletypes();
0667     }
0668     elsif ($prodtype == 28)
0669     {
0670         $embedok = 1;
0671     $filenamestring = "pythia8_PhotonJet10";
0672     if (! defined $nopileup)
0673     {
0674         if (defined $embed)
0675         {
0676         if ($embed eq "pau")
0677         {
0678             $filenamestring = sprintf("%s_sHijing_pAu_0_10fm%s",$filenamestring, $pAu_pileupstring);
0679         }
0680         elsif ($embed eq "central")
0681         {
0682             $filenamestring = sprintf("%s_sHijing_0_488fm%s",$filenamestring, $AuAu_pileupstring);
0683         }
0684         else
0685         {
0686             $filenamestring = sprintf("%s_sHijing_0_20fm%s",$filenamestring, $AuAu_pileupstring);
0687         }
0688         }
0689         else
0690         {
0691         $filenamestring = sprintf("%s%s",$filenamestring,$pp_pileupstring);
0692         }
0693     }
0694         $pileupstring = $pp_pileupstring;
0695     &commonfiletypes();
0696     }
0697     elsif ($prodtype == 29)
0698     {
0699         $embedok = 1;
0700     $filenamestring = "pythia8_PhotonJet20";
0701     if (! defined $nopileup)
0702     {
0703         if (defined $embed)
0704         {
0705         if ($embed eq "pau")
0706         {
0707             $filenamestring = sprintf("%s_sHijing_pAu_0_10fm%s",$filenamestring, $pAu_pileupstring);
0708         }
0709         elsif ($embed eq "central")
0710         {
0711             $filenamestring = sprintf("%s_sHijing_0_488fm%s",$filenamestring, $AuAu_pileupstring);
0712         }
0713         else
0714         {
0715             $filenamestring = sprintf("%s_sHijing_0_20fm%s",$filenamestring, $AuAu_pileupstring);
0716         }
0717         }
0718         else
0719         {
0720         $filenamestring = sprintf("%s%s",$filenamestring,$pp_pileupstring);
0721         }
0722     }
0723         $pileupstring = $pp_pileupstring;
0724     &commonfiletypes();
0725     }
0726     elsif ($prodtype == 30)
0727     {
0728         $embedok = 1;
0729     $filenamestring = "Herwig_MB";
0730     if (! defined $nopileup)
0731     {
0732         if (defined $embed)
0733         {
0734         if ($embed eq "pau")
0735         {
0736             $filenamestring = sprintf("%s_sHijing_pAu_0_10fm%s",$filenamestring, $pAu_pileupstring);
0737         }
0738         elsif ($embed eq "central")
0739         {
0740             $filenamestring = sprintf("%s_sHijing_0_488fm%s",$filenamestring, $AuAu_pileupstring);
0741         }
0742         else
0743         {
0744             $filenamestring = sprintf("%s_sHijing_0_20fm%s",$filenamestring, $AuAu_pileupstring);
0745         }
0746         }
0747         else
0748         {
0749         $filenamestring = sprintf("%s%s",$filenamestring,$pp_pileupstring);
0750         }
0751     }
0752         $pileupstring = $pp_pileupstring;
0753     &commonfiletypes();
0754     }
0755     elsif ($prodtype == 31)
0756     {
0757         $embedok = 1;
0758     $filenamestring = "Herwig_Jet10";
0759     if (! defined $nopileup)
0760     {
0761         if (defined $embed)
0762         {
0763         if ($embed eq "pau")
0764         {
0765             $filenamestring = sprintf("%s_sHijing_pAu_0_10fm%s",$filenamestring, $pAu_pileupstring);
0766         }
0767         elsif ($embed eq "central")
0768         {
0769             $filenamestring = sprintf("%s_sHijing_0_488fm%s",$filenamestring, $AuAu_pileupstring);
0770         }
0771         else
0772         {
0773             $filenamestring = sprintf("%s_sHijing_0_20fm%s",$filenamestring, $AuAu_pileupstring);
0774         }
0775         }
0776         else
0777         {
0778         $filenamestring = sprintf("%s%s",$filenamestring,$pp_pileupstring);
0779         }
0780     }
0781         $pileupstring = $pp_pileupstring;
0782     &commonfiletypes();
0783     }
0784     elsif ($prodtype == 32)
0785     {
0786         $embedok = 1;
0787     $filenamestring = "Herwig_Jet30";
0788     if (! defined $nopileup)
0789     {
0790         if (defined $embed)
0791         {
0792         if ($embed eq "pau")
0793         {
0794             $filenamestring = sprintf("%s_sHijing_pAu_0_10fm%s",$filenamestring, $pAu_pileupstring);
0795         }
0796         elsif ($embed eq "central")
0797         {
0798             $filenamestring = sprintf("%s_sHijing_0_488fm%s",$filenamestring, $AuAu_pileupstring);
0799         }
0800         else
0801         {
0802             $filenamestring = sprintf("%s_sHijing_0_20fm%s",$filenamestring, $AuAu_pileupstring);
0803         }
0804         }
0805         else
0806         {
0807         $filenamestring = sprintf("%s%s",$filenamestring,$pp_pileupstring);
0808         }
0809     }
0810         $pileupstring = $pp_pileupstring;
0811     &commonfiletypes();
0812     }
0813     elsif ($prodtype == 33)
0814     {
0815         $embedok = 1;
0816     $filenamestring = "pythia8_Jet15";
0817     if (! defined $nopileup)
0818     {
0819         if (defined $embed)
0820         {
0821         if ($embed eq "pau")
0822         {
0823             $filenamestring = sprintf("%s_sHijing_pAu_0_10fm%s",$filenamestring, $pAu_pileupstring);
0824         }
0825         elsif ($embed eq "central")
0826         {
0827             $filenamestring = sprintf("%s_sHijing_0_488fm%s",$filenamestring, $AuAu_pileupstring);
0828         }
0829         else
0830         {
0831             $filenamestring = sprintf("%s_sHijing_0_20fm%s",$filenamestring, $AuAu_pileupstring);
0832         }
0833         }
0834         else
0835         {
0836         $filenamestring = sprintf("%s%s",$filenamestring,$pp_pileupstring);
0837         }
0838     }
0839         $pileupstring = $pp_pileupstring;
0840     &commonfiletypes();
0841     }
0842     elsif ($prodtype == 34)
0843     {
0844         $embedok = 1;
0845     $filenamestring = "pythia8_Jet50";
0846     if (! defined $nopileup)
0847     {
0848         if (defined $embed)
0849         {
0850         if ($embed eq "pau")
0851         {
0852             $filenamestring = sprintf("%s_sHijing_pAu_0_10fm%s",$filenamestring, $pAu_pileupstring);
0853         }
0854         elsif ($embed eq "central")
0855         {
0856             $filenamestring = sprintf("%s_sHijing_0_488fm%s",$filenamestring, $AuAu_pileupstring);
0857         }
0858         else
0859         {
0860             $filenamestring = sprintf("%s_sHijing_0_20fm%s",$filenamestring, $AuAu_pileupstring);
0861         }
0862         }
0863         else
0864         {
0865         $filenamestring = sprintf("%s%s",$filenamestring,$pp_pileupstring);
0866         }
0867     }
0868         $pileupstring = $pp_pileupstring;
0869     &commonfiletypes();
0870     }
0871     elsif ($prodtype == 35)
0872     {
0873         $embedok = 1;
0874     $filenamestring = "pythia8_Jet70";
0875     if (! defined $nopileup)
0876     {
0877         if (defined $embed)
0878         {
0879         if ($embed eq "pau")
0880         {
0881             $filenamestring = sprintf("%s_sHijing_pAu_0_10fm%s",$filenamestring, $pAu_pileupstring);
0882         }
0883         elsif ($embed eq "central")
0884         {
0885             $filenamestring = sprintf("%s_sHijing_0_488fm%s",$filenamestring, $AuAu_pileupstring);
0886         }
0887         else
0888         {
0889             $filenamestring = sprintf("%s_sHijing_0_20fm%s",$filenamestring, $AuAu_pileupstring);
0890         }
0891         }
0892         else
0893         {
0894         $filenamestring = sprintf("%s%s",$filenamestring,$pp_pileupstring);
0895         }
0896     }
0897         $pileupstring = $pp_pileupstring;
0898     &commonfiletypes();
0899     }
0900     elsif ($prodtype == 36)
0901     {
0902         $embedok = 1;
0903     $filenamestring = "pythia8_Jet5";
0904     if (! defined $nopileup)
0905     {
0906         if (defined $embed)
0907         {
0908         if ($embed eq "pau")
0909         {
0910             $filenamestring = sprintf("%s_sHijing_pAu_0_10fm%s",$filenamestring, $pAu_pileupstring);
0911         }
0912         elsif ($embed eq "central")
0913         {
0914             $filenamestring = sprintf("%s_sHijing_0_488fm%s",$filenamestring, $AuAu_pileupstring);
0915         }
0916         else
0917         {
0918             $filenamestring = sprintf("%s_sHijing_0_20fm%s",$filenamestring, $AuAu_pileupstring);
0919         }
0920         }
0921         else
0922         {
0923         $filenamestring = sprintf("%s%s",$filenamestring,$pp_pileupstring);
0924         }
0925     }
0926         $pileupstring = $pp_pileupstring;
0927     &commonfiletypes();
0928     }
0929 
0930     else
0931     {
0932     print "no production type $prodtype\n";
0933     exit(1);
0934     }
0935     &fill_other_types();
0936 }
0937 
0938 if (defined $embed && ! $embedok)
0939 {
0940     print "Embedding not implemented for type $prodtype\n";
0941     exit(1);
0942 }
0943 
0944 my $filenamestring_with_runnumber = sprintf("%s\-%010d-",$filenamestring,$runnumber);
0945 if ($#ARGV < 0)
0946 {
0947     if (! defined $prodtype)
0948     {
0949     print "usage: CreateFileLists.pl -type <production type> <filetypes>\n";
0950     print "parameters:\n";
0951     print "-embed : pp embedded into MB AuAu hijing (only for pp types)\n";
0952     print "  -embed pau : embedded into pAu (only for pp types)\n";
0953     print "  -embed central : embedded into central AuAu\n";
0954     print "-l     : last segment\n";
0955     print "-n     : <number of events>\n";
0956     print "-nopileup : without pileup\n";
0957     print "-nobkgpileup : background without pileup (use with -embed)\n";
0958     print "-rand  : randomize segments used\n";
0959     print "-run   : runnumber (mandatory, no default anymore)\n";
0960     print "-s     : starting segment (remember first segment is 0)\n";
0961     print "\n-type  : production type\n";
0962     foreach my $pd (sort { $a <=> $b } keys %proddesc)
0963     {
0964         print "    $pd : $proddesc{$pd}\n";
0965     }
0966     print "\n-pileup : pileup rate selection (default = $pileup)\n";
0967     foreach my $pd (sort { $a <=> $b } keys %pileupdesc)
0968     {
0969         print "    $pd : $pileupdesc{$pd}\n";
0970     }
0971     print "\n-nobkgpileup : no pileup of background event (use with -embed)\n";
0972         print "\n Single particle mandatory options:\n";
0973         print "-particle : G4 particle name\n";
0974         print "-mom : (optional) p or pt\n";
0975         print "-pmin : minimum momentum (in MeV/c)\n";
0976         print "-pmax : maximum momentum (in MeV/c)\n";
0977 
0978         print "\n Special production mandatory options:\n";
0979         print "-production : production name\n";
0980 
0981     print "\navailable file types (choose at least one, --> means: written to):\n";
0982     foreach my $tp (sort keys %dsttype)
0983     {
0984         if (! exists $exclude_these{$tp})
0985         {
0986         print "$tp  --> $dsttype{$tp}\n";
0987         }
0988     }
0989     }
0990     else
0991     {
0992     print "\navailable file types for -type $prodtype: $proddesc{$prodtype}:\n";
0993     foreach my $tp (sort keys %filetypes)
0994     {
0995         print "\t$tp : $filetypes{$tp}\n";
0996     }
0997     }
0998 
0999     exit(0);
1000 }
1001 
1002 if (defined $randomize && ! defined $nEvents)
1003 {
1004     print "randomizing segments only if number of events is selected\n";
1005     exit(0);
1006 }
1007 
1008 if (! defined $prodtype )
1009 {
1010     print "need to give production type\n";
1011     print "-type : production type\n";
1012     foreach my $pd (sort keys %proddesc)
1013     {
1014     print "    $pd : $proddesc{$pd}\n";
1015     }
1016     exit(0);
1017 }
1018 if (! exists $proddesc{$prodtype})
1019 {
1020     print  "invalid production type $prodtype, valid values\n";
1021     print "-type : production type\n";
1022     foreach my $pd (sort keys %proddesc)
1023     {
1024     print "    $pd : $proddesc{$pd}\n";
1025     }
1026     exit(0);
1027 }
1028 
1029 #check dst types
1030 my %req_types = ();
1031 
1032 # hash of {dsttype} containing hash of segment,filename
1033 my %allfilehash = ();
1034 
1035 my %allevthash = ();
1036 
1037 my %nocombine = ();
1038 &fill_nocombine_files;
1039 
1040 while($#ARGV >= 0)
1041 {
1042     if (! exists $dsttype{$ARGV[0]})
1043     {
1044     print "dst type $ARGV[0] does not exist\n";
1045     print "\navailable types:\n";
1046     foreach my $tp (sort keys %dsttype)
1047     {
1048         print "$tp\n";
1049     }
1050     exit(1);
1051     }
1052     if (exists $req_types{$ARGV[0]})
1053     {
1054     print "please no duplicate file types ($ARGV[0])\n";
1055     exit(1);
1056     }
1057 
1058     if (exists $nocombine{$ARGV[0]})
1059     {
1060     if ($#ARGV >= 1 || keys %req_types > 0)
1061     {
1062         print "File type $ARGV[0] cannot be combined with other files\n";
1063         exit(1);
1064     }
1065     }
1066     $req_types{$ARGV[0]} = 1;
1067     $allfilehash{$ARGV[0]} = ();
1068     $allevthash{$ARGV[0]} = ();
1069     shift (@ARGV);
1070 
1071 }
1072 print "This Can Take a While (10 minutes depending on the amount of events and the number of file types you want)\n";
1073 my $conds = sprintf("dsttype = ? and filename like \'\%%%s\%\'",$filenamestring_with_runnumber);
1074 
1075 if (exists $notlike{$filenamestring})
1076 {
1077     my $ref = $notlike{$filenamestring};
1078     foreach my $item  (@$ref)
1079     {
1080     $conds = sprintf("%s and filename not like  \'\%%%s\%\'",$conds,$item);
1081     }
1082 }
1083 if (defined $start_segment)
1084 {
1085     $conds = sprintf("%s and segment >= %d",$conds,$start_segment);
1086 }
1087 if (defined $last_segment)
1088 {
1089     if (defined $start_segment)
1090     {
1091     if ($last_segment < $start_segment)
1092     {
1093         print "last segment: (-l $last_segment) smaller than start segment: (-s $start_segment), I will try but you will not get anything\n";
1094     }
1095     }
1096     $conds = sprintf("%s and segment <= %d",$conds,$last_segment);
1097 }
1098 my $getfilesql = sprintf("select filename,segment,events from datasets where %s order by segment",$conds);
1099 #my $getfilesql = sprintf("select filename,segment,events from datasets where %s ",$conds);
1100 
1101 my %getfiles = ();
1102 foreach  my $tp (keys %req_types)
1103 {
1104     if ($tp eq "G4Hits" || $tp eq "G4HitsOld")
1105     {
1106     if (defined $embed)
1107     {
1108         print "Selecting G4Hits with -embed is not supported (and does not make sense)\n";
1109         exit(1);
1110     }
1111     my $newfilenamestring;
1112     if (defined $nopileup) # for no pileup we have the string already (G4Hits are nopileup)
1113     {
1114         my @sp1 = split(/-/,$filenamestring_with_runnumber);
1115         $newfilenamestring = $filenamestring_with_runnumber;
1116     }
1117     else
1118     {
1119         my $splitstring = sprintf("%s",$pileupstring);
1120             my @sp2 = split(/$splitstring/,$filenamestring_with_runnumber);
1121         $newfilenamestring = sprintf("%s-%010d-",$sp2[0],$runnumber);
1122     }
1123     my $newgetfilesql = $getfilesql;
1124     $newgetfilesql =~ s/$filenamestring_with_runnumber/$newfilenamestring/;
1125     $getfiles{"G4Hits"} = $dbh->prepare($newgetfilesql);
1126     $getfiles{"G4HitsOld"} = $dbh->prepare($newgetfilesql);
1127     if (defined $verbose)
1128     {
1129         print "sql (newgetfilesql): $newgetfilesql\n";
1130     }
1131     }
1132     else
1133     {
1134     $getfiles{$tp} = $dbh->prepare($getfilesql);
1135     if (defined $verbose)
1136     {
1137         print "sql (getfilesql): $getfilesql\n";
1138     }
1139     }
1140 }
1141 #die;
1142 # here we fill the big hash with all segments/files for all requested filetypes
1143 if (defined $verbose)
1144 {
1145     print "fetching files from DB done, hashing all of them\n";
1146 }
1147 foreach my $tp (sort keys %req_types)
1148 {
1149     my %dsthash = ();
1150     my %evthash = ();
1151     $getfiles{$tp}->execute($tp);
1152     if ($getfiles{$tp}->rows == 0)
1153     {
1154     print "no files for type $tp\n";
1155     exit(0);
1156     }
1157     while (my @res = $getfiles{$tp}->fetchrow_array())
1158     {
1159     my $hashkey = sprintf("%05d",$res[1]);
1160     $dsthash{$hashkey} = $res[0];
1161     $evthash{$res[0]} = $res[2];
1162     }
1163     $allfilehash{$tp} = \%dsthash;
1164     $allevthash{$tp} = \%evthash;
1165 }
1166 
1167 my $entries = 200000000; # given that we have 200k files max, this value is always higher
1168 my $lowtype;
1169 # here we find the dst type with the smallest number of entries (segments)
1170 # so we do not loop too much when finding matches for the other types
1171 if (defined $verbose)
1172 {
1173     print "hashing done, finding hash with lowest number of entries\n";
1174 }
1175 foreach my $tp (sort { $a <=> $b } keys %allfilehash)
1176 {
1177     if ($entries > keys %{$allfilehash{$tp}})
1178     {
1179     $entries = keys %{$allfilehash{$tp}};
1180     $lowtype = $tp;
1181     }
1182 }
1183 # here $lowtype is the dst type with the smallest number of segments
1184 #print "lowest entries: $entries, type: $lowtype\n";
1185 #print Dumper(%allevthash);
1186 if (defined $verbose)
1187 {
1188     print "matching hashes\n";
1189 }
1190 
1191 my @segarray = ();
1192 foreach my $seg (sort { $a <=> $b } keys %{$allfilehash{$lowtype}})
1193 {
1194     foreach my $tp (sort { $a <=> $b } keys %allfilehash)
1195     {
1196     if ($tp eq $lowtype)
1197     {
1198         next;
1199     }
1200     if (! exists  $allfilehash{$tp}{$seg})
1201     {
1202         last;
1203     }
1204     }
1205     push(@segarray,$seg);
1206 }
1207 # in segarray we have the common segments of all files now
1208 
1209 # remove segments from array when number of events is reached
1210 # randomize segments when -r is set
1211 if (defined $nEvents)
1212 {
1213     if (defined $randomize)
1214     {
1215     @segarray = shuffle(@segarray);
1216     }
1217     my @tmparray = ();
1218     foreach my $seg (@segarray)
1219     {
1220     push(@tmparray,$seg);
1221     $nEvents -= $allevthash{$lowtype}{$allfilehash{$lowtype}{$seg}};
1222     if ($nEvents <= 0)
1223     {
1224         last;
1225     }
1226     }
1227     @segarray = @tmparray;
1228 }
1229 # sort list of segments and write to output file
1230 my $nSelectedEvents = 0;
1231 my %filesorted = ();
1232 foreach my $seg (@segarray)
1233 #foreach my $seg (sort { $a <=> $b } @segarray)
1234 {
1235     $nSelectedEvents += $allevthash{$lowtype}{$allfilehash{$lowtype}{$seg}};
1236 #   print "segment $seg is good\n";
1237 #    foreach my $tp (sort keys %allfilehash)
1238     foreach my $tp (keys %allfilehash)
1239     {
1240 #       print "using $allfilehash{$tp}{$seg}\n";
1241 #   my $printcmd = sprintf("echo %s >> %s",$allfilehash{$tp}{$seg},$dsttype{$tp});
1242     $filesorted{$dsttype{$tp}}{$allfilehash{$tp}{$seg}} = 1;
1243 #   print "$printcmd\n";
1244 #   system($printcmd);
1245     }
1246 
1247 }
1248 foreach my $listfile (keys %filesorted)
1249 {
1250     open(F3,">$listfile");
1251     foreach my $fil (sort keys %{$filesorted{$listfile}})
1252     {
1253     print F3 "$fil\n";
1254     }
1255     close(F3);
1256 }
1257 print "wrote the following list files containing >= $nSelectedEvents events:\n";
1258 foreach my $tp (sort { $a <=> $b } keys %allfilehash)
1259 {
1260     print "$dsttype{$tp}\n";
1261 }
1262 
1263 
1264 $getdsttypes->finish();
1265 foreach my $tp (keys %getfiles)
1266 {
1267     $getfiles{$tp}->finish();
1268 }
1269 $dbh->disconnect;
1270 
1271 sub commonfiletypes
1272 {
1273 # for no pileup pass(X) --> pass(X-1)
1274 # pass1
1275     $filetypes{"G4Hits"} = "G4 Hits";
1276 #    $filetypes{"G4HitsOld"} = "Old G4 Hits";
1277 # pass2
1278     $filetypes{"DST_BBC_G4HIT"} = "Pileup BBC (now MBD), EPD G4Hits";
1279     $filetypes{"DST_CALO_G4HIT"} = "Pileup Calorimeter G4Hits";
1280     $filetypes{"DST_TRKR_G4HIT"} = "Pileup Tracking Detector G4 Hits";
1281     $filetypes{"DST_TRUTH_G4HIT"} = "temporary Pileup Truth info, use DST_TRUTH";
1282 # pass3 mbdepd
1283     $filetypes{"DST_MBD_EPD"} = "Reconstructed Mbd, Epd";
1284 # pass3 calo
1285     $filetypes{"DST_CALO_CLUSTER"} = "Reconstructed Calorimeter Towers and Clusters";
1286 #pass3 trk
1287     $filetypes{"DST_TRKR_HIT"} = "TPC and Silicon Hits";
1288     $filetypes{"DST_TRUTH"} = "Truth Info (updated with Clusters)";
1289 #pass4 truth jets
1290     $filetypes{"DST_TRUTH_JET"} = "Truth Jets";
1291 #pass4 tracks
1292     $filetypes{"DST_TRKR_CLUSTER"} = "pass0 output: tpc clusters";
1293     $filetypes{"DST_TRACKSEEDS"} = "passA output: track seeds";
1294     $filetypes{"DST_TRACKS"} = "passC output: Reconstructed Tracks";
1295 #pass5 tracks/clusters
1296     $filetypes{"DST_GLOBAL"} = "Global Info (MBD, sEPD, Vertex)";
1297     $filetypes{"DST_TRUTH_RECO"} = "digested track truth info";
1298 }
1299 
1300 
1301 # here are filetypes which are ntuples or cannot be combined
1302 # with other files for any other reason
1303 sub fill_nocombine_files
1304 {
1305     $nocombine{"JET_EVAL_DST_HF_CHARM"} = 1;
1306     $nocombine{"JET_EVAL_DST_HF_BOTTOM"} = 1;
1307     $nocombine{"QA_DST_HF_CHARM"} = 1;
1308     $nocombine{"QA_DST_HF_BOTTOM"} = 1;
1309 }
1310 
1311 sub fill_other_types
1312 {
1313     my $sqlstring = sprintf("select distinct(dsttype) from datasets where filename like '%%%s%%'",$filenamestring);
1314     my $getalltypes = $dbh->prepare($sqlstring);
1315     $getalltypes->execute();
1316     while (my @res = $getalltypes->fetchrow_array())
1317     {
1318     if (! exists $filetypes{$res[0]})
1319     {
1320         $filetypes{$res[0]} = "No Description";
1321     }
1322     }
1323     $getalltypes->finish();
1324 }
1325 
1326 sub print_single_types
1327 {
1328     my $sqlstring = sprintf("select filename from datasets where runnumber = %d and filename like '%%_single_%%' and segment=0",$runnumber);
1329     my $getallfiles = $dbh->prepare($sqlstring);
1330     $getallfiles->execute();
1331     my $runsplit = sprintf("MeV-%010d",$runnumber);
1332     my $runsplit_embed = sprintf("_sHijing_0_20fm");
1333     my $runsplit_runnumber = sprintf("-%010d",$runnumber);
1334     my %types = ();
1335     my %dsts = ();
1336     while (my @res = $getallfiles->fetchrow_array())
1337     {
1338     my @sp1 = split(/_single_/,$res[0]);
1339         my @sp2;
1340         my $typeflag = "";
1341     if ($sp1[1] =~ /MeV/)
1342     {
1343         @sp2 = split(/$runsplit/,$sp1[1]);
1344     }
1345     if ($sp1[1] =~ /$runsplit_embed/)
1346     {
1347         @sp2 = split(/$runsplit_embed/,$sp1[1]);
1348             $typeflag = "-embed ";
1349     }
1350     else
1351     {
1352         @sp2 = split(/$runsplit_runnumber/,$sp1[1]);
1353     }
1354     $types{$sp2[0]} = $typeflag;
1355         $dsts{$sp1[0]} = 1;
1356     }
1357     $getallfiles->finish();
1358     foreach my $name (sort keys %types)
1359     {
1360     if ($name =~ /(\S+)\_(\d+)\_(\d+).*/ )
1361     {
1362         my $part = $1;
1363             my $mom;
1364             my $minp = $2;
1365             my $maxp = $3;
1366         if ($part =~ /(\S+)_(\S+)/)
1367         {
1368         $part = $1;
1369         $mom = $2;
1370         }
1371         if (defined $mom)
1372         {
1373         print "CreateFileList.pl -type 14 $types{$name} -run $runnumber -particle $part -mom $mom -pmin $minp -pmax $maxp\n";
1374         }
1375         else
1376             {
1377                 print "CreateFileList.pl -type 14 $types{$name} -run $runnumber -particle $part -pmin $minp -pmax $maxp\n";
1378             }
1379     }
1380         else
1381         {
1382             print "CreateFileList.pl -type 14 $types{$name} -run $runnumber -particle $name\n";
1383 
1384         }
1385     }
1386     print "\nDST types:\n";
1387     foreach my $name (sort keys %dsts)
1388     {
1389     print "$name\n";
1390     }
1391 }
1392 
1393 sub print_special_types
1394 {
1395     my $sqlstring = sprintf("select filename from datasets where runnumber = %d and filename like '%%_special_%%'",$runnumber);
1396     my $getallfiles = $dbh->prepare($sqlstring);
1397     $getallfiles->execute();
1398     my $runsplit = sprintf("-%010d",$runnumber);
1399     my %types = ();
1400     my %dsts = ();
1401     while (my @res = $getallfiles->fetchrow_array())
1402     {
1403     my @sp1 = split(/_special_/,$res[0]);
1404     my @sp2 = split(/$runsplit/,$sp1[1]);
1405     $types{$sp2[0]} = 1;
1406         $dsts{$sp1[0]} = 1;
1407     }
1408     $getallfiles->finish();
1409     foreach my $name (sort keys %types)
1410     {
1411         print "CreateFileList.pl -type 15 -production $name\n";
1412     }
1413     print "\nDST types:\n";
1414     foreach my $name (sort keys %dsts)
1415     {
1416         print "$name\n";
1417     }
1418 }
1419 
1420 sub print_runs
1421 {
1422     my $getrunnumbers = $dbh->prepare("select distinct(runnumber) from datasets where dataset = 'mdc2' order by runnumber");
1423     $getrunnumbers->execute();
1424     print "Available Runs (check our wiki for more details for each runnumber):\n";
1425     while(my @res = $getrunnumbers->fetchrow_array())
1426     {
1427     print "$res[0]\n";
1428     }
1429     print "NB: Not all DSTs are available for all runs\n";
1430     $getrunnumbers->finish();
1431 }