![]() |
|
|
Bdb packages | Design docs | Source docs | Guidelines | Recent releases |
|
Main Page Modules Namespace List Class Hierarchy Alphabetical List Compound List File List Compound Members File Members /Framework/src/AppFileStream.cc
Go to the documentation of this file.00001 //-------------------------------------------------------------------------- 00002 // File and Version Information: 00003 // $Id: AppFileStream.cc,v 1.3 2000/11/06 15:58:21 desilva Exp $ 00004 // 00005 // Description: 00006 // Class AppFileStream. The output stream class, implemented as a file. 00007 // 00008 // Environment: 00009 // Software developed for the BaBar Detector at the SLAC B-Factory. 00010 // 00011 // Author List: 00012 // David R. Quarrie Original Author 00013 // 00014 // Copyright Information: 00015 // Copyright (C) 1999 Lawrence Berkeley Laboratory 00016 // 00017 //------------------------------------------------------------------------ 00018 #include "Experiment/Experiment.hh" 00019 00020 //#ifndef DEFECT_NO_STRING_CLASS 00021 //#include <string> 00022 //#else 00023 //#endif 00024 00025 //----------------------- 00026 // This Class's Header -- 00027 //----------------------- 00028 #include "Framework/AppFileStream.hh" 00029 00030 //------------- 00031 // C Headers -- 00032 //------------- 00033 #include <assert.h> 00034 #include <string.h> 00035 00036 //--------------- 00037 // C++ Headers -- 00038 //--------------- 00039 #include <iostream.h> 00040 00041 //------------------------------- 00042 // Collaborating Class Headers -- 00043 //------------------------------- 00044 #ifndef CDF 00045 //#include "colias/colias.hh" 00046 #else 00047 #include "Trybos/TRY_Disk_File.hh" 00048 #endif 00049 //? #include "Framework/APPPath.hh" 00050 00051 // ---------------------------------------- 00052 // -- Public Function Member Definitions -- 00053 // ---------------------------------------- 00054 00055 //---------------- 00056 // Constructors -- 00057 //---------------- 00058 00059 AppFileStream::AppFileStream( 00060 const char* const theName, 00061 const char* const theFile, 00062 const char* const theDescription ) 00063 : AppStream( theName, theFile, theDescription) 00064 #ifdef CDF 00065 , _file( NULL ) 00066 #endif 00067 { 00068 } 00069 00070 //-------------- 00071 // Destructor -- 00072 //-------------- 00073 00074 AppFileStream::~AppFileStream( ) 00075 { 00076 00077 #ifdef CDF 00078 close( ); 00079 #endif 00080 } 00081 00082 //------------- 00083 // Selectors -- 00084 //------------- 00085 00086 const char* 00087 AppFileStream::filename( ) const 00088 { 00089 return destination( ); 00090 } 00091 00092 bool 00093 AppFileStream::isOpen( ) const 00094 { 00095 bool result = false; 00096 if ( NULL != _destination ) { 00097 #ifdef CDF 00098 if ( _file != NULL ) result = _file->is_open(); 00099 #else 00100 if ( ((fstream*)&_file)->rdbuf()->is_open( ) ) { 00101 result = true; 00102 } 00103 #endif 00104 } 00105 return result; 00106 } 00107 00108 //------------- 00109 // Modifiers -- 00110 //------------- 00111 00112 void 00113 AppFileStream::setFilename( const char* const theName ) 00114 { 00115 setDestination( theName ); 00116 } 00117 00118 bool 00119 AppFileStream::open( ) 00120 { 00121 bool result = false; 00122 if ( NULL != _destination) { 00123 #ifndef CDF 00124 _file.open( _destination, ios::out ); 00125 #else 00126 _file = new TRY_Disk_File; 00127 // the file type should be selected with an if when 00128 // there is actually more then one file type 00129 _file->open( _destination, false ); // false=file is not readonly 00130 #endif 00131 if ( isOpen( ) ) { 00132 result = true; 00133 } else { 00134 cout << name() << "::open Failed to open Output file" << endl; 00135 } 00136 } 00137 return result; 00138 } 00139 00140 void 00141 AppFileStream::close( ) 00142 { 00143 if ( isOpen( ) ) { 00144 #ifndef CDF 00145 _file.close( ); 00146 #else 00147 _file->close( ); 00148 delete _file; 00149 _file = NULL; 00150 #endif 00151 } 00152 } 00153 00154 // ------------------------------------------- 00155 // -- Protected Function Member Definitions -- 00156 // ------------------------------------------- 00157 00158 bool 00159 AppFileStream::writeToDestination( AbsEvent* anEvent ) 00160 { 00161 bool result = true; 00162 #ifdef CDF 00163 if (! _file->write( *anEvent ) ) { 00164 cout << name() << "::write failed, event not written"; 00165 } 00166 #endif 00167 return result; 00168 }
BaBar Public Site | SLAC | News | Links | Who's Who | Contact Us
Page Owner: Jacek Becla
Last Update: October 04, 2002