00001
00002
00003
00004 import os
00005 import GaudiPython as gaudi
00006
00007 def init(loc) :
00008
00009
00010
00011 g=gaudi.AppMgr()
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 g.ExtSvc += [ "XmlCnvSvc" , "XmlParserSvc" ]
00025 g.EvtSel = "NONE"
00026
00027 det = g.service('DetectorPersistencySvc')
00028 det.CnvServices = ["XmlCnvSvc"]
00029
00030 det = g.service('XmlCnvSvc')
00031
00032 det.AllowGenericConversion = True
00033
00034
00035
00036
00037 det = g.service('DetectorDataSvc')
00038 det.UsePersistency = True
00039 det.DetDbRootName = "dd"
00040 det.DetStorageType = 7
00041 det.DetDbLocation = loc
00042
00043 def _dir_ ( self , node = None , level = -1 ) :
00044 """
00045 The simple tool to perform the inspection fo Data Store
00046
00047 Usage:
00048
00049 evtSvc = gaudi.evtSvc()
00050 evtSvc.dir('MC')
00051 data = evtSvc['Rec/Calo']
00052 evtSvc.dir( data)
00053
00054 """
00055 if 0 == level : return gaudi.SUCCESS ;
00056 if str is type(node) : node = self.retrieveObject( node )
00057 elif not node : return self.dir('', level )
00058 if not node : return gaudi.FAILURE
00059 if hasattr ( node , 'registry' ) : node = node.registry()
00060 if hasattr ( node , 'identifier' ) :
00061 obj = node.object ()
00062 if not obj :
00063 obj = self.retrieveObject( node.identifier() )
00064 print node.identifier()
00065 else :
00066 if hasattr( obj , 'size' ) :
00067 size = obj.size()
00068 if 0 == size : print "%s (empty) %s" % ( node.identifier() , type( obj ) )
00069 elif hasattr ( obj , 'containedObjects' ) :
00070 c = obj.containedObjects()[0]
00071 print "%s container of %d %s objects " % ( node.identifier() , obj.size() , type(c))
00072 else :
00073 print "%s %s " % ( node.identifier() , type( node.object()) )
00074 else :
00075 print "%s %s " % ( node.identifier() , type( node.object()) )
00076 else : print "The node has no 'identifier'"
00077
00078 for l in self.leaves( node ) :
00079 if l : self.dir( l , level - 1 )
00080 return gaudi.SUCCESS
00081
00082 def _get_( self , node = None , cut = lambda x : True ) :
00083 if str is type(node) : node = self.retrieveObject( node )
00084 elif not node : return _get_( self , '' , cut )
00085 if not node : return []
00086 if hasattr ( node , 'registry' ) : node = node.registry()
00087 result = []
00088 if hasattr ( node , 'identifier' ) :
00089 obj = node.object()
00090 if cut( obj ) : result += [ obj ]
00091 for l in self.leaves ( node ) :
00092 if l : result += _get_( self , l , cut )
00093 return result
00094
00095 gaudi.iDataSvc.dir = _dir_
00096 gaudi.iDataSvc.DIR = _get_
00097
00098
00099
00100 if "__main__" == __name__ :
00101 import sys, getopt, os
00102
00103 vol="/dd"
00104 det=os.getenv("XMLDETDESCROOT")
00105 if det == "":
00106 print "Warning: no XMLDETDESCROOT variable, no default detector description"
00107 else:
00108 det += "/DDDB/dayabay.xml"
00109
00110 optlist,args = getopt.getopt(sys.argv[1:],"-V:v:d:")
00111
00112 verbose = None
00113 for opt,arg in optlist:
00114 if opt == "-V":
00115 verbose = arg
00116 if opt == "-v":
00117 vol = arg
00118 if opt == "-d":
00119 det = arg
00120 pass
00121 pass
00122
00123 print "Top volume =",vol
00124 print "Detector file = ",det
00125
00126
00127 init(det)
00128 g=gaudi.AppMgr()
00129 if verbose:
00130 g.service('MessageSvc').OutputLevel = 1
00131 det = g.detSvc()
00132
00133 det.dir(vol)
00134 det.dump()
00135
00136