Hi Rooters,
Again a stupid problem
I read 2 ASCII files in 2 different ways and I show the data on the screen, but when I create an object (thant later I will store in a ROOT file an clean) and I try to fill the members inside the āwhileā loop that Iām using to read, the output ROOT file contains only crap when Iām trying to recover what my new ROOT file contains. I have tried almost all the possibilities: I had created one function to fill the object, I had store the values in a vector tha is being read by an external āforā loop, I had change the shape of the objectā¦ always crap, Iām storing different numbers that Iām seein in my screen!
Here you have the part of the code that I use to create the output ROOT file (a part of the main):
[code]ā¦
TFile hfile(RootOut,āRECREATEā,āData from Raw filesā);
ā¦
ifstream infile;
ā¦
//trees and branches---------------------------
CRawData *entry = 0; //the object āentryā, the class CRawData
TTree *tree = new TTree(āPinoā,āRAW data treeā);
tree->Branch(āentriesā,āCRawDataā,&entry,16000,2);
//opening the files-------------------------------------
FILE *file = fopen(RawIn, ārā);
infile.open(SlowCIn);
Int_t ent = 0; //number of entries
while (!feof(file)) {
reading(file,Traw,Trigch,Datach,th1,th2,th3); //function that reads from one file
cout << "Raw Time passed " << Traw << " TrigCh " << Trigch << endl;
// here I obtein proper values
entry = new CRawData(); // the object again
//reading from SlowCIn
infile >> TimeStart >> Time >> Gas_Pres >> Gas_Temp >> GasTA >> GasTB >> O2cont >> HVFcage;
// put the data on the screen
cout << " Times " << TimeStart << " " << Time << endl;
cout << " Gas P and T " << Gas_Pres << " " << Gas_Temp << endl;
cout << " TA and TB " << GasTA << " " << GasTB << endl;
cout << " O2 and HVFcage " << O2cont << " " << HVFcage << endl;
//building a spectrum
making(th1,th2,th3,array);
for (int i=0;i<1024; i++){
//cout << " spectrum bin : " << array[i] << endl;
}
//store the data in a CRawData object-------------------
build(TimeStart,Time,Gas_Pres,Gas_Temp,GasTA,GasTB,O2cont,HVFcage,array,entry);
tree->Fill();
ent++;
entry->Clear();
}
tree->Print();
cout << " Number of entries : " << ent << endl;
infile.close();
printf( āReading File SlowCIn Closed\nā );
//āSLowCInā closed---------------------------------------
if( !fclose(file) )
printf( āReading File RawIn Closed\nā );
else
{
printf( āError: file NOT CLOSED\nā );
return 1;
}
hfile.Write();
hfile.Close();
cout<< " Writting File RootOut Closed "<< endl;
-------------------------------------------------------[/code]
With this Iām expecting a Tree with a branch and lot of leaves with serialized information about the members of my object.
After that I try to read one leaf (for example āGasTAā) with this program:
[code]---------------------------------------------------------
int main(int argc, char **argv) //main program
{
//the application
TApplication *myApp = new TApplication(āmyAppā,&argc, argv);
TFile *f= new TFile(āalgo.rootā);
TTree Pino = (TTree)f->Get(āPinoā);
CRawData entry = new CRawData();
Pino->SetBranchAddress(āentriesā,&entry);
Pino->SetBranchStatus("",1);
Int_t eventos = (int)Pino->GetEntries();
cout << āEvents in the file :ā << eventos << endl;
Int_t muestra;
cout << āEvents to analyze ?:ā << endl;
cin >> muestra;
for(Int_t i=0;i< muestra;i++){
if (i >0){
entry->Clear();}
if (Pino->GetEvent(i)<0){
cout << "la cagaste !" << endl;
continue;
}
cout << "Gas TA" << entry->getGasTB() << endl; //here I'm reading
}//end for
//close the file
f->Close();
//run myApp object
myApp->Run();
return 0;
}// end of main
------------------------------------------------------[/code]
Well, this is a long post, I know, but surely the answer will be short. I need to solve it, so, if I solve it before receiving an answer, I will post the solution
Thanks in advance!
Cheers!