RE: creation of a Branch in a Tree Object from struct

From: Philippe Canal <pcanal_at_fnal.gov>
Date: Sat, 18 Feb 2006 00:22:39 -0600


HI Victor,

To simplify your task you should simply use the compiler as follow. Create a file datablock.hh

// Start of fiel datablock.h
struct HEADER_PAIRS1
{

   char name[100];
   int value;
} ;
struct dataBlock_t
{

   HEADER_PAIRS1 hdr[6];
   int val[500];
} ;

#ifdef __MAKECINT__
#pragma link C++ class HEADER_PAIRS1+;
#pragma link C++ class dataBlock_t+;
#endif

Then you script would be:

// Start of script initTree.C
void initTree()
{

   dataBlock_t * dataBl = new dataBl;

   TFile *dataFile;
   TTree *dataTreeSpecHdr;
   TTree *dataTreeSpctr;

   const Text_t *title = "Ca38_data";
   const Text_t *fname = "tree.root";
   Option_t *option = "RECREATE";
   Int_t comp = 1;
   dataFile = new TFile(fname,option,title,comp);    if(dataFile->IsOpen())

      cout << "\n ROOT file: " << fname << " opend" << endl;    else
   {

      cerr << "\n Couldn't open ROOT file: " << fname << endl;
      exit (-2);

   }

   dataTreeSpctr = new TTree("TreeSpctr", "TAMU Ca38, Sep, 2005, Lifetime,Spectra");

   dataTreeSpctr->Branch("spctr",&dataBl); }

and use something like:

   gROOT->ProcessLine(".L datablock.h+");    gROOT->ProcessLine(".L initTree.C");
   initTree();

Cheers,
Philippe.

-----Original Message-----
From: owner-roottalk_at_pcroot.cern.ch [mailto:owner-roottalk_at_pcroot.cern.ch] On Behalf Of Victor Golovko
Sent: Friday, February 17, 2006 1:37 PM
To: roottalk_at_pcroot.cern.ch
Subject: [ROOT] creation of a Branch in a Tree Object from struct

Hello,

probably this is a quite stupid question, but I did not find the answer by myself (well, I am not an expert in C++ programming).

The following code illustrates my problem


typedef struct {

char name[100];

int value;

}HEADER_PAIRS1; typedef struct {

HEADER_PAIRS1 hdr[6];

int val[500];

} dataBlock_t;

void initTree()

{

dataBlock_t dataBl;

TFile *dataFile;

TTree *dataTreeSpecHdr;

TTree *dataTreeSpctr;

const Text_t *title = "Ca38_data";

const Text_t *fname = "tree.root";

Option_t *option = "RECREATE";

Int_t comp = 1;

dataFile = new TFile(fname,option,title,comp);

if(dataFile->IsOpen())

cout << "\n ROOT file: " << fname << " opend" << endl;

else

{

cerr << "\n Couldn't open ROOT file: " << fname << endl;

exit (-2);

}

dataTreeSpctr = new TTree("TreeSpctr", "TAMU Ca38, Sep, 2005, Lifetime, Spectra");

// ???? dataTreeSpctr->Branch("spctr",&dataBl.val,"Data[500]/I");

}


I would like to store in the tree object all information that is defined as a dataBlock_t structure (variable dataBl) as a Branch? How it would be possible?

Thanks for helping me.

Victor.

February 17, 2006 Received on Sat Feb 18 2006 - 07:31:08 MET

This archive was generated by hypermail 2.2.0 : Mon Jan 01 2007 - 16:31:57 MET