CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
Functions
DBSApi_cff Namespace Reference

Functions

def DictToXML
 
def FillSource
 
def GetDbsInfo
 
def loadXML
 
def serialize
 

Function Documentation

def DBSApi_cff.DictToXML (   root)

Definition at line 80 of file DBSApi_cff.py.

References serialize().

80 
81 def DictToXML(root):
82  from xml.dom.minidom import parseString
83  outdom = parseString(serialize(root)) #closure test to check incopatibilities, and better printing
84  return outdom.toprettyxml()
def DictToXML
Definition: DBSApi_cff.py:80
def serialize
Definition: DBSApi_cff.py:65
def DBSApi_cff.FillSource (   eventType,
  source 
)

Definition at line 41 of file DBSApi_cff.py.

References GetDbsInfo(), mps_monitormerge.items, and print().

41 
42 def FillSource(eventType,source):
43  import os
44  requirements = ''
45  for item in datasetDict[eventType].items():
46  requirements += item[0]+' = '+item[1]+' and '
47  requirements += 'release = %s' % os.environ['CMSSW_VERSION']
48  foundDs = GetDbsInfo('dataset', requirements)
49  selDs = ''
50  if len(foundDs) > 1:
51  print("Multiple datasets found for %s! Which one you would like to use?" % eventType)
52  for ds in foundDs:
53  print("%s : %s" % (foundDs.index(ds),ds))
54  cnum = int(raw_input("\nselect Dataset: "))
55  selDs = foundDs[cnum]
56  elif len(foundDs) == 0:
57  print("Sorry! No Dataset found, exiting...")
58  return None
59  else:
60  selDs = foundDs[0]
61  requirements = 'dataset = %s' % selDs
62  files = GetDbsInfo('file', requirements)
63  for entry in files:
64  source.fileNames.append(entry)
def FillSource
Definition: DBSApi_cff.py:41
def GetDbsInfo
Definition: DBSApi_cff.py:2
void print(TMatrixD &m, const char *label=nullptr, bool mathematicaFormat=false)
Definition: Utilities.cc:47
def DBSApi_cff.GetDbsInfo (   toFind,
  requirements 
)

Definition at line 2 of file DBSApi_cff.py.

References str.

Referenced by FillSource().

2 
3 def GetDbsInfo(toFind, requirements):
4  "Interface with the DBS API to get the whatever you want of a requirements. ALWAYS RETURN A LIST OF STRINGS"
5  from xml.dom.minidom import parseString
6  from DBSAPI.dbsApi import DbsApi
7  args = {}
8  args['url']='http://cmsdbsprod.cern.ch/cms_dbs_prod_global/servlet/DBSServlet'
9  args['version']='DBS_2_0_9'
10  args['mode']='POST'
11  api = DbsApi(args)
12  data = api.executeQuery("find %s where %s" % (toFind, requirements))
13  domresults = parseString(data)
14  dbs = domresults.getElementsByTagName('dbs')
15  result = dbs[0].getElementsByTagName('results')
16  rows=result[0].getElementsByTagName('row')
17  retList = []
18  for row in rows:
19  resultXML = row.getElementsByTagName(toFind)[0]
20  node=(resultXML.childNodes)[0] #childNodes should be a one element array
21  retList.append(str(node.nodeValue))
22  return retList
23 
24 #Matching names to real datasetNames
25 datasetDict={
26  #GEN-SIM-RECO tier
27  'ZTT' : { 'primds' : 'RelValZTT', 'tier' : 'GEN-SIM-RECO',},
28  'QCD' : { 'primds' : 'RelValQCD_FlatPt_15_3000', 'tier' : 'GEN-SIM-RECO',},
29  'ZMM' : { 'primds' : 'RelValZMM', 'tier' : 'GEN-SIM-RECO',},
30  'ZEE' : { 'primds' : 'RelValZEE', 'tier' : 'GEN-SIM-RECO',},
31  #Data
32  'RealData' : { 'primds' : 'Jet', 'tier' : 'RECO', 'dataset' : '*RelVal*'},
33  'RealMuonsData' : { 'primds' : 'Mu', 'tier' : 'RECO', 'dataset' : '*RelVal*'},
34  'RealElectronsData' : { 'primds' : 'Electron', 'tier' : 'RECO', 'dataset' : '*RelVal*'},
35  #FastSim
36  'ZTTFastSim' : { 'primds' : 'RelValZTT', 'tier' : 'GEN-SIM-DIGI-RECO','dataset' : '*FastSim*',},
37  #'FastSimQCD' : { 'primds' : 'RelValQCD_FlatPt_15_3000', 'tier' : 'GEN-SIM-DIGI-RECO','dataset' : '*FastSim*',}, NOT YET IN RELVAL CONTENT
38  #'FastSimZMM' : { 'primds' : 'RelValZMM', 'tier' : 'GEN-SIM-DIGI-RECO','dataset' : '*FastSim*',},
39  'ZEEFastSim' : { 'primds' : 'RelValZEE', 'tier' : 'GEN-SIM-DIGI-RECO','dataset' : '*FastSim*',},
40  }
def GetDbsInfo
Definition: DBSApi_cff.py:2
#define str(s)
def DBSApi_cff.loadXML (   xml,
  eventType,
  source 
)

Definition at line 85 of file DBSApi_cff.py.

References dumpparser.parse(), python.rootplot.root2matplotlib.replace(), and str.

85 
86 def loadXML(xml,eventType,source):
87  from xml.dom.minidom import parse
88  wrappedCont = parse(xml)
89  content = wrappedCont.getElementsByTagName('dataFiles')[0]
90  byType = content.getElementsByTagName(eventType)
91  if len(byType) == 0:
92  return None
93  fnames = byType[0].getElementsByTagName('file')
94  for fname in fnames:
95  node = (fname.childNodes)[0] #childNodes should be a one element array
96  source.fileNames.append(str(node.nodeValue).replace('\n','').replace('\t',''))
def loadXML
Definition: DBSApi_cff.py:85
#define str(s)
def DBSApi_cff.serialize (   root)

Definition at line 65 of file DBSApi_cff.py.

Referenced by DictToXML().

65 
66 def serialize(root):
67  xmlstr = ''
68  for key in root.keys():
69  if isinstance(root[key], dict):
70  xmlstr = '%s<%s>%s</%s>' % (xmlstr, key, serialize(root[key]), key)
71  elif isinstance(root[key], list):
72  xmlstr = '%s<%s>' % (xmlstr, key)
73  for item in root[key]:
74  xmlstr = '%s%s' % (xmlstr, serialize(item))
75  xmlstr = '%s</%s>' % (xmlstr, key)
76  else:
77  value = root[key]
78  xmlstr = '%s<%s>%s</%s>' % (xmlstr, key, value, key)
79  return xmlstr
def serialize
Definition: DBSApi_cff.py:65