Hello again,
I have run into a snag trying to read objects of the following class from ROOT trees:
class particle_event : public TObject
{
public:
particle_event();
~particle_event();
void Clear(Option_t *opt = "");
inline vector<st_track> &getPrimaryElectronPlus(void);
inline UInt_t getNumPrimaryElectronPlus(void) const;
inline vector<st_track> &getPrimaryElectronMinus(void);
inline UInt_t getNumPrimaryElectronMinus(void) const;
inline vector<st_track> &getGlobalElectronPlus(void);
inline UInt_t getNumGlobalElectronPlus(void) const;
inline vector<st_track> &getGlobalElectronMinus(void);
inline UInt_t getNumGlobalElectronMinus(void) const;
inline UShort_t getCentralityClass(void) const;
inline Int_t getEventNum(void) const;
inline Int_t getNTrack(void) const;
inline Double_t getVZ(void) const;
inline void setCentralityClass(const UShort_t a);
inline void setEventNum(const Int_t a);
inline void setNTrack(const Int_t a);
inline void setVZ(const Double_t a);
private:
vector<st_track> mPrimaryElectronPlus; //||
vector<st_track> mPrimaryElectronMinus; //||
vector<st_track> mGlobalElectronPlus; //||
vector<st_track> mGlobalElectronMinus; //||
UShort_t mCentralityClass;
Int_t mEventNum;
Int_t mNTrack;
Double_t mVZ;
ClassDef(particle_event, 1)
};
The writing code seems to work fine (calling Show() on the tree displays all the numbers that were supposed to end up stored) and I have no problems reading fundamental data members, but trying to do anything on any of the vectors causes the interpreter to throw an error.
The reader macro looks as follows:
void treeReadTest(void)
{
gSystem->Load("libMKS"); // this is where particle_event is
TFile *f = new TFile("test.root");
TTree *t4 = (TTree *) f->Get("PicoTree");
particle_event *event = new particle_event();
TBranch *branch = t4->GetBranch("particle_events");
branch->SetAddress(&event);
Int_t nevent = (Int_t) t4->GetEntries();
for (Int_t i = 0; i < nevent; i++) {
branch->GetEntry(i);
cout << "Read event " << event->getEventNum()
<< "\n\tnTrack: " <<event->getNTrack()
<< "\n\tprimary tracks (+/-): " << event->getNumPrimaryElectronPlus() << " / " << event->getNumPrimaryElectronMinus()
<< "\n\tglobal tracks (+/-): " << event->getNumGlobalElectronPlus() << " / " << event->getNumGlobalElectronMinus()
<< '\n' << endl;
if (event->getNumPrimaryElectronMinus() > 0)
cout << "VECT " << event->getPrimaryElectronMinus().size() << endl;
event->Clear();
}
return;
}
and the error in question is shown below:
Processing treeReadTest.C...
Read event 187986
nTrack: 174
primary tracks (+/-): 0 / 1
global tracks (+/-): 0 / 1
Error: Can't call vector<st_track,allocator<st_track> >::size() in current scope treeReadTest.C:28:
Possible candidates are...
(in vector<st_track,allocator<st_track> >)
Error: non class,struct,union object getPrimaryElectronMinus() used with . or -> treeReadTest.C:28:
VECT (class G__CINT_ENDL)192951200
*** Interpreter error recovered ***
This is the end of ROOT -- Goodbye
What is wrong here?