IoDataStreamItr Class Reference

#include <IoDataStreamItr.h>

Inheritance diagram for IoDataStreamItr:
IoDDSStreamItr IoDummyStreamItr IoInputStreamItr IoRerootStreamItr

List of all members.

Public Member Functions

 IoDataStreamItr ()
 IoDataStreamItr (const char *sourceName)
virtual ~IoDataStreamItr ()
const char * GetSourceName () const
void SetSourceName (const char *name)
virtual bool IsValid () const =0
virtual const char * GetFormat () const =0
virtual int LoadRecords (MomNavigator *mom)=0
virtual int Increment (int n=1, MomNavigator *m=0)=0
virtual int Decrement (int n=1, MomNavigator *m=0)=0
virtual JobCResult GoTo (const VldContext &vld, MomNavigator *m=0)=0
virtual int GoToEOF ()
virtual int DefineStream (const char *streamname, const char *treename)
virtual int Streams (const char *streamlist)
virtual int Select (const char *stream, const char *selection, bool isRequired=false)
virtual int SetSequenceMode (const char *stream, Per::ESequenceMode seqmode)
virtual int SetPerOwnedDisabled (const char *stream, bool perowneddisabled=true)
virtual int SetWindow (const char *stream, double lower, double upper)
virtual void SetPort (unsigned int port)
virtual void SetTimeOut (unsigned int seconds)
virtual int SetMaxFileRepeat (const char *stream, int numRepeat)
virtual int SetMeanMom (const char *stream, double mean)
virtual int SetPushRandom (const char *stream, bool setRandom)
virtual void SetRandomSeed (int rSeed)
virtual int SetTestMode (const char *stream, bool testmode)
virtual void AddFile (const char *fullfilepathname, int at=-1, const char *streamlist="*")
virtual const char * GetCurrentFile (const char *streamname="*") const
virtual JobCResult GoToFile (int i, const char *streamlist="*")
virtual JobCResult GoToFile (const char *fullfilepathname, const char *streamlist="*")
virtual JobCResult NextFile (int n=1, const char *streamlist="*")
virtual JobCResult PrevFile (int n=1, const char *streamlist="*")
virtual void RemoveFile (const char *fullfilepathname="*", const char *streamlist="*")
virtual std::ostream & ListFile (std::ostream &os, const char *streamlist="*") const

Private Member Functions

virtual JobCResult OpenFile ()
virtual void CloseFile ()

Private Attributes

std::string fSourceName
std::list< std::string > fFileList
std::list< std::string >::iterator fFileListItr
bool fIsBOF

Detailed Description

Definition at line 61 of file IoDataStreamItr.h.


Constructor & Destructor Documentation

IoDataStreamItr::IoDataStreamItr (  ) 

Definition at line 18 of file IoDataStreamItr.cxx.

00018                                 :
00019                fSourceName(""),fFileListItr(fFileList.end()),fIsBOF(false) { }

IoDataStreamItr::IoDataStreamItr ( const char *  sourceName  ) 

Definition at line 23 of file IoDataStreamItr.cxx.

00023                                                       :
00024        fSourceName(sourceName),fFileListItr(fFileList.end()),fIsBOF(false) { }

IoDataStreamItr::~IoDataStreamItr (  )  [virtual]

Definition at line 28 of file IoDataStreamItr.cxx.

00028 { }


Member Function Documentation

void IoDataStreamItr::AddFile ( const char *  fullfilepathname,
int  at = -1,
const char *  streamlist = "*" 
) [virtual]

Reimplemented in IoDDSStreamItr, IoDummyStreamItr, and IoInputStreamItr.

Definition at line 99 of file IoDataStreamItr.cxx.

References fFileList, fFileListItr, find(), and fIsBOF.

00100                                                             {
00101 //======================================================================
00102 // Add fullfilepathname to the list of input files at the position "at". 
00103 // -1 = end of list.  streamlist is ignored in this def implementation,
00104 // i.e. action is applied to all streams.
00105 //======================================================================
00106   // Remember the current file so we can come back here
00107   std::string curf;
00108   if ( !fIsBOF && fFileList.size()>0) curf = (*fFileListItr);
00109 
00110   // Figure out where to insert the file into the list
00111   std::string f(fullfilepathname);
00112   if (at<0)  {
00113     fFileList.push_back(f); 
00114   }
00115   else if (at==0) {
00116     fFileList.push_front(f);
00117   }
00118   else {
00119     std::list<std::string>::iterator itr(fFileList.begin());
00120     std::list<std::string>::iterator itrEnd(fFileList.end());
00121     for (int i=0; (i<at && itr!=itrEnd); ++i, ++itr) continue;
00122     fFileList.insert(itr,f);
00123   }
00124   
00125   // Put the position back to the orginal file (or start of list)
00126   if ( fIsBOF || fFileList.size()==1) {
00127     fIsBOF = true;  // NextFile will move to first file
00128   }
00129   else {
00130     // Find original file in new list
00131     fFileListItr = std::find(fFileList.begin(),fFileList.end(),curf);
00132     fIsBOF = false;
00133   }
00134 
00135   return;
00136 
00137 }

void IoDataStreamItr::CloseFile (  )  [private, virtual]

Reimplemented in IoRerootStreamItr.

Definition at line 369 of file IoDataStreamItr.cxx.

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

00369                                 {
00370 //======================================================================
00371 // Close current file 
00372 // Return: none.
00373 //======================================================================
00374 
00375   return;
00376 
00377 }

virtual int IoDataStreamItr::Decrement ( int  n = 1,
MomNavigator m = 0 
) [pure virtual]
int IoDataStreamItr::DefineStream ( const char *  streamname,
const char *  treename 
) [virtual]

Reimplemented in IoDummyStreamItr, and IoInputStreamItr.

Definition at line 41 of file IoDataStreamItr.cxx.

Referenced by IoInputModule::DefineStream(), and IoInputModule::UpdateStreamConfig().

00042                                                               { return 0; }

const char * IoDataStreamItr::GetCurrentFile ( const char *  streamname = "*"  )  const [virtual]

Reimplemented in IoDDSStreamItr, IoDummyStreamItr, and IoInputStreamItr.

Definition at line 184 of file IoDataStreamItr.cxx.

References fFileList, fFileListItr, and fIsBOF.

Referenced by IoInputModule::GetCurrentFile(), IoInputModule::NextFile(), and IoRerootStreamItr::OpenFile().

00184                                                                             {
00185 //======================================================================
00186 // Return current fullfilepathname.
00187 //======================================================================
00188   std::string currentfilename;
00189   if ( !fIsBOF && fFileListItr != fFileList.end() ) 
00190     currentfilename = *fFileListItr;
00191   return currentfilename.c_str();
00192 }

virtual const char* IoDataStreamItr::GetFormat (  )  const [pure virtual]
const char* IoDataStreamItr::GetSourceName (  )  const [inline]
virtual JobCResult IoDataStreamItr::GoTo ( const VldContext vld,
MomNavigator m = 0 
) [pure virtual]
int IoDataStreamItr::GoToEOF (  )  [virtual]

Reimplemented in IoDDSStreamItr, IoDummyStreamItr, IoInputStreamItr, and IoRerootStreamItr.

Definition at line 32 of file IoDataStreamItr.cxx.

References Increment().

Referenced by IoInputModule::Prev().

00033 {
00034   static const int BIG_NUMBER = 1000000;
00035   while (this->Increment(BIG_NUMBER)) { continue; }
00036   return 1; // AOK
00037 }

JobCResult IoDataStreamItr::GoToFile ( const char *  fullfilepathname,
const char *  streamlist = "*" 
) [virtual]

Reimplemented in IoDDSStreamItr, IoDummyStreamItr, and IoInputStreamItr.

Definition at line 261 of file IoDataStreamItr.cxx.

References CloseFile(), fFileList, fFileListItr, find(), fIsBOF, GoToFile(), Msg::kDebug, JobCResult::kWarning, Msg::kWarning, MSG, and OpenFile().

00262                                                                    {
00263 //======================================================================
00264 // Move the stream to file fullfilepathname in the list. If "", go to
00265 // first file in the list.
00266 // Return JobCResult::kAOK if advance successful and file opened okay, or
00267 //        JobCResult::kWarning, if requested file name not in list or
00268 //        JobCResult error code returned from OpenFile() if file open failed.
00269 //======================================================================
00270 
00271   std::string f(fullfilepathname);
00272 
00273   if (f == "") return this->GoToFile(0); // w/o argument reset to start of list
00274 
00275   std::list<std::string>::iterator itr = 
00276           std::find(fFileList.begin(), fFileList.end(), f);
00277 
00278   if ( itr != fFileList.end() ) {
00279     MSG("Io",Msg::kDebug) << "Go to file '" << f << "'." << endl;
00280     this -> CloseFile();
00281     fFileListItr = itr;
00282     fIsBOF = false;
00283     return this -> OpenFile(); // returns JobCResult::kAOK or error code   
00284   }
00285 
00286   MSG("Io",Msg::kWarning) << "File '" << f << "' not found in list." << endl;
00287   return JobCResult::kWarning;  // requested file not found 
00288 
00289 }

JobCResult IoDataStreamItr::GoToFile ( int  i,
const char *  streamlist = "*" 
) [virtual]

Reimplemented in IoDDSStreamItr, IoDummyStreamItr, and IoInputStreamItr.

Definition at line 231 of file IoDataStreamItr.cxx.

References CloseFile(), fFileList, fFileListItr, fIsBOF, JobCResult::kWarning, Msg::kWarning, MSG, and OpenFile().

Referenced by GoToFile().

00231                                                                         {
00232 //======================================================================
00233 // Move the stream to the nth file in the list ( n = 0 is first )
00234 // Return JobCResult::kAOK if advance successful and file opened okay, or
00235 //        JobCResult::kWarning, if requested file number out of range, or
00236 //        JobCResult error code returned from OpenFile() if file open failed.
00237 //======================================================================
00238 
00239   std::list<std::string>::iterator itr(fFileList.begin());
00240   std::list<std::string>::iterator itrEnd(fFileList.end());
00241   int i = 0;
00242   for ( ; i < n && itr != itrEnd; ++i,++itr) { continue; }
00243 
00244   if ( i != n || itr == itrEnd ) {
00245     // Did not find file -- warn and take no action
00246     MSG("Io",Msg::kWarning) << 
00247       "Request to goto file ["<< n <<"]. Only " << i <<" files loaded."<< endl;
00248     return JobCResult::kWarning;
00249   }
00250 
00251   this -> CloseFile(); // Close the current file
00252   fFileListItr = itr; // Reset the current file pointer
00253   fIsBOF = false;
00254   
00255   return this -> OpenFile(); // returns JobCResult::kAOK or error code
00256  
00257 }

virtual int IoDataStreamItr::Increment ( int  n = 1,
MomNavigator m = 0 
) [pure virtual]
virtual bool IoDataStreamItr::IsValid (  )  const [pure virtual]
std::ostream & IoDataStreamItr::ListFile ( std::ostream &  os,
const char *  streamlist = "*" 
) const [virtual]

Reimplemented in IoDDSStreamItr, IoDummyStreamItr, and IoInputStreamItr.

Definition at line 323 of file IoDataStreamItr.cxx.

References fFileList, fFileListItr, and len.

00324                                                                             {
00325 //======================================================================
00326 // Print the file list on ostream
00327 //======================================================================
00328 
00329   int indx = 0;
00330   MsgFormat ifmt("%3i");
00331 
00332   std::string s;
00333   s = "index  file name";
00334   os << s << endl;
00335   int len = s.size();
00336   s = "=====  ";
00337   os << s;
00338   for ( int i = s.size()+1; i < len; i++ ) os << "=";
00339   os << endl;
00340   
00341   std::list<std::string>::const_iterator itr(fFileList.begin());
00342   std::list<std::string>::const_iterator itrEnd(fFileList.end());
00343   for (; itr!=itrEnd; itr++) {
00344     os << "[" << ifmt(indx++) << "] ";
00345     if (itr == fFileListItr) os << "*";
00346     else os << " ";
00347     os << (*itr) << endl;
00348   }
00349 
00350   return os;
00351 
00352 }

virtual int IoDataStreamItr::LoadRecords ( MomNavigator mom  )  [pure virtual]
JobCResult IoDataStreamItr::NextFile ( int  n = 1,
const char *  streamlist = "*" 
) [virtual]

Reimplemented in IoDDSStreamItr, IoDummyStreamItr, and IoInputStreamItr.

Definition at line 196 of file IoDataStreamItr.cxx.

References CloseFile(), fFileList, fFileListItr, fIsBOF, JobCResult::kEndOfInputStream, and OpenFile().

00196                                                                         {
00197 //======================================================================
00198 // Move to the next file in the list (move by n positions)
00199 // Return JobCResult::kAOK if advance successful and file opened okay, or
00200 //        JobCResult::kEndOfInputStream, if at end of file list, or
00201 //        JobCResult error code returned from OpenFile() if file open failed.
00202 //======================================================================
00203 
00204   // If we've hit the end of the input stream, don't allow the user to
00205   // step further
00206   if ( fFileList.empty() || (!fIsBOF && fFileListItr == fFileList.end()) ) {
00207     return JobCResult::kEndOfInputStream;
00208   }
00209 
00210   this -> CloseFile();
00211   for ( int i = 0; i < n; i++ ) {
00212     if ( fIsBOF ) {
00213       fFileListItr = fFileList.begin();
00214       fIsBOF = false;
00215     }
00216     else fFileListItr++;
00217     
00218     // Flag attempts to read past the end of the file list
00219     if (fFileListItr == fFileList.end()) {
00220       // Flag that we've reached the end of the input stream
00221       return JobCResult::kEndOfInputStream;
00222     }
00223   }
00224 
00225   return this -> OpenFile(); // returns JobCResult::kAOK or error code
00226  
00227 }

JobCResult IoDataStreamItr::OpenFile (  )  [private, virtual]

Reimplemented in IoRerootStreamItr.

Definition at line 357 of file IoDataStreamItr.cxx.

References JobCResult::kWarning.

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

00357                                      {
00358 //======================================================================
00359 // Open current file. User must override this dummy def implementation. 
00360 // Return JobCResult::kAOK if success, else error message
00361 //======================================================================
00362 
00363   return JobCResult::kWarning;
00364 
00365 }

JobCResult IoDataStreamItr::PrevFile ( int  n = 1,
const char *  streamlist = "*" 
) [virtual]

Reimplemented in IoDDSStreamItr, IoDummyStreamItr, and IoInputStreamItr.

Definition at line 293 of file IoDataStreamItr.cxx.

References CloseFile(), fFileList, fFileListItr, fIsBOF, JobCResult::kBeginOfInputStream, and OpenFile().

00293                                                                         {
00294 //======================================================================
00295 // Rewind to the previous file in the list (move by n positions). 
00296 // Return JobCResult::kAOK if rewind successful and file opened okay, or
00297 //        JobCResult::kBeginOfInputStream, if at begin of file list, or
00298 //        JobCResult error code returned from OpenFile() if file open failed.
00299 //======================================================================
00300 
00301   // If we've hit the beginning of the input stream, don't allow the user 
00302   // to step further
00303   if ( fIsBOF ) {
00304     return JobCResult::kBeginOfInputStream;
00305   }
00306 
00307   this -> CloseFile();
00308   for ( int i = 0; i < n; i++ ) {
00309     if ( fFileListItr == fFileList.begin() ) fIsBOF = true;
00310     else fFileListItr--;
00311   
00312     // Flag attempts to read past the begin of the file list
00313     if ( fIsBOF ) {
00314       // Flag that we've reached the end of the input stream
00315       return JobCResult::kBeginOfInputStream;
00316     }
00317   }
00318 
00319   return this -> OpenFile(); // returns JobCResult::kAOK or error code   
00320 
00321 }

void IoDataStreamItr::RemoveFile ( const char *  fullfilepathname = "*",
const char *  streamlist = "*" 
) [virtual]

Reimplemented in IoDDSStreamItr, IoDummyStreamItr, and IoInputStreamItr.

Definition at line 141 of file IoDataStreamItr.cxx.

References fFileList, fFileListItr, find(), fIsBOF, Msg::kWarning, and MSG.

00142                                                                {
00143 //======================================================================
00144 // Remove the fullfilepathname from the list of input data files. If == "*", 
00145 // remove all files.  streamlist is ignored in this def implementation,
00146 // i.e. action is applied to all streams.
00147 //======================================================================
00148   
00149   std::string curf; bool isBegin = false;
00150   if ( !fIsBOF && fFileListItr != fFileList.end() ) 
00151                                                     curf = *fFileListItr;
00152   else if ( fIsBOF ) isBegin = true;
00153 
00154   std::string f(fullfilepathname);
00155 
00156   std::list<std::string>::iterator itr(fFileList.end());
00157   while ( !fFileList.empty() && itr != fFileList.begin() ) {
00158     itr--;  // Move backwards to undisturbed list as files erased off end
00159     if ( f == "*" || f == (*itr) ) {
00160       if ( fFileListItr == itr ) {
00161         MSG("Io",Msg::kWarning)
00162           << "Attempt to remove currently opened file\n" << (*itr) 
00163           << " ignored." << endl;
00164       }
00165       else {
00166         fFileList.erase(itr);
00167       }
00168     }
00169   }
00170 
00171   // Reset file iterator in revised list
00172   if ( isBegin && !fFileList.empty() ) fIsBOF = true;
00173   else {
00174     fFileListItr = std::find(fFileList.begin(),fFileList.end(),curf);
00175     fIsBOF = false;
00176   }
00177   
00178   return;
00179 
00180 }

int IoDataStreamItr::Select ( const char *  stream,
const char *  selection,
bool  isRequired = false 
) [virtual]

Reimplemented in IoDDSStreamItr, IoDummyStreamItr, and IoInputStreamItr.

Definition at line 50 of file IoDataStreamItr.cxx.

Referenced by IoInputModule::Select(), and IoInputModule::UpdateStreamConfig().

00052                                                    { return 0; }

int IoDataStreamItr::SetMaxFileRepeat ( const char *  stream,
int  numRepeat 
) [virtual]

Reimplemented in IoInputStreamItr.

Definition at line 83 of file IoDataStreamItr.cxx.

Referenced by IoInputModule::SetMaxFileRepeat(), and IoInputModule::UpdateStreamConfig().

00083 { return 0; }

int IoDataStreamItr::SetMeanMom ( const char *  stream,
double  mean 
) [virtual]

Reimplemented in IoInputStreamItr.

Definition at line 87 of file IoDataStreamItr.cxx.

Referenced by IoInputModule::SetMeanMom(), and IoInputModule::UpdateStreamConfig().

00087 { return 0; }

int IoDataStreamItr::SetPerOwnedDisabled ( const char *  stream,
bool  perowneddisabled = true 
) [virtual]

Reimplemented in IoInputStreamItr.

Definition at line 61 of file IoDataStreamItr.cxx.

Referenced by IoInputModule::SetPerOwnedDisabled().

00062                                                                   { return 0; }

void IoDataStreamItr::SetPort ( unsigned int  port  )  [virtual]

Definition at line 75 of file IoDataStreamItr.cxx.

00075 { }

int IoDataStreamItr::SetPushRandom ( const char *  stream,
bool  setRandom 
) [virtual]

Reimplemented in IoInputStreamItr.

Definition at line 91 of file IoDataStreamItr.cxx.

Referenced by IoInputModule::SetPushRandom(), and IoInputModule::UpdateStreamConfig().

00091 { return 0; }

void IoDataStreamItr::SetRandomSeed ( int  rSeed  )  [virtual]

Reimplemented in IoInputStreamItr.

Definition at line 95 of file IoDataStreamItr.cxx.

Referenced by IoInputModule::SetRandomSeed(), and IoInputModule::UpdateStreamConfig().

00095 {}

int IoDataStreamItr::SetSequenceMode ( const char *  stream,
Per::ESequenceMode  seqmode 
) [virtual]

Reimplemented in IoDummyStreamItr, and IoInputStreamItr.

Definition at line 56 of file IoDataStreamItr.cxx.

Referenced by IoInputModule::SetSequenceMode(), and IoInputModule::UpdateStreamConfig().

00057                                                               { return 0; }

void IoDataStreamItr::SetSourceName ( const char *  name  )  [inline]
int IoDataStreamItr::SetTestMode ( const char *  stream,
bool  testmode 
) [virtual]

Reimplemented in IoInputStreamItr.

Definition at line 66 of file IoDataStreamItr.cxx.

Referenced by IoInputModule::SetTestMode(), and IoInputModule::UpdateStreamConfig().

00067                                                       { return 0; }

void IoDataStreamItr::SetTimeOut ( unsigned int  seconds  )  [virtual]

Reimplemented in IoDDSStreamItr.

Definition at line 79 of file IoDataStreamItr.cxx.

00079 { }

int IoDataStreamItr::SetWindow ( const char *  stream,
double  lower,
double  upper 
) [virtual]

Reimplemented in IoDummyStreamItr, and IoInputStreamItr.

Definition at line 71 of file IoDataStreamItr.cxx.

Referenced by IoInputModule::SetWindow(), and IoInputModule::UpdateStreamConfig().

00071 { return 0; }

int IoDataStreamItr::Streams ( const char *  streamlist  )  [virtual]

Reimplemented in IoDDSStreamItr, IoDummyStreamItr, and IoInputStreamItr.

Definition at line 46 of file IoDataStreamItr.cxx.

Referenced by IoInputModule::UpdateStreamConfig().

00046 { return 0; }


Member Data Documentation

std::list<std::string> IoDataStreamItr::fFileList [private]
std::list<std::string>::iterator IoDataStreamItr::fFileListItr [private]
bool IoDataStreamItr::fIsBOF [private]

Definition at line 119 of file IoDataStreamItr.h.

Referenced by AddFile(), GetCurrentFile(), GoToFile(), NextFile(), PrevFile(), and RemoveFile().

std::string IoDataStreamItr::fSourceName [private]

Definition at line 116 of file IoDataStreamItr.h.

Referenced by GetSourceName(), and SetSourceName().


The documentation for this class was generated from the following files:

Generated on 22 Nov 2017 for loon by  doxygen 1.6.1