Steffen Müller > SOOT > SOOT::Struct

Download:
SOOT-0.17.tar.gz

Dependencies

Annotate this POD

View/Report Bugs
Source  

NAME ^

SOOT::Struct - Perl interface to generate new C-level struct types

SYNOPSIS ^

  use SOOT::Struct;
  my $struct = SOOT::Struct->new(
    name   => 'person_t',
    fields => [
      'name' => 'Char_t[20]',
      'age'  => 'UInt_t',
    ],
  );
  
  print $struct->code;
  # prints the C-code necessary for compilation
  
  $struct->compile;
  # writes the code to a temporary file and compiles it with CInt/ACLiC
  
  my $person = person_t->new;
  $person->name("Steffen"); # stores in struct via SOOT
  print $person->name(), "\n"; # fetches via SOOT

DESCRIPTION ^

This package provides a (limited) object oriented interface to creating new C-level structs that are known to ROOT and available as Perl classes.

All struct members will be available as Perl methods (see SYNOPSIS above). The Perl methods return the value of the struct member when called without arguments and set the value of the member if called with an argument. For array-like members, you need to pass a reference to a Perl array. The one exception are arrays of type Char_t[] which are special cased to be converted to/from perl strings. For example, given a member 'Int_t[3] foo', you can set it with

  $struct->foo([1, 2, 3]);

If you added a fourth element to the array, it would be ignored. If you pass in less elements that the struct allows for, the remaining elements will be padded with zeroes.

The necessary type conversions are only implemented for basic types and only for up to one level of arrays. Storing/accessing matrices does not work.

The generated code looks something like this:

  class $yourstructname : public TObject {
    public:
    $yourfirsttype $yourfirstfield;
    ...
    ClassDef($yourstructname, 1);
  };

METHODS ^

new

Creates a new dynamic struct type. Required named argument: The name of the new struct type.

Optionally takes a named argument 'fields'. fields can have the same forms as add_fields() accepts.

add_fields

Adds more fields to the end of the struct. Can be used in one of two forms. It accepts a single string as argument which is parsed as a simple struct definition (just data members). Anything up to the first { and after the last } is ignored.

Alternatively, you may provide key/value pairs that indicate field names and their types respectively. Note that with this syntax, the number of items in a static array is part of the type:

  $struct->add_fields(foo => 'Int_t[20]');

whereas you would normally write in a C struct declaration:

  Int_t foo[20];

If that bothers you, use the first variant of add_fields().

code

Returns the code that is to be compiled with ROOT's ACLiC.

compile

Generates the C code, writes it to a file determined by the program name and the name of the struct and compiles it with ACLiC, so that the struct becomes available to SOOT/Perl.

SEE ALSO ^

SOOT

http://root.cern.ch

AUTHOR ^

Steffen Mueller, <smueller@cpan.org>

COPYRIGHT AND LICENSE ^

Copyright (C) 2010-2011 by Steffen Mueller

SOOT, the Perl-ROOT wrapper, is free software; 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: