Intensity Frontier
Common Offline Documentation:
art Workbook and Users Guide
Alpha Release 0.90
June 2, 2016
This version of the documentation is written for version August2015 of the art-workbook code.
Scientific Computing Division
Future Programs and Experiments Department
Scientific Software Infrastructure Group
Principal Author: Rob Kutschke
Other contributors: Marc Paterno, Mike Wang
Editor: Anne Heavey
art Developers: L. Garren, C. Green, K. Knoepfel,
J. Kowalkowski, M. Paterno and P. Russo
Detailed Table of Contents iv
chapter*.2
List of Figures xx
chapter*.3
List of Tables xxii
chapter*.4
List of Code and Output Listings xxii
chapter*.4 I Introduction 1
part.1
1 How to Read this Documentation 2
chapter.1 1.1 If you are new to HEP Software...
section.1.1 1.2 If you are an HEP Software expert...
section.1.2
1.3 If you are somewhere in between...
section.1.3
2 Conventions Used in this Documentation 4
chapter.2 2.1 Terms in Glossary
section.2.1 2.2 Typing Commands
section.2.2 2.3 Listing Styles
section.2.3
2.4 Procedures to Follow
section.2.4 2.5 Important Items to Call Out
section.2.5
2.6 Site-specific Information
section.2.6
3 Introduction to the art Event Processing Framework 7
chapter.3 3.1 What is art and Who Uses it?
section.3.1 3.2 Why art?
section.3.2 3.3 C++ and C++11
section.3.3
3.4 Getting Help
section.3.4 3.5 Overview of the Documentation Suite
section.3.5
3.5.1 The Introduction
subsection.3.5.1 3.5.2 The Workbook
subsection.3.5.2
3.5.3 Users Guide
subsection.3.5.3 3.5.4 Reference Manual
subsection.3.5.4
3.5.5 Technical Reference
subsection.3.5.5 3.5.6 Glossary
subsection.3.5.6
3.6 Some Background Material
section.3.6 3.6.1 Events and Event IDs
subsection.3.6.1
3.6.2 art Modules and the Event Loop
subsection.3.6.2 3.6.3 Module Types
subsection.3.6.3
3.6.4 art Data Products
subsection.3.6.4 3.6.5 art Services
subsection.3.6.5
3.6.6 Dynamic Libraries and art
subsection.3.6.6 3.6.7 Build Systems and art
subsection.3.6.7
3.6.8 External Products
subsection.3.6.8 3.6.9 The Event-Data Model and Persistency
subsection.3.6.9
3.6.10 Event-Data Files
subsection.3.6.10 3.6.11 Files on Tape
subsection.3.6.11
3.7 The Toy Experiment
section.3.7 3.7.1 Toy Detector Description
subsection.3.7.1
3.7.2 Workflow for Running the Toy Experiment Code
subsection.3.7.2
3.8 Rules, Best Practices, Conventions and Style
section.3.8
4 Unix Prerequisites 34
chapter.4 4.1 Introduction
section.4.1 4.2 Commands
section.4.2 4.3 Shells
section.4.3 4.4 Scripts: Part 1
section.4.4
4.5 Unix Environments
section.4.5 4.5.1 Building up the Environment
subsection.4.5.1
4.5.2 Examining and Using Environment Variables
subsection.4.5.2 4.6 Paths and $PATH
section.4.6
4.7 Scripts: Part 2
section.4.7 4.8 bash Functions and Aliases
section.4.8 4.9 Login Scripts
section.4.9
4.10 Suggested Unix and bash References
section.4.10
5 Site-Specific Setup Procedure 45
chapter.5
6 Get your C++ up to Speed 48
chapter.6 6.1 Introduction
section.6.1 6.2 File Types Used and Generated in C++ Programming
section.6.2
6.3 Establishing the Environment
section.6.3 6.3.1 Initial Setup
subsection.6.3.1
6.3.2 Subsequent Logins
subsection.6.3.2 6.4 C++ Exercise 1: Basic C++ Syntax and Building an Executable
section.6.4
6.4.1 Concepts to Understand
subsection.6.4.1 6.4.2 How to Compile, Link and Run
subsection.6.4.2
6.4.3 Discussion
subsection.6.4.3 6.4.3.1 Primitive types, Initialization and Printing Output
subsubsection.6.4.3.1
6.4.3.2 Arrays
subsubsection.6.4.3.2 6.4.3.3 Equality testing
subsubsection.6.4.3.3
6.4.3.4 Conditionals
subsubsection.6.4.3.4 6.4.3.5 Some C++ Standard Library Types
subsubsection.6.4.3.5
6.4.3.6 Pointers
subsubsection.6.4.3.6 6.4.3.7 References
subsubsection.6.4.3.7 6.4.3.8 Loops
subsubsection.6.4.3.8
6.5 C++ Exercise 2: About Compiling and Linking
section.6.5 6.5.1 What You Will Learn
subsection.6.5.1
6.5.2 The Source Code for this Exercise
subsection.6.5.2 6.5.3 Compile, Link and Run the Exercise
subsection.6.5.3
6.5.4 Alternate Script build2
subsection.6.5.4 6.5.5 Suggested Homework
subsection.6.5.5
6.6 C++ Exercise 3: Libraries
section.6.6 6.6.1 What You Will Learn
subsection.6.6.1
6.6.2 Building and Running the Exercise
subsection.6.6.2 6.7 Classes
section.6.7
6.7.1 Introduction
subsection.6.7.1 6.7.2 C++ Exercise 4 v1: The Most Basic Version
subsection.6.7.2
6.7.3 C++ Exercise 4 v2: The Default Constructor
subsection.6.7.3
6.7.4 C++ Exercise 4 v3: Constructors with Arguments
subsection.6.7.4
6.7.5 C++ Exercise 4 v4: Colon Initializer Syntax
subsection.6.7.5
6.7.6 C++ Exercise 4 v5: Member functions
subsection.6.7.6
6.7.7 C++ Exercise 4 v6: Private Data and Accessor Methods
subsection.6.7.7
6.7.7.1 Setters and Getters
subsubsection.6.7.7.1 6.7.7.2 What’s the deal with the underscore?
subsubsection.6.7.7.2
6.7.7.3 An example to motivate private data
subsubsection.6.7.7.3
6.7.8 C++ Exercise 4 v7: The
inline Specifier
subsection.6.7.8
6.7.9 C++ Exercise 4 v8: Defining Member Functions within the Class Declaration
subsection.6.7.9
6.7.10 C++ Exercise 4 v9: The Stream Insertion Operator and Free Functions
subsection.6.7.10
6.7.11 Review
subsection.6.7.11 6.8 Overloading functions
section.6.8 6.9 C++ References
section.6.9
7 Using External Products in UPS 107
chapter.7 7.1 The UPS Database List: PRODUCTS
section.7.1
7.2 UPS Handling of Variants of a Product
section.7.2
7.3 The setup Command: Syntax and Function
section.7.3
7.4 Current Versions of Products
section.7.4
7.5 Environment Variables Defined by UPS
section.7.5
7.6 Finding Header Files
section.7.6 7.6.1 Introduction
subsection.7.6.1
7.6.2 Finding art Header Files
subsection.7.6.2
7.6.3 Finding Headers from Other UPS Products
subsection.7.6.3
7.6.4 Exceptions: The Workbook, ROOT and Geant4
subsection.7.6.4 II
Workbook 119
part.2
8 Preparation for Running the Workbook Exercises 120
chapter.8 8.1 Introduction
section.8.1 8.2 Getting Computer Accounts on Workbook-enabled Machines
section.8.2
8.3 Choosing a Machine and Logging In
section.8.3 8.4 Launching new Windows: Verify X Connectivity
section.8.4
8.5 Choose an Editor
section.8.5
9 Exercise 1: Running Pre-built art Modules 124
chapter.9 9.1 Introduction
section.9.1 9.2 Prerequisites
section.9.2
9.3 What You Will Learn
section.9.3 9.4 The art Run-time Environment
section.9.4
9.5 The Input and Configuration Files for the Workbook Exercises
section.9.5
9.6 Setting up to Run Exercise 1
section.9.6 9.6.1 Log In and Set Up
subsection.9.6.1
9.6.1.1 Initial Setup Procedure using Standard Directory
subsubsection.9.6.1.1
9.6.1.2 Initial Setup Procedure allowing Self-managed Working Directory
subsubsection.9.6.1.2
9.6.1.3 Setup for Subsequent Exercise 1 Login Sessions
subsubsection.9.6.1.3
9.7 Execute art and Examine Output
section.9.7 9.8 Understanding the Configuration
section.9.8
9.8.1 Some Bookkeeping Syntax
subsection.9.8.1 9.8.2 Some Physics Processing Syntax
subsection.9.8.2
9.8.3 art Command line Options
subsection.9.8.3 9.8.4 Maximum Number of Events to Process
subsection.9.8.4
9.8.5 Changing the Input Files
subsection.9.8.5 9.8.6 Skipping Events
subsection.9.8.6
9.8.7 Identifying the User Code to Execute
subsection.9.8.7 9.8.8 Paths and the art Workflow
subsection.9.8.8
9.8.8.1 Paths and the art Workflow: Details
subsubsection.9.8.8.1 9.8.8.2 Order of Module Execution
subsubsection.9.8.8.2
9.8.9 Writing an Output File
subsection.9.8.9 9.9 Understanding the Process for Exercise 1
section.9.9
9.9.1 Follow the Site-Specific Setup Procedure (Details)
subsection.9.9.1
9.9.2 Make a Working Directory (Details)
subsection.9.9.2
9.9.3 Setup the toyExperiment UPS Product (Details)
subsection.9.9.3
9.9.4 Copy Files to your Current Working Directory (Details)
subsection.9.9.4
9.9.5 Source makeLinks.sh (Details)
subsection.9.9.5 9.9.6 Run art (Details)
subsection.9.9.6
9.10 How does art find Modules?
section.9.10 9.11 How does art find FHiCL Files?
section.9.11
9.11.1 The -c command line argument
subsection.9.11.1 9.11.2 #include Files
subsection.9.11.2
9.12 Review
section.9.12 9.13 Test your Understanding
section.9.13 9.13.1 Tests
subsection.9.13.1
9.13.2 Answers
subsection.9.13.2
10 Exercise 2: Building and Running Your First Module 162
chapter.10 10.1 Introduction
section.10.1 10.2 Prerequisites
section.10.2 10.3 What You Will Learn
section.10.3
10.4 Initial Setup to Run Exercises
section.10.4 10.4.1 “Source Window” Setup
subsection.10.4.1
10.4.2 Examine Source Window Setup
subsection.10.4.2 10.4.2.1 About git and What it Did
subsubsection.10.4.2.1
10.4.2.2 Contents of the Source Directory
subsubsection.10.4.2.2
10.4.3 “Build Window” Setup
subsection.10.4.3 10.4.3.1 Standard Procedure
subsubsection.10.4.3.1
10.4.3.2 Using Self-managed Working Directory
subsubsection.10.4.3.2
10.4.4 Examine Build Window Setup
subsection.10.4.4 10.5 The art Development Environment
section.10.5
10.6 Running the Exercise
section.10.6 10.6.1 Run art on first.fcl
subsection.10.6.1
10.6.2 The FHiCL File first.fcl
subsection.10.6.2 10.6.3 The Source Code File First_module.cc
subsection.10.6.3
10.6.3.1 The #include Statements
subsubsection.10.6.3.1
10.6.3.2 The Declaration of the Class First, an Analyzer Module
subsubsection.10.6.3.2
10.6.3.3 An Introduction to Analyzer Modules
subsubsection.10.6.3.3
10.6.3.4 The Constructor for the Class First
subsubsection.10.6.3.4
10.6.3.5 Aside: Omitting Argument Names in Function Declarations
subsubsection.10.6.3.5
10.6.3.6 The Member Function analyze and the Representation of an Event
subsubsection.10.6.3.6
10.6.3.7 Representing an Event Identifier with art::EventID
subsubsection.10.6.3.7
10.6.3.8 DEFINE_ART_MACRO: The Module Maker Macros
subsubsection.10.6.3.8
10.6.3.9 Some Alternate Styles
subsubsection.10.6.3.9 10.7 What does the Build System Do?
section.10.7
10.7.1 The Basic Operation
subsection.10.7.1 10.7.2 Incremental Builds and Complete Rebuilds
subsection.10.7.2
10.7.3 Finding Header Files at Compile Time
subsection.10.7.3
10.7.4 Finding Dynamic Library Files at Link Time
subsection.10.7.4 10.7.5 Build System Details
subsection.10.7.5
10.8 Suggested Activities
section.10.8 10.8.1 Create Your Second Module
subsection.10.8.1
10.8.2 Use artmod to Create Your Third Module
subsection.10.8.2
10.8.3 Running Many Modules at Once
subsection.10.8.3 10.8.4 Access Parts of the EventID
subsection.10.8.4
10.9 Final Remarks
section.10.9 10.9.1 Why is there no First_module.h File?
subsection.10.9.1
10.9.2 The Three-File Module Style
subsection.10.9.2 10.10 Flow of Execution from Source to FHiCL File
section.10.10
10.11 Review
section.10.11 10.12 Test Your Understanding
section.10.12 10.12.1 Tests
subsection.10.12.1
10.12.2 Answers
subsection.10.12.2 10.12.2.1 FirstBug01
subsubsection.10.12.2.1
10.12.2.2 FirstBug02
subsubsection.10.12.2.2
11 General Setup for Login Sessions 218
chapter.11 11.1 Source Window
section.11.1 11.2 Build Window
section.11.2
12 Keeping Up to Date with Workbook Code and Documentation 220
chapter.12 12.1 Introduction
section.12.1 12.2 Special Instructions for Summer 2014
section.12.2
12.3 How to Update
section.12.3 12.3.1 Get Updated Documentation
subsection.12.3.1
12.3.2 Get Updated Code and Build It
subsection.12.3.2
12.3.3 See which Files you have Modified or Added
subsection.12.3.3
13 Exercise 3: Some other Member Functions of Modules 226
chapter.13 13.1 Introduction
section.13.1 13.2 Prerequisites
section.13.2 13.3 What You Will Learn
section.13.3
13.4 Setting up to Run this Exercise
section.13.4 13.5 The Source File Optional_module.cc
section.13.5
13.5.1 About the begin* Member Functions
subsection.13.5.1 13.5.2 About the art::*ID Classes
subsection.13.5.2
13.5.3 Use of the override Identifier
subsection.13.5.3 13.5.4 Use of const References
subsection.13.5.4
13.5.5 The analyze Member Function
subsection.13.5.5 13.6 Running this Exercise
section.13.6
13.7 The Member Function beginJob versus the Constructor
section.13.7
13.8 Suggested Activities
section.13.8 13.8.1 Add the Matching end Member functions
subsection.13.8.1
13.8.2 Run on Multiple Input Files
subsection.13.8.2 13.8.3 The Option --trace
subsection.13.8.3
13.9 Review
section.13.9 13.10 Test Your Understanding
section.13.10 13.10.1 Tests
subsection.13.10.1
13.10.2 Answers
subsection.13.10.2
14 Exercise 4: A First Look at Parameter Sets 238
chapter.14 14.1 Introduction
section.14.1 14.2 Prerequisites
section.14.2 14.3 What You Will Learn
section.14.3
14.4 Setting up to Run this Exercise
section.14.4 14.5 The Configuration File pset01.fcl
section.14.5
14.6 The Source code file PSet01_module.cc
section.14.6 14.7 Running the Exercise
section.14.7
14.8 Member Function Templates and their Arguments
section.14.8
14.8.1 Types Known to ParameterSet::get<T>
subsection.14.8.1 14.8.2 User-Defined Types
subsection.14.8.2
14.9 Exceptions (as in “Errors”)
section.14.9 14.9.1 Error Conditions
subsection.14.9.1
14.9.2 Error Handling
subsection.14.9.2 14.9.3 Suggested Exercises
subsection.14.9.3
14.10 Parameters and Data Members
section.14.10 14.11 Optional Parameters with Default Values
section.14.11
14.11.1 Policies About Optional Parameters
subsection.14.11.1
14.12 Numerical Types: Precision and Canonical Forms
section.14.12
14.12.1 Why Have Canonical Forms?
subsection.14.12.1 14.12.2 Suggested Exercises
subsection.14.12.2
14.12.2.1 Formats
subsubsection.14.12.2.1 14.12.2.2 Fractional versus Integral Types
subsubsection.14.12.2.2
14.13 Dealing with Invalid Parameter Values
section.14.13 14.14 Review
section.14.14
14.15 Test Your Understanding
section.14.15 14.15.1 Tests
subsection.14.15.1
14.15.2 Answers
subsection.14.15.2
15 Exercise 5: Making Multiple Instances of a Module 264
chapter.15 15.1 Introduction
section.15.1 15.2 Prerequisites
section.15.2 15.3 What You Will Learn
section.15.3
15.4 Setting up to Run this Exercise
section.15.4 15.5 The Source File Magic_module.cc
section.15.5
15.6 The FHiCL File magic.fcl
section.15.6 15.7 Running the Exercise
section.15.7
15.8 Discussion
section.15.8 15.8.1 Order of Analyzer Modules is not Important
subsection.15.8.1
15.8.2 Two Meanings of Module Label
subsection.15.8.2 15.9 Review
section.15.9
15.10 Test Your Understanding
section.15.10 15.10.1 Tests
subsection.15.10.1
15.10.2 Answers
subsection.15.10.2
16 Exercise 6: Accessing Data Products 271
chapter.16 16.1 Introduction
section.16.1 16.2 Prerequisites
section.16.2
16.3 What You Will Learn
section.16.3 16.4 Background Information for this Exercise
section.16.4
16.4.1 The Data Type GenParticleCollection
subsection.16.4.1
16.4.2 Data Product Names
subsection.16.4.2 16.4.3 Specifying a Data Product
subsection.16.4.3
16.4.4 The Data Product used in this Exercise
subsection.16.4.4 16.5 Setting up to Run this Exercise
section.16.5
16.6 Running the Exercise
section.16.6 16.7 Understanding the First Version, ReadGens1
section.16.7
16.7.1 The Source File ReadGens1_module.cc
subsection.16.7.1
16.7.2 Adding a Link Library to CMakeLists.txt
subsection.16.7.2
16.7.3 The FHiCL File readGens1.fcl
subsection.16.7.3 16.8 The Second Version, ReadGens2
section.16.8
16.9 The Third Version, ReadGens3
section.16.9 16.10 Suggested Activities
section.16.10
16.11 Review
section.16.11 16.12 Test Your Understanding
section.16.12 16.12.1 Tests
subsection.16.12.1
16.12.2 Answers
subsection.16.12.2
17 Exercise 7: Making a Histogram 291
chapter.17 17.1 Introduction
section.17.1 17.2 Prerequisites
section.17.2 17.3 What You Will Learn
section.17.3
17.4 Setting up to Run this Exercise
section.17.4 17.5 The Source File FirstHist1_module.cc
section.17.5
17.5.1 Introducing art::ServiceHandle
subsection.17.5.1 17.5.2 Creating a Histogram
subsection.17.5.2
17.5.3 Filling a Histogram
subsection.17.5.3 17.5.4 A Few Last Comments
subsection.17.5.4
17.6 The Configuration File firstHist1.fcl
section.17.6 17.7 The file CMakeLists.txt
section.17.7
17.8 Running the Exercise
section.17.8 17.9 Inspecting the Histogram File
section.17.9
17.9.1 A Short Cut: the browse command
subsection.17.9.1 17.9.2 Using CINT Scripts
subsection.17.9.2
17.10 Finding ROOT Documentation
section.17.10 17.10.1 Overwriting Histogram Files
subsection.17.10.1
17.10.2 Changing the Name of the Histogram File
subsection.17.10.2
17.10.3 Changing the Module Label
subsection.17.10.3 17.10.4 Printing From the TBrowser
subsection.17.10.4
17.11 Review
section.17.11 17.12 Test Your Understanding
section.17.12 17.12.1 Tests
subsection.17.12.1
17.12.2 Answers
subsection.17.12.2
18 Exercise 8: Looping Over Collections 318
chapter.18 18.1 Introduction
section.18.1 18.2 Prerequisites
section.18.2 18.3 What You Will Learn
section.18.3
18.4 Setting Up to Run Exercise
section.18.4 18.5 The Class GenParticle
section.18.5
18.5.1 The Included Header Files
subsection.18.5.1 18.5.2 Particle Parent-Child Relationships
subsection.18.5.2
18.5.3 The Public Interface for the Class GenParticle
subsection.18.5.3
18.5.4 Conditionally Excluded Sections of Header File
subsection.18.5.4
18.6 The Module LoopGens1
section.18.6 18.7 CMakeLists.txt
section.18.7
18.8 Running the Exercise
section.18.8 18.9 Variations on the Exercise
section.18.9
18.9.1 LoopGens2_module.cc
subsection.18.9.1 18.9.2 LoopGens3_module.cc
subsection.18.9.2
18.9.3 LoopGens3a_module.cc
subsection.18.9.3 18.10 Review
section.18.10
18.11 Test Your Understanding
section.18.11 18.11.1 Test 1
subsection.18.11.1
18.11.2 Test 2
subsection.18.11.2 18.11.3 Test 3
subsection.18.11.3 18.11.4 Answers
subsection.18.11.4
18.11.4.1 Test 1
subsubsection.18.11.4.1 18.11.4.2 Test 2
subsubsection.18.11.4.2
18.11.4.3 Test 3
subsubsection.18.11.4.3
19 3D Event Displays 342
chapter.19 19.1 Introduction
section.19.1 19.2 Prerequisites
section.19.2 19.3 What You Will Learn
section.19.3
19.4 Setting up to Run this Exercise
section.19.4 19.5 Running the Exercise
section.19.5
19.5.1 Startup and General Layout
subsection.19.5.1 19.5.2 The Control Panel
subsection.19.5.2
19.5.2.1 The List-Tree Widget and Context-Sensitive Menus
subsubsection.19.5.2.1
19.5.2.2 The Event-Navigation Pane
subsubsection.19.5.2.2 19.5.3 Main EVE Display Area
subsection.19.5.3
19.6 Understanding How the 3D Event Display Module Works
section.19.6
19.6.1 Overview of the Source Code File EventDisplay3D_module.cc
subsection.19.6.1
19.6.2 Class Declaration and Constructor
subsection.19.6.2
19.6.3 Creating the GUI and Drawing the Static Detector Components in the beginJob() Member Function
subsection.19.6.3
19.6.3.1 The Default GUI
subsubsection.19.6.3.1 19.6.3.2 Adding the Global Elements
subsubsection.19.6.3.2
19.6.3.3 Customizing the GUI
subsubsection.19.6.3.3 19.6.3.4 Adding the Navigation Pane
subsubsection.19.6.3.4
19.6.4 Drawing the Generated Hits and Tracks in the analyze() Member Function
subsection.19.6.4
20 Troubleshooting 379
chapter.20 20.1 Updating Workbook Code
section.20.1
20.2 XWindows (xterm and Other XWindows Products)
section.20.2
20.2.1 Mac OSX 10.9
subsection.20.2.1 20.3 Trouble Building
section.20.3
20.4 art Won’t Run
section.20.4 III User’s Guide 381
part.3
21 git 382
chapter.21 21.1 Aside: More Details about git
section.21.1
21.1.1 Central Repository, Local Repository and Working Directory
subsection.21.1.1
21.1.1.1 Files that you have Added
subsubsection.21.1.1.1 21.1.1.2 Files that you have Modified
subsubsection.21.1.1.2
21.1.1.3 Files with Resolvable Conflicts
subsubsection.21.1.1.3
21.1.1.4 Files with Unresolvable Conflicts
subsubsection.21.1.1.4 21.1.2 git Branches
subsection.21.1.2
21.1.3 Seeing which Files you have Modified or Added
subsection.21.1.3
22 art Run-time and Development Environments 391
chapter.22 22.1 The art Run-time Environment
section.22.1 22.2 The art Development Environment
section.22.2
23 art Framework Parameters 399
chapter.23 23.1 Parameter Types
section.23.1 23.2 Structure of art Configuration Files
section.23.2
23.3 Services
section.23.3 23.3.1 System Services
subsection.23.3.1
23.3.2 FloatingPointControl
subsection.23.3.2 23.3.3 Message Parameters
subsection.23.3.3
23.3.4 Optional Services
subsection.23.3.4 23.3.5 Sources
subsection.23.3.5
23.3.6 Modules
subsection.23.3.6
24 Job Configuration in art: FHiCL 405
chapter.24 24.1 Basics of FHiCL Syntax
section.24.1 24.1.1 Specifying Names and Values
subsection.24.1.1
24.1.2 FHiCL-reserved Characters and Identifiers
subsection.24.1.2 24.2 FHiCL Identifiers Reserved to art
section.24.2
24.3 Structure of a FHiCL Run-time Configuration File for art
section.24.3 24.4 Order of Elements in a FHiCL Run-time Configuration File for art
section.24.4
24.5 The physics Portion of the FHiCL Configuration
section.24.5 24.6 Choosing and Using Module Labels and Path Names
section.24.6
24.7 Scheduling Strategy in art
section.24.7 24.8 Scheduled Reconstruction using Trigger Paths
section.24.8
24.9 Reconstruction On-Demand
section.24.9 24.10 Bits and Pieces
section.24.10 IV
Appendices 424
part.4
A Obtaining Credentials to Access Fermilab Computing Resources 425
appendix.A A.1 Kerberos Authentication
section.A.1 A.2 Fermilab Services Account
section.A.2
B Installing Locally 427
appendix.B B.1 Install the Binary Distributions: A Cheat Sheet
section.B.1
B.2 Preparing the Site Specific Setup Script
section.B.2 B.3 Links to the Full Instructions
section.B.3
C art Completion Codes 432
appendix.C
D Viewing and Printing Figure Files 435
appendix.D D.1 Viewing Figure Files Interactively
section.D.1 D.2 Printing Figure Files
section.D.2
E CLHEP 437
appendix.E E.1 Introduction
section.E.1 E.2 Multiple Meanings of Vector in CLHEP
section.E.2
E.3 CLHEP Documentation
section.E.3 E.4 CLHEP Header Files
section.E.4
E.4.1 Naming Conventions and Syntax
subsection.E.4.1 E.4.2 .icc Files
subsection.E.4.2
E.5 The CLHEP Namespace
section.E.5 E.5.1 using Declarations and Directives
subsection.E.5.1
E.6 The Vector Package
section.E.6 E.6.1 CLHEP::Hep3Vector
subsection.E.6.1
E.6.1.1 Some Fragile Member Functions
subsubsection.E.6.1.1
E.6.2 CLHEP::HepLorentzVector
subsection.E.6.2 E.6.2.1 HepBoost
subsubsection.E.6.2.1
E.7 The Matrix Package
section.E.7 E.8 The Random Package
section.E.8
F Include Guards 453
appendix.F V Index 455
part.5
Index 456
section*.87
The art document suite, which is currently in an alpha release form, consists of an introductory section and the first few exercises of the Workbook1 , plus a glossary and an index. There are also some preliminary (incomplete and unreviewed) portions of the Users Guide included in the compilation.
The Workbook exercises require you to download some code to edit, execute and evaluate. Both the documentation and the code it references are expected to undergo continual development throughout 2013 and 2014. The latest is always available at the art Documentation website. Chapter 12 tells you how to keep up-to-date with improvements and additions to the Workbook code and documentation.
Read Parts I and II (the introductory material and the Workbook) from start to finish. The Workbook is aimed at an audience who is familiar with (although not necessarily expert in) Unix, C++ and Fermilab’s UPS product management system, and who understands the basic art framework concepts. The introductory chapters prepare the “just starting out” reader in all these areas.
Read chapters 1, 2 and 3: this is where key terms and concepts used throughout the art document suite get defined. Skip the rest of the introductory material and jump straight into running Exercise 1 in Chapter 9 of the Workbook. Take the approach of: Don’t need it? Don’t read it.
Read chapters 1, 2 and 3 and skim the remaining introductory material in Part I to glean what you need. Along with the experts, you can take the approach of: Don’t need it? Don’t read it.
Most of the material in this introduction and in the Workbook is written so that it can be understood by those new to HEP computing; if it is not, please let us know (see Section 3.4)!
The first instance of each term that is defined in the glossary is written in italics followed by a γ (Greek letter gamma), e.g., framework(γ).
Unix commands that you must type are shown in the format unix command. Portions of the command for which you must substitute values are shown in slanted font within the command. e.g., you would type your actual username when you see username).
While art supports OS X as well as flavors of Linux, the instructions for using art are nearly identical for all supported systems. When operating-system specific instructions are needed they are noted in the exercises.
When an example Unix command line would overflow the page width, this documentation will use a trailing backslash to indicate that the command is continued on the next line. We indent the second line to make clear that it is not a separate command from the first line. For example:
You can type the entire command on a single line if it fits, without typing the backslash, or on two lines with the backslash as the final character of the first line. Do not leave a space before the backslash unless it is required in the command syntax, e.g., before an option, as in
Code listings in C++ are shown as:
1// This is a C++ file listing.
2float* pa = &a;
3
Code listings in FHiCL are shown as:
Other script or file content is denoted:
Computer output from a command is shown as:
Step-by-step procedures that the reader is asked to follow are denoted in the following way:
Occasionally, text will be called out to make sure that you don’t miss it. Important or tricky terms and concepts will be marked with an “pointing finger” symbol in the margin, as shown at right.
Items that are even trickier will be marked with a “bomb” symbol in the margin, as shown at right. You really want to avoid the problems they describe.
In some places it will be necessary for a paragraph or two to be written for experts. Such paragraphs will be marked with a “dangerous bends” symbol in the margin, as shown at right. Less experienced users can skip these sections on first reading and come back to them at a later time.
Text that refers in particular to Fermilab-specific information is marked with a Fermilab picture, as shown at right.
Text that refers in particular to information about using
Experiment-specific information will be kept to an absolute minimum; wherever it appears, it will be marked with an experiment-specific icon, e.g., the Mu2e icon at right.
The initial clients of
The Fermilab SCD has also developed a related product named
https://cdcvs.fnal.gov/redmine/projects/artdaq/wiki.
A technial paper on
The design of
Experiments using
In all previous experiments at Fermilab, and in most previous experiments elsewhere, infrastructure software (i.e., the framework, broadly construed – mostly forms of bookkeeping) has been written in-house by each experiment, and each implementation has been tightly coupled to that experiment’s code. This tight coupling has made it difficult to share the framework among experiments, resulting in both great duplication of effort and mixed quality.
In 2011, the International Standards Committee voted to approve a new standard for C++, called C++ 11.
Much of the existing user code was written prior to the adoption of the C++ 11 standard and has not yet been updated. As you work on your experiment, you are likely to encounter both code written the new way and code written the old way. Therefore, the Workbook will often illustrate both practices.
A very useful compilation of what is new in C++ 11 can be found at
This reference material is written for advanced C++ users.
Please send your questions and comments to
When complete, this documentation suite will contain several principal components, or
This introductory volume is intended to set the stage for using
The Workbook is a series of standalone, self-paced exercises that will introduce the building
blocks of the
One of the Workbook’s primary functions is training readers how and where to find
more extensive documentation on both
The Workbook assumes some basic computing skills and some basic familiarity with the C++ computing language; Chapter 6 provides a tutorial/refresher for readers who need to improve their C++ skills.
The Workbook is written using recommended best practices that have become current since the adoption of C++ 11 (see Section 3.8).
Because
The Users Guide is targeted at physicists who have reached an intermediate level of
competence with
The Reference Manual will be targeted at physicists who already understand the major ideas
underlying
The Technical Reference will be targeted at the experts who develop and maintain
The glossary will evolve as the documentation set grows. At the time of writing, it includes
definitions of
This section defines some language and some background material about the
In almost all HEP experiments, the core idea underlying all bookkeeping is the
In a typical HEP experiment, the trigger or DAQ system assigns an event identifier (event ID) to
each event; this ID uniquely identifies each event, satisfying a critical requirement imposed by
The simplest event ID is a monotonically increasing integer. A more common practice is to
define a multi-part ID and
There are two common methods of using this event ID scheme and
When an experiment takes data, events read from the DAQ are typically written to disk files, with copies made on tape. The events in a single subRun may be spread over several files; conversely, a single file may contain many runs, each of which contains many subRuns.
Users provide executable code to
The simplest command to run
The argument to
When
These rules will be explained as you work through the Workbook and they are summarized in
The code base of a typical experiment will contain many C++ classes. Only a small fraction of these will be modules; most of the rest will be ordinary C++ classes that are used within modules3 .
A user can tell
Imagine the processing of each event as the assembly of a widget on an assembly
line and imagine each module as a worker that needs to perform a set task on each
widget. Each worker has a task that must be done on each widget that passes by; in
addition some workers may need to do some start-up or close-down jobs. Following this
metaphor,
For those of you who are familiar with
After
The event loop
This entire set of steps comprises the event loop. One of
Every
Note that no module may change information that is already present in an event.
What does an analyzer do if it may neither alter information in an event nor add to it? Typically it
creates printout and it creates ROOT files containing histograms,
Most novice users will only write analyzer modules and filter modules; readers with a little more
experience may also write producer modules. The Workbook will provide examples of all three.
Few people other than
This section introduces more ideas and terms dealing with event information that you will need as you progress through the Workbook.
The term
Because these data products are intrinsically experiment-dependent, each experiment defines its
own data products. In the Workbook, you will learn about a set of data products designed for use
with the toy experiment. There are a small number of data products that are defined by
A data product is just a C++
Very often, a data product is a
Previous sections of this Introduction have introduced the concept of C++ classes that have
to obey a certain set of rules defined by
In a typical
To provide managed access to the second sort of information,
After
Once a service has been constructed, any code in any module can ask
It is also legal for one service to request information from another service as long as the dependency chain does not have any loops. That is, if Service A uses Service B, then Service B may not use Service A, either directly or indirectly.
For those of you familiar with the C++ Singleton Design Pattern, an
When code is executed within the
To make an experiment’s code available to
Experiments that use
The
The compiler options corresponding to the three levels are listed in Table 3.1.
| |
| |
| |
| |
As you progress through the Workbook, you will see that the exercises use some software
packages that are part of neither
These packages and tools are referred to as
An initial list of the external products you will need to become familiar with includes:
Any particular line of code in a Workbook exercise may use elements from, say, four or five of these packages. Knowing how to parse a line and identify which feature comes from which package is a critical skill. The Workbook will provide a tour of the above packages so that you will recognize elements when they are used and you will learn where to find the necessary documentation.
For the
Finally, it is important to recognize an overloaded word,
Section 3.6.4 introduced the idea of
While each experiment will define its own data product classes, there is a common set of
questions that
The answers to these questions form what is called the
A question that is closely related to the EDM is: what technologies are supported to write data
products from memory to a disk file and to read them from the disk file back into memory in a
separate
A few other related terms that you will encounter include:
When you read data from an experiment and write the data to a disk file, that disk file is usually
called a
When you simulate an experiment and write a disk file that holds the information produced by the simulation, what should you call the file? The Particle Data Group has recommended that this not be called a “data file” or a “simulated data file;” they prefer that the word “data” be strictly reserved for information that comes from an actual experiment. They recommend that we refer to these files as “files of simulated events” or “files of Monte Carlo events” 6. Note the use of “events,” not “data.”
This leaves us with a need for a collective noun to describe both data files and files of simulated
events. The name in current use is
Many experiments do not have access to enough disk space to hold all of their event-data files, ROOT files and log files. The solution is to copy a subset of the disk files to tape and to read them back from tape as necessary.
At any given time, a snapshot of an experiment’s files will show some on tape only, some on tape
with copies on disk, and some on disk only. For any given file, there may be multiple copies on
disk and those copies may be distributed across many
Conceptually, two pieces of software are used to keep track of which files are where, a
https://cdcvs.fnal.gov/redmine/projects/sam-main/wiki.
The Workbook exercises are based around a made-up (
The software for the toy experiment is designed around a toy detector, which is shown in
Figure 3.3. The
The toy detector is a central detector made up of 15 concentric shells, with their axes centered on
the
Each shell is a detector that measures
All of the code in the toyExperiment product works in the set of units described in Table 3.2.
Because the code in the Workbook is built on toyExperiment, it uses the same units.
The first six units listed in Table 3.2 are the base units defined by the CLHEP SystemOfUnits package. These are also the units used by Geant4.
| |
| |
| |
| |
| |
| |
| |
| |
The workflow of the toy experiment code includes five steps: three simulation steps, a reconstruction step and an analysis step:
For each event, the event generator creates some signal particles and some background particles. The first signal particle is generated with the following properties:
The event generator then decays this particle to
The background particles are generated by the following algorithm:
The above algorithm generates events with a total charge of zero but there is no concept of momentum or energy balance. About 47% of these events will not have any background tracks.
In the detector simulation step, particles neither scatter nor lose energy when they pass through
the detector cylinders; nor do they decay. Therefore, the charged particles follow a perfectly
helical trajectory. The simulation follows each charged particle until it either exits the detector or
until it completes the outward-going arc of the helix. When the simulated trajectory crosses one
of the detector shells, the simulation records the true point of intersection. All intersections are
recorded; at this stage in the simulation, there is no notion of inefficiency or resolution. The
simulation does not follow the trajectory of the
Figure 3.4 shows an event display of a simulated event that has no background tracks. In
this event the
Figure 3.5 shows an event display of another simulated event, one that has four background
tracks, all drawn in green. In the
The third step in the simulation chain (hit-making) is to inspect the intersections produced by the
detector simulation and turn them into data-like hits. In this step, a simple model of inefficiency
is applied and some intersections will not produce hits. Each hit represents a 2D measurement
The three simulation steps use tools provided by
The fourth step is the reconstruction step. The toyExperiment does not yet have properly working
reconstruction code; instead it mocks up credible looking results. The output of this code is a
data product that represents a fitted helix; it contains the fitted track parameters of the helix, their
covariance matrix and collection of smart pointers that point to the hits that are on the
reconstructed track. When we write proper tracking finding and track fitting code for the
toyExperiment, the classes that describe the fitted helix will not change. Because the main
point of the Workbook exercises is to illustrate the bookkeeping features in
The fifth step in the workflow does a simulated analysis using the fitted helices from the
reconstruction step. It forms all distinct pairs of tracks and requires that they be oppositely charged.
It then computes the invariant mass of the pair, under the assumption that both fitted helices are
kaons.7
This module is an analyzer module and does not make any output data product. But it does make
some histograms, one of which is a histogram of the reconstructed invariant mass of all pairs of
oppositely charged tracks; this histogram is shown in Figure 3.6. When you run the Workbook
exercises, you will make this plot and can compare it to Figure 3.6. In the figure you can see a
clear peak that is created when the two reconstructed tracks are the two true daughters of the
generated
In many places, the Workbook will recommend that you write fragments of code in a particular way. The reason for any particular recommendation may be one of the following:
It is important to be able to distinguish between rules, best practices, conventions and styles; you must follow the rules; it wise to use best practices and established conventions; but style suggestions are just that, suggestions. This documentation will distinguish among these options when discussing the recommendations that it makes.
If you follow the recommendations for best practices and common conventions, it will be easier to verify that your code is correct and your code will be easier to understand, develop and maintain.
You will work through the Workbook exercises on a computer that is running some version of the Unix operating system. This chapter describes where to find information about Unix and gives a list of Unix commands that you should understand before starting the Workbook exercises. This chapter also describes a few ideas that you will need immediately but which are usually not covered in the early chapters of standard Unix references.
If you are already familiar with Unix and the
In the Workbook exercises, most of the commands you will enter at the Unix prompt will be standard Unix commands, but some will be defined by the software tools that are used to support the Workbook. The non-standard commands will be explained as they are encountered. To understand the standard Unix commands, any standard Linux or Unix reference will do. Section 4.10 provides links to Unix references.
Most Unix commands are documented via the
In Unix, everything is case sensitive; so the command
or
Before starting the Workbook, make sure that you understand the basic usage of the following Unix commands:
You also need to be familiar with the following Unix concepts:
When you type a command at the prompt, a command-line interpreter called a
For those of you with accounts on a Fermilab machine, your login shell was initially set to the
If you are working on a non-Fermilab machine and
Some commands are executed internally by the shell but other commands are dispatched to an
appropriate program or script, and launch a child shell (of the same variety) called a
In order to automate repeated operations, you may write multiple Unix commands into a file and
tell
Throughout the Workbook exercises you will run many scripts. You should understand the big picture of what they do, but you don’t need to understand the details of how they work.
If you would like to learn more about
Very generally, a Unix
This constitutes a basic
Particular programs (e.g.,
In turn, the Workbook code, which must work for all experiments and at Fermilab as well as at
collaborating institutions, requires yet more environment configuration – a
Given the different experiments using
When you finish the Workbook and start to run real code, you will set up your experiment-specific
environment on top of the more generic
This concept of the environment hierarchy is illustrated in Figure 4.1.
One way to see the value of an environment variable is to use the
At any point in an interactive command or in a shell script, you can tell the shell that you want
the value of the environment variable by prefixing its name with the
Here,
By convention, environment variables are virtually always written in all capital letters2 .
There may be times when the Workbook instructions tell you to set an environment variable to some value. To do so, type the following at the command prompt:
If you read
In addition,
All of these path concepts are important to users of
When you source the scripts that setup your environment for
To make the output easier to read by replacing all of the colons with newline characters, enter:
In the above line, the vertical bar is referred to as a
There are two ways to run a bash script (actually three, but two of them are the same).
Suppose that you are given a bash script named
The first version,
The second and third versions are equivalent. They do not start a subshell; they execute the
commands from
Some shell scripts are designed so that they must be sourced and others are designed so that they must be executed. Many shell scripts will work either way.
If the purpose of a shell script is to modify your working environment then it must be sourced, not executed. As you work through the Workbook exercises, pay careful attention to which scripts it tells you to source and which to execute. In particular, the scripts to setup your environment (the first scripts you will run) are bash scripts that must be sourced because their purpose is to configure your environment so that it is ready to run the Workbook exercises.
Some people adopt the convention that all bash scripts end in
If you would like to learn more about bash, some references are listed in Section 4.10.
The bash shell also has the notion of a
You can see the names of all defined bash functions using:
The bash shell also supports the idea of
You can read more about bash shell functions and aliases in any standard bash reference.
When you type a command at the command prompt, bash will resolve the command using the following order:
To learn how bash will resolve a particular command, enter:
When you first login to a computer running the Unix operating system, the system will
look for specially named files in your home directory that are scripts to set up your
working environment; if it finds these files it will source them before you first get a shell
prompt. As mentioned in Section 4.5, these scripts modify your
When your account on a Fermilab computer was first created, you were given
standard versions of the files
If you are working on a non-Fermilab computer, inspect the login scripts to understand what they do.
It can be useful to inspect the login scripts of your colleagues to find useful customizations.
If you read generic Unix documentation, you will see that there are other login scripts with
names like,
The following cheat sheet provides some of the basics:
A more comprehensive summary is available from:
Information about writing bash scripts and using bash interactive features can be found in:
The first of these is a compact introduction and the second is more comprehensive.
The above guides were all found at the Linux Documentation Project: Workbook:
Books about Unix are numerous, of course. Examples include Mark Sobell’s
Section 4.5 discussed the notion of a working environment on a computer. This chapter answers the question: How do I make sure that my environment is configured so that I can run the Workbook exercises or my experiment’s code?
This chapter will explain how to do this in several different situations:
On every computer that hosts the Workbook, a procedure must be established that every user
is expected to follow once per login session. In most cases (NO
As a user of the Workbook, you will need to know what the procedure is and you must remember to follow it each time that you log in.
For all of the Intensity Frontier experiments at Fermilab, the site-specific setup procedure defines all of the environment variables that are necessary to create the working environment for either the Workbook exercises or for the experiment’s own code.
Table 5.1 lists the site-specific setup procedure for each experiment. You will follow the procedure when you get to Section 9.6.
| |
| |
| |
| |
| |
| |
|
|
|
|
| |
| |
| |
| |
| |
NO
Once you have a clean login, follow the procedure given in Listing 5.1.
This change is for topic one.
There are two goals for this chapter. The first is to provide an overview of the features of C++ that
will be important for users of
You will need to consult standard documentation to learn about any of the features that you are
not already familiar with. The examples and exercises in this chapter will in many cases only
skim the surface of C++ features that you will need to know how to manipulate as
you work through the Workbook exercises and then use C++ code with
The second goal is to explain the process of turning source code files into an
This chapter is designed around a handful of exercises, each of which you will first build and run, then “pick apart” to understand how the results were obtained.
A typical program consists of many source code files, each of which contains a human-readable
description of one or more components of the program. In the Workbook, you will see source
code files written in the C++ computer language; these files have names that end in
In the compilation step each source file is translated into
It is often convenient to collect related groups of object files and put them into
The job of the
After the linker has finished, you can run your executable program typing the filename of the
program at the bash command prompt. If you do not have the current directory on the
A typical program links both to libraries that were built from the program’s source code and to
libraries from other sources. Some of these other libraries might have been developed by the
same programmer as general purpose tools to be used by his or her future programs;
other libraries are provided by third parties, such as
Now that you know about libraries, we can give a second reason why an object file, by itself, is not an executable program: until it is linked, it does not have access to the functions provided by any of the external libraries. Even the simplest program will need to be linked against some of the libraries supplied by the compiler vendor and by the operating system.
The names of all of the libraries and object files that you give to the linker is called the
To start these exercises for the first time, do the following:
After these steps, you are ready to begin the exercise in Section 6.4.
If you log out and log back in again, reestablish your environment by following these steps:
This section provides a program that illustrates the concepts in C++ that are assumed knowledge for the Workbook material. Brief explanations are provided, but in many cases you will need to consult other sources to gain the level of understanding that you will need. Several C++ references are listed in Section 6.9.
This sample program will introduce you to the following C++ concepts and features:
The above list explicitly does not include classes, objects and inheritance, which will be discussed in Sections 6.7 and a future section on inheritance.
In this section you will learn how to compile, link and run the small C++ program that illustrates the features of C++ that are considered prerequisites to the Workbook exercises.
Run the following procedure. The idea here is for you to get used to the steps and see what results you get. Then in Section 6.4.3 you will examine the source file and output.
To compile, link and run the sample C++ program, called
Just to see how the exercise was built, look at the script
This turned the source file
Look at the file
In the source file, it is important to first point out the function called the
int main () { ... executable code ... }
Compare your output with the standard example:
There will almost certainly be a handful of differences, which we will discuss in Section 6.4.3.1.
The following sections correspond to sections of the code in
All variables, parameters, arguments, and so on in C++ need to have a
Now, about the handful of differences in the output of one run versus another. There are two main sources of the differences: (1) an uninitialized variable and (2) variation in object addresses from run to run.
In
This line is also the source of the warning message produced by the
See Section 6.4.3.6 for other output that may vary between program runs.
The next section of the example code introduces
While you might find use of arrays in existing code, we recommend avoiding them in new code
arrays, and using either
Two variables which refer to different objects that contain the same value (either by design or by
coincidence) are
Another distinction to be made is that of two variables being
# include < algoritm > # include < string > std :: size_t maxSize ( std :: string const & a , std :: string const & b ) { return std :: max ( a . size (), b . size ()); }
If we consider the call:
std :: string s ( ~ cow ~ ); auto sz = maxSize ( s , s );
then, in the body of the function
The primary conditional statements in C++ are
// Note : this is pseudocode , not C ++ type variable - to - initialize ( expression - to - evaluate ) ? value - if - true : value - if - false ;
An example is shown in the code.
The C++ Standard Library is quite large, and contains many classes, functions, class templates,
and function templates. Our sample code introduces only three: the class
A
The
A pointer is a variable whose value is the memory address of another object. The type of pointer must correspond to the type of the object to which it points.
In addition to the sources of difference in the program output between runs discussed in Section 6.4.3.1, another stems from the line:
float * pa = & a ;
This line declares a variable
Note that this line could have been written with the asterisk next to
float * pa = & a ;
This latter style is common in the C community. In the C++ community, the former style is
preferred, because it emphasizes the type of the variable
Since the address may change from run to run, so may the printout that starts
The next line,
std :: cout << ~ * pa = ~ << * pa << std :: endl ;
shows how to access the value to which a pointer points. This is called
In Section 6.7 you will learn about
(* panimal ). size () panimal -> size ()
In the example code, the lines
std :: cout << ~ The size of animal is : ~ << (* panimal ). size () << std :: endl ; std :: cout << ~ The size of animal is : ~ << panimal -> size () << std :: endl ;
do exactly the same thing. Note that the parentheses in the first line are necessary because the
precedence of
Note that in many situations, the compiler is free to convert an array-of-
A
float a ; float & ra = a ; float * p = & a ; float * q = & ra ;
The values of
Loops, also called
In the previous exercise, the user code was found in a single file and the build script performed compiling and linking in a single step. For all but the smallest programs, this is not practical. It would mean, for example, that you would need to recompile and relink everything when you made even the smallest change anywhere in the code; generally this would take much too long. To address this, some computer languages, including C++, allow you to break up a large program into many smaller files and rebuild only a small subset of files when you make changes in one.
There are two exercises in this section. In the first one the source code consists of three files. This example has enough richness to discuss the details of what happens during compiling and linking, without being overwhelming. The second exercise introduces the idea of libraries.
The source code for this exercise is found in
The file
Look at
To be recognized as a main program, there is one more requirement:
The body of the main program (between the braces), declares and defines a variable
You, as the programmer using that function, need to know what the function does but the C++
compiler doesn’t. It only needs to know the name, argument list and return type of the function
— information that is provided in the header file,
double times2 ( double );
This line is called the
The other three lines in
Finally, the file
double times2 ( double i ) { return 2 * i ; }
It names its argument
We now have a rich enough example to discuss a case in which the same word is frequently used for two different things — instead of two words used for the same thing.
Sometimes people use the phrase “the source code of the function named
The phrase
Based on the above description, when this exercise is run, we expect it to print out:
To perform this exercise, first log in and
This matches the expected printout.
Look at the file
You should have noticed that the same command,
If the
The third command (with no
As it is compiling the main program,
The compiler also makes a table that lists all functions defined by the file and all functions that
are called by code within the file. The name of each entry in the table is called a
When the compiler writes an object file, it writes out both the compiled code and the table of linker symbols.
The symbol table in the file
The job of the linker (also invoked by the command
Sometimes resolving one unresolved reference will generate new ones. The linker iterates until
(a) all references are resolved and no new unresolved references appear (success) or (b) the same
unresolved references continue to appear (error). In the former case, the linker writes the output
to the file specified by the
After the link completes, the files
The script
Look at the script
This script automatically does the same operations as
It takes a bit of experience to decipher the error messages issued by a C++ compiler. The three exercises in this section are intended to introduce you to them so that you (a) get used to looking at them and (b) understand these particular errors if/when you encounter them later.
Each of the following three exercises is independent of the others. Therefore, when you finish with each exercise, you will need to undo the changes you made in the source file(s) before beginning the next exercise.
The first homework exercise will issue the diagnostic:
When you see a message like this one, you can guess that either you have not included a required header file or you have misspelled the name of the function.
The second homework exercise will issue the diagnostic (second and last lines split into two here):
This error message says that the compiler has found two functions that have the same signature but different return types. The compiler does not know which of the two functions you want it to use.
The bottom line here is that you must ensure that the definition of a function is consistent with its declaration; and you must ensure that the use of a function is consistent with its declaration.
The third homework exercise illustrates the C++ idea of
double tmp = a ; ... std :: cout << ~ times2 ( a ) ~ << times2 ( tmp ) << std :: endl ;
Consult the standard C++ documentation to understand when implicit type conversions may occur; see Section 6.9.
Multiple object files can be grouped into a single file known as a
In this section you will repeat the example of Section 6.5 with a variation. You will create a
library from
To perform this exercise, do the following:
This matches the expected printout. Now let’s look at the script
Note that from this point on, in order to reduce the verbosity of some library descriptions, we
will use the Linux form of library names (
The two new features are in step 2, which creates the dynamic library, and step 4, in which
In the filename
The other parts of the name, the prefix
To perform the exercise using
The only difference between
while that from
In the script
In the above, the dot in
This syntax generalizes to multiple libraries in multiple directories as follows. Suppose that the
libraries
The
To perform the exercise using
The difference between
The comments in the sample program used in Section 6.4 emphasized that every variable has a
type:
The language features that allow users to define types are the
Classes and structures (types introduced by either
In general, a class is specified by both a
class MyClassName { // required : declarations of all members of the class // optional : definitions of some members of the class };
The string
A class
class MyClassName ;
Class declarations are rarely used because a class definition also acts as a class declaration.
The remainder of Section 6.7 will give many examples of
In a class definition, the semi-colon after the closing brace is important.
The upcoming sections will illustrate some features of classes, with an emphasis on features that
will be important in the first few Workbook exercises. This is not indended to be a comprehensive
description of classes. To illustrate, we will show nine versions of a type named
This documentation will use technically correct language so that you will find it easier to read the standard reference materials. We will point out colloquial usage as necessary.
Note that the C++ Standard uses the phrase
Here you will see a very basic version of the class
To build and run this example:
The values printed out in the first line of the output may be different when you run the program
(remember initialization?). When you look at the code you will see that
Look at the header file
1 # ifndef Point_h 2 # define Point_h 4 class Point { 5 public : 6 double x ; 7 double y ; 8 }; 10 # endif /* Point_h */ 11
The three lines starting with
Line 4 introduces the name
The body of the class definition begins on line 4, with the opening brace; the body of the class
definition ends on line 8, with the closing brace. The definition of the class is followed by a
semicolon. Line 5 states that the following members of the class are
In this exercise there is no file
Look at the function
1 # include ~ Point . h ~ 2 # include < iostream > 4 int main () { 5 Point p0 ; 6 std :: cout << ~ p0 : ( ~ << p0 . x << ~ , ~ << p0 . y << ~ ) ~ 7 << std :: endl ; 9 p0 . x = 1.0; 10 p0 . y = 2.0; 11 std :: cout << ~ p0 : ( ~ << p0 . x << ~ , ~ << p0 . y << ~ ) ~ 12 << std :: endl ; 14 Point p1 ; 15 p1 . x = 3.0; 16 p1 . y = 4.0; 17 std :: cout << ~ p1 : ( ~ << p1 . x << ~ , ~ << p1 . y << ~ ) ~ 18 << std :: endl ; 20 Point p2 = p0 ; 21 std :: cout << ~ p2 : ( ~ << p2 . x << ~ , ~ << p2 . y << ~ ) ~ 22 << std :: endl ; 24 std :: cout << ~ Address of p0 : ~ << & p0 << std :: endl ; 25 std :: cout << ~ Address of p1 : ~ << & p1 << std :: endl ; 26 std :: cout << ~ Address of p2 : ~ << & p2 << std :: endl ; 28 return 0; 29 } 30
When the first line of code in the
Point p0 ;
is executed, the program will ensure that memory has been
allocated5
to hold the data members of
Some other standard pieces of C++ nomenclature can now be defined:
An important take-away from the above is that a
We have now seen multiple meanings for the word
Which is meant must be determined from context. In this Workbook, we will use “class instance” rather than “object” to distinguish between the second and third meanings in any place where such differentiation is necessary.
The last section of the main program (and of
Figure 6.1 shows a diagram of the computer memory at the end of running
Now, for a bit more terminology: each of the objects referred to by the variables
This exercise expands the class
To build and run this example:
When you run the code, all of the printout should match the above printout exactly.
Look at
Point ();
The parentheses tell you that this new member is some sort of function. A C++ class may have several different kinds of functions.
A function that has the same name as the class itself has a special role and is called a
Look at the file
Point :: Point () { x = 0.; y = 0.; }
Look at the program
Point p0 ;
When the program executes this line, the first step is the same as before: it ensures that memory
has been allocated for the data members of
The next block of the program assigns new values to the data members of
In the previous example,
This exercise introduces four new ideas:
To build and run this exercise,
Look at the file
Point ( double ax , double ay );
This line declares a second constructor; we know it is a constructor because it is a function whose
name is the same as the name of the class. It is distinguishable from the default constructor
because its argument list is different than that of the default constructor. As before,
the file
Look at the file
Look at the file
Point p0 (1.,2.);
This line declares the variable
The next line of code
Point p1 ( p0 );
uses the
We recommend that for any class whose data members are either built-in types, of which
If your class has data members that are pointers, or data members that manage some external
resource, such as a file that you are writing to, these pointers should be
The next line in the file prints the values of the data members of
Notice that in the previous version of
Point p0 ; p0 . x = 3.1; p0 . y = 2.7;
This is called
Point p0 (1.,2.);
We strongly recommend using single-phase construction whenever possible. Obviously it takes less real estate, but more importantly:
This version of the class
To build and run this exercise,
The file
Now look at the file
If you think about these rules carefully, you will see that in
On the other hand, when the compiler compiled the source code for the default constructor in
Therefore, the machine code for the
In some cases it does not matter which of these two ways you use to write a constructor; but on those occasions that it does matter, the right answer is always the colon-initializer syntax. So we strongly recommend that you always use the colon-initializer syntax. In the Workbook, all classes are written with colon-initializer syntax.
Now look at the second constructor in
Look at
This section will introduce
To build and run this exercise,
Look at the file
double mag () const ; double phi () const ; void scale ( double factor );
All three lines declare
The first of these member functions is named
Similarly, the member function named
The third member function,
If a member function does not modify any data members, you should always declare it
Look at
Later on in
The next part of
The next part of
The file
The next line calls the member function
One final comment is in order. Many other modern computer languages have ideas very similar
to C++ classes and C++ member functions; in some of those languages, the name
Here we suggest four activities as homework to help illustrate the meaning of
double Point :: mag () const { x *= 2.; return std :: sqrt ( x * x + y * y ); }
Then build the code again; you should see the following diagnostic message:
Point const p0 (1,2);
Then build the code again; you should see the following diagnostic message:
These first two homework exercises illustrate how the compiler enforces the contract defined by
the qualifier
In the first homework exercise, the value of a member datum is modified, thereby breaking the contract. The compiler detects it and issues a diagnostic message.
In the second homework exercise, the variable
double mag ();
Then build the code again; you should see the following diagnostic message:
The third and fourth homework exercises illustrate that the compiler considers two member
functions that are identical except for the presence of the
This version of the class
A 2D point class, with member data in Cartesian coordinates, is not a good example of
To build and run this exercise,
Look at
Relative to version
Yes, there are two functions named
The two member functions named
If you want to see what mangled names are created for the class
You can understand the output of
In a class declaration, if any of the identifiers
Look at
Relative to version
Inspect the code in the implementation of each of the new member functions. The member function
The member functions in the overload set for the name
There is no requirement that there be accessors and setters for every data member of a class; indeed, many classes provide no such member functions for many of their data members. If a data member is important for managing internal state but is of no direct interest to a user of the class, then you should certainly not provide an accessor or a setter.
Now that the data members of
Look at
Relative to version
Figure 6.2 shows a diagram of the computer memory at the end of running this version of
The key point in Figure 6.2 is that each object has its own member data but there is only one
copy of the code. Even if there are thousands of objects of type
Initially this sounds a little weird: the previous paragraph talks about passing an argument to the
function
For example, the accessor
double x () const { return this -> x_ ; }
This version of the syntax makes it much clearer how there can be one copy of the code even
though there are many objects in memory; but it also makes the code harder to read once you
have understood how the magic works. There are not many places in which you need to explicitly
use the keyword
C++ will not permit you to use the same name for both a data member and its accessor. Since the accessor is part of the public interface, it should get the simple, obvious, easy-to-type name. Therefore the name of the data member needs to be decorated to make it distinct.
The convention used in the Workbook exercises and in the toyExperiment UPS product is that the names of member data end in an underscore character. There are some other conventions that you may encounter:
_name ; m_name ; mName ; theName ;
You may also see the choice of a leading underscore followed by a capital letter, or a double underscore. Never do this. Such names are reserved for use by C++ implementations; use of such names may produce accidental collisions with names used in an implementation, and cause errors that might be very difficult to diagnose. While this is a very small risk, it seems wise to adopt habits that guarantee that it can never happen.
It is common to extend the pattern for decorating the names of member data to all member data, even those without accessors. One reason for doing so is just symmetry. A second reason has to do with writing member functions; the body of a member function will, in general, use both member data and variables that are local to the member function. If the member data are decorated differently than the local variables, it can make the member functions easier to understand.
This section describes a class for which it makes sense to have private data: a 2D point class that
has data members
If this class is implemented with private data manipulated by member functions, then the constructors and member functions can enforce the guarantees.
The language used in the software engineering texts is that a guaranteed relationship among the
data members is called an
If a class has no invariant then one is free to choose public data. The Workbook and the toyExperiment never make this choice. One reason is that classes that begin life without an invariant sometimes acquire one as the design matures — we recommend that you plan for this unless you are 100% sure that the class will never have an invariant. A second reason is that many people who are just starting to learn C++ find it confusing to encounter some classes with private data and others with public data.
This section introduces the
To build and run this exercise, cd to the directory
Look at
Comparing
The
The specifier does not force inlining on the compiler. Why the option? In some cases inlining is a
net positive thing, in other cases it’s a net negative; based on heuristics, the compiler will
determine which, and choose. For some functions, offering the option at all (i.e., including the
specifier
Specifying a function as
In the “decline-to-inline” case, the compiler will write a copy of the
function once for each source file in which a definition of the function
appears12 .
During linking, the copy of the compiled function in the same object file will be used to satisfy
calls to the function. Result: a larger memory footprint, but no reduction in execution
time. Clearly, for a bigger or more complex function, use of the
C++ does not permit you to force inlining; an
The bottom line is that you should always declare simple accessors and simple setters
Look at the definition of the member function
The version of
To build and run this exercise,
This is the same output made by
Relative to
When you define a member function inside the class declaration, the function is implicitly
declared
When you define a member function within the class declaration, you must not prefix the function name with the class name and the scope resolution operator; that is,
double Point :: x () const { return x_ ; }
would produce a compiler diagnostic.
In summary, there are two ways to write inlined definitions of member functions. In most cases,
the two are entirely equivalent and the choice is simply a matter of style. The one exception
occurs when you are writing a class that will become part of an
When writing an
This section illustrates how to write a
Point p0 (1,2); std :: cout << p0 << std :: endl ;
instead of
Point p0 (1, 2); std :: cout << ~ p0 : ( ~ << p0 . x () << ~ , ~ << p0 . y () << ~ ) ~
To build and run this exercise,
This is the same output made by
Look at
Look at
Look at
In
std :: ostream & operator <<( std :: ostream & ost , Point const & p );
If the class whose type is used as second argument is declared in a namespace (which it is not, in this case), then the stream insertion operator must be declared in the same namespace.
When the compiler sees the use of a
We write
Point p0 (1,2), p1 (3,4); std :: cout << p0 << ~ ~ << p1 << std :: endl ;
The C++ compiler parses this left to right. First it recognizes the expression
Look at the implementation of the stream insertion operator in
std :: ostream & operator <<( std :: ostream & ost , Point const & p ) { ost << ~ ( ~ << p . x () << ~ , ~ << p . y () << ~ ) ~ ; return ost ; }
The first argument,
In this example, the stream insertion operator does
If you wish to write a stream insertion operator for another class, just follow the pattern used here.
If you want to understand more about why the operator is written the way that it is, consult the standard C++ references; see Section 6.9.
The stream insertion operator is a
The choice of whether to put the declaration of the stream insertion operator (or any other free function) into (1) the header file containing a class declaration or (2) its own header file is a tradeoff between the following two criteria:
The definition of this operator is typically put into the implementation file, rather than being inlined. Such functions are generally poor candidates for inlining.
Ultimately this is a judgment call and the code in this example follows the recommendations
made by the
With one exception, if including a function declaration in
The class
This section lists some recommended C++ references, both text books and online materials.
The following references describe the C++ core language,
The following references describe the C++ Standard Library,
The following contains an introductory tutorial. Many copies of this book are available at the Fermilab library. It is a very good introduction to the big ideas of C++ and Object Oriented Programming but it is not a fast entry point to the C++ skills needed for HEP. It also has not been updated for the current C++ standard.
The following contains a discussion of recommended best practices. It has not been updated for the current C++ standard.
Section 3.6.8 introduced the idea of external products. For the Intensity Frontier experiments (and for Fermilab-based experiments in general), access to external products is provided by a Fermilab-developed product-management package called Unix Product Support (UPS). An important UPS feature – demanded by most experiments as their code evolves – is its support for multiple versions of a product and multiple builds (e.g., for different platforms) per version.
Another notable feature is its capacity to handle multiple databases of products. So, for example, on Fermilab computers, login scripts (see Section 4.9) set up the UPS system, providing access to a database of products commonly used at Fermilab.
The
In this chapter you will learn how to see which products UPS makes available, how UPS handles variants of a given product, how you use UPS to initialize a product provided in one of its databases and about the environment variables that UPS defines.
The act of setting up UPS defines a number of environment variables (discussed in Section 7.5),
one of which is
The environment variable
If you are on a Fermilab machine, you can look at the value of PRODUCTS just after logging in,
before sourcing your site-specific setup script. Run
It should have a value of
This generic Fermilab UPS database contains a handful of software products commonly used at
Fermilab; most of these products are used by all of the Intensity Frontier Experiments.
This database does not contain any of the experiment-specific software nor does it
contain products such as
After you source your site-specific setup script, look at
You can see which products
Each directory name in these listings corresponds to the name of a UPS product. If you are on a
different experiment, the precise contents of your experiment’s product directory may be
slightly different. Among other things, both databases contain a subdirectory named
An important feature of UPS is its capacity to make multiple variants of a product available to
users. This of course includes different versions, but beyond that, a given version of a product
may be built more than one way, e.g., for use by different operating systems (what UPS
distinguishes as
The full identifier of a UPS product includes its product name, its version, its flavor and its full set of qualifiers. In Section 7.3, you will see how to fully identify a product when you set it up.
Any given UPS database contains several to many, many products. To select a product and make
it available for use, you use the
In most cases the correct flavor can be automatically detected by
Putting in real-looking values, it would look something like:
What does the
Setting up dependent products works recursively. In this way, a single
When you follow a given site-specific setup procedure, the
If this happens, the simplest solution is to log out and log in again. Make sure that you carefully follow the instructions for doing the site specific setup procedure.
Few people will need to know more than the above about the UPS system. Those who do can consult the full UPS documentation at:
For some UPS products, but not all, the site administrator may define a particular fully-qualified
version of the product as the default version. In the language of UPS this notion of default is
called the
When you run this, the UPS system will automatically insert the version and qualifiers of the version that has been declared current.
Having a current version is a handy feature for products that add convenience features to your interactive environment; as improvements are added, you automatically get them.
However the notion of a current version is very dangerous if you want to ensure that software built at one site will build in exactly the same way on all other sites. For this reason, the Workbook fully specifies the version number and qualifiers of all products that it requires; and in turn, the products used by the Workbook make fully qualified requests for the products on which they depend.
When your login script or site-specific setup script initializes UPS, it defines many environment
variables in addition to
In discussing the other important variables, the toyExperiment product will be used as an example product. For a different product, you would replace “toyExperiment” or “TOYEXPERIMENT” in the following text by the product’s name. Once you have followed your appropriate setup procedure (Table 5.1) you can issue the following command this is informational for the purposes of this section; you don’t need to do it until you start running the first Workbook exercise):
The version and qualifiers shown here are the ones to use for the Workbook exercises. When the
Almost all UPS products that you will use in the Workbook define these three environment variables. Several, including toyExperiment, define many more. Once you’re running the exercises, you will be able to see all of the environment variables defined by the toyExperiment product by issuing the following command:
Many software products have version numbers that contain dot characters. UPS requires that
version numbers not contain any dot characters; by convention, version dots are replaced with
underscores. Therefore
The software for the Workbook depends on a large number of external products; the same is true, on an even larger scale, for the software in your experiment. The preceeding sections in this chapter discussed how to establish a working environment in which all of these software products are available for use.
When you are working with the code in the Workbook, and when you are working on your experiment, you will frequently encounter C++ classes and functions that come from these external products. An important skill is to be able to identify them when you see them and to be able to follow the clues back to their source and documentation. This section will describe how to do that.
An important aid to finding documentation is the use of
This subsection will use the example of the class
The class that holds the
If you look at code that uses
1 # include ~ art / Framework / Principal / Event . h ~ 2
The
When you setup the
You can follow this same pattern for any class or function that is part of
If you are new to C++, you will likely find this header file difficult to understand; you do not need to understand it when you first encounter it but, for future reference, you do need to know where to find it.
Earlier in this section, you read that if a C++ file uses
We can summarize this discussion as follows: if a C++ source file uses
Finally, from time to time, you will need to dig through several layers of header files to find the information you need.
There are two code browsing tools that you can use to help navigate the layering of header files and to help find class declarations that are not in a file named for the class:
(In the above, both URLs are live links.)
Section 3.7 introduced the idea that the Workbook is built around a UPS product named
toyExperiment, which describes a made-up experiment. All classes and functions defined in this
UPS product are defined in the namespace
One of the classes from the toyExperiment UPS product is
1 # include ~ toyExperiment / MCDataProducts / GenParticle . h ~ 2
As for headers included from
With a few exceptions, discussed in Section 7.6.4, if a class or function from a UPS product is used in the Workbook code, it will obey the following pattern:
Using this information, the name of the header file will always be
This pattern holds for all of the UPS products listed in Table 7.1.
| |
| |
| |
| |
| |
| |
| |
| |
A table listing git- and LXR-based code browsers for many of these UPS products can be found
near the top of the web page:
https://cdcvs.fnal.gov/redmine/projects/art/wiki
There are three exceptions to the pattern described in Section 7.6.3:
The Workbook is so tightly coupled to the toyExperiment UPS product that all classes
in the Workbook are also in its namespace,
The ROOT package is a CERN-supplied software package that is used by
The rule for writing an include directive for a header file from ROOT is to write its name without any leading path elements:
1 # include ~ TFile . h ~ 2
All of the ROOT header files are found in the directory that is pointed to by the environment
variable
Or you can the learn about this class using the reference manual at the CERN web site: http://root.cern.ch/root/html534/ClassIndex.html
You will not see theGeant4 package in the Workbook but it will be used by the software for your experiment, so it is described here for completeness. Geant4 is a toolkit for modeling the propagation particles in electromagnetic fields and for modeling the interactions of particles with matter; it is the core of all detector simulation codes in HEP and is also widely used in both the Medical Imaging community and the Particle Astrophysics community.
As with ROOT, Geant4 was designed before namespaces were a stable part of the C++ language. Therefore Geant4 adopted the following conventions.
Most of the header files defined by Geant4 are found in a single directory, which is pointed to by
the environment variable
The rule for writing an include directive for a header file from Geant4 is to write its name without any leading path elements:
The workbook does not set up a version of Geant4; therefore G4INCLUDE is not defined. If it were, you would look at this file by:
Both ROOT and Geant4 define many thousands of classes, functions and global variables. In order to avoid collisions with these identifiers, do not define any identifiers that begin with any of (case-sensitive):
The Workbook exercises can be run in several environments:
Many details of the working environment change from site to site1 and these differences are parameterized so that (a) it is easy to establish the required environment, and (b) the Workbook exercises behave the same way at all sites. In this chapter you will learn how to find and log into the right machine remotely from your local machine (laptop or desktop), and make sure it can support your Workbook work.
In order to run the exercises in the Workbook, you will need an account on a machine that can access your site’s installation of the Workbook code. The experiments provide instructions for getting computer accounts on their machines (and various other information for new users) on web pages that they maintain, as listed in Table 8.1. The URLs in the table are live hyperlinks.
Currently, each of the experiments using
| |
| |
| |
| |
| |
| |
| |
| |
| |
At time of writing, the new-user instructions for all LArSoft-based experiments are at the LArSoft site; there are no separate instructions for each experiment.
If you are planning to take the
If you would like a computer account on a Fermilab computer in order to evaluate
The experiment-specific machines confirmed to host the Workbook code are listed in Table 8.2
In most cases the name given is not the name of an actual computer, but rather a round-robin alias
for a cluster. For example, if you log into
| |
| |
| |
| |
| |
| |
| |
| |
| |
|
|
Each experiment’s web page has instructions on how to log in to its computers from your local machine.
Some of the Workbook exercises will launch an X window from the remote machine that opens
in your local machine. To test that this works, type
This should, without any messages, give you a new command prompt. After a few seconds, a new shell window should appear on your laptop screen; if you are logging into a Fermilab computer from a remote site, this may take up to 10 seconds. If the window does not appear, or if the command issues an error message, contact a computing expert on your experiment.
To close the new window, type
If you have a problem with
As you work through the Workbook exericses you will need to edit files. Familiarize yourself with one of the editors available on the computer that is hosting the Workbook. Most Fermilab computers offer four reasonable choices: emacs, vi, vim and nedit. Of these, nedit is probably the most intuitive and user-friendly. All are very powerful once you have learned to use them. Most other sites offer at least the first three choices. You can always contact your local system administrator to suggest that other editors be installed.
In this first exercise of the Workbook, you will be introduced to the
Before running any of the exercises in this Workbook, you need to be familiar enough with the material discussed in Part I (Introduction) of this documentation set and with Chapter 8 to be able to find information as needed.
If you are following the instructions below on an older Mac computer (OSX 10.6, Snow Leopard, or earlier), and if you are reading the instructions from a PDF file, be aware that if you use the mouse or trackpad to cut and paste text from the PDF file into your terminal window, the underscore characters will be turned into spaces. You will have to fix them before the commands will work.
In this exercise you will learn:
This discussion is aimed to help you understand the process described in this chapter as a whole
and how the pieces fit together in the
At the center of the figure is a box labelled “
One remaining box in the figure (at right, second from bottom) is not encountered in the first
Workbook exercise but has been provided for completeness. In most
The arrows in Figure 9.1 show the direction in which information flows. Everything but the
output flows into the
Several event-data input files have been provided for use by the Workbook exercises. These input files are packaged as part of the toyExperiment UPS product. Table 9.1 lists the range of event IDs found in each file. You will need to refer back to this table as you proceed.
| | | |
| | | |
| | | |
| | | |
| | |
|
| | |
|
| | | |
A run-time configuration (FHiCL) file has been provided for each exercise. For Exercise 1 it is
The intent of this section is for the reader to start from “zero” and execute an
Some steps are written as statements, others as commands to issue at the prompt. Notice that
Most readers: Follow the steps in Section 9.6.1.1, then proceed directly to Section 9.7.
If you wish to manage your working directory yourself, skip Section 9.6.1.1, follow the steps in Section 9.6.1.2, then proceed to Section 9.7.
If you log out and wish to log back in to continue this exercise, follow the procedure outlined in Section 9.6.1.3.
Proceed to Section 9.7.
Proceed to Section 9.7.
If you log out and later wish to log in again to work on this exercise, you need to do the folllowing:
Compare this with the list given in Section 9.6.1. You will see that three steps are missing because they only need to be done the first time.
You are now ready to run
From your working directory, execute
Compare the ouptut you produced (in the file
Every time you run
The file
This file is written in the Fermilab Hierarchical Configuration Language (FHiCL, pronounced
“fickle”), a language that was developed at Fermilab to support run-time configuration for several
projects, including
The full details of the FHiCL language, plus the details of how it is used by
In a FHiCL file, the start of a comment is marked either by the hash sign character (
The hash sign has one other use. If the first eight characters of a line are exactly
The basic element of FHiCL is the
A group of FHiCL definitions delimited by braces {} is called a
The fragment of
The name
Within the
The string
In most cases the filenames in the sequence must be enclosed in quotes. FHiCL, like many other languages has the following rule: if a string contains white space or any special characters, then quoting it is required, otherwise quotes are optional.
FHiCL has its own set of special characters; these include anything
It is implied in the foregoing discussion that a FHiCL
The identifier
The fragment of
At the outermost scope of the FHiCL file,
For our current purposes, the module
where RR, SS and EE are substituted with the actual run, subRun and event number of each event.
If you look back at Listing 9.1, you will see that this line appears ten times, once each for events
1 through 10 of run 1, subRun 0 (as expected, according to Table 9.1). The remainder of the
listing is standard output generated by
On line 20,
The remainder of the lines in
The
Note that some options have both a short form and a long form. This is a common convention for Unix programs; the short form is convenient for interacive use and the long form makes scripts more readable. It is also a common convention that the short form of an option begins single dash character, while the long form of an option begins with two dash characters, for example --help above.
By default
Run each of these commands and observe their output.
The second way is within the FHiCL file. Start by making a copy of
Edit
By convention this is added after the fileNames definition but it can go anywhere inside the
source parameter set because the order of parameters within a FHiCL table is not important. Run
You should see output from the
To configure the file for
If the maximum number of events is specified both on the command line and in the FHiCL file, then the command line takes precedence. Compare the outputs of the following commands:
For historical reasons, there are multiple ways to specify the input event-data file (or the list of
input files) to an
If input file names are provided both in the FHiCL file and on the command line, the command line takes precedence.
Let’s run a few examples.
We’ll start with the
To see what you should expect given the following input file, check Table 9.1, then run:
Notice that the ten events in this output are from run 2 subRun 0, in contrast to the previous
printout which showed events from run 1. Notice also that the command line specification
overrode that in the FHiCL file. The
This time, edit the source parameter set inside the
(Notice that you also added
Check Table 9.1 to see what you should expect, then rerun
You will see 20 lines from the
Back to the
This will read only
There are several ways to specify multiple files at the command line. One choice is to use the
Now run
You should see the
Finally, you can list the input files at the end of the
(Remember the Unix convention about a trailing backslash marking a command that continues
on another line; see Chapter 2. ) In this case you should see the
In summary, there are three ways to specify input files from the command line; all of them
override any input files specified in the FHiCL file. Do not try to use two or more of these
methods on a single
The
An equivalent operation can be done from the command line in two different ways. Try the following two commands and compare the output:
You can also specify the intial event to process relative to a given event ID (which, recall,
contains the run, subRun and event number). Edit
When you run this job,
Recall from Section 9.8.2 that the
Look back at the listing on page 207, which contains the
The identifier
Here
Module labels are fully described in Section 24.5.
In this example
Now look at the FHiCL fragment below that starts with
When
In the FHiCL files in this exercise, all of the modules are analyzer modules. Since analyzers do
not make data products, these module labels are nothing more than identifiers inside the FHiCL
file. For producer modules, however, which
Within
In the
In this exercise there is only one module to run (the analyzer
The FHiCL parameter
An
Recall from Section
Note that any path listed in the
If the
both of which are allowable,
As is standard in FHiCL, if the definition of
The notion of
The above description is intended to be sufficient for completing the Workbook exercises. If you want to learn more, now or later, Section 9.8.8.1 provides more detail.
This section is optional; it contains more details about the material just described in Section 9.8.8. It is not really a “dangerous bend” section for experts — just a side trip.
Exercise 1 is not rich enough to illustrate how to specify an
Suppose that there are two groups of people working on a large collaborative project, the project
leaders are Anne and Rob. Each group has a workflow that requires running five or six module
instances; some of the module instances may be in the workflow for both groups. Recall that an
instance of a module refers to the name of a module plus its parameter set, and a module instance
is specified by giving its module label. For this example let’s have eight module instances with
the unimaginative names
That is, Anne defines the modules that her group needs to run and Rob defines the modules that
his group needs to run. Anne and Rob do not need to know anything about each other’s list. The
parameter definitions
The parameter named
The above machinery probably seems a little heavyweight for the example given. But consider a workflow like that needed to design the trigger for the CMS experiment, which requires about 200 paths and many hundreds of modules. Finding the set of unique modules labels is not a task that is best done by hand! By introducing the idea of paths, the design allows each group to focus on its own work, unaffected by the other groups.
Actually, the above is only part of the story: the module labels given in the paths
To illustrate this parallel mechanism let’s continue the above example of two work groups led by
Rob and Anne. In this case let there be filter modules with labels given by,
Here the parameters
During
Now, what happens if you define a path with a mix of modules from the two groups? It might look like this:
In this case
Furthermore, if you put a module label into either
Now it’s time to define two really badly chosen
names:3
Similarly the paths prefixed with
This documentation will try to avoid avoid confusion between
If the
When more than one
The rules for order of execution of module instances named in an
The file
Output files are written by output modules; one module can write one file. An
If you wish to add an output module to an
If you wish to add more output modules, repeat steps 2 and 3 for each additional output file.
The parameter set
In the example of
Before running the exercise, look at the source parameter set of
To run
The first command will write the ouptut file; the second will check that the output file was
created and will tell you its size; the last one will read back the output file and print the event IDs
for all of the events in the file. You should see the
Section 9.6.1 contained a list of steps needed to run this exercise; this section will
describe each of those steps in detail. When you understand what is done in these
steps, you will understand
Steps 1 and 4 should be self explanatory and will not be discussed further.
When reading this section, you do not need to run any of the commands given here; this is commentary on commands that you have already run.
The site-specific setup procedure, described in Chapter 5, ensures that the UPS system is
properly initialized and that the UPS database (containing all of the UPS products
needed to run the Workbook exercises) is present in the
This procedure also defines two environment variables that are defined by your experiment to allow you to run the Workbook exercises on their computer(s):
If these environment variables are not defined, ask a system admin on your experiment.
On the Fermilab computers the home disk areas are quite small so most experiments ask that their collaborators work in some other disk space. This is common to sites in general, so we recommend working in a separate space as a best practice. The Workbook is designed to require it.
This step, shown on two lines as:
creates a new directory to use as your working directory. It is defined relative to an environment variable described in Section 9.9.1. It only needs to be done the first time that you log in to work on Workbook exercises.
If you follow the rest of the naming scheme, you will guarantee that you have no conflicts with other parts of the Workbook.
As discussed in Section 9.6.1.2, you may of course choose your own working directory on any disk that has adequate disk space.
This step is the main event in the eight-step process.
This command tells UPS to find a product named toyExperiment, with the specified version and
qualifiers, and to
The required qualifiers may change from one experiment to another and even from one site to
another within the same experiment. To deal with this, the site specific setup procedure defines
the environment variable
The complete UPS qualifier for toyExperiment has two components, separated by a colon: the
string defined by
Each version of the toyExperiment product knows that it requires a particular version and
qualifier of the
If you are interested, you can inspect your environment before and after doing this setup. To do this, log out and log in again. Before doing the setup, run the following commands:
Then
The step:
only needs to be done only the first time that you log in to work on the Workbook.
In this step you copied the files that you will use for the exercises into your current working directory. You should see these files:
This step:
only needs to be done only the first time that you log in to work on the Workbook. It created
some symbolic links that
The FHiCL files used in the Workbook exercises look for their input files in the subdirectory
in which the necessary input files are found.
This script also ensures that there is an output directory that you can write into when you run the
exercises and adds a symbolic link from the current working directory to this output directory.
The output directory is made under the directory
Issuing the command:
runs the
When you ran
It looked at the environment variable
The output should look similar to that shown in Listing 9.3.
Of course the leading element of each directory name,
If you compare the names of the directories listed in
If you
When
LD_LIBRARY_PATH and looks for a file whose name matches the pattern,
where the asterisk matches (zero or) any combination of characters.
The name of the file is:
If
This section will describe where
When you issued the command
In this case, the output will show the translated value of the environment variable
Some experiments have chosen to configure their version of the
Section 9.8 discussed the listing on page 208, which contains the fragments of
This is part of the toyExperiment UPS product.
The version of
When building
When you got set up to run Exercise 1 in Section 9.6.1, you may have noticed the four FHiCL
files with
For each of these exercises, your job is to figure out what’s wrong, fix it and rerun the command.
With practice you will learn to decipher the error messages that
Note that in the output of each command the
The MSG-s message is what actually caused art to shutdown.
This will make an error message that includes the following:
This will make an error message that includes the following:
This will make an error message that includes the following:
This will make an error message that includes the following:
The answers are intentionally placed on a new page (remember to try before you read further!).
This says to look for a file with that name in the current working directory. It’s not
there because all of the input files are in the subdirectory
The second message tells you that something wrong in the path named
and
The answer is that in the definition of the module label
In this exercise you will build and run a simple
In this and all subsequent Workbook exercises, you will use the build system used by the
Exercise 2 and all subsequent Workbook exercises will use the setup instructions found in Sections 10.4 and 11.
Before running this exercise, you need to be familiar with the material in Part I (Introduction) of this documentation set and Chapter 9 from Part II (Workbook). Concepts that this chapter refers to include:
In this chapter you will also encounter the C++ idea of
In this exercise you will learn:
Up through step 4 of the procedure in this section, the results should look similar to those of
Exercise 1. Note that the directory name chosen here in the
If you want to use a self-managed working directory, in steps 3 and 4, make a directory of your
choosing and
In your source window do the following:
The
Git is a source code management system2 that is used to hold the source code for the Workbook exercises. A source code managment system is a tool that looks after the bookkeeping of the development of a code base; among many other things it keeps a complete history of all changes and allows one to get a copy of the source code as it existed at any time in the past. Because of git’s many advanced features, many HEP experiments are moving to git. git is fully described in the git manual3 .
Some experiments set up git in their site-specific setup procedure; others do not.
In running
The
Executing the
If you wish to learn about
If you do not see the expected output, contact the
Figure 10.1 shows roughly what your source directory contains at the end of the setup
procedure. You can see the correspondence between it and the output of the
Notice that it contains a subdirectory of the same name as its parent,
Look inside the
If you look inside the
The file
Again, advanced users wanting to manage their own working directory may skip to Section 10.4.3.2.
Now go to your build window and do the following:
Skip Section 10.4.3.2 and move on to Section 10.4.4.
The steps in this procedure that are the same as for the “standard” procedure are explained in Section 10.4.4.
Now go to your build window and do the following:
Logging in and sourcing the site-specific setup script should be clear by now. Notice that next
you are told to
Step 6 sources a script called
Check that there are no error messages in the indicated block. The listing concludes with a
request for you to run a
This script sets up all of the UPS products on which the Workbook depends; this is analogous
to the actions taken by Step 6 in the first exercise (Section 9.6.1.1) when you were
working in the
After sourcing this script, the contents of
At this time the two subdirectories
Step 7 (
After the build has completed do an
Also do an
After runing
Most of these files are standard files that are explained in the
An
These links are present so that the FHiCL files for the Workbook exercises do not need to be customized on a per-user or per-site basis.
In the preceeding sections of this chapter you established what is known as the
In Section 10.4.1, step 4b (
In step 7 of Section 10.4.3, you ran
In the figure, information flow at run-time is denoted by the blue lines. When you
ran the
In all environments, the
The first of these is denoted in the figure by the box labeled “Configuration File.” In the
The remaining elements in Figure 10.3 are the same as described for Figure 9.1.
Figure 10.4, a combination of Figures 10.1 and 10.2), illustrates the distinct source and build areas, and the relationship between them. It does not show all the contents in each subdirectory.
In your build window, make sure that your current working directory is your build directory. From here, run the first part of this exercise by typing the following:
(As a reminder, we suggest you get in the habit of routing your output to the
The second difference is that the words printed out for each event are a little different; the
printout from
while that from
The reason for changing this printout is so that you can identify, from the printout, which module was run.
Compare the FHiCL file used in this exercise,
The file
This dynamic library file was created when you ran
This section will describe the source code for the module
When you ran
This is the dynamic library that was loaded by
Look at the file
All module files that you will see in the Workbook share these “broad strokes.” Some
experiments that use
1 # include ~ art / Framework / Core / EDAnalyzer . h ~ 2 # include ~ art / Framework / Core / ModuleMacros . h ~ 3 # include ~ art / Framework / Principal / Event . h ~ 5 # include < iostream > 7 namespace tex { 9 class First : public art :: EDAnalyzer { 11 public : 13 explicit First ( fhicl :: ParameterSet const & ); 15 void analyze ( art :: Event const & event ) override ; 17 }; 19 } 21 tex :: First :: First ( fhicl :: ParameterSet const & pset ) : 22 art :: EDAnalyzer ( pset ) { 23 std :: cout << ~ Hello from First :: constructor . ~ 24 << std :: endl ; 25 } 27 void tex :: First :: analyze ( art :: Event const & event ){ 28 std :: cout << ~ Hello from First :: analyze . Event id : ~ 29 << event . id () 30 << std :: endl ; 31 } 33 DEFINE_ART_MODULE ( tex :: First ) 34
The first three lines of code in the file
1 # include ~ art / Framework / Core / EDAnalyzer . h ~ 2 # include ~ art / Framework / Core / ModuleMacros . h ~ 3 # include ~ art / Framework / Principal / Event . h ~ 4
The next line includes the C++ header that enables this code to write output to the screen; for details, see any standard C++ documentation.
5 # include < iostream > 6
Those of you with some C++ experience may have noticed that there is no file named
If you are a C++ beginner you will likely find these header files difficult to understand; you do not need to understand them at this time but you do need to know where to find them for future reference.
Let’s start with short explanations of each line and follow up with more information.
7 namespace tex { 9 class First : public art :: EDAnalyzer { 11 public : 13 explicit First ( fhicl :: ParameterSet const & ); 15 void analyze ( art :: Event const & event ) override ; 17 }; 18
The first line opens a namespace named
The next line begins the declaration of the class
The line
The first one is a constructor. Since
13 explicit First ( fhicl :: ParameterSet const & ); 14
The second declares the
15 void analyze ( art :: Event const & event ) override ; 16
Section 3.6.3 discussed the idea of
A module may also contain any other member data and any other member functions that are
needed to do its job. You can see from Listing 10.2 that the class
The requirement that the class name match the filename (minus the
The declaration of the constructor begins with the keyword
The
For those who are knowledgeable about C++, the base class
The next code in the source file (Listing 10.2) is the
21 tex :: First :: First ( fhicl :: ParameterSet const & pset ) : 22 art :: EDAnalyzer ( pset ) { 23 std :: cout << ~ Hello from First :: constructor . ~ 24 << std :: endl ; 25 } 26
The fragment
The argument to the constructor is of type
The argument to the constructor is passed by
The first line of the constructor contains the fragment “
The requirement that the constructor of an analyzer module pass the parameter set to the
constructor of
In the declaration of the class
In the declaration of a function, a name supplied for an argument is ignored by the compiler. So code will compile correctly with or without a name. Remember that a constructor is just a special kind of function so the rule applies to constructors too. It is very common for authors of code to provide an argument name as a form of documentation. You will code written both with and without named arguments in declarations.
The above discussion only applied to the
The definition of the member function
27 void tex :: First :: analyze ( art :: Event const & event ){ 28 std :: cout << ~ Hello from First :: analyze . Event id : ~ 29 << event . id () 30 << std :: endl ; 31 } 32
If the type of the argument is not exactly correct, including the the
Note that the
Section 3.6.1 discussed the HEP idea of an event and the
At any given time in a running
As described in Section 3.6.3, analyzer modules may only inspect data in
You can find the header file for
The body of the function is almost trivial: it prints some information to let the user know that it
has been called. In Section 10.6.1, when you ran
If you compare this to the source code you can see that the fragment
This fragment tells the compiler to do the following:
Section 3.6.1 discussed the idea of an event identifier, which has three components, a run
number, a subRun number and event number. In this section you will learn where to find the class
that
Before you work through this section, you may wish to review Section 7.6 which discusses how to find header files.
In Section 10.6.3.6 you learned that the member function
or use one of the code browsers discussed in 7.6.2. In this file you will find the definition of the member function
EventID id () const { return aux_ . id ();}
The important thing to look at here is the return type,
# include ~ art / Persistency / Provenance / EventID . h ~
which is the header file that declares
and find the declaration for
// An EventID labels an unique readout of the data // acquisition system , which we call an ‘‘ event ’’.
Look again at
RunNumber_t run () const ; SubRunNumber_t subRun () const ; EventNumber_t event () const ;
Earlier in
namespace art { typedef std :: uint32_t EventNumber_t ; }
meaning that the event number is represented as a 32-bit unsigned integer. A
The authors of
namespace art { typedef unsigned EventNumber_t ; }
The difference is the use of
Why did the authors of
std :: unit32_t event () const ;
The answer is that it makes it easy to change the definition of the type should that be necessary. If, for example, an experiment requires that event numbers be of length 64 bits, only one change is needed, followed by a recompilation.
It is good practice to use typedefs for every concept for which the underlying data type is not absolutely certain.
It is a very common, but not universal, practice within the HEP C++ community that typedefs
that are used to give context-specific names to the C++ built-in types (
One last observation about
namespace art { std :: ostream & operator <<( std :: ostream & os , EventID const & iID ); }
This tells the compiler that the class
<< event . id ()
The final line in
DEFINE_ART_MODULE ( tex :: First )
invokes a C preprocessor macro. This macro is defined in the header file that was pulled in by
# include ~ art / Framework / Core / ModuleMacros . h ~
If you are not familiar with the C preprocessor, don’t worry; you do not need to look under the hood. But if you would like to learn about it, consult any standard C++ reference.
The
The
C++ allows some flexibility in syntax, which can be seen as either powerful or confusing, depending on your level of expertise. Here we introduce you to a few alternate styles that you will need to recognize and may want to use.
Look at the
std :: cout << ~ Hello from First :: analyze . Event id : ~ << event . id () << std :: endl ; }
This could have been written:
art :: EventID id = event . id (); std :: cout << ~ Hello from First :: analyze . Event id : ~ << id << std :: endl ;
This alternate version explicitly creates a temporary object of type
You will certainly encounter the first line of the above written in a different style, too, i.e.,
art :: EventID id ( event . id ());
Here
You may also see the argument list of the analyze function written a little differently,
void analyze ( const art :: Event & );
instead of
void analyze ( art :: Event const & );
The position of the
Finally, Listing 10.3 shows the same information as Listing 10.2 but using a style in which the
namespace remains open after the class declaration. In this style, the leading
# include ~ art / Framework / Core / EDAnalyzer . h ~ # include ~ art / Framework / Core / ModuleMacros . h ~ # include ~ art / Framework / Principal / Event . h ~ # include < iostream > namespace tex { class First : public art :: EDAnalyzer { public : explicit First ( fhicl :: ParameterSet const & ); void analyze ( art :: Event const & event ) override ; }; First :: First ( fhicl :: ParameterSet const & pset ) : art :: EDAnalyzer ( pset ){ std :: cout << ~ Hello from First :: constructor . ~ << std :: endl ; } void First :: analyze ( art :: Event const & event ){ std :: cout << ~ Hello from First :: analyze . Event id : ~ << event . id () << std :: endl ; } } DEFINE_ART_MODULE ( tex :: First )
In Section 10.4.3 you issued the command
When you ran
The object file contains the machine code for the class
The verb
To be complete, when you ran
How did
When
The object file created by the compilation step is a temporary file and, once it has been inserted into the dynamic library, it is not used any more. Therefore the name of the object file is not important.
On the other hand, the name of the dynamic library file is very important.
where the
When naming dynamic libraries,
You can check that this file is there by issuing the following command from your build directory:
This algorithm guarantees that every module within
The experiments using
When you edit a file in your source area you will need to rebuild that file in order for those changes to take effect. If any other files in your source area depend on the file that you edited, they too will need to be rebuilt. To do this, reissue the command:
Remember that this command must be executed from your build directory and that, before
executing it, you must have setup the environment in your build window. When you run this
command,
If you want to clean up everything in your build area and rebuild everything from scratch, use the following command:
This command will give you five seconds to abort it before it starts removing files; to abort, type
When you do a clean build it will remove all files in your build directory that are not managed by
When you ran
If you edit certain files in the
When
You can spot-check this by doing, for example,
You will see that the
There are a few small perturbations on this pattern. The most visible is that the ROOT product
puts most of its header files into a single directory,
When the compiler compiles a
I
There may be many such arguments on one command line. If you compiled the code by hand,
you would add the
When
A corollary of this discussion is that when you wish to include a header file from a UPS product,
the
This system illustrates how the Workbook can work the same way on many different computers
at many different sites. As the author of some code, you only need to know paths of include files
relative to the relevant
This system has the potential weakness that if two products each have a header file with exactly
the same relative path name, the compiler will get confused. Should this happen, the compiler
will always choose the file from the earlier of the two
The convention of having the UPS product name in the relative path of
The module
it must resolve all of the undefined symbols from all of the object files that go into
the library. To resolve a symbol, the linker must learn what dynamic library defines
that symbol. When it discovers the answer, it will write the name of that dynamic
library into something called the
If library A depends on library B and library B depends on library C, but library A does not
directly depend on library C, then the dependency list of library A should contain only library B.
In other words, the dependency should contain only
To learn where to look for symbol definitions, the linker looks at its command line to find
something called the
For these Workbook exercises, the author of each exercise has determined the link
list for each dynamic library that will be built for that exercise. In the
The five
Almost all
When
The experiments that use
Consult the
This section provides the next layer of details about the build system;
If you want to see what
For example, if you really want to know the name of the object file, you can find it in the verbose output. For this exercise, the object file is (the path is shown here on two lines):
Also, you can read the verbose listing to discover the flags given to the compiler and linker. The
more instructive compiler and linker flags valid at time of writing are given in Table 10.1.The
C++ 11 features are selected by the presence of the
tells the linker that it must resolve all external references at link time. This is sometime referred
to as a
| |
| |
| |
| |
| |
|
|
|
|
|
|
This section contains some suggested exercises in which you will make your own modules and
learn more about how to use the class
In this exercise you will create a new module by copying
Go to your source window and
Edit the files
The new module needs the same link list as did
Go to your build window and
This should complete with the message:
If you get an error message, consult a local expert or the
When you run
You can verify that
Stay in your build directory and run the new module:
Compare
This exercise is much like the previous one; the difference is that you will use a tool named
Go to your source window and
The command
The leading elements of the directory name will reflect your UPS products area, and may be
different from what is shown here. The version number,
From your source directory, type the following commands:
The second command tells
If you compare
The
Edit
When you built
Edit
Go to your build window and
Refer to the previous section to learn how to identify a successful build and how to verify that the expected library was created.
Stay in your build directory and run the third module:
Compare
In this exercise you will run four modules at once, the three made in this exercise plus the
Go to your source window and
Edit the file
When you run
Go to your build window and
Run the exercise:
Compare
Remember that
In this exercise, you will access the individual parts of the event identifier.
Before proceeding with this section, review the material in Section 10.6.3.7 which discusses the
class
In this exercise, you are asked to rewrite the file
and so on for each event.
To do this, you will need to reformat the text in the
You will do the editing in your source window, in the subdirectory
When you think that you have successfully rewritten the module, you can test it by going to your
build window and
If you have not figured out how to do this exercise after about 15 minutes, you can find one
possible answer in the file
To run the answer module and verify that it makes the requested output, run:
(The command can be typed on a single line.) You did not need to build this module because it
was already built the first time that you ran
There is a second correct answer to this exercise. If you look at the header file for
EventNumber_t event () const { return aux_ . event ();} SubRunNumber_t subRun () const { return aux_ . subRun ();} RunNumber_t run () const { return id (). run ();}
So you could have called these directly,
std :: cout << ~ Hello from FirstAnswer01 :: analyze . ~ << ~ run number : ~ << event . run () << ~ sub run number : ~ << event . subRun () << ~ event number : ~ << event . event () << std :: endl ;
instead of
std :: cout << ~ Hello from FirstAnswer01 :: analyze . ~ << ~ run number : ~ << event . id (). run () << ~ sub run number : ~ << event . id (). subRun () << ~ event number : ~ << event . id (). event () << std :: endl ;
But the point of this exercise was to learn a little about how to dig down into nested header files to find the information you need.
When you performed the exercises in this chapter, you saw, for example, the file
In a typical C++ programming environment there is a header file (
The reason for having
If you think carefully, you are already aware of a very common exception to the pattern of one
The
In this chapter, the source for the module
Some experiments use this three-file style. The authors of
In this style,
# ifndef art - workbook_FirstModule_First_h # define art - workbook_FirstModule_First_h # include ~ art / Framework / Core / EDAnalyzer . h ~ # include ~ art / Framework / Principal / Event . h ~ namespace tex { class First : public art :: EDAnalyzer { public : explicit First ( fhicl :: ParameterSet const & ); void analyze ( art :: Event const & event ) override ; }; } # endif
The file
# include ~ art - workbook / FirstModule / First . h ~ # include < iostream > tex :: First :: First ( fhicl :: ParameterSet const & pset ) : art :: EDAnalyzer ( pset ) { std :: cout << ~ Hello from First :: constructor . ~ << std :: endl ; } void tex :: First :: analyze ( art :: Event const & event ){ std :: cout << ~ Hello from First :: analyze . Event id : ~ << event . id () << std :: endl ; }
And
# include ~ art - workbook / FirstModule / First . h ~ # include ~ art / Framework / Core / ModuleMacros . h ~ DEFINE_ART_MODULE ( tex :: First )
The properties that a class must have in order to be an analyer module are summarized in
Section 10.6.3.2 for reference. This section reviews how the source code found in an analyzer
module, e.g.,
The last bullet really means that the dynamic library contains a factory function that can
construct instances of
Two modules are provided that intentionally contain bugs and fail to build:
Your job in each case is to figure out what’s wrong with the module and fix it. The build system
will ignore these files until the
Pay attention to which window you do each operation in; there’s a fair bit of back-and-forth between the source and build windows!
Repeat the procedure for the second file. Because this is the first time you are doing this, we will give you a hint: you only need to fix one line in the first file but you need to fix two in the second.
The answers are intentionally placed on a new page (remember to try before you read further!).
In
void analyze ( art :: Event & event ) override ;
There is a missing
Because of the
In
void analyze ( art :: Event & event );
and the second is in the implementation:
void tex :: FirstBug02 :: analyze ( art :: Event & event ){
In the first line, both the
Because the
While there are legitimate reasons to hide a virtual function, most cases are, in fact, errors. Therefore the build system for the Workbook is configured as follows:
This forces you to think about each case and decide if it is really what you intended. To learn how to allow hiding of virtual functions consult the cetbuildtools documentation.
After you’ve done the initial setup described in Section 10.4, there are some steps that don’t need to be repeated for subsequent login sessions. To begin a general login session for Exercise 2 or any subsequent exercise, you need to follow the instructions in this chapter.
If during your initial setup you chose to manage your own directory names, then the names of your source and build directories will be different than those shown here.
In your source window:
The contents of the source directory is discussed in Section 10.4.2.2.
In your build window:
The build window setup is discussed in Section 10.4.4 and the
As you well know by now, the Workbook exercises require you to download some code to edit,
build, execute and evaluate. Both the documentation and the code it references are expected to
undergo continual development throughout 2014. The latest is always available at the
Announcements of new releases are made on the
Until the full set of exercises is written, you will have to update occasionally just to get the latest exercises. Come back to this chapter whenever you reach the end of the available exercises. Or come back and update whenever a new release is announced; it may include improvements to existing exercises.
This chapter will show you how to update. The steps include:
First, check which documentation release you’re currently using: it’s noted on the title page of this
document1 .
Then go to the
Download a new copy of the documentation, as needed.
Also noted on the title page of the documentation is the
release2 of
the art-workbook code that the documentation is intended for. Recall from Figure 10.1 that
Chances are that you’re using the code release that goes with the documentation you have been
using. You can check by looking in the file
This shows version v0_00_13 as an example. If your version is earlier than the one listed on the cover of the latest documentation, you will need to get new code and build it.
These instructions illustrate updating the working version of the art-workbook code from version v0_00_13 to version v0_00_15. There is nothing special about these two versions; the instructions serve as a model for a change between any pair of versions.
The output from this command is shown in Listing 12.1.
Use the new version number twice in this command.
In the messages produced in this step, watch for the names of files that you have modified.
Check for conflicts that
To rebuild your updated working code:
At any time you can check to see which files you have modified and which you have added. The
code is structured in such a way that when you checkout a new version, these files will remain in
your working directory and will not be modified or deleted. The
To see the new/modified files,
Do not issue the
In the rare case that you have neither modified nor added any files, the output of
Recall the discussion in Section 3.6.2 about widget-making workers on an assembly line. All
workers have a task to perform on each widget as it passes by and some workers may also
need to perform start-up or shut-down tasks. If a module has something that it must
do at the start of the job, then the author of the module can write a member function
named
The author of a module may also provide member functions to perform actions at the start of a subRun, at start of a run, at the end of a subRun or at the end of a Run.
These member functions are
In this exercise you will build and execute an analyzer module that illustrates three of these
member functions:
You may also perform a suggested exercise to add the three corresponding member functions
The prerequisites for this chapter include all of the material in Part I (Introduction) and all of the material up to this point in Part II (Workbook).
In particular, make sure that you understand the
This chapter will show you
As you gain experience, you will gain proficiency at knowing
You will also be introduced to the classes
that are analogous to the
The source code for the module you will run is
In your source window, look at the source file
The optional member functions
In Section 10.6.3.7 you learned about the class
The header files for these classes are found at:
Similar to the
In the call to
The
Always provide the
For those with some C++ background, the three member functions
In
Because the object is passed by reference, the
There is a very important habit that you need to develop as a user of
To access the
for the subRun and
In your
You may sometimes see this written as:
Both versions mean exactly the same thing. When a type is long and awkward to write, the
Look at the file
In your build directory, run the following command
The part of the printed output that comes from the module
The member function
A small number of things must be done in the constructor — see below. Other tasks can be done
in either place but most experiments have found it useful to follow the rough guideline that you
should put initializers and code related to
The correct place to initialize data members is in the constructor and, whenever possible, you
should use the initailizer list syntax. Never defer initialization of a data member to the
For those of you familiar with ROOT, we can provide an example of something physics-related.
You should create histograms, ntuples and trees in one of the
Go to your source window. In the file
Then go to your build window and make sure that your current directory is your build directory. Then rebuild this module and run it:
Consult Chapter 10 if you need to remember how to indentify that the build completed
successfully. Compare the output from this run of
The solution to this activity is provided as the file
Does the output of your code match the output from this code?
In a single run of
If you need a reminder about how to tell
Make sure that the printout from this job matches the description of the event loop found in Section 3.6.2.
The
You should be able to identify your printout among the printout from
When you are getting an error from
As you gain experience, you will gain proficiency at knowing
You will also be introduced to the classes
Two files are provided, one of which intentionally contain bugs. The module should compile and run, but some printout will be missing. The files are:
Your job is to figure out what’s missing and why, then fix it. The answer is provided at the end.
The answer is intentionally placed on a new page (remember to try before you read further!).
The code compiles and runs but the printout from the
The warning that we tripped over in the Exercise 2 test only comes up if the name of the member function is exactly the same and the argument list is different.
In the previous few chapters you have used FHiCL files to configure
Among other things, you have learned how to define a module label and its corresponding parameter set, the simplest case looking like:
where the
When you define a module label, you may enter additional FHiCL definitions (i.e.,
This functionality allows you to write modules whose behaviour is run-time configurable. For example, if you have a reconstruction algorithm that depends on some cuts, the values of those cuts can be provided in this way.
The prerequisite for this chapter is all of the material in Part I (Introduction) and the material in Part II (Workbook) up to and including Chapter 10. You can read this chapter without necessarily having read Chapter 12 or 13.
In Section 10.6.3.4 you saw that the constructor of a module is required to take an argument of
type
In this chapter you will learn how to use this argument to read additional parameters in a
parameter set. In particular, you will learn about the class
You will also learn:
Finally, you will learn a small amount about C++ templates and C++ exceptions, just enough to understand the exercise.
The source code for the first module you will run is
The FHiCL file that you will run in this exericse is
The parameter
Looking at the parameter set, it appears that the parameter
The source code for this exercise is found in the file
When
Let’s examine the first part of the constructor; see Listing 14.2.
1 tex :: PSet01 :: PSet01 ( fhicl :: ParameterSet const & pset ): 2 art :: EDAnalyzer ( pset ){ 4 std :: string a = pset . get < std :: string >( ~ a ~ ); 5 int b = pset . get < int > ( ~ b ~ ); 6 double c = pset . get < double >( ~ c ~ ); 7 bool d = pset . get < bool > ( ~ d ~ ); 8 std :: vector < int > e = pset . get < std :: vector < int >>( ~ e ~ ); 9 fhicl :: ParameterSet f = pset . get < fhicl :: ParameterSet >( ~ f ~ ); 11 int fa = f . get < int >( ~ a ~ ); 12 int fb = f . get < int >( ~ b ~ ); 14 std :: string module_type = 15 pset . get < std :: string >( ~ module_type ~ ); 17 std :: string module_label = 18 pset . get < std :: string >( ~ module_label ~ ); 19
Recall from Section 14.5 that the object
The angle bracket syntax
When you ask for the value of a parameter, the name of the parameter is specified as a familiar
function argument while the return type is specified between the angle brackets. The name
between the angle brackets is called a
For example, look at the line that reads the parameter
4 std :: string a = pset . get < std :: string >( ~ a ~ ); 5
It first declares a local variable named
The returned value is used to initialize the local variable,
It is not required that the local variable,
The following line, that sets the parameter
5 int b = pset . get < int >( ~ b ~ ); 6
is similar to the previous line; the main difference is that
It is beyond the scope of this chapter to discuss how the template mechanism is used to trigger
automatic type conversions. It is sufficient to remember the following: when you use the
The authors of FHiCL could have designed a different interface, such as:
std :: string a = pset . get_as_string ( ~ a ~ ); std :: string b = pset . get_as_int ( ~ b ~ );
Instead they chose to write it using templates. The reason for this choice is that it allows one to
add new types to FHiCL without needing to recompile FHiCL. How you do this is beyond the
scope of this chapter. You now know everything that you need to know about templates in order
to use
The rest of the lines in the section of code shown in Listing 14.2 extract the remaining
parameters from
1 std :: cout << ~ \ n --------------------\ nPart 1:\ n ~ ; 2 std :: cout << ~ a : ~ << a << std :: endl ; 3 std :: cout << ~ b : ~ << b << std :: endl ; 4 std :: cout << ~ c : ~ << c << std :: endl ; 5 std :: cout << ~ d : ~ << d << std :: endl ; 7 std :: cout << ~ e : ~ ; 8 for ( int i : e ){ 9 std :: cout << ~ ~ << i ; 10 } 11 std :: cout << std :: endl ; 13 std :: cout << ~ f . a : ~ << fa << std :: endl ; 14 std :: cout << ~ f . b : ~ << fb << std :: endl ; 16 std :: cout << ~ module_type : ~ << module_type << std :: endl ; 17 std :: cout << ~ module_label : ~ << module_label << std :: endl ; 18
1 std :: cout << ~ \ n --------------------\ nPart 2:\ n ~ ; 2 std :: cout << ~ f as string : ~ 3 << f . to_string () 4 << std :: endl ; 5 std :: cout << ~ f as indented - string :\ n ~ 6 << f . to_indented_string () 7 << std :: endl ; 8
1 std :: cout << ~ \ n --------------------\ nPart 3:\ n ~ ; 2 std :: cout << ~ pset :\ n ~ 3 << pset . to_indented_string () 4 << std :: endl ; 5
Your code may ask for the values of parameters from a
We offer two final comments on
Now let’s see what happens when you run the job. In your build directory, run the following command
The expected output from this command is shown in Listing 14.6.
The module reads in the parameter set and then prints out each of the values in several different
ways as explained in Section 14.6. Check that the printout matches the definitions of the
parameters from
Now that you have seen templates, we can introduce some more language that you will need to
know. In the above examples,
On its own,
1 ParameterSet :: get < T > 2
or by the abbreviation
If you are familar with template meta-programming you can find the source for the class
In particular, this is where you can find the source for
This section describes the different types that can be used as the template argument for
You can write helper functions that will allow the type
These files allow you to define a FHiCL parameter as:
and to read it as
1 auto zaxis = pset . get < CLHEP :: Hep3Vector >( ~ zaxis ~ ); 2
There are two sorts of error conditions that may occur when reading parameters from a parameter set:
To give an example of the second sort, suppose that on line 6 of Listing 14.1 you change the
FHiCL definition of the parameter
6 double c = pset . get < double >( ~ c ~ ); 7
The code will correctly find that parameter
In both cases, the code inside
From time to time code within
There are several other options that cannot be described here because the necessary background information has not yet been established.
When
For most sorts of errors, the orderly shutdown will be successful and your work up to the error will be preserved. However, there are circumstances for which the orderly shutdown will fail, for example when there is no disk space to hold more output.
For all exception cases but one,
These default behaviors can be changed in the FHiCL file.
The technology that
In
Note, too, that the completion status is nonzero.
In
Information from the parameter set is often needed in a member function of the module class.
This information is propagated from the parameter set to the member function by storing the
values of these parameters as data members of the module class. This is illustrated in the two files
If you need to refamiliarize yourself with the concept of data members of a class, refer to Section 6.7.2.
There are three things to notice in
If you need to refamiliarize yourself with the colon intializer syntax, refer to Section 6.7.5, or with the conventions about underscore characters in the names of data members, refer to Section 6.7.7.2 covers
To run this example, enter
The expected output from this is given in Listing 14.9.
This example is only relevant when parameters are actually used in member functions. If a
parameter is used only inside the constructor, do not store it as a data member; instead you
should store it as a local variable of the constructor. This brings up a
It is sometimes convenient to provide a default value for a parameter. Default values may be
provided in the source code that reads the parameter set. This mechanism is illustrated by the
files
You have already seen that the member function template
1 int b = pset . get < int >( ~ b ~ ); 2
It also takes an optional second function argument, a default value for the parameter. For example,
1 int b = pset . get < int >( ~ b ~ ,0); 2
If the second argument is present, there two cases:
When reading the code in this example you will encounter the expression:
1 std :: vector < double >(5,1.0); 2
This tells the compiler to instantiate an object of type
This expression appears as the second argument of the second call to the member function
With the above explanations, the source code for this example should be reasonably
self-explanatory; it looks for two parameters named
To run this example,
The expected output from this is given in Listing 14.10.
As a suggested exercise, edit
Allowing
FHiCL recognizes numbers in both fixed point and exponential notation, for example
In the preceding exercises you defined some numerical values in a FHiCL file, read them into your code and printed them out; the printed values exactly matched the input values. The values used in those exercises were carefully chosen to avoid a few surprises: there are cases in which the printed value will be an equivalent, but not identical, form. This section discusses those cases and provides some examples.
When FHiCL recognizes that a parameter value is a number it converts the number into a
Some examples of numbers and their canonical forms are given in Table 14.1.
| | | |
| |
||
| | | |
| | | |
| | | |
| | | |
| | | |
If a numerical value, when expressed as a fixed point number, has no fractional part, your
code may ask for the parameter to be returned as either a floating point type (such
as
1 int b = pset . get < int >( ~ b ~ ); 2
It might also have been written
1 double b = pset . get < double >( ~ b ~ ); 2
which would do the expected thing: given the input from
On the other hand, if a numercial value, when expressed as a fixed point number, does have a
fractional part, you may only ask for the parameter to be returned as a floating point type. If you
ask for such a value as an
What is the point of having canonial forms for numbers?
There are times when it is necessary for
When comparing two parameter sets a trivial, but pernicious, complication is when two parameter sets differ only by meaningless differences in the representation of numbers, such as “1” vs “1.0”. If one compares the canonical forms of the two paremeter sets, this complication is removed.
The above ideas are illustrated by the files
The expected output from this is given in Listing 14.11.
Read the source code and the FHiCL file; then examine the output. The first three lines show
three different printed formats of the parameter
Line 4 shows the canonical form of the parameter
If you modify the precision of
Line 7 shows the canonical form of the parameter
For the next exercise, edit
When you read a parameter from a parameter set it is always to a good idea to check
that the value of the parameter is within the allowed set or range of values. If a
parameter has an invalid value, the
In order to initiate an orderly shutdown, you throw an exception. An example of how to do so is
found in
The constructor argument to
From that file, chose an enum value does a good job of describing the sort of issue that caused
you to throw the exception. You can also append arbitrary text, as is shown in the example; make
sure that the text tells users enough so that they can understand the problem. You should
terminate the text with a new line character, not with
Instead of using the class
To execute this example, use the file
Edit the value of the
You can read more about exceptions in any standard C++ reference.
A variant of this example is in
The other feature of
You will also learn:
Finally, you will learn a small amount about C++ templates and C++ exceptions, just enough to understand the exercise.
The answers are intentionally placed on a new page (remember to try before you read further!).
Run each of the three files
Copy the file
Repeat this for the other two files ending in
In
In
In
In
In
In
In a typical HEP experiment is often necessary to repeat one analysis several times, with each version differing only in the values of some cuts; this is frequently done to tune cuts or to study systematic errors. Very often it is both convenient and efficient to run all of the variants of the analysis in a single job.
A powerful feature of
The prerequisite for this chapter is all of the material in Part I (Introduction) and the material in Part II (Workbook) up to and including Chapter 14, but excluding Chapter 13.
In this chapter you will learn how to run an
The source code for the first module you will run is
The source code for this exercise is found in the file
The FHiCL file used to run this exercise is
In your build directory, run the following command
The expected output from this command is shown in Listing 15.1; for clarity, the printout made
by
As it happens,
Therefore
For producer modules, which may add information to the event, the order of execution is often very important. When you reach the exercises that run producer modules, you will be told how to specify the order of execution.
You may wish to review some of the other ideas about
In the preceeding discussion, the name
Clearly these two meanings are very closely related, which is why the same name,
After working through this exercise, you should:
Remember to switch from your source window to your build window as you edit files and run
Edit
Then re-run
Do you see the expected additional printout?
Now run the configuration with the intentional errors.
This will run but produce an error. There are two bugs. When you fix the first one and rerun, a new one will pop up. Your job is to figure out each problem, in turn, and fix it.
The answers are intentionally placed on a new page (remember to try before you read further!).
For the first activity, you must add a new analyzer module label to
After you run the
Running
The
Notice the
Section 10.6.3.6 described the class
Prerequisites for this chapter include all of the material in Part I (Introduction) and the material in Part II (Workbook) up to and including Chapter 14.
You must also be familiar with the toy experiment described in Section 3.7.
This exercise will use class templates and member function templates in several places. The use
of templates was introduced in Section 14.6. Recall that a class template is a set of rules for
creating a class and that a member function template is a set of rules for creating a member
function. You need to know how to use templates but you do not need to know how to write one.
You will need a minimal understanding of the class template
In this exercise you will learn about:
The input files used for the
In this exercise you will retrieve this data product and print the number of generated particles
in each event.
Each generated particle in the simulated event is described by an object of type
The header files that describe these two classes,
The content of
1 # include ~ toyExperiment / MCDataProducts / GenParticle . h ~ 3 # include < vector > 5 namespace tex { 7 typedef std :: vector < GenParticle > GenParticleCollection ; 8 } 9
Why did the authors of the workbook decide to use a typedef and not simply ask you to
code
Please use the typedef
Why did the authors of the workbook decide to call this typedef
The generic name
Each
Each data product name must be unique within an
In particular, periods, dashes, commas, underscores, semicolons, white space and single colons are not allowed; underscores are only allowed as the field separator, not within a field.
The friendly name of a data type is a concept that
The full set of rules is given in the Users’ Guide.
Corollaries of the above discussion include:
To identify a data product,
To tell
The header for
You can construct an input tag by passing it a string with the three fields separated by colons,
e.g.,:
For this exercise, the full specification of the input tag includes only the module label and the process name:
The double colon indicates that the instance name (which would come between the colons) is an empty string. The process name rarely needs to be specified, and in fact it is not needed in this exercise. It will be sufficient to specify the input tag as
There are other constructors for
The input files used for this exercise contain data products, one of which this exercise will use. This data product has the following attributes:
In this exercise you will run three modules that differ in only a few lines. The three source files
use different syntax to accomplish the same thing. Most of the subsequent exercises in the
workbook will use the syntax shown in the third version,
You will run the exercise from your build directory in your build window. To run this exercise,
This will make the usual
The module
1 # include ~ toyExperiment / MCDataProducts / GenParticleCollection . h ~ 3 # include ~ art / Framework / Core / EDAnalyzer . h ~ 4 # include ~ art / Framework / Core / ModuleMacros . h ~ 5 # include ~ art / Framework / Principal / Event . h ~ 7 # include < iostream > 8 # include < string > 9
In the next portion of the file, notice the new data member
9 namespace tex { 10 class ReadGens1 : public art :: EDAnalyzer { 12 public : 13 explicit ReadGens1 ( fhicl :: ParameterSet const & ); 14 void analyze ( art :: Event const & event ) override ; 16 private : 17 art :: InputTag gensTag_ ; 18 }; 19 } 20
Notice two things in the remainder of the file, below: Lines 26-27 introduce the concept of a
20 tex :: ReadGens1 :: ReadGens1 ( fhicl :: ParameterSet const & pset ): 21 art :: EDAnalyzer ( pset ), 22 gensTag_ ( pset . get < std :: string >( ~ genParticlesInputTag ~ )){ 23 } 24 void tex :: ReadGens1 :: analyze ( art :: Event const & event ){ 26 art :: Handle < GenParticleCollection > gens ; 27 event . getByLabel ( gensTag_ , gens ); 29 std :: cout << ~ ReadGens1 :: analyze event : ~ 30 << event . id (). event () 31 << ~ GenParticles : ~ 32 << gens -> size () 33 << std :: endl ; 34 } 36 DEFINE_ART_MODULE ( tex :: ReadGens1 ) 37
As you work through the
The handle is an example of a broader idea sometimes called a
The header for the class template
The
The following line calls
When this line is executed, the event object looks to see if it contains a data product that matches the request. There are three possible outcomes:
In the first case, the event object will give the handle a pointer to the requested
If the event object finds exactly one match, it will also add two pieces of metadata to the handle.
One is a pointer to an object of type
The third case bears one more comment: the developers of
If the
In all cases but one,
It is possible to test the state of
In the preceding discussion we did not mention that
The
It is different from the previous dynamic libraries that are explicitly
This library contains the object code for the classes and functions defined in the
Here we will call it a
Adding this library to the link list required a one-line modification to
The string
There is only one fragment of
On line 4 of this fragment, the parameter
We recommend that you always initialize input tags using parameters from the parameter set and that you never initialize them using strings defined within the code. This will allow you run the same module on data products with different input tags; this is a widely used feature.
We further recommend that you not provide a default value in the call to get the parameter value from the parameter set. This derives from a general recommendation that parameters affecting physics output should never have default values; the only parameters with default values should be those that control debugging and diagnostics.
Version 2 of this exercise consists of the files
It will produce the same output as the previous two versions.
The only significant change from version 1 to version 2 is that lines
1 art :: Handle < GenParticleCollection > gens ; 2 event . getByLabel ( gensTag_ , gens ); 3
have been replaced by the single (long) line:
1 art :: ValidHandle < GenParticleCollection > gens = 2 event . getValidHandle < GenParticleCollection >( gensTag_ ); 3
This version is a little verbose but that aspect will be addressed in version 3. Note
that the class template
The above line has functionality very similar to that of the two lines from version 1: the net
result is that
However, there are several signficant differences between
Unlike an
Version 3 of this exercise consists of the files
It will produce the same output as the previous two versions.
The only change from version 2 is that the call to
1 auto gens = 2 event . getValidHandle < GenParticleCollection >( gensTag_ ); 3
This version uses a feature of C++ that is new in C++-11, the keyword
When you call the member function
Version 3 is the version that we recommend you use but you can use any of the three. We
introduced the version using the keyword
In future exercises we will use the pattern of version 3 regularly.
Edit
Run
Edit
Run
You would also get an error if
Observe that for each event
Look at the last line of the
You can reconfigure
This line tells
In this chapter you have learned:
Two source files and one FHiCL file are provided that contain intentional bugs. Your job, of course, is to find the bugs and fix them. The answers are provided in Section 16.12.2.
The source files listed below fail to build. Follow essentially the same procedure as outlined in
Section 10.12 on each of these files. To run them in
What’s with the
The FHiCL file
For the file
As the error message indicates, the error is indeed in the line:
Remember that
More generally, the syntax
For the file
The problem here is that the constructor of an analyzer module must pass the parameter set to the
constructor of
To make the build work, fix the constructor to look like
1 tex :: ReadGensBug01 :: ReadGensBug01 ( fhicl :: ParameterSet 2 const & pset ): 3 art :: EDAnalyzer ( pset ), 4 gensTag_ ( pset . get < std :: string >( ~ genParticlesInputTag ~ )){ 5 } 6
Now it should work fine.
Finally, run
The parameter value for
One of the workhorse tools of HEP data analysis is ROOT. Among its many features
are tools for data analysis, visualization, presentation and persistency. As was
discussed in Section 3.6.9,
This exercise will show you how to use ROOT in the
Detailed information about ROOT is available from its website,
http://root.cern.ch/drupal.
Most of the modules that get run in a typical
All user interactions with ROOT should happen via this service.
Note that is possible to use ROOT as an event-processing framework, e.g., the AliRoot
framework used by the ALICE Collaboration. But if you are using
Prerequisites for this chapter include all of the material in Part I (Introduction) and the material in Part II (Workbook) up to and including Chapter 16.
In this exercise you will learn:
The module
The FHiCL file
The file
The file
The C++ source code for this exercise is found in the file
The name
The
1 # include ~ toyExperiment / MCDataProducts / GenParticleCollection . h ~ 3 # include ~ art / Framework / Core / EDAnalyzer . h ~ 4 # include ~ art / Framework / Core / ModuleMacros . h ~ 5 # include ~ art / Framework / Principal / Event . h ~ 6 # include ~ art / Framework / Services / Optional / TFileService . h ~ 8 # include ~ TH1D . h ~ 10 # include < iostream > 11 # include < string > 13 namespace tex { 15 class FirstHist1 : public art :: EDAnalyzer { 17 public : 19 explicit FirstHist1 ( fhicl :: ParameterSet const & ); 21 void beginJob () override ; 22 void analyze ( art :: Event const & event ) override ; 24 private : 26 art :: InputTag gensTag_ ; 28 TH1D * hNGens_ ; 30 }; 32 } 33
The two new headers can be found at:
The conventions for including header files from ROOT differ from those for including header
files from
When ROOT was developed, namespaces were not supported robustly by many C++ compilers. Therefore a different set of conventions were adopted – and remain – for ROOT:
Listing 17.2 shows the implementation section of the file
1 tex :: FirstHist1 :: FirstHist1 ( fhicl :: ParameterSet const & pset ): 2 art :: EDAnalyzer ( pset ), 3 gensTag_ ( pset . get < std :: string >( ~ genParticlesInputTag ~ )), 4 hNGens_ ( nullptr ){ 5 } 7 void tex :: FirstHist1 :: beginJob (){ 9 art :: ServiceHandle < art :: TFileService > tfs ; 10 hNGens_ = tfs -> make < TH1D >( ~ hNGens ~ , 11 ~ Number of generated particles per event ~ , 12 20, 0., 20.); 14 } 16 void tex :: FirstHist1 :: analyze ( art :: Event const & event ){ 18 auto gens = 19 event . getValidHandle < GenParticleCollection >( gensTag_ ); 21 hNGens_ -> Fill ( gens -> size ()); 23 } 24
The new features in this listing are:
The identifier
We strongly recommend, first, that you use
Section 3.6.5 discussed the idea of
In a similar way that access to data products is provided by the class templates
Once a service handle has been constructed, the downstream code can use the service handle as a
pointer to the pointee, i.e., to
The header file for
It is automatically included by one of the files that are already included in
Lines 9 through 12 of Listing 17.2,
9 art :: ServiceHandle < art :: TFileService > tfs ; 10 hNGens_ = tfs -> make < TH1D >( ~ hNGens ~ , 11 ~ Number of generated particles per event ~ , 12 20, 0., 20.); 13
use
In the case of creating a
ROOT defines that the low edge of a bin is within that bin, while the upper edge of a bin is part of the next bin up. Therefore the lower edge of the lowest bin is inside the histogram but the upper edge of the uppermost bin is outside of the histogram.
If you would like to learn more about the
Where is the histogram created? The histogram is created in memory that is owned
and managed by ROOT. ROOT also knows that when the job is finished, it should
write the histogram to a ROOT output file that you can inspect at a later time. The
name of the output file is specified in the FHiCL file for the
Just as file systems have the notion of directories and subdirectories (or folders and subfolders if
you prefer), a ROOT file has the notion of directories and subdirectories that are internal to the
ROOT file. If a module makes at least one histogram, then the
Recall that within a given
Line 21 of Listing 17.2
21 hNGens_ -> Fill ( gens -> size ()); 22
fills the histogram pointed to by
If you look up the function prototype for
All of the comments above about management of ROOT directories and writing histograms to
files are also true for most other sorts of ROOT objects. In particular they are true for
If you think carefully about
If you talk to an HEP old-timer about creating histograms, he or she will probably call it “booking a histogram.” This is language left over from a precursor to ROOT named HBOOK.
Both the histogram files (output) and the
In order to make it clear which ROOT files are of which type, the
Some experiments, Mu2e, for example, have adopted the same convention. Other experiments have
chosen that event-data files always end in
The file
The most important new feature is at line 12,
which configures the
If this parameter is missing, or if the configuration for the
Unlike in the previous excercises, the FHiCL file runs on the large input event-data file,
The
The two new link libraries are specified by
and
Many projects use the convention that files ending in
You do not need to understand the details of how the
This module does not make any of its own printout. You should see the standard printout from
You should see that the
In this section you will inspect the file
First, look again at
To inspect the histogram you will remain in your build directory and you will run the interactive
ROOT program, using the command
In step 4 you should have recognized the name of the folder,
About the
Now look at the histogram in the right hand panel of the TBrowser window. In the statistics box
on the upper right you should see that it has 1000 entries, one for each event in the input file. You
should also notice that only the odd bins are populated: this is because the generated events
always contains three signal particles, plus a random number of pairs of background particles
(
The above description for viewing a ROOT file interactively requires a lot of tedious typing at
step 2. The toyExperiment UPS product provides a command named
Then follow the instructions from the previous section, starting at step 3.
When you created your
where
When you type a command at the
It is a common convention that files that contain CINT scripts have a file type of
This exercise provides an example of a CINT script,
To use this script, run:
This will open a window on your display, draw the histogram in that window and save the
window to the PDF file
Appendix D has instructions on how to view the PDF file interactively. For those of you at Fermilab, it also has instructions on how to print the PDF file.
If you compare this figure to the histogram in Figure 17.2 you will see that there is difference in the statistics box in the upper right. In this figure, the name of the histogram is not shown but three new fields are: the number of entries below the lower limit (Underflow), the number of entries above the upper limit (Overflow) and the number of entries between the limits (Integral). The field named “Entries” is the sum of Integral plus Underflow plus Overflow.
It is beyond the scope of this writeup to describe all of the features in Listing 17.5, but we will describe some of the code.
Regarding lines 9 and 12, we will let comments in the code be a guide, and give two additional
hints. The object
Line 17 tells ROOT what to draw in the statistics box in the upper right of every histogram. The
comments in the code describe the mnemonics of the letter codes. The full set of letter codes is
described on the ROOT web site: http://root.cern.ch/root/html534/TStyle.html as part of the
documentation for the member function
Line 20 opens the input file. The ROOT type
Line 23 has two statements on it. The first declares
Line 26 tells ROOT to open a new window on your display. The first argument is an arbitrary name that must be unique within the job; ROOT uses it internally to differentiate multiple canvases. The second argument is the title that will be drawn on the title bar of the window.
Line 29 tells ROOT to draw the histogram on the canvas. If, at line 21, ROOT was unable to properly set the pointer, then this line will produce an error message and return control to the root prompt in the build window.
Line 31 tells ROOT to flush its internal buffers and make sure that everything that is in the queue to be drawn on the canvas is actually drawn.
Line 33 tells ROOT to save the canvas by writing it to the file specified as the function argument.
The format in which the file will be written is governed by the file type field in the filename,
The main ROOT web site is http://root.cern.ch/drupal. On the top navigation bar there is a title
labeled
One possible starting point for learning ROOT is the ROOT Primer. You can find it by first going
to the User’s Guide page or you can follow the direct link:
http://root.cern.ch/drupal/content/users-guide#primer
One of the most useful parts of the ROOT documentation suite is the Reference Guide, which can
be reached from the pull down menu. The direct link to this page is:
http://root.cern.ch/root/html534/ClassIndex.html
This section has a description of all of the members in each ROOT class.
Suppose that you run
It is your responsibility not to overwrite files that you wish to keep. One way to keep a file that is
valuable is to use the unix
To restore the file to a writeable state the unix command is:
You can change the name of the histogram file by editing the FHiCL file but you can also do so
from the
In
You can use the
In this exercise you have learned:
Two source files and one FHiCL file are provided that contain intentional bugs. Your job, of course, is to find the bugs and fix them. The answers are provided in Section 17.12.2.
The source files listed below fail to build. Follow essentially the same procedure as outlined in
Section 10.12 on each of these files. To run them in
Next, run
The answers are intentionally placed on a new page (remember to try before you read further!).
When you run
The cause of the problem is that
private : ... TH1D * hNGens_ ;
When you run
The solution is to replace the dot in the
hNGens_ -> Fill ( gens -> size ());
When you try to run:
you will obtain the following error message:
To fix
In Chapter 16 you learned about the data product that describes all of the particles in a generated
event. It has a type of
Prerequisites for this chapter include all of the material in Part I (Introduction) and the material in Part II (Workbook) up to and including Chapter 17.
In this exercise you will learn:
The main body of the exercise consists of the files
This chapter discusses the data product
The header file and the source file can be found at:
Open the files to follow along with the discussion.
The header file
The PDG in the name of first header file refers to the
http://pdg.lbl.gov/2007/reviews/montecarlorpp.pdf
The Workbook includes a class that declares and initializes a small subset of the PDG codes, only
those that are of interest to the toy experiment. It does so by way of an
The only content of this class is the enum that defines mnemonic names for each code. By using
the mnemonic names instead of the integer codes, your code will be understandable by people
who do not have all of the codes committed to memory. To use one of the codes in the
Workbook, you need to give its full name; for example, use
The class templates from the next header files,
The header files
You can find specific discussions about
The last of the six newly introduced headers is
One of the important notions in many HEP event generators is that some particles are created by a primary interaction; these are called primary particles. Other particles are created by the decay of one of the primary particles or by the interaction of one of the primary particles with material in the experiment; these are called secondary particles.
Therefore one of the ideas encoded in a
The first element of the class declaration for
This type is a collection of smart pointers that allows you to find the children of a given
The
which is the default, and another that declares a few data members:
It also has some private member functions with access to them provided by (public) accessor functions; accessors are discussed in Section 6.7.7. The accessor functions are given in Table 18.1.
The public interface has one non-const member function that is used to add a child particle to a
This member function will not be discussed here but it will be discussed
Finally there is a do-nothing definition of operator less-than; this is required to work around a
bug in a tool named
The member function
The member function
As was described in Table 3.2, the position is given in mm and the 4-momentum is given in MeV.
The member function
The member function
that returns the size of the collection, which corresponds to the number of children of the
The member function
The member function
You will notice that the implementations of the member functions
makes the programmer’s intent manifest, while coding
requires that the reader draw some context-dependent inferences to understand the programmer’s intent.
The remaining two member functions have to do with parent-child navigation and will be
described in Chapters
In
.
The final part of the public interface comes after the declaration of the class.2 It is the free function, called the stream insertion operator:
If
ROOT has a tool called
This module has some new features.
Listing 18.2 shows the loop over the generated particles, found in the
The simple picture of this range-based for loop is that the body of the loop will be executed once
for each element in the collection specified by the expression to the right of the colon. On the
first pass,
Had the first line of the loop been written,
The code would have compiled and it would have produced the correct results. However, on each
pass of the loop,
Why is there a
What sort of collection types may be on the right-hand side of the colon? Any standard libary collection type is allowed. User-written collection types may also be used.
The first two lines of the body of the loop are
Recall that a reference behaves like a compile-time alias; therefore there is no run-time cost for these lines to be present. The code is written this way because the author thinks that it makes the loop body easier to read.
The last two lines of the loop body fill the histograms with the requested information. If
you are not familiar with the accessor member functions of
As a last comment, the line that defines the variable
While this version makes the intent more explicit, and perhaps makes it a little easier to understand, it also forces an unnecessary copy. So the authors of the Workbook elected to choose the more efficient, albeit more obscure, variant.
The file
The last step will make a figure like that shown in Figure 18.1. It will also write the figure to the
file
For those of you at Fermilab, it also has instructions on how to print the
The file
The main reason for showing this variation is to advocate for writing code in more small
functions rather than in fewer larger functions. In this example the body of the loop is short and
there is little benefit from abstracting it into a function. However, if the body of the loop is long,
then there is a real benefit in doing so — it allows the reader of the
The loop body should be abstracted into a function if it meets any of the following criteria:
To run this variation of the exercise, do the following in your build directory:
This will produce a page of histograms that should be identical to those made by
Regarding the second item on the list, when a type is as simple as
Regarding the third item on the list, the Workbook authors felt it would be confusing to use this
form before showing you the first form. However, from now on we will use this form to get a
const reference to its 3-momentum from a
The file
This module makes seven histograms of the momentum spectrum of the generated particles. The first is made using the familiar range-based for loop and is provided for reference.
The second method uses operator square brackets:
Recall that the type of
The third method uses the
The member function
If you use the operator
We strongly recommend that, when possible, you use a
The fourth method uses iterators:
An iterator behaves like a pointer to the selected element. If you wish to learn about iterators, consult any standard C++ reference.
The fifth method also uses iterators:
Here we have used the
This is the first time in the Workbook that using
We recommend the fifth method over the fourth method. In the fifth method, the scope of
the loop iterator
The sixth method introduces the comma operator:
Finally, the seventh version uses the
The benefit to using this form only appears if you are writing templates — so whereas you are unlikely to use it yourself, you may see others using it.
The C++ language also supports
The bottom line is this: if a
To run this variation of the exercise, do the following in your build directory:
This will make two files of histogram output:
Each file will show a
You can inspect the file
In
In
You might find it easier to understand the second version if you break it into two steps:
Note that both blocks of code end by defining a variable named
In the remainder of the member function
In this exercise you have learned:
Test 1 asks you to write a module. For tests 2 and 3, files are provided that contain intentional bugs. Your job, of course, is to find the bugs and fix them. The answers, provided in Section 18.11.4, are intentionally placed on a new page.
In this assignment you will write your own module class and FHiCL file, build your module, run
Create your new
In your new module file, extend
For each generated particle print to
Add a parameter set parameter to limit this printout to a number of events specified in the parameter set. The default should be for no printout.
When you are ready to build your module, go to your build directory and give the
command:
This will compile your module and link it into a shared library.
Prepare a FHiCL file to run this module on the file
To run your module, go to your build directory and give the command:
When you are done, you can compare your solution to that given in the files
Compare the printout made by
The first line of printout, when split over two lines, will look like:
The printout for each
You can inspect the printout to see that only five different PDG Id codes occur:
To help compare histograms you can make a multipage PDF file containing all of the reference
histograms with the command:
This will make a file named
Appendix D has instructions on how to view a multipage PDF file interactively.
For those of you at Fermilab it also has instructions on how to print it using the Fermilab printers.
You can also study the file
In the source directory for this exercise there are three files that end in
The source files listed below fail to build. For each in turn, follow essentially the same procedure as outlined in Section 10.12.
For
When you have found and fixed the error in
If you have trouble finding the error and wish to try one of the other files, rename the
The code in
Navigate to the histogram
In
The declaration to the left of the colon should be a const reference, not a non-const reference.
The underlying reason for this is that the
This error message is shown here on two lines for readability.
In
This time the error is that the
However the caret does correctly indicate where to look for the error. Again, the error message is shown here on two lines for readability.
In
The error is that the type of
An inferior solution would be to remove the ampersand and make
In
The issue is that both
The prefered solution is write the code the way that
This makes it clear that we want to call the
Most high energy physics experiments have some form of an
This chapter will describe a 3D event display for visualizing the detector geometry,
simulated hits, and simulated tracks of the toyExperiment. It was built using ROOT’s
GUI and EVE classes in an
Detailed information on the ROOT GUI and EVE classes can be found starting from the ROOT Reference Guide page, http://root.cern.ch/drupal/content/reference-guide.
Additional information for the ROOT GUI classes can also be found in the ROOT User’s guide, http://root.cern.ch/drupal/content/users-guide.
There is also a ROOT page dedicated to EVE, http://root.cern.ch/drupal/content/eve, where there are references to presentations and write-ups on EVE from conference proceedings.
Prerequisites for this chapter include all of the material in Part I (Introduction) and all of the
chapters in Part II (Workbook) up to and including Chapter
In this chapter you will learn:
If your are logging in after having closed an earlier session, follow the instructions in Chapter 11. If you are continuing on directly from the previous exercise, keep both your source and build windows open.
To start up the event display, run the following command in your build directory:
.
This brings up a TEveBrowser which is a customized version of the ROOT TBrowser for
ROOT’s Event Visualization Environment (EVE). The first thing you will notice is
that the TEveBrowser used in this exercise, which is shown in Figure 19.1, looks
just like a TBrowser except for some key differences which will be described next.
On the left hand side are three tabbed panes, which will be referred to collectively
here as the control panel. Aside from the usual
Clicking on the
Expanding the first top-level item in the list-tree labeled
As shown in the expanded list-tree widgets in Figures 19.4a and 19.4b, each view contains two
separate scenes (ROOT
Expanding each of the second-level items under
The fourth and last top-level item in the list-tree widget is labeled
One last thing to note about the list-tree widget is the presence of a check box preceding the item label. This box is used to toggle the visibility of the graphical representation associated with the item in the appropriate scenes shown in the main EVE display area.
Directly below the list-tree widget, in the same
As a second example, select one of the leaf items representing a generated track under the
Let us skip the second tabbed pane labeled
Having covered the event-navigation panel in some detail, let us now move on to the
right hand side of our TEveBrowser. Skipping the ROOT command console in the
bottom, which is identical to that in a generic TBrowser, let us focus our attention
on the main EVE display area which was briefly introduced in Section 19.5.1. As
described previously, this area has two tabbed panes labeled
In the viewports of a tabbed pane, you will also notice a title bar at the top with the words
You may have noticed that hovering your mouse cursor over an element in the dynamic
event-type scenes (as opposed to static detector-type scenes), such as one representing a
generated track and hit, highlights that particular element. It also pops up a text box, known as
The 3D event display module in this workbook excercise is an
The event display service used in this exercise is a much simplified version of the one used in the
NOvANO
With
For our discussion of the source code for the event display module, refer to the following file in the art-workbook source directory:
At the top of this file, you will find the included headers arranged according to package.
Following the includes for
Coming after the section containing the included headers, is an anonymous namespace with
helper functions for (1) setting the transparency and color of drawn detector components, and (2)
drawing generated hits. This is followed by the declaration of the
Starting at around the middle of the file, is the source code for the
Let us now take a closer look at the code, beginning with the class declaration shown
in Listing 19.1. The constructor and
On lines 24-25, we declare the
Pointers to the viewers associated with the 2D
Shown in listing 19.2 is the code implementing the constructor of the
In the code overview of Section 19.6.1, we mentioned that one-time tasks, such as starting up the
EVE manager and drawing detector components, are done in the
Referring to Listing 19.3, the very first thing done, on line 5, is to start up the EVE central
application manager. More precisely, this line checks whether the pointer,
These values are passed to the constructor for
The number of
Since one
From the discussion above, we see that line 5 of Listing 19.3 actually does quite a bit of work
for us by providing us with a browser with an initial set of widgets that include object and file
browsers, a 3D viewer, and a command line console. With all of these tasks taken care of by
EVE, we can immediately focus our attention on visualizing the detector components. This is a
straightforward task which, essentially, only requires providing EVE with a description of the
detector geometry through the EVE manager’s
Having created the default GUI and drawn the detector components, we will now look at extending the event display by adding multiview orthographic projections and an event-navigation panel.
The two views we will create are:
Referring to Listing 19.4, we begin by creating two new scenes for each of these views in
lines 7 through 10. The two arguments passed to the
Let us now look at lines 14 through 16. The first line creates a projection manager of
type
On lines 24 through 43, we create viewers for the orthographic scenes and projection managers
constructed above. The first two lines declare and initialize pointers used in the code. On the next
line, we use a static helper function which creates an empty window slot in the tab widget in the
right main area, and returns a pointer to it. This tab widget is specified by using the
EVE browser’s
On line 33, we insert the first frame in our horizontal stack of frames and select it as the current
window. The next line then gets the current window as an empty slot, creates a GL viewer, and
embeds it in the window slot. The first argument passed to
Moving on now to Listing 19.5, on lines 6 and 7, we use the projection manager object’s
The last few lines in
The
On the next two lines, we create a horizontally aligned and a vertically aligned composite
sub-frame having the top-level frame (
The buttons described above allow us to step through events sequentially, one at a time, in the
forward or backward direction. The next few lines of the code we will discuss create text entry
widgets that allow us to navigate directly to an event by entering its run and event numbers. We
start by creating a horizontally aligned frame for the run number text entry widget on line 37 of
Listing 19.6. We wish to label this widget with the text
Moving on to Listing 19.7, the text entry widget is created on Line 5. The first argument to the
constructor is a pointer to the horizontally aligned frame serving as the parent widget. We create
a 5-character text buffer to hold the string for the value of the run number and point the
The steps described above for the run number text entry widget are repeated on
Lines 14 through 25 for the event number text entry widget. On Lines 28 and 29,
we stack the run and event number widgets up on top of each other by making them
children of the vertically aligned frame created earlier (
The call to
The previous sections dealt with setting up the static components of the event display. This
section will deal with the components associated with an event and which change from event
to event. These components, which include run and event numbers, and generated
hits and tracks, are created or updated in the
Before we begin drawing the generated hits and tracks, we first delete any non-global elements
associated with the previous event, such as the generated tracks and hits, and interactively added
annotations. Line 19 gets the list of all the GL viewers associated with the current EVE manager
and deletes all the overlay elements in each viewer that are annotations. The next line deletes
all the non-global elements that were previously added through the EVE manager’s
With our viewers and list-trees cleared of old structures, we can now draw the generated hits for
the current event. In Listing 19.9, after setting up a handle pointing to the
On Lines 19-21, we create separate containers for hits originating from
The code to draw the hits is implemented in the
Let us now look at how generated tracks are drawn in Listing 19.11. As for the generated hits,
we begin by setting up a handle to point to the
On Line 19, we get the track propagator object associated with the track list. This is used to
calculate the path of the track for a given magnetic field. In the following lines, we specify the
magnetic field, the maximum extents of the track in the radial and
Once the propagator is set up, we loop over the generated tracks in our collection, skipping those
that have decayed. We first construct a
Continuing with the track loop on line 5 in Listing 19.12, we assign a color for each track
based on its particle identity. At the end of each iteration through the loop, we add
the track to the list of tracks pointed to by
At the very end of the
If the remote machine that you log onto to run the Workbook exercises runs into problems during the setup procedure, it’s possible that the admin for that machine has not installed the most recent versions of the Workbook code, or some dependent code. Contact the administrator.
The XWindows products, xterm, xclock and so on, likely reside in the directory
At Fermilab, open a service desk ticket at
If the buildtool doesn’t seem to find your module, check that it can see it:
Make sure it’s not some other module that’s causing the build failure.
Make sure you’re in your build window
Make sure the path to the FHiCL file is correct, e.g.,
The source code for the exercises in the
If you want some background on
You will need to know how to install
To install
This will automatically download a disk image. Open the disk image and click on the .pkg file.
In your home directory, edit the file .bash_profile and add the line:
and how to download updates as the developers make them:
To bring your working copy of the workbook code up to date, you need to use
At any given time, there are three copies of the code that you need to be aware of, the central repository, your local clone of the central repository and the working copy of the code in your source directory.
There are two other source code managment systems that are widely used in HEP,
To bring your working code up to date you need to do two steps:
The discussion of the checkout has several cases. Each is discussed in one of the following sub-sections. It is possible for all four of these cases to occur on any given checkout.
When you worked on Exericse 2, you added some files to your working directories; for example
you added the files
You do not need to take any action; just be aware of the situation.
Another case occurs for files that have the following properties:
For example, suppose that you modified
In this case, the checkout command will issue a warning message to let you know that your working version contains changes that are not part of the release you checked out.
You do not need to take any action; just be aware of the situation.
Another case occurs for files that have the first two properties from the list in Section 21.1.1.2 but which have been modified in the central repository since you cloned the repository. This will happen from time to time when when we update exercises based on suggestions from users.
When this happens there are two cases, one of which is discussed here, while the other is discussed in the next sub-section.
If the two sets of changes (yours and those in the repository) are on different lines of the file
It is your repsonsibility to identify these cases, understand the changes made in the repository
and understand if
The final case is a variant of the previous case; it occurs when
The art-workbook has been designed so that this should happen very, very rarely. Most readers should bookmark this spot for future reference and only read it when they need to.
Fortunately, to use the workbook you do not need to know very much about branches; all that
you need to know is summarized in Figure 21.1, which shows a simplified view of the way that
the art-workbook team uses
In Figure 21.1 time starts at the bottom of the figure and runs upward. The art-workbook team
has adopted the convention that the most up to date version of the art-workbook code will always
be found by checking out a branch named
At the earliest time represented in Figure 21.1, the develop branch existed in some state that the
art-workbook team liked. So they tagged the develop branch with the name
This is illustrated in Figure 21.1 by the blue line labelled
In Figure 21.1 the red line labelled
In this example, the development team decided to tag the develop branch after the
The next items on the figure are the branches named
After this, the develop branch is again tagged, this time with a version named
The next items on the timeline are the branches named
Finally, the develop branch is tagged one more time, this time with the name
In Figure 21.1 consider a time when both branches
Fortunately, to use the workbook you do not need to know very much about branches. You really need to know only two things.
This is a bit of simplification but it captures the big ideas. Users of art-workbook should always work with one of the release branches; and they should always consult the documentaion to learn which version of the code is matched to that version of the documentation.
Users of the art-workbook should never work in the develop branch; at any given time that branch may contain code that is still under development.
At any time you can check to see which files you have modified and which you have added. To
do this,
You should not issue the
In the rare case that you have neither modified nor added any files, the output of
Your
Figures 22.1, 22.2 and 22.3 show the elements of the run-time environment in various scenarios, and a general direction of information flow for job execution.
When you are running
They are colon-separated lists of directory names. When you type a command at the command prompt, or in a shell script, the (bash) shell splits the line using whitespace and the first element is taken as the name of a command. It looks in three places to figure out what you want it to do. In order of precedence:
Some parts of the run-time environment will be established at login time by your login scripts. This is highly site-dependent. We will describe what happens at Fermilab - consult your site experts to find out if anything is provided for you at your remote site.
When running the workbook, the interesting parts of your environment are established in two steps:
The Workbook, and the software suites for most IF experiments, are designed so that all site dependence is encoded in the site-specific setup script; that script adds information to your environment so that the project-specific scripts can be written to work properly on any site.
The development environment includes the run-time environment in Section 22.1 plus the following.
Figures 22.4, 22.5 and 22.6 illustrate the development environment for various scenarios.
In some experiments the run-time and development environments are identical.
It turns out that there is no perfect solution for the job that build tools do. As a result, several different tools are widely used. Every tool has some pain associated with it. You never get to avoid pain entirely but you do get to pick where you will take your pain.
The workbook uses a build tool named
This chapter describes all the parameters currently understood by the
The parameters are described in tables for each module. The type of a defined parameter may be:
The expected structure of an
Note, any parameter set is optional, although certain parameters or sets are expected to be in particular locations if defined.
These services are always loaded regardless of whether a configuration is specified.
These parameters control the behavior of floating point exceptions in different modules.
| | | | |
| | | | |
| | | |
|
| | | |
|
| | | | |
| | | |
|
| | | |
|
| | | |
|
| | | |
|
These parameters configure the behavior of the message logger (this is a pseudo-service – not accessible via ServiceHandle).
| | | | |
| | | |
|
|
|
|||
These services are only loaded if a configuration is specified (although it may be empty).
Output modules
Run-time configuration for
By convention, the names of FHiCL files end in
See Figure 22.1 in Section 22.1 to see how the configuration file fits into the run-time environment.
The FHiCL concept of
A FHiCL file contains a collection of definitions of the form
where “name” is a parameter that is assigned the value “value.” Many types of values are possible, from simple atomic values (a number, string, etc., with no internal whitespace) to highly structured table-like values; a value may also be a reference to a previously defined value. The white space on either side of the colon is optional. However, to include whitespace within a string, the string must be quoted (single or double quotes are equivalent in this case).
The fragment below will be used to illustrate some of the basics of FHiCL syntax:
Several identifiers, characters and strings are
The following characters, including the two-character sequence ::, are reserved to FHiCL:
The following strings have special meaning to FHiCL. They can be used as parameter values to pass to classes, e.g., to initialize a variable within a program, but their uses will not be fully described here because of subtleties and variations. As you work with C++ and FHiCL, the way to use them will become clearer.
The first six strings (three lines) above function as identifiers reserved to
FHiCL supports run-time configuration for several projects, not only for
if they define a list of modules or a processing block, or with square brackets
if they define a list of paths.
The following is a list of the identifiers reserved to
The following may appear within the
The last two elements specify which of the modules will be executed in an
The identifier
Here is a sample FHiCL file called
Let’s look at it step-by-step.
Similar to C++ syntax, this effectively replaces the ‘#include’ line with the contents of the named file. This particular file sets up a messaging service.
The value of the parameter
This
Here RootInput is used; the data input file, in ROOT format, is assigned to the variable
Note that if no source parameter set is present,
See the web page about configuring input and output modules for details about what other parameters may be supplied to these parameter sets.
Before starting processing, this puts the message logger in the recommended configuration.
In
The
We will expand on the
In FHiCL files there are very, very few places in which order is important. Here are the places where it matters:
Here is a list of
Regarding trigger_paths and end_paths, the following is a conceptual description of how
A conceptual description for the porcessing of services is as follows:
For a module label you may choose any name, as long as it is unique within a job, contains no
underscore (_) characters and is not one of the names reserved to
The minimum configuration of a module is:
for example, in our code above:
Let’s take this a step farther, and assume that this EDProducer-type module MakeA
accepts four arguments that we want to provide to
This list under
Note that
For a module label or a path name, you may choose any name so long as it is unique within a job,
contains no underscore (_) characters and is not one of the names reserved to
Any name that is a top-level name inside of the
It is important to recognize which identifiers are module labels and which are path names in a FHiCL file. It is also important to distinguish between a class that is a module and instances of that module class, each uniquely identified by a module label.
Analyzer modules and the output modules may be separated into different paths; that might be convenient at some times but it is not necessary. On the other hand, keeping trigger paths separate has real meaning.
A set of scheduling rules is enforced in
The full description of the scheduler strategy is given below:
In the above there is a lot of focus on which groups of modules are free to be run in an arbitrary
order. This is laying the groundwork for module-parallel execution:
For simple cases, in which there is one trigger path with only a few modules in the path, and one end path with only a few modules in the path, the extra level of bookkeeping is just extra typing with no obvious benefit. The benefit comes when many work groups wish to run their modules on the same events during one art job; perhaps this is a job skimming off many different calibration samples or perhaps it is a job selecting many different streams of interesting Monte Carlo events. In such a case, each work group needs only to define their own trigger path and their own end path, without regard for the requirements of other work groups; each work group also needs to ensure that their paths are added to the end_paths and trigger_paths variables. Art will then automatically, and correctly, schedule the work without redoing any work twice and without skipping work that must be done. This feature came for free with art and, while it imposes a small burden for novice users doing simple jobs, it provides an enormously powerful feature for advanced users. Therefore it was retained in art when some other features were removed.
Consider the following problem. You wish to run a job that has:
Here is code that would accomplish this:
Recall that the names process_name, source, physics, producers, analyzers, filters, trigger_paths,
end_paths and outputs are reserved to
What variables are known to
I know that trigger path are // different from end paths, they can contain different types of modules; // event gets frozen after trigger path.
art knows to match the value defi
ned by the name ’module_name" to a C++ object fi
le with the name module_name_module.so" somewhere in the path defi
ned by LD LIBRARY PATH.
Further information on the FHiCL language and usage can be found at the mu2e FHiCL page.
To request your Fermilab computing account(s) and permissions to log into the your
experiment’s nodes, fill out the form Request for Fermilab Visitor ID and Computer Accounts.
Typically, experimenters that are not Fermilab employees are considered
After you submit the form, an email from the Fermilab Service Desk should arrive within a week (usually more quickly), saying that your Visitor ID (an identifying number), Kerberos Principal and Services Account have been created. You will need to change the password for both Kerberos and Services.
Your Kerberos Principal is effectively a username for accessing nodes that run
Kerberos in what’s called the FNAL.GOV
To change your Kerberos password, first choose one (minimum 10 characters with mixture of
upper/lower case letters and numbers and/or symbols such as !, , #, $, &, *, %). From your
local machine, log into the machine using
Your Kerberos password will remain valid for 400 days.
The Services Account enables you to access a number of important applications at Fermilab with a single username/password (distinct from your Kerberos username/password). Applications available via the Services Account include SharePoint, Redmine, Service Desk, VPN and others.
To get your initial Services Account password, a user must first contact the Service Desk to get issued a first time default password. Once a default password is issued, users can access http://password-reset.fnal.gov/ to change it.
If you are not on-site or connected to the Fermi VPN, call the Service Desk at 630-840-2345. You will be given a one-time password and a link to change it.
This appendix describes how to install all of the software needed to run the
The
The
https://cdcvs.fnal.gov/redmine/projects/cet-is-public/wiki/Build_packages_required_by_art
No additional information on building from source will be provided in this document.
At this writing, binary distributions are available for:
The binary files are distributed in the format of relocatable UPS packages 7. The first step is to
choose a directory into which the UPS packages will be installed; the full path to this directory is
arbitrary; the directory name is arbitrary but it is traditionally chosen to be
The following procedure illustrates how to download the binaries for toyExperiment plus all of the binaries for the products on which toyExperiment depends. The example is given for SLF6 for non-neutrino experiments. Other options are discussed after the procedure:
This section describes how to prepare a bash script that serves as the site specific setup
procedure. Everyone who wishes the use the
The name of the file is arbitrary; for purposes of this example we will call it
The listing below shows the required contents of this file:
You should also ensure that this script is not executable:
This is because users must source, not execute, this script.
The first line of the file initializes the UPS system for the current login session. Be sure to change <products> to the appropriate path for your site.
The art workbook instructions presume that the adminstrators of site may have policies such as:
source code and binaries belong on one disk while event-data files, log files and root files belong
on another disk. You should define
so that the directory
is a directory in which the user specified by <username> can work. It should point to a disk on
which the user may put source and binary files.
You should define
so that the directory
is a directory in which the user specified by <username> can work. It should point to a disk on
which the user may put event-data, root and log files.
For example, on Mu2e machines at Fermilab, the values of these variables are:
It is OK if both environment variables point at the same directory; everything will still work correctly.
If contraints from your site policies do not allow you to define these two environment variables then you should tell users to follow self managed procedures that are presented as options in Sections 9.6.1.2 and 10.4.3.2.
The environment variable
Note that the prof/debug option is NOT part of
In the example of downloading binaries earlier in this session, the option string was
Note the change in punctuation.
You may wish to add additional local customizations to this script. For example if you get git
from your UPS products area you may wish to setup git. In this file you should not setup versions
of toyExperiment,
The general instructions for downloading binaries are at:
https://cdcvs.fnal.gov/redmine/projects/cet-is-public/wiki/Get_binary_distributions
Instructions that are specific to this version of toyExperiment are at: The full instructions are
available at:
http://scisoft.fnal.gov/scisoft/bundles/toyExperiment/v0_00_29/toyExperiment-v0_00_29.html
When
The number at the end of this line is also the exit status that
Inside the
If you ran
Here the symbol $? is a bash variable that holds the status code returned by the previously
executed command. If you write a shell script that runs
| | |
| ||
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
In many of the exercises in the Workbook you will produce files that contain figures. These files
will be in formats such as
For those of you who are working on the Fermilab General Purpose Computing Facility (GPCF), this chapter has instructions on how to view these files interactively and how to print them.
If you are logged in to a Fermilab machine from offsite, viewing figures interactively may be too slow to be practical. It depends on the quality of the network connection between Fermilab and your site; and it depends on the details of the file you are viewing. In such cases, the best alternative is to copy the file to a local machine and it view it using the tools available there.
On a GPCF machine there are two interactive commands that will allow you to view a figure file:
Despite its name,
Another interactive command that is present on some Unix machines is,
Some people prefer
On most Fermilab machines PDF files can be printed from the command line or from a browser. Other graphics formats need to be viewed in a browser and printed from the browser or saved as PDF and then printed from the command line.
General information about printing at Fermilab is available at fermiprint.fnal.gov.
The wikipedia entry for CLHEP,http://en.wikipedia.org/wiki/CLHEP, describes it as:
CLHEP (short for A Class Library for High Energy Physics) is a C++ library that provides utility classes for general numerical programming, vector arithmetic, geometry, pseudorandom number generation, and linear algebra, specifically targeted for high energy physics simulation and analysis software. The project is hosted by CERN and currently managed by a collaboration of researchers from CERN and other physics research laboratories and academic institutions. According to the project’s website, CLHEP is in maintenance mode (accepting bug fixes but no further development is expected).
The
This appendix will discuss those parts of CLHEP that are important for the
CLHEP is divided in packages and the
CLHEP uses the word
The Vector package does not make a distinction between positions, displacements, velocities and momentum. The same classes are used for all four.
The CLHEP home page is http://proj-clhep.web.cern.ch/proj-clhep.
The following is a direct link to the CLHEP documentation page:
http://proj-clhep.web.cern.ch/proj-clhep/index.html#docu
In many cases the documentation for CLHEP is simply the code or the comments in the code.
You can view the header files by looking under $CLHEP_INC. You can view the source files by
looking under $CLHEP_DIR/source. A more convenient format to view the header files is to use
the CLHEP Doxygen site:
http://proj-clhep.web.cern.ch/proj-clhep/doc/CLHEP_2_1_3_1/doxygen/html/
Doxygen simply presents the information found in the header file in a format that is easier to
view than the header file itself.
To get information about a CLHEP class, go to the Doxygen page, click on the tab named “Classes”, and use your browser’s search function to find the name the class.
The syntax to include a CLHEP header file is:
where
Almost all of the class names in CLHEP begin with the prefix
In most cases, the name of the header file for a class is the name of the class, excluding
the leading
There is one important header file that follows an unusual naming pattern. The header file
Following a convention in use during the mid 1990’s when the CLHEP package was developed,
CLHEP header files contain only declarations. When inline implementations are required,
CLHEP puts them in a file with the same name as the header file but with
The convention of using
All identifiers defined by CLHEP are in the
An example of a
This tells the compiler that, when ever it sees
An example of a
This tells the compiler that it should recognize all identifiers from the
Using declarations and directives are a part of C++ that you can read about in any standard text.
Using
One very important rule is that you must never code using directives or using declarations in
header files. You should only use them in source files.
.
For the particular case of CLHEP you should not use
Consider what happens if you code:
The CLHEP Units package defines many identifiers with commonly used short names,
A common programming error is to forget to declare a variable before using it. Normally the
compiler will recognize this error and issue a diagnostic message. If, on the other hand,
one of your undeclared variables matches one of the CLHEP variable names, and if
you have used
A similar problem occurs if you code:
This introduces three one letter identifiers into the scope of your code:
The bottom line is that CLHEP does not mix with using directives and using declarations.
The
The class
You can also browse the class header using Doxygen:
Because this is a particularly simple class, the header serves as complete documentation. If you
are a beginner to C++ this might not be enough. So this section will show a few of the commonly
used features. The goal of this section is to guide you through the header file so that you will
learn how to understand a typical CLHEP header file.
In each of the first four constructors the missing components are set to 0. If you check the
There is a single
or
There are many synonyms for access to the individual elements. If
similarly for
The full names
Why are there so many different ways of doing the same thing?
Why does documentation talk about all of these ways of doing the same thing? Because you are likely to encounter them as you read code written by others.
The header tells you that the above accessors functions exist because it contains:
All of the accessors are implemented inline. The first two accessors are member functions, similar to many you have seen before. You do not need to learn all of the details about the last two accessors — you only need to recognize their use, as illustrated on the previous page.
If you do wish to learn more about the third accessor it will be described in any standard C++ text
under the topic of “functors”. If you wish to learn more about the fourth accessor, it
will be described in any standard C++ text; find the section on
If
Similarly for setting the values of the
The header tells you that the above accessors functions exist because it contains:
You can also set the values of all three components at once. For example the following sets the
value of
The header tells you that this function exists because it contains:
Table E.1 lists some of the commonly used member functions of
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
The C++ compiler knows how to use combinations of the above functions to allow you to write:
which have the obvious meaning.
and is used as follows:
This comparison suffers from the usual dangers about doing comparisons of floating point numbers for equality.
The
and is used as follows:
The notion of nearness is expressed as,
The fragility comes from the second argument. This argument is optional and has a default value that
is set to the value of a static member datum of the class,
There are similar comments about the functions:
which are used as:
The class
You can also browse the class header using Doxygen:
As for
If you are not familiar with reading C++ header files you should read Section E.6.2 before reading this section. That section has more examples of how to translate a declaration in a header file into example code; this section presumes that you can do that yourself.
In the
In each constructor, the missing components are set to zero. As for
In the following examples the objects
Similarly for the
Prefer to use one of the first two forms. The third form is perfectly correct but it may be difficult for readers of your code to understand its intended function (only real CLHEP experts will understand it). The fourth form executes more slowly than the others.
The following code fragments set the value of the
Similarly for the
Two of the above lines in three previous three blocks may be difficult to understand. The two lines:
are implemented, respectively, by the following operators of the class
You do not need to understand how these work, just that the above two assignments work. If you do wish to, you can look in any standard C++ reference in a section that might be called type-cast operators or implicit conversions.
A common beginner’s mistake involves confusion about the function
The common mistake is to use
The
If you consult the header file or Doxygen documentation you will see that
The
The
The two classes with names ending in
All of the header files presented in the Workbook begin and end with a three line structure called an include guard. An example is shown this listing:
# ifndef package_path_to_file_h # define package_path_to_file_h // The C ++ content of the header file # endif /* package_path_to_file_h */
The three lines beginning with
Suppose that you have a main program that includes two header files
In the first two lines, the text
The first time that the preprocessor encounters
If every header file in a code base correctly uses include guards, then every header file can safely include all other header files on which it depends and one need not worry about this causing compiler errors due to multiple declarations of a class or function.
For include guards to work, each header file must chose a C preprocessor variable name that is
unique within every compilation unit in which it might be included, either directly included or
indirectly included. The convention that is used by
analyzer module, 183
characteristics, 183
configure via parameter set, 241
events passed by reference, 187
flow of execution, 212
order in path, 267
signature, 187
use of override, 184
API, 12
art, 7
API, 12
applicability, 7
artmod, 204
as an external product, 23
build systems, 201
C++, 7
command, 14
command line options, 136
long form, 136
short form, 136
configuration file, 14
data persistency, 291
data product, 19
development environment, 162, 175, 395
documentation suite, 9
dynamic library usage, 191
error conditions, 154
error status, 131
event, 13
event ID, 13
event loop, 14
event sharing, 187
executable, 125
execution syntax, 130
flow of execution, 212
getting help, 9
identifiers, 409
input file
specify in FHiCL, 137
specify on command line, 137
job status, 131
log file, 131
module, 14
module types, 18
operate on multiple modules, 207
output file, 131
output module, 147
paths used in, 40
post-initialization steps, 16
processing order, 267
rerun same module, 141, 264
ROOT classes, 291
ROOT support, 25
run-time configuration, 125
command line options, 132
FHiCL file, 132
run-time environment, 125, 148, 391
sample output, 130
services, 20
specify events to process, 136, 139
specify modules to process, 140
TFileService, 291
Unix environment, 38
use as external package, 8
use of ROOT, 291
users, 8
art module, 14
art-users email list, 9
art::EDAnalyzer, 182
art::Event, 187, 267
art::EventID, 271
art::ServiceHandle, 292
artdaq, 8
artmod, 204
options, 206
auto, 285
beginJob, 300
boost, 23
browse command, 306
build system, 22, 162
instructions for, 169
build tools, 395
building code
clean rebuild, 197
complete, 197
finding dynamic libraries, 200
incremental, 197
linking, 200
saving output files, 197
buildtool, 173, 177
algorithm, 196
CMakeLists.txt file, 195
error, 197
functions, 194
verbose mode for experts, 202
C++, 9
-Werror, 56
.cc files, 49
.dylib files, 49
.h files, 49
.o files, 49
.so files, 49
accessors, 92, 324
base class, 16
build, 48, 66
output option, 54
build commands, 63
c++ command, 63, 65, 67
compile, 48, 53
declaration, 100
definition within declaration, 100
dereferencing operator, 327
enum, 320
exception, 251
executable program, 49
float, 58
free functions, 104, 325
function
argument list, 61
declaration, 61
definition, 62, 68
implementation, 62
return type, 61
function ‘main’, 54, 61, 64
header files, 49, 61
implementation within declaration, 100
implicit type conversion, 68
include directive, 67
include guards, 61
include ROOT header syntax, 294
inheritance, 16, 163
libraries, 49, 60
link, 48, 53
link list, 50
linker, 65
linker symbols, 65
looping
breaking up code, 330
const reference, 334
do-while, 333
for writing templates, 333
range-based, 326
using at function, 331
using comma operator, 333
using iterators, 332
using iterators with auto, 332
using std::vector as array, 331
while, 333
main program, 54
main program, 53, 61
module, 15
object files, 49
pointer, 58
prerequisites, 53
rebuild subset, 60
signature, 68
Singleton Design Pattern, 21
source code files, 49
std::vector<T>, 53
stream insertion operator, 104, 325
syntax flexibility, 192
temporary object recommendations, 192
uninitialized variable, 55
unresolved references, 65
variable addresses, 55
variable type, 58
C++11, 9
conditional exclusion, 325
calibration constants, 20
cetbuildtools, 22, 23, 162, 395
CETLIB, 23
CINT, 292
file naming convention, 308
multiple png files, 334
relation to C++, 308
script, 293
subtract two histograms, 334
class templates, 296
CLHEP, 23, 321
cmake, 22, 301
variable, 282, 303
definition, 201
CMakeLists.txt file
buildtool, 195
cmsrun, 8
coding
best practices, 33
conditional exclusion, 325
conventions, 33
rules, 33
style, 33
coding standards, 9
C++, 9
C++ 11, 9
collection, 20
colon initializer syntax, 239, 261
conditions information, 20, 125
configuration file, 14
constructor
explicit argument, 184
data file, 25
data members
store parameter values, 253
data product, 19, 135, 271
collection, 20
contents, 20
distinguish from products, 24
name, 272, 274
operations, 25
persistency, 25
persistent representation, 25
specification, 276, 281
transient representation, 25
data type
friendly name, 275
in data product name, 275
debugging
using optional parameters, 256
defaultExceptions, 286
development environment, 395
Doxygen, 12
dynamic libraries, 21
.dylib files, 21
.so files, 21
build system, 22
dependency lists, 200
directories, 153
file extensions, 125
naming rules, 195
paths to, 125
run-time loading, 184
use in instance creation, 191
use with buildtool, 196
dynamic library, 15
building, 179
matching module name, 179
dynamic load libraries, 21
EDAnalyzer, 141
EDM, 25
endJob, 300
error handling, 251
default vs alternate behavior, 252
event, 13, 13
contents, 187
representation, 190
representation in art, 186
unique identifier, 13
event ID, 13, 271
event number, 13, 188
EventID return type, 189
individual parts of, 208
run number, 13, 188
subRun number, 13, 188
event loop, 14, 18, 18
event-data files, 26
event-data files for Workbook, 126
Event-Data Model, 25
ROOT support, 25
exceptions, 240, 262
experiment code, 21
external products, 23
FermiGrid, 24
Fermilab Hierarchical Configuration Language, 405
FHiCL, 23, 124, 132, 405
fhicl::ParameterSet, 185
definition
form, 133
definitions, 238
file extension, 132
identifier
analyzers, 135
physics, 134
source, 133
numerical forms
formats, 258
numerical types, 256
output module, 147
optional parameters, 147
parameter name, 244
parameter set, 238
error conditions, 250
print, 239, 261
parameter value
store as data member, 253
store as local variable, 254
parameters, 238
canonical form, 240, 256, 262
default value, 254
default values, 240, 262
internal representation, 242
optional, 254
policies, 256
properties, 241
return type, 243
paths, 142
process name, 135
scope, 133
source file, 133
special characters, 134
specify input files, 137
syntax, 133
table, 133, 238
value, 134
fhicl::ParameterSet, 238
get, 244
file catalog, 26
file of Monte Carlo events, 26
file of simulated events, 26
filter module, 18
forward declarations, 321
four-vector conversion, 327
framework, 7
boundary with user code, 8
infrastructure, 8
friendly name, 275, 281
textbf, 275
gcc, 23
GenParticle, 273, 278, 320, 322
GenParticleCollection, 273, 320
geometry information, 125
geometry specification, 20
getting help, 9
git, 23, 165
about, 166
handle
invalid, 280
handles, 279
default construct, 280
service, 298
valid, 281, 284
header files
absence of, 210
conflicts, 199
finding, 198
from UPS product, 199
Geant4, 198
ROOT, 198
help with art, 9
Hep3Vector, 321
HepLorentzVector, 321
histogram
change module label, 313
create using TFileService, 298
filling, 300
formats, 313
pointer naming convention, 294
save, 313
structure, 299
subtracting two, 334
view interactively, 306
view with ROOT, 292
view with TBrowser, 304, 313
write to PDF, 292
histogram file, 299, 304
change name, 313
overwriting, 312
ifdh_sam, 24
inheritance, 182
input tag
initialization, 283
jobsub_tools, 24
keyword
auto, 285
member function
argument names, 186
for analyzer module, 184
optional, 184
override identifier, 184, 187
template, 249
message service, 20
purpose of, 136
MF, 23
module, 14
C++ class, 15
analyzer, 18
member function requirement, 246
class, 238
communication between, 267
create with artmod, 204
dependencies, 201
filter, 18
finding, 153
header files, 181
identify from art output, 179
instance, 264, 299
in data product name, 275
name, 275
label, 140, 141, 266, 268, 299
identify parameter set, 268
in data product name, 275
name instance, 268
naming rules, 142
parameter set, 238
uniqueness, 142
naming rules, 195
optional member function, 184
output, 18
producer, 18
requirements, 15
run simultaneously, 206
source, 18
source code, 180
three-file style, 211
type, 133, 141, 183
types, 18
module types, 18
namespaces
fhicl, 185
ROOT, 294
tex, 182
toy experiment, 182
naming variables, 244
NTuple, 18
null pointer, 296
nullptr, 296
output directory, 177
output module, 18
overload set, 68
packages, 23
parameter set, 133, 266
for module configuration, 141
module label, 141
parameters
default value recommendations, 283
Particle Data Group, 320
particles
generated, 320
parent-child relationships, 322
PDG identifier codes, 320
primary, 322
secondary, 322
paths
art, 143
different types of, 145
FHiCL, 142
module order, 267
PDG, 320
particle identifier codes, 320
plugins, 21
png files, viewing, 328
pointer, 284
bare, 284
naming convention for histogram, 294
pointers, 280
safe, 280
smart, 280
process name, 135
in data product name, 275
processing loop, 18
producer module, 18
processing order, 267
products, 23, 109
access to, 107
distinguish from data product, 24
distribution via UPS/UPD, 24, 107
external, 107
product directories, 107
PRODUCTS, 107
reconstruction on demand, 15
replica manager, 26
ROOT, 18, 23, 291
booking a histogram, 300
create histogram, 298
cycle numbers, 306
deleting a histogram, 300
dictionaries, 325
documentation links, 311
exit from root program, 305
file naming conventions, 300
filling a histogram, 300
genreflex tool, 325
global namespace, 294
histogram file, 299
histogram vs event-data filenames, 300
include header syntax, 294
input vs output filenames, 300
output file structure, 299
TBrowserWindow, 305
TFileService, 298
TNtuples, 300
treatment of bin edges, 299
TTrees, 300
ROOT files
event-data, 292
histograms, 292
RootInput module, 133
run, 13
run-time configuration
value types, 406
run-time configuration file, 14
run-time environment, 391
SAM, 24, 26
service handle, 298
services, 20, 296
access via handle, 298
message service, 20
requesting information from, 21
TFileService, 21
set up to run Workbook, 127
build window, 169
source window, 165
setup to run Workbook
loggin back in, 218
shareable libraries,
site-specific setup, 45
procedures, 46
Unix environment, 45
site-specific setup procedure, 149
setup git, 166
smart pointer, 21
source code
compile and link, 180
filenames
modules, 184
source directory, 165
source module, 18
std::vector, 255, 271
dynamic sizing, 272
subRun, 13
TBrowser, 304
print histogram, 313
templates, 240, 243, 262
argument, 243, 272, 276
dummy, 249
type, 244
class, 271, 274, 284
member function, 249, 271, 282
templates:collections of objects, use with, 274
testing
using optional parameters, 256
TFileService, 21, 291, 292, 296
arguments, 298
configure, 293, 301
create histogram, 298
toy experiment, 11, 26
namespace, 182
setup, 150
Tree, 18
typedef, 273
recommendation for use of, 190
Unix
bash alias, 42
bash function, 42
bash script, 41
bash shell, 36
commands, 34
computing environment, 37
environment, 37
environment variables, 37, 38, 45
examine environment, 38
execute vs source, 41
help for commands, 34
important concepts, 35
login scripts, 43
login shell, 36
non-standard commands, 34
path vs PATH, 39
scripts, 36
shell variables, 39
shells, 36
suggested references, 43
working environment, 37, 45
UPS
product conflicts, 199
product header files, 199
products area, 125
UPS/UPD, 23, 23
databases, 107
features, 107
UPS/UPD:initialization, 149
UPS/UPD:qualifiers, 150
UPS:product dependency lists, 200
user code, 7
viewing png files, 328
Workbook, 11
build window
contents, 171
setup, 169
disk space, 150
event-data files, 126
FHiCL files
machine-independent, 174
multi-site usage, 199
obtain code, 165
setup to run exercises, 127
initial, 127, 129
self-managed, 129
standard, 127
subsequent logins, 130
source directory contents, 168
toy experiment, 11
Unix environment, 38