CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
getDQMSummary.py
Go to the documentation of this file.
1 #!/usr/bin/env python
2 import os, sys, re
3 import xml.parsers.expat
4 from ROOT import *
5 
6 
7 
8 # DQM Report Summary Parser ---- Yuri Gotra May-30-2008
9 # getDQMSummary.py ~/3d/DQM_R000043434.root
10 
11 
12 
13 usage = "usage: %s <DQM_File.root>" % os.path.basename(sys.argv[0])
14 
15 if len(sys.argv) < 2:
16  print usage
17  sys.exit(2)
18 else:
19  argv = sys.argv
20  infile = argv[1]
21  outfile = argv[2]
22  print argv[1]
23  f = TFile(infile, 'read')
24  ff = open(outfile,'w')
25 
26 
27 reportSummary = "<reportSummary>"
28 DQMDataDir = "DQMData"
29 EventInfoDir = "/Run summary/EventInfo"
30 ReportSummaryContentsDir = "/Run summary/EventInfo/reportSummaryContents"
31 summary = std.vector(float)()
32 reportSummaryContents = std.vector(string)()
33 f.cd(DQMDataDir)
34 dirtmp = gDirectory
35 dirlist = dirtmp.GetListOfKeys()
36 iter = dirlist.MakeIterator()
37 key = iter.Next()
38 td = None
39 
40 while key:
41  td = key.ReadObj()
42  dirName = td.GetName()
43  if(re.search('Run (\d+)', dirName)):
44  rundirname = dirName
45  break
46  key = iter.Next()
47 
48 SummaryContentsDirExists = 0
49 
50 def getDQMSegSummaryResult(f, subdet):
51  global SummaryContentsDirExists
52  SummaryContentsDirExists = 0
53  ReportSummaryContentsDir = "/Run summary/EventInfo/reportSummaryContents"
54  SummaryContentsDir = DQMDataDir + '/' + rundirname + '/' + subdet + ReportSummaryContentsDir
55  SegEventInfoDir = DQMDataDir + '/' + rundirname + '/' + subdet + EventInfoDir
56  f.cd(SegEventInfoDir)
57 
58  dirtmp = gDirectory
59  dirlist = dirtmp.GetListOfKeys()
60  iter = dirlist.MakeIterator()
61  key = iter.Next()
62  td = None
63 
64  while key:
65  td = key.ReadObj()
66  dirName = td.GetName()
67  if(re.search('reportSummaryContents', dirName)):
68  SummaryContentsDirExists = 1
69  break
70  key = iter.Next()
71  if(SummaryContentsDirExists):
72  f.cd(SummaryContentsDir)
73  else:
74  SummaryContentsDirExists = 0
75  print "Warning: No reportSummaryContents directory found in", subdet
76  return reportSummaryContents, summary
77  SummaryContentsDir = gDirectory
78  dirlist = SummaryContentsDir.GetListOfKeys()
79  iter = dirlist.MakeIterator()
80  key = iter.Next()
81  tk = None
82  while key:
83  tk = key.ReadObj()
84  keyName = tk.GetName()
85  mn = re.search('(<.+?>)', keyName)
86  if(mn):
87  reportSummaryContent = mn.group(0)
88  ms = re.split('=', keyName)
89  m = re.search('-?\d?\.?\d+', ms[1])
90  segsummary = m.group(0)
91  summary.push_back(float(segsummary))
92  reportSummaryContents.push_back(reportSummaryContent)
93  key = iter.Next()
94  return reportSummaryContents, summary
95 
97 
98  reportSummaryDir = DQMDataDir + '/' + rundirname + '/' + subdet + EventInfoDir
99 
100  f.cd(reportSummaryDir)
101  reportSummaryDir = gDirectory
102  dirlist = reportSummaryDir.GetListOfKeys()
103  iter = dirlist.MakeIterator()
104  key = iter.Next()
105  tk = None
106  while key:
107  tk = key.ReadObj()
108  keyName = tk.GetName()
109  if(re.search(reportSummary, keyName)):
110  ms = re.split('=', keyName)
111  m = re.search('-?\d?\.?\d+', ms[1])
112  detsummary = m.group(0)
113  break
114  key = iter.Next()
115  return detsummary
116 
117 DQMDataDir = "DQMData"
118 
119 f.cd(DQMDataDir)
120 dirtmp = gDirectory
121 dirlist = dirtmp.GetListOfKeys()
122 iter = dirlist.MakeIterator()
123 key = iter.Next()
124 td = None
125 
126 # controlling THE SUBDETECTOR dir list
127 while key:
128  td = key.ReadObj()
129  dirName = td.GetName()
130  if(re.search('Run (\d+)', dirName)):
131  rundirname = dirName
132  break
133  key = iter.Next()
134 
135 RunDirFull = DQMDataDir + '/' + rundirname
136 f.cd(RunDirFull)
137 dirtmp = gDirectory
138 dirlist = dirtmp.GetListOfKeys()
139 iter = dirlist.MakeIterator()
140 key = iter.Next()
141 
142 
143 SubDetectors =std.vector(string)()
144 
145 while key:
146  td = key.ReadObj()
147  dirName = td.GetName()
148  print dirName
149  SubDetectors.push_back(dirName)
150  key = iter.Next()
151 
152 print SubDetectors
153 
154 for subdet in SubDetectors:
155  print >>ff, '============================'
156  print >>ff, rundirname, subdet
157  getDQMSegSummaryResult(f, subdet)
158  if( SummaryContentsDirExists == 1):
159  summary.push_back(float(getDQMDetSummaryResult()))
160  reportSummaryContents.push_back(reportSummary)
161  j = 0
162  for i in summary:
163  print >> ff, reportSummaryContents[j], int(1000*i)
164  j = j + 1
165  summary.clear()
166  reportSummaryContents.clear()
167 print >> ff, '============================'
def getDQMSegSummaryResult
if(dp >Float(M_PI)) dp-
def getDQMDetSummaryResult