Functions | |
def | DictToXML |
def | FillSource |
def | GetDbsInfo |
def | loadXML |
def | serialize |
def DBSApi_cff::DictToXML | ( | root | ) |
Definition at line 79 of file DBSApi_cff.py.
def DBSApi_cff::FillSource | ( | eventType, | |
source | |||
) |
Definition at line 40 of file DBSApi_cff.py.
00041 : 00042 import os 00043 requirements = '' 00044 for item in datasetDict[eventType].items(): 00045 requirements += item[0]+' = '+item[1]+' and ' 00046 requirements += 'release = %s' % os.environ['CMSSW_VERSION'] 00047 foundDs = GetDbsInfo('dataset', requirements) 00048 selDs = '' 00049 if len(foundDs) > 1: 00050 print "Multiple datasets found for %s! Which one you would like to use?" % eventType 00051 for ds in foundDs: 00052 print "%s : %s" % (foundDs.index(ds),ds) 00053 cnum = int(raw_input("\nselect Dataset: ")) 00054 selDs = foundDs[cnum] 00055 elif len(foundDs) == 0: 00056 print "Sorry! No Dataset found, exiting..." 00057 return None 00058 else: 00059 selDs = foundDs[0] 00060 requirements = 'dataset = %s' % selDs 00061 files = GetDbsInfo('file', requirements) 00062 for entry in files: 00063 source.fileNames.append(entry)
def DBSApi_cff::GetDbsInfo | ( | toFind, | |
requirements | |||
) |
Definition at line 1 of file DBSApi_cff.py.
00002 : 00003 "Interface with the DBS API to get the whatever you want of a requirements. ALWAYS RETURN A LIST OF STRINGS" 00004 from xml.dom.minidom import parseString 00005 from DBSAPI.dbsApi import DbsApi 00006 args = {} 00007 args['url']='https://cmsdbsprod.cern.ch/cms_dbs_prod_global/servlet/DBSServlet' 00008 args['version']='DBS_2_0_9' 00009 args['mode']='POST' 00010 api = DbsApi(args) 00011 data = api.executeQuery("find %s where %s" % (toFind, requirements)) 00012 domresults = parseString(data) 00013 dbs = domresults.getElementsByTagName('dbs') 00014 result = dbs[0].getElementsByTagName('results') 00015 rows=result[0].getElementsByTagName('row') 00016 retList = [] 00017 for row in rows: 00018 resultXML = row.getElementsByTagName(toFind)[0] 00019 node=(resultXML.childNodes)[0] #childNodes should be a one element array 00020 retList.append(str(node.nodeValue)) 00021 return retList 00022 00023 #Matching names to real datasetNames 00024 datasetDict={ 00025 #GEN-SIM-RECO tier 00026 'ZTT' : { 'primds' : 'RelValZTT', 'tier' : 'GEN-SIM-RECO',}, 00027 'QCD' : { 'primds' : 'RelValQCD_FlatPt_15_3000', 'tier' : 'GEN-SIM-RECO',}, 00028 'ZMM' : { 'primds' : 'RelValZMM', 'tier' : 'GEN-SIM-RECO',}, 00029 'ZEE' : { 'primds' : 'RelValZEE', 'tier' : 'GEN-SIM-RECO',}, 00030 #Data 00031 'RealData' : { 'primds' : 'Jet', 'tier' : 'RECO', 'dataset' : '*RelVal*'}, 00032 'RealMuonsData' : { 'primds' : 'Mu', 'tier' : 'RECO', 'dataset' : '*RelVal*'}, 00033 'RealElectronsData' : { 'primds' : 'Electron', 'tier' : 'RECO', 'dataset' : '*RelVal*'}, 00034 #FastSim 00035 'ZTTFastSim' : { 'primds' : 'RelValZTT', 'tier' : 'GEN-SIM-DIGI-RECO','dataset' : '*FastSim*',}, 00036 #'FastSimQCD' : { 'primds' : 'RelValQCD_FlatPt_15_3000', 'tier' : 'GEN-SIM-DIGI-RECO','dataset' : '*FastSim*',}, NOT YET IN RELVAL CONTENT 00037 #'FastSimZMM' : { 'primds' : 'RelValZMM', 'tier' : 'GEN-SIM-DIGI-RECO','dataset' : '*FastSim*',}, 00038 'ZEEFastSim' : { 'primds' : 'RelValZEE', 'tier' : 'GEN-SIM-DIGI-RECO','dataset' : '*FastSim*',}, 00039 }
def DBSApi_cff::loadXML | ( | xml, | |
eventType, | |||
source | |||
) |
Definition at line 84 of file DBSApi_cff.py.
00085 : 00086 from xml.dom.minidom import parse 00087 wrappedCont = parse(xml) 00088 content = wrappedCont.getElementsByTagName('dataFiles')[0] 00089 byType = content.getElementsByTagName(eventType) 00090 if len(byType) == 0: 00091 return None 00092 fnames = byType[0].getElementsByTagName('file') 00093 for fname in fnames: 00094 node = (fname.childNodes)[0] #childNodes should be a one element array 00095 source.fileNames.append(str(node.nodeValue).replace('\n','').replace('\t',''))
def DBSApi_cff::serialize | ( | root | ) |
Definition at line 64 of file DBSApi_cff.py.
00065 : 00066 xmlstr = '' 00067 for key in root.keys(): 00068 if isinstance(root[key], dict): 00069 xmlstr = '%s<%s>%s</%s>' % (xmlstr, key, serialize(root[key]), key) 00070 elif isinstance(root[key], list): 00071 xmlstr = '%s<%s>' % (xmlstr, key) 00072 for item in root[key]: 00073 xmlstr = '%s%s' % (xmlstr, serialize(item)) 00074 xmlstr = '%s</%s>' % (xmlstr, key) 00075 else: 00076 value = root[key] 00077 xmlstr = '%s<%s>%s</%s>' % (xmlstr, key, value, key) 00078 return xmlstr