[ROOT] tfile->Write() kills other class members

From: Patrick Marks (pmarks@gmail.com)
Date: Tue Jun 01 2004 - 15:03:00 MEST


I'm working on a Visual c++ data acquistion program and am storing my
data to a root file.  An object, which does not inherit from a root
object manages the data taking, and contains pointers to a TTree,
TFile, the DAQ control structures, and a 'sync' struct written to by
another thread that controls the data taking.  THe control thread
inherits from TGMainFrame.  Everything works, data is written to my
root file. The problem is that when I call tfile->Close() or
tfile->Write() from the DAQ object it clobbers the other members of
the class.  Below is a brief outline of my code. Any ideas why writing
or closing the TFile interferes with my object -- the object ownership
rules don't seem to suggest that the objects will be owned by the
file, though i can't tell for sure.  Thanks for any help!

Patrick Marks

class MyGUI : TGMainFrame {

  MyDAQ *daq;
  struct sync *control;


void MyGUI::DoDAQ() {

  daq = new MyDAQ();
  control->status = START;
  // Some code to start MyDAQ::Run in a new thread


clas MyDAQ {

  TFile *tfile;
  TTree *ttree;
  MyEvent *ev;   // Inherits from TObject
  struct sync *contol;
 // Some DAQ related members...

void MyDAQ::Run() {


while(CheckControl()){     // look at *control
  GetData();  // Fills ev

tfile->Write();  // the sync & tfile member pointers are  changed to
invalid ptrs by this line.
                    // same thing happens if i call tfile->Close() instead 

tfile->Close()                        // now this segfaults
sync->status = STOPPED;   // or this does (whichever comes first)


This archive was generated by hypermail 2b29 : Sun Jan 02 2005 - 05:50:08 MET