Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | File List | Namespace Members | Class Members | File Members | Related Pages

io::EventHandle Class Reference

Match up the event data model to file input and output. More...

#include <EventHandle.h>

Inheritance diagram for io::EventHandle:

edm::EventHandle List of all members.

Public Member Functions

 EventHandle ()
virtual ~EventHandle ()
int Index () const
int SetupInputFile (TFile *f)
int SetupOutputFile (TFile *f)
int Advance (int n=1)
int Rewind (int n=1)
void Close ()
virtual int Load (int branchID) const
void Report ()
int Write ()

Protected Attributes

int fIndex
 Location in current input file.

TFile * fInputFile
 Pointer to input source. Not owned.

TFile * fOutputFile
 Pointer to output file. Not owned.

TTree * fEventTree
 The input event tree.

TBranch * fBranch [kNBranch]
 Branches where events are stored.

TTree * fOutEventTree
 The ouput event tree.


Static Protected Attributes

const int fBucketSize = 16000
const int fSplitLevel = 99

Detailed Description

Match up the event data model to file input and output.

Definition at line 18 of file IoModules/EventHandle.h.


Constructor & Destructor Documentation

EventHandle::EventHandle  ) 
 

Construct the default event handle

Reimplemented from edm::EventHandle.

Definition at line 27 of file IoModules/EventHandle.cxx.

References edm::EventHandle::ClearLoadFlags().

00027                          :
00028   fIndex         ( 0 ),
00029   fInputFile     ( 0 ),
00030   fOutputFile    ( 0 ),
00031   fEventTree     ( 0 ),
00032   fOutEventTree  ( 0 )
00033 { 
00034   Long64_t tsize = 150; // Set the limit of event tree to be large (GB)
00035   for (int i = 0; i < 3; ++i) tsize *= 1000; // Convert to bytes from GB
00036   TTree::SetMaxTreeSize(tsize);
00037 
00038   this->ClearLoadFlags();
00039 }

EventHandle::~EventHandle  )  [virtual]
 

Clear all data arrays and delete the event

Reimplemented from edm::EventHandle.

Definition at line 43 of file IoModules/EventHandle.cxx.

00043 { }


Member Function Documentation

int EventHandle::Advance int  n = 1  ) 
 

Definition at line 157 of file IoModules/EventHandle.cxx.

References edm::EventHandle::ClearLoadFlags(), fEventTree, and fIndex.

Referenced by io::ReadWriteModule::Advance().

00158 {
00159 //======================================================================
00160 // Advance n places in the input stream. Return the difference between
00161 // the new position and the old.
00162 //======================================================================
00163   if (fEventTree==0 || n<1) return 0;
00164 
00165   int indexSave = fIndex;
00166   int nEntries  = (int)fEventTree->GetEntries();
00167 
00168   fIndex += n;
00169   if (fIndex>=nEntries) fIndex = nEntries-1;
00170 
00171   // Since we've moved on, mark all branches as unloaded
00172   this->ClearLoadFlags();
00173 
00174   return fIndex-indexSave;
00175 }

void EventHandle::Close  ) 
 

Definition at line 252 of file IoModules/EventHandle.cxx.

References fOutEventTree, and fOutputFile.

Referenced by io::ReadWriteModule::SetOutputFileName().

00253 {
00254   if (fOutputFile && fOutEventTree) {
00255     fOutEventTree->Write();
00256     delete fOutEventTree;
00257     fOutEventTree = 0;
00258   }
00259 }

int EventHandle::Index  )  const
 

Returns:
The current place in the event stream.

Definition at line 49 of file IoModules/EventHandle.cxx.

References fIndex.

Referenced by io::ReadWriteModule::Report().

00049 { return fIndex; }

int EventHandle::Load int  branchID  )  const [virtual]
 

Loads one branch if branchID < EDMEventHandle::kNBranch, or loads entire event if branchID == kNBranch

Implements edm::EventHandle.

Definition at line 203 of file IoModules/EventHandle.cxx.

References fBranch, fEventTree, fIndex, fInputFile, edm::EventHandle::IsLoaded(), and edm::EventHandle::SetLoaded().

Referenced by Write().

00204 {
00205   // Do not load anything if a ROOT input file is not specified
00206   if (!fInputFile) return 0;
00207   assert ((branchID >= 0) && (branchID <= kNBranch));
00208 
00209   // If branchID is maxed out, load all the branches. Load one-by-one
00210   // to avoid over-writing branched already loaded.
00211   if (branchID == kNBranch) {
00212     for (int i=0; i<kNBranch; ++i) this->Load(i);
00213     return 1;
00214   }
00215   
00216   // Check if branch is already loaded
00217   if (this->IsLoaded((BranchID_t) branchID)) return 0;
00218   
00219   // Make sure that this branch exists before actually loading it
00220   if (fBranch[branchID]) {
00221     fBranch[branchID]->GetEntry(fIndex);
00222     this->SetLoaded(branchID);
00223     return 1;
00224   }
00225   else {
00226     // Do this in case event was written with split level 0, when
00227     // event is written to one branch
00228     std::cout << "IoEventHandle::Load() Warning: Branch " << branchID
00229               << " is missing. Loading entire event" << std::endl;
00230     fEventTree->GetEntry(fIndex);
00231     this->SetLoaded(kNBranch);
00232   }
00233 
00234   return 0;
00235 }

void EventHandle::Report  ) 
 

Definition at line 263 of file IoModules/EventHandle.cxx.

References fEventTree, and fOutEventTree.

00264 {
00265   if (fEventTree) {
00266     std::cout << "IoEventHandle EventTree: " << std::endl;
00267     fEventTree->Print();
00268   }
00269   if (fOutEventTree) {
00270     std::cout << "IoEventHandle OutEventTreee: " << std::endl;
00271     fOutEventTree->Print();
00272   }
00273 }

int EventHandle::Rewind int  n = 1  ) 
 

Definition at line 179 of file IoModules/EventHandle.cxx.

References edm::EventHandle::ClearLoadFlags(), fEventTree, and fIndex.

Referenced by io::ReadWriteModule::Rewind().

00180 {
00181 //======================================================================
00182 // Rewind n places in the input stream. Return the difference between
00183 // the new position and the old.
00184 //======================================================================
00185   if (fEventTree==0 || n<1) return 0;
00186 
00187   int indexSave = fIndex;
00188 
00189   fIndex -= n;
00190   if (fIndex<0) fIndex = 0;
00191 
00192   // Since we've moved on, mark all branches as unloaded
00193   this->ClearLoadFlags();
00194   
00195   return indexSave-fIndex;
00196 }

int EventHandle::SetupInputFile TFile *  f  ) 
 

Map this event handle onto the input file f

Parameters:
f : Input file
Returns:
1 if AOK, 0 if errors

Definition at line 58 of file IoModules/EventHandle.cxx.

References edm::EventHandle::ClearLoadFlags(), fBranch, fEventTree, fIndex, fInputFile, and gsEventTree.

Referenced by io::ReadWriteModule::SetupInputFile().

00059 {
00060   fInputFile = f;
00061 
00062   // In with the new...
00063   fEventTree = dynamic_cast<TTree*>(f->Get(gsEventTree));
00064   if (fEventTree==0) {
00065     std::cout << 
00066       "Failed to find " << gsEventTree << " in file '"
00067               << f->GetName() << "'" << std::endl;
00068     f->ls();
00069     return 0;
00070   }
00071 
00072   // Don't check for 0 on these until we try to use them. Its possible
00073   // and legal for the branches to have been dropped from a file.
00074   const char* branch[] = { 
00075     "fHeader", "fMC",     "fDetSim", "fDAQ",  "fRaw",
00076     "fRawAux", "fCal",    "fReco",   "fUser", "fSummary"
00077   };
00078   void* baddr[kNBranch];
00079   baddr[kHeaderID]  = &fEvent->fHeader;
00080   baddr[kMCID]      = &fEvent->fMC;
00081   baddr[kDetSimID]  = &fEvent->fDetSim;
00082   baddr[kDAQID]     = &fEvent->fDAQ;
00083   baddr[kRawID]     = &fEvent->fRaw;
00084   baddr[kRawAuxID]  = &fEvent->fRawAux;
00085   baddr[kCalID]     = &fEvent->fCal;
00086   baddr[kRecoID]    = &fEvent->fReco;
00087   baddr[kUserID]    = &fEvent->fUser;
00088   baddr[kSummaryID] = &fEvent->fSummary;
00089   for (int ibranch=0; ibranch<kNBranch; ++ibranch) {
00090     fBranch[ibranch] = fEventTree->GetBranch(branch[ibranch]);
00091     if (fBranch[ibranch]!=0) {
00092       fBranch[ibranch]->SetAddress(baddr[ibranch]);
00093       fBranch[ibranch]->SetAutoDelete(kTRUE);
00094     }
00095     else {
00096       std::cout << __FILE__ << ":" << __LINE__ 
00097                 << "\tFailed to make branch " << branch[ibranch] 
00098                 << std::endl;
00099       std::cout << "\tFile not formed correctly?" << std::endl;
00100       abort();
00101     }
00102   }
00103 
00104   // Flag all branches as unloaded
00105   this->ClearLoadFlags();
00106 
00107   // Reset to the start of the file
00108   fIndex = 0;
00109 
00110   return 1;
00111 }

int EventHandle::SetupOutputFile TFile *  f  ) 
 

Definition at line 115 of file IoModules/EventHandle.cxx.

References fBucketSize, fOutEventTree, fOutputFile, fSplitLevel, and gsEventTree.

Referenced by io::ReadWriteModule::SetOutputFileName().

00116 {
00117 //======================================================================
00118 // Set up an output file for writing events
00119 //======================================================================
00120   fOutputFile = f;
00121   
00122   // Out with the old
00123   if (fOutEventTree) { 
00124     delete fOutEventTree; 
00125     fOutEventTree=0; 
00126   }
00127 
00128   // In with the new...  
00129   TDirectory* startDir = gDirectory;
00130 
00131   fOutputFile->cd();
00132   fOutEventTree = new TTree(gsEventTree, gsEventTree);
00133   assert(fOutEventTree);
00134 
00135   int bSz  = fBucketSize;
00136   int sLvl = fSplitLevel;
00137   fOutEventTree->Branch("fHeader", "edm::EventHeader",
00138                         &fEvent->fHeader, bSz, sLvl);
00139   fOutEventTree->Branch("fTop",    "TFolder", &fEvent->fTop,    bSz, sLvl);
00140   fOutEventTree->Branch("fMC",     "TFolder", &fEvent->fMC,     bSz, sLvl);
00141   fOutEventTree->Branch("fDetSim", "TFolder", &fEvent->fDetSim, bSz, sLvl);
00142   fOutEventTree->Branch("fDAQ",    "TFolder", &fEvent->fDAQ,    bSz, sLvl);
00143   fOutEventTree->Branch("fRaw",    "TFolder", &fEvent->fRaw,    bSz, sLvl);
00144   fOutEventTree->Branch("fRawAux", "TFolder", &fEvent->fRawAux, bSz, sLvl);
00145   fOutEventTree->Branch("fCal",    "TFolder", &fEvent->fCal,    bSz, sLvl);
00146   fOutEventTree->Branch("fReco",   "TFolder", &fEvent->fReco,   bSz, sLvl);
00147   fOutEventTree->Branch("fUser",   "TFolder", &fEvent->fUser,   bSz, sLvl);
00148   fOutEventTree->Branch("fSummary","TFolder", &fEvent->fSummary,bSz, sLvl);
00149   
00150   startDir->cd();
00151   
00152   return 1;
00153 }

int EventHandle::Write  ) 
 

Definition at line 239 of file IoModules/EventHandle.cxx.

References fOutEventTree, fOutputFile, and Load().

Referenced by io::ReadWriteModule::WriteEvent().

00240 {
00241   if (fOutputFile && fOutEventTree) {
00242     // Make sure we load any branches which haven't been loaded yet so
00243     // they get written
00244     this->Load(kNBranch);
00245     fOutEventTree->Fill();
00246   }
00247   return 1;
00248 }


Member Data Documentation

TBranch* io::EventHandle::fBranch[kNBranch] [protected]
 

Branches where events are stored.

Definition at line 47 of file IoModules/EventHandle.h.

Referenced by Load(), and SetupInputFile().

const int io::EventHandle::fBucketSize = 16000 [static, protected]
 

Definition at line 37 of file IoModules/EventHandle.h.

Referenced by SetupOutputFile().

TTree* io::EventHandle::fEventTree [protected]
 

The input event tree.

Definition at line 46 of file IoModules/EventHandle.h.

Referenced by Advance(), Load(), Report(), Rewind(), and SetupInputFile().

int io::EventHandle::fIndex [protected]
 

Location in current input file.

Definition at line 43 of file IoModules/EventHandle.h.

Referenced by Advance(), Index(), Load(), Rewind(), and SetupInputFile().

TFile* io::EventHandle::fInputFile [protected]
 

Pointer to input source. Not owned.

Definition at line 44 of file IoModules/EventHandle.h.

Referenced by Load(), and SetupInputFile().

TTree* io::EventHandle::fOutEventTree [protected]
 

The ouput event tree.

Definition at line 48 of file IoModules/EventHandle.h.

Referenced by Close(), Report(), SetupOutputFile(), and Write().

TFile* io::EventHandle::fOutputFile [protected]
 

Pointer to output file. Not owned.

Definition at line 45 of file IoModules/EventHandle.h.

Referenced by Close(), SetupOutputFile(), and Write().

const int io::EventHandle::fSplitLevel = 99 [static, protected]
 

If you set split level to 0, the tree will be written in one branch which is not very efficient

Definition at line 40 of file IoModules/EventHandle.h.

Referenced by SetupOutputFile().


The documentation for this class was generated from the following files:
Generated on Thu Jul 24 12:01:17 2008 for NOvA Offline by doxygen 1.3.5