Derived class

From: Roger Mason <rmason_at_esd.mun.ca>
Date: Wed, 31 Mar 2010 08:19:12 -0230


Hello,

I made a class (called od) using TTree::MakeClass and derived a class "odextra" from it:

/* @(#)odextra.h
 */

#ifndef _ODEXTRA_H
#define _ODEXTRA_H 1

#include <TH2.h>
#include <TStyle.h>
#include <TCanvas.h>

#include <vector>
#include <set>
#include <algorithm>
#include <iostream>

class odextra : public od {
public:

  vector<Double_t> v;   

  ~odextra();
};

#endif /* _ODEXTRA_H */

I made the data members of odextra public so they can be filled from within the Loop() method created by TTree::MakeClass.

I have a file od.C that contains:

#define od_cxx
#include "od.h"
#include "odextra.h"

#ifdef od_cxx

odextra::~odextra(){
  cout << "odextra destructor called " << endl; }
#endif

void od::Loop()
{

   if (fChain == 0) return;

   fChain->SetBranchStatus("*",0);  // disable all branches
   fChain->SetBranchStatus("energy",1);  // activate branchname
   fChain->SetBranchStatus("type",1);  // activate branchname

   Long64_t nentries = fChain->GetEntriesFast();

   Long64_t nbytes = 0, nb = 0;

   odextra e;

   b_type->SetAddress(&type);

   for (Long64_t jentry=0; jentry<nentries;jentry++) {

      Long64_t ientry = LoadTree(jentry);
      if (ientry < 0) break;
      nb = fChain->GetEntry(jentry);   nbytes += nb;

      e.v.push_back(energy);

      if (jentry < 10) 
         cout << "Energy = " << e.v.at(jentry) << endl;

      }

   }
}

Compiling with ACLiC succeeds and I can create an od object but when I run the Loop() method the output is nonsense:

root [2] od t
root [3] t.Loop()
Energy = 1.22176e+161
... snipped 9 repeats of this output
odextra destructor called
od destructor called

and a second call to t.Loop() results in a segfault.

root [4] t.Loop()

I am using:

ROOT 5.22/00b (branches/v5-22-00-patches_at_28611, Nov 11 2009, 11:56:00 on linuxx8664gcc)

I suppose I have abused C++ somewhere and it is taking revenge. If someone could point me in the right direction I'd be most obliged.

Thanks,
Roger Received on Wed Mar 31 2010 - 12:49:18 CEST

This archive was generated by hypermail 2.2.0 : Wed Mar 31 2010 - 17:50:01 CEST