File indexing completed on 2024-04-06 12:33:18
0001 from __future__ import print_function
0002 def GetDbsInfo(toFind, requirements):
0003 "Interface with the DBS API to get the whatever you want of a requirements. ALWAYS RETURN A LIST OF STRINGS"
0004 from xml.dom.minidom import parseString
0005 from DBSAPI.dbsApi import DbsApi
0006 args = {}
0007 args['url']='http://cmsdbsprod.cern.ch/cms_dbs_prod_global/servlet/DBSServlet'
0008 args['version']='DBS_2_0_9'
0009 args['mode']='POST'
0010 api = DbsApi(args)
0011 data = api.executeQuery("find %s where %s" % (toFind, requirements))
0012 domresults = parseString(data)
0013 dbs = domresults.getElementsByTagName('dbs')
0014 result = dbs[0].getElementsByTagName('results')
0015 rows=result[0].getElementsByTagName('row')
0016 retList = []
0017 for row in rows:
0018 resultXML = row.getElementsByTagName(toFind)[0]
0019 node=(resultXML.childNodes)[0]
0020 retList.append(str(node.nodeValue))
0021 return retList
0022
0023
0024 datasetDict={
0025
0026 'ZTT' : { 'primds' : 'RelValZTT', 'tier' : 'GEN-SIM-RECO',},
0027 'QCD' : { 'primds' : 'RelValQCD_FlatPt_15_3000', 'tier' : 'GEN-SIM-RECO',},
0028 'ZMM' : { 'primds' : 'RelValZMM', 'tier' : 'GEN-SIM-RECO',},
0029 'ZEE' : { 'primds' : 'RelValZEE', 'tier' : 'GEN-SIM-RECO',},
0030
0031 'RealData' : { 'primds' : 'Jet', 'tier' : 'RECO', 'dataset' : '*RelVal*'},
0032 'RealMuonsData' : { 'primds' : 'Mu', 'tier' : 'RECO', 'dataset' : '*RelVal*'},
0033 'RealElectronsData' : { 'primds' : 'Electron', 'tier' : 'RECO', 'dataset' : '*RelVal*'},
0034
0035 'ZTTFastSim' : { 'primds' : 'RelValZTT', 'tier' : 'GEN-SIM-DIGI-RECO','dataset' : '*FastSim*',},
0036
0037
0038 'ZEEFastSim' : { 'primds' : 'RelValZEE', 'tier' : 'GEN-SIM-DIGI-RECO','dataset' : '*FastSim*',},
0039 }
0040
0041 def FillSource(eventType,source):
0042 import os
0043 requirements = ''
0044 for item in datasetDict[eventType].items():
0045 requirements += item[0]+' = '+item[1]+' and '
0046 requirements += 'release = %s' % os.environ['CMSSW_VERSION']
0047 foundDs = GetDbsInfo('dataset', requirements)
0048 selDs = ''
0049 if len(foundDs) > 1:
0050 print("Multiple datasets found for %s! Which one you would like to use?" % eventType)
0051 for ds in foundDs:
0052 print("%s : %s" % (foundDs.index(ds),ds))
0053 cnum = int(raw_input("\nselect Dataset: "))
0054 selDs = foundDs[cnum]
0055 elif len(foundDs) == 0:
0056 print("Sorry! No Dataset found, exiting...")
0057 return None
0058 else:
0059 selDs = foundDs[0]
0060 requirements = 'dataset = %s' % selDs
0061 files = GetDbsInfo('file', requirements)
0062 for entry in files:
0063 source.fileNames.append(entry)
0064
0065 def serialize(root):
0066 xmlstr = ''
0067 for key in root.keys():
0068 if isinstance(root[key], dict):
0069 xmlstr = '%s<%s>%s</%s>' % (xmlstr, key, serialize(root[key]), key)
0070 elif isinstance(root[key], list):
0071 xmlstr = '%s<%s>' % (xmlstr, key)
0072 for item in root[key]:
0073 xmlstr = '%s%s' % (xmlstr, serialize(item))
0074 xmlstr = '%s</%s>' % (xmlstr, key)
0075 else:
0076 value = root[key]
0077 xmlstr = '%s<%s>%s</%s>' % (xmlstr, key, value, key)
0078 return xmlstr
0079
0080 def DictToXML(root):
0081 from xml.dom.minidom import parseString
0082 outdom = parseString(serialize(root))
0083 return outdom.toprettyxml()
0084
0085 def loadXML(xml,eventType,source):
0086 from xml.dom.minidom import parse
0087 wrappedCont = parse(xml)
0088 content = wrappedCont.getElementsByTagName('dataFiles')[0]
0089 byType = content.getElementsByTagName(eventType)
0090 if len(byType) == 0:
0091 return None
0092 fnames = byType[0].getElementsByTagName('file')
0093 for fname in fnames:
0094 node = (fname.childNodes)[0]
0095 source.fileNames.append(str(node.nodeValue).replace('\n','').replace('\t',''))