RT stop in TTree->Branch [WinNT)

From: Mariusz Stanczak (MStanczak@usa.net)
Date: Thu Oct 28 1999 - 05:43:46 MEST


The program below used to be a C program that used char[] and which I
decided to convert to using string(s) and fstream(s).  The program logic
remained unchanged but now the program stops on a third trip through the
main while loop (on a line marked with arrow) with the error text included
below and exit code 3.  This is with 2.23.6 on WinNT.
Thanks for any pointers,

/Mariusz

---- error text -----
CustomReAlloc2: oldsize != size
Fatal in <CustomReAlloc2>: storage area overwritten
aborting
Warning in <TWinNTSystem::StackTrace>: this method must be overridden!
---- error text end -----

----- code -----
#include <time.h>
#include <stdlib.h>
#include <stdio.h>
#include <string>
#include <fstream>
#include <iostream>

#include "TFile.h"
#include "TTree.h"
#include "TBenchmark.h"
#include "TROOT.h"

using namespace std;

int main() {
	TROOT root("rif", "ROOT Interface");
	TBenchmark *gBenchmark = new TBenchmark();
	TFile *f_root;
	TTree *tree;
	char *e = 0;
	string f_path = "";
	const char *f_name = "usall.prn";

	e = getenv("DATA_PATH");
	if (e)
		f_path = string(e) + f_name;
	else
		f_path = f_name;

	ifstream f_in(f_path.c_str());
	if (!f_in) {
		cerr << "Cannot open in " << f_path << endl;
		return 1;
	}

	string s = "";
	string prev_s = "";
	string date = "";
	string temp_s = "";
	string fname = "";
	int sequence = 0;
	char stmp[6] = "";
	struct tm t;
	struct {
		Int_t time;
		Float_t fo;
		Float_t fh;
		Float_t fl;
		Float_t fc;
		UInt_t iv;
	} data ;
	data.fo = 0.0;	// force floating point

	//read a line
	while (!f_in.eof()) {
		f_in >> s >> date >> data.fo >> data.fh
			>> data.fl >> data.fc >> data.iv;

		if (s == "")
			continue;

		if (s != prev_s) {
			if (prev_s != "") {
				f_root->Write();
				f_root->Close();
				cout << "File " << fname;
				gBenchmark->Show(prev_s.c_str());
				gBenchmark->Reset();
			}
			prev_s = s;
			gBenchmark->Start(s.c_str());

			sequence += 1;
			sprintf(stmp, "%05.5i", sequence);
			fname = string("F") + stmp + ".data";

			temp_s = s + " price file";
			// these two leak... OK for now (f_root->Open() does not work!)
			f_root = new TFile(fname.c_str(), "RECREATE", temp_s.c_str());
			tree = new TTree(s.c_str(), "");
		}
		sscanf(date.c_str(), "%4d%2d%2d", &t.tm_year, &t.tm_mon,
&t.tm_mday);
		t.tm_year -= 1900;
		t.tm_mon -= 1;
		t.tm_sec = t.tm_min = t.tm_hour = 0;
		data.time = (Int_t)mktime(&t);

		if (data.time == -1) continue;

		tree->Branch(date.c_str(), &data,
				"time/i:fo/F:fh/F:fl/F:fc/F:iv/i");		<=== blows up here
		tree->Fill();
	}
	f_root->Write();
	return 0;
}
----- code end -----



This archive was generated by hypermail 2b29 : Tue Jan 04 2000 - 00:43:41 MET