00001
00002
00003 from GaudiPython.GaudiAlgs import GaudiAlgo
00004 from GaudiPython import SUCCESS, FAILURE
00005
00006 class TesterAlg(GaudiAlgo):
00007
00008 def __init__(self,myname,npoints,target_de_name):
00009 GaudiAlgo.__init__(self,myname)
00010 self.npoints = npoints
00011 self.target_de_name = target_de_name
00012 return
00013
00014 def initialize(self):
00015 sc = GaudiAlgo.initialize(self)
00016 if sc.isFailure():
00017 print 'Failed to initialize GaudiAlgo base class'
00018 return sc
00019 self.css = self.svc('ICoordSysSvc','CoordSysSvc')
00020 if not self.css:
00021 print 'Failed to get CoordSysSvc'
00022 return FAILURE
00023 self.ExecuteOnce = True
00024 return sc;
00025
00026 def execute(self):
00027
00028 import GaudiKernel.SystemOfUnits as units
00029
00030 import time
00031 start = time.time()
00032 for x in range(0,self.npoints):
00033 print x
00034 for y in range(0,self.npoints):
00035 for z in range(0,self.npoints):
00036 pt = [x*units.mm,y*units.mm,z*units.mm]
00037 self.do_point(pt)
00038 if x+y+z == 0: first = time.time()
00039 continue
00040 continue
00041 continue
00042 stop = time.time()
00043
00044 print "\nFirst in %f seconds, remaining %d points in %f seconds"%\
00045 (first-start,pow(self.npoints,3)-1,stop-first)
00046
00047
00048 return SUCCESS
00049
00050 def do_point(self,pt):
00051
00052
00053
00054 de = self.getDet(self.target_de_name)
00055 if not de:
00056 print 'Failed to get DE',self.target_de_name
00057 return FAILURE
00058
00059
00060 import PyCintex
00061 Gaudi = PyCintex.makeNamespace('Gaudi')
00062 point = Gaudi.XYZPoint(pt[0],pt[1],pt[2])
00063 gpoint = de.geometry().toGlobal(point)
00064
00065
00066 btde = self.css.belongsToDE(gpoint)
00067 while btde:
00068 if btde.name() != de.name(): break
00069 btde = btde.parentIDetectorElement()
00070 continue
00071 if not btde:
00072 print 'Bogus: center of target DE is not in target DE',\
00073 self.target_de_name
00074 return FAILURE
00075
00076
00077 csde = self.css.coordSysDE(gpoint)
00078 if not csde:
00079 print 'Failed to find coordinate system DE for '\
00080 '[',gpoint.x(),gpoint.y(),gpoint.z(),']'
00081 return FAILURE
00082
00083
00084
00085
00086 return SUCCESS
00087
00088 class TesterAlg2(GaudiAlgo):
00089
00090 def __init__(self,myname,global_points,should_fail = False):
00091 GaudiAlgo.__init__(self,myname)
00092 self.gp = global_points
00093 self.should_fail = should_fail
00094 return
00095
00096 def initialize(self):
00097 sc = GaudiAlgo.initialize(self)
00098 if sc.isFailure():
00099 print 'Failed to initialize GaudiAlgo base class'
00100 return sc
00101 self.css = self.svc('ICoordSysSvc','CoordSysSvc')
00102 if not self.css:
00103 print 'Failed to get CoordSysSvc'
00104 return FAILURE
00105 self.ExecuteOnce = True
00106 return sc;
00107
00108 def execute(self):
00109
00110 import PyCintex
00111 Gaudi = PyCintex.makeNamespace('Gaudi')
00112 gpoint = Gaudi.XYZPoint(self.gp[0],self.gp[1],self.gp[2])
00113
00114 print 'Checking %f,%f,%f'%(self.gp[0],self.gp[1],self.gp[2])
00115 btde = self.css.belongsToDE(gpoint)
00116 print 'Found belong to DE: %s'%btde.name()
00117 lpoint = btde.geometry().toLocal(gpoint)
00118 print 'Local point in belongs to DE: %f,%f,%f'%(lpoint.x(),lpoint.y(),lpoint.z())
00119
00120
00121 csde = self.css.coordSysDE(gpoint)
00122 if csde:
00123 print 'Found coord sys DE: %s'%csde.name()
00124 if self.should_fail:
00125 print '\tbut, I should not have.'
00126 return FAILURE
00127 return SUCCESS
00128 print 'Failed to find coord sys DE for point'
00129 if self.should_fail:
00130 print '\twhich is as expected'
00131 return SUCCESS
00132 return FAILURE
00133
00134 def configure():
00135 from DetHelpers.DetHelpersConf import CoordSysSvc
00136 css = CoordSysSvc()
00137 css.OutputLevel = 1
00138
00139 from Gaudi.Configuration import ApplicationMgr
00140 theApp = ApplicationMgr()
00141 theApp.ExtSvc.append(css)
00142 return
00143
00144 def run(app):
00145
00146 ta = TesterAlg2('TesterAlg21',[-414582.0,814258.0,-1923.73])
00147 app.addAlgorithm(ta)
00148
00149 ta = TesterAlg2('TesterAlg22',[-410670.0,813170.0,3100.75])
00150 app.addAlgorithm(ta)
00151
00152 ta = TesterAlg2('TesterAlg23',[-417953,747954,-62099.1],True)
00153 app.addAlgorithm(ta)
00154
00155 size = 10
00156 ta1 = TesterAlg('TesterAlg11',size,
00157 '/dd/Structure/AD/db-ade1/db-sst1/db-oil1/db-oav1/db-lso1')
00158 app.addAlgorithm(ta1)
00159 ta2 = TesterAlg('TesterAlg12',size,
00160 '/dd/Structure/AD/db-ade2/db-sst2/db-oil2/db-oav2/db-lso2')
00161 app.addAlgorithm(ta2)
00162 return