CMS 3D CMS Logo

DBSApi_cff.py
Go to the documentation of this file.
1 def GetDbsInfo(toFind, requirements):
2  "Interface with the DBS API to get the whatever you want of a requirements. ALWAYS RETURN A LIST OF STRINGS"
3  from xml.dom.minidom import parseString
4  from DBSAPI.dbsApi import DbsApi
5  args = {}
6  args['url']='http://cmsdbsprod.cern.ch/cms_dbs_prod_global/servlet/DBSServlet'
7  args['version']='DBS_2_0_9'
8  args['mode']='POST'
9  api = DbsApi(args)
10  data = api.executeQuery("find %s where %s" % (toFind, requirements))
11  domresults = parseString(data)
12  dbs = domresults.getElementsByTagName('dbs')
13  result = dbs[0].getElementsByTagName('results')
14  rows=result[0].getElementsByTagName('row')
15  retList = []
16  for row in rows:
17  resultXML = row.getElementsByTagName(toFind)[0]
18  node=(resultXML.childNodes)[0] #childNodes should be a one element array
19  retList.append(str(node.nodeValue))
20  return retList
21 
22 #Matching names to real datasetNames
23 datasetDict={
24  #GEN-SIM-RECO tier
25  'ZTT' : { 'primds' : 'RelValZTT', 'tier' : 'GEN-SIM-RECO',},
26  'QCD' : { 'primds' : 'RelValQCD_FlatPt_15_3000', 'tier' : 'GEN-SIM-RECO',},
27  'ZMM' : { 'primds' : 'RelValZMM', 'tier' : 'GEN-SIM-RECO',},
28  'ZEE' : { 'primds' : 'RelValZEE', 'tier' : 'GEN-SIM-RECO',},
29  #Data
30  'RealData' : { 'primds' : 'Jet', 'tier' : 'RECO', 'dataset' : '*RelVal*'},
31  'RealMuonsData' : { 'primds' : 'Mu', 'tier' : 'RECO', 'dataset' : '*RelVal*'},
32  'RealElectronsData' : { 'primds' : 'Electron', 'tier' : 'RECO', 'dataset' : '*RelVal*'},
33  #FastSim
34  'ZTTFastSim' : { 'primds' : 'RelValZTT', 'tier' : 'GEN-SIM-DIGI-RECO','dataset' : '*FastSim*',},
35  #'FastSimQCD' : { 'primds' : 'RelValQCD_FlatPt_15_3000', 'tier' : 'GEN-SIM-DIGI-RECO','dataset' : '*FastSim*',}, NOT YET IN RELVAL CONTENT
36  #'FastSimZMM' : { 'primds' : 'RelValZMM', 'tier' : 'GEN-SIM-DIGI-RECO','dataset' : '*FastSim*',},
37  'ZEEFastSim' : { 'primds' : 'RelValZEE', 'tier' : 'GEN-SIM-DIGI-RECO','dataset' : '*FastSim*',},
38  }
39 
40 def FillSource(eventType,source):
41  import os
42  requirements = ''
43  for item in datasetDict[eventType].items():
44  requirements += item[0]+' = '+item[1]+' and '
45  requirements += 'release = %s' % os.environ['CMSSW_VERSION']
46  foundDs = GetDbsInfo('dataset', requirements)
47  selDs = ''
48  if len(foundDs) > 1:
49  print "Multiple datasets found for %s! Which one you would like to use?" % eventType
50  for ds in foundDs:
51  print "%s : %s" % (foundDs.index(ds),ds)
52  cnum = int(raw_input("\nselect Dataset: "))
53  selDs = foundDs[cnum]
54  elif len(foundDs) == 0:
55  print "Sorry! No Dataset found, exiting..."
56  return None
57  else:
58  selDs = foundDs[0]
59  requirements = 'dataset = %s' % selDs
60  files = GetDbsInfo('file', requirements)
61  for entry in files:
62  source.fileNames.append(entry)
63 
64 def serialize(root):
65  xmlstr = ''
66  for key in root.keys():
67  if isinstance(root[key], dict):
68  xmlstr = '%s<%s>%s</%s>' % (xmlstr, key, serialize(root[key]), key)
69  elif isinstance(root[key], list):
70  xmlstr = '%s<%s>' % (xmlstr, key)
71  for item in root[key]:
72  xmlstr = '%s%s' % (xmlstr, serialize(item))
73  xmlstr = '%s</%s>' % (xmlstr, key)
74  else:
75  value = root[key]
76  xmlstr = '%s<%s>%s</%s>' % (xmlstr, key, value, key)
77  return xmlstr
78 
79 def DictToXML(root):
80  from xml.dom.minidom import parseString
81  outdom = parseString(serialize(root)) #closure test to check incopatibilities, and better printing
82  return outdom.toprettyxml()
83 
84 def loadXML(xml,eventType,source):
85  from xml.dom.minidom import parse
86  wrappedCont = parse(xml)
87  content = wrappedCont.getElementsByTagName('dataFiles')[0]
88  byType = content.getElementsByTagName(eventType)
89  if len(byType) == 0:
90  return None
91  fnames = byType[0].getElementsByTagName('file')
92  for fname in fnames:
93  node = (fname.childNodes)[0] #childNodes should be a one element array
94  source.fileNames.append(str(node.nodeValue).replace('\n','').replace('\t',''))
def DictToXML(root)
Definition: DBSApi_cff.py:79
def serialize(root)
Definition: DBSApi_cff.py:64
def FillSource(eventType, source)
Definition: DBSApi_cff.py:40
def replace(string, replacements)
def GetDbsInfo(toFind, requirements)
Definition: DBSApi_cff.py:1
def loadXML(xml, eventType, source)
Definition: DBSApi_cff.py:84
def parse(path, config)
Definition: dumpparser.py:13
#define str(s)