Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:32:36

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