shtol
December 18, 2017, 7:02am
1
Dear all,
I need to process a tree including objects, discribed in shared library.
I have the following code:
> {
> gSystem->Load("libEvent.so");
>
> gROOT->GetPluginManager()->AddHandler("TVirtualStreamerInfo",
> "*",
> "TStreamerInfo",
> "RIO",
> "TStreamerInfo()");
>
> TFile *f = new TFile("test1.root");
>
> TTree *t = (TTree*)gDirectory->Get("t");
>
> Int_t np;
> t->SetBranchAddress("np",&np);
> std::vector<BEPoint> *data;
> t->SetBranchAddress("fBEPoints",&data);
>
> Long64_t nentries = t->GetEntries();
>
> std:::cout<<"N="<<nentries<<std::endl;
> Long64_t ientry = t->LoadTree(1);
> Int_t nbytes=0;
> nbytes += t->GetEntry(1);
>
> std:::cout<<"np="<<np<<std::endl;
> std:::cout<<"size="<<data->size()<<std::endl;
> }
and the followinf output:
> root [0] .x loadtest.C
> N=1000
> np=2
> Error: illegal pointer to class object data 0x0 3101 loadtest.C:27:
> *** Interpreter error recovered ***
So it seems that data of type Int_t (np) are loaded correctly, but data of type std::vector (data) are not loaded. What is wrong?
Thanks,
Dmitry.
shtol
December 22, 2017, 11:10am
3
Thanks, but this doesn’t help. Now the code is:
> {
> gSystem->Load("libEvent.so");
>
> gROOT->GetPluginManager()->AddHandler("TVirtualStreamerInfo",
> "*",
> "TStreamerInfo",
> "RIO",
> "TStreamerInfo()");
>
> TFile *f = new TFile("test1.root");
>
> TTree *t = (TTree*)gDirectory->Get("t");
>
> Int_t np;
> t->SetBranchAddress("np",&np);
> std::vector<BEPoint> *data = 0;
> t->SetBranchAddress("fBEPoints",&data);
>
> Long64_t nentries = t->GetEntries();
>
> std:::cout<<"N="<<nentries<<std::endl;
> Long64_t ientry = t->LoadTree(1);
> Int_t nbytes=0;
> nbytes += t->GetEntry(1);
>
> std:::cout<<"np="<<np<<std::endl;
> std:::cout<<"size="<<data->size()<<std::endl;
> }
and the output is:
> root [0] .x loadtest.C
> N=1000
> np=2
> Error: illegal pointer to class object data 0x0 3101 loadtest.C:27:
> *** Interpreter error recovered ***
So it seems data are not loaded.
Maybe your tree has no “fBEPoints” branch. Try:
t->Print();
Try also:
if (data) std::cout << "size=" << data->size() << std::endl;
else std::cout << "no data in tree" << std::endl;
BTW. When you post “source code” or “output” here, do remember to enclose them into two lines which contain just three characters ``` (see how your posts have been edited above).
shtol
December 25, 2017, 8:46am
5
The tree contains fBEPoints
> root [2] t->Print()
> ******************************************************************************
> *Tree :t : tree with events *
> *Entries : 100000 : Total = 56172334 bytes File Size = 16856086 *
> * : : Tree compression factor = 3.33 *
> ******************************************************************************
> *Br 0 :np : np/I *
> *Entries : 100000 : Total Size= 401400 bytes File Size = 3269 *
> *Baskets : 13 : Basket Size= 32000 bytes Compression= 122.62 *
> *............................................................................*
> *Br 1 :cnp : cnp/D *
> *Entries : 100000 : Total Size= 802556 bytes File Size = 6078 *
> *Baskets : 26 : Basket Size= 32000 bytes Compression= 131.91 *
> *............................................................................*
> *Br 2 :ncp : ncp/I *
> *Entries : 100000 : Total Size= 401417 bytes File Size = 3282 *
> *Baskets : 13 : Basket Size= 32000 bytes Compression= 122.14 *
> *............................................................................*
> *Br 3 :cncp : cncp/D *
> *Entries : 100000 : Total Size= 802586 bytes File Size = 6104 *
> *Baskets : 26 : Basket Size= 32000 bytes Compression= 131.35 *
> *............................................................................*
> *Br 4 :ntrk : ntrk/I *
> *Entries : 100000 : Total Size= 401434 bytes File Size = 3054 *
> *Baskets : 13 : Basket Size= 32000 bytes Compression= 131.27 *
> *............................................................................*
> *Br 5 :cntrk : cntrk/D *
> *Entries : 100000 : Total Size= 802616 bytes File Size = 6130 *
> *Baskets : 26 : Basket Size= 32000 bytes Compression= 130.80 *
> *............................................................................*
> *Br 6 :ntrkf : ntrkf/I *
> *Entries : 100000 : Total Size= 401451 bytes File Size = 3067 *
> *Baskets : 13 : Basket Size= 32000 bytes Compression= 130.71 *
> *............................................................................*
> *Br 7 :cntrkf : cntrkf/D *
> *Entries : 100000 : Total Size= 802646 bytes File Size = 6156 *
> *Baskets : 26 : Basket Size= 32000 bytes Compression= 130.25 *
> *............................................................................*
> *Br 8 :tpc : tpc/I *
> *Entries : 100000 : Total Size= 401417 bytes File Size = 3029 *
> *Baskets : 13 : Basket Size= 32000 bytes Compression= 132.34 *
> *............................................................................*
> *Br 9 :ctpc : ctpc/D *
> *Entries : 100000 : Total Size= 802586 bytes File Size = 6104 *
> *Baskets : 26 : Basket Size= 32000 bytes Compression= 131.35 *
> *............................................................................*
> *Br 10 :dch : dch/I *
> *Entries : 100000 : Total Size= 401417 bytes File Size = 3029 *
> *Baskets : 13 : Basket Size= 32000 bytes Compression= 132.34 *
> *............................................................................*
> *Br 11 :cdch : cdch/D *
> *Entries : 100000 : Total Size= 802586 bytes File Size = 6104 *
> *Baskets : 26 : Basket Size= 32000 bytes Compression= 131.35 *
> *............................................................................*
> *Br 12 :farich : farich/I *
> *Entries : 100000 : Total Size= 401468 bytes File Size = 3080 *
> *Baskets : 13 : Basket Size= 32000 bytes Compression= 130.17 *
> *............................................................................*
> *Br 13 :cfarich : cfarich/D *
> *Entries : 100000 : Total Size= 802676 bytes File Size = 6182 *
> *Baskets : 26 : Basket Size= 32000 bytes Compression= 129.71 *
> *............................................................................*
> *Br 14 :csi : csi/I *
> *Entries : 100000 : Total Size= 401417 bytes File Size = 3029 *
> *Baskets : 13 : Basket Size= 32000 bytes Compression= 132.34 *
> *............................................................................*
> *Br 15 :ccsi : ccsi/D *
> *Entries : 100000 : Total Size= 802586 bytes File Size = 6104 *
> *Baskets : 26 : Basket Size= 32000 bytes Compression= 131.35 *
> *............................................................................*
> *Br 16 :ifr : ifr/I *
> *Entries : 100000 : Total Size= 401417 bytes File Size = 3029 *
> *Baskets : 13 : Basket Size= 32000 bytes Compression= 132.34 *
> *............................................................................*
> *Br 17 :cifr : cifr/D *
> *Entries : 100000 : Total Size= 802586 bytes File Size = 6104 *
> *Baskets : 26 : Basket Size= 32000 bytes Compression= 131.35 *
> *............................................................................*
> *Br 18 :farichL1 : farichL1/I *
> *Entries : 100000 : Total Size= 401502 bytes File Size = 3106 *
> *Baskets : 13 : Basket Size= 32000 bytes Compression= 129.08 *
> *............................................................................*
> *Br 19 :cfarichL1 : cfarichL1/D *
> *Entries : 100000 : Total Size= 802736 bytes File Size = 6236 *
> *Baskets : 26 : Basket Size= 32000 bytes Compression= 128.59 *
> *............................................................................*
> *Br 20 :farichL3 : farichL3/I *
> *Entries : 100000 : Total Size= 401502 bytes File Size = 3106 *
> *Baskets : 13 : Basket Size= 32000 bytes Compression= 129.08 *
> *............................................................................*
> *Br 21 :cfarichL3 : cfarichL3/D *
> *Entries : 100000 : Total Size= 802736 bytes File Size = 6236 *
> *Baskets : 26 : Basket Size= 32000 bytes Compression= 128.59 *
> *............................................................................*
> *Branch :event *
> *Entries : 100000 : BranchElement (see below) *
> *............................................................................*
> *Br 22 :TObject : *
> *Entries : 100000 : Total Size= 1405949 bytes File Size = 155862 *
> *Baskets : 57 : Basket Size= 32000 bytes Compression= 9.01 *
> *............................................................................*
> *Br 23 :fHeader : *
> *Entries : 100000 : Total Size= 2810305 bytes File Size = 393909 *
> *Baskets : 101 : Basket Size= 32000 bytes Compression= 7.13 *
> *............................................................................*
> *Br 24 :fPrimary : *
> *Entries : 100000 : Total Size= 11838710 bytes File Size = 3405868 *
> *Baskets : 384 : Basket Size= 32000 bytes Compression= 3.47 *
> *............................................................................*
> *Br 25 :fTPCHits : *
> *Entries : 100000 : Total Size= 1406010 bytes File Size = 155633 *
> *Baskets : 57 : Basket Size= 32000 bytes Compression= 9.02 *
> *............................................................................*
> *Br 26 :fDCHHits : *
> *Entries : 100000 : Total Size= 1406010 bytes File Size = 155633 *
> *Baskets : 57 : Basket Size= 32000 bytes Compression= 9.02 *
> *............................................................................*
> *Br 27 :fFRCHits : *
> *Entries : 100000 : Total Size= 1406010 bytes File Size = 155633 *
> *Baskets : 57 : Basket Size= 32000 bytes Compression= 9.02 *
> *............................................................................*
> *Br 28 :fFRCPoints : *
> *Entries : 100000 : Total Size= 1406132 bytes File Size = 156371 *
> *Baskets : 57 : Basket Size= 32000 bytes Compression= 8.98 *
> *............................................................................*
> *Br 29 :fCSIHits : *
> *Entries : 100000 : Total Size= 1406010 bytes File Size = 155633 *
> *Baskets : 57 : Basket Size= 32000 bytes Compression= 9.02 *
> *............................................................................*
> *Br 30 :fIFRHits : *
> *Entries : 100000 : Total Size= 1406010 bytes File Size = 155633 *
> *Baskets : 57 : Basket Size= 32000 bytes Compression= 9.02 *
> *............................................................................*
> *Br 31 :fBEPoints : *
> *Entries : 100000 : Total Size= 18434949 bytes File Size = 11847514 *
> *Baskets : 591 : Basket Size= 32000 bytes Compression= 1.55 *
> *............................................................................*
shtol
December 25, 2017, 9:51am
7
I always used MakeClass. But with this tree I again have a problem:
> //////////////////////////////////////////////////////////
> // This class has been automatically generated on
> // Mon Dec 25 16:49:00 2017 by ROOT version 5.26/00d
> // from TTree t/tree with events
> // found on file: test_newgeom_corrYZ.root
> //////////////////////////////////////////////////////////
>
> #ifndef testclass_h
> #define testclass_h
>
> #include <TROOT.h>
> #include <TChain.h>
> #include <TFile.h>
>
> class testclass {
> public :
> TTree *fChain; //!pointer to the analyzed TTree or TChain
> Int_t fCurrent; //!current Tree number in a TChain
>
> // Declaration of leaf types
> Int_t np;
> Double_t cnp;
> Int_t ncp;
> Double_t cncp;
> Int_t ntrk;
> Double_t cntrk;
> Int_t ntrkf;
> Double_t cntrkf;
> Int_t tpc;
> Double_t ctpc;
> Int_t dch;
> Double_t cdch;
> Int_t farich;
> Double_t cfarich;
> Int_t csi;
> Double_t ccsi;
> Int_t ifr;
> Double_t cifr;
> Int_t farichL1;
> Double_t cfarichL1;
> Int_t farichL3;
> Double_t cfarichL3;
> //Event *event;
> EventHeader fHeader;
> //vector<Primary> fPrimary;
> //vector<TPCHit> fTPCHits;
> //vector<DCHHit> fDCHHits;
> //vector<FRCHit> fFRCHits;
> //vector<FRCPoint> fFRCPoints;
> //vector<CSIHit> fCSIHits;
> //vector<IFRHit> fIFRHits;
> //vector<BEPoint> fBEPoints;
> ...
Most of data, which are objects (not numbers or arrays) are not included in class - only fHeader is included. Why?
Which ROOT version are you using?
This is probably a question to @pcanal as I remember that some older versions had some problems with objects.
If you can use a recent ROOT 6 version, try to “MakeSelector” which should behave better.
shtol
December 25, 2017, 10:02am
9
Current version us ROOT 5.26/00d
shtol
December 25, 2017, 10:06am
11
Just now tried ROOT 5.34/36 - the same situation.
So, try the newest ROOT 6.
If you cannot, post your ROOT file here and I will try to do it.
system
Closed
January 8, 2018, 10:07am
13
This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.