1 / 4

Containers in GaudiPython E. Rodrigues, NIKHEF

LHCb Core Software Meeting. Containers in GaudiPython E. Rodrigues, NIKHEF. Access to Gaudi containers not natural/simple in Python. The Standard Way. import gaudimodule gaudi = gaudimodule.AppMgr() EVT = gaudi.evtsvc(). >>> hits = EVT[ ‘Event/MC/OT/Hits’ ] >>> type(hits)

khuong
Download Presentation

Containers in GaudiPython E. Rodrigues, NIKHEF

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. LHCb Core Software Meeting Containers in GaudiPython E. Rodrigues, NIKHEF LHCb Core Software Meeting, 18 Jan. 2006

  2. Access to Gaudi containers not natural/simple in Python The Standard Way import gaudimodule gaudi = gaudimodule.AppMgr() EVT = gaudi.evtsvc() >>> hits = EVT[ ‘Event/MC/OT/Hits’ ] >>> type(hits) <class 'gaudimodule.KeyedContainer<MCHit,Containers::KeyedObjectManager<Containers::hashmap> >'> >>> 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) <type ‘list’> >>> for hit in lhits: ... print hit This would be preferred … … and is widely used in practice … LHCb Core Software Meeting, 18 Jan. 2006

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

  4. Simple extension to gaudimodule.py 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() ) ] # inside the AppMgr class! class AppMgr( iService ) : # … def levtsvc( self ) : svc = Helper.service( self._svcloc, 'EventDataSvc' ) return iListDataSvc(name, svc) # … levtSvc = levtsvc PROPOSAL BTW: also works for the detector data service with the replacement ‘EventDataSvc’ by ‘DetectorDataSvc’ LHCb Core Software Meeting, 18 Jan. 2006

More Related