SLAC PEP-II
BABAR
SLAC<->RAL
Babar logo
Workbook HEPIC Databases PDG HEP preprints
Organization Detector Computing Physics Documentation
Personnel Glossary Sitemap Search Hypernews
Unwrap page!
Wkbk. Search
Wkbk. Sitemap
Introduction
Non SLAC
HOWTO's
Introduction
Logging In
QuickTour
Detector
Info Resources
Software Infrastructure
CM2 Introduction
Unix
OO
SRT
Objectivity
Event Store
Framework
Beta
Modifying Code
Writing and Editing
Compiling
Debugging
Analysis
Framework II
Analysis
Find Data
Batch Processing
PAW
PAW II
ROOT I
ROOT II
ROOT III
Advanced Infrastructure
New Releases
Workdir
Main Packages
Event Displays
Gen/Sim/Reco
Contributing Software
SRT and CVS
Coding
Advanced Topics
Make CM2 Ntuples
New Packages
New Packages 2
Persistent Classes
Java
Site Installation
Check this page for HTML 4.01 Transitional compliance with the
W3C Validator
(More checks...)

Workbook for BaBar Offline Users - Writing Code

Using an Object Oriented design approach to make proper use of C++.

Object Oriented programming offers a powerful model for writing computer software. Objects are "black boxes" which send and receive messages. This approach speeds the development of new programs, and, if properly used, improves the maintenance, reusability, and modifiability of software by limiting the dependences among the various objects which are coded.

OO Analysis and Design brings in a new approach to modelization with respect to traditional (procedural) methods, understanding the  OO vs SA/SD analysis & design characteristics is important. The C++ language offers an easier transition via C, but it still requires an OO design approach in order to make proper use of this technology. This can often be a major problem for experienced C programmers.


OO Courses and References

Object Orientation

Object Orientation relies heavily upon concepts and terminology that make up the boundaries of the paradigm. Principles and definitions cannot be ignored in order to program within the OO paradigm boundaries.

A rudimentary discussion of Object Orientation may be found in the Object Orientation section of this workbook.

You may want to look at the FAQ to get quick answers to the basic ideas behind OO.

As an introduction to Object Oriented Programming, Bob Jacobsen and Dave Quarrie presented a series of lectures at SLAC in 1995. Like the C++ course, these lectures were recorded and the videos are available or loan and for copy from SLAC and in Europe.

The transparencies from the talks are available on the web.

Some useful books on OO design are:

  • Robert C. Martin, "Designing Object-Oriented C++ Application Using the Booch Method", Prentice-Hall Inc, 1995, ISBN 0-13-203837-4.
  • E.Gamma, R.Helm, R.Johnson and J.Vlissides, ``Design Patterns'', Addison-Wesley, ISBN 0-201-63361-2.
  • I.White, ``Using the Booch Method: a Rational Approach'', Benjamin Cummins, ISBN 0-8053-0614-5.
  • G.Booch, ``Object Oriented Analysis and Design with Applications (2nd ed)'', Benjamin Cummins, ISBN 0-8053-5340-2.

Methods

Methods (functions) in OO are the way to develop software following a controlled and repeatable process. Methods rely on the parallel production of documentation (mostly OO diagrams) and code). Examples are:

The C++ Language

You may or may not do OO programming with C++ (not even so-called pure-OO languages force you to go OO). If ever, these books are gold-plated: if you don't have them, buy them (and read them). They cover what you should and should not do with OO/C++.
  • Meyers, Effective C++, Second Edition, 224 pgs, Addison-Wesley, 1998, ISBN 0-201-92488-9. Covers 50 topics in a short essay format.
  • Meyers, More Effective C++, 336 pgs, Addison-Wesley, 1996, ISBN 0-201-63371-X. Covers 35 topics in a short essay format.
  • Gamma et al., Design Patterns, Elements of Reusable Object-Oriented Software, Addison-Wesley, ISBN 0-201-63361-2. Patterns and what OO is all about: The introduction should be carved into each developer's brain.

While Meyers works constitute the do's and dont's, the following two works cover most if not all aspect of legal C++.

  • Lippman and Lajoie, C++ Primer, Third Edition, 1237 pgs, Addison-Wesley, 1998, ISBN 0-201-82470-1. Very readable/approachable.
  • Stroustrup, The C++ Programming Language, Third Edition, 646 pgs, Addison-Wesley, 1998, ISBN 0-201-53992-6. Covers a lot of groun
A series of 8 lectures introducing users to C++ programming were given by Paul Kunz during 1995. These lectures were all video'd and the videos are available for loan and copy from SLAC and in Europe. The full transparencies for the course are available on the WWW (copies of these will be essential when viewing the videos !) at /BFROOT/www/Computing/Programming/ProgC++class.html. The Paul Kunz course closely follows the following text:
  • John J. Barton and Lee R. Nackman, ``Scientific and Engineering C++: An Introduction with Advanced Techniques and Examples'',published by Addison-Wesley (ISBN 0-201-53393)
This books contains many code examples, all of which are available from the Web, via links on the above pages. The book is really aimed at teaching the basics of C++ to Scientists and Engineers (i.e. FORTRAN programmers).

Other useful texts for learning C++ are:

  • Stanley B. Lippman,``C++ Primer'', published by Addison Wesley. ( ISBN 0-201-54848-8 )
  • Ira Pohl, ``Object Oriented Programming Using C++ - 2nd Edition'', published by Addison Wesley ( ISBN 0-201-89550-1 )
  • Scott Meyers,``Effective C++'', published by Addison Wesley. ( ISBN 0-201-56364-X )
  • Scott Meyers,``More Effective C++'', published by Addison Wesley. ( ISBN 0-201-63371-X )

Related Documents:


BaBar C++ Coding Conventions

In general, each file in a package should represent a class, and each class should contain methods (functions) to do just one task. The classes are defined in the header files (*.hh) which represent the class interface. In it you state what the class is called and declare the variables and functions within that class. The .cc file is just the implementation of the functions. The convention:
#ifndef MYCLASSNAME_HH
#define MYCLASSNAME_HH

<class declaration info>

#endif
should be adhered to for header files to avaoid the header file being "#include"'d more than once at compilation stage.

Classes involving the Objectivity database are different - they contain a .cc file and a .ddl file (from which the compiler automatically creates a *_ddl.hh in a tmp directory when it's processing). These files are beyond the scope of this workbook chapter, and will be dealt with in the WorkBook chapter Writing Persistent Classes Related Documents:


External Class Libraries

Related Documents:

Warning and Error Messages


Writing messages in a way that allows program recover, allows logging and allows the user to control verbosity
 

CodeWizard: a Tool for Checking Coding Style

Related Documents:

Great Circle: a Tool for Finding Memory Leaks

Related Documents:

Insure++: a Tool for Checking for Memory Misuse

Related Documents:
General Related Documents:

Back to Workbook Front Page

Neil Geddes
Massimo Marino
Joseph Perl
Last updated:
Jenny Williams

Last modification: 5 August 2004
Last significant update: 9 October 2002