#include <Utilities/DCacheAdaptor/interface/DCacheFile.h>
Public Member Functions | |
virtual void | abort (void) |
virtual void | close (void) |
virtual void | create (const std::string &name, bool exclusive=false, int perms=0666) |
virtual void | create (const char *name, bool exclusive=false, int perms=0666) |
DCacheFile (const std::string &name, int flags=IOFlags::OpenRead, int perms=0666) | |
DCacheFile (const char *name, int flags=IOFlags::OpenRead, int perms=0666) | |
DCacheFile (IOFD fd) | |
DCacheFile (void) | |
virtual void | open (const std::string &name, int flags=IOFlags::OpenRead, int perms=0666) |
virtual void | open (const char *name, int flags=IOFlags::OpenRead, int perms=0666) |
virtual IOOffset | position (IOOffset offset, Relative whence=SET) |
virtual IOSize | read (void *into, IOSize n) |
Read into into at most n number of bytes. | |
virtual void | resize (IOOffset size) |
virtual IOSize | write (const void *from, IOSize n) |
Write n bytes of data starting at address from. | |
~DCacheFile (void) | |
Private Attributes | |
bool | m_close |
IOFD | m_fd |
std::string | m_name |
Definition at line 8 of file DCacheFile.h.
DCacheFile::DCacheFile | ( | void | ) |
Definition at line 8 of file DCacheFile.cc.
00009 : m_fd (EDM_IOFD_INVALID), 00010 m_close (false) 00011 {}
DCacheFile::DCacheFile | ( | IOFD | fd | ) |
DCacheFile::DCacheFile | ( | const std::string & | name, | |
int | flags = IOFlags::OpenRead , |
|||
int | perms = 0666 | |||
) |
Definition at line 25 of file DCacheFile.cc.
References open().
00028 : m_fd (EDM_IOFD_INVALID), 00029 m_close (false) 00030 { open (name.c_str (), flags, perms); }
DCacheFile::~DCacheFile | ( | void | ) |
Definition at line 32 of file DCacheFile.cc.
References m_close, and m_name.
00033 { 00034 if (m_close) 00035 edm::LogError("DCacheFileError") 00036 << "Destructor called on dCache file '" << m_name 00037 << "' but the file is still open"; 00038 }
Definition at line 169 of file DCacheFile.cc.
References EDM_IOFD_INVALID, m_close, and m_fd.
00170 { 00171 if (m_fd != EDM_IOFD_INVALID) 00172 dc_close (m_fd); 00173 00174 m_close = false; 00175 m_fd = EDM_IOFD_INVALID; 00176 }
Reimplemented from Storage.
Definition at line 143 of file DCacheFile.cc.
References EDM_IOFD_INVALID, m_close, m_fd, and m_name.
Referenced by open().
00144 { 00145 if (m_fd == EDM_IOFD_INVALID) 00146 { 00147 edm::LogError("DCacheFileError") 00148 << "DCacheFile::close(name='" << m_name 00149 << "') called but the file is not open"; 00150 m_close = false; 00151 return; 00152 } 00153 00154 dc_errno = 0; 00155 if (dc_close (m_fd) == -1) 00156 edm::LogWarning("DCacheFileWarning") 00157 << "dc_close(name='" << m_name 00158 << "') failed with error '" << dc_strerror (dc_errno) 00159 << "' (dc_errno=" << dc_errno << ")"; 00160 00161 m_close = false; 00162 m_fd = EDM_IOFD_INVALID; 00163 00164 // Caused hang. Will be added back after problem is fixed. 00165 // edm::LogInfo("DCacheFileInfo") << "Closed " << m_name; 00166 }
void DCacheFile::create | ( | const std::string & | name, | |
bool | exclusive = false , |
|||
int | perms = 0666 | |||
) | [virtual] |
Definition at line 53 of file DCacheFile.cc.
References open(), IOFlags::OpenCreate, IOFlags::OpenExclusive, IOFlags::OpenTruncate, and IOFlags::OpenWrite.
00056 { 00057 open (name.c_str (), 00058 (IOFlags::OpenCreate | IOFlags::OpenWrite | IOFlags::OpenTruncate 00059 | (exclusive ? IOFlags::OpenExclusive : 0)), 00060 perms); 00061 }
Definition at line 42 of file DCacheFile.cc.
References open(), IOFlags::OpenCreate, IOFlags::OpenExclusive, IOFlags::OpenTruncate, and IOFlags::OpenWrite.
00045 { 00046 open (name, 00047 (IOFlags::OpenCreate | IOFlags::OpenWrite | IOFlags::OpenTruncate 00048 | (exclusive ? IOFlags::OpenExclusive : 0)), 00049 perms); 00050 }
void DCacheFile::open | ( | const char * | name, | |
int | flags = IOFlags::OpenRead , |
|||
int | perms = 0666 | |||
) | [virtual] |
Definition at line 70 of file DCacheFile.cc.
References close(), EDM_IOFD_INVALID, Exception, m_close, m_fd, m_name, O_NONBLOCK, IOFlags::OpenAppend, IOFlags::OpenCreate, IOFlags::OpenExclusive, IOFlags::OpenNonBlock, IOFlags::OpenRead, IOFlags::OpenTruncate, IOFlags::OpenUnbuffered, and IOFlags::OpenWrite.
Referenced by create(), DCacheFile(), and open().
00073 { 00074 m_name = name; 00075 00076 // Actual open 00077 if ((name == 0) || (*name == 0)) 00078 throw cms::Exception("DCacheFile::open()") 00079 << "Cannot open a file without a name"; 00080 00081 if ((flags & (IOFlags::OpenRead | IOFlags::OpenWrite)) == 0) 00082 throw cms::Exception("DCacheFile::open()") 00083 << "Must open file '" << name << "' at least for read or write"; 00084 00085 // If I am already open, close old file first 00086 if (m_fd != EDM_IOFD_INVALID && m_close) 00087 close (); 00088 00089 // Translate our flags to system flags 00090 int openflags = 0; 00091 00092 if ((flags & IOFlags::OpenRead) && (flags & IOFlags::OpenWrite)) 00093 openflags |= O_RDWR; 00094 else if (flags & IOFlags::OpenRead) 00095 openflags |= O_RDONLY; 00096 else if (flags & IOFlags::OpenWrite) 00097 openflags |= O_WRONLY; 00098 00099 if (flags & IOFlags::OpenNonBlock) 00100 openflags |= O_NONBLOCK; 00101 00102 if (flags & IOFlags::OpenAppend) 00103 openflags |= O_APPEND; 00104 00105 if (flags & IOFlags::OpenCreate) 00106 openflags |= O_CREAT; 00107 00108 if (flags & IOFlags::OpenExclusive) 00109 openflags |= O_EXCL; 00110 00111 if (flags & IOFlags::OpenTruncate) 00112 openflags |= O_TRUNC; 00113 00114 IOFD newfd = EDM_IOFD_INVALID; 00115 dc_errno = 0; 00116 if ((newfd = dc_open (name, openflags, perms)) == -1) 00117 throw cms::Exception("DCacheFile::open()") 00118 << "dc_open(name='" << name 00119 << "', flags=0x" << std::hex << openflags 00120 << ", permissions=0" << std::oct << perms << std::dec 00121 << ") => error '" << dc_strerror(dc_errno) 00122 << "' (dc_errno=" << dc_errno << ")"; 00123 00124 m_fd = newfd; 00125 00126 // Turn off read-ahead, or adjust read-ahead size depending on 00127 // whether buffering has been requested. This is a very tricky 00128 // balance here. Without read-ahead data processing appears to 00129 // become exceedingly slow, and with default (1MB) read-ahead 00130 // it appears to saturate disk servers and network. Try tread 00131 // reasonable middle ground here. 00132 if (flags & IOFlags::OpenUnbuffered) 00133 dc_noBuffering(m_fd); 00134 else 00135 dc_setBufferSize(m_fd, 64000); 00136 00137 m_close = true; 00138 00139 edm::LogInfo("DCacheFileInfo") << "Opened " << m_name; 00140 }
Implements Storage.
Definition at line 251 of file DCacheFile.cc.
References Storage::CURRENT, EDM_IOFD_INVALID, Storage::END, Exception, m_fd, m_name, HLT_VtxMuL3::result, and Storage::SET.
00252 { 00253 if (m_fd == EDM_IOFD_INVALID) 00254 throw cms::Exception("DCacheFile::position()") 00255 << "DCacheFile::position() called on a closed file"; 00256 if (whence != CURRENT && whence != SET && whence != END) 00257 throw cms::Exception("DCacheFile::position()") 00258 << "DCacheFile::position() called with incorrect 'whence' parameter"; 00259 00260 IOOffset result; 00261 int mywhence = (whence == SET ? SEEK_SET 00262 : whence == CURRENT ? SEEK_CUR 00263 : SEEK_END); 00264 00265 dc_errno = 0; 00266 if ((result = dc_lseek64 (m_fd, offset, mywhence)) == -1) 00267 throw cms::Exception("DCacheFile::position()") 00268 << "dc_lseek64(name='" << m_name << "', offset=" << offset 00269 << ", whence=" << mywhence << ") failed with error '" 00270 << dc_strerror (dc_errno) << "' (dc_errno=" << dc_errno << ")"; 00271 00272 // FIXME: dCache returns incorrect value on SEEK_END. 00273 // Remove this hack when dcap has been fixed. 00274 if (whence == SEEK_END && (result = dc_lseek64 (m_fd, result, SEEK_SET)) == -1) 00275 throw cms::Exception("DCacheFile::position()") 00276 << "dc_lseek64(name='" << m_name << "', offset=" << offset 00277 << ", whence=" << SEEK_SET << ") failed with error '" 00278 << dc_strerror (dc_errno) << "' (dc_errno=" << dc_errno << ")"; 00279 00280 return result; 00281 }
Read into into at most n number of bytes.
If this is a blocking stream, the call will block until some data can be read, end of input is reached, or an exception is thrown. For a non-blocking stream the available input is returned. If none is available, an exception is thrown.
In | case of error, a IOError exception is thrown. This includes the situation where the input stream is in non-blocking mode and no input is currently available (FIXME: make this simpler; clarify which exception). |
Implements IOInput.
Definition at line 195 of file DCacheFile.cc.
References BUGLINE, Exception, m_fd, m_name, and s.
00196 { 00197 IOSize done = 0; 00198 while (done < n) 00199 { 00200 dc_errno = 0; 00201 ssize_t s = dc_read (m_fd, (char *) into + done, n - done); 00202 if (s == -1) 00203 throw cms::Exception("DCacheFile::read()") 00204 << "dc_read(name='" << m_name << "', n=" << (n-done) 00205 << ") failed with error '" << dc_strerror(dc_errno) 00206 << "' (dc_errno=" << dc_errno << ")"; 00207 else if (s == 0) 00208 // end of file 00209 break; 00210 else if (s < ssize_t (n-done)) 00211 edm::LogInfo("DCacheFileWarning") 00212 << "dc_read(name='" << m_name << "', n=" << (n-done) 00213 << ") returned a short read of " << s << " bytes; " 00214 << "please report a bug in dCache referencing the " 00215 << "comment on line " << BUGLINE << " of " << __FILE__; 00216 done += s; 00217 } 00218 00219 return done; 00220 }
Implements Storage.
Definition at line 284 of file DCacheFile.cc.
References Exception, and m_name.
00285 { 00286 throw cms::Exception("DCacheFile::resize()") 00287 << "DCacheFile::resize(name='" << m_name << "') not implemented"; 00288 }
Write n bytes of data starting at address from.
In | case of error, an exception is thrown. However if the stream is in non-blocking mode and cannot accept output, it will not throw an exception -- the return value will be less than requested. |
Implements IOOutput.
Definition at line 223 of file DCacheFile.cc.
References BUGLINE, Exception, m_fd, m_name, and s.
00224 { 00225 IOSize done = 0; 00226 while (done < n) 00227 { 00228 dc_errno = 0; 00229 ssize_t s = dc_write (m_fd, (const char *) from + done, n - done); 00230 if (s == -1) 00231 throw cms::Exception("DCacheFile::write()") 00232 << "dc_write(name='" << m_name << "', n=" << (n-done) 00233 << ") failed with error '" << dc_strerror(dc_errno) 00234 << "' (dc_errno=" << dc_errno << ")"; 00235 else if (s < ssize_t (n-done)) 00236 edm::LogInfo("DCacheFileWarning") 00237 << "dc_write(name='" << m_name << "', n=" << (n-done) 00238 << ") returned a short write of " << s << " bytes; " 00239 << "please report a bug in dCache referencing the " 00240 << "comment on line " << BUGLINE << " of " << __FILE__; 00241 done += s; 00242 } 00243 00244 return done; 00245 }
bool DCacheFile::m_close [private] |
Definition at line 45 of file DCacheFile.h.
Referenced by abort(), close(), open(), and ~DCacheFile().
IOFD DCacheFile::m_fd [private] |
Definition at line 44 of file DCacheFile.h.
Referenced by abort(), close(), open(), position(), read(), and write().
std::string DCacheFile::m_name [private] |
Definition at line 46 of file DCacheFile.h.
Referenced by close(), open(), position(), read(), resize(), write(), and ~DCacheFile().