00001
00002 """
00003 Example of interactive exploration of detector description, following
00004 getting into the CMT environment :
00005 dyb__ dybgaudi/Detector/XmlDetDesc
00006
00007 Using python -i or ipython :
00008
00009 import xmldetdesc as xdd
00010 dsv = xdd.detsvc()
00011
00012 In [3]: dsv.dir("/dd", 2 )
00013 /dd <class 'GaudiPython.Pythonizations.DataObject'>
00014 /dd/Geometry
00015 /dd/Materials
00016 /dd/Structure
00017 Out[3]: SUCCESS
00018
00019 In [4]: dsv.dir("/dd/Geometry", 2 )
00020 /dd/Geometry <class 'GaudiPython.Pythonizations.DataObject'>
00021 /dd/Geometry/DayaBay
00022 /dd/Geometry/Sites
00023 /dd/Geometry/Pool
00024 /dd/Geometry/PoolDetails
00025 /dd/Geometry/PmtPanel
00026 /dd/Geometry/AD
00027 /dd/Geometry/AdDetails
00028 /dd/Geometry/AdPmts
00029 /dd/Geometry/RPC
00030 /dd/Geometry/PMT
00031 Out[4]: SUCCESS
00032
00033 CAUTION these will list the entire description:
00034 dsv.dir("/dd", -1 )
00035 dsv.dir("/dd" )
00036
00037 """
00038
00039
00040
00041 from Gaudi.Configuration import *
00042
00043 def config(xmlfile=None):
00044
00045 if not xmlfile:
00046 import sys, os
00047 loc = os.getenv("XMLDETDESCROOT")
00048 if not loc:
00049 print "Warning: no XMLDETDESCROOT variable, no detector description"
00050 sys.exit(1)
00051 else:
00052 loc += "/DDDB/dayabay.xml"
00053 pass
00054 xmlfile = loc
00055 pass
00056
00057
00058
00059 from XmlTools.XmlToolsConf import XmlCnvSvc, XmlParserSvc
00060 xmlcnv = XmlCnvSvc()
00061 xmlcnv.AllowGenericConversion = True
00062 xmlparser = XmlParserSvc()
00063
00064 app = ApplicationMgr()
00065 app.ExtSvc += [ xmlcnv , xmlparser ]
00066
00067 detper = DetectorPersistencySvc()
00068 detper.CnvServices.append(xmlcnv)
00069
00070 detdat = DetectorDataSvc()
00071 detdat.UsePersistency = True
00072 detdat.DetDbRootName = "dd"
00073 detdat.DetStorageType = 7
00074 detdat.DetDbLocation = xmlfile
00075 return
00076
00077
00078
00079 def dress_idatasvc():
00080 import GaudiPython as gaudi
00081
00082 def _dir_ ( self , node = None , level = -1 ) :
00083 """
00084 The simple tool to perform the inspection fo Data Store
00085
00086 Usage:
00087
00088 evtSvc = gaudi.evtSvc()
00089 evtSvc.dir('MC')
00090 data = evtSvc['Rec/Calo']
00091 evtSvc.dir( data)
00092
00093 """
00094 if 0 == level : return gaudi.SUCCESS ;
00095 if str is type(node) : node = self.retrieveObject( node )
00096 elif not node : return self.dir('', level )
00097 if not node : return gaudi.FAILURE
00098 if hasattr ( node , 'registry' ) : node = node.registry()
00099 if hasattr ( node , 'identifier' ) :
00100 obj = node.object ()
00101 if not obj :
00102 obj = self.retrieveObject( node.identifier() )
00103 print node.identifier()
00104 pass
00105 else :
00106 if hasattr( obj , 'size' ) :
00107 size = obj.size()
00108 if 0 == size : print "%s (empty) %s" % ( node.identifier() , type( obj ) )
00109 elif hasattr ( obj , 'containedObjects' ) :
00110 c = obj.containedObjects()[0]
00111 print "%s container of %d %s objects " % ( node.identifier() , obj.size() , type(c))
00112 pass
00113 else :
00114 print "%s %s " % ( node.identifier() , type( node.object()) )
00115 pass
00116 else :
00117 print "%s %s " % ( node.identifier() , type( node.object()) )
00118 pass
00119 else : print "The node has no 'identifier'"
00120
00121 for l in self.leaves( node ) :
00122 if l : self.dir( l , level - 1 )
00123 continue
00124 return gaudi.SUCCESS
00125
00126 def _get_( self , node = None , cut = lambda x : True ) :
00127 if str is type(node) : node = self.retrieveObject( node )
00128 elif not node : return _get_( self , '' , cut )
00129 if not node : return []
00130 if hasattr ( node , 'registry' ) : node = node.registry()
00131 result = []
00132 if hasattr ( node , 'identifier' ) :
00133 obj = node.object()
00134 if cut( obj ) : result += [ obj ]
00135 pass
00136 for l in self.leaves ( node ) :
00137 if l : result += _get_( self , l , cut )
00138 continue
00139 return result
00140
00141 gaudi.iDataSvc.dir = _dir_
00142 gaudi.iDataSvc.DIR = _get_
00143
00144
00145 def detsvc():
00146 config()
00147 dress_idatasvc()
00148 import GaudiPython as gp
00149 g = gp.AppMgr()
00150 dsv = g.detSvc()
00151 return dsv
00152
00153 def dump():
00154 dress_idatasvc()
00155 import GaudiPython as gaudi
00156 app = gaudi.AppMgr()
00157 det = app.detSvc()
00158 det.dir("/dd")
00159 det.dump()
00160
00161 return
00162
00163 if '__main__' == __name__:
00164 config()
00165 dump()
00166
00167