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

PerInputStream Class Reference

#include <PerInputStream.h>

Inheritance diagram for PerInputStream:

PerStream List of all members.

Public Member Functions

 PerInputStream (string treename)
virtual ~PerInputStream ()
std::vector< PerRecordTagsGetWindowTags () const
const VldContextGetLastEntryVld () const
Per::ESequenceMode GetSequenceMode () const
bool IsValidSelectionString () const
bool IsEnd () const
bool IsBegin () const
bool IsFileEnd () const
bool IsOpen () const
bool IsRequired () const
std::ostream & Print (std::ostream &s) const
int AdvanceLowerBoundTags (const VldContext &keyVld)
int AdvanceWindowTags (const VldContext &keyVld)
int AdvanceTags ()
void Close ()
void CloseFile ()
TObject * GetObject (Int_t entry=0, bool useselection=true)
const PerRecordTagsGetTags ()
TObject * Next (bool seek=false)
const PerRecordTagsNextTags ()
TObject * Previous (bool seek=false)
const PerRecordTagsPrevTags ()
void Rewind ()
bool SetFile (string fullfilepathname, Per::EAccessMode accessmode=Per::kRead)
void SetFileEnd (bool isFileEnd=true)
bool SetSelection (string selection="")
void SetRequired (bool isRequired)
void SetSequenceMode (Per::ESequenceMode seqMode=Per::kKey)
void SetUpdateMode (bool updatemode=true)
void SetWindow (double lower, double upper)
 Set the window relative to the key VldContext to use in kWindow mode.
VldContext GetVldContext (Int_t treeindex)
int GetMaxFileRepeat () const
double GetMeanMom () const
double GetPushRandom () const
bool RepeatFile () const
void SetMaxFileRepeat (int num=0)
void SetMeanMom (double mm=0.)
void SetPushRandom (bool tf=true)
void SetRandomGenerator (TRandom *ranGen)
int AddFile (std::string fullfilepathname, int at=-1)
int GoToFile (int n)
int GoToFile (std::string fullfilepathname)
int NextFile (int n=1)
int PrevFile (int n=1)
int RemoveFile (std::string fullfilepathname="*")
int IsEndOfFiles () const
int IsBeginOfFiles () const
std::ostream & ListFile (std::ostream &os) const
void ShuffleTagsList (TRandom *ranGen)

Private Types

typedef std::list< PerRecordTags
>::iterator 
TagsListItr
typedef std::list< std::string
>::iterator 
FileListItr

Private Member Functions

bool IsSelected () const
bool AdvanceTagsList ()
bool RewindTagsList ()
void CleanTagsList (bool isforward=true)
bool UpdateTree ()
void DisableFile ()
VldContext GetNextFileVldFromMap () const

Private Attributes

bool fIsValidSelectionString
string fSelection
bool fRequired
TTreeFormula * fTTreeFormula
Short_t fTreeCycle
bool fFileEnd
bool fUpdateMode
bool fFileEnabled
bool fNewTree
Per::ESequenceMode fSequenceMode
std::list< PerRecordTagsfTagsList
TagsListItr fTagsItr
UInt_t fMaxListSize
VldContext fLastEntryVld
PerRecordTags fTagsBegin
PerRecordTags fTagsEnd
std::list< std::string > fFileList
std::map< std::string, VldContextfFileVldContextMap
FileListItr fFileItr
double fWindowLower
double fWindowUpper
std::vector< PerRecordTagsfWindowTags
int fCurrFileRepeat
int fMaxFileRepeat
double fMeanMom
bool fPushRandom
bool fRepeatedFile
TRandom * fRanGen
bool fIsBOF
 pointer to the PerInputStreamManager random # gen (NOT OWNED BY PERINPUTSTREAM)
TFileCacheRead * fFileCacheRead
UInt_t fSumTags

Friends

class PerInputStreamManager

Member Typedef Documentation

typedef std::list<std::string>::iterator PerInputStream::FileListItr [private]
 

Definition at line 119 of file PerInputStream.h.

typedef std::list<PerRecordTags>::iterator PerInputStream::TagsListItr [private]
 

Definition at line 118 of file PerInputStream.h.

Referenced by AdvanceTagsList(), and RewindTagsList().


Constructor & Destructor Documentation

PerInputStream::PerInputStream string  treename  ) 
 

Definition at line 970 of file PerInputStream.cxx.

References fLastEntryVld, fTagsBegin, fTagsEnd, Per::GetVldBegin(), MSG, and PerRecordTags::SetVldContext().

00970                                               :
00971   PerStream(treename),fIsValidSelectionString(true),fSelection(""),
00972   fRequired(false),fTTreeFormula(0),
00973   fTreeCycle(-1),fFileEnd(true),fUpdateMode(false),fFileEnabled(false),
00974   fNewTree(false),fSequenceMode(Per::kKey),
00975   fTagsItr(fTagsList.end()),fMaxListSize(100),fFileItr(fFileList.end()),
00976   fWindowLower(0.0), fWindowUpper(0.0), fWindowTags(),
00977   fCurrFileRepeat(0), fMaxFileRepeat(0), fMeanMom(1.), fPushRandom(true),
00978   fRepeatedFile(false), fRanGen(0), fIsBOF(false), fFileCacheRead(0),
00979   fSumTags(0)
00980 {
00981   //
00982   //  Purpose:  Default constructor.
00983   //
00984   //  Arguments: 
00985   //    treename  string   name of input tree served by this stream.
00986   //
00987   //  Return:    n/a.
00988   //
00989   //  Contact:   S. Kasahara
00990   // 
00991   //  Notes: This constructor doesn't do anything except fill in data members.
00992   //         PerInputStream does not become active until PerInputStream::
00993   //         SetFile is invoked.
00994   // 
00995 
00996   MSG("Per",Msg::kDebug) << "PerInputStream normal ctor at " << this 
00997                          << " for tree " << treename.c_str() << endl;
00998   
00999   fLastEntryVld = Per::GetVldBegin();
01000   fTagsBegin.SetVldContext(Per::GetVldBegin());
01001   fTagsEnd.SetVldContext(Per::GetVldEnd());
01002 
01003 }

PerInputStream::~PerInputStream  )  [virtual]
 

Definition at line 1005 of file PerInputStream.cxx.

References Close(), fFileCacheRead, fRanGen, and MSG.

01005                                 {
01006   //
01007   //  Purpose:  PerInputStream destructor.  
01008   //
01009   //  Contact:   S. Kasahara
01010   // 
01011 
01012   MSG("Per",Msg::kDebug) << "PerInputStream dtor at " << this 
01013                          << " for tree " << fTreeName.c_str() << endl;
01014   if (fRanGen) fRanGen = 0; // (*fRanGen) is owned by PerInputStreamManager !!
01015   if (fFileCacheRead) delete fFileCacheRead; fFileCacheRead = 0;
01016 
01017   Close();
01018 
01019 }


Member Function Documentation

int PerInputStream::AddFile std::string  fullfilepathname,
int  at = -1
 

Definition at line 52 of file PerInputStream.cxx.

References find().

00052                                                               {
00053   //
00054   //  Purpose:  Add file to stream file list at position at.
00055   //
00056   //  Arguments: fullfilepathname
00057   //                          at = position in file list (-1 => end of list)
00058   //             
00059   //  Return: 1 if successful, 0 if not. For now its always 1, but
00060   //          may add some error checking later.
00061   //
00062   //  Contact:   S. Kasahara
00063   //  Adapted from M. Messier's IoInputModule::AddFile.
00064 
00065   std::string curf;
00066   if ( !fIsBOF && fFileList.size() > 0 ) curf = *fFileItr;
00067 
00068   if ( at < 0 ) { 
00069     fFileList.push_back(fullfilepathname);
00070   }
00071   else if ( at == 0 ) {
00072     fFileList.push_front(fullfilepathname);
00073   }
00074   else {
00075     std::list<std::string>::iterator itr(fFileList.begin());
00076     std::list<std::string>::iterator itrEnd(fFileList.end());
00077     for ( int i = 0; (i < at && itr != itrEnd); ++i, ++itr ) continue;
00078     fFileList.insert(itr,fullfilepathname);
00079   }
00080 
00081   // insert may have changed file pointed to by fFileItr
00082   if ( fIsBOF || fFileList.size() == 1 ) {
00083     fIsBOF = true; // NextFile will move to first file
00084   }
00085   else {
00086     // Find original file in new list
00087     fFileItr = std::find(fFileList.begin(),fFileList.end(),curf);
00088     fIsBOF = false;
00089   } 
00090 
00091   return 1;
00092 
00093 }

int PerInputStream::AdvanceLowerBoundTags const VldContext keyVld  ) 
 

Definition at line 464 of file PerInputStream.cxx.

References fUpdateMode, GetNextFileVldFromMap(), GetTags(), PerRecordTags::GetVldContext(), Per::GetVldEnd(), PerRecordTags::IsBegin(), PerRecordTags::IsEnd(), IsEndOfFiles(), IsFileEnd(), VldContext::IsValid(), NextFile(), NextTags(), PrevFile(), and PrevTags().

00464                                                                   {
00465   //  Purpose:  Advance record tags in Per::kLowerBound streams to
00466   //            be equal to or less than the keyVld given in the argument.
00467   //
00468   //  Argument: none.
00469   //
00470   //  Return:  1 if successful, else 0 (=> waiting for new records on streams 
00471   //           when reading in update mode).   
00472   //
00473   //  Contact:   S. Kasahara
00474   //
00475   //  Notes: To return successful when in update mode requires that the
00476   //         method is able to see at least one record set with validity
00477   //         equal to or greater than the specified input validity, or that
00478   //         the method can see that the open file has been closed by
00479   //         the writer.
00480   //
00481 
00482   PerRecordTags tags = this -> GetTags();
00483   // Advance until equal to or greater than specified keyVld
00484   bool isdone = false;
00485   while ( (tags.IsBegin() || (tags.GetVldContext() < keyVld)
00486                           || (tags.IsEnd() && !this->IsEndOfFiles()))
00487                           && !isdone ) {
00488     tags = this -> NextTags();
00489     if ( tags.IsEnd() ) {
00490       if ( fUpdateMode && !this->IsFileEnd() ) return 0; // failure
00491       else {
00492         VldContext nextfilevld = GetNextFileVldFromMap();
00493         if ( nextfilevld != Per::GetVldEnd() && ( !nextfilevld.IsValid() 
00494                                              || nextfilevld <= keyVld ) ) {
00495           if ( this->NextFile() ) tags = this -> NextTags();
00496         }
00497         else isdone = true;
00498       }
00499     }
00500   }
00501 
00502   // Rewind until one set less or equal to specified input keyVld
00503   while ( tags.IsEnd() || tags.GetVldContext() > keyVld ) {
00504     // Rewind one set
00505     tags = this->PrevTags();
00506     if ( tags.IsBegin() ) {
00507       if ( this -> PrevFile() ) tags = this -> PrevTags();
00508     }
00509   }
00510 
00511   return 1;
00512 
00513 }

int PerInputStream::AdvanceTags  ) 
 

Definition at line 589 of file PerInputStream.cxx.

References fSumTags, fUpdateMode, GetTags(), PerRecordTags::IsEnd(), IsEndOfFiles(), IsFileEnd(), NextFile(), and NextTags().

Referenced by PerInputStreamManager::LoadRecord().

00589                                 {
00590   //
00591   // Purpose: Advance tags according to input order
00592   //
00593   // Return: 1 if successful, else 0 ( => waiting for new records on
00594   //         streams when reading in update mode).
00595   //
00596   // Contact: K. Arms
00597   //
00598   // Notes:  To return successful when in update mode requires that the
00599   //         method can see the open file and isn't at the end
00600   //
00601 
00602   PerRecordTags tags = this -> GetTags();
00603   /*
00604   bool inWhile = false;
00605 
00606   while ( tags.IsBegin()                      ||
00607           ( tags.IsEnd() && !IsEndOfFiles() )  ) {
00608     inWhile = true;
00609     //tags = this -> NextTags();
00610     if ( tags.IsEnd() ) {
00611       if ( fUpdateMode && !this -> IsFileEnd() ) return 0; // failure
00612       else if ( this -> NextFile() ) tags = this -> NextTags();
00613     }
00614   }
00615 
00616   if (!inWhile) 
00617   */
00618   if ( tags.IsEnd() && !IsEndOfFiles() ) {
00619     if ( fUpdateMode && !this -> IsFileEnd() ) return 0; // failure
00620     else if ( this -> NextFile() ) tags = this -> NextTags();
00621   }
00622   else
00623     tags = this -> NextTags();
00624 
00625   fSumTags++;
00626 
00627   if ( tags.IsEnd() && IsEndOfFiles() ) return 0;
00628 
00629   return 1;
00630 
00631 }

bool PerInputStream::AdvanceTagsList  )  [private]
 

Definition at line 95 of file PerInputStream.cxx.

References CleanTagsList(), fTagsList, fUpdateMode, PerRecordTags::GetIndexHi(), PerRecordTags::GetIndexLo(), PerStream::GetNumEntries(), Per::GetVldBegin(), GetVldContext(), PerRecordTags::GetVldContext(), Per::GetVldEnd(), PerRecordTags::IsComplete(), PerRecordTags::IsEnd(), IsFileEnd(), PerRecordTags::SetIndexHi(), TagsListItr, and UpdateTree().

Referenced by NextTags().

00095                                      {
00096   //
00097   //  Purpose:  Advance fTagsList to include next block of records with
00098   //            common VldContext.
00099   //
00100   //  Arguments: none
00101   //             
00102   //  Return: true if successful. New record block is stored in fTagsList
00103   //          PerRecordTags object.
00104   //
00105   //  Contact:   S. Kasahara
00106   // 
00107 
00108   if ( !fTFile ) return 0; // require opened file, but not tree 
00109 
00110   // Find entry corresponding to last data block in tags list.
00111   TagsListItr itr = fTagsList.end();
00112   if ( itr != fTagsList.begin() ) itr--;
00113   Int_t lastIndex = -1;
00114   VldContext oldVld = Per::GetVldBegin();
00115   if ( itr != fTagsList.end() ) {
00116     // the & is critical here to modify *itr contents
00117     PerRecordTags& oldTags = *itr; 
00118     if ( oldTags.IsEnd() ) {
00119       if ( !oldTags.IsComplete() ) {
00120         oldTags.SetIndexHi(oldTags.GetIndexLo());
00121         return 1;
00122       }
00123       else {
00124         return 0;
00125       }
00126     }
00127     lastIndex = TMath::Max(oldTags.GetIndexLo(),oldTags.GetIndexHi());
00128     oldVld = oldTags.GetVldContext();
00129   }
00130 
00131   // Advance in tree if we have not reached the end
00132   VldContext newVld = oldVld;
00133   while ( newVld == oldVld && ++lastIndex <= this->GetNumEntries() ) {
00134     if ( lastIndex == this->GetNumEntries() && fUpdateMode ) {
00135       this -> UpdateTree();
00136     }
00137     if ( lastIndex < this->GetNumEntries() ) {
00138       newVld = this -> GetVldContext(lastIndex);
00139     }
00140     else {
00141       // no new entries and update tree has been tried
00142       if ( !fUpdateMode || IsFileEnd() ) {
00143         // file is closed by writer or update mode not requested
00144         newVld = Per::GetVldEnd();  // indicate end of input stream
00145       }
00146       else return 0;  // file is open and reading in updatemode
00147     }
00148   }
00149 
00150 
00151   // Successfully advanced to next Vld block in tree
00152   // Complete previous Vld block if it exists
00153   if ( itr != fTagsList.end() ) (*itr).SetIndexHi(lastIndex-1);
00154   // Start new TagsList entry but indicate its incompleteness
00155   // by setting indexHi = -2 
00156   PerRecordTags recordtags("",fTreeName,fFullFilePathName,lastIndex,
00157                            -2,newVld);
00158   fTagsList.push_back(recordtags);
00159   
00160   this -> CleanTagsList(true);
00161 
00162   return  1;
00163 
00164 }

int PerInputStream::AdvanceWindowTags const VldContext keyVld  ) 
 

Definition at line 522 of file PerInputStream.cxx.

References VldTimeStamp::Add(), fUpdateMode, fWindowLower, fWindowTags, fWindowUpper, VldContext::GetDetector(), VldContext::GetSimFlag(), GetTags(), VldContext::GetTimeStamp(), Per::GetVldBegin(), PerRecordTags::GetVldContext(), Per::GetVldEnd(), PerRecordTags::IsBegin(), PerRecordTags::IsEnd(), IsEndOfFiles(), IsFileEnd(), make_delta(), NextFile(), NextTags(), PrevFile(), and PrevTags().

00522                                                               {
00523   //
00524   // Purpose: Advance window tags around keyVld in lower/upper window
00525   //          specified by user.  Records are loaded in fWindowTags
00526   //          and may be retrieved with GetWindowTags().
00527   //
00528   // Return: 1 if successful, else 0 ( => waiting for new records on
00529   //         streams when reading in update mode).  Success will be
00530   //         returned even if no records in the window are found.
00531   //
00532   // Contacts: B. Viren and S. Kasahara
00533   //
00534   // Notes:  To return successful when in update mode requires that the
00535   //         method is able to see at least one record set with validity
00536   //         equal to or greater than the specified input validity (+ upper
00537   //         window), or that the method can see that the open file has
00538   //         been closed by the writer
00539 
00540   fWindowTags.clear();
00541   if ( keyVld == Per::GetVldEnd() || keyVld == Per::GetVldBegin() ) return 0;
00542 
00543   // Make vldcontext for latter side of window
00544   VldTimeStamp top_vt = keyVld.GetTimeStamp();
00545   top_vt.Add(make_delta(fWindowUpper));
00546   VldContext topVld(keyVld.GetDetector(),keyVld.GetSimFlag(),top_vt);
00547   
00548   PerRecordTags tags = this -> GetTags();
00549   // Advance until equal to or just greater than specified window
00550   while ( tags.IsBegin() || ( tags.GetVldContext() < topVld )
00551                          || ( tags.IsEnd() && !IsEndOfFiles()) ) {
00552     tags = this -> NextTags();
00553     if ( tags.IsEnd() ) {
00554       if ( fUpdateMode && !this -> IsFileEnd() ) return 0; // failure
00555       else if ( this -> NextFile() ) tags = this -> NextTags();
00556     }
00557   }
00558 
00559   // Rewind until one set less or equal to top window edge
00560   while (  tags.IsEnd() || tags.GetVldContext() > topVld ) {
00561     tags = this -> PrevTags();
00562     if ( tags.IsBegin() ) {
00563       if ( this -> PrevFile() ) {
00564         tags = this -> PrevTags();
00565       }
00566     }
00567   }
00568   
00569   // success, but no tags in window found
00570   if ( tags.IsBegin() || tags.IsEnd() ) return 1; 
00571   
00572   // At this point we have aligned upper tag with upper end of window
00573   // Move through tags in reverse to find lower limit, but do not
00574   // cross file boundary.  Current limitation is that all tags in
00575   // window must be from the same file. 
00576   VldTimeStamp bot_vt = keyVld.GetTimeStamp();
00577   bot_vt.Add(make_delta(fWindowLower));
00578   VldContext botVld(keyVld.GetDetector(),keyVld.GetSimFlag(),bot_vt);
00579 
00580   while ( tags.GetVldContext() > botVld ) {
00581     fWindowTags.push_back(tags);
00582     tags = this -> PrevTags();
00583   }
00584 
00585   return 1;
00586    
00587 }

void PerInputStream::CleanTagsList bool  isforward = true  )  [private]
 

Definition at line 167 of file PerInputStream.cxx.

References fTagsList.

Referenced by AdvanceTagsList(), and RewindTagsList().

00167                                                  {
00168   //
00169   //  Purpose:  Keep record tags cache to reasonable size as defined by 
00170   //            fMaxListSize.
00171   //
00172   //  Arguments: true means low index records are popped off the list.
00173   //             false means high index records are popped off the list.
00174   //             
00175   //  Return:  none.
00176   //
00177   //  Contact:   S. Kasahara
00178   // 
00179 
00180   if ( isForward ) {
00181     while ( fTagsList.size() > fMaxListSize ) fTagsList.pop_front();
00182   }
00183   else {
00184     while ( fTagsList.size() > fMaxListSize ) fTagsList.pop_back();
00185   }
00186 
00187   return;
00188 
00189 }

void PerInputStream::Close  )  [virtual]
 

Reimplemented from PerStream.

Definition at line 191 of file PerInputStream.cxx.

References CloseFile().

Referenced by ~PerInputStream().

00191                            {
00192   //
00193   //  Purpose:  Close the input stream.
00194   //
00195   //  Arguments: none.
00196   //
00197   //  Return:  none.
00198   //
00199   //  Contact:   S. Kasahara
00200   // 
00201 
00202   CloseFile();
00203 
00204 }

void PerInputStream::CloseFile  )  [virtual]
 

Reimplemented from PerStream.

Definition at line 206 of file PerInputStream.cxx.

References PerStream::CloseFile(), and DisableFile().

Referenced by Close(), GoToFile(), NextFile(), PrevFile(), RemoveFile(), and SetFile().

00206                                {
00207   //
00208   //  Purpose:  Close the file attached to the input stream.
00209   //
00210   //  Arguments: none.
00211   //
00212   //  Return:  none.
00213   //
00214   //  Contact:   S. Kasahara
00215   // 
00216 
00217   this -> DisableFile(); // disable file but don't actually close it
00218   PerStream::CloseFile();  // now close it
00219 
00220 }

void PerInputStream::DisableFile  )  [private]
 

Definition at line 222 of file PerInputStream.cxx.

References fFileEnabled, fFileEnd, fTagsItr, fTagsList, fTreeCycle, and fTTreeFormula.

Referenced by CloseFile(), NextFile(), and PrevFile().

00222                                  {
00223   //
00224   //  Purpose:  Disable the file attached to the input stream but don't
00225   //            actually close it 
00226   //
00227   //  Arguments: none.
00228   //
00229   //  Return:  none.
00230   //
00231   //  Contact:   S. Kasahara
00232   // 
00233 
00234   fTagsList.clear();
00235   fTagsItr = fTagsList.end();
00236   fFileEnd = true; 
00237   fTreeCycle = -1;
00238   if (fTTreeFormula) delete fTTreeFormula; fTTreeFormula = 0;
00239   fFileEnabled = false;
00240 
00241 }

const VldContext& PerInputStream::GetLastEntryVld  )  const [inline]
 

Definition at line 46 of file PerInputStream.h.

Referenced by PerInputStreamManager::GetLastEntryVld().

00046 { return fLastEntryVld; }

int PerInputStream::GetMaxFileRepeat  )  const [inline]
 

Definition at line 83 of file PerInputStream.h.

00083 { return fMaxFileRepeat; }

double PerInputStream::GetMeanMom  )  const [inline]
 

Definition at line 84 of file PerInputStream.h.

Referenced by PerInputStreamManager::LoadRecord().

00084 { return fMeanMom; }

VldContext PerInputStream::GetNextFileVldFromMap  )  const [private]
 

Definition at line 438 of file PerInputStream.cxx.

References fFileItr, fFileList, fFileVldContextMap, and Per::GetVldEnd().

Referenced by AdvanceLowerBoundTags().

00438                                                        {
00439   // Purpose: Retrieve next file vldcontext from fFileVldContextMap
00440   //          if available.  VldContext is that of the first entry of
00441   //          the tree stored in the next file.  If not available,
00442   //          return invalid VldContext.  If no new files in list,
00443   //          return Per::GetVldEnd().
00444 
00445   VldContext invalidvld;
00446   
00447   if ( fFileList.empty() || fFileItr == fFileList.end() 
00448                          || fIsBOF ) return invalidvld;
00449 
00450   std::list<std::string>::const_iterator fileitr = fFileItr;
00451   fileitr++;
00452     
00453   if ( fileitr == fFileList.end() ) return Per::GetVldEnd();
00454   std::string fullfilepathname = *fileitr;
00455 
00456   std::map<std::string,VldContext>::const_iterator fv_itr;
00457   fv_itr = fFileVldContextMap.find(fullfilepathname);
00458   if (fv_itr == fFileVldContextMap.end()) return invalidvld;
00459 
00460   return fv_itr->second;
00461   
00462 }

TObject * PerInputStream::GetObject Int_t  entry = 0,
bool  useselection = true
 

Definition at line 243 of file PerInputStream.cxx.

References fFileCacheRead, fNewTree, fUpdateMode, PerStream::GetFullFilePathName(), PerStream::GetTestMode(), PerStream::GetTreeName(), IsBegin(), RecRecord::IsClearable(), IsEnd(), IsFileEnd(), IsOpen(), PerStream::IsPerOwnedDisabled(), IsSelected(), MSG, PerStream::Reset(), PerStream::SetPerOwned(), RecRecord::SetPerOwned(), and UpdateTree().

Referenced by GetVldContext(), Next(), and Previous().

00243                                                                 {
00244   //
00245   //  Purpose:  Retrieve object from current TTree corresponding to given
00246   //            entry number.  Entries are subject to the selection
00247   //            cut specified by the user via the
00248   //            PerInputStream::SetSelection method.  If the entry
00249   //            fails to pass the selection cut, a null pointer is
00250   //            returned.
00251   //
00252   //  Arguments: entry   Int_t requested entry by number in current TTree.
00253   //             useselection bool apply selection cuts specified through
00254   //                               PerInputStream::SetSelection.  If false
00255   //                               selection cuts will be ignored
00256   //                               (default = true). 
00257   //
00258   //  Return:  pointer to TObject if successful, else (TObject*)0.
00259   //
00260   //  Contact:   S. Kasahara
00261   // 
00262   //  Notes:  The TObject returned to the user is owned by the user, i.e.
00263   //          the user has the responsibility of deleting the allocated
00264   //          memory of this object.
00265   //          Use IsBegin() or IsEnd() to determine 
00266   //          if entry range limits of current tree have been reached.
00267 
00268   Reset(true);  // reset contents of object cache
00269 
00270   if ( !IsOpen() ) {
00271     return (TObject*)0;
00272   }
00273 
00274   fEntry = entry;  // requested entry becomes current entry
00275 
00276   if ( IsEnd() && fUpdateMode && !IsFileEnd() ) {
00277     // Attempt to update tree if writer has not yet closed file
00278     // and user has requested update mode
00279     UpdateTree();
00280   }
00281 
00282   if ( IsBegin() || IsEnd() ) {
00283     // requested entry number exceeds range of stream
00284     return (TObject*)0;
00285   }
00286 
00287   // Create new object of class stored in this tree  
00288   // fTObject = (TObject*)fTClass -> New();
00289   if ( !fTObject ) {
00290     fTBranch -> SetAddress(&fTObject); // and set branch address
00291     if ( fNewTree && fTObject ) {
00292       fNewTree = false;
00293       if ( !IsPerOwnedDisabled() ) {
00294         RecRecord* recrecord = dynamic_cast<RecRecord*>(fTObject);
00295         if ( recrecord && recrecord->IsClearable()) {
00296           recrecord->SetPerOwned(true);
00297           SetPerOwned(true);
00298         }
00299       }
00300     }
00301   }
00302   
00303   if ( !useselection || IsSelected() ) {
00304     // entry is retrieved and loaded into fTObject
00305     if (fFileCacheRead) fTTree->GetCurrentFile()->SetCacheRead(fFileCacheRead);
00306     Int_t nbytes = fTTree->GetEntry(fEntry);
00307     if (fFileCacheRead) fTTree->GetCurrentFile()->SetCacheRead(0);
00308     
00309     if ( nbytes <= 0 ) {
00310       // An error occured in retrieval of object
00311       MSG("Per",Msg::kError) << "An error occurred while retrieving\n"
00312         << "entry " << fEntry << " from tree " << this->GetTreeName() 
00313         << " in file\n" << this -> GetFullFilePathName() << "." << endl;
00314       this -> Reset(true);
00315       if ( GetTestMode() ) return 0;
00316       else {
00317         MSG("Per",Msg::kFatal) << "Aborting job due to read of corrupt record."
00318                                << endl;
00319         abort();
00320       }
00321     }
00322     // A little too Verbose
00323     //MSG("Per",Msg::kVerbose) 
00324     //  << "GetObject retrieved object with " << nbytes << " bytes from tree "
00325     // << fTreeName << " entry " << fEntry << "." << endl;
00326   }  
00327   else {
00328     this -> Reset(true);
00329   }
00330 
00331   TObject* objptr = fTObject;
00332   this -> Reset(); // soft reset of fTObject ptr, must do this now 
00333   
00334   return objptr; // caller now owns object 
00335 
00336 }

double PerInputStream::GetPushRandom  )  const [inline]
 

Definition at line 85 of file PerInputStream.h.

Referenced by PerInputStreamManager::LoadRecord().

00085 { return fPushRandom; }

Per::ESequenceMode PerInputStream::GetSequenceMode  )  const [inline]
 

Definition at line 48 of file PerInputStream.h.

Referenced by PerInputStreamManager::AdvanceLowerBoundTags(), PerInputStreamManager::AdvanceRecordTags(), PerInputStreamManager::AdvanceSequentialTags(), PerInputStreamManager::AdvanceWindowTags(), PerInputStreamManager::LoadRecordWithTag(), PerInputStreamManager::Print(), and PerInputStreamManager::RewindRecordTags().

00048 { return fSequenceMode; }

const PerRecordTags & PerInputStream::GetTags  ) 
 

Definition at line 406 of file PerInputStream.cxx.

References fTagsItr, fTagsList, and IsOpen().

Referenced by AdvanceLowerBoundTags(), AdvanceTags(), AdvanceWindowTags(), PerInputStreamManager::GetCurrentKeyVld(), PerInputStreamManager::GoToFile(), PerInputStreamManager::IsSelectedSet(), NextTags(), PrevTags(), and PerInputStreamManager::RewindRecordTags().

00406                                              {
00407   //
00408   //  Purpose:  Return tags containing location of current block of sequential
00409   //            records of common VldContext.
00410   //
00411   //  Arguments: none.
00412   //             
00413   //  Return:  PerRecordTags of current set of tags in list.  The 
00414   //           current position in map is maintained by fTagsItr.
00415   //           If record tags list is empty but the stream IsOpen(), the 
00416   //           begin-of-stream PerRecordTags 
00417   //           is returned.  If the record tags list is not empty, but the 
00418   //           iterator points to the end of this list,
00419   //           the end-of-stream PerRecordTags is returned.  Use
00420   //           PerRecordTags::IsBegin and PerRecordTags::IsEnd to test
00421   //           for these conditions.
00422   //
00423   //  Contact:   S. Kasahara
00424   // 
00425 
00426   if ( fTagsItr != fTagsList.end() ) {
00427     return *fTagsItr;
00428   }
00429 
00430   if ( fTagsList.empty() && this -> IsOpen() ) {
00431     return fTagsBegin;
00432   }
00433 
00434   return fTagsEnd;
00435 
00436 }

VldContext PerInputStream::GetVldContext Int_t  treeindex  ) 
 

Definition at line 339 of file PerInputStream.cxx.

References RecRecord::GetHeader(), PerStream::GetNumEntries(), GetObject(), PerStream::GetTreeName(), RecMinosHdr::GetVldContext(), Per::GetVldEnd(), IsOpen(), PerStream::IsPerOwned(), and MSG.

Referenced by AdvanceTagsList(), RewindTagsList(), and UpdateTree().

00339                                                     {
00340   //
00341   //  Purpose:  Retrieve VldContext of entry for specified tree index.
00342   //
00343   //  Arguments: tree index
00344   //
00345   //  Return:  VldContext if successful, else Per::GetVldEnd()
00346   //
00347   //  Contact:   S. Kasahara
00348   //
00349   //  Notes:  Retrieves object from header branch of tree only.
00350   //
00351 
00352   if ( !IsOpen() ) return Per::GetVldEnd();
00353 
00354   // Otherwise try to find the entry on the tree
00355   if ( index >= this -> GetNumEntries() || index < 0 ) {
00356     return Per::GetVldEnd();
00357   }
00358   
00359   bool isOwnedAtEntry = false;
00360   if ( IsPerOwned() ) isOwnedAtEntry = true;
00361   
00362   fTTree -> SetBranchStatus("*",false);
00363   fTTree -> SetBranchStatus(fTBranch->GetName(),true);
00364   fTTree -> SetBranchStatus("fHeader*",true);
00365   
00366   Int_t saveEntry = fEntry;
00367   VldContext indexVld = Per::GetVldEnd();
00368   TObject* object = this -> GetObject(index,false);
00369   if ( !object ) {
00370     MSG("Per",Msg::kWarning) << " No object retrieved from\n"
00371                              << "tree " << this->GetTreeName() << " index "
00372                              << index << "." << endl;
00373   }
00374   else {
00375     if ( RecMinos* record = dynamic_cast<RecMinos*>(object) ) {
00376       const RecMinosHdr* header = record -> GetHeader();
00377       if ( header ) indexVld = header->GetVldContext();
00378     }
00379     else if ( RecRecord* record = dynamic_cast<RecRecord*>(object) ) {
00380       indexVld = (record->GetHeader()).GetVldContext();
00381     }
00382     else {
00383       MSG("Per",Msg::kWarning) << " No VldContext retrieved from\n"
00384                                << "tree " << this->GetTreeName() << " index "
00385                                << index << "." << endl;
00386     }
00387 
00388     // object is owned by this method
00389     if ( !IsPerOwned() ) {
00390       delete object; object = 0;
00391     }
00392   }
00393    
00394   // turn all branches back on
00395   fTTree -> SetBranchStatus("*",true);
00396   if ( IsPerOwned() && !isOwnedAtEntry ) {
00397     if ( fTObject && fTBranch ) fTBranch->SetAddress(&fTObject); 
00398   }
00399   
00400   fEntry = saveEntry;
00401 
00402   return indexVld;
00403 
00404 }

std::vector<PerRecordTags> PerInputStream::GetWindowTags  )  const [inline]
 

Definition at line 45 of file PerInputStream.h.

00045 { return fWindowTags; }

int PerInputStream::GoToFile std::string  fullfilepathname  ) 
 

Definition at line 666 of file PerInputStream.cxx.

References CloseFile(), fFileItr, fFileList, fIsBOF, GoToFile(), MSG, and SetFile().

00666                                                        {
00667   //
00668   // Purpose: Move the stream to the file fullfilepathname in file list.
00669   //
00670   // Arguments: file name. If "", move the stream to the first file in the
00671   //            list. 
00672   //
00673   // Return: 1 if successful, 0 if not.  If file not found, no
00674   //         action is taken.
00675   //
00676   // Notes: Adapted from M. Messier's IoInputModule::GoToFile. Note
00677   //        that this method requires that fullfilepathname have been
00678   //        added to the stream file list first via the AddFile method.
00679   //
00680 
00681   if ( fFileList.empty() ) return 0;
00682   if ( fullfilepathname == "" ) return (this -> GoToFile(0));
00683 
00684   std::list<std::string>::iterator itr;
00685   for ( itr = fFileList.begin(); itr != fFileList.end(); ++itr ) { 
00686     if ( fullfilepathname == (*itr) ) { 
00687       this -> CloseFile();
00688       fFileItr = itr;
00689       fIsBOF = false;
00690       return ( this -> SetFile(fullfilepathname,Per::kRead) );
00691     }
00692   }
00693 
00694   // Failed to find file in list
00695   MSG("Per",Msg::kWarning) << " Request to GoToFile " << fullfilepathname
00696    << " on stream " << fStreamName << " failed.\n Not found in list." << endl;
00697 
00698   return 0;
00699 
00700 }

int PerInputStream::GoToFile int  n  ) 
 

Definition at line 633 of file PerInputStream.cxx.

References CloseFile(), fFileItr, fFileList, fIsBOF, MSG, and SetFile().

Referenced by GoToFile().

00633                                   {
00634   //
00635   // Purpose: Move the stream to the nth file in the list
00636   //
00637   // Arguments: file number (0 is first)
00638   //
00639   // Return: 1 if successful, 0 if not.  If n is out of range, no
00640   //         action is taken.
00641   //
00642   // Notes: Adapted from M. Messier's IoInputModule::GoToFile
00643   //
00644 
00645   std::list<std::string>::iterator itr(fFileList.begin());
00646   int i = 0;
00647   for ( ; i < n && itr != fFileList.end(); ++i, ++itr ) { continue; }
00648 
00649   if ( i != n || itr == fFileList.end() ) {
00650     MSG("Per",Msg::kWarning) 
00651       << " Request to GoToFile ["<< n << "] on stream " << fStreamName 
00652       << " failed.\n Valid file index range 0-" << fFileList.size()-1 
00653       << "." << endl;
00654     return 0;
00655   } 
00656 
00657   this -> CloseFile();  // close current file
00658   fFileItr = itr;
00659   fIsBOF = false;
00660   
00661   std::string fullfilepathname = *fFileItr;
00662   return (this -> SetFile(fullfilepathname,Per::kRead));
00663 
00664 }

bool PerInputStream::IsBegin  )  const [inline]
 

Definition at line 51 of file PerInputStream.h.

Referenced by GetObject(), and Previous().

00051 { return (fEntry < 0) ? true : false; }

int PerInputStream::IsBeginOfFiles  )  const [inline]
 

Definition at line 100 of file PerInputStream.h.

References fFileList.

Referenced by PerInputStreamManager::RewindRecordTags().

00100                               { return (!fFileList.empty() && fIsBOF) 
00101                                                                     ? 1 : 0; }

bool PerInputStream::IsEnd  )  const [inline]
 

Definition at line 50 of file PerInputStream.h.

References PerStream::GetNumEntries().

Referenced by GetObject(), and Next().

00050 {return (fEntry>=this->GetNumEntries()) ? true:false; }

int PerInputStream::IsEndOfFiles  )  const [inline]
 

Definition at line 99 of file PerInputStream.h.

References fFileItr, fFileList, and fIsBOF.

Referenced by AdvanceLowerBoundTags(), PerInputStreamManager::AdvanceRecordTags(), AdvanceTags(), and AdvanceWindowTags().

00099 { return ( !fIsBOF && fFileItr == fFileList.end() ) ? 1 : 0;}

bool PerInputStream::IsFileEnd  )  const [inline]
 

Definition at line 52 of file PerInputStream.h.

Referenced by AdvanceLowerBoundTags(), PerInputStreamManager::AdvanceRecordTags(), AdvanceTags(), AdvanceTagsList(), AdvanceWindowTags(), GetObject(), PerInputStreamManager::IsFileEnd(), Next(), PerInputStreamManager::Print(), SetFile(), and UpdateTree().

00052 { return fFileEnd; }

bool PerInputStream::IsOpen  )  const [inline]
 

Reimplemented from PerStream.

Definition at line 53 of file PerInputStream.h.

References PerStream::IsOpen().

Referenced by PerInputStreamManager::GetCurrentKeyVld(), GetObject(), GetTags(), GetVldContext(), IsSelected(), Previous(), and RewindTagsList().

00053 { return (PerStream::IsOpen() && fFileEnabled) ? true: false; }

bool PerInputStream::IsRequired  )  const [inline]
 

Definition at line 54 of file PerInputStream.h.

Referenced by PerInputStreamManager::IsSelectedSet().

00054 { return fRequired; }

bool PerInputStream::IsSelected  )  const [private]
 

Definition at line 702 of file PerInputStream.cxx.

References fTTreeFormula, IsOpen(), and MSG.

Referenced by GetObject().

00702                                       {
00703   //
00704   //  Purpose:  Apply user's selection cut (if specified) to current
00705   //            entry of TTree.  User's specify a selection cut via the
00706   //            PerInputStream::SetSelection method.
00707   //
00708   //  Arguments: none.
00709   //
00710   //  Return: true if entry passes selection cut.
00711   //
00712   //  Contact:   S. Kasahara
00713   // 
00714   //  Notes:  This mechanism of applying TTreeFormula to implement user's 
00715   //          selection cuts is adapted from an application observed in the 
00716   //          Babar's Pico Analysis Framework. 
00717   // 
00718 
00719   if ( !IsOpen() ) {
00720     MSG("Per",Msg::kWarning) 
00721       << "PerInputStream::IsSelected called on unopened stream " 
00722       << fStreamName << "." << endl;
00723     return false;
00724   }
00725 
00726   bool pass = true;
00727 
00728   // Check to see if user has implemented a selection cut and apply it.
00729   if ( fTTreeFormula ) {
00730     // TTree::LoadTree changes to entry of interest - doesn't load data yet 
00731     fTTree -> LoadTree(fEntry); 
00732     // Ask the treeformula to evaluate if this entry in the tree would pass
00733     // or fail the selection cuts.  Only necessary branches will be retrieved.
00734     if ( fTTreeFormula -> EvalInstance() == 0 ) {
00735       // if zero, the entry failed the cuts
00736       pass = false;
00737     }
00738   }
00739 
00740   return pass;  
00741 
00742 }

bool PerInputStream::IsValidSelectionString  )  const [inline]
 

Definition at line 49 of file PerInputStream.h.

00049 { return fIsValidSelectionString; }

std::ostream & PerInputStream::ListFile std::ostream &  os  )  const
 

Definition at line 744 of file PerInputStream.cxx.

References fFileList, len, and s().

00744                                                          {
00745  //
00746   //  Purpose:  Print the contents of the fFileList for this stream.
00747   //
00748   //  Contact:   S. Kasahara
00749   // 
00750   //  Notes:  Adapted from M. Messier's IoInputModule::List() method.
00751   //
00752 
00753   int idx = 0;
00754   std::string s;
00755   s = "index filename\n";
00756   os << s;
00757   int len = s.size();
00758   s = "=====  ";
00759   os << s;
00760   for ( int i = s.size()+1; i < len;  ++i) os << "=";
00761   os << endl;
00762 
00763   MsgFormat ifmt("%3i");
00764   std::list<std::string>::const_iterator itr;
00765   for ( itr = fFileList.begin(); itr != fFileList.end(); itr++ ) {
00766     os << "[" << ifmt(idx++)  << "] ";
00767     if ( itr == fFileItr ) os << "*";
00768     else os << " ";
00769     os << (*itr) << endl;
00770   }
00771  
00772   return os;
00773 
00774 }

TObject * PerInputStream::Next bool  seek = false  ) 
 

Definition at line 776 of file PerInputStream.cxx.

References fUpdateMode, GetObject(), IsEnd(), IsFileEnd(), and PerStream::Reset().

00776                                        {
00777   //
00778   //  Purpose:  Retrieve next entry from stream.  Entries are subject
00779   //            to the selection cut specified by the user via the
00780   //            PerInputStream::SetSelection method.  If the entry fails to
00781   //            pass the selection cut, and "seek" is set false, the
00782   //            a null pointer is returned.  If "seek" is set true,
00783   //            the method will continue to increment fEntry until it
00784   //            finds an entry passing the selection cut, or the end of
00785   //            the stream is reached.
00786   //
00787   //  Arguments: seek    bool   set true if user wishes to have stream
00788   //                            scroll through entries until it finds
00789   //                            entry passing selection cuts.
00790   //                            (default = false)
00791   //
00792   //  Return: pointer to retrieved TObject.  Returns null pointer if an
00793   //          error occured, the end of the stream is reached, or entry
00794   //          failed selection cuts and seek=false was set.
00795   //
00796   //  Contact:   S. Kasahara
00797   // 
00798   //  Notes:  The TObject returned to the user is owned by the user, i.e.
00799   //          the user has the responsibility of deleting the allocated
00800   //          memory of this object.
00801   //          Use PerInputStream::IsEnd() to determine if Next failed
00802   //          to retrieve a new entry because end of current tree has been 
00803   //          reached.   
00804 
00805   Reset(); // reset object cache
00806 
00807   if ( !fTFile ) {
00808     // No file has been opened
00809     return (TObject*)0;
00810   }
00811 
00812   if ( IsEnd() && (!fUpdateMode || IsFileEnd()) ) {
00813     // Reached end of entries on this stream 
00814     return (TObject*)0;
00815   }
00816  
00817   TObject* object = 0;
00818   if ( !seek ) {
00819     if(!IsEnd())fEntry++; // increment entry number
00820     object = GetObject(fEntry); 
00821   }
00822   else {
00823     // user has requested to seek for next entry satisfying selection cuts
00824     while (object == (TObject*)0) {
00825       if(!IsEnd())fEntry++;  // Increment current entry number
00826       object = GetObject(fEntry); 
00827       if (IsEnd()) break;  // this silliness is to give GetObject a chance
00828       // to update tree before giving up
00829     }
00830   }
00831 
00832   return object;  // caller now owns object
00833 
00834 }

int PerInputStream::NextFile int  n = 1  ) 
 

Definition at line 836 of file PerInputStream.cxx.

References CloseFile(), DisableFile(), fCurrFileRepeat, fFileItr, fFileList, fIsBOF, fMaxFileRepeat, fRepeatedFile, fSequenceMode, fTagsList, PerStream::GetStreamName(), MSG, PrevFile(), RemoveFile(), and SetFile().

Referenced by AdvanceLowerBoundTags(), PerInputStreamManager::AdvanceRecordTags(), AdvanceTags(), AdvanceWindowTags(), and RemoveFile().

00836                                   {
00837   //
00838   //  Purpose:  Move stream forward n files in stream file list.  If n exceeds 
00839   //            number of files to end of list, ptr is left at eof marker.  
00840   //
00841   //  Arguments: number of files to advance.
00842   //             
00843   //  Return: 0 if number of requested files not advanced or file not 
00844   //          successfully opened, else 1. 
00845   //
00846   //  Contact:   S. Kasahara
00847   // 
00848   //  Notes: Use IsEndOfFiles() to determine if at end of file list.
00849   //         If the next file in the list does not exist or cannot be 
00850   //         opened, a warning is issued and the file will be skipped, 
00851   //         advancing to the next file in the list
00852 
00853   if ( fFileList.empty() || (!fIsBOF && fFileItr == fFileList.end()) ) return 0;
00854 
00855   if ( fSequenceMode == Per::kSequential ||
00856        fSequenceMode == Per::kRandom      ) {
00857     if ( fCurrFileRepeat < fMaxFileRepeat &&
00858          !fTagsList.empty()                ) {
00859       MSG("Per",Msg::kDebug) << "Reusing file " << *fFileItr << endl;
00860       fRepeatedFile = true;
00861       fCurrFileRepeat++;
00862       return 1;
00863     } // end if : repeat file for random/sequential streams
00864     else {
00865       fCurrFileRepeat = 0;
00866     } // reset the repeat file counter if it is exceeded or we have no tags
00867   } // end if kSequential or kRandom sequence mode
00868 
00869   this -> DisableFile(); // disable current file but don't close it yet
00870 
00871   for ( int i = 0; i < n; i++ ) {
00872     if ( fIsBOF ) {
00873       fFileItr = fFileList.begin();
00874       fIsBOF = false;
00875     }
00876     else fFileItr++;
00877     
00878     // Flag attempts to read past the end of the file list
00879     if ( fFileItr == fFileList.end() ) {
00880       // Flag that we've reached the end of the input stream
00881       return 0;
00882     }
00883   }
00884 
00885   this -> CloseFile();
00886   std::string fullfilepathname = *fFileItr;
00887   if ( !this -> SetFile(fullfilepathname,Per::kRead) ) {
00888     // File open failed
00889     MSG("Per",Msg::kWarning) << "Stream " << GetStreamName() 
00890         << " failed\nto open file " << fullfilepathname 
00891         << ". File will be removed from this stream's file list and skipped." 
00892         << endl;
00893     this -> PrevFile(); // back up one so not sitting on file to be removed
00894     this -> RemoveFile(fullfilepathname);
00895     return this -> NextFile(); // and move to next
00896   }
00897 
00898   return 1;
00899 
00900 }

const PerRecordTags & PerInputStream::NextTags  ) 
 

Definition at line 902 of file PerInputStream.cxx.

References AdvanceTagsList(), fCurrFileRepeat, fMaxFileRepeat, fRanGen, fRepeatedFile, fSequenceMode, fTagsItr, fTagsList, GetTags(), PerRecordTags::IsComplete(), MSG, and ShuffleTagsList().

Referenced by AdvanceLowerBoundTags(), PerInputStreamManager::AdvanceRecordTags(), AdvanceTags(), and AdvanceWindowTags().

00902                                               {
00903   //
00904   //  Purpose:  Return tags containing location of next block of sequential
00905   //            records of common VldContext.
00906   //
00907   //  Arguments: none.
00908   //             
00909   //  Return:  PerRecordTags of next set of tags in list.  The 
00910   //           current position in map is maintained by fTagsItr.
00911   //           If no new records are available, the end-of-stream PerRecordTags
00912   //           is returned. Use PerRecordTags::IsEnd() to test for this 
00913   //           condition.  
00914   //
00915   //  Contact:   S. Kasahara
00916   // 
00917 
00918   PerRecordTags currentTags = this->GetTags();
00919 
00920   if ( fTagsItr != fTagsList.end() ) {
00921     fTagsItr++;
00922     if ( fTagsItr != fTagsList.end() && (*fTagsItr).IsComplete() ) {
00923       return *fTagsItr;
00924     }
00925   }
00926 
00927   if ( (fSequenceMode == Per::kSequential ||
00928         fSequenceMode == Per::kRandom      ) &&
00929        fRepeatedFile                         &&
00930        fCurrFileRepeat <= fMaxFileRepeat     &&
00931        !fTagsList.empty()                     ) {
00932     // shuffle tags list for Per::kRandom sequence mode
00933     if (fSequenceMode == Per::kRandom) {
00934       ShuffleTagsList(fRanGen);
00935     }
00936     MSG("Per",Msg::kDebug) << "Repeating file in stream " << fStreamName
00937                            << endl;
00938     fRepeatedFile = false;
00939     // put the tags list iterator at the beginning of the list
00940     fTagsItr = fTagsList.begin();
00941     return *fTagsItr;
00942   } // return the beginning of the tags list if we repeat the file
00943 
00944   // Reached end of map, advance and reposition iterator to end of map
00945   if ( this -> AdvanceTagsList() ) {
00946     fTagsItr = fTagsList.end();
00947     fTagsItr--;
00948     if ( !(*fTagsItr).IsComplete() ) {
00949       if ( fTagsItr != fTagsList.begin() ) {
00950         fTagsItr--;
00951         if ( *fTagsItr == currentTags && currentTags.IsComplete() ) {
00952           return ( this->NextTags() );
00953         }
00954       }
00955       else return (this -> NextTags() ); //required under special circumstances
00956     }
00957     return *fTagsItr;
00958   }   
00959   else {
00960     // Leave iter at previous complete location (open file) or at eof marker
00961     fTagsItr = fTagsList.end();
00962     if ( fTagsItr != fTagsList.begin() ) fTagsItr--;
00963     if (!(*fTagsItr).IsComplete() && fTagsItr != fTagsList.begin()) fTagsItr--;
00964   }
00965 
00966   return fTagsEnd;
00967 
00968 }

int PerInputStream::PrevFile int  n = 1  ) 
 

Definition at line 1021 of file PerInputStream.cxx.

References CloseFile(), DisableFile(), fFileItr, fFileList, fIsBOF, and SetFile().

Referenced by AdvanceLowerBoundTags(), AdvanceWindowTags(), and NextFile().

01021                                   {
01022   //
01023   //  Purpose:  Move stream back n files in  stream file list.  
01024   //
01025   //  Arguments: number of files to rewind.
01026   //             
01027   //  Return: 0 if n files not rewound or file not successfully open, else 1.
01028   //
01029   //  Contact:   S. Kasahara
01030   // 
01031 
01032   if ( fFileList.empty() || fIsBOF ) return 0;
01033 
01034   this -> DisableFile(); // disable current file but don't close it yet
01035 
01036   for ( int i = 0; i < n; i++ ) {
01037     if ( fFileItr == fFileList.begin() ) fIsBOF = true;
01038     else fFileItr--;
01039 
01040     // Flag attempts to read past the begin of the file list
01041     if ( fIsBOF ) return 0;
01042   }
01043 
01044   this -> CloseFile();
01045   std::string fullfilepathname = *fFileItr;
01046   return (this -> SetFile(fullfilepathname,Per::kRead));
01047 
01048 }

TObject * PerInputStream::Previous bool  seek = false  ) 
 

Definition at line 1050 of file PerInputStream.cxx.

References GetObject(), IsBegin(), IsOpen(), and PerStream::Reset().

01050                                            {
01051   //
01052   //  Purpose:  Retrieve previous entry from stream.  Entries are subject
01053   //            to the selection cut specified by the user via the
01054   //            PerInputStream::SetSelection method.  If the entry fails to
01055   //            pass the selection cut, and "seek" is set false, the
01056   //            a null pointer is returned.  If "seek" is set true,
01057   //            the method will continue to decrement fEntry until it
01058   //            finds an entry passing the selection cut, or the beginning of
01059   //            the stream is reached.
01060   //
01061   //  Arguments: seek   bool   set true if user wishes to have stream 
01062   //                           scroll through entries until it finds
01063   //                           entry passing selection cuts.
01064   //                           (default = false)
01065   //
01066   //  Return: pointer to retrieved TObject.  Returns null pointer if an
01067   //          error occured, the end of the stream is reached, or entry
01068   //          failed selection cuts and seek=false was set.
01069   //
01070   //  Contact:   S. Kasahara
01071   // 
01072   //  Notes:  The TObject returned to the user is owned by the user, i.e.
01073   //          the user has the responsibility of deleting the allocated
01074   //          memory of this object.
01075   //          Use PerInputStream::IsBegin() to determine if Previous failed
01076   //          to retrieve a new entry because beginning of stream has been 
01077   //          reached.  
01078 
01079   Reset(); // reset object cache
01080 
01081   if ( !IsOpen() ) {
01082     // No file has been opened
01083     return (TObject*)0;
01084   }
01085 
01086   if ( IsBegin() ) {
01087     return (TObject*)0;
01088   }
01089 
01090   TObject* object = 0;
01091   if ( !seek ) {
01092     fEntry--; // decrement entry number
01093     object = GetObject(fEntry); 
01094   }
01095   else {
01096     // user has requested to seek for next entry satisfying selection cuts
01097     while ( !IsBegin() && object == (TObject*)0) {
01098       fEntry--;  // Decrement current entry number
01099       object = GetObject(fEntry);
01100     }
01101   }
01102 
01103   return object;  // caller now owns object
01104 
01105 }

const PerRecordTags & PerInputStream::PrevTags  ) 
 

Definition at line 1108 of file PerInputStream.cxx.

References fTagsItr, fTagsList, GetTags(), and RewindTagsList().

Referenced by AdvanceLowerBoundTags(), AdvanceWindowTags(), and PerInputStreamManager::RewindRecordTags().

01108                                               {
01109   //
01110   //  Purpose:  Return tags containing location of previous block of sequential
01111   //            records of common VldContext.
01112   //
01113   //  Arguments: none.
01114   //             
01115   //  Return:  PerRecordTags of previous set of tags in list.  The 
01116   //           current position in map is maintained by fTagsItr.
01117   //           If no new records are available, a begin of stream
01118   //           PerRecordTags is returned.  Use PerRecordTags::IsBegin 
01119   //           to test for this condition.
01120   //
01121   //  Contact:   S. Kasahara
01122   // 
01123 
01124   PerRecordTags currentTags = this -> GetTags();
01125 
01126   if ( fTagsItr != fTagsList.begin() ) {
01127     fTagsItr--;
01128     if ( fTagsItr != fTagsList.end() && (*fTagsItr).IsComplete() ) {
01129       return *fTagsItr;
01130     }
01131   }
01132 
01133   // Reached beginning of list, rewind and reposition iterator to start of list
01134   if ( this -> RewindTagsList() ) {
01135     fTagsItr = fTagsList.begin();
01136     if ( !(*fTagsItr).IsComplete() ) {
01137       fTagsItr++;
01138       if ( fTagsItr == fTagsList.end() || !(*fTagsItr).IsComplete() || 
01139            (*fTagsItr == currentTags) ) 
01140         return ( this-> PrevTags());
01141     }
01142     return *fTagsItr;
01143   }  
01144   else {
01145     // Leave iterator at eof marker
01146     fTagsItr = fTagsList.begin();
01147   }
01148 
01149   // Failure returns a beginning-of-stream tags
01150   return fTagsBegin;
01151 
01152 }

std::ostream & PerInputStream::Print std::ostream &  s  )  const [virtual]
 

Reimplemented from PerStream.

Definition at line 1155 of file PerInputStream.cxx.

References fSelection, and PerStream::Print().

Referenced by operator<<().

01155                                                       {
01156   //
01157   //  Purpose:  Print status of stream on ostream.
01158   //
01159   //  Arguments: ms ostream to display on.
01160   //
01161   //  Return:  ostream reference.
01162   //
01163   //  Contact:   S. Kasahara
01164   //
01165 
01166   ms << "  PerInput"; 
01167   PerStream::Print(ms);
01168   ms << "  The current entry number of this stream is " << fEntry << endl;
01169   if ( !fSelection.empty() ) {
01170     ms << "  The selection cut:\n    " << fSelection 
01171        << "\n  has been specified for this stream.\n " << endl;
01172   }
01173   else {
01174     ms << "  A selection cut has not been specified for this stream." << endl;
01175   }
01176 
01177   return ms;
01178 
01179 }

int PerInputStream::RemoveFile std::string  fullfilepathname = "*"  ) 
 

Definition at line 1219 of file PerInputStream.cxx.

References CloseFile(), fFileItr, fFileList, find(), fIsBOF, and NextFile().

Referenced by NextFile().

01219                                                          {
01220   //
01221   //  Purpose:  Remove fullfilepathname from the list of input data files.
01222   //  
01223   //  Arguments: fullfilepathname  If == "*" (default), all files are removed.
01224   //             
01225   //  Return: number of removed files. 
01226   //
01227   //  Contact:   S. Kasahara
01228   //
01229   //  Notes: If requested file is currentfile, file will be closed.
01230   //         If fullfilepathname == "*", all files will be closed, and
01231   //         file iterator will be set to end of list.
01232   //         Otherwise, only 1 file (first matching) will be removed from
01233   //         file list, and iterator will be left alone if file is not
01234   //         currentfile, or incremented to next file if requested file
01235   //         is currentfile.
01236 
01237   
01238   if ( fFileList.empty() ) return 0; // nothing to remove
01239 
01240   if ( fullfilepathname == "*" ) {
01241     int nremoved = fFileList.size();
01242     if ( !fIsBOF && fFileItr != fFileList.end() ) CloseFile();
01243     fFileList.erase(fFileList.begin(),fFileList.end());
01244     fFileItr = fFileList.end();
01245     fIsBOF = false;
01246     return nremoved;
01247   }
01248   
01249   std::string currentFile = ""; bool isBegin = false;
01250   if ( !fIsBOF && fFileItr != fFileList.end() ) currentFile = *fFileItr;
01251   else if ( fIsBOF ) isBegin = true;
01252   std::list<std::string>::iterator itr=std::find(fFileList.begin(),
01253                                        fFileList.end(),fullfilepathname);
01254   if ( itr == fFileList.end() ) return 0; // requested file not in list
01255   
01256   if ( (!fIsBOF) && itr == fFileItr ) {
01257     // Current file, move forward 
01258     this -> NextFile();
01259     if ( fFileItr != fFileList.end() ) currentFile = *fFileItr;
01260     else currentFile = "";
01261   }
01262   
01263   fFileList.erase(itr);
01264 
01265   // Reset file iterator in revised list
01266   if ( isBegin && !fFileList.empty() ) fIsBOF = true;
01267   else { 
01268     fFileItr = std::find(fFileList.begin(),fFileList.end(),currentFile);
01269     fIsBOF = false;
01270   }
01271 
01272   return 1; 
01273   
01274  }

bool PerInputStream::RepeatFile  )  const [inline]
 

Definition at line 86 of file PerInputStream.h.

References fCurrFileRepeat.

00086 { return (fCurrFileRepeat < fMaxFileRepeat); }

void PerInputStream::Rewind  )  [inline]
 

Definition at line 70 of file PerInputStream.h.

00070 { fEntry = -1; }

bool PerInputStream::RewindTagsList  )  [private]
 

Definition at line 1276 of file PerInputStream.cxx.

References CleanTagsList(), fTagsList, PerRecordTags::GetIndexHi(), PerRecordTags::GetIndexLo(), PerStream::GetNumEntries(), Per::GetVldBegin(), GetVldContext(), PerRecordTags::GetVldContext(), Per::GetVldEnd(), PerRecordTags::IsBegin(), PerRecordTags::IsComplete(), IsOpen(), PerRecordTags::SetIndexLo(), and TagsListItr.

Referenced by PrevTags().

01276                                     {
01277   //
01278   //  Purpose:  Rewind fTagsList to include previous block of records with
01279   //            common VldContext.
01280   //
01281   //  Arguments: none
01282   //             
01283   //  Return: true if successful. New record block is stored in fTagsList
01284   //          PerRecordTags object.
01285   //
01286   //  Contact:   S. Kasahara
01287   // 
01288 
01289 
01290 
01291   if ( !IsOpen() ) return 0;
01292 
01293   // Find entry corresponding to first data block in tags list.
01294   TagsListItr itr = fTagsList.begin();
01295   Int_t lastIndex = this->GetNumEntries();
01296   VldContext oldVld = Per::GetVldEnd();
01297   if ( itr != fTagsList.end() ) {
01298     // The & is critical here so that can modify *itr contents
01299     PerRecordTags& oldTags = *itr;
01300     if ( oldTags.IsBegin() ) {
01301       if ( !oldTags.IsComplete() ) {
01302         oldTags.SetIndexLo(oldTags.GetIndexHi());
01303       // at beginning
01304         return 1;
01305       }
01306       else return 0;
01307     }
01308     if ( oldTags.IsComplete() ) lastIndex = oldTags.GetIndexLo();
01309     else lastIndex = TMath::Max(oldTags.GetIndexLo(),oldTags.GetIndexHi());
01310     oldVld = oldTags.GetVldContext();
01311   }
01312 
01313   // Rewind in tree if we have not reached the beginning
01314   VldContext newVld = oldVld;
01315   while ( newVld == oldVld && --lastIndex >= -1 ) {
01316     if ( lastIndex > -1 ) {
01317       newVld = this -> GetVldContext(lastIndex);
01318     }
01319     else {
01320       // At beginning of stream, lastIndex == -1
01321       newVld = Per::GetVldBegin();
01322     }
01323   }
01324 
01325   // Successfully rewound to previous Vld block in tree
01326   // Complete previous Vld block if it exists
01327   if ( itr != fTagsList.end() ) (*itr).SetIndexLo(lastIndex+1);
01328   PerRecordTags recordtags("",fTreeName,fFullFilePathName,-2,
01329                            lastIndex,newVld);
01330   fTagsList.push_front(recordtags);
01331   
01332   this -> CleanTagsList(false);
01333 
01334   return  1;
01335 
01336 }

bool PerInputStream::SetFile string  fullfilepathname,
Per::EAccessMode  accessmode = Per::kRead
 

Definition at line 1338 of file PerInputStream.cxx.

References Per::AsString(), CloseFile(), fFileEnabled, fFileEnd, fUpdateMode, PerFileManager::GetErrorCode(), PerFileManager::Instance(), IsFileEnd(), MSG, PerFileManager::OpenFile(), and UpdateTree().

Referenced by GoToFile(), NextFile(), and PrevFile().

01339                                                         {
01340   //
01341   //  Purpose:  Set new input file for this stream.
01342   //
01343   //  Arguments: fullfilepathname string      new filename containing stream.
01344   //             accessmode Per::EAccessMode  accessmode in which to open file.
01345   //                                          (default Per::kRead is currently
01346   //                                           the only allowed access mode
01347   //                                           for an input stream).
01348   //
01349   //  Return:  true if file was opened successfully and 
01350   //           i)tree of requested name was successfully retrieved OR
01351   //          ii)fUpdateMode has been set true for this stream and file is 
01352   //             not yet closed by the writer (and so potential for later 
01353   //             successful retrieval of tree exists).  This case is useful 
01354   //             when attempting to read an open file. 
01355   //
01356   //  Contact:   S. Kasahara
01357   //
01358   //  Notes: If SetFile returns false, PerStream::GetErrorCode can
01359   //         be used to determine reason for failure.
01360   //
01361 
01362   MSG("Per",Msg::kVerbose) << "SetFile(" << fullfilepathname << ","
01363                            << Per::AsString(accessmode) << ") called." << endl;
01364 
01365   // save current working directory so environment is left undisturbed on
01366   // output
01367   TDirectory* savedir = gDirectory;
01368 
01369   // Close, if necessary, old TTree and TFile before proceeding.
01370   CloseFile();
01371 
01372   fErrorCode = Per::kErrSuccess;
01373 
01374   if ( accessmode != Per::kRead ) {
01375     MSG("Per",Msg::kWarning) 
01376       << "PerInputStream::SetFile called w/ invalid accessmode "
01377       << Per::AsString(accessmode) << endl;
01378     fErrorCode = Per::kErrInvalidAccessMode;
01379     savedir -> cd();
01380     return false;
01381   }
01382 
01383   // Use file manager singleton to open file in requested mode.
01384   PerFileManager& perfilemanager = PerFileManager::Instance();
01385   const PerFile* file  = perfilemanager.OpenFile(fullfilepathname,accessmode);
01386   if ( !file ) {
01387     // file open failed, load file error in errorcode
01388     fErrorCode = perfilemanager.GetErrorCode();
01389     savedir -> cd();
01390     return false;
01391   }
01392   fTFile = file -> GetTFile();
01393   fFullFilePathName = fullfilepathname;
01394   fFileEnd = false;
01395 
01396   // Retrieve the requested tree from the file 
01397   if ( !UpdateTree() && ( !fUpdateMode || IsFileEnd() ) ) {
01398     // No Tree of requested name was available and writer has closed file
01399     // or user has not requested update mode
01400     MSG("Per",Msg::kWarning) << "Stream " << fStreamName.c_str()
01401                              << " failed to find tree " << fTreeName.c_str() 
01402                              << " in file " << fFullFilePathName.c_str() 
01403                              << "." << endl;
01404     fErrorCode = Per::kErrTreeReadError;
01405     CloseFile();
01406     savedir -> cd();
01407     return false;
01408   }
01409   
01410   savedir -> cd();
01411   fFileEnabled = true;
01412   return true;
01413 
01414 }

void PerInputStream::SetFileEnd bool  isFileEnd = true  )  [inline]
 

Definition at line 72 of file PerInputStream.h.

References fFileEnd.

00072 { fFileEnd = isFileEnd; }

void PerInputStream::SetMaxFileRepeat int  num = 0  )  [inline]
 

Definition at line 87 of file PerInputStream.h.

References fMaxFileRepeat.

00087 { fMaxFileRepeat = (num > 0)? num : 0; }

void PerInputStream::SetMeanMom double  mm = 0.  )  [inline]
 

Definition at line 88 of file PerInputStream.h.

References fMeanMom.

00088 { fMeanMom = (mm > 0.)? mm : 0.; }

void PerInputStream::SetPushRandom bool  tf = true  )  [inline]
 

Definition at line 89 of file PerInputStream.h.

References fPushRandom.

00089 { fPushRandom = tf; }

void PerInputStream::SetRandomGenerator TRandom *  ranGen  )  [inline]
 

Definition at line 90 of file PerInputStream.h.

References fRanGen.

00090 { fRanGen = ranGen; }

void PerInputStream::SetRequired bool  isRequired  )  [inline]
 

Definition at line 74 of file PerInputStream.h.

References fRequired.

00074 { fRequired = isRequired; }

bool PerInputStream::SetSelection string  selection = ""  ) 
 

Definition at line 1416 of file PerInputStream.cxx.

References fIsValidSelectionString, fSelection, fTTreeFormula, and MSG.

Referenced by UpdateTree().

01416                                                   {
01417   //
01418   //  Purpose:  Select certain entries of TTree only according to attributes
01419   //            of the data stored in the TTree. This method makes use
01420   //            of the TTreeFormula class to apply the requested selection
01421   //            to the TTree.
01422   //
01423   //  Arguments: selection  string describing selection cut to be applied
01424   //                        to TTree served by this stream.   
01425   //                        The form of the selection string is the same
01426   //                        as that used by the TTree::Draw mechanism, and
01427   //                        includes the specification of the branchname
01428   //                        and accessor methods of interest.  3 examples:
01429   //                      1)"((RawDaqSnarlHeader*)fHeader)->GetSnarl() < 100"
01430   //                         where fHeader is the name of the header branch
01431   //                         and GetSnarl() is the header accessor method.
01432   //                      2)"fComponents -> GetEntries() > 0"
01433   //                         where fComponents is the name of the TObjArray
01434   //                         branch and GetEntries() is the TObjArray accessor
01435   //                         method.
01436   //                      3)"((RawDaqSnarlHeader*)fHeader)->GetSnarl() < 100 &&
01437   //                         fComponents -> GetEntries() > 0"
01438   //                         to illustrate that selection cuts can be applied
01439   //                         in combination.
01440   //
01441   //  Return:  false if application of TTreeFormula to open TTree failed
01442   //           due to invalid expression.
01443   //
01444   //  Contact:   S. Kasahara
01445   //
01446 
01447   MSG("Per",Msg::kVerbose) << "PerInputStream::SetSelection " << selection
01448                            << " on stream " << fStreamName << "." << endl;
01449 
01450   // Delete previous fTTreeFormula, if appropriate.
01451   if ( fTTreeFormula ) delete fTTreeFormula; fTTreeFormula = 0;
01452 
01453   fSelection = selection;
01454    fIsValidSelectionString = true;
01455 
01456   // If TTree is open, fTTreeFormula is immediately created.  
01457   // Otherwise, fTTreeFormula will be created at time of TTree creation.
01458   if ( fTTree && !fSelection.empty() ) {
01459     fTTreeFormula = new TTreeFormula("PerSelection",fSelection.c_str(),fTTree);
01460     if (fTTreeFormula -> GetNdim() <= 0) {
01461       MSG("Per",Msg::kWarning) << "Invalid selection string ignored." << endl;
01462       delete fTTreeFormula; fTTreeFormula = 0;
01463       fIsValidSelectionString = false;
01464       return false;
01465     }
01466   }
01467 
01468   return true;
01469 
01470 }

void PerInputStream::SetSequenceMode Per::ESequenceMode  seqMode = Per::kKey  )  [inline]
 

Definition at line 75 of file PerInputStream.h.

References fSequenceMode.

00076                        { fSequenceMode=seqMode; }

void PerInputStream::SetUpdateMode bool  updatemode = true  )  [inline]
 

Definition at line 77 of file PerInputStream.h.

References fUpdateMode.

00077 { fUpdateMode = updatemode; }

void PerInputStream::SetWindow double  lower,
double  upper
[inline]
 

Set the window relative to the key VldContext to use in kWindow mode.

Definition at line 79 of file PerInputStream.h.

References fWindowLower, and fWindowUpper.

00080        { fWindowLower=lower; fWindowUpper=upper; }

void PerInputStream::ShuffleTagsList TRandom *  ranGen  ) 
 

Definition at line 1181 of file PerInputStream.cxx.

References fTagsList, and MSG.

Referenced by NextTags().

01182 {
01183   //
01184   // Purpose: Shuffle the tags list
01185   //
01186   // Note: This "swap shuffle" requires at least 3 reshuffles per
01187   //       call to this function to insure sufficient randomization.
01188   //       5 reshuffles is extra-safe.
01189   //
01190   // Contact: K. Arms
01191   //
01192 
01193   MSG("Per",Msg::kDebug) << "Shuffling " << fTagsList.size()-1
01194                          << " tags in stream " << fStreamName << endl;
01195 
01196   // >~ 3 insures a uniform randomization
01197   const unsigned int kNumRepeatShuffle = 5;
01198 
01199   for (unsigned int rep = 0; rep < kNumRepeatShuffle; rep++) {
01200     list<PerRecordTags>::iterator forward  = fTagsList.begin();
01201     list<PerRecordTags>::iterator backward = fTagsList.end();
01202     backward--; // puts itr at the last entry, which is a dummy
01203 
01204     while ( forward != (fTagsList.end()--) ){
01205       while ( backward != fTagsList.begin() ){
01206         backward--;
01207         bool flip = ranGen->Integer(2);
01208         if (flip) {
01209           PerRecordTags temp = *forward;
01210           *forward  = *backward;
01211           *backward = temp;
01212         } // end if       
01213       } // end while (backward)
01214       forward++;
01215     } // end while (forward)
01216   } // end reshuffle loop
01217 }

bool PerInputStream::UpdateTree  )  [private]
 

Definition at line 1472 of file PerInputStream.cxx.

References fCurrFileRepeat, fFileCacheRead, fFileEnabled, fFileEnd, fFileVldContextMap, fLastEntryVld, fMaxListSize, fNewTree, fRepeatedFile, fSelection, fSequenceMode, fTagsList, fTreeCycle, fTTreeFormula, PerStream::GetClassName(), PerStream::GetNumEntries(), PerFileManager::GetOpenedFile(), Per::GetVldBegin(), GetVldContext(), PerFileManager::Instance(), IsFileEnd(), MSG, and SetSelection().

Referenced by AdvanceTagsList(), GetObject(), and SetFile().

01472                                 {
01473   //
01474   //  Purpose: Retrieve latest TTree of name fTreeName from file.
01475   //
01476   //  Arguments: none.
01477   //
01478   //  Return:  true if tree was successfully retrieved, else false.
01479   //
01480   //  Contact:   S. Kasahara
01481   //
01482   //  Notes:  PerInputStream::SetFile must have been previously called to
01483   //          open the input file.
01484   //
01485 
01486   if ( !fTFile || this -> IsFileEnd() ) return false;
01487 
01488   bool newtree = false;
01489   TDirectory* saveDir = gDirectory;
01490   fTFile -> cd();
01491 
01492   // Retrieve latest set of keys from file and status of file closure
01493   Int_t nkeys = fTFile -> ReadKeys();
01494   if ( !nkeys ) {
01495     if (saveDir) saveDir -> cd();
01496     return false;
01497   }
01498 
01499   fFileEnd = PerFileManager::Instance().GetOpenedFile(fFullFilePathName)
01500                                                    -> HasFileEndKey();
01501 
01502   // The following loop only pulls in a new tree if it differs in cycle
01503   // number from a previously loaded tree to increase the efficiency in
01504   // the case of the read of an open ROOT file.
01505   TKey *key;
01506   TIter nextkey(fTFile->GetListOfKeys());
01507   while ((key = (TKey*)nextkey())) {
01508     if (strcmp(fTreeName.c_str(),key->GetName())==0) {
01509       // A new tree will be pulled in only if it differs from previous
01510       if ((fTreeCycle != key -> GetCycle()) || fFileEnd ) {
01511         TTree* tree = dynamic_cast<TTree*> (key -> ReadObj());
01512         if ( tree ) {
01513           // Successfully read in tree. (Failure to read in tree may be due
01514           // to a collision.)
01515           // Delete old tree before replacing it with new
01516           if (fTTree) delete fTTree; fTTree = 0; fTBranch = 0; 
01517           fTTree = tree;
01518 
01519           fTreeCycle = key -> GetCycle();
01520           newtree = true;
01521         }
01522         else {
01523           MSG("Per",Msg::kInfo) 
01524           << "PerInputStream experienced a recoverable collision reading tree "
01525           << fTreeName << " cycle " << key -> GetCycle() << "\nfrom file " 
01526           << fFullFilePathName << "." << endl;
01527         }  
01528         break;
01529       }
01530     }
01531   }  
01532 
01533   if ( newtree ) {
01534     // Retrieved tree is new
01535 
01536     if ( !fUpdateMode ) {
01537       // Not dispatcher 
01538       // TFile::UseCache broke between version 5.10/00 and 5.12/00
01539       // Try using SetCacheSize, which was fully implemented in root HEAD
01540       // on 7/23/2007.  
01541       if ( gROOT -> GetVersionInt() >= 51200 ) { 
01542         fTTree -> SetCacheSize(50000000); // per P. Canal instruction
01543         // The fFileCacheRead must be owned by this input stream to 
01544         // avoid having a segv on close when reading multiple trees from 
01545         // the same file.
01546         if ( fFileCacheRead ) delete fFileCacheRead; fFileCacheRead = 0;
01547         fFileCacheRead = fTFile -> GetCacheRead(); // store the new cache
01548         fTFile -> SetCacheRead(0); // ownership is ours! bwahaha
01549       }
01550     }
01551 
01552     // Every time we do an UpdateTree do a full delete of object cache
01553     // because otherwise SetBranchAddress won't be called for new tree
01554     if ( fTObject ) delete fTObject; fTObject = 0;
01555     fPerOwned = false;
01556     fNewTree = true;
01557 
01558     // Retrieve main branch and other data from information stored in TTree.
01559     // There should only be one main branch in TTree's created with the
01560     // Persistency package.
01561     TObjArray* branchlist = fTTree -> GetListOfBranches();
01562     Int_t nbranch = branchlist -> GetEntriesFast();
01563     if (nbranch != 1) {
01564       MSG("Per",Msg::kWarning) << "Unexpected number of main branches in tree "
01565                   << fTreeName << " from file " << fFullFilePathName << endl;
01566       delete fTTree; fTTree = 0; fTreeCycle= -1;
01567     }
01568     else {
01569       TBranchElement* branchelement 
01570                     = dynamic_cast<TBranchElement*>(branchlist -> At(0));
01571       if ( !branchelement ) {
01572         MSG("Per",Msg::kWarning) 
01573           << "Failed to retrieve main TBranchElement from tree" << fTreeName 
01574           << " from file " << fFullFilePathName << "." << endl;
01575         delete fTTree; fTTree = 0; fTreeCycle= -1;
01576       } 
01577       else {
01578         //classname&TClass of objects stored there,this is also name of branch.
01579         fClassName = branchelement -> GetClassName();
01580         fTBranch   = (TBranch*)branchelement;
01581  
01582         // Number of entries in this tree
01583         Int_t numEntries = this -> GetNumEntries();
01584 
01585         // Check to see if user has specified selection string
01586         if (!fSelection.empty()) {
01587           // If existing TTreeFormula, just apply it to new tree
01588           // This is a workaround until root fixes TTreeFormula memory leak
01589           if ( fTTreeFormula && fTreeCycle > 1) {
01590             fTTreeFormula->SetTree(fTTree);
01591             fTTreeFormula->UpdateFormulaLeaves();
01592           }
01593           else {
01594             this->SetSelection(fSelection); 
01595           }
01596         }
01597   
01598         // Store VldContext of first & last entry for use by manager in stream 
01599         // synchronization
01600         fFileEnabled = true;
01601         fLastEntryVld = Per::GetVldBegin();
01602         if ( numEntries > 0 ) { 
01603           fLastEntryVld = this -> GetVldContext(numEntries-1);
01604           fFileVldContextMap[fFullFilePathName] = this->GetVldContext(0);
01605         }
01606       }
01607     }
01608   }
01609   if ( newtree && fTTree != (TTree*)0) {
01610     if (fSequenceMode == Per::kSequential ||
01611         fSequenceMode == Per::kRandom      ) {
01612       fMaxListSize    = this->GetNumEntries()+1;
01613       fCurrFileRepeat = 0;
01614       fTagsList.erase( fTagsList.begin(), (fTagsList.end()--) );
01615       fRepeatedFile   = (fSequenceMode == Per::kRandom)? true : false;
01616     } // done setting the cache size to the number of snarls in this file
01617 
01618     MSG("Per",Msg::kDebug) << "\nUpdateTree retrieved tree " << fTreeName 
01619     << " with " << this->GetNumEntries() << " entries from file " 
01620     << fFullFilePathName << ". Last entry Vld " << fLastEntryVld << endl;
01621   }
01622   
01623   if (saveDir) saveDir -> cd();
01624 
01625   return (fTTree != (TTree*)0) ? true : false;
01626 
01627 
01628 }


Friends And Related Function Documentation

friend class PerInputStreamManager [friend]
 

Definition at line 36 of file PerInputStream.h.


Member Data Documentation

int PerInputStream::fCurrFileRepeat [private]
 

Definition at line 146 of file PerInputStream.h.

Referenced by NextFile(), NextTags(), RepeatFile(), and UpdateTree().

TFileCacheRead* PerInputStream::fFileCacheRead [private]
 

Definition at line 153 of file PerInputStream.h.

Referenced by GetObject(), UpdateTree(), and ~PerInputStream().

bool PerInputStream::fFileEnabled [private]
 

Definition at line 129 of file PerInputStream.h.

Referenced by DisableFile(), SetFile(), and UpdateTree().

bool PerInputStream::fFileEnd [private]
 

Definition at line 127 of file PerInputStream.h.

Referenced by DisableFile(), SetFile(), SetFileEnd(), and UpdateTree().

FileListItr PerInputStream::fFileItr [private]
 

Definition at line 140 of file PerInputStream.h.

Referenced by GetNextFileVldFromMap(), GoToFile(), IsEndOfFiles(), NextFile(), PrevFile(), and RemoveFile().

std::list<std::string> PerInputStream::fFileList [private]
 

Definition at line 138 of file PerInputStream.h.

Referenced by GetNextFileVldFromMap(), GoToFile(), IsBeginOfFiles(), IsEndOfFiles(), ListFile(), NextFile(), PrevFile(), and RemoveFile().

std::map<std::string,VldContext> PerInputStream::fFileVldContextMap [private]
 

Definition at line 139 of file PerInputStream.h.

Referenced by GetNextFileVldFromMap(), and UpdateTree().

bool PerInputStream::fIsBOF [private]
 

pointer to the PerInputStreamManager random # gen (NOT OWNED BY PERINPUTSTREAM)

Definition at line 152 of file PerInputStream.h.

Referenced by GoToFile(), IsEndOfFiles(), NextFile(), PrevFile(), and RemoveFile().

bool PerInputStream::fIsValidSelectionString [private]
 

Definition at line 122 of file PerInputStream.h.

Referenced by SetSelection().

VldContext PerInputStream::fLastEntryVld [private]
 

Definition at line 135 of file PerInputStream.h.

Referenced by PerInputStreamManager::AdvanceRecordTags(), PerInputStream(), and UpdateTree().

int PerInputStream::fMaxFileRepeat [private]
 

Definition at line 147 of file PerInputStream.h.

Referenced by NextFile(), NextTags(), and SetMaxFileRepeat().

UInt_t PerInputStream::fMaxListSize [private]
 

Definition at line 134 of file PerInputStream.h.

Referenced by UpdateTree().

double PerInputStream::fMeanMom [private]
 

Definition at line 148 of file PerInputStream.h.

Referenced by SetMeanMom().

bool PerInputStream::fNewTree [private]
 

Definition at line 130 of file PerInputStream.h.

Referenced by GetObject(), and UpdateTree().

bool PerInputStream::fPushRandom [private]
 

Definition at line 149 of file PerInputStream.h.

Referenced by SetPushRandom().

TRandom* PerInputStream::fRanGen [private]
 

Definition at line 151 of file PerInputStream.h.

Referenced by NextTags(), SetRandomGenerator(), and ~PerInputStream().

bool PerInputStream::fRepeatedFile [private]
 

Definition at line 150 of file PerInputStream.h.

Referenced by NextFile(), NextTags(), and UpdateTree().

bool PerInputStream::fRequired [private]
 

Definition at line 124 of file PerInputStream.h.

Referenced by SetRequired().

string PerInputStream::fSelection [private]
 

Definition at line 123 of file PerInputStream.h.

Referenced by PerInputStreamManager::IsSelectedSet(), Print(), SetSelection(), and UpdateTree().

Per::ESequenceMode PerInputStream::fSequenceMode [private]
 

Definition at line 131 of file PerInputStream.h.

Referenced by NextFile(), NextTags(), SetSequenceMode(), and UpdateTree().

UInt_t PerInputStream::fSumTags [private]
 

Definition at line 154 of file PerInputStream.h.

Referenced by AdvanceTags(), and PerInputStreamManager::LoadRecord().

PerRecordTags PerInputStream::fTagsBegin [private]
 

Definition at line 136 of file PerInputStream.h.

Referenced by PerInputStream().

PerRecordTags PerInputStream::fTagsEnd [private]
 

Definition at line 137 of file PerInputStream.h.

Referenced by PerInputStream().

TagsListItr PerInputStream::fTagsItr [private]
 

Definition at line 133 of file PerInputStream.h.

Referenced by DisableFile(), GetTags(), NextTags(), and PrevTags().

std::list<PerRecordTags> PerInputStream::fTagsList [private]
 

Definition at line 132 of file PerInputStream.h.

Referenced by AdvanceTagsList(), CleanTagsList(), DisableFile(), GetTags(), NextFile(), NextTags(), PrevTags(), RewindTagsList(), ShuffleTagsList(), and UpdateTree().

Short_t PerInputStream::fTreeCycle [private]
 

Definition at line 126 of file PerInputStream.h.

Referenced by DisableFile(), and UpdateTree().

TTreeFormula* PerInputStream::fTTreeFormula [private]
 

Definition at line 125 of file PerInputStream.h.

Referenced by DisableFile(), IsSelected(), PerInputStreamManager::IsSelectedSet(), SetSelection(), and UpdateTree().

bool PerInputStream::fUpdateMode [private]
 

Definition at line 128 of file PerInputStream.h.

Referenced by AdvanceLowerBoundTags(), AdvanceTags(), AdvanceTagsList(), AdvanceWindowTags(), GetObject(), Next(), SetFile(), and SetUpdateMode().

double PerInputStream::fWindowLower [private]
 

Definition at line 142 of file PerInputStream.h.

Referenced by AdvanceWindowTags(), and SetWindow().

std::vector<PerRecordTags> PerInputStream::fWindowTags [private]
 

Definition at line 144 of file PerInputStream.h.

Referenced by AdvanceWindowTags().

double PerInputStream::fWindowUpper [private]
 

Definition at line 143 of file PerInputStream.h.

Referenced by AdvanceWindowTags(), and SetWindow().


The documentation for this class was generated from the following files:
Generated on Mon Feb 15 11:10:00 2010 for loon by  doxygen 1.3.9.1