CMS 3D CMS Logo

/afs/cern.ch/work/a/aaltunda/public/www/CMSSW_5_3_14/src/Validation/RecoTau/python/DBSApi_cff.py

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