Hi ROOTer's,
I have a problem when I try to run the following code in ROOT.
I can't figure out what it is. Here is what I am going to do.
I have root file called "first.root" and another root file "second.root".
Both files have the same name "EVENT" for the Tree.
This is what I want to do. First I load the first.root file. Then for
every event of first.root file I need to load the second.root file
and get the event infor for the same event number as first.
When I run the following code, It is ok for about 250 events and then
stop giving the message "Segmentation violation".
What is wrong with code?
Is there any example code somewhere?
I am using root version 3.00/06 on a RH7.0 Linux machine.
Thank you in advance.
R. Guna
email: phguna@feynman.phys.subr.edu
==========================================================================
{
Int_t evno; //event no
ULong_t time; //time in sec
UShort_t msec; //time in half mili. sec
UShort_t evttype; //event type
UShort_t subtype; //event sub type
UShort_t tt; //trigger type
UInt_t raw_hits; //No of hits of Raw Data
UShort_t raw_addr[6248]; //ElePackedID
UShort_t raw_adc[6248]; //RawADC
UInt_t cal_hits; //No of hits of Calibrated Data
UInt_t cal_id[5002]; //PhyPackedID
Float_t cal_ed[5002]; //Ed
// USer Defined
Int_t evnt;
UShort_t evnttype;
TFile *f = new TFile("first.root");
// Read Tree named "EVENT" in memory.
// Tree pointer is assigned the same name.
TTree *EVENT = (TTree *)f->Get("EVENT");
// Access each branch
TBranch *bevno = (TBranch *)EVENT->GetBranch("EVNO");
TBranch *btime = (TBranch *)EVENT->GetBranch("TIME");
TBranch *bmsec = (TBranch *)EVENT->GetBranch("MSEC");
TBranch *bevttype = (TBranch *)EVENT->GetBranch("EVTTYPE");
TBranch *bsubtype = (TBranch *)EVENT->GetBranch("SUBTYPE");
TBranch *btt = (TBranch *)EVENT->GetBranch("TT");
TBranch *braw_hits = (TBranch *)EVENT->GetBranch("RAW_HITS");
TBranch *bcal_hits = (TBranch *)EVENT->GetBranch("CAL_HITS");
TBranch *braw_addr = (TBranch *)EVENT->GetBranch("RAW_ADDR");
TBranch *braw_adc = (TBranch *)EVENT->GetBranch("RAW_ADC");
TBranch *bcal_id = (TBranch *)EVENT->GetBranch("CAL_ID");
TBranch *bcal_ed = (TBranch *)EVENT->GetBranch("CAL_ED");
// Set addresses
bevno->SetAddress(&evno);
btime->SetAddress(&time);
bmsec->SetAddress(&msec);
bevttype->SetAddress(&evttype);
bsubtype->SetAddress(&subtype);
btt->SetAddress(&tt);
braw_hits->SetAddress(&raw_hits);
bcal_hits->SetAddress(&cal_hits);
braw_addr->SetAddress(&raw_addr[0]);
braw_adc->SetAddress(&raw_adc[0]);
bcal_id->SetAddress(&cal_id[0]);
bcal_ed->SetAddress(&cal_ed[0]);
// variables for unpacking cal_id(physical ID)
unsigned ID1,ID2,ID3,ID4;
Int_t k;
// write to a file
Int_t nbytes=0;
Int_t nentries = EVENT->GetEntries();
for (Int_t i=0; i<nentries;i++) {
nbytes += EVENT->GetEvent(i);
cout<<" Event Number: "<<i<<endl;
// loading the second root file to search for
// corrosponding event
UInt_t evno1 ; //event no
UInt_t time1 ; //time in sec
UShort_t msec1 ; //time in half mili. sec
UShort_t evttype1 ; //event type
UShort_t subtype1 ; //event sub type
UShort_t tt1 ; //trigger type
UShort_t raw_adc1[4][5][5][7][16] ;
TFile *f2 = new TFile("second.root") ;
// Read Tree named "EVENT" in memory.
// Tree pointer is assigned the same name.
TTree *EVENT = (TTree *)f2->Get("EVENT") ;
// Access each branch
TBranch *bevno = (TBranch *)EVENT->GetBranch("EVNO") ;
TBranch *btime = (TBranch *)EVENT->GetBranch("TIME") ;
TBranch *bmsec = (TBranch *)EVENT->GetBranch("MSEC") ;
TBranch *bevttype = (TBranch *)EVENT->GetBranch("EVTTYPE") ;
TBranch *bsubtype = (TBranch *)EVENT->GetBranch("SUBTYPE") ;
TBranch *btt = (TBranch *)EVENT->GetBranch("TT") ;
TBranch *braw_adc = (TBranch *)EVENT->GetBranch("RAW_ADC") ;
// Set addresses
bevno->SetAddress(&evno1) ;
btime->SetAddress(&time1) ;
bmsec->SetAddress(&msec1) ;
bevttype->SetAddress(&evttype1) ;
bsubtype->SetAddress(&subtype1) ;
btt->SetAddress(&tt1) ;
braw_adc->SetAddress(&raw_adc1[0][0][0][0][0]) ;
// dummy varuables
Int_t ii, j, k, l, m, n ;
Int_t nbytes1=0;
Int_t nentries1 = EVENT->GetEntries();
ii = i;
nbytes += EVENT->GetEvent(ii);
cout<<" 2 event "<<ii<<endl;
for(j=0; j<4; j++) {
for(k=1; k<3; k++) {
for(l=0; l<5; l++) {
for(m=0; m<7; m++) {
for(n=0; n<16; n++) {
if(raw_adc1[j][k][l][m][n]!=0) {
cout<<j<<" "<<k<<" "<<l<<" "<<m<<" "<<n<<" "
<<raw_adc1[j][k][l][m][n]<<endl;
} //if
}//n
}
}
}
} //j
// closing second root file
f2->Close();
} // i
f->Close();
} //end
This archive was generated by hypermail 2b29 : Thu Jan 01 2004 - 17:50:08 MET