Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-11-26 02:34:40

0001 #!/usr/bin/env python3
0002 
0003 import sys,os,tempfile,shutil,subprocess,glob
0004 import argparse
0005 
0006 if __name__ == "__main__":
0007 
0008     # define options
0009     parser = argparse.ArgumentParser(description="Harvest track validation plots")
0010     parser.add_argument("files", metavar="file", type=str, nargs="+",
0011                         help="files to be harvested (convert edm DQM format to plain ROOT format")
0012     parser.add_argument("-o", "--outputFile", type=str, default="harvest.root",
0013                         help="output file (default: 'harvest.root')")
0014 
0015     opts = parser.parse_args()
0016 
0017     # absolute path outputFile
0018     outputFile = os.path.abspath(opts.outputFile)
0019 
0020     # check the input files
0021     for f in opts.files:
0022         if not os.path.exists(f):
0023             parser.error("DQM file %s does not exist" % f)
0024 
0025     # compile a file list for cmsDriver
0026     filelist = ",".join(["file:{0}".format(os.path.abspath(_file)) for _file in opts.files])
0027 
0028     # go to a temporary directory
0029     _cwd = os.getcwd()
0030     _tempdir = tempfile.mkdtemp()
0031     os.chdir(_tempdir)
0032 
0033     # compile cmsDriver command
0034     cmsDriverCommand = "cmsDriver.py harvest --scenario pp --filetype DQM --conditions auto:run2_mc --mc -s HARVESTING:@trackingOnlyValidation+@trackingOnlyDQM+postProcessorHLTtrackingSequence -n -1 --filein {0}".format(filelist)
0035     print("# running cmsDriver" + "\n" + cmsDriverCommand)
0036     
0037     # run it
0038     subprocess.call(cmsDriverCommand.split(" "))
0039 
0040     # find the output and move it to the specified output file path
0041     ofiles = glob.glob("DQM*.root")
0042     if len(ofiles) != 1:
0043         print("ERROR: expecting exactly one output file matching DQM*.root")
0044         print("  ls of current directory({0}):".format(_tempdir))
0045         os.system("ls -lt")
0046         sys.exit()
0047     shutil.move(ofiles[0],outputFile)
0048     
0049     # move back to the original directory
0050     os.chdir(_cwd)
0051 
0052     # and get rid of the temporary directory
0053     shutil.rmtree(_tempdir)
0054