CMS 3D CMS Logo

harvestHGCalValidationPlots.py
Go to the documentation of this file.
1 #!/usr/bin/env python
2 
3 from __future__ import print_function
4 import sys,os,tempfile,shutil,subprocess,glob
5 import argparse
6 
7 if __name__ == "__main__":
8 
9  # define options
10  parser = argparse.ArgumentParser(description="Harvest track validation plots")
11  parser.add_argument("files", metavar="file", type=str, nargs="+",
12  help="files to be harvested (convert edm DQM format to plain ROOT format")
13  parser.add_argument("-o", "--outputFile", type=str, default="harvest.root",
14  help="output file (default: 'harvest.root')")
15 
16  opts = parser.parse_args()
17 
18  # absolute path outputFile
19  outputFile = os.path.abspath(opts.outputFile)
20 
21  # check the input files
22  for f in opts.files:
23  if not os.path.exists(f):
24  parser.error("DQM file %s does not exist" % f)
25 
26  # compile a file list for cmsDriver
27  filelist = ",".join(["file:{0}".format(os.path.abspath(_file)) for _file in opts.files])
28 
29  # go to a temporary directory
30  _cwd = os.getcwd()
31  _tempdir = tempfile.mkdtemp()
32  os.chdir(_tempdir)
33 
34  # compile cmsDriver command
35  cmsDriverCommand = "cmsDriver.py harvest --scenario pp --filetype DQM --conditions auto:phase2_realistic --mc -s HARVESTING:@JetMETOnlyValidation+@HGCalValidation -n -1 --filein {0}".format(filelist)
36  print("# running cmsDriver" + "\n" + cmsDriverCommand)
37 
38  # run it
39  subprocess.call(cmsDriverCommand.split(" "))
40 
41  # find the output and move it to the specified output file path
42  ofiles = glob.glob("DQM*.root")
43  if len(ofiles) != 1:
44  print("ERROR: expecting exactly one output file matching DQM*.root")
45  print(" ls of current directory({0}):".format(_tempdir))
46  os.system("ls -lt")
47  sys.exit()
48  shutil.move(ofiles[0],outputFile)
49 
50  # move back to the original directory
51  os.chdir(_cwd)
52 
53  # and get rid of the temporary directory
54  shutil.rmtree(_tempdir)
S & print(S &os, JobReport::InputFile const &f)
Definition: JobReport.cc:66
static std::string join(char **cmd)
Definition: RemoteFile.cc:17