CMS 3D CMS Logo

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