9 Associators How to relate objects to each other Create relations Save relations Use relations: Associators.

Slides:



Advertisements
Similar presentations
Gaudi Framework Tutorial, April Accessing Event Data.
Advertisements

Object-Oriented PHP (1)
. Templates. Example… A useful routine to have is void Swap( int& a, int &b ) { int tmp = a; a = b; b = tmp; }
1 Data Structures Data Structures Topic #2. 2 Today’s Agenda Data Abstraction –Given what we talked about last time, we need to step through an example.
Templates. Objectives At the conclusion of this lesson, students should be able to Explain how function templates are used Correctly create a function.
Data Structures Using C++ 2E
Automation Repository - QTP Tutorials Made Easy The Zero th Step TEST AUTOMATION AND QTP.
CSE 332: C++ templates and generic programming I Motivation for Generic Programming in C++ We’ve looked at procedural programming –Reuse of code by packaging.
DaVinci status Juan Palacios LHCb Software Week March, 2009.
SEAL V1 Status 12 February 2003 P. Mato / CERN Shared Environment for Applications at LHC.
The Pseudocode Programming Process Chapter 9. Summary of Steps in Building Classes and Routines.
Object Oriented Data Structures
Programming Languages and Paradigms Object-Oriented Programming.
REFACTORING Lecture 4. Definition Refactoring is a process of changing the internal structure of the program, not affecting its external behavior and.
Recap, Test 1 prep, Composition and Inheritance. Dates Test 1 – 12 th of March Assignment 1 – 20 th of March.
Data Structures Using C++ 2E
Design patterns. What is a design pattern? Christopher Alexander: «The pattern describes a problem which again and again occurs in the work, as well as.
Programming in Java Unit 2. Class and variable declaration A class is best thought of as a template from which objects are created. You can create many.
CS212: Object Oriented Analysis and Design Lecture 6: Friends, Constructor and destructors.
CERN Tutorial, September Job Options and Printing.
Job Options and Printing 1 LHCb software tutorial - September 2011.
Copyright © Curt Hill Generic Classes Template Classes or Container Classes.
9 Associators How to relate objects to each other Create relations Save relations Use relations: Associators.
Object-Oriented Program Development Using Java: A Class-Centered Approach, Enhanced Edition.
Particle to MC truth association Juan Palacios (Nikhef) LHCb software week June
Use of Gaudi in Reconstruction Weidong Li 23/06/2004.
Gaudi Framework Tutorial, April Algorithm Tools: what they are, how to write them, how to use them.
Gaudi Framework Tutorial, April Job Options and Printing.
Chapter 10 Defining Classes. The Internal Structure of Classes and Objects Object – collection of data and operations, in which the data can be accessed.
Nyhoff, ADTs, Data Structures and Problem Solving with C++, Second Edition, © 2005 Pearson Education, Inc. All rights reserved Stacks.
Lecture 3 Classes, Structs, Enums Passing by reference and value Arrays.
Slide 1 Linked Data Structures. Slide 2 Learning Objectives  Nodes and Linked Lists  Creating, searching  Linked List Applications  Stacks, queues.
CS212: Object Oriented Analysis and Design Lecture 24: Introduction to STL.
Overview of C++ Templates
Interfaces About Interfaces Interfaces and abstract classes provide more structured way to separate interface from implementation
Physical Database Design Purpose- translate the logical description of data into the technical specifications for storing and retrieving data Goal - create.
CS-1030 Dr. Mark L. Hornick 1 Basic C++ State the difference between a function/class declaration and a function/class definition. Explain the purpose.
Chapter 5 Index and Clustering
The Prototype Pattern (Creational) ©SoftMoore ConsultingSlide 1.
Bologna Tutorial, April Job Options and Printing.
Tutorial: Examples (09may00 - ATLAS Software LBNL) May 2000 Prototype Framework Tutorial: Examples Paolo Calafiura, Charles Leggett HCG/NERSC/LBNL.
More about Java Classes Writing your own Java Classes More about constructors and creating objects.
Review of Function Overloading Allows different functions to have the same name if they have different types or numbers of arguments, e.g. int sqr(int.
INFSO-RI Enabling Grids for E-sciencE gLite C++ Configurator Practical experience gLite Configuration Meeting, March 1, 2005 Peter.
Gaudi Framework Tutorial, April Creating Objects and Writing Data.
DaVinciAssociators How to relate physics objects to MC truth.
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.
Object Oriented Programming Elhanan Borenstein Lecture #7.
Nirmalya Roy School of Electrical Engineering and Computer Science Washington State University Cpt S 223 – Advanced Data Structures C++ Review 2.
Copyright © 2012 Pearson Education, Inc. Chapter 10 Advanced Topics.
Gaudi Framework Tutorial, Algorithm Tools: what they are and how to use them.
Gaudi Framework Tutorial, April Histograms And N-tuples.
Athena StoreGate Tutorial: May 30, Objectives Learn how to access data objects using StoreGate How to record/retrieve by TYPE Optionally using keys.
11/15/2004 CDB LCG/CONDDB MEETING (CERN) 1 An Overview of the CDB API Igor A. Gaponenko (LBNL)
Gaudi Framework Tutorial, April Histograms And N-tuples.
Classes CS 162 (Summer 2009). Parts of a Class Instance Fields Methods.
Motivation for Generic Programming in C++
CS212: Object Oriented Analysis and Design
Pointer to an Object Can define a pointer to an object:
Classes C++ representation of an object
“Algorithm Tools” what they are, how to get them and how to use them
Static data members Constructors and Destructors
CS 215 Final Review Ismail abumuhfouz Fall 2014.
Writing Physics Tools Schedule: Timing Topic 20 minutes Lecture
CS212: Object Oriented Analysis and Design
Map interface Empty() - return true if the map is empty; else return false Size() - return the number of elements in the map Find(key) - if there is an.
Array Lists Chapter 6 Section 6.1 to 6.3
Data Structures & Algorithms
Classes C++ representation of an object
Accessing Event Data Schedule: Timing Topic 20 minutes Lecture
Presentation transcript:

9 Associators How to relate objects to each other Create relations Save relations Use relations: Associators

9.2DaVinci Tutorial Relations between objects Which type of objects –Any object: int, double, complex class, keyed/contained objects… –Most interesting: two sets of contained objects What is a relation? From set To set

9.3DaVinci Tutorial Types of relations One or two directional (1D / 2D) –But reverse relations can always be retrieved from direct relations –Hence, only 1D relations are made persistent –Advice: create only 1D relations, unless both usages are frequent Normal relations –Simple link between objects –Not necessarily between all objects of each set –Possibly several links from/to an object Weighted relations –The link carries additional information (can be any class) An ordering should be possible on the WEIGHT class Example: int, double But could be complex class with the == and < operators defined

9.4DaVinci Tutorial How to create relations 1. Instantiate the relation table (in the creation algorithm) #include “MyAssociator.h”.. new Table* table; // The type “Table” is defined in MyAssociator.h 2. Usually one loops on all objects in the FROM set for( from_iterator frIt=from.begin(); from.end()!=frIt; frIt++) { 3. For each object, decide which objects of the TO set to link to, possibly which weight. double weight = computeWeight( frIt, toIt ); if( weight > 0 ) { // Example of how to decide 4. Establish the relation table->relate( *frIt, *toIt [, weight]);

9.5DaVinci Tutorial How to save relations (1) Once the table is filled Optionally apply filters (if weighted) FromObj* from; ToObj* to; Weight threshold; table->filterFrom( from, threshold, {false,true}); // Keeps only relations with weight > (true) or > than a threshold Optionally remove some relations (all) table->removeFrom( from ); table->removeTo( to );

9.6DaVinci Tutorial How to save relations (2) Declare the relations table in the transient store StatusCode sc = eventSvc()->registerObject( outputData(), table); // outputData() returns the location in TES // it should be declared as a property of the algorithm If the table should be discarded (e.g. in case of error) –Do not forget to delete table; // avoid memory leaks!

9.7DaVinci Tutorial How to use relations? In order to use relations, the user algorithm should use a Gaudi tool called an Associator Generic Associator tool available Guidelines for Associators –Specialise the associator (for ease of use) –New class derived from the class Associator –For weighted Associators: class AssociatorWeighted Where does the tool look for the table? –The tool looks in the TES –If not found, it tries and get it from the PES –If not found, one can define a construction algorithm which should save the relations table in the TES (at the location they are expected!)

9.8DaVinci Tutorial Associators Naming conventions –Type of the Associator tool class FromObj2ToObjOtherInfoAsct : public Associator[Weighted] {... }; OtherInfo is optional (should not reflect the method used but the content) –If ToObj and FromObj can be “factorised”, do not repeat the common part in ToObj class Particle2MCWeightedAsct; class ITCluster2MCParticleAsct; –Type for the relations table FromObj2ToObjOtherInfoAsct::Table –Type for the Associator tool interface FromObj2ToObjOtherInfoAsct::IAsct

9.9DaVinci Tutorial Declaring an associator In MyAssociator.h (note that “Weighted” is only in case of weighted relations) #include "Relations/AssociatorWeighted.h”.. class Particle2MCWeightedAsct : public AssociatorWeighted { public: // Define data types // Define the relations table, templated class typedef RelationWeighted1D Table; // Defines the type of the base associator typedef OwnType Asct;.. // Minimal constructor Particle2MCWeightedAsct(const std::string& type, const std::string& name, const IInterface* parent ) : Asct( type, name, parent) { }; }

9.10DaVinci Tutorial Declaring an associator (2) Declare types for retrieving ranges of objects –When getting objects related to a given From (To) object, one gets a “range” –A “range” can be seen as a list/vector of objects –A “range” has an iterator, with the usual begin() and end() methods –For ease of use, one can define meaning full types for ranges, e.g. typedef Particle2MCWeightedAsct::FromRange ParticlesToMC; typedef Particle2MCWeightedAsct::FromIterator ParticlesToMCIterator; typedef Particle2MCWeightedAsct::ToRange MCsFromParticle; typedef Particle2MCWeightedAsct::ToIterator MCsFromParticleIterator; DLL file for loading the tool –MyAssociators_dll.cpp #include "GaudiKernel/LoadFactoryEntries.h" LOAD_FACTORY_ENTRIES(PhysAssociators)

9.11DaVinci Tutorial Declaring an Associator (3) A _load.cpp file must be defined to declare the necessary factories –MyAssociators_load.cpp: #include "DaVinciAssociators/Particle2MCWeightedAsct.h” // Declare factory for the associator DECLARE_TOOL_FACTORY( Particle2MCWeightedAsct ); // Declare factory for the relations table DECLARE_OBJECT_FACTORY( Particle2MCWeightedTable );. DECLARE_FACTORY_ENTRIES( PhysAssociators ) { DECLARE_OBJECT( Particle2MCWeightedTable ); // Declare the Table object DECLARE_TOOL( Particle2MCWeightedAsct ); // Declare the Associator tool DECLARE_ALGORITHM( Particle2MCWeighted ); // Declare the construction algorithm }

9.12DaVinci Tutorial An instance of the tool should be created in the user algorithm –Returns a pointer to an Associator interface (type Iasct*): Particle2MCWeightedAsct::IAsct* m_pAsctWithChi2; ///< Pointer to associator with chi2 as weight.. // This is the Particle2MCWeighted tool sc = toolSvc()->retrieveTool( "Particle2MCWeightedAsct", m_pAsctWithChi2); /// “Particle2MCWeightedAsct” is the type of the tool (as in _load) /// m_pAsctWithChi2 is a pointer to the interface used later on Retrieving an Associator [“MyAssociator”,] /// [“MyAssociator”,] is an optional private name to that tool

9.13DaVinci Tutorial Using an Associator Retrieve a range of ToObj given a FromObj Particle* part =... ;... MCsfromParticle mcParts = m_pAsctWithChi2->rangeFrom( part ); MCsfromParticleIterator mcPartsIt; for( mcPartIt = mcParts.begin(); mcParts.end() != mcPartIt; mcPartIt++) {... // CAUTION: *mcPartIt is not of type MCParticle!!! MCParticle* mcPart = mcPartIt->to(); Weight weight = mcPartIt->weight(); } Similarly one can retrieve a range of FromObj given a ToObj Particle* part =... ;... ParticlesToMC parts = m_pAsctWithChi2->rangeTo( mcPart );

9.14DaVinci Tutorial Using an Associator (2) Often, relations are one-to-one between the two sets –Possibly no linked object, but never 2 or more –Shortcut to directly access the object: MCParticle* mcPartChi2; double chi2; mcPartChi2 = m_pAsctWithChi2->associatedFrom( *part[, chi2]); if( mcPartChi2 ) { // There was an associated MCParticle } else { // There was no associated MCParticle OR there was not relations table }

9.15DaVinci Tutorial Using an Associator (3) Advanced usage of weighted associators –One can retrieve relations which have a weight larger (smaller) than a threshold Particle* part =... ;... MCsfromParticleChi2 mcParts = m_pAsctWithChi2->rangeWithHighCutFrom( part, maxChi2 ); // This will return a range containing only associated MCParticles // if the weight (I.e. the chi2) is smaller than maxChi2 –No one-to-one retrieval method with cut, but trivially double chi2; mcPartChi2 = m_pAsctWithChi2->associatedFrom( *part, chi2); if( mcPartChi2 && chi2 < maxChi2) { // There was an associated MCParticle with chi2 < maxChi2 }

9.16DaVinci Tutorial Using an Associator (4) Miscellaneous features –Testing if the relations table is present if( false == m_pAsctChi2->tableExists() ) { // The table doesn’t exist } else { // One can retrieve information safely } –Getting a status code when retrieving a range Range range; StatusCode sc = m_pAsct->rangeFrom( from, range); if( sc.isSuccess() ) { // One can use range safely }

9.17DaVinci Tutorial JobOptions for Associators Properties of the base class –No default: to be defined in the constructor using set_property( name, value); –Location of the relations table in the TES Toolsvc.Particle2MCWithChi2Asct.Location = "Phys/Relations/Particle2MCWithChi2"; –Convention for the location name: Root: the TES branch of the “To” objects /Relations Leaf: name of the Associator –Creation algorithm ToolSvc.Particle2MCWithChi2Asct.AlgorithmType = "Particle2MCWithChi2"; ToolSvc.Particle2MCWithChi2Asct.AlgorithmName = "Particle2MCWithChi2"; –Note: one can give an alternate name to the Associator and/or to the algorithm… The same Associator can be used twice with different settings

9.18DaVinci Tutorial JobOptions for Associators (2) Example of dual usage of a single associator –In the code, retrieve the same tool with two different names // First the WithChi2 associator (of type Particle2MCWeightedAsct) sc = toolSvc()->retrieveTool( “Particle2MCWeightedAsct”, “WithChi2Asct”, m_pAsctWithChi2); // This is another type of Particle2MC tool, differentiated by jobOptions sc = toolSvc()->retrieveTool(“Particle2MCWeightedAsct”, "LinkAsct", m_pAsctLinks ); –In the JobOptions file, declare different locations and algorithms // first associator using chi2 as weight Toolsvc.WithChi2Asct.Location = "Phys/Relations/Particle2MCWithChi2"; ToolSvc.WithChi2Asct.AlgorithmType = "Particle2MCWithChi2"; ToolSvc.WithChi2Asct.AlgorithmName = "Particle2MCWithChi2"; // alternate associator using stored links Toolsvc.LinkAsct.Location = "Phys/Relations/Particle2MCLinks"; ToolSvc.LinkAsct.AlgorithmType = "Particle2MCLinks"; ToolSvc.LinkAsct.AlgorithmName = "Particle2MCLinks";

9.19DaVinci Tutorial Further features Location of the table –Advise: Use as for containers a static const definition in the.h file static const std::string& Particle2MCAsctLocation = "Phys/Relations/Particle2MC"; Define the Associator property (in the Associator constructor) setProperty( location, Particle2MCAsctLocation ); Use for registering in the TES OutputTable as property of the algorithm declareProperty( "OutputTable", m_outputTable = Particle2MCAsctLocation );... StatusCode sc = eventSvc()->registerObject( outputTable(), table); The associator automatically sets the OutputTable property of the algorithm

9.20DaVinci Tutorial DaVinci Associators Package Phys/DaVinciAssociators Many associators defined, with various creation algorithms UserAlgo Particle2MCWeightedAsct ProtoParticle2MCAsct Particle2MCWithChi2 ChargedPP2MC Particle2MCLinks TES /Phys/…/Particles /Phys/Relations/Particle2MCLinks /Phys/Relations/ProtoParticle2MC /Phys/Relations/Particle2MCWithChi2

9.21DaVinci Tutorial DaVinciAssociators 2 Algorithm properties –Particle2MCWithChi2.opts Particle2MCWithChi2.InputData ={"Phys/Production/Particles”}; Particle2MCWithChi2.OutputTable = "Phys/Relations/Particle2MCWithChi2"; Particle2MCWithChi2.FillHistos = true; –Particle2MCChi2.opts Particle2MCChi2.InputData = {"Phys/Production/Particles”}; Particle2MCChi2.OutputTable = "Phys/Relations/Particle2MC"; Particle2MCChi2.Chi2Cut = 100.; –Particle2MCLinks.opts Particle2MCLinks.InputData = {"Phys/Production/Particles”}; Particle2MCLinks.OutputTable = "Phys/Relations/Particle2MCLinks";

9.22DaVinci Tutorial Summary Associators and relations tables are very powerful means for linking indirectly objects –No explicit link in the data model –Relations are external and can be serialized or re-created –Exemples: Particle to MCParticle Clusters to MCParticle Vertex to Particles (not implemented that way, but could be) A generic tool exists, could be used as such For physics studies, we suggest to follow guidelines described in this presentation Other users could follow them as well…