CMS 3D CMS Logo

harvestHGCalValidationPlots.py
Go to the documentation of this file.
1 #!/usr/bin/env python3
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  print("Warning: this script is deprecated and will be removed in the future. Please use the step4_HARVESTING.py step provided by cmsDriver in your workflow instead.")
10  # define options
11  parser = argparse.ArgumentParser(description="Harvest track validation plots")
12  parser.add_argument("files", metavar="file", type=str, nargs="+",
13  help="files to be harvested (convert edm DQM format to plain ROOT format")
14  parser.add_argument("-o", "--outputFile", type=str, default="harvest.root",
15  help="output file (default: 'harvest.root')")
16 
17  opts = parser.parse_args()
18 
19  # absolute path outputFile
20  outputFile = os.path.abspath(opts.outputFile)
21 
22  # check the input files
23  for f in opts.files:
24  if not os.path.exists(f):
25  parser.error("DQM file %s does not exist" % f)
26 
27  # compile a file list for cmsDriver
28  filelist = ",".join(["file:{0}".format(os.path.abspath(_file)) for _file in opts.files])
29 
30  # go to a temporary directory
31  _cwd = os.getcwd()
32  _tempdir = tempfile.mkdtemp()
33  os.chdir(_tempdir)
34 
35  # compile cmsDriver command
36  cmsDriverCommand = "cmsDriver.py harvest --scenario pp --filetype DQM --conditions auto:phase2_realistic --mc -s HARVESTING:@JetMETOnlyValidation+@HGCalValidation -n -1 --filein {0}".format(filelist)
37  print("# running cmsDriver" + "\n" + cmsDriverCommand)
38 
39  # run it
40  subprocess.call(cmsDriverCommand.split(" "))
41 
42  # find the output and move it to the specified output file path
43  ofiles = glob.glob("DQM*.root")
44  if len(ofiles) != 1:
45  print("ERROR: expecting exactly one output file matching DQM*.root")
46  print(" ls of current directory({0}):".format(_tempdir))
47  os.system("ls -lt")
48  sys.exit()
49  shutil.move(ofiles[0],outputFile)
50 
51  # move back to the original directory
52  os.chdir(_cwd)
53 
54  # and get rid of the temporary directory
55  shutil.rmtree(_tempdir)
void print(TMatrixD &m, const char *label=nullptr, bool mathematicaFormat=false)
Definition: Utilities.cc:47
static std::string join(char **cmd)
Definition: RemoteFile.cc:21