Stefan Roiser CERN / PH / SFT

Slides:



Advertisements
Similar presentations
Question Bank. Explain the syntax of if else statement? Define Union Define global and local variables with example Concept of recursion with example.
Advertisements

C++ Language Fundamentals. 2 Contents 1. Introduction to C++ 2. Basic syntax rules 3. Declaring and using variables.
Reflex Dictionary Generator Antti Hahto
Seal Dictionary Applications Area Internal Review 20 October 2003 Stefan Roiser / CERN.
SEAL Reflex, the new Reflection Library Stefan Roiser (for the LCG/SEAL Dictionary work package) LCG Applications Area Meeting, Oct. 6, 2004.
Review of C++ Programming Part II Sheng-Fang Huang.
SEAL V1 Status 12 February 2003 P. Mato / CERN Shared Environment for Applications at LHC.
Java and C++, The Difference An introduction Unit - 00.
CSE 332: C++ templates This Week C++ Templates –Another form of polymorphism (interface based) –Let you plug different types into reusable code Assigned.
CINT & Reflex: New Reflection Data Structures Masa(haru) Goto Agilent Philippe Canal Fermilab/CD Stefan Roiser, Axel Naumann PH/SFT.
Copyright © 2012 Pearson Education, Inc. Chapter 13: Introduction to Classes.
Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 13: Introduction to Classes.
Looping and Counting Lecture 3 Hartmut Kaiser
C++ Programming Basic Learning Prepared By The Smartpath Information systems
The SEAL C++ Reflection System Stefan Roiser (for the LCG/SEAL Dictionary work package) CHEP 2004, 27. Sept Oct., Interlaken.
JACO JACO - Java Access to C++ Objects Mark Dönszelmann and Tony Johnson 25 May 2000.
CS 11 C++ track: lecture 1 Administrivia Need a CS cluster account sysadmin/account_request.cgi Need to know UNIX (Linux)
Python Primer 1: Types and Operators © 2013 Goodrich, Tamassia, Goldwasser1Python Primer.
LC Software Workshop, May 2009, CERN P. Mato /CERN.
Introduction to Java Chapter 7 - Classes & Object-oriented Programming1 Chapter 7 Classes and Object-Oriented Programming.
Inheritance. Inheritance - Introduction Idea behind is to create new classes that are built on existing classes – you reuse the methods and fields and.
CMPSC 16 Problem Solving with Computers I Spring 2014 Instructor: Lucas Bang Lecture 16: Introduction to C++
Spring 2009 Programming Fundamentals I Java Programming XuanTung Hoang Lecture No. 8.
Prof. amr Goneid, AUC1 CSCE 110 PROGRAMMING FUNDAMENTALS WITH C++ Prof. Amr Goneid AUC Part 15. Dictionaries (1): A Key Table Class.
ROOT Team Meeting Axel Naumann CERN PH/SFT Crienftlex Extended Version. And also Director’s Cut. Crienftlex.
D. Duellmann - IT/DB LCG - POOL Project1 The LCG Dictionary and POOL Dirk Duellmann.
CINT & Reflex – The Future CINT’s Future Layout Reflex API Work In Progress: Use Reflex to store dictionary data Smaller memory footprint First step to.
Copyright © 2015, 2012, 2009 Pearson Education, Inc., Publishing as Addison-Wesley All rights reserved. Chapter 13: Introduction to Classes.
G.Govi CERN/IT-DB 1GridPP7 June30 - July 2, 2003 Data Storage with the POOL persistency framework Motivation Strategy Storage model Storage operation Summary.
CINT/Reflex workshop 1 Rene Brun 4 May 2005 Summary of the CINT/Reflex workshop 2-6 May 2005
ROOT / Reflex ‘07+ Stefan Roiser Missed last team meeting b/c.
CS212: Object Oriented Analysis and Design
C++ Lesson 1.
Pointer to an Object Can define a pointer to an object:
Procedural and Object-Oriented Programming
SEAL Project Status LCG Applications Area Internal Review
Winter 2009 Tutorial #6 Arrays Part 2, Structures, Debugger
VBA - Excel VBA is Visual Basic for Applications
Dictionary generation for the Experiments
Module 11: File Structure
Introduction to C++ Systems Programming.
Event Data Definition in LHCb
Semantic Analysis with Emphasis on Name Analysis
Assignment #1 Advanced Programming in C /2017
Activities and Intents
Review: Two Programming Paradigms
Geant4 Geometry Objects Persistency using ROOT
C++ in 90 minutes.
Introduction to Classes
Dirk Düllmann CERN Openlab storage workshop 17th March 2003
Data Modeling II XML Schema & JAXB Marc Dumontier May 4, 2004
C++ History C++ was designed at AT&T Bell Labs by Bjarne Stroustrup in the early 80's Based on the ‘C’ programming language C++ language standardised in.
Java Review: Reference Types
The dirty secrets of objects
Introduction to Classes
Pointers, Dynamic Data, and Reference Types
Abstraction: Generic Programming, pt. 2
Variables, Identifiers, Assignments, Input/Output
Sridhar Narayan Java Basics Sridhar Narayan
Python Primer 1: Types and Operators
Introduction to Classes and Objects
Lab4 problems More about templates Some STL
CSCE 314: Programming Languages Dr. Dylan Shell
Pointers and References
Pointers, Dynamic Data, and Reference Types
SPL – PS1 Introduction to C++.
Abstract Types Defined as Classes of Variables
Introduction to Classes and Objects
Presentation transcript:

Stefan Roiser CERN / PH / SFT Reflex & new rootcint Stefan Roiser CERN / PH / SFT

Content Reflection in general Reflex introduction Design API Code Examples Reflex Integration with ROOT/CINT Generation of Dictionaries Status Outlook Stefan Roiser ROOT Users Workshop - 28 Sep 2005

Definitions Reflection is the ability of a language to introspect it’s own structure at runtime and interact with it in a generic way A dictionary provides reflection information about types of a certain language to the user Stefan Roiser ROOT Users Workshop - 28 Sep 2005

What is Reflection? Without prior knowledge about objects Particle p; ClassBuilder(“Particle”). AddDataMember(“m_mass”). AddFunctionMember(“mass”); Particle p; std::cout << p.mass(); Type t = Type::ByName(“Particle”); Object o = t.Construct(); std::cout << object_cast<double> (o.Invoke(“mass”)); o.Destruct(); class Particle { public: double mass(); private: double m_mass; }; Stefan Roiser ROOT Users Workshop - 28 Sep 2005

Reflection and C++ Very limited support by the language (RTTI) CINT Other languages do (e.g. Java, Python,…) CINT Supports reflection of C++ constructs Several other approaches exist, but … Tied to a system or Instrumentation of code needed Stroustrup proposed XTI (eXtended Type Information) Dormant project Stefan Roiser ROOT Users Workshop - 28 Sep 2005

Goals Enhance C++ with reflection capabilities non intrusive, automated Close to the C++ ISO 14882 standard Extra information stored in “properties” Light and standalone system Small memory footprint Multi platform Linux, Windows, Mac OSX, … Stefan Roiser ROOT Users Workshop - 28 Sep 2005

3 Levels of Reflection Reflex supports: Introspection Interaction Retrieve information (e.g. class name, return type) Interaction Handle objects (e.g. create instance, call function, get/set data member) Modification Change information (e.g. add function member, add properties, add class template instance) Stefan Roiser ROOT Users Workshop - 28 Sep 2005

Design ideas API Identification Implementation Handful (i.e. 8 ) classes the user has to deal with Full functionality, mainly through forward functions Identification A unique immutable id of each type/scope (no delete) Implementation Provides the content of the reflection information Stefan Roiser ROOT Users Workshop - 28 Sep 2005

Reflection Model TypeTempl Type MemberTempl PropertyList Object User Level Scope Base Member TypeName ScopeName Identification TypeBase ScopeBase Class Array Function Typedef Pointer Namespace TemplateInst FunMemTInst ClassTInst PropListImpl MemberBase Union Pointer2Mem Fundamental Enum DataMember FuncMember Implementation TypeTImpl MemberTImpl Stefan Roiser ROOT Users Workshop - 28 Sep 2005

User Classes (general) Small memory allocation ~ sizeof (Pointer) + sizeof(int) By value semantics operator bool() Will return true if the Type, Scope, etc. is declared and implemented Function “std::string Name(unsigned)” Returns the “SCOPED | FINAL | QUALIFIED” name Many “Is*” functions to ask questions e.g. IsVolatile, IsClass, etc. Stefan Roiser ROOT Users Workshop - 28 Sep 2005

User Classes Type Scope Member Pointer, Pointer to Member, Typedef, Array, Function, Union, Enum, Fundamental, Class, Instantiated Template Class Contains CV qualification (plus Reference) Function return/parameter types, array length, typedef types Scope Namespace, Class, Union, Enum Walk up/down hierarchy, access type/member information Member Function Member, Data Member Invoke function members, get/set data members Stefan Roiser ROOT Users Workshop - 28 Sep 2005

User Classes (ctd.) Object PropertyList Base Represents a C++ class instance (address + type) Invoke functions, get/set members, dynamic type PropertyList Attach collection of key/value pairs to Types, Scopes, Members Key is string, Value is “Any” object Base Base type, access, offset TypeTemplate / MemberTemplate Template instances, template parameters Stefan Roiser ROOT Users Workshop - 28 Sep 2005

Example: Introspection // The Reflex namespace inside Root using namespace ROOT::Reflex; // Get type by its name Type cl = Type::ByName(“Particle”); // If class print all data members if ( cl.IsClass() ) { for ( size_t d = 0; d < cl.DataMemberCount(); d++ ) { Member dm = cl.DataMemberNth(d); cout << dm.Type().Name(SCOPED) << " " << dm.Name() <<";"; // output comment line if exists if ( dm.PropertyList().HasKey("comment") ) { cout << m.PropertyListGet().PropertyAsString("comment"); } cout << endl; Stefan Roiser ROOT Users Workshop - 28 Sep 2005

Example: Interaction // Get a type by its name Type cl = Type::ByName(“Particle”); // Instantiate an instance Object obj = cl.Construct(); // Call a method Object ret = obj.Invoke(“function”); // Alternatively for ( size_t f = 0; f < cl.FunctionMemberCount(); f++ ) { if (cl.FunctionMemberNth(f).Name() == “function”) { ret = cl.FunctionMemberNth(f).Invoke(obj); } // Delete the instance obj.Destruct(); Stefan Roiser ROOT Users Workshop - 28 Sep 2005

Why using Reflex? Advantages Memory Allocation 100 % C++ code Better C++ coverage Smaller memory footprint Memory Allocation ROOT / CINT Reflex -> Mini workshop 2005 @ CERN - Decision to use Reflex Stefan Roiser ROOT Users Workshop - 28 Sep 2005

Integration with ROOT CINT Datastructs CINT CintDict.so CINT API interpreter Cintex ROOT Meta Datastructs ROOT meta PyRoot Reflex API Datastructs RflxDict.so pyreflex Stefan Roiser ROOT Users Workshop - 28 Sep 2005

Integration with ROOT CINT CINT API interpreter ROOT ROOT Meta Datastructs ROOT meta PyRoot Reflex API Reflex/CINT Datastructs RflxDict.so pyreflex Stefan Roiser ROOT Users Workshop - 28 Sep 2005

Integration with ROOT CINT CINT API interpreter ROOT meta PyRoot Reflex API Reflex/CINT Datastructs RflxDict.so pyreflex Stefan Roiser ROOT Users Workshop - 28 Sep 2005

Dictionary Generation with CINT rootcint -reflex CINT parser rflx_gendict Type Selection Linkdef.h G__* .cxx .h make .so .cxx X User Program Core .so Cint .so Cintex.so Reflex .so Stefan Roiser ROOT Users Workshop - 28 Sep 2005

Dictionary Generation with gccxml rootcint -gccxml gcc_xml .xml gendict.py selection.xml Type Selection Linkdef.h (temp) .h G__* .cxx .so make make .cxx X Reflex .so Cintex.so Cint .so User Program Core .so Stefan Roiser ROOT Users Workshop - 28 Sep 2005

selection.xml file Functionality Simple adaptation to user requests Allows inclusion/exclusion of types Usage of patterns Apply special information (transient, class ID) Non-intrusive way of attaching information Simple adaptation to user requests <lcgdict> <class pattern=“T*”/> <class name=“Particle”> <field name=“fOnlyInMemory” transient=“true”/> </class> <exclusion> <class name=“Vertex”/> </exclusion> </lcgdict> Stefan Roiser ROOT Users Workshop - 28 Sep 2005

gcc_xml “[…] generate an XML description of a C++ program from GCC's internal representation.” Any gcc compilable program can be used as input “rootcint -gccxml” uses the temporary XML file to produce dictionary C++ source files Stefan Roiser ROOT Users Workshop - 28 Sep 2005

Parser commands Current Status Transition phase Final status [] ~ > rootcint -f dict.cxx –c … (Cint dictionaries) Current Status [] ~ > rootcint -f dict.cxx -c … (Cint dictionaries) [] ~ > rootcint -f dict.cxx –c -reflex … (Reflex dict wth Cint) [] ~ > rootcint -f dict.cxx -c -gccxml … (Reflex dict wth gccxml) Transition phase [] ~ > rootcint -f dict.cxx -c … (Reflex dict wth Cint) [] ~ > rootcint -f dict.cxx -c -gccxml … (Reflex dict wth gccxml) Final status Stefan Roiser ROOT Users Workshop - 28 Sep 2005

Status Reflex Cintex rootcint -reflex rootcint -reflex -gccxml Ready to use (available through ROOT cvs) For the time being optional in ROOT (--enable-reflex) Cintex For the time being optional in ROOT (--enable-cintex) rootcint -reflex rootcint integration missing (trivial) makecint produces reflex dictionaries (~ 80 % of C++ standard) rootcint -reflex -gccxml Works with selection.xml file Understand Linkdef.h syntax Stefan Roiser ROOT Users Workshop - 28 Sep 2005

Outlook Reflex/Cintex rootcint -reflex rootcint -reflex -gccxml New versions will be imported in ROOT cvs Selection classes for Reflex (allows type selection from within C++) rootcint -reflex October release: most functionality will be available December release: ready rootcint -reflex -gccxml October release: gendict.py understanding Linkdef.h syntax Reflex/Cint datastructures merge See Philippe’s talk Stefan Roiser ROOT Users Workshop - 28 Sep 2005

Pointers Seal Dictionary page Reflex page (work in progress …) GCC_XML http://seal.web.cern.ch/seal/snapshot/work-packages/dictionary/index.html Reflex page (work in progress …) http://cern.ch/seal-reflex GCC_XML http://www.gccxml.org Stefan Roiser ROOT Users Workshop - 28 Sep 2005