CMS 3D CMS Logo

contentValuesLib.py
Go to the documentation of this file.
1 from __future__ import print_function
2 import sys, os, optparse, re, json
3 import ROOT, xmlrpclib
4 
5 SERVER_URL = "http://pccmsdqm04.cern.ch/runregistry/xmlrpc"
6 
7 ONLINE_DATASET = '/Global/Online/ALL'
8 
9 # FOLDER UNDER EvInfo NAME SUMMARY VALUE IN EvInfo
10 FOLDERS = {
11  'reportSummaryContents': ( 'DQM', 'reportSummary' ),
12  'CertificationContents': ( 'CERT', 'CertificationSummary' ),
13  'DAQContents': ( 'DAQ', 'DAQSummary' ),
14  'DCSContents': ( 'DCS', 'DCSSummary' )
15 }
16 
17 SUBSYSTEMS = {
18  'CSC' : 'CSC',
19  'DT' : 'DT',
20  'ES' : 'ES',
21  'EcalBarrel' : 'ECAL',
22  'EcalEndcap' : 'ECAL',
23  'Hcal' : 'HCAL',
24  'L1T' : 'L1T',
25  'L1TEMU' : 'L1T',
26  'Pixel' : 'PIX',
27  'RPC' : 'RPC',
28  'SiStrip' : 'STRIP'
29 }
30 
31 def getDatasetName(file_name):
32  """ Method to get dataset name from the file name"""
33  d = None
34  try:
35  d = re.search("(__[a-zA-Z0-9-_]+)+", file_name).group(0)
36  d = re.sub("__", "/", d)
37  except:
38  d = None
39  return d
40 
41 def getSummaryValues(file_name, translate, filters = None):
42  """ Method to extract keys from root file and return dict """
43  ROOT.gROOT.Reset()
44 
45  run_number = None
46  result = {}
47 
48  f = ROOT.TFile(file_name, 'READ')
49 
50  root = f.GetDirectory("DQMData")
51  if root == None: return (run_number, result)
52 
53  run = None
54  for key in root.GetListOfKeys():
55  if re.match("^Run [0-9]+$", key.ReadObj().GetName()) and key.IsFolder():
56  run_number = int(re.sub("^Run ", "", key.ReadObj().GetName()))
57  run = key.ReadObj()
58  break
59 
60  if run == None: return (run_number, result)
61 
62  for sub in run.GetListOfKeys():
63 
64  sub_name = sub.ReadObj().GetName()
65  if sub_name not in SUBSYSTEMS: continue
66 
67  sub_key = sub_name
68  if translate:
69  sub_key = SUBSYSTEMS[sub_name]
70 
71  if filters != None:
72  if not re.match(filters[0], sub_key):
73  continue
74 
75  if sub_key not in result:
76  result[sub_key] = {}
77 
78  evInfo = sub.ReadObj().GetDirectory("Run summary/EventInfo")
79  if evInfo == None: continue
80 
81  for folder_name in FOLDERS.keys():
82 
83  folder = evInfo.GetDirectory(folder_name)
84  if folder == None: continue
85 
86  folder_id = folder_name
87  if translate:
88  folder_id = FOLDERS[folder_name][0]
89 
90  if filters != None:
91  if not re.match(filters[1], folder_id):
92  continue
93 
94  if folder_id not in result[sub_key]:
95  result[sub_key][folder_id] = {}
96 
97  value_filter = None
98  if filters != None:
99  value_filter = filters[2]
100 
101  writeValues(folder, result[sub_key][folder_id], None, value_filter)
102  writeValues(evInfo, result[sub_key][folder_id], {FOLDERS[folder_name][1]: 'Summary'}, value_filter)
103 
104  f.Close()
105 
106  return (run_number, result)
107 
108 def writeValues(folder, map, keymap = None, filter = None):
109  """ Write values (possibly only for the keys in the keymap and filtered) from folder to map """
110  for value in folder.GetListOfKeys():
111  full_name = value.ReadObj().GetName()
112  if not value.IsFolder() and re.match("^<.+>f=-{,1}[0-9\.]+</.+>$", full_name):
113  value_name = re.sub("<(?P<n>[^>]+)>.+", "\g<n>", full_name)
114  value_numb = float(re.sub("<.+>f=(?P<n>-{,1}[0-9\.]+)</.+>", "\g<n>", full_name))
115  if keymap == None or value_name in keymap:
116  if not keymap == None:
117  if not keymap[value_name] == None:
118  value_name = keymap[value_name]
119  if filter == None or re.match(filter, value_name):
120  if value_name not in map:
121  map[value_name] = value_numb
122 
123 def checkFilter(raw_filter):
124  """ Check if filter is OK """
125  if raw_filter != None:
126  try:
127  filter = eval(raw_filter)
128  if not isinstance("", type(filter[0])) or not isinstance("", type(filter[1])) or not isinstance("", type(filter[2])):
129  raise TypeError('')
130  except:
131  print("Bad filter value ", raw_filter, ".\nFilter should be written in python tupple with 3 elements, i.e. \"('subsystem','folder','value')\". elements are in regexp format.")
132  sys.exit(2)
133  else:
134  filter = ('.*', '.*', '.*')
135  return filter
dqmMemoryStats.float
float
Definition: dqmMemoryStats.py:127
contentValuesLib.getSummaryValues
def getSummaryValues(file_name, translate, filters=None)
Definition: contentValuesLib.py:41
contentValuesLib.checkFilter
def checkFilter(raw_filter)
Definition: contentValuesLib.py:123
createfilelist.int
int
Definition: createfilelist.py:10
contentValuesLib.getDatasetName
def getDatasetName(file_name)
Definition: contentValuesLib.py:31
edm::print
S & print(S &os, JobReport::InputFile const &f)
Definition: JobReport.cc:66
contentValuesLib.writeValues
def writeValues(folder, map, keymap=None, filter=None)
Definition: contentValuesLib.py:108
watchdog.group
group
Definition: watchdog.py:82