CMS 3D CMS Logo

mps_monitormerge.py
Go to the documentation of this file.
1 #!/usr/bin/env python
2 
3 import os
4 import subprocess
5 import argparse
6 import Alignment.MillePedeAlignmentAlgorithm.mpslib.Mpslibclass as mpslib
7 
8 # setup argument parser
9 parser = argparse.ArgumentParser(description='Merge millePedeMonitor-root-files from eos, that are from the same dataset.',
10  formatter_class=argparse.RawDescriptionHelpFormatter)
11 # positional argument: config file
12 parser.add_argument('eosDir',
13  action='store',
14  help = 'path of the eos directory')
15 # parse argument
16 args = parser.parse_args()
17 eosDir = args.eosDir
18 
19 # read mps.db
20 lib = mpslib.jobdatabase()
21 lib.read_db()
22 for i in xrange(lib.nJobs):
23  print lib.JOBSP3[i]
24 
25 # count how much jobs there are of each dataset
26 occurences = []
27 items = []
28 for i in xrange(lib.nJobs):
29  if lib.JOBSP3[i] not in items:
30  items.append(lib.JOBSP3[i])
31 
32 for i in xrange(len(items)):
33  occurences.append(lib.JOBSP3.count(items[i]))
34 
35 # copy files from eos and combine root-files of each dataset with "hadd"
36 counter = 0
37 for i in xrange(len(items)):
38  command = 'hadd '
39  command += 'monitormerge_'+items[i]+'.root '
40  for j in xrange(occurences[i]):
41  os.system('cp '+eosDir+'/millePedeMonitor%03d.root .' % (counter+j+1))
42  command += 'millePedeMonitor%03d.root ' % (counter+j+1)
43  os.system(command)
44  for j in xrange(occurences[i]):
45  os.system('rm millePedeMonitor%03d.root' % (counter+j+1))
46  counter += occurences[i]
47 
48 
49 
50 
51 
52 
53 
54 
55 
56 
57 
58 
59 
60 
61