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

DemoInputModule.cc

Go to the documentation of this file.
00001 
00002 //
00003 // DemoInputModule
00004 //
00005 // Package: Per (Persistency) Demo class
00006 //
00007 // S. Kasahara 04/2001
00008 //
00009 // Purpose: DemoInputModule class illustrates how to initialize and
00010 //          receive data objects from a PerInputStream using a
00011 //          PerInputStreamManager to manage the input streams.
00012 //
00014 #include <string>
00015 #include "MessageService/MsgService.h"
00016 #include "Persistency/test/DemoInputModule.h"
00017 #include "Persistency/PerInputStream.h"
00018 
00019 std::ostream& operator<<(std::ostream& ms, const DemoInputModule& dm) {
00020   return dm.Print(ms); 
00021 }
00022 
00023 //   Definition of static data members
00024 //   *********************************
00025 
00026 //CVSID("$Id: DemoInputModule.cc,v 1.10 2001/12/19 05:11:56 kasahara Exp $");
00027 
00028 // Definition of methods (alphabetical order)
00029 // ******************************************
00030 
00031 bool DemoInputModule::BeginFile(std::string streamname,
00032                                 std::string fullfilepathname, 
00033                                 Per::EAccessMode accessmode) {
00034   //
00035   //  Purpose:  Begin new file for stream streamname.
00036   //
00037   //  Argument: streamname        streamname on which to begin new file.
00038   //                              if streamname = "*", set new file on
00039   //                              all managed streams. 
00040   //            fullfilepathname  full file path name of output file
00041   //            accessmode        accessmode in which file is to be opened
00042   //                              (either kRead or kUpdate) (default = kRead)
00043   //
00044   //  Return:  return true if successfully opened file for all managed
00045   //                       streams.
00046   //
00047   //  Contact:   S. Kasahara
00048   //
00049 
00050 
00051   bool openok = fInputStreamManager.SetFile(streamname,fullfilepathname,accessmode);
00052   return openok;
00053 
00054 }
00055 
00056 void DemoInputModule::BeginJob() {
00057   //
00058   // Purpose: Perform initialization of streams required at job startup.
00059   //
00060   // Arguments: none.
00061   //
00062   // Return: none.
00063   //
00064   // Contact:  S. Kasahara
00065   //
00066 
00067   PerInputStream* instream;
00068   // Open raw data streams (note that streamname need not be same as 
00069   // treename, although they can be)
00070   instream = fInputStreamManager.OpenStream("DaqSnarl","DaqSnarl");
00071 
00072   // Set selection string for this stream.  This specifies the cut that the
00073   // user would like to apply to data members of the object (RawRecord)
00074   // stored on this stream.  See PerInputStream::SetSelection for more info.
00075   // instream->SetSelection("((RawDaqSnarlHeader*)fHeader) -> GetSnarl() % 10 == 0"); 
00076   
00077 }
00078 
00079 void DemoInputModule::EndFile(std::string streamname) {
00080   //
00081   //  Purpose:  Close current file for specified stream.
00082   //
00083   //  Argument: streamname   string  if streamname="*", close file on all
00084   //                                 managed streams. 
00085   //
00086   //  Return:  none.
00087   //
00088   //  Contact:   S. Kasahara
00089   //
00090 
00091   fInputStreamManager.CloseFile(streamname);
00092 
00093   return;
00094 
00095 }
00096 
00097 void DemoInputModule::EndJob() {
00098   // 
00099   // Purpose: Close all streams at job end.
00100   //
00101   // Arguments: none.
00102   //
00103   // Return: none.
00104   //
00105   // Contact:  S. Kasahara
00106   //
00107 
00108   fInputStreamManager.CloseStream();
00109 
00110 }
00111 
00112 bool DemoInputModule::IsBegin() const {
00113   // 
00114   // Purpose: Check to see if all managed streams have reached beginning of
00115   //          current set of streams.
00116   //
00117   // Arguments: none.
00118   //
00119   // Return: none.
00120   //
00121   // Contact:  S. Kasahara
00122   //
00123 
00124   bool isbegin = false;
00125   if (fInputStreamManager.IsBegin())
00126     isbegin = true;
00127 
00128   return isbegin;
00129 
00130 }
00131 
00132 bool DemoInputModule::IsEnd() const {
00133   // 
00134   // Purpose: Check to see if all managed streams have reached end of
00135   //          current tree.
00136   //
00137   // Arguments: none.
00138   //
00139   // Return: none.
00140   //
00141   // Contact:  S. Kasahara
00142   //
00143 
00144   bool isend = false;
00145   if (fInputStreamManager.IsEnd())
00146     isend = true;
00147 
00148   return isend;
00149 
00150 }
00151 
00152 Int_t DemoInputModule::Next(MomNavigator* mom,Int_t advanceby) {
00153   //  Purpose:  Retrieve next entry from managed streams satisfying user's
00154   //            selection string (if specified).  The objects are
00155   //            extracted from the input streams and loaded into the
00156   //            input MomNavigator object.
00157   //
00158   //  Argument: mom  pointer to MomNavigator
00159   //            advanceby  number of records to move ahead (default=1)
00160   //
00161   //  Return:  returns the number of records retrieved.  
00162   //
00163   //  Contact:   S. Kasahara
00164   //
00165 
00166   Int_t nobject = fInputStreamManager.Next(mom,advanceby);
00167   return nobject;
00168 
00169 }
00170 
00171 Int_t DemoInputModule::Previous(MomNavigator* mom,Int_t rewindby) {
00172   //  Purpose:  Retrieve previous entry from managed streams satisfying user's
00173   //            selection string (if specified).  The objects are
00174   //            extracted from the input streams and loaded into the
00175   //            input MomNavigator object.
00176   //
00177   //  Argument: mom  pointer to MomNavigator
00178   //            rewindby  number of records to move back by (default=1)
00179   //
00180   //  Return:  returns the number of records retrieved.  
00181   //
00182   //  Contact:   S. Kasahara
00183   //
00184 
00185   Int_t nobject = fInputStreamManager.Previous(mom,rewindby);
00186   return nobject;
00187 
00188 }
00189 
00190 std::ostream& DemoInputModule::Print(std::ostream& ms) const {
00191   // Purpose:  Print status of demo input model on std::ostream.
00192   //
00193   // Arguments: ms std::ostream to display on.
00194   //
00195   // Return: std::ostream reference.
00196   //
00197   // Contact: S. Kasahara
00198   //
00199 
00200   fInputStreamManager.Print(ms);
00201 
00202   return ms;
00203 
00204 }
00205 
00206 
00207 
00208 
00209 
00210 
00211 
00212 
00213 
00214 
00215 
00216 
00217 
00218 
00219 
00220 
00221 
00222 
00223 
00224 
00225 
00226 
00227 
00228 
00229 
00230 
00231 
00232 
00233 
00234 
00235 
00236 
00237 
00238 
00239 
00240 
00241 
00242 
00243 
00244 
00245 
00246 
00247 
00248 
00249 
00250 
00251 

Generated on Mon Feb 15 11:06:36 2010 for loon by  doxygen 1.3.9.1