Tutorial: Examples (09may00 - ATLAS Software LBNL) May 2000 Prototype Framework Tutorial: Examples Paolo Calafiura, Charles Leggett HCG/NERSC/LBNL.

Slides:



Advertisements
Similar presentations
C Language.
Advertisements

INHERITANCE BASICS Reusability is achieved by INHERITANCE
Chapter 7: User-Defined Functions II
OOP in Java Nelson Padua-Perez Chau-Wen Tseng Department of Computer Science University of Maryland, College Park.
Classes and Instances. Introduction Classes, Objects, Methods and Instance Variables Declaring a Class with a Method and Instantiating an Object of a.
Rossella Lau Lecture 8, DCO10105, Semester B, DCO10105 Object-Oriented Programming and Design  Lecture 8: Polymorphism & C++ pointer  Inheritance.
Chapter 6 C Arrays Acknowledgment The notes are adapted from those provided by Deitel & Associates, Inc. and Pearson Education Inc. Arrays are data structures.
Computer Science II Exam I Review Monday, February 6, 2006.
Data Abstraction and Object- Oriented Programming CS351 – Programming Paradigms.
1 Procedural Concept The main program coordinates calls to procedures and hands over appropriate data as parameters.
1 Chapter One A First Program Using C#. 2 Objectives Learn about programming tasks Learn object-oriented programming concepts Learn about the C# programming.
C++ / G4MICE Course Session 3 Introduction to Classes Pointers and References Makefiles Standard Template Library.
REFACTORING Lecture 4. Definition Refactoring is a process of changing the internal structure of the program, not affecting its external behavior and.
Dr. Ahmad R. Hadaegh A.R. Hadaegh California State University San Marcos (CSUSM) Page 1 Virtual Functions Polymorphism Abstract base classes.
Lecture 8 Inheritance Richard Gesick. 2 OBJECTIVES How inheritance promotes software reusability. The concepts of base classes and derived classes. To.
Recap, Test 1 prep, Composition and Inheritance. Dates Test 1 – 12 th of March Assignment 1 – 20 th of March.
LHCb Software week November, 1999 M.Frank LHCb/CERN N-Tuples within Gaudi ã Definition ã Usage ä Run through simplified example ã The persistent.
A First Book of C++: From Here To There, Third Edition2 Objectives You should be able to describe: Function and Parameter Declarations Returning a Single.
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.
Athena and HEC Test Beam Reconstruction Tutorial October 12, 2001 CERN N. Kanaya, M. Marino, S. Rajagopalan, M. Wielers.
CERN Tutorial, September Job Options and Printing.
Job Options and Printing 1 LHCb software tutorial - September 2011.
GLAST Gaudi Code Review, 10 Sept. 2002, H. Kelly, 2-1 GLAST Event Data Model and Persistency.
1 Advanced Issues on Classes Part 3 Reference variables (Tapestry pp.581, Horton 176 – 178) Const-reference variables (Horton 176 – 178) object sharing:
Introduction to the HARP Software reconstructed drift chamber triplets (MC data)
9 Associators How to relate objects to each other Create relations Save relations Use relations: Associators.
More About Objects and Methods Chapter 5. Outline Programming with Methods Static Methods and Static Variables Designing Methods Overloading Constructors.
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.
N ATIONAL E NERGY R ESEARCH S CIENTIFIC C OMPUTING C ENTER Charles Leggett Interval of Validity Service IOVSvc ATLAS Software Week May Architecture.
Jose A. Hernando Trigger Gaudies Reconstruction Tools & Algorithms Inspectors MC & Data Algorithms Template preserved container Jose A. Hernando.
CS 376b Introduction to Computer Vision 01 / 23 / 2008 Instructor: Michael Eckmann.
Session 7 Methods Strings Constructors this Inheritance.
Introduction to c++ programming - object oriented programming concepts - Structured Vs OOP. Classes and objects - class definition - Objects - class scope.
Programming with Java © 2002 The McGraw-Hill Companies, Inc. All rights reserved. 1 McGraw-Hill/Irwin Chapter 5 Creating Classes.
 2007 Pearson Education, Inc. All rights reserved C Arrays.
Programming With Java ICS201 University Of Ha’il1 Chapter 7 Inheritance.
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.
Bologna Tutorial, April Job Options and Printing.
Classes, Interfaces and Packages
Chapter 1 C++ Basics Review (Section 1.4). Classes Defines the organization of a data user-defined type. Members can be  Data  Functions/Methods Information.
1 C# - Inheritance and Polymorphism. 2 1.Inheritance 2.Implementing Inheritance in C# 3.Constructor calls in Inheritance 4.Protected Access Modifier 5.The.
25th Nov, 1999 LHCb Event Data Model Pavel Binko, LHCb / CERN 1 LHCb Software Week LHCb Event Data Model Pavel Binko LHCb / CERN.
Athena Tutorial: Liquid Argon Example ATHENA The ATLAS Control Framework Tutorial: Liquid Argon Example Based on original by S. Rajagopalan BNL.
N ATIONAL E NERGY R ESEARCH S CIENTIFIC C OMPUTING C ENTER Charles Leggett Prototype GEANT4 Service for ATHENA framework ATLAS Software Workshop Dec 3.
Proposal for extension of GaudiAlgorithm and GaudiTool classes Vanya Belyaev CERN & ITEP/Moscow.
Gaudi Framework Tutorial, Algorithm Tools: what they are and how to use them.
Creating Java Applications (Software Development Life Cycle) 1. specify the problem requirements - clarify 2. analyze the problem - Input? Processes? Output.
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.
© 2004 Pearson Addison-Wesley. All rights reserved September 5, 2007 Packages & Random and Math Classes ComS 207: Programming I (in Java) Iowa State University,
Gaudi Framework Tutorial, April Histograms And N-tuples.
HYDRA Framework. Setup of software environment Setup of software environment Using the documentation Using the documentation How to compile a program.
Design issues for Object-Oriented Languages
C# for C++ Programmers 1.
Classes C++ representation of an object
Programming with ANSI C ++
User-Written Functions
“Algorithm Tools” what they are, how to get them and how to use them
Writing Physics Tools Schedule: Timing Topic 20 minutes Lecture
Array Lists Chapter 6 Section 6.1 to 6.3
C Arrays.
Java Programming Language
Lecture 22 Inheritance Richard Gesick.
Pointers, Dynamic Data, and Reference Types
Tonga Institute of Higher Education
Classes C++ representation of an object
Review for Midterm 3.
SPL – PS1 Introduction to C++.
Presentation transcript:

Tutorial: Examples (09may00 - ATLAS Software LBNL) May 2000 Prototype Framework Tutorial: Examples Paolo Calafiura, Charles Leggett HCG/NERSC/LBNL ATLAS Software LBNL May 9, 2000

Tutorial: Examples (09may00 - ATLAS Software LBNL) Example 1: HelloWorld Concepts Part 0: –set up build environments –create a new package –compile and link –run Part 1: –The Messaging Service Part 2: –The JobOptions and Properties Service Files: –HelloWorld.cxx, HelloWorld.h

Tutorial: Examples (09may00 - ATLAS Software LBNL) Example 1: Part 0 Setup Build Environments > source /auto/atlas/tools/WorkshopSetup.csh Work area: ~/Workshop > cd ~/Workshop source files are in src41/ControlExamples/GaudiTutorial/src header files in src41/ControlExamples/GaudiTutorial/GaudiTutorial build from ~/Workshop/build41 > gmake install execute from ~/Workshop/run >./tutorial_examples output solutions to examples in ~/Workshop/solutions/ex1/part1...

Tutorial: Examples (09may00 - ATLAS Software LBNL) Example 1: Part 0 Initial Files For each example, copy initial files from ~/Workshop/solutions/ex(n) copy source files (*.cxx) to your source file area. > cd ~/Workshop/src41/ControlExamples/GaudiTutorial/src > cp ~/Workshop/solutions/ex1/*.cxx. copy header files (*.h) to your header file area. > cd../GaudiTutorial > cp ~/Workshop/solutions/ex1/*.h. copy GNUmakefile.in > cd.. > cp ~/Workshop/solutions/ex1/GNUmakefile. copy jobOptions.txt to run area. > cd ~/Workshop/run > cp ~/Workshop/solutions/ex1/jobOptions.txt.

Tutorial: Examples (09may00 - ATLAS Software LBNL) Example 1: Part 0 Shortcuts Aliases have been defined to cd to various directories: gotosrc == cd ~/Workshop/src41/ControlExamples/GaudiTutorial/src gotohdr == cd ~/Workshop/src41/ControlExamples/GaudiTutorial/GaudiTutorial gotobld == cd ~/Workshop/build41 gotorun == cd ~/Workshop/run gotosol == cd ~/Workshop/solutions Initialization files can be automatically copied to the correct directories with: WorkshopInit example# The full solutions can be copied to the correct directories with: WorkshopCheat example# part# If you do this, don’t forget to “gmake build” afterwards To filter out SLUG output:./tutorial_examples < atlas.datback | filter

Tutorial: Examples (09may00 - ATLAS Software LBNL) Example 1: Part 1 The Messaging Service Add Message Service header to HelloWorld source: #include “Gaudi/MessageSvc/MsgStream.h” To print to message service: MsgStream log(messageService(), name()); log << MSG::INFO << “hello world” << endreq; Various message levels and jobOptions equivalents: MSG::DEBUG== 2 DEFAULT MSG::INFO== 3 MSG::WARNING== 4 MSG::ERROR== 5 MSG::FATAL== 6

Tutorial: Examples (09may00 - ATLAS Software LBNL) Example 1: Part 1 Messaging Service (cont) add Message Service output level to jobOptions.txt MessageSvc.OutputLevel = 2; Can set output level for each algorithm independently HelloWorld.OutputLevel = 2; To tell the framework to run the algorithm, add the Algorithm name to the jobOptions file: ApplicationMgr.TopAlg = {“HelloWorld”}; Now edit the files, build the executable, and run it.

Tutorial: Examples (09may00 - ATLAS Software LBNL) Example 1: Part 1 Accessing Services from Algorithms Any registered service can be accessed from an algorithm once its header file has been included in the algorithm. The algorithm class provides hooks to the various services. The most common services are: messageService() eventDataService() histogramDataService() ntupleService() detDataService() serviceLocator() and more....

Tutorial: Examples (09may00 - ATLAS Software LBNL) Example 1: Part 2 Properties Algorithms can have properties, which are settable at run time via the jobOptions file. In the source file of HelloWorld, include the the header for the Property Manager: #include “Gaudi/JobOptionsSvc/PropertyMgr.h” Declare the property variable in header file as a private data member: int m_foo; In Algorithm constructor, declare the property: declareProperty(“Foo”, m_foo); This makes an association between a data member and a property name as used in the jobOptions The supported data types are: int, double, bool, string std::vector, std::vector, std::vector, std::vector

Tutorial: Examples (09may00 - ATLAS Software LBNL) Example 1: Part 2 Properties (cont) Add the property entry in the jobOptions file: HelloWorld.Foo = 42; Do the same thing for a bool, a double, and a string vector. For vectors the syntax is: HelloWorld.StringVecFoo = {“Hello”, “World”}; Print out the value of the properties using the messaging service in the execute() method.

Tutorial: Examples (09may00 - ATLAS Software LBNL) Example 1: Postscript SimpleProperties A new type of Properties class called a “SimpleProperty” has been added to the framework, which provides the ability to do bounds checking. Though not part of this tutorial, it will become the preferred usage of properties. The properties member data will be declared as: SimpleProperty m_int; or IntegerProperty m_int; Optional bounds can be set in the initialize() method as: m_property.setBounds(lower, upper); m_property.setUpper(upper); m_property.setLower(lower);

Tutorial: Examples (09may00 - ATLAS Software LBNL) Example 2: Transient Data Store, Multiple Algorithms Concepts: Part 1: –Getting to the Transient Data Store –Getting the event header from the TDS, and accessing its components Part 2: –Creating a DataObject –Writing DataObject to TDS –Reading DataObject from TDS –Chaining multiple algorithms

Tutorial: Examples (09may00 - ATLAS Software LBNL) Example 2: Transient Data Store, Multiple Algorithms Part 3: –Creating a ContainedObject –Writing a vector of ContainedObjects to TDS –Reading vector of ContainedObjects from TDS Files: ReadData.cxx, ReadData.h WriteData.cxx, WriteData.h DataObj.h, ContObj.h

Tutorial: Examples (09may00 - ATLAS Software LBNL) Example 2: Transient Data Store Event information is kept in the TDS under the /Event hierarchy. There are several ways to get objects out of the TDS. These include the findObject() and retrieveObject() methods from the IDataProviderSvc, as well as the SmartDataPtr<>, and SmartRef<> templates. We prefer to use the SmartDataPtr as it provides the cleanest interface. When an object is registered with the TDS, the TDS becomes the owner of the object. DON’T CALL THE DELETE METHOD OF THE OBJECT. See chapter 6 of the Gaudi manual for further details.

Tutorial: Examples (09may00 - ATLAS Software LBNL) Example 2: Part 1 Getting to the TDS Start with the ReadData algorithm skeleton Add the headers for the ZebraTDREvent, the event data service, and the Smart Data Pointer: #include “ZebraTDRCnv/ZebraTDREvent.h” #include “Gaudi/DataSvc/SmartDataPtr.h” #include “Gaudi/DataSvc/EvtDataSvc.h” In the execute() method of ReadData, Get a SmartDataPtr to the Event in the TDS: SmartDataPtr evt(eventDataService(),”/Event”); Check to see if a valid event was found: if (!evt) { print error message, return FAILURE } Get the event and run numbers: int event = evt->event_number(); int run = evt->run_number();

Tutorial: Examples (09may00 - ATLAS Software LBNL) Example 2: Part 2 Creating a DataObject To be registered in the TDS, an object must be a DataObject, ie it must inherit from DataObject. You must also define a static constant Class ID, which must be unique for each class. In MyDataObj.h: #include “Gaudi/Kernel/DataObject.h” const static CLID CLID_MDO = ; class MyDataObj: public DataObject { public: MyDataObj(): DataObject(){}; static CLID& classID() { return CLID_MDO; } virtual CLID& clID() { return CLID_MDO; } int val() { return m_dat; } void val( int i) { m_dat = i; } virtual ~MyDataObj(){}; private: int m_dat; };

Tutorial: Examples (09may00 - ATLAS Software LBNL) Example 2: Part 2 Writing DataObject to TDS The DataObject will be written to a location in the TDS as specified by a property in jobOptions: declareProperty(“DataObjLoc”, m_DataObjLoc); Add this to the constructors of both the ReadData and WriteData algorithms In the execute() method of WriteData, create a DataObject of type MyDataObj, and set its member data: MyDataObj *dobj = new MyDataObj; dobj->val(10); Register it in the event TDS: StatusCode sc = eventDataService()-> registerObject(m_DataObjLoc,dobj); if ( sc.isFailure(){ print error message }

Tutorial: Examples (09may00 - ATLAS Software LBNL) Example 2: Part 2 Read DataObject from TDS Objects in the TDS can be accessed via a SmartDataPtr<>, which is templated in the type of the object, and has a usage syntax similar to a normal pointer. In the execute() method of ReadData, get a SmartDataPtr of type MyDataObj from the event TDS, with its location specified by the property variable: SmartDataPtr dobj(eventDataService(),m_DataObjLoc); if (! dobj) { print error message } Print value of object member data: log << MSG::INFO << “Data Object Val: “ val() << endreq;

Tutorial: Examples (09may00 - ATLAS Software LBNL) Example 2: Part 2 DataObject Locations In the jobOptions file, specify the locations of the objects to be written / read: WriteData.DataObjLoc = “/Event/tmpD”; ReadData.DataObjLoc = “/Event/tmpD”; Make sure that you’re reading from the same location as you’re writing to

Tutorial: Examples (09may00 - ATLAS Software LBNL) Example 2: Part 2 Chaining Multiple Algorithms In order to execute more than one algorithm, all that must be modified is the “TopAlg” property of the Application Manager in the jobOptions file: ApplicationMgr.TopAlg = { “WriteData”, “ReadData”} ; Modify the GNUmakefile.in so that WriteData.cxx gets compiled: > cd ~/Workshop/src41/ControlExamples/GaudiTutorial libGaudiTutorial.so_SRC = src/ReadData.cxx src/WriteData.cxx Compile and link using “gmake install” run the executable in the run directory

Tutorial: Examples (09may00 - ATLAS Software LBNL) Example 2: Part 3 Creating a Contained Object If you want to store a collection of objects, such as a group of hits, in the TDS, you should use an ObjectVector or an ObjectList. Objects must inherit from ContainedObject if they are to be stored in an ObjectVector/List: #include “Gaudi/Kernel/ContainedObject.h” const static CLID CLID_MYCO = ; class MyContObj: public ContainedObject { public: MyContObjt(): ContainedObject(){}; static CLID& classID() { return CLID_MYCO; } virtual CLID& clID() { return CLID_MYCO; } void set(float t, int i) { m_time = t; m_channelID= i;} int id() { return m_channelId; }..... private: int m_channelId; float m_time; };

Tutorial: Examples (09may00 - ATLAS Software LBNL) Example 2: Part 3 Writing a Contained Object In the execute() method of WriteData, create and fill a ContainedObject with the hits: MyContObj *mco_1 = new MyContObj; mco_1->set(11.3, 1);.... Create an ObjectVector on the heap, and fill it with a contained object: ObjectVector *cobj = new ObjectVector ; cobj->push_back(mco_1); cobj->push_back(mco_2);...

Tutorial: Examples (09may00 - ATLAS Software LBNL) Example 2: Part 3 Writing a Contained Object Register the ObjectVector with the TDS, and check to see that all went well: sc = eventDataService()-> registerObject(m_ContObjLoc, cobj); if ( sc.isFailure() ) { print error mesg }; In the jobOptions file, specify the location of the object to be written: WriteData.ContObjLoc = “/Event/tmpC”; ReadData.ContObjLoc = “/Event/tmpC”; Make sure it’s a different location that what was specified for the DataObject. Only one object can be registered to any one location.

Tutorial: Examples (09may00 - ATLAS Software LBNL) Example 2: Part 3 Reading Contained Object from TDS In the execute() method of ReadData, get a SmartDataPtr that points to the contained object in the TDS: SmartDataPtr > vec(eventDataService(), m_ContObjLoc); Iterate through the vector, printing out the values of its members: ObjectVector ::iterator it; for (it=vec->begin(); it!=vec->end; it++) { int Id = (*it)->id(); float time = (*it)->time(); log << MSG::INFO << “ID: “ << Id << “ Time: “ << time << endreq; } Now build and run the executable

Tutorial: Examples (09may00 - ATLAS Software LBNL) Example 3 Sub-Algorithms Concepts: Part 1: –Using sub algorithms Part 2: –Using multiple identical sub-algorithms Files MainAlg.cxx, MainAlg.h SubAlg.cxx, SubAlg.h

Tutorial: Examples (09may00 - ATLAS Software LBNL) Example 3: Part 1 Sub-Algorithms Sub-algorithms allow a higher degree of user control over the execution and ordering of algorithms. Sub-algorithms are not automatically created by the framework - this has to be done explicitly by their parent algorithm. Once created, the initialize() method of the sub- algorithm is automatically called, but the execute() phase must be explicitly invoked by the parent algorithm. The finalize() method is automatically called by the framework.

Tutorial: Examples (09may00 - ATLAS Software LBNL) Example 3: Part 1 Sub-Algorithms The sub-algorithm (SubAlg) will be very simple, with just a single string property called “SubString” declareProperty(“SubString”, m_substr); In the initialize() and execute() methods of the sub-algorithm, we want to print out the value of its string property.

Tutorial: Examples (09may00 - ATLAS Software LBNL) Example 3: Part 1 Sub-Algorithms The sub-algorithm will be referenced via a string property of the parent algorithm (MainAlg). declareProperty(“SubAlgType”,m_subAlgType); declareProperty(“SubAlgName”,m_subAlgName); The properties of the sub-algorithm will also be set by properties of the parent algorithm declareProperty(“SubAlgPropName”, m_subAlgPropName); declareProperty(“SubAlgPropVal”,m_subAlgPropVal); In order to identify the sub-algorithm, we want to keep a pointer to it as a member data of the parent algorithm. In the header of MainAlg: Algorithm* p_Sub;

Tutorial: Examples (09may00 - ATLAS Software LBNL) Example 3: Part 1 Sub-Algorithms In the initialize() method of the parent algorithm, the sub-algorithm must be created: sc = createSubAlgorithm(m_subAlgType, m_subAlgName,p_Sub); if ( sc.isFailure() ) { print error message } In the execute() method of the parent algorithm, we want to set a property of the sub-algorithm: sc = p_Sub->setProperty( StringProperty (m_subAlgPropName, m_subAlgPropVal) ); Then we want to execute the sub-algorithm: sc = p_Sub->execute();

Tutorial: Examples (09may00 - ATLAS Software LBNL) Example 3: Part 2 Multiple Identical Sub-Algorithms In order to execute multiple identical sub- algorithms, each one must be created by the parent algorithm with a different name. First change the SubAlgName and SubAlgPropVal properties in the parent algorithm to be vector. Same for p_Sub which will become a vector. Then in the initialize() method of the parent alg: m_nSubAlg = m_subAlgName.size(); Algorithm* psb; for (int i=0; i< m_nSubAlg; i++) { sc = createSubAlgorithm(m_subAlgType, m_subAlgName[i], psb); if ( sc.isFailure() ) { print error message } p_Sub.push_back(psb); }

Tutorial: Examples (09may00 - ATLAS Software LBNL) Example 3: Part 2 Multiple Identical Sub-Algorithms In the execute() method, loop over all sub- algorithms, setting and printing their properties for (int i=0; i<m_nSubAlg; i++) { log << MSG::INFO << “setting property “ << m_subAlgPropName << “ to “ << m_subAlgPropVal[i] << “ for subalg “ << m_subAlgType << “ instance “ << m_subAlgName[i] << endreq; sc = p_Sub[i]->setProperty( StringProperty (m_subAlgPropName, m_subAlgPropVal[i]) ); if ( sc.isFailure() ) { print error message } sc = p_Sub[i]->execute(); }

Tutorial: Examples (09may00 - ATLAS Software LBNL) Example 3: Part 2 Multiple Identical Sub-Algorithms In the jobOptions file: MainAlg.SubAlgType = "SubAlg"; MainAlg.SubAlgPropName = "SubString"; MainAlg.SubAlgName = { "SubAlgInst_1", "SubAlgInst_2", "SubAlgInst_3" }; MainAlg.SubAlgPropVal = { "new string 1", "new string 2", "new string 3" }; SubAlgInst_1.SubString = "original string 1"; SubAlgInst_2.SubString = "original string 2"; SubAlgInst_3.SubString = "original string 3";

Tutorial: Examples (09may00 - ATLAS Software LBNL) Example 3: Postscript Sequencer A new algorithm type called a sequencer has been added to the framework. The sequencer provides the same functionality as the sub-algorithms, but in a more automatic manner. Instead of explicitly creating and executing the sequencer in the appropriate methods of the parent algorithm, the sequencing path is set via the jobOptions: ApplicationMgr.TopAlg = { “Sequencer/TopSequencer” }; TopSequencer.Members={“Sequencer/Path1”,“Sequencer/Path2”}; Path1.Members = {“hello”,”Prescaler/Prescaler1”,”goodbye”}; Path2.Members = {“hello”,”Prescaler/Prescaler2”,”goodbye”}; Prescaler1.percentPass = 20.0; Prescaler2.percentPass = 50.0;

Tutorial: Examples (09may00 - ATLAS Software LBNL) Example 4 Histograms and NTuples Concepts Part 1: –Histograms Part 2: –Ntuples Files Hist.cxx, Hist.h Ntup.cxx, Ntup.h

Tutorial: Examples (09may00 - ATLAS Software LBNL) Example 4: Part 1 Histograms Histograms are kept in the TDS in a special area, which, unlike the event store, is not cleared with each new event. This area is “/stat”, and is managed by the histogram service HistogramSvc. Histograms must be registered with the TDS, like any other data object. The framework uses HTL histograms, and saves them in the hbook format.

Tutorial: Examples (09may00 - ATLAS Software LBNL) Example 4: Part 1 Histograms In the header file, add the data member: IHistogram1D* m_hist; In the source file, add the headers: #include “Gaudi/Interfaces/IHistogramSvc.h” #include “Gaudi/HistogramSvc/H1D.h” In the initialize() method, create a histogram object, and register it: m_hist = new H1D(“TestHist”, “Test Histogram”, “1”,100,0,100); sc = histogramDataService() -> registerObject( “/stat/simple”+m_hist->number(),m_hist); if ( sc.isFailure() ) { print error message }

Tutorial: Examples (09may00 - ATLAS Software LBNL) Example 4: Part 1 Histograms In the execute() method, fill the histogram: m_hist->fill( float(event), 1.); In the jobOptions file, specify the name of the output file: HistogramPersistencySvc.OutputFile = “histo.hbook”; Compile and execute Run PAW to look at the output

Tutorial: Examples (09may00 - ATLAS Software LBNL) Example 4: Part 2 NTuples NTuples are managed by a service similar to the histogramming service - NTupleSvc. They are kept in the TDS in their own area, called “/NTUPLES”. The framework saves the NTuples in hbook format. Both column-wise and row-wise NTuples are supported.

Tutorial: Examples (09may00 - ATLAS Software LBNL) Example 4: Part 2 NTuples For a column-wise NTuple, the variables must first be declared as data members of the class: NTuple::Item m_size; NTuple::Item m_run,m_event; NTuple::Array m_rundata; NTuple::Tuple* p_nt1; In the source file, add the includes: #include “Gaudi/Interfaces/INTupleSvc.h” #include “Gaudi/NTupleSvc/NTuple.h” #include “Gaudi/NTupleSvc/NTupleDirectory.h”

Tutorial: Examples (09may00 - ATLAS Software LBNL) Example 4: Part 2 NTuples In the initialize() method, create and register the ntuple: NTuple::Directory *col=0; NTupleFilePtr file1(ntupleService(), “/NTUPLES/FILE1”); if ( file1 ) { if ( !( col=ntupleService()-> createDirectory(“/NTUPLES/FILE1/COL”)) ){ print error message: can’t create dir } } else { print error message: can’t create file }

Tutorial: Examples (09may00 - ATLAS Software LBNL) Example 4: Part 2 NTuples NtuplePtr nt1(ntupleService(), “/NTUPLES/FILE1/COL/10”); nt1= ntupleService()-> book( col,10,CLID_ColumnWiseTuple, “Col Wise”); if ( nt1 ) { p_nt1 = nt1; sc = nt1->addItem(“Event”, m_event); if ( sc.isFailure() ) { print error } sc = nt1->addItem(“Run”, m_run); sc = nt1->addItem(“Size”, m_size, 0, 100); sc = nt1->addItem(“rundata”, m_size, m_rundata); } else { print error: can’t book ntuple }

Tutorial: Examples (09may00 - ATLAS Software LBNL) Example 4: Part 2 NTuples In the execute() method, fill the ntuple m_size = 2 + (evt->event_number() %3); m_event = evt->event_number(); m_run = evt->run_number(); m_rundata[0] = m_run; m_rundata[1] = m_event; for (int i=2; i<m_size; i++) { m_rundata[i] = i; } sc = ntupleService()->writeRecord(p_nt1); if ( sc.isFailure() ) { print error message }

Tutorial: Examples (09may00 - ATLAS Software LBNL) Example 4: Part 2 NTuples In the jobOptions file, set the output file name and the file format type (only hbook works for now) NTupleSvc.Output = { “FILE1#tuple1.hbook(WRITE)” }; NTupleSvc.Type = 6; modify GNUmakefile.in to build Ntup.cxx, modify the jobOptions file to run the Ntup algorithm, then run it and look at the ntuple written to the file “tuple1.hbook” with PAW.