More information on this package is here.
//Begin_Html <!--
/* -->
<h1>TNT10Reader</h1>
<p>
This clas mimicks the behavior of a TChain object, but is capable
of reading the NTuple-10 format instead of native root formats.
</p>
<b>Huge Wopping Warning:</b><br>
When used for certain operations without an output file open,
this class will read the ENTIRE set of HBOOK files and stick all
of its contents into one Huge Wopping TChain. The result is that
the root.exe will eat a serious amount of memory (~1.2 Gb for 2 nt files)
This will cause your system to start swapping and everything will stop
to a crawl (especially X) leaving your system "hung" for a long time.
<b>You want to have a TFile open for writing to prevent this.</b> It will
be MUCH MUCH faster, and when you close the file, you have a root version
of the ntuple.
A different version of an NT10Reader could NOT make a TTree, would not
allow you to write a file, but it would read an ntuple faster without
having a file open. This would be faster.... (Let me know if you write one.)
</p>
<b>Important Note:</b>
<p>
Since the NT10 ntuple is NOT a stable definition, you (someone)
will need to adopt this class for each run period (cooking code version).
The adoption is fairly straight forward.
The version is in the include file NT10_E2b.h in I_VERSION and will be
reported to you with a GetReaderType() call.
Adoptiong to a different NT10 version requires modification of NT10_E2b.h
see instructions in that file.
</p><p>
<b>WARNING:</b><br>
Since the clas inherits from TChain all the calls to TChain methods
will exist, however they may not function! Quite a few should be
over-written to function, some *may* work just as is....
As I put more effort into this clas, more and more of it will.
</p><p>
This class "borrows" heavily from THbookFile and THbookTree
</p><p>
<h3>Improvements needed:</h3>
<ol>
<li> Get the runnumber from the file name and store it.</li>
<li> TESTING </li>
</ol>
<pre>
<!-- */
// --> End_Html
#ifdef NTUPLEMAKER
#include "NT10_NtupleMaker.h"
#else
#include "NT10_E2b.h"
#endif
#include "TNT10Reader.h"
#include "Hbook_interface.h"
Bool_t TNT10Reader::fgPawInit = kFALSE;
Int_t *TNT10Reader::fgLuns = 0;
TNT10Reader::TNT10Reader(const char *name,const char *title): TChain(name,title){
fNtNum = 10;
fNRun=0;
fHbookLun = 0;
fDebug_Mode=0x0;
fReadSequential = kTRUE;
fNtLastRead=-1;
fCurrentEvent = -1;
fEvntHeader = NULL;
fcaEVNTStore=NULL;
fcaECPBStore=NULL;
fcaSCPBStore=NULL;
fcaDCPBStore=NULL;
fcaCCPBStore=NULL;
fcaLCPBStore=NULL;
fEVNT = NULL;
fDCPB = NULL;
fECPB = NULL;
fSCPB = NULL;
fCCPB = NULL;
fLCPB = NULL;
fTree = new TTree(this->TChain::GetName(),this->TChain::GetTitle());
fTree->SetMaxTreeSize(21474836480ULL);
gROOT->GetListOfBrowsables()->Add((TChain *)(this),this->TChain::GetName());
InitBanks();
InitClones();
InitBranches();
if(!fgPawInit){
Int_t pawc_size = PAWC_SIZE;
hlimit(pawc_size);
fgPawInit = kTRUE;
fgLuns = new Int_t[10];
for (Int_t i=0;i<10;i++) fgLuns[i] = 0;
cerr << "PAW Space initialized.\n";
}
cerr << "TNT10Reader init ok.\n";
}
TNT10Reader::~TNT10Reader(){
if(fEvntHeader) delete fEvntHeader;
if(fcaEVNTStore)delete fcaEVNTStore;
if(fEVNT) delete fEVNT;
if(fcaDCPBStore)delete fcaDCPBStore;
if(fDCPB) delete fDCPB;
if(fcaECPBStore)delete fcaECPBStore;
if(fECPB) delete fECPB;
if(fcaSCPBStore)delete fcaSCPBStore;
if(fSCPB) delete fSCPB;
if(fcaCCPBStore)delete fcaCCPBStore;
if(fCCPB) delete fCCPB;
if(fcaLCPBStore)delete fcaLCPBStore;
if(fLCPB) delete fLCPB;
if(fTree){
fTree->Delete("");
cerr << "Tree deleted.\n";
fTree=NULL;
}
if(fgInstanceCount==0){
}
}
TString TNT10Reader::GetReaderType(){
return( TString("NT10Reader ")+TString(I_VERSION));
}
Int_t TNT10Reader::Add(const char *name,Int_t nentries){
if (strchr(name,'*') == 0) {
return AddFile(name,nentries);
}
Int_t nf = 0;
char aname[2048];
strcpy(aname,name);
char *dot = (char*)strstr(aname,".hbook");
const char *behind_dot_root = 0;
if (dot) {
if (dot[5] == '/') behind_dot_root = dot + 6;
*dot = 0;
}
char *slash = strrchr(aname,'/');
if (slash) {
*slash = 0;
slash++;
strcat(slash,".hbook");
} else {
strcpy(aname,gSystem->WorkingDirectory());
slash = (char*)name;
}
const char *file;
void *dir = gSystem->OpenDirectory(gSystem->ExpandPathName(aname));
if (dir) {
TRegexp re(slash,kTRUE);
while ((file = gSystem->GetDirEntry(dir))) {
if (!strcmp(file,".") || !strcmp(file,"..")) continue;
TString s = file;
if (strcmp(slash,file) && s.Index(re) == kNPOS) continue;
if (behind_dot_root != 0 && *behind_dot_root != 0)
nf += AddFile(Form("%s/%s/%s",aname,file,behind_dot_root),TChain::kBigNumber);
else
nf += AddFile(Form("%s/%s",aname,file),TChain::kBigNumber);
}
gSystem->FreeDirectory(dir);
}
return nf;
}
Int_t TNT10Reader::AddFile(const char *name,Int_t nentries){
char *treename = (char*)TChain::GetName();
if (fNtrees+1 >= fTreeOffsetLen) {
fTreeOffsetLen *= 2;
Long64_t *trees = new Long64_t[fTreeOffsetLen];
for (Int_t i=0;i<=fNtrees;i++) trees[i] = fTreeOffset[i];
delete [] fTreeOffset;
fTreeOffset = trees;
}
Int_t nch = strlen(name) + strlen(treename);
char *filename = new char[nch+1];
strcpy(filename,name);
Int_t pksize = 0;
if (nentries <= 0) {
Open(filename);
if (IsZombie()) {
delete [] filename;
return 0;
}
nentries = GetNTEntries();
pksize = TChain::kBigNumber;
}
if (nentries > 0) {
if (nentries < TChain::kBigNumber) {
fTreeOffset[fNtrees+1] = fTreeOffset[fNtrees] + nentries;
fEntries += nentries;
} else {
fTreeOffset[fNtrees+1] = TChain::kBigNumber;
fEntries = nentries;
}
fNtrees++;
TChainElement *element = new TChainElement(treename,filename);
element->SetPacketSize(pksize);
element->SetNumberEntries(nentries);
fFiles->Add(element);
} else {
TChain::Warning("Add","Adding Tree with no entries from file: %s",filename);
}
delete [] filename;
return 1;
}
Double_t TNT10Reader::Compute_Entries(){
TChainElement *file;
fTreeOffset[0]=0;
fEntries=0;
for(Int_t i=0;i<fFiles->GetEntries();i++){
file = (TChainElement*)fFiles->At(i);
if(file->GetEntries()>=TChain::kBigNumber){
if(Open(file->GetTitle())){
file->SetNumberEntries(fNevents);
Close();
}
}
fTreeOffset[i+1]= fTreeOffset[i]+fNevents;
fEntries += fNevents;
}
return(fEntries);
}
Int_t TNT10Reader::Draw(const char *varexp, const char *selection, Option_t *option,Int_t nentries, Int_t firstentry)
{
if (LoadTree(firstentry) < 0) return 0;
return TTree::Draw(varexp,selection,option,nentries,firstentry);
}
GetEntries_return_t TNT10Reader::GetEntries() const{
if (fEntries >= (Stat_t)TChain::kBigNumber) {
((TNT10Reader *)this)->Compute_Entries();
}
return(fEntries);
}
GetEntries_return_t TNT10Reader::GetEntriesFast() const{
return(fEntries);
}
Int_t TNT10Reader::GetEntry(Int_t entry, Int_t getall){
Int_t local_entry;
if(entry<0){
local_entry = fReadEntry+1;
}else{
local_entry = entry;
}
if(LoadTree(local_entry)<0)return(0);
return(fTree->GetEntry(fReadEntry,getall));
}
Int_t TNT10Reader::Next(){
Int_t status = kNOERR;
if(fCurrentEvent >= GetEntriesFast()-1){
if(fDebug_Mode&kDBG_Info) cout << "TNT10Reader::Next : End of Event Entries Reached !" << endl;
if(fDebug_Mode & kDBG_Error)cout << "TNT10Reader::Next : End of Event Entries Reached !" << endl;
status = kERR_end_of_file;
} else {
CleanEventClones();
GetEntry(++fCurrentEvent);
}
return status;
}
Int_t TNT10Reader::Fill_Tree_from_Paw(){
Fill_HEADER();
Fill_EVNT();
Fill_DCPB();
Fill_ECPB();
Fill_SCPB();
Fill_CCPB();
Fill_LCPB();
Int_t nbytes = fTree->Fill();
if(fDebug_Mode>10){
cerr << "Tree stored " << nbytes << " bytes into baskets.\n";
}
return(nbytes);
}
void TNT10Reader::Fill_HEADER(void){
fEvntHeader->NRun = fNRun;
fEvntHeader->NEvent = nt10.evntid;
fEvntHeader->Time = 0;
fEvntHeader->Type = nt10.evntype;
fEvntHeader->ROC = 0;
fEvntHeader->EvtClas = nt10.evntclas;
fEvntHeader->TrigBits = 0;
fEvntHeader->EStatus = nt10.evstat;
fEvntHeader->TrgPrs = nt10.evntclas;
fEvntHeader->NPGP = nt10.gpart + 100*nt10.npart;
fEvntHeader->FC = nt10.q_l;
fEvntHeader->FCG = nt10.q_l;
fEvntHeader->TG = nt10.t_l;
fEvntHeader->STT = nt10.tr_time;
#ifdef NT10_MAKER
fEvntHeader->RF1 = nt10.rf_time1;
fEvntHeader->RF2 = nt10.rf_time2;
#else
fEvntHeader->RF1 = nt10.rf_time;
fEvntHeader->RF2 = nt10.rf_time;
#endif
fEvntHeader->Latch1 = 0;
#ifdef NT10_E2b
fEvntHeader->Helicity_Scaler = nt10.hlsc;
fEvntHeader->Interrupt_Time = nt10.intt;
fEvntHeader->Level2 = nt10.l2bit;
fEvntHeader->Level3 = nt10.l3bit;
#else
fEvntHeader->Helicity_Scaler = 0;
fEvntHeader->Interrupt_Time = 0;
fEvntHeader->Level2 = 0;
fEvntHeader->Level3 = 0;
#endif
}
void TNT10Reader::Fill_EVNT(void){
for(Int_t ievnt=0;ievnt< nt10.gpart; ievnt++){
if(fDebug_Mode>10){
cerr << "Storing EVNT entry number " << ievnt << endl;
}
fEVNT->Id = nt10.id[ievnt];
fEVNT->Charge = (UChar_t) nt10.q[ievnt];
fEVNT->Betta = nt10.b[ievnt];
fEVNT->Px = nt10.p[ievnt]*nt10.cx[ievnt];
fEVNT->Py = nt10.p[ievnt]*nt10.cy[ievnt];
fEVNT->Pz = nt10.p[ievnt]*nt10.cz[ievnt];
fEVNT->X = nt10.vx[ievnt];
fEVNT->Y = nt10.vy[ievnt];
fEVNT->Z = nt10.vz[ievnt];
fEVNT->Dcstat = (UChar_t)nt10.dc[ievnt];
fEVNT->Ccstat = (UChar_t)nt10.cc[ievnt];
fEVNT->Scstat = (UChar_t)nt10.sc[ievnt];
fEVNT->Ecstat = (UChar_t)nt10.ec[ievnt];
fEVNT->Lcstat = (UChar_t)nt10.lec[ievnt];
fEVNT->Status = (UChar_t)nt10.stat[ievnt];
TClonesArray &tEVNTBank = *fcaEVNTStore;
new(tEVNTBank[fnEVNT_Store++]) TEVNTClass(fEVNT);
}
}
void TNT10Reader::Fill_DCPB(void){
for(Int_t idc=0;idc< nt10.dc_part; idc++){
if(fDebug_Mode>10){
cerr << "Storing DC entry number " << idc << endl;
}
fDCPB->Sctr = nt10.dc_sect[idc]*100 + nt10.dc_trk[idc];
fDCPB->X_sc = (Float_t)nt10.dc_xsc[idc];
fDCPB->Y_sc = (Float_t)nt10.dc_ysc[idc];
fDCPB->Z_sc = (Float_t)nt10.dc_zsc[idc];
fDCPB->Cx_sc = (Float_t)nt10.dc_cxsc[idc];
fDCPB->Cy_sc = (Float_t)nt10.dc_cysc[idc];
fDCPB->Cz_sc = (Float_t)nt10.dc_czsc[idc];
#ifdef NT10_E2b
fDCPB->X_ec = (Float_t)nt10.dc_vx[idc];
fDCPB->Y_ec = (Float_t)nt10.dc_vy[idc];
fDCPB->Z_ec = (Float_t)nt10.dc_vz[idc];
fDCPB->Th_cc =(Float_t)nt10.dc_vr[idc]; ;
#else
fDCPB->X_ec = (Float_t)nt10.dc_xec[idc];
fDCPB->Y_ec = (Float_t)nt10.dc_yec[idc];
fDCPB->Z_ec = (Float_t)nt10.dc_zec[idc];
fDCPB->Th_cc =(Float_t)nt10.dc_thcc[idc]; ;
#endif
fDCPB->Chi2 = (Float_t)nt10.dc_c2[idc];
fDCPB->Status = (Int_t)nt10.dc_stat[idc];
TClonesArray &tDCPBBank = *fcaDCPBStore;
new(tDCPBBank[fnDCPB_Store++]) TDCPBClass(fDCPB);
}
}
void TNT10Reader::Fill_ECPB(void){
for(Int_t iec=0;iec< nt10.ec_part; iec++){
if(fDebug_Mode>10){
cerr << "Storing EC entry number " << iec << endl;
}
fECPB->Scht=(Int_t)(nt10.ec_sect[iec]*100+nt10.ec_whol[iec]);
fECPB->Etot=(Float_t)nt10.etot[iec];
fECPB->Ein =(Float_t)nt10.ec_ei[iec];
fECPB->Eout=(Float_t)nt10.ec_eo[iec];
fECPB->Time=(Float_t)nt10.ec_t[iec];
fECPB->Path=(Float_t)nt10.ec_r[iec];
fECPB->X =(Float_t)nt10.ech_x[iec];
fECPB->Y =(Float_t)nt10.ech_y[iec];
fECPB->Z =(Float_t)nt10.ech_z[iec];
fECPB->M2_hit=(Float_t)nt10.ec_m2[iec];
fECPB->M3_hit=(Float_t)nt10.ec_m3[iec];
fECPB->M4_hit=(Float_t)nt10.ec_m4[iec];
fECPB->Innstr=(Int_t)nt10.ec_inst[iec];
fECPB->Outstr=(Int_t)nt10.ec_oust[iec];
fECPB->Chi2ec=(Float_t)nt10.ec_c2[iec];
fECPB->Status=(Int_t)nt10.ec_stat[iec];
TClonesArray &tECPBBank = *fcaECPBStore;
new(tECPBBank[fnECPB_Store++]) TECPBClass(fECPB);
}
}
void TNT10Reader::Fill_SCPB(void){
for(Int_t isc=0;isc< nt10.sc_part; isc++){
if(fDebug_Mode>10){
cerr << "Storing SC entry number " << isc << endl;
}
fSCPB->Scpdht=(Int_t) (nt10.sc_sect[isc]*10000+
nt10.sc_pd[isc] *100+
nt10.sc_hit[isc]);
fSCPB->Edep= (Float_t) nt10.edep[isc];
fSCPB->Time= (Float_t) nt10.sc_t[isc];
fSCPB->Path= (Float_t) nt10.sc_r[isc];
fSCPB->Chi2sc=(Float_t) nt10.sc_c2[isc];
fSCPB->Status=(Int_t ) nt10.sc_stat[isc];
TClonesArray &tSCPBBank = *fcaSCPBStore;
new(tSCPBBank[fnSCPB_Store++]) TSCPBClass(fSCPB);
}
}
void TNT10Reader::Fill_CCPB(void){
for(Int_t icc=0;icc< nt10.cc_part; icc++){
if(fDebug_Mode>0){
cerr << "Storing DC entry number " << icc << endl;
}
fCCPB->Scsght=(Int_t )(nt10.cc_sect[icc]*1000+
nt10.cc_segm[icc]*100+
nt10.cc_hit[icc]);
fCCPB->Nphe= (Float_t) nt10.nphe[icc];
fCCPB->Time= (Float_t) nt10.cc_t[icc];
fCCPB->Path= (Float_t) nt10.cc_r[icc];
fCCPB->Chi2cc=(Float_t) nt10.cc_c2[icc];
fCCPB->Status=(Int_t ) 1.;
TClonesArray &tCCPBBank = *fcaCCPBStore;
new(tCCPBBank[fnCCPB_Store++]) TCCPBClass(fCCPB);
}
}
void TNT10Reader::Fill_LCPB(void){
for(Int_t ilc=0;ilc< nt10.lac_part; ilc++){
if(fDebug_Mode>0){
cerr << "Storing LAC entry number " << ilc << endl;
}
fLCPB->Scht= (Int_t )(nt10.lec_sect[ilc]*100+
nt10.lec_hit[ilc]);
fLCPB->Etot= (Float_t) nt10.lec_etot[ilc];
fLCPB->Time= (Float_t) nt10.lec_t[ilc];
fLCPB->Path= (Float_t) nt10.lec_r[ilc];
fLCPB->X= (Float_t) nt10.lec_x[ilc];
fLCPB->Y= (Float_t) nt10.lec_y[ilc];
fLCPB->Z= (Float_t) nt10.lec_z[ilc];
fLCPB->Chi2lc= (Float_t) nt10.lec_c2[ilc];
fLCPB->Status= (Int_t ) nt10.lec_stat[ilc];
#ifdef NT10_E2b
fLCPB->Ein= (Float_t) nt10.lec_ein[ilc];
#else
fLCPB->Ein= (Float_t) 0.;
#endif
TClonesArray &tLCPBBank = *fcaLCPBStore;
new(tLCPBBank[fnLCPB_Store++]) TLCPBClass(fLCPB);
}
}
void TNT10Reader::InitBanks(void){
if(!fEvntHeader) fEvntHeader = new THEADERClass();
if(!fEVNT) fEVNT = new TEVNTClass();
if(!fDCPB) fDCPB = new TDCPBClass();
if(!fECPB) fECPB = new TECPBClass();
if(!fSCPB) fSCPB = new TSCPBClass();
if(!fCCPB) fCCPB = new TCCPBClass();
if(!fLCPB) fLCPB = new TLCPBClass();
}
void TNT10Reader::InitClones(){
if(!fcaEVNTStore) fcaEVNTStore = new TClonesArray("TEVNTClass",1);
if(!fcaECPBStore) fcaECPBStore = new TClonesArray("TECPBClass",1);
if(!fcaSCPBStore) fcaSCPBStore = new TClonesArray("TSCPBClass",1);
if(!fcaDCPBStore) fcaDCPBStore = new TClonesArray("TDCPBClass",1);
if(!fcaCCPBStore) fcaCCPBStore = new TClonesArray("TCCPBClass",1);
if(!fcaLCPBStore) fcaLCPBStore = new TClonesArray("TLCPBClass",1);
}
Int_t TNT10Reader::InitBranches(){
Int_t bufsize = k__BUFSIZE__;
Int_t split = 1;
if(fDebug_Mode>0){
cerr << "Initializing Branches ... \n";
}
fEvntHeaderBranch = fTree->Branch("HEADER","THEADERClass",&fEvntHeader,bufsize,split);
if(fDebug_Mode>0)cerr << "Header done... \n";
fTree->SetBranchStatus("HEADER",1);
fEVNTBranch = fTree->Branch("EVNT",&fcaEVNTStore,bufsize,split);
if(fDebug_Mode>0)cerr << "EVNT done... \n";
fECPBBranch = fTree->Branch("ECPB",&fcaECPBStore,bufsize,split);
if(fDebug_Mode>0)cerr << "ECPB done... \n";
fSCPBBranch = fTree->Branch("SCPB",&fcaSCPBStore,bufsize,split);
if(fDebug_Mode>0)cerr << "SCPB done... \n";
fDCPBBranch = fTree->Branch("DCPB",&fcaDCPBStore,bufsize,split);
if(fDebug_Mode>0)cerr << "DCPB done... \n";
fCCPBBranch = fTree->Branch("CCPB",&fcaCCPBStore,bufsize,split);
if(fDebug_Mode>0)cerr << "CCPB done... \n";
fLCPBBranch = fTree->Branch("LCPB",&fcaLCPBStore,bufsize,split);
if(fDebug_Mode>0)cerr << "LCPB done... \n";
fTree->SetBranchStatus("*",1);
return(1);
}
void TNT10Reader::SetBranchAddress(const char *bname, void **add){
Int_t bufsize = k__BUFSIZE__;
Int_t split = 1;
if( strcmp(bname,"HEADER") == 0){
fEvntHeaderBranch = fTree->Branch("HEADER","THEADERClass",add,bufsize,split);
fEvntHeader =(THEADERClass *) (*add);
}else if( strcmp(bname,"EVNT") == 0){
fEVNTBranch = fTree->Branch("EVNT",add,bufsize,split);
fcaEVNTStore =(TClonesArray *)(*add);
}else if( strcmp(bname,"ECPB") == 0){
fECPBBranch = fTree->Branch("ECPB",add,bufsize,split);
fcaECPBStore =(TClonesArray *)(*add);
}else if( strcmp(bname,"SCPB") == 0){
fSCPBBranch = fTree->Branch("SCPB",add,bufsize,split);
fcaSCPBStore =(TClonesArray *)(*add);
}else if( strcmp(bname,"DCPB") == 0){
fDCPBBranch = fTree->Branch("DCPB",add,bufsize,split);
fcaDCPBStore =(TClonesArray *)(*add);
}else if( strcmp(bname,"CCPB") == 0){
fCCPBBranch = fTree->Branch("CCPB",add,bufsize,split);
fcaCCPBStore =(TClonesArray *)(*add);
}else if( strcmp(bname,"LCPB") == 0){
fLCPBBranch = fTree->Branch("LCPB",add,bufsize,split);
fcaLCPBStore =(TClonesArray *)(*add);
}else{
cerr << "WARNING -- This clas does not know about the " << bname << " bank.\n";
cerr << " Please make sure you are using the correct version. \n";
}
}
Double_t TNT10Reader::LoadAll(void){
Int_t totent=(Int_t)GetEntries()-1;
LoadTree(totent);
return(fEntries);
}
Int_t TNT10Reader::LoadTree(Int_t entry){
Int_t iret=0;
if(!fNtrees) return -1;
if(entry < 0 || entry >= fEntries) return -2;
if(!fTree){
fTree = new TTree(this->TChain::GetName(),this->TChain::GetTitle());
InitClones();
InitBranches();
}
Int_t n_found_local=-1;
if(fReadSequential){
n_found_local=fTree->GetEntry(entry);
}
Int_t t;
if (fTreeNumber!=-1 &&
(entry >= fTreeOffset[fTreeNumber] && entry < fTreeOffset[fTreeNumber+1])){
t = fTreeNumber;
}
else {
for (t=0;t<fNtrees;t++) {
if (entry < fTreeOffset[t+1]) break;
}
}
fReadEntry = entry - fTreeOffset[t];
if(n_found_local>0){
return(fReadEntry);
}
if( (entry > fNtLastRead + 1) && fReadSequential){
for(Int_t ievt=fNtLastRead;ievt<=entry;ievt++){
LoadTree(ievt);
}
return(fReadEntry);
}
if (t == fTreeNumber) {
CleanEventClones();
hgnt(fNtNum,fReadEntry+1,iret);
if(fDebug_Mode>10){
printf("Event: %5d %5d %6d \n",nt10.evntid,nt10.npart,nt10.evntclas);
}
if(iret){
return(0);
}
Fill_Tree_from_Paw();
fNtLastRead = entry;
return(fReadEntry);
}
if(fDebug_Mode>10)cerr << "Need new file.\n";
if (!IsZombie()) {
Close();
}
TChainElement *element = (TChainElement*)fFiles->At(t);
if (!element) return -4;
Open(element->GetTitle());
if (IsZombie()) {
if(fDebug_Mode)cerr << "ZOMBIE \n";
Close();
return -3;
}
fTreeNumber = t;
Int_t nentries = GetNTEntries();
if (fTreeOffset[fTreeNumber+1] != fTreeOffset[fTreeNumber] + nentries) {
fTreeOffset[fTreeNumber+1] = fTreeOffset[fTreeNumber] + nentries;
fEntries = fTreeOffset[fNtrees];
element->SetNumberEntries(nentries);
if (entry >= fTreeOffset[fTreeNumber+1]) {
if (fTreeNumber < fNtrees && entry < fTreeOffset[fTreeNumber+2]) return LoadTree(entry);
else fReadEntry = -2;
}
}
SetChainOffset(fTreeOffset[t]);
if (fPlayer) fPlayer->UpdateFormulaLeaves();
if (fNotify) fNotify->Notify();
LoadTree(fReadEntry);
return fReadEntry;
}
void TNT10Reader::CleanEventClones(){
if(fDebug_Mode>10){
cerr << "Clearing Clones arrays.\n";
}
if(fcaEVNTStore) fcaEVNTStore->Clear();
if(fcaECPBStore) fcaECPBStore->Clear();
if(fcaSCPBStore) fcaSCPBStore->Clear();
if(fcaDCPBStore) fcaDCPBStore->Clear();
if(fcaCCPBStore) fcaCCPBStore->Clear();
if(fcaLCPBStore) fcaLCPBStore->Clear();
fnEVNT_Store=0;
fnECPB_Store=0;
fnSCPB_Store=0;
fnDCPB_Store=0;
fnCCPB_Store=0;
fnLCPB_Store=0;
}
Int_t TNT10Reader::Close(void){
if(fgLuns) fgLuns[fHbookLun-10]=0;
hrend(PASSCHAR("NT10"),4);
return(0);
};
Int_t TNT10Reader::Open(const char *name){
Int_t iret=0,recsiz=0;
Int_t bignum=9999,zero=0;
if(fHbookLun>0){
if(fDebug_Mode>4)cerr << "Forgot to close lun?\n";
Close();
}
fHbookLun=0;
for (Int_t i=0;i<10;i++) {
if (fgLuns[i] == 0) {
fHbookLun = 10+i;
fgLuns[i] = 1;
break;
}
}
if (fHbookLun == 0) {
TChain::Error("THbookFile","Too many HbookFiles\n");
return(0);
}
if(fDebug_Mode>4)cerr << "Opening file: " << name << endl;
hropen(fHbookLun,PASSCHAR("NT10"),PASSCHAR(name),PASSCHAR("p"),recsiz,iret,4,strlen(name),1);
if(iret){
fHbookLun = 0;
fgLuns[fHbookLun-10]=0;
cerr << "Could not open file. Iret = " << iret << endl;
return(0);
}
hrin(fNtNum,bignum,zero);
fNevents = (Int_t)GetNTEntries();
if(fNevents == 0){
cerr << "ERROR reading NT10 ntuple.\n";
Close();
return(0);
}
if(fDebug_Mode > 0){
Dir();
NTPrint();
cerr << "Number of events: " << fNevents << endl;
}
hbname(fNtNum,PASSCHAR(" "),zero,PASSCHAR("$CLEAR"),1,6);
hbname(fNtNum,PASSCHAR("HEVT"),nt10.npart,PASSCHAR("$SET"),4,4);
hbname(fNtNum,PASSCHAR("EVNT"),nt10.gpart,PASSCHAR("$SET"),4,4);
hbname(fNtNum,PASSCHAR("DCPB"),nt10.dc_part,PASSCHAR("$SET"),4,4);
hbname(fNtNum,PASSCHAR("ECPB"),nt10.ec_part,PASSCHAR("$SET"),4,4);
hbname(fNtNum,PASSCHAR("SCPB"),nt10.sc_part,PASSCHAR("$SET"),4,4);
hbname(fNtNum,PASSCHAR("CCPB"),nt10.cc_part,PASSCHAR("$SET"),4,4);
SetTitle("NT10");
SetName(name);
gROOT->GetListOfBrowsables()->Add((TChain *)this,name);
fList = new TList();
fKeys = new TList();
for (Int_t key=1;key<1000000;key++) {
Int_t z0 = 0;
rzink(key,z0,"S",1);
if (quest[0]) break;
if (quest[13] & 8) continue;
Int_t id = quest[20];
THbookKey *akey = new THbookKey(id,(THbookFile *)this);
fKeys->Add(akey);
}
return(1);
}
void TNT10Reader::PrintEventStatus(){
if (fCurrentEvent < 0) {
cout << "No Current Event to Display! Make sure you have some event read in!" << endl;
} else {
cout << endl << "Status on Run # " << fEvntHeader->NRun <<" Event #" << fEvntHeader->NEvent << endl;
cout << " Bank | # entries " << endl;
cout << "---------+-------------" << endl;
cout << " EVNT | " << fcaEVNTStore->GetEntries() << endl;
cout << " ECPB | " << fcaECPBStore->GetEntries() << endl;
cout << " SCPB | " << fcaSCPBStore->GetEntries() << endl;
cout << " DCPB | " << fcaDCPBStore->GetEntries() << endl;
cout << " CCPB | " << fcaCCPBStore->GetEntries() << endl;
cout << " LCPB | " << fcaLCPBStore->GetEntries() << endl;
cout << " TGBI | " << fcaTGBIStore->GetEntries() << endl;
#ifdef WRITE_GSIM
cout << " GSIM | " << fcaGSIMStore->GetEntries() << endl;
#endif
cout << "---------+-------------" << endl << endl;
}
}
void TNT10Reader::Browse(TBrowser *b){
if(b){
b->Add(fTree);
b->Add(fList,"memory");
b->Add(fKeys,"IDs on disk");
}
}
void TNT10Reader::Dir(void){
hldir(PASSCHAR("//"),PASSCHAR("T"),2,1);
}
Int_t TNT10Reader::GetNTEntries() const{
Int_t noent;
hnoent(fNtNum,noent);
return(noent);
}
void TNT10Reader::NTPrint(void){
hprnt(fNtNum);
}
Int_t TNT10Reader::SetNtNum(Int_t ntnum){
if(ntnum>0)fNtNum=ntnum;
return(fNtNum);
}
Int_t TNT10Reader::GetNRows(const Char_t *bankname){
Int_t nRows = -1;
if(strncmp(bankname,"EVNT",4) == 0){
nRows = fcaEVNTStore->GetEntries();
}
if(strncmp(bankname,"ECPB",4) == 0){
nRows = fcaECPBStore->GetEntries();
}
if(strncmp(bankname,"SCPB",4) == 0){
nRows = fcaSCPBStore->GetEntries();
}
if(strncmp(bankname,"DCPB",4) == 0){
nRows = fcaDCPBStore->GetEntries();
}
if(strncmp(bankname,"CCPB",4) == 0){
nRows = fcaCCPBStore->GetEntries();
}
if(strncmp(bankname,"LCPB",4) == 0){
nRows = fcaLCPBStore->GetEntries();
}
if(strncmp(bankname,"TGBI",4) == 0){
nRows = fcaTGBIStore->GetEntries();
}
if(fDebug_Mode & kDBG_Error){
if(nRows == -1){
cout << "TClasTool::NBankRows (ERROR): Bank \"" << bankname << "\" not found.."<< endl;
}
}
return nRows;
}
TVector3 TNT10Reader::GetPart3Vector(Int_t indx){
TVector3 v3vect(0,0,0);
if(indx>=0 && indx<GetNPart()){
TEVNTClass *cEvnt = (TEVNTClass *) GetBankRow("EVNT",indx);
if(cEvnt!=NULL){
v3vect.SetXYZ(cEvnt->GetPx(),cEvnt->GetPy(),cEvnt->GetPz());
} else if(fDebug_Mode&kDBG_Error) cout << "GetPart3Vector: Particle does not exist.." << endl;
} else if(fDebug_Mode&kDBG_Error) cout << "GetPart3Vector: Cannot find particle at row " << indx
<< " there are only " << GetNPart() << " particle in the event" << endl;
return v3vect;
}
TVector3 TNT10Reader::GetPartVertex(Int_t indx){
TVector3 v3vect(0,0,0);
if(indx>=0 && indx<GetNPart()){
TEVNTClass *cEvnt = (TEVNTClass *) GetBankRow("EVNT",indx);
if(cEvnt!=NULL){
v3vect.SetXYZ(cEvnt->GetX(),cEvnt->GetY(),cEvnt->GetZ());
} else if(fDebug_Mode&kDBG_Error) cout << "GetPart3Vector: Particle does not exist.." << endl;
} else if(fDebug_Mode&kDBG_Error) cout << "GetPart3Vector: Cannot find particle at row " << indx
<< " there are only " << GetNPart() << " particle in the event" << endl;
return v3vect;
}
Int_t TNT10Reader::GetPartID(Int_t indx){
Int_t p_id = 0;
if(indx>=0 && indx<GetNPart()){
TEVNTClass *cEvnt = (TEVNTClass *) GetBankRow("EVNT",indx);
if(cEvnt!=NULL){
p_id = cEvnt->GetId();
} else if(fDebug_Mode&kDBG_Error) cout << "GetPartID: Particle does not exist.." << endl;
} else if(fDebug_Mode&kDBG_Error) cout << "GetPartID: Cannot find particle at row " << indx
<< " there are only " << GetNPart() << " particle in the event" << endl;
return p_id;
}
Int_t TNT10Reader::GetPartCharge(Int_t indx){
Int_t p_ch = 0;
if(indx>=0 && indx<GetNPart()){
TEVNTClass *cEvnt = (TEVNTClass *) GetBankRow("EVNT",indx);
if(cEvnt!=NULL){
p_ch = cEvnt->GetCharge();
} else if(fDebug_Mode&kDBG_Error) cout << "GetPartID: Particle does not exist.." << endl;
} else if(fDebug_Mode&kDBG_Error) cout << "GetPartID: Cannot find particle at row " << indx
<< " there are only " << GetNPart() << " particle in the event" << endl;
return p_ch;
}
Int_t TNT10Reader::GetEventNumber(){
return(fEvntHeader->NEvent);
}
Int_t TNT10Reader::GetRunNumber(){
return(fNRun);
}
Int_t TNT10Reader::GetCurrentEvent(){
return fCurrentEvent;
}
TObject *TNT10Reader::GetBankRow(const Char_t *bankname,Int_t nrow){
TClonesArray *BankStore = 0;
if(strncmp(bankname,"EVNT",4) == 0){
BankStore = fcaEVNTStore;
if((fDebug_Mode& kDBG_Debug2) > 0) cout << "TClasTool::GetBankRow : Set Pointer to fcaDataPointer " << endl;
}
if(strncmp(bankname,"ECPB",4) == 0){
BankStore = fcaECPBStore;
if((fDebug_Mode&kDBG_Debug2) > 0) cout << "TClasTool::GetBankRow : Set Pointer to fcaECPBStore " << endl;
}
if(strncmp(bankname,"SCPB",4) == 0){
BankStore = fcaSCPBStore;
if((fDebug_Mode&kDBG_Debug2) > 0) cout << "TClasTool::GetBankRow : Set Pointer to fcaSCPBStore " << endl;
}
if(strncmp(bankname,"DCPB",4) == 0){
BankStore = fcaDCPBStore;
if((fDebug_Mode&kDBG_Debug2) > 0) cout << "TClasTool::GetBankRow : Set Pointer to fcaDCPBStore " << endl;
}
if(strncmp(bankname,"CCPB",4) == 0){
BankStore = fcaCCPBStore;
if((fDebug_Mode&kDBG_Debug2) > 0) cout << "TClasTool::GetBankRow : Set Pointer to fcaCCPBStore " << endl;
}
if(strncmp(bankname,"LCPB",4) == 0){
BankStore = fcaLCPBStore;
if((fDebug_Mode&kDBG_Debug2) > 0) cout << "TClasTool::GetBankRow : Set Pointer to fcaLCPBStore " << endl;
}
if(BankStore == NULL){
if(fDebug_Mode& kDBG_Error) cout << "TClasTool::GetBankRow (ERROR): Can not find Bank \"" << bankname <<"\" " << endl;
return NULL;
} else {
if(nrow<0 || nrow >= BankStore->GetEntries()){
if(fDebug_Mode& kDBG_Error) cout << "TClasTool::GetBankRow (ERROR): Bank \"" << bankname <<"\" has only " << BankStore->GetEntries() << " entries "<< endl << "Can not get row # " << nrow << endl << "Use rows from 0 to " << BankStore->GetEntries() << endl;
return NULL;
} else {
return (TObject *) BankStore->At(nrow);
}
}
}
TChain *TNT10Reader::GetTree(Char_t *treename){
return(this);
}
ClassImp(TNT10Reader)
Author: Maurik Holtrop
Last update: ClasTool/ClasBanks:$Name: $:$Id: TNT10Reader.cc,v 1.10 2007/03/01 22:27:00 holtrop Exp $
CopyLeft - This code is freely available.
ROOT Home page - ClasTool Class index - Class Hierarchy - Top of the page