// Tried on: RedHat 7.3 (gcc2.96) and 8.0 (gcc3.2) with ROOT v.3.03/09 and // 3.05/05 compiled from CVS image on 5th June 2003 Hello ROOTers Attached is a simplified version of a script which we have been trying to use in order to read some simulated events, filter them through our detection setup, and write the results in TTrees which we keep in TFiles on disk. I have removed all reference to our own classes so that the example can be tested anywhere - also demonstrating that the problem doesn't come from our code !! ;-) In order to limit the size of the ROOT files, we stop every 100000 events to write the current tree to disk and close the current file, then open a new file with a new tree before continuing. Compilation with ACLiC gives the following error: root [0] .L Example.C+ Info in <TUnixSystem::ACLiC>: creating shared library /home/john/lib//home/john/Desktop/Analysis/ROOT/escano/./Example_C.so /home/john/lib/home/john/Desktop/Analysis/ROOT/escano/filejSOCOc.cxx: In function `int G__filejSOCOc__8_25(G__value*, const char*, G__param*, int)': /home/john/lib/home/john/Desktop/Analysis/ROOT/escano/filejSOCOc.cxx:92: cannot convert `int**' to `TTree**' for argument `2' to `TFile* OpenROOTFile(int, TTree**)' g++: /home/john/lib//home/john/Desktop/Analysis/ROOT/escano/./filejSOCOc.o: No such file or directory Error in <ACLiC>: Compilation failed! Is this normal ? Carrying on regardless, we added the "main()" that you can see commented at the end of the file, compiled with g++: g++ `root-config --cflags --libs` Example.C -o Example.exe (no errors) and ran the resulting executable. It produced the following output: -rw-r--r-- 1 john users 29M Jun 6 20:02 xesn50run1_1.root -rw-r--r-- 1 john users 76K Jun 6 21:28 xesn50run1_2.root -rw-r--r-- 1 john users 126K Jun 6 22:53 xesn50run1_3.root -rw-r--r-- 1 john users 66K Jun 7 00:17 xesn50run1_4.root -rw-r--r-- 1 john users 71K Jun 7 01:41 xesn50run1_5.root -rw-r--r-- 1 john users 74K Jun 7 03:04 xesn50run1_6.root -rw-r--r-- 1 john users 83K Jun 7 04:27 xesn50run1_7.root -rw-r--r-- 1 john users 70K Jun 7 05:49 xesn50run1_8.root -rw-r--r-- 1 john users 66K Jun 7 07:29 xesn50run1_9.root -rw-r--r-- 1 john users 64K Jun 7 08:53 xesn50run1_10.root As you can see, although each file took about the same time to produce (1h30), only the first one contains any events, while the other files contain empty trees. In a small scale test we performed beforehand (read 100 events, changing file every 10 events) all the files/trees contained events. Can anybody see why this should be ? Thanks a lot for any advice. -- John D. Frankland Beam Coordinator GANIL B.P. 55027 14076 CAEN Cedex 05 tel: +33 (0)231454628 fax: +33 (0)231454665 #ifndef __CINT__ #include <iostream> using std::cout; using std::endl; #include "TFile.h" #include "TTree.h" #endif TFile* OpenROOTFile(Int_t fnum, TTree **newtree); void ReadEvents(){ //Read simulated events from a text file, simulate their detection by INDRA and //store the results in a set of ROOT files containing TTree's. A new file/tree is begun //every 100000 events. Int_t filenumber=1; //counter for the ROOT files TTree *tree; TFile *rootfile = OpenROOTFile(filenumber, &tree); tree->Print(); UInt_t nevents = 999999; while( nevents-- ) //loop over all events in file { //...read an event from some file, process it, and then ... tree->Fill(); if(!(nevents%1000)) cout << "Events left " << nevents << endl; if(!(nevents%100000)&&nevents) { //Every 100000 events, write the current tree and close the file, //open a new file with a new tree cout << "Closing file : " << rootfile->GetName() << endl; tree->Write(); rootfile->Close(); filenumber++; //increment file counter rootfile = OpenROOTFile(filenumber, &tree);//open new file } } tree->Write(); rootfile->Close(); } TFile* OpenROOTFile(Int_t fnum, TTree **newtree) { //Open a file with name "fname", and create a TTree //Return pointer to the file, and the pointer to the tree Char_t filename[30]; sprintf(filename,"xesn50run1_%d.root",fnum); //open file for writing TFile *f = new TFile(filename,"RECREATE"); f->cd(); cout << "File opened : " << f->GetName() << endl; //create TTree *newtree = new TTree("t4","Simulated and Filtered events"); //branch definitions... return f; } int main() { ReadEvents(); return 0; }
This archive was generated by hypermail 2b29 : Thu Jan 01 2004 - 17:50:12 MET