Hi Roger,
Can you try when compiling with aclic ? (i.e. load with .L odextra.cxx+) ?
One question though ... why do you have odextra derive from od BUT then go ahead and create a odextra on the stack in your loop method.
odextra e;
It is very plausible that the 2 od object (the one in the base of the 'odextra e' and the one on which Loop is being called are stepping on each other (and the 'energy' you copy might not be set at all (while 'maybe' e.energy is).
Cheers,
Philippe.
On 3/31/10 5:49 AM, Roger Mason wrote:
> 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()
>
> *** Break *** segmentation violation
> ...
>
> 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 - 15:49:30 CEST
This archive was generated by hypermail 2.2.0 : Thu Apr 01 2010 - 23:50:01 CEST