CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
contentValuesFiles.py
Go to the documentation of this file.
1 #!/usr/bin/env python
2 
3 from contentValuesLib import *
4 import xml.dom.minidom
5 
6 reDatasetParts = "^/([^/]+)/([^/]+)/([^/]+)$"
7 DEFAULT_BASE = "/afs/cern.ch/cms/CAF/CMSCOMM/COMM_DQM/data/"
8 
9 REMINDERS = [
10  ('^/StreamExpress/', 'Express/%(numberPart1)03d/%(numberPart2)03d/DQM_V0001_R%(number)09d__StreamExpress__%(datasetPart2)s__%(datasetPart3)s.root'),
11  ('^/Global/Online/ALL$', 'Online/%(numberPart1)03d/%(numberPart2)03d/DQM_V0003_R%(number)09d.root')
12 ]
13 
14 class OptionParser(optparse.OptionParser):
15  """ Option parser class """
16  def __init__(self):
17  optparse.OptionParser.__init__(self, usage="%prog [options]", version="%prog 0.0.1", conflict_handler="resolve")
18  self.add_option("--url", action="store", type="string", dest="url", default=SERVER_URL, help="specify RR XML-RPC server URL. Default is " + SERVER_URL)
19  self.add_option("--from", action="store", type="int", dest="from", default=None, help="specify run number lower threshold inclusive. Note that all runs/datasets retrieval can take a long time!")
20  self.add_option("--to", action="store", type="int", dest="to", default=None, help="specify run number upper threshold inclusive. Note that all runs/datasets retrieval can take a long time!")
21  self.add_option("--base", action="store", type="string", dest="base", default=DEFAULT_BASE, help="file base. Default is " + DEFAULT_BASE)
22 
23 def getNodeText(nodelist):
24  rc = ""
25  for node in nodelist:
26  if node.nodeType == node.TEXT_NODE:
27  rc = rc + node.data
28  return rc
29 
30 if __name__ == "__main__":
31 
32  # Create option parser and get options/arguments
33  optManager = OptionParser()
34  (opts, args) = optManager.parse_args()
35  opts = opts.__dict__
36 
37  server = xmlrpclib.ServerProxy(opts['url'])
38  query = {'hasSummaryValues': 'false'}
39  if opts['from'] != None:
40  query['number'] = '>= ' + str(opts['from'])
41  if opts['to'] != None:
42  if 'number' in query:
43  query['number'] += ' and <= ' + str(opts['to'])
44  else:
45  query['number'] = '<= ' + str(opts['to'])
46 
47  xmldata = server.DataExporter.export('GLOBAL', 'xml_all', query)
48 
49  datasets = []
50  dom = xml.dom.minidom.parseString(xmldata)
51 
52  for run in dom.getElementsByTagName("RUN"):
53  number = int(getNodeText(run.getElementsByTagName("NUMBER")[0].childNodes))
54  for dataset in run.getElementsByTagName("DATASET"):
55  datasets.append((number, getNodeText(dataset.getElementsByTagName("NAME")[0].childNodes)))
56 
57  for (number, dataset) in datasets:
58  parts = None
59  m = re.search(reDatasetParts, dataset)
60  if m == None:
61  sys.stderr.write("Wrong dataset name (run %d, dataset %s)!\n" % (number, dataset))
62  else:
63  parts = m.group(1, 2, 3)
64  fullPath = None
65  for (reminderPattern, reminderFormat) in REMINDERS:
66  if re.match(reminderPattern, dataset):
67  reminder = reminderFormat % \
68  { 'number': number, 'dataset': dataset,
69  'numberPart1': int(re.search('^([0-9]+)([0-9]{3})$', str(number)).group(1)),
70  'numberPart2': int(re.search('^([0-9]+)([0-9]{3})$', str(number)).group(2)),
71  'datasetPart1': parts[0],
72  'datasetPart2': parts[1],
73  'datasetPart3': parts[2]
74  }
75  fullPath = opts['base'] + reminder
76  break
77 
78  if fullPath == None:
79  sys.stderr.write("Dataset was not identified (run %d, dataset %s)!\n" % (number, dataset))
80  else:
81  try:
82  os.stat(fullPath)
83  sys.stdout.write(fullPath)
84  sys.stdout.write('\n')
85  except:
86  sys.stderr.write("File [%s] not exists or is not accessible (run %d, dataset %s)!\n" % (fullPath, number, dataset))
87 
88 
89  sys.exit(0)
90 
91 
tuple group
Definition: watchdog.py:82