SOOT::SQL2Tree - Make a TTree from a SQL SELECT
use SOOT::SQL2Tree; my $dbh = DBI->connect(...); my $sql2tree = SOOT::SQL2Tree->new(dbh => $dbh); my $tree = $sql2tree->make_tree("SELECT * FROM particles WHERE rapidity IS NOT NULL"); $tree->Draw("energy:rapidity");
WARNING: This is highly experimental stuff!
SOOT is a Perl extension for using the ROOT library. It is very similar to the Ruby-ROOT or PyROOT extensions for their respective languages. Specifically, SOOT was implemented after the model of Ruby-ROOT.
SOOT::SQL2Tree implements a very simple minded interface to databases in which you can generate a ROOT TTree from a SQL SELECT statement.
SOOT::SQL2Tree
TTree
SELECT
The main interface is object-oriented, but there is a convenience function for quick hacks and command line usage (see below). It can be exported on demand and will be export by default if the module is loaded in a one-liner.
Constructor. Takes named parameters. Requires at least a dbh argument that is a DBI database handle.
dbh
DBI
Optional arguments:
Sets the TTree name or title.
A hash reference associating the SQL column names with a subroutine reference. Those callbacks will be called with the column value as argument for every time the column is encountered in the input. The column value will be replaced with the return value of the callback in the output.
Example:
my $sql2tree = SOOT::SQL2Tree->new( dbh => ..., colmaps => { distance => sub { $_[0]/1000 }, # convert from km to m ... } ); my $tree = $sql2tree->make_tree("SELECT distance, ... FROM foo");
Any unmapped columns will be inserted into the tree without modification.
A hash reference that maps the input SQL type of a column to another type. Keys must be column names, values must be SQL types. Mostly only useful for manually modified columns (see colmaps).
colmaps
coltypes => { distance => 'double', },
Getter/setter for the colmaps attribute.
Getter/setter for the coltypes attribute.
coltypes
Getter/setter for the TTree name.
Getter/setter for the TTree title. Defaults to the TTree name or nothing if there is no name.
Alternative non-OO interface for quick hacks. Take positional parameters. Returns a TTree object.
Parameters:
Either a DBI object, an array ref containing the arguments to the DBI connect() method, or just the dsn string.
connect()
The SQL to run. Nuff said.
Optional array reference containing bind parameters for the SQL.
Optional hash reference containing attributes to pass to the statement handler execute() call.
execute()
The module can automatically detect and transform the types of most basic SQL types and char and varchar strings.
char
varchar
Strings are likely problematic and currently untested.
Check the code for the recognized types or use the coltypes option to set the type of your column manually.
http://root.cern.ch
SOOT
Steffen Mueller, <smueller@cpan.org>
Copyright (C) 2011 by Steffen Mueller
SOOT, the Perl-ROOT wrapper, is free software and so is SOOT::SQL2Tree; you can redistribute it and/or modify it under the same terms as ROOT itself. That is, the GNU Lesser General Public License. A copy of the full license text is available from the distribution as the LICENSE file.
1 POD Error
The following errors were encountered while parsing the POD:
You forgot a '=back' before '=head1'
To install SOOT::SQL2Tree, copy and paste the appropriate command in to your terminal.
cpanm
cpanm SOOT::SQL2Tree
CPAN shell
perl -MCPAN -e shell install SOOT::SQL2Tree
For more information on module installation, please visit the detailed CPAN module installation guide.