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

PerStream.cxx

Go to the documentation of this file.
00001 
00002 //
00003 // PerStream
00004 //
00005 // Package: Per (Persistency).
00006 //
00007 // S. Kasahara 04/2001
00008 //
00009 // Purpose: Base class for managing an individual data stream.  A data
00010 //          stream serves data to/from a ROOT TTree in a ROOT TFile.
00011 //          The user should use the PerStreamManager and derived classes to 
00012 //          open and close PerStreams.   
00013 //
00015 
00016 #include "TTree.h"
00017 #include "TFile.h"
00018 #include "Persistency/PerFileManager.h"
00019 #include "Persistency/PerStream.h"
00020 #include "Record/RecRecord.h"
00021 #include "MessageService/MsgService.h"
00022 
00023 CVSID("$Id: PerStream.cxx,v 1.18 2009/01/05 04:37:56 schubert Exp $");
00024 
00025 std::ostream& operator<<(std::ostream& ms, const PerStream& ps) {
00026   return ps.Print(ms);
00027 }
00028 
00029 ClassImp(PerStream)
00030 
00031 //   Definition of static data members
00032 //   *********************************
00033 
00034 
00035 // Definition of methods (alphabetical order)
00036 // ***************************************************
00037 
00038 //.......................................................................
00039 
00040 void PerStream::Close() {
00041   //
00042   //  Purpose:  Close the stream.
00043   //
00044   //  Arguments: none.
00045   //
00046   //  Return:  none.
00047   //
00048   //  Contact:   S. Kasahara
00049   // 
00050 
00051   CloseFile();  // close file for this stream
00052 
00053 }
00054 
00055 //.......................................................................
00056 
00057 void PerStream::CloseFile() {
00058   //
00059   //  Purpose:  Close current file serving this stream.
00060   //
00061   //  Arguments: none.
00062   //
00063   //  Return: none.
00064   //
00065   //  Contact:   S. Kasahara
00066   // 
00067 
00068   if ( fPerOwned && fTObject ) {
00069     delete fTObject;
00070   }
00071   fPerOwned = false;
00072   fTObject = 0;  // the cached object is not owned by the stream.
00073 
00074   // delete TTree.  This also deletes managed TBranches.
00075   if( fTTree) delete fTTree; fTTree = 0; fTBranch = 0; 
00076  
00077   // Starting with root ~v5.13 the fTTree dtor will create
00078   // a new object at the fTObject ptr address, but only 
00079   // some of the time (oddly). Check to see if a new object has
00080   // been created by the TTree dtor, and delete it if so.
00081   if ( fTObject ) delete fTObject;  fTObject = 0;
00082   
00083   if (!fFullFilePathName.empty()) {
00084     PerFileManager& filemanager = PerFileManager::Instance();
00085     filemanager.CloseFile(fFullFilePathName);
00086     fFullFilePathName = "";
00087     fTFile = 0;
00088     fEntry = -1;
00089   } 
00090 
00091   return;
00092 
00093 }
00094 
00095 //.......................................................................
00096 
00097 PerStream::PerStream(std::string treename) : 
00098   fTreeName(treename),fStreamName(""),fClassName(""),
00099   fFullFilePathName(""),fTFile(0),fTTree(0),fTBranch(0),fTObject(0),
00100   fEntry(-1),fEnable(true),fPerOwned(false),fPerOwnedDisabled(false),
00101   fErrorCode(Per::kErrSuccess),fTestMode(false) {
00102   //
00103   //  Purpose:  Default constructor.
00104   //
00105   //  Arguments: 
00106   //    treename   string   name of the tree served by this stream.
00107   //    streamname string   name of this stream (default = treename)
00108   //  Return:    n/a.
00109   //
00110   //  Contact:   S. Kasahara
00111   // 
00112 
00113   TTree::SetBranchStyle(1);  // use new 3.01 style of creating branches
00114 
00115 }
00116 
00117 //.......................................................................
00118 
00119 PerStream::~PerStream() {
00120   //
00121   //  Purpose:  PerStream destructor.  Closes stream and retrieves
00122   //            allocated memory.
00123   //
00124   //  Contact:   S. Kasahara
00125   // 
00126 
00127   Close();
00128 
00129 }
00130 
00131 //.......................................................................
00132 
00133 void PerStream::SetPerOwned(bool perowned) {
00134   //
00135   // Purpose: Designate this stream as owning it's records.  This will
00136   //          allow it to reuse the same record on each stream read to increase
00137   //          the efficiency of i/o.
00138   //
00139   // Contact: S. Kasahara
00140   //
00141 
00142   if ( perowned && IsPerOwnedDisabled() ) {
00143     MSG("Per",Msg::kWarning) 
00144       << "PerStream::SetPerOwned called for stream " << GetStreamName()
00145       << " but user has SetPerOwnedDisabled for this stream. Ignored." 
00146       << endl;
00147   }
00148   else fPerOwned = perowned;
00149 
00150   return;
00151   
00152 }
00153 
00154 //.......................................................................
00155 
00156 void PerStream::SetPerOwnedDisabled(bool perowneddisabled) {
00157   //
00158   // Purpose: Disable Per ownership for this stream.  
00159   //
00160   // Contact: S. Kasahara
00161   //
00162 
00163   if ( perowneddisabled && IsPerOwned() ) fPerOwned = false;
00164   fPerOwnedDisabled = perowneddisabled;
00165 
00166   return;
00167   
00168 }
00169 
00170 //.......................................................................
00171 
00172 std::ostream& PerStream::Print(std::ostream& ms) const {
00173   //
00174   //  Purpose:  Print status of stream on std::ostream.
00175   //
00176   //  Arguments: ms std::ostream to display on.
00177   //
00178   //  Return:  std::ostream reference.
00179   //
00180   //  Contact:   S. Kasahara
00181   // 
00182 
00183   ms << "Stream serving tree " << fTreeName 
00184      << (IsOpen() ? " is open " : " is not open ")      << "and" 
00185      << (IsEnabled() ? " enabled." : " disabled.") << endl;
00186   if ( IsOpen() ) {
00187     ms << "  Total entries in stream tree = " << (Int_t)fTTree ->GetEntries() 
00188        << endl;
00189     ms << "  The current file assigned to this stream is " 
00190        << fTTree->GetCurrentFile()->GetName() << endl; 
00191   }
00192   ms << "  This stream serves objects of classname " << fClassName << "." 
00193      << endl;
00194 
00195   return ms;
00196 
00197 }
00198 
00199 void PerStream::Reset(bool ishard) {
00200   //
00201   //  Purpose:  Reset.
00202   //
00203   //  Arguments: ishard, true => implies delete or Clear object (object owned) 
00204   //                    false => implies set object ptr to 0 (default)
00205   //
00206   //  Return: none.
00207   //
00208   //  Contact:   S. Kasahara
00209   // 
00210 
00211   if (!fTObject) return;
00212   
00213   if ( IsPerOwned() ) {
00214     if (ishard) {
00215       RecRecord* recrecord = dynamic_cast<RecRecord*>(fTObject);
00216       recrecord -> Clear(); 
00217       recrecord -> HasBeenModified(); // clear tags so that i/o will repersist
00218     }
00219   }
00220   else {
00221     if ( ishard ) {
00222       if ( fTObject ) delete fTObject; 
00223       fTObject = 0;
00224     }
00225     else {
00226       // object cache not owned, reset
00227       fTObject = 0;
00228     }
00229   }
00230 
00231   return;
00232 
00233 }
00234 

Generated on Mon Feb 15 11:07:19 2010 for loon by  doxygen 1.3.9.1