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