1 / 20

Aspect-Oriented Extensions to HEP Frameworks

Aspect-Oriented Extensions to HEP Frameworks. Paolo Calafiura, Craig E. Tull presented by Wim Lavrjisen LBNL NERSC/HCG. What is AOP?. Aspect-Oriented Programming (AOP) Methodology to decompose problems into Functional components (e.g. OO classes)

iokina
Download Presentation

Aspect-Oriented Extensions to HEP Frameworks

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. Aspect-Oriented Extensions to HEP Frameworks Paolo Calafiura, Craig E. Tull presented by Wim Lavrjisen LBNL NERSC/HCG

  2. What is AOP? Aspect-Oriented Programming (AOP) • Methodology to decompose problems into • Functional components (e.g. OO classes) • Aspectsthatcrosscutfunctional components • Technology to weave these components and aspects into an implementation • Started at Xerox PARC in late 90s • About 10 actively supported tools available for AO software development. See http://www.aosd.net Aspect-Oriented Extensions to HEP Frameworks

  3. Display Figure FigureElement moveBy(int, int) makePoint(..)makeLine(..) • DisplayUpdating is an Aspect that crosscuts the class tree, capturing a commonality not readily expressible using inheritance Point Line getX()getY()setX(int)setY(int)moveBy(int, int) getP1()getP2()setP1(Point)setP2(Point)moveBy(int, int) DisplayUpdating The Figure Editor Example • FigureElement captures structural commonalities of Point and Line • Element Factory • Element Movement Aspect-Oriented Extensions to HEP Frameworks

  4. The AOP Promise StatusCode AthenaOutputStream::decodeAcceptAlgs( ) { StatusCode result = decodeAlgorithms( m_acceptNames, m_acceptAlgs ); MsgStream log(msgSvc(), name()); if (m_acceptNames.value().size()) { log << MSG::DEBUG << "Found AcceptNames: " ; vector<string>::const_iterator first = m_acceptNames.value().begin(); vector<string>::const_iterator last = m_acceptNames.value().end(); for (; first != last; ++first) { log << MSG::DEBUG << (*first); } log << MSG::DEBUG << endreq; } return result; } Localize implementation of aspects cutting across “natural” problem decomposition Logging, Thread synchr, Tracing,… StatusCode AthenaOutputStream::decodeVetoAlgs( ) { StatusCode result = decodeAlgorithms( m_vetoNames, m_vetoAlgs ); MsgStream log(msgSvc(), name()); if (m_vetoNames.value().size()) { log << MSG::DEBUG << "Found VetoNames: " ; vector<string>::const_iterator first = m_vetoNames.value().begin(); vector<string>::const_iterator last = m_vetoNames.value().end(); for (; first != last; ++first) { log << MSG::DEBUG << (*first); } log << MSG::DEBUG << endreq; } else { log << MSG::DEBUG << "No VetoNames found " << endreq; } return result; } Claim is that AOP will complement not replaceOOP, components, generic programming, etc. Logging Aspect Aspect-Oriented Extensions to HEP Frameworks

  5. AspectC++ An aspect-oriented extension to C++ modeled on the popular aspectJ language • ac++compiler: weaves aspect code into original sources, emits standard C++ • Supports library-based development • Open-source, release 0.9pre1 July 04 • Actively developed and supported http://www.aspectc.org Aspect-Oriented Extensions to HEP Frameworks

  6. Quick ac++ Syntax Overview http://www.aspectc.org/Documentation.5.0.html An aspect captures a crosscutting concern • Otherwise behaves very much like a C++ class aspect RedirectOstream: virtual public IProperty { private: ISvcLocator* m_locator; public: const MsgStream& log() const; }; Aspect-Oriented Extensions to HEP Frameworks

  7. Quick ac++ Syntax Overview - 2 An advice adds behaviour to an aspect: • what to do before, after, and around certain joinpoints in the control flow aspect RedirectOstream { advice call("ostream & ostream::operator <<(const char*&)")&& args(what): around(const char*& what) { log() << what; } }; //streamlined example, life more complicated Aspect-Oriented Extensions to HEP Frameworks

  8. Quick ac++ Syntax Overview - 3 An advice can (re-)use a pointcut(set of joinpoints) to specify when should run • A pointcut can be ’virtual’, allowing to abstract the “when” of an aspect. aspect DisplayUpdate { pointcut virtual moved() = call(“% FigureElement.moveBy(int, int)”) || call(“void Point.set%(double)”) || call(“void Line.set%(Point)”); }; Aspect-Oriented Extensions to HEP Frameworks

  9. Quick ac++ Syntax Overview - 4 Rich joinpoint API, including accessors to • active objects (this, that, arg, result,…) • reflective info (signatures, types,…) aspect ViewUpdate : public DisplayUpdating { advice moved() : after() { m_display.redraw( tjp->that()); } }; aspect TraceUpdate : public DisplayUpdating { advice moved() : before() { cout << thisJoinPoint->toString() << endl; } }; Aspect-Oriented Extensions to HEP Frameworks

  10. Quick ac++ Syntax Overview - 5 An aspect can introduce in C++ classes • methods, data members and even base classes pointcut mapkeys()=“String || UnsignedLong"; aspect threadSafe { private: advice mapkeys() : baseclass(ThreadNo); }; Aspect-Oriented Extensions to HEP Frameworks

  11. Application Manager Converter Converter Sequencer Converter Event LoopMgr Event Store Data Files Message Service Persistency Service H H H H H StoreGateSvc JobOptions Service Algorithm Algorithm T T T D D Particle Prop. Service Data Files D D StoreGateSvc D D Persistency Service D D D Detector Store Other Services Auditors Histogram Service Athena/Gaudi: our target architecture Aspect-Oriented Extensions to HEP Frameworks

  12. Examples of HEP Cross-cutting Concerns Logging • Redirect cout/cerr output to MsgStream • But templated joinpoints not yet supported by ac++ • Add reflection info to errors/exceptions Interactive Job Configuration • Invoke call back whenever a property attribute of an object is set/modified • Gaudi support this for attributes inheriting from a Property base class • Ideally use “set” pointcut function on attributes • “set” not yet supported by ac++ Aspect-Oriented Extensions to HEP Frameworks

  13. Examples of HEP Cross-cutting concerns Data Object History (aka Provenance) • Gaudi History keeps track of which Algorithm recorded data object to TDS • Aspect also allows to keep track of data object creator and of who modified it. • Pointcut defined as OR of all non-const methods of a data object class Reference Management • Check that objects recorded on TDS are not accidentally deleted. • Check that retrieved services/tools are released. Aspect-Oriented Extensions to HEP Frameworks

  14. Application Manager MotherThread Event LoopMgr Event LoopMgr Message Service StoreGateSvc StoreGateSvc JobOptions Service Algorithm Algorithm Algorithm Algorithm StoreGateSvc StoreGateSvc Thread 1 Thread 2 Thread-aware Naming Service All objects in Gaudi located by name (and type ID). Transparently extend naming scheme to handle MT copies Aspect-Oriented Extensions to HEP Frameworks

  15. Thread-aware Naming Service: C++ Solution When multiple copies exist attach thread ID to object name • Handled in Gaudi using helper classes, but • Hard to edit all name-server codes that needed to use the helpers • Shotgun Surgery (one of Fowler’s “code smells”) • Helper code clutters original (non MT) name-server codes Aspect-Oriented Extensions to HEP Frameworks

  16. Thread-aware Naming Service:AOP Solution • Extend the name type inserting the threadID helper as a base class advice mapkeys() : baseclass(ThreadNo); • Use the new type where the old one was • Still hard to define the pointcut • no more Shotgun surgery: everything in the aspect advice execution("% theLocator::registerService(...)") && args(k, pService) : before(const mapkey& k, IService* pService) {…} Aspect-Oriented Extensions to HEP Frameworks

  17. Do we need AOP? • Helps dealing with constantly evolving requirements  • “Thinking in aspects” provides a vocabulary, if not yet a paradigm, to identify and design cross-cutting concerns. • C++ offers native implementation techniques • Macros (yes, macros!) • Policy-based designs using templated wrappers • But aspects are more compact and powerful using AOP tools • Makes understanding control flow even harder Aspect-Oriented Extensions to HEP Frameworks

  18. Can we use AOP? Not yet (at least not for LHC experiments) • ac++ (our favourite) still not quite ready • Open-sourced, actively developed • Well specified (builds on aspectJ) • Insufficiently documented • Probably not ready for large-scale builds • Slow, no dependency management tool yet • Not yet std C++ compatible • No templates, limited standard library • Further investigate physical coupling. Aspect-Oriented Extensions to HEP Frameworks

  19. AAcknowledgements We would like to thank the ac++ team and community for their support and advice

  20. ac++ implementation • A preprocessor • Emits std c++ • No run-time overhead • Limitations (rel 0.9) • No dependency resolution • Error detection and reporting (~templates) • No namespaces • Limited STL support • No templates in aspects Aspect-Oriented Extensions to HEP Frameworks

More Related