File indexing completed on 2024-04-06 12:13:29
0001
0002
0003 if (@ARGV < 4) {
0004 print<<HEAD
0005
0006 This code converts a DataCard to a python fragment for DataCardFileWriter.
0007
0008 Syntax:
0009
0010 ConvertDataCardToPython {inputfile} {outputfile} {fragmentname} {datacardname}
0011
0012 inputfile - The name of the input file to be converted to a python fragment for DataCardFileWriter
0013 outputfile - The name of the output file that is to contain DataCardFileWriter python fragment
0014 fragmentname - The name of the python fragment
0015 datacardname - The name of the datacard to be written out by DataCardFileWriter
0016
0017 Example [from within GeneratorInterface/EvtGenInterface/python/]:
0018 ../test/ConvertDataCardToPython.pl ../data/DECAY_2010.DEC test_cff.py mywriter DECAY_2010.DEC
0019
0020 HEAD
0021 ;
0022 }
0023 else {
0024 $inputfile=$ARGV[0];
0025 $outputfile=$ARGV[1];
0026 $fragmentname=$ARGV[2];
0027 $datacardname=$ARGV[3];
0028
0029 if(-e $outputfile){
0030 printf("Output File already exists: $outputfile \nRemove it and try again...");
0031 exit();
0032 }
0033
0034 @DataSets;
0035 open(InDAT, $inputfile) || die("Could not open file $inputfile!\n");
0036 while ($item = <InDAT>) {
0037 chomp($item);
0038 push(@DataSets,$item);
0039 }
0040 close(InDAT);
0041
0042 open(OutDAT, '>>', $outputfile) || die("Could not open file $inputfile!");
0043 print {OutDAT} "import FWCore.ParameterSet.Config as cms\n";
0044 print {OutDAT} "$fragmentname = cms.EDAnalyzer(\"DataCardFileWriter\",\n";
0045 print {OutDAT} "\tFileName = cms.string(\"$datacardname\"),\n";
0046 print {OutDAT} "\tFileContent = cms.vstring()\n";
0047 print {OutDAT} "\t)\n";
0048 $i=0;
0049 $j=0;
0050 $nlines = @DataSets;
0051
0052 foreach $DS (@DataSets){
0053 if($i==255){
0054 $i=0;
0055 print {OutDAT} "\t])\n";
0056 }
0057 if($i==0){
0058 print {OutDAT} "$fragmentname.FileContent.extend([\n";
0059 }
0060 $i++;
0061 $j++;
0062 $comma=",";
0063 if($i==255 || $j==$nlines){ $comma="";}
0064 $DS =~ s/\\/\\\\\\\\/g;
0065 $DS =~ s/\"/\\"/g;
0066 print {OutDAT} "\t\"$DS\"$comma\n";
0067 }
0068 print {OutDAT} "\t])\n";
0069 close(OutDAT);
0070 }