problem writing TTree

From: Dan Holmes <dan.holmes_at_cern.ch>
Date: Tue, 29 Jan 2008 16:56:05 +0100


Hi ROOT support,

..sorry if i missed this in some faqs somewhere..

I have problems with some code that fills and writes a tree. It was working ok on slc3/root 5.04, (linked afs version) for many years but now i have upgraded to slc4, downloaded binaries (and am trying 5.16, 5.18).

I have attached my set of .cpp files (makeTree wraps readData which uses the rootTree object). I suspect you don't want to look at any of them apart from rootTree.cc.

The whole thing compiles ok.::
g++ -o makeTree.exe makeTree.cpp `root-config --cflags --libs` The problem comes when the destructor to readData is called and rootTree class tries to do TTree*->Write(). I get the horrible error string attached.

Anyone know what i'm doing wrong or have any pointers??

cheers,

Dan.

#ifndef readData_h
#define readData_h

#include "dictionary.cc"
#include "rootTree.cc"

using namespace std;
typedef map <string,unsigned int> si_map;

class readData {

public:

readData(string* pathToFile);
~readData();

void readDataFile(int maxNumEvts);// this just wraps the readEvent function, int defines max num evts, 0 is all!

private:
void readEvent();// this is the big one, it controlls the flow of reading from data and writing to root

inline void readEventHeaders();
inline void readDataBlockHeaders();

inline void readMEDataRecords();
inline void readMBDataRecords();
inline void readSPDataRecords();
inline void readEventTrailers();
inline void readBlockCounters();

inline std::ifstream* openFileStream(std::string* FileName);//danger function; you have to delete the pointer it returns inline void readHexWord();

ifstream* dataStream;
unsigned int hexwd;
dictionary* dictionary_;
rootTree* rootTree_;

//maps of all of the data words:(best to allocate memory once, with construction)

//Event Headers:
si_map HD1a_map, HD1b_map, HD1c_map, HD1d_map, HD2a_map, HD2b_map, HD2c_map, HD2d_map;

//Block of Counters:
si_map BCa_map, BCb_map, BCc_map, BCd_map;

//Data block headers:
si_map BH1a_map, BH1b_map, BH1c_map, BH1d_map, BH2a_map, BH2b_map, BH2c_map, BH2d_map;

// ME Data Records
si_map MEa_map, MEb_map, MEc_map, MEd_map;

// MB Data Records
si_map MBa_map, MBb_map, MBc_map, MBd_map;

// SP Data Records
si_map SPa_map, SPb_map, SPc_map, SPd_map;

// Event Trailers
si_map TR1a_map, TR1b_map, TR1c_map, TR1d_map, TR2a_map, TR2b_map, TR2c_map, TR2d_map;

};

#endif

#ifndef rootTree_h
#define rootTree_h

#include "TTree.h"
#include "TFile.h"

#include <iostream>
#include <map>

using namespace std;
typedef map <string,unsigned int> si_map;

class rootTree {

public:

rootTree();
~rootTree();

TTree* getTree();

void fillEventHeader(si_map HD1a_map, si_map HD1b_map, si_map HD1c_map, si_map HD1d_map,

                        si_map HD2a_map, si_map HD2b_map ,si_map HD2c_map, si_map HD2d_map);

void fillBlockCounter(si_map BCa_map, si_map BCb_map, si_map BCc_map, si_map BCd_map);

void fillDataBlockHeader(si_map BH1a_map, si_map BH1b_map, si_map BH1c_map, si_map BH1d_map,

			si_map BH2a_map, si_map BH2b_map, si_map BH2c_map, si_map BH2d_map, 
			int bx);

void fillMEDataRecord(si_map MEa_map, si_map MEb_map, si_map MEc_map, si_map MEd_map,
			int bx, int LINK);

void fillMBDataRecord(si_map MBa_map, si_map MBb_map, si_map MBc_map, si_map MBd_map,
			int bx, int whichMB);
			
void fillSPDataRecord(si_map SPa_map, si_map SPb_map, si_map SPc_map, si_map SPd_map, 
			int bx, int mode);

void fillEventTrailer(si_map TR1a_map, si_map  TR1b_map, si_map  TR1c_map, si_map TR1d_map,
			si_map  TR2a_map, si_map  TR2b_map, si_map  TR2c_map, si_map  TR2d_map);

private:

TTree* tree;
TFile* file;

bool debug;

// Tree variables::
//indexes in vbles are the BX number (1->7) within L1A window and the muon number(1->15) in the bx

   Int_t L1ANumber, L1A_BXN;
   Int_t quality[8][16], cscID[8][16], wireGP[8][16], CLCT_PAT_ID[8][16], CLCT_PAT[8][16], L_R_bit[8][16]; 
   Int_t ME_BXN[8][16], BC0[8][16];
   
   Int_t Phi[8][4], CHRG[8][4], ETA[8][4], del12Phi[8][4], del23Phi[8][4], sign[8][4];
   Int_t MS_ID[8][4], MB_ID[8][4], ME4_ID[8][4], ME3_ID[8][4], ME2_ID[8][4], ME1_ID[8][4] ;    Int_t MB_TBIN[8][4], ME4_TBIN[8][4], ME3_TBIN[8][4], ME2_TBIN[8][4], ME1_TBIN[8][4];    

   Int_t SynchErrors[8], validPatternLinks[8], VQa[8], VQd[8];    

   Int_t OC, TC;

//DT data vbles: indexes are bx (1->7) and whichMB (1==MBa, 2==MBd)   Int_t quality_MB[8][3], phi_bend_MB[8][3], BC0_MB[8][3], BXN0_MB[8][3], BXN1_MB[8][3], phi_MB[8][3], MB_BXN[8][3];   Int_t FLAG[8][3];
};

#endif

#include "readData.cc"
#include "TTree.h"

using namespace std;

int main(int argc, char* argv[]){

string* pathToFile = new string();

if (argc>1){

        pathToFile -> insert(0,const_cast<const char*>(argv[1]));    }
   else{

   	cout<<"please supply full path to dat data file"<<endl;
   	exit(0);

   }    

 // int numEvts = 0;//will run over all evts    int numEvts = 50000; //will run over first 20k

   readData* readData_ = new readData(pathToFile);    readData_ -> readDataFile(numEvts);

   delete readData_;
   delete pathToFile;
}

Received on Tue Jan 29 2008 - 16:56:10 CET

This archive was generated by hypermail 2.2.0 : Thu Jan 31 2008 - 11:50:01 CET