Upload
austen-skinner
View
218
Download
2
Tags:
Embed Size (px)
Citation preview
JANA Calibration API David Lawrence -- JLab 1
The JANA Calibrations and Conditions Database API
March 23, 2009David Lawrence JLab
3/23/09
Newport News, Virginia
JANA Calibration API David Lawrence -- JLab 2
The GlueX Experiment
3/23/09
real g beam
2 Tesla solenoidmagnet
30 cm LH2 target
Forward EM calorimeter and forward TOF wall downstream
Cylindrical and planar drift chambers inside magnet
Barrel EM calorimeter inside magnet
The “continuous wave” 12GeV electron beam at JLab has a beam bunch every 2 ns
Conventional meson has quantum numbers determined only by constituent quarks
Hybrid meson has some quantum properties due to contributions from the “glue”
JANA Calibration API David Lawrence -- JLab 3
Data Rates in 12GeV eraFront EndDAQ Rate
EventSize
L1 TriggerRate
Bandwidthto massStorage
GlueX 3 GB/s 15 kB 200 kHz 300 MB/sCLAS12 100 MB/s 20 kB 10 kHz 100 MB/sALICE 500 GB/s 2.5 MB 200 kHz 200 MB/sATLAS 113 GB/s 1.5MB 75 kHz 300 MB/sCMS 200 GB/s 1 MB 100kHz 100 MB/sLHCb 40 GB/s 40 kB 1 MHz 100 MB/sSTAR 8 GB/s 80 MB 100 Hz 30 MB/sPHENIX 900 MB/s ~60 kB ~ 15 kHz 450 MB/s
3/23/09
LHC
JLab
BNL *
CHEP
2007
talk
Sylv
ain
Chap
elin
priv
ate
com
m.
* NIM A499 Mar. 2003 ppg 762-765** CHEP2006 talk MartinL. Purschke
**
4
Targeted Customers for JCalibration• “B”-coders = reconstruction code authors
(“A”-coders = framework authors; “C”-coders = physics analysis)
3/23/09 JANA Calibration API David Lawrence -- JLab
JCalibration URL run_number context (string) …
Reconstruction Code namepath (string)
STL container ref.
Database
Reconstruction Program
B-coders A-coders
The minimal information needed from the reconstruction code is the name of the constants and a container to put them in. (The container implicitly contains a data type.)
JANA Calibration API David Lawrence -- JLab 5
API For Accessing ConstantsConstants can be stored in either arrays (1D) or tables (2D) and can be indexed either by name (key-value) or by position.
// Get 1-D array of values indexed by namebool Get(string namepath, map<string, T> &vals) // Get 1-D array of values indexed by rowbool Get(string namepath, vector<T> &vals) // Get 2-D table of values indexed by row and namebool Get(string namepath, vector< map<string, T> > &vals) // Get 2-D table of values indexed by row and columnbool Get(string namepath, vector< vector<T> > &vals)
arra
ysta
bles
3/23/09
// Get list of available namepaths from backendvoid GetListOfNamepaths(vector<string> &namepaths)
disc
over
y
JANA Calibration API David Lawrence -- JLab 6
map<string, double> twpars;loop->Get("FDC/driftvelocity/timewalk_parameters", twpars); slope = twpars["slope"];offset = twpars["offset"];exponent = twpars["exponent"];
Example of Accessing Calibration Constants as key-value pairs
... in factory class definition …
Template method converts values to doubles using stringstream class
For a few parameters like this, it makes sense to copy them into local data members of the factory class
3/23/09
double slope, offset, exponent;
... in brun() method ...
JANA Calibration API David Lawrence -- JLab 7
Backend Requirements
3/23/09
virtual bool GetCalib(string namepath, map<string, string> &svals)virtual bool GetCalib(string namepath, vector< map<string, string> > &svals)virtual void GetListOfNamepaths(vector<string> &namepaths)
To implement a JCalibration interface to a new backend, only 3 virtual methods need to be implemented!
OK, actually, it’s closer to 6, but these 3 are for the generator class and are trivial.
virtual const char* Description(void)virtual double CheckOpenable(string url, int run, string context)virtual JCalibration* MakeJCalibration(string url, int run, string context)
• The generator mechanism allows access to multiple types of databases in the same executable.• Access to a new type can even be brought in through a plugin.
JANA Calibration API David Lawrence -- JLab 8
Calibration Web Service
• The JCalibrationWS class provides calibration constants through a web service– Implemented as a plugin so remote access can be added to an existing executable– Allows read-only access to calibration constants from anywhere in the world over HTTP
(http://www.jlab.org/Hall-D/cgi-bin/calib)– Uses gSOAP, a C++ SOAP implementation– Currently works like a proxy for JCalibrationFile on server side, but could trivially be
made to use another type of backend
• Calibration constants will need to be accessible from remote computers via the internet
• Direct access to a database is problematic due to cybersecurity concerns
• Web services work over HTTP and so are the appropriate mechanism for remote access
3/23/09
JANA Calibration API David Lawrence -- JLab 9
Saving a (semi-)complete set of calibration constants to the local disk
All JANA programs have the command line option:--dumpcalibrations
• Records which namepaths are requested during a job and writes the constants into ASCII files compatible with JCalibrationFile
• Avoids copying and running entire database or even copying a “complete” set of calibration constants (which could include obsolete ones or ones not applicable to the current run/code version)
3/23/09
JANA Calibration API David Lawrence -- JLab 10
SUMMARY• A simple API for accessing calibration/conditions DB exists
in JANA that allows code development prior to developing the actual database– C++ templates + ANSI stringstream allows handling of all data
types• Web Service is a good option for allowing remote access
to constants in a cyber-secure way– SOAP standard (Java, C++, …)
• JANA has a built-in mechanism for dumping constants to the local disk regardless of the source– Local access is (almost) always faster than network access
3/23/09
http://www.jlab.org/JANA
JANA Calibration API David Lawrence -- JLab 11
Backup Slides
3/23/09
JANA Calibration API David Lawrence -- JLab 12
Threads in JANA
3/23/09
• Each thread in JANA is composed of its own event processing loop and a complete set of factories
• Reconstruction of a given event is done entirely inside of a single thread
• No mutex locking is required by authors of reconstruction code
• Threads work asynchronously to maximize rates at the expense of not maintaining the event order on output
raw data read in
reconstructed values written out(e.g. ROOT tree)
JANA Calibration API David Lawrence -- JLab 13
Example of Accessing Calibration Constants as an array
... in factory class definition ...vector<double> tof_tdc_offsets;
... in brun() method ...loop->GetCalib(”TOF/tdc_offsets", tof_tdc_offsets);if(tof_tdc_offsets.size()!=Ntof) throw JException(“Bad Ntof!”);
... in evnt() method ... double t = tof->tdc - tof_tdc_offsets[tof->id];
3/23/09
JANA Calibration API David Lawrence -- JLab 14
Backend Database• The API defines the routines B-coders will use to obtain calibration
constants independent of the details of how the actual database is implemented
• This does impose some requirements of the database design itself:– Store both 1-D arrays and 2-D tables– Index either by name or position– Uniquely identify constants by
• Run number• Context string (may include timestamp)• URL
• JCalibrationFile implements a trivial calibration backend that maps directly to ASCII files on the local file system– Represents snapshot of constants and so ignores run number and context string– URL points to root directory (e.g. file:///group/halld/calib)– Constants currently kept in svn
(https://halldsvn.jlab.org/repos/trunk/calib)
3/23/09
JANA Calibration API David Lawrence -- JLab 15
Calibration object generators and namepath Discoveryo Generator mechanism for JCalibration• JCalibrationGenerator class added• Allows multiple types of database
backends to be supported in same binary
• Allows new calibration database backends to be added dynamically to pre-compiled binaries
• Useful for private development of backend alongside trunk without disturbing standard builds
o Discovery mechanism• JCalibration now has a new virtual
method called GetListOfNamepaths() that can be used to probe a calibration backend for the available constants
• This is utilized in the jcalibread utility using the “-L” switch3/23/09
JANA Calibration API David Lawrence -- JLab 16
Recycled Containers
... in factory class definition ... const double *fcal_gains;
... in brun() method ...const vector<double> *my_fcal_gains; loop->GetCalib(”FCAL/Energy/gains", my_fcal_gains);fcal_gains = &(my_fcal_gains->front());
... in evnt() method ...double Ecorr = fcal_hit->E * fcal_gains[fcal_hit->id];
fcal_gains[3] =1.2; // This will generate compile time error!
A new templated Get() method has been added to JCalibration that instructs it to keep ownership of the constants and just return a const pointer to the container.
Since STL vectors keep internal data sequential in memory, the values can be accessed via a standard array pointer while maintaining const correctness.
3/23/09