PerOutputStreamManager Class Reference

#include <PerOutputStreamManager.h>

Inheritance diagram for PerOutputStreamManager:

PerStreamManager List of all members.

Public Member Functions

 PerOutputStreamManager ()
virtual ~PerOutputStreamManager ()
std::ostream & Print (std::ostream &s, const char *option="") const
PerOutputStreamOpenStream (string streamname, string treename, string classname, string username="", string inputstreamname="", Int_t splitlevel=0, Int_t basketsize=64000, Int_t compress=-1)
Int_t Put (const MomNavigator *mom)
Int_t Write (string streamname="*", bool force=true)
Int_t SetAutoSave (std::string streamname="*", UInt_t autoSaveInt=0, UInt_t autoSaveTime=0, UInt_t autoSaveBytes=0, bool basketSaveLinked=true)

Private Member Functions

UInt_t GetRecordTimeSec (TObject *object)

Detailed Description

Definition at line 26 of file PerOutputStreamManager.h.


Constructor & Destructor Documentation

PerOutputStreamManager::PerOutputStreamManager (  )  [inline]

Definition at line 31 of file PerOutputStreamManager.h.

00031 {}

virtual PerOutputStreamManager::~PerOutputStreamManager (  )  [inline, virtual]

Definition at line 32 of file PerOutputStreamManager.h.

00032 {}


Member Function Documentation

UInt_t PerOutputStreamManager::GetRecordTimeSec ( TObject *  object  )  [private]

Definition at line 39 of file PerOutputStreamManager.cxx.

References DataUtil::GetVldContext().

Referenced by Put().

00039                                                                {
00040   // Private method to extract record time from time stamp if possible
00041   // else returns 0
00042 
00043   UInt_t recordTime = 0;
00044 
00045   if ( !object ) return recordTime;
00046 
00047   if ( RecMinos* record = dynamic_cast<RecMinos*>(object) ) {
00048     recordTime = (record -> GetVldContext() -> GetTimeStamp()).GetSec();
00049   }
00050   else if ( RecRecord* record = dynamic_cast<RecRecord*>(object) ) {
00051     recordTime = (record->GetHeader()).GetVldContext().GetTimeStamp().GetSec();
00052   }
00053 
00054   return recordTime;
00055   
00056 }

PerOutputStream * PerOutputStreamManager::OpenStream ( string  streamname,
string  treename,
string  classname,
string  username = "",
string  inputstreamname = "",
Int_t  splitlevel = 0,
Int_t  basketsize = 64000,
Int_t  compress = -1 
)

Definition at line 58 of file PerOutputStreamManager.cxx.

References PerStreamManager::fStreamMap, Msg::kWarning, and MSG.

Referenced by DemoDaqOutputModule::BeginJob(), RotoServer::OpenFile(), OltNewModule::OpenFile(), OltNewModule::OpenSpy(), PerValidate::OutputStreamMgr(), and SpillTimeCreateKeyFile().

00065                                                                      {
00066   //
00067   //  Purpose:  Open output stream with name streamname.
00068   //
00069   //  Arguments:streamname     name of stream to be opened. Names of managed
00070   //                           streams must be unique.
00071   //            treename       name of tree to be served by this stream.
00072   //            classname      classname of objects to be stored in this stream
00073   //            username       username of objects to be stored in this stream
00074   //                           used as secondary id to classname (default="")
00075   //       inputstreamname     input strm name of origin of objs to be stored
00076   //                           in this stream used as tertiary id (default="")
00077   //            splitlevel     splitlevel of created ROOT TTree branch 
00078   //                           (default = 0).
00079   //            basketsize     basketsize with which main branch on stream is
00080   //                           opened (default = 64000).
00081   //            compress       compression level with which tree will be 
00082   //                           written to file. Default = -1 => set to  
00083   //                           default compression level of file (ROOT
00084   //                           sets default file compression = 1).  Valid
00085   //                           range is 0 -> 9 with 0 == no compression.  
00086   //
00087   //  Return:  pointer to PerOutputStream. If unable to open stream (because
00088   //           stream with this streamname has already been opened), returns
00089   //           (PerOutputStream*)0.
00090   //
00091   //  Contact:   S. Kasahara
00092   //
00093   //  Notes: PerOutputStream objects are owned by the PerOutputStreamManager 
00094   //         and should only be deleted through the 
00095   //         PerStreamManager::CloseStream method.
00096 
00097   bool openok = false;
00098 
00099   PerOutputStream* stream = (PerOutputStream*)fStreamMap[streamname];
00100   if (!stream) {
00101     // Stream not found in map, need to create new one
00102     stream = new PerOutputStream(treename,classname,username,inputstreamname,
00103                                                splitlevel,basketsize,compress);
00104     stream -> SetStreamName(streamname);
00105     fStreamMap[streamname] = stream;
00106     openok = true;
00107   }
00108   else {
00109     MSG("Per",Msg::kWarning)<<"Stream manager failed to open requested stream "
00110       << streamname << " because name conflicts with previously opened stream."
00111       << endl;
00112   }
00113 
00114   return (openok) ? stream : (PerOutputStream*)0;
00115 
00116 }

std::ostream & PerOutputStreamManager::Print ( std::ostream &  s,
const char *  option = "" 
) const

Definition at line 119 of file PerOutputStreamManager.cxx.

References PerStreamManager::fPrintOpt, PerStreamManager::fStreamMap, and PerStreamManager::Print().

Referenced by operator<<().

00120                                                                       {
00121   //
00122   //  Purpose:  Print status of output stream manager on std::ostream.
00123   //
00124   //  Arguments: ms          std::ostream to display on.
00125   //             option      verbosity level ("" (default),or "brief")
00126   //  Return:  std::ostream reference.
00127   //
00128   //  Contact:   S. Kasahara
00129   //
00130 
00131   TString opt = option;
00132   opt.ToLower();
00133   if ( opt == "brief" || opt.IsNull() && fPrintOpt == "brief") {
00134     ms << "PerOutputStreamManager managing enabled streams: " << endl;
00135     Int_t nenabled = 0;
00136     for(StreamMapConstItr citr = fStreamMap.begin();
00137                           citr!= fStreamMap.end(); ++citr) {
00138       PerOutputStream* outstream =dynamic_cast<PerOutputStream*>(citr->second);
00139       if ( outstream -> IsEnabled() ) {
00140         ms << nenabled << ")" << citr->first 
00141            << " persisting records of class " 
00142            << outstream->GetClassName();
00143         string username = outstream->GetUserName();
00144         if ( !username.empty() ) ms << ", username " << username;
00145         string inputstreamname = outstream->GetInputStreamName();
00146         if ( !inputstreamname.empty() ) 
00147           ms << ", originating from input stream " << inputstreamname;
00148         ms << " with splitlevel " << outstream->GetSplitLevel() 
00149            << " and AutoSave(Int,Time,Bytes) (" << outstream->GetAutoSaveInt()
00150            << "," << outstream->GetAutoSaveTime() << "," 
00151            << outstream->GetAutoSaveBytes() << ")" << endl;
00152         nenabled++;
00153       }
00154     }
00155   }
00156   else {
00157     ms << "PerOutput";
00158     PerStreamManager::Print(ms);
00159   }
00160 
00161   return ms;
00162 
00163 }

Int_t PerOutputStreamManager::Put ( const MomNavigator mom  ) 

Definition at line 166 of file PerOutputStreamManager.cxx.

References PerStreamManager::fStreamMap, GetRecordTimeSec(), Msg::kVerbose, MSG, MSGSTREAM, and Munits::second.

Referenced by PerValidate::OutputStreamMgr(), IoOutputModule::Put(), DemoDaqOutputModule::Put(), and SpillTimeCreateKeyFile().

00166                                                          {
00167   //  Purpose:  Extract objects from mom and fill them into stream tree 
00168   //            designated to persist that object.
00169   //
00170   //  Argument: mom  pointer to MomNavigator
00171   //
00172   //  Return:  number of objects actually persisted.
00173   //
00174   //  Contact:   S. Kasahara
00175   //
00176 
00177   PerOutputStream* outstream;
00178 
00179   Int_t nobject = 0;
00180 
00181   // Loop over output streams managed by this stream manager
00182   UInt_t maxcurrentTime = 0;
00183   for ( StreamMapConstItr citr = fStreamMap.begin(); 
00184                           citr != fStreamMap.end(); ++citr ) {
00185     outstream = (PerOutputStream*)citr -> second;
00186     if (outstream -> IsOpen() && outstream -> IsEnabled()) {
00187     // retrieve classname & username of objects served by this stream
00188       string streamusername = outstream -> GetUserName(); 
00189       string streaminputstream = outstream -> GetInputStreamName(); 
00190 
00191       // Loop over objects stored in Mom.
00192       TIter fiter = const_cast<MomNavigator*>(mom) -> FragmentIter();
00193       TObject* object = 0;
00194       while ( (object = fiter.Next()) ) {
00195         // SetObject will test to see if this object is of the right type
00196         // for the output stream
00197         if ( outstream -> SetObject(object) ) {
00198           outstream -> Store();
00199           outstream -> Reset();
00200           MsgStream& msgPer = MSGSTREAM("Per",Msg::kVerbose);
00201           msgPer << "Persisted object: class " << object->IsA()->GetName();
00202           if ( !streamusername.empty() ) 
00203             msgPer << ", username " << object->GetName();
00204           if ( !streaminputstream.empty() )  
00205             msgPer << ", origin " << streaminputstream;
00206           msgPer << " on output stream " << citr->first << "." << endl;
00207           UInt_t currentTime = GetRecordTimeSec(object);
00208           if ( currentTime > maxcurrentTime ) maxcurrentTime = currentTime;
00209           nobject++;
00210         }
00211       }
00212     }
00213   }
00214 
00215   if ( maxcurrentTime > 0 ) {
00216     for ( StreamMapConstItr citr = fStreamMap.begin();
00217           citr != fStreamMap.end(); ++citr ) {
00218       outstream = (PerOutputStream*)citr -> second;
00219       outstream -> AutoSaveByTime(maxcurrentTime);
00220     }
00221   }
00222 
00223   MSG("Per",Msg::kVerbose) << "Put persisted " 
00224        << nobject << " total object(s). " << endl; 
00225   return nobject;
00226 
00227 }

Int_t PerOutputStreamManager::SetAutoSave ( std::string  streamname = "*",
UInt_t  autoSaveInt = 0,
UInt_t  autoSaveTime = 0,
UInt_t  autoSaveBytes = 0,
bool  basketSaveLinked = true 
)

Definition at line 229 of file PerOutputStreamManager.cxx.

References PerStreamManager::fStreamMap, PerStreamManager::GetOpenedStream(), Munits::second, and PerOutputStream::SetAutoSave().

Referenced by IoOutputModule::Config().

00231                              {
00232   //  Purpose:  Set autosave interval(s) of specified stream(s).
00233   //
00234   //  Argument: streamname  std::string  name of stream.
00235   //                                if streamname="*" (default), change will 
00236   //                                affect all streams.
00237   //           autoSaveInt   UInt_t  TTree save entry interval     (default=0 
00238   //                              => no AutoSave requested at entry intervals) 
00239   //           autoSaveTime  UInt_t  TTree save time interval(sec) (default=0 
00240   //                              => no AutoSave requested at time intervals) 
00241   //           autoSaveBytes UInt_t  TTree save byte interval      (default=0 
00242   //                              => no AutoSave requested at byte intervals) 
00243   //        basketSaveLinked bool    tie basket dumps to TTree saves so that
00244   //                                 all branch baskets are dumped just before
00245   //                                 the tree header is saved to disk. 
00246   //                                 (default = true)
00247   //
00248   //  Return:  number of streams affected.
00249   //
00250   //  Contact:   S. Kasahara
00251   //
00252   //  Notes:  Invokes PerOutputStream::SetAutoSave for each requested 
00253   //          stream.
00254   //
00255 
00256   Int_t nstream = 0;
00257 
00258   if (streamname == "*") {
00259     for (StreamMapConstItr citr = fStreamMap.begin();
00260          citr != fStreamMap.end(); ++citr) {
00261       ((PerOutputStream*)(citr -> second)) 
00262        -> SetAutoSave(autosaveint,autosavetime,autosavebytes,basketsavelinked);
00263       nstream++;
00264     }
00265   }
00266   else {
00267     PerOutputStream* stream = (PerOutputStream*)GetOpenedStream(streamname);
00268     if (stream) {
00269       stream->SetAutoSave(autosaveint,autosavetime,autosavebytes,
00270                           basketsavelinked);
00271       nstream++;
00272     }
00273   }
00274 
00275   return nstream;
00276   
00277 }

Int_t PerOutputStreamManager::Write ( string  streamname = "*",
bool  force = true 
)

Definition at line 279 of file PerOutputStreamManager.cxx.

References PerStreamManager::fStreamMap, PerStreamManager::GetOpenedStream(), and Munits::second.

Referenced by RotoServer::CloseFile(), OltNewModule::CloseFile(), IoOutputModule::CloseFile(), OltNewModule::CloseSpy(), DemoDaqOutputModule::EndFile(), PerValidate::OutputStreamMgr(), RotoServer::Run(), SpillTimeCreateKeyFile(), and RotoServer::~RotoServer().

00279                                                                  {
00280   //  Purpose:  Write tree of specified stream(s) to file.
00281   //
00282   //  Argument: streamname  string  name of stream for which to write tree.
00283   //                                if streamname="*" (default), all 
00284   //                                streams will have their tree written.
00285   //            force       bool    true => tree is written to file even
00286   //                                if empty (default).  
00287   //
00288   //  Return:  number of trees written to file.
00289   //
00290   //  Contact:   S. Kasahara
00291   //
00292   //  Notes:  Invokes PerOutputStream::Write for each requested stream.
00293   //          This method would normally be invoked only once just before
00294   //          CloseFile.  
00295 
00296   Int_t ntree = 0;
00297 
00298   if (streamname == "*") {
00299     // Write tree on all streams
00300     for (StreamMapConstItr citr = fStreamMap.begin();
00301          citr != fStreamMap.end(); ++citr) {
00302       if ( force || citr -> second -> GetNumEntries() != 0 ) { 
00303         Int_t nbytes = ((PerOutputStream*)(citr -> second)) -> Write();
00304         if ( nbytes > 0 ) ntree++;
00305       }
00306     }
00307   }
00308   else {
00309     // Write tree on specified stream
00310     PerOutputStream* stream = (PerOutputStream*)GetOpenedStream(streamname);
00311     if (stream) {
00312       if ( force || stream -> GetNumEntries() != 0 ) {
00313         Int_t nbytes = stream -> Write();
00314         if ( nbytes > 0 ) ntree++;
00315       }
00316     }
00317   }
00318 
00319   return ntree;
00320   
00321 }


The documentation for this class was generated from the following files:
Generated on Mon Aug 11 01:06:41 2014 for loon by  doxygen 1.4.7