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

Slides:



Advertisements
Similar presentations
1 Heaps & Priority Queues (Walls & Mirrors - Remainder of Chapter 11)
Advertisements

Gaudi Framework Tutorial, April Accessing Event Data.
. Templates. Example… A useful routine to have is void Swap( int& a, int &b ) { int tmp = a; a = b; b = tmp; }
Using Templates Object-Oriented Programming Using C++ Second Edition 11.
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.
Chapter 3.7 Memory and I/O Systems. 2 Memory Management Only applies to languages with explicit memory management (C or C++) Memory problems are one of.
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
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.
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.
LECTURE LECTURE 17 More on Templates 20 An abstract recipe for producing concrete code.
REFACTORING Lecture 4. Definition Refactoring is a process of changing the internal structure of the program, not affecting its external behavior and.
Recursion Bryce Boe 2013/11/18 CS24, Fall Outline Wednesday Recap Lab 7 Iterative Solution Recursion Binary Tree Traversals Lab 7 Recursive Solution.
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.
COIT29222 Structured Programming Slide 1 COIT29222-Structured Programming Lecture Week 06  Reading: Study Guide Book 2, Modules 9 & 10 Textbook (4 th.
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.
C++ Tutorial Hany Samuel and Douglas Wilhelm Harder Department of Electrical and Computer Engineering University of Waterloo Copyright © 2006 by Douglas.
Stacks. A stack is a data structure that holds a sequence of elements and stores and retrieves items in a last-in first- out manner (LIFO). This means.
Priority Queues Dr. David Matuszek
Copyright © Curt Hill Generic Classes Template Classes or Container Classes.
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.
CS 376b Introduction to Computer Vision 01 / 23 / 2008 Instructor: Michael Eckmann.
C Functions Three major differences between C and Java functions: –Functions are stand-alone entities, not part of objects they can be defined in a file.
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
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
1 Becoming More Effective with C++ … Day Two Stanley B. Lippman
Bologna Tutorial, April Job Options and Printing.
Data Structures and Algorithms Searching Algorithms M. B. Fayek CUFE 2006.
Tutorial: Examples (09may00 - ATLAS Software LBNL) May 2000 Prototype Framework Tutorial: Examples Paolo Calafiura, Charles Leggett HCG/NERSC/LBNL.
INFSO-RI Enabling Grids for E-sciencE gLite C++ Configurator Practical experience gLite Configuration Meeting, March 1, 2005 Peter.
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.
Chapter 17: Linked Lists. Objectives In this chapter, you will: – Learn about linked lists – Learn the basic properties of linked lists – Explore insertion.
Nirmalya Roy School of Electrical Engineering and Computer Science Washington State University Cpt S 223 – Advanced Data Structures C++ Review 2.
OOP Basics Classes & Methods (c) IDMS/SQL News
Copyright © 2012 Pearson Education, Inc. Chapter 10 Advanced Topics.
Gaudi Framework Tutorial, Algorithm Tools: what they are and how to use them.
9 Associators How to relate objects to each other Create relations Save relations Use relations: Associators.
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++
Classes C++ representation of an object
“Algorithm Tools” what they are, how to get them and how to use them
CS 215 Final Review Ismail abumuhfouz Fall 2014.
Writing Physics Tools Schedule: Timing Topic 20 minutes Lecture
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
CSE 432 Presentation GoF: Factory Method PH: “To Kill a Singleton”
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 FromObj2ToObjAsct : public Associator[Weighted] {... }; OtherInfo is optional (should not relect the method used but the content) –If ToObj and FromObj can be “factorised”, do not repeat the common part in ToObj class Particle2MCWithChi2Asct; 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 Particle2MCWithChi2Asct : 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 Particle2MCWithChi2Asct(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 Particle2MCWithChi2Asct::FromRange ParticlesToMCChi2; typedef Particle2MCWithChi2Asct::FromIterator ParticlesToMCChi2Iterator; typedef Particle2MCWithChi2Asct::ToRange MCsFromParticleChi2; typedef Particle2MCWithChi2Asct::ToIterator MCsFromParticleChi2Iterator; 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/Particle2MCWithChi2Asct.h” // Declare factory for the associator static const ToolFactory s_Particle2MCWithChi2AsctFactory; const IToolFactory& Particle2MCWithChi2AsctFactory = s_Particle2MCWithChi2AsctFactory; // Declare factory for the relations table static const DataObjectFactory s_Particle2MCWithChi2TableFactory; const Ifactory& Particle2MCWithChi2TableFactory = s_Particle2MCWithChi2TableFactory;... DECLARE_FACTORY_ENTRIES( PhysAssociators ) { DECLARE_OBJECT( Particle2MCWithChi2Table ); // Declare the Table object DECLARE_TOOL( Particle2MCWithChi2Asct ); // Declare the Associator tool DECLARE_ALGORITHM( Particle2MCWithChi2 ); // 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*): Particle2MCWithChi2Asct::IAsct* m_pAsctWithChi2; ///< Pointer to associator with chi2 as weight.. // This is the Particle2MCWithChi2 tool sc = toolSvc()->retrieveTool( "Particle2MCWithChi2Asct", m_pAsctWithChi2); /// “Particle2MCWithChi2Asct” 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 =... ;... MCsfromParticleChi2 mcParts = m_pAsctWithChi2->rangeFrom( part ); MCsfromParticleChi2Iterator 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 =... ;... ParticlesToMCChi2 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 default Associator (called Particle2MCAsct) sc = toolSvc()->retrieveTool( m_nameMCAsct, m_pAsctChi2); // This is another type of Particle2MC tool, diffentiated by jobOptions sc = toolSvc()->retrieveTool( m_nameMCAsct, "LinkAsct", m_pAsctLinks ); –In the JobOptions file, declare different locations and algorithms // default associator using best chi2 Toolsvc.Particle2MCAsct.Location = "Phys/Relations/Particle2MC"; ToolSvc.Particle2MCAsct.AlgorithmType = "Particle2MCChi2"; ToolSvc.Particle2MCAsct.AlgorithmName = "Particle2MCChi2"; // alternate associator using stored links Toolsvc.LinkAsct.Location = "Phys/Relations/Particle2MCLinks"; ToolSvc.LinkAsct.AlgorithmType = "Particle2MCLinks"; ToolSvc.LinkAsct.AlgorithmName = "Particle2MCLinks";

9.19DaVinci Tutorial Caveats Location of the table –No direct connection between the Associator (location property) and the creation algorithm… –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 (e.g. as default property of the algorithm) declareProperty( "OutputData", m_outputData = Particle2MCAsctLocation );... StatusCode sc = eventSvc()->registerObject( outputData(), table);

9.20DaVinci Tutorial DaVinci Associators Package Phys/DaVinciAssociators Two associators defined, with 3 creation algorithms UserAlgo Particle2MCAsct Particle2MCWithChi2Asct Particle2MCLinks Particle2MCWithChi2 Particle2MCChi2 TES /Phys/…/Particles /Phys/Relations/Particle2MC /Phys/Relations/Particle2MCWithChi2 /Phys/Relations/Particle2MCLink

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

9.22DaVinci Tutorial DaVinciAssociators 3 Caveat –Be careful with inputData and location of the relations table in the TES Outlook –Use an array of TES locations as inputData –Transmit properties from the tool to the algorithm in order to have only once the definition of the location in the TES –Use ProtoParticles to establish the relation (when available)

9.23DaVinci 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…