CMS 3D CMS Logo

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