Steffen Müller > SOOT-SQL2Tree > SOOT::SQL2Tree

Download:
SOOT-SQL2Tree-0.02.tar.gz

Dependencies

Annotate this POD

View/Report Bugs
Module Version: 0.02   Source  

NAME ^

SOOT::SQL2Tree - Make a TTree from a SQL SELECT

SYNOPSIS ^

  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");

DESCRIPTION ^

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.

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.

METHODS ^

new

Constructor. Takes named parameters. Requires at least a dbh argument that is a DBI database handle.

Optional arguments:

name, title

Sets the TTree name or title.

colmaps

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.

coltypes

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).

  coltypes => {
    distance => 'double',
  },

colmaps

Getter/setter for the colmaps attribute.

coltypes

Getter/setter for the coltypes attribute.

name

Getter/setter for the TTree name.

title

Getter/setter for the TTree title. Defaults to the TTree name or nothing if there is no name.

FUNCTIONS ^

sql2tree

Alternative non-OO interface for quick hacks. Take positional parameters. Returns a TTree object.

Parameters:

database handle

Either a DBI object, an array ref containing the arguments to the DBI connect() method, or just the dsn string.

SQL SELECT statement

The SQL to run. Nuff said.

binds (optional)

Optional array reference containing bind parameters for the SQL.

attributes (optional)

Optional hash reference containing attributes to pass to the statement handler execute() call.

KNOWN SQL TYPES ^

The module can automatically detect and transform the types of most basic SQL types and char and varchar strings.

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.

SEE ALSO ^

http://root.cern.ch

SOOT

AUTHOR ^

Steffen Mueller, <smueller@cpan.org>

COPYRIGHT AND LICENSE ^

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.

syntax highlighting: