Presentation is loading. Please wait.

Presentation is loading. Please wait.

LHCb Core Software Meeting, 18 Jan. 2006 1/4 Containers in GaudiPython E. Rodrigues, NIKHEF Why >>> for i in range( hits.size() ): >>> for i in range(

Similar presentations


Presentation on theme: "LHCb Core Software Meeting, 18 Jan. 2006 1/4 Containers in GaudiPython E. Rodrigues, NIKHEF Why >>> for i in range( hits.size() ): >>> for i in range("— Presentation transcript:

1 LHCb Core Software Meeting, 18 Jan. 2006 1/4 Containers in GaudiPython E. Rodrigues, NIKHEF Why >>> for i in range( hits.size() ): >>> for i in range( hits.size() ):... print hits.containedObject(i)... print hits.containedObject(i) When we can simply have >>> for hit in hits: >>> for hit in hits:... print hit... print hit LHCb Core Software Meeting

2 LHCb Core Software Meeting, 18 Jan. 2006 2/4 The Standard Way >>> hits = EVT[ ‘Event/MC/OT/Hits’ ] >>> type(hits) >'> >>> for i in range( hits.size() ):... print hits.containedObject(i) # simple conversion container  Python list def toList( container ) : if container == None : return [] return [ container.containedObject(i) for i in range( container.size() ) ] >>> lhits = toList( hits ) >>> type(lhits) >>> for hit in lhits:... print hit import gaudimodule gaudi = gaudimodule.AppMgr() EVT = gaudi.evtsvc() Access to Gaudi containers not natural/simple in Python This would be preferred … … and is widely used in practice …

3 LHCb Core Software Meeting, 18 Jan. 2006 3/4 Some possibilities … >>> hits = LEVT[ ‘Event/MC/OT/Hits’ ] >>> type(hits) >>>  Let’s agree for a second that we want to deal with containers naturally in (Gaudi)Python, i.e. as with lists or tuples 1 st option: every user drags “toList” definitions everywhere – not great 1 st option: every user drags “toList” definitions everywhere – not great 2 nd option: define a “toList” function centrally, say in gaudimodule.py 2 nd option: define a “toList” function centrally, say in gaudimodule.py – one still has to call “toList” everywhere – one still has to call “toList” everywhere 3 rd option: incorporate the conversion in GaudiPython itself – my preference 3 rd option: incorporate the conversion in GaudiPython itself – my preference import gaudimodule gaudi = gaudimodule.AppMgr() LEVT = gaudi.levtsvc() IMAGINE A NEW SERVICE This is possible …

4 LHCb Core Software Meeting, 18 Jan. 2006 4/4 Simple extension to gaudimodule.py # inside the AppMgr class! class AppMgr( iService ) : # … def levtsvc( self ) : svc = Helper.service( self._svcloc, 'EventDataSvc' ) return iListDataSvc(name, svc) # … levtSvc = levtsvc class iListDataSvc( iDataSvc ) : def __getitem__( self, path ) : container = iDataSvc.__getitem__( self, path ) if container == None : return [] return [ container.containedObjects(i) for i in range( container.size() ) ] PROPOSAL BTW: also works for the detector data service with the replacement ‘EventDataSvc’ by ‘DetectorDataSvc’


Download ppt "LHCb Core Software Meeting, 18 Jan. 2006 1/4 Containers in GaudiPython E. Rodrigues, NIKHEF Why >>> for i in range( hits.size() ): >>> for i in range("

Similar presentations


Ads by Google