CMS 3D CMS Logo

/afs/cern.ch/work/a/aaltunda/public/www/CMSSW_6_2_7/src/Utilities/StorageFactory/src/Storage.cc

Go to the documentation of this file.
00001 #include "Utilities/StorageFactory/interface/Storage.h"
00002 #include "FWCore/Utilities/interface/Exception.h"
00003 #include <cassert>
00004 
00005 Storage::Storage (void)
00006 {}
00007 
00008 Storage::~Storage (void)
00009 {}
00010 
00012 IOSize
00013 Storage::read (IOBuffer into, IOOffset pos)
00014 { return read (into.data (), into.size (), pos); }
00015 
00016 IOSize
00017 Storage::read (void *into, IOSize n, IOOffset pos)
00018 {
00019   // FIXME: this is not thread safe!  split into separate interface
00020   // that a particular storage can choose to support or not?  make
00021   // sure that throw semantics are correct here!
00022   // FIXME: use saveposition object in case exceptions are thrown?
00023   IOOffset here = position ();
00024   position (pos);
00025   n = read (into, n);
00026   position (here);
00027   return n;
00028 }
00029 
00030 IOSize
00031 Storage::readv (IOPosBuffer *into, IOSize n)
00032 {
00033   IOOffset here = position();
00034   IOSize total = 0;
00035   for (IOSize i = 0; i < n; ++i)
00036   {
00037     try
00038     {
00039       position(into[i].offset());
00040       total += read(into[i].data(), into[i].size());
00041     }
00042     catch (cms::Exception &)
00043     {
00044       if (! total)
00045         throw;
00046       break;
00047     }
00048   }
00049   position(here);
00050   return total;
00051 }
00052 
00054 IOSize
00055 Storage::write (IOBuffer from, IOOffset pos)
00056 { return write (from.data (), from.size (), pos); }
00057 
00058 IOSize
00059 Storage::write (const void *from, IOSize n, IOOffset pos)
00060 {
00061   // FIXME: this is not thread safe!  split into separate interface
00062   // that a particular storage can choose to support or not?  make
00063   // sure that throw semantics are correct here!
00064 
00065   // FIXME: use saveposition object in case exceptions are thrown?
00066   IOOffset here = position ();
00067   position (pos);
00068   n = write (from, n);
00069   position (here);
00070   return n;
00071 }
00072 
00073 IOSize
00074 Storage::writev (const IOPosBuffer *from, IOSize n)
00075 {
00076   IOSize total = 0;
00077   for (IOSize i = 0; i < n; ++i)
00078   {
00079     try
00080     {
00081       total += write(from[i].data(), from[i].size(), from[i].offset());
00082     }
00083     catch (cms::Exception &)
00084     {
00085       if (! total)
00086         throw;
00087       break;
00088     }
00089   }
00090   return total;
00091 }
00092 
00094 IOOffset
00095 Storage::position (void) const
00096 {
00097   Storage *self = const_cast<Storage *> (this);
00098   return self->position (0, CURRENT);
00099 }
00100 
00101 IOOffset
00102 Storage::size (void) const
00103 {
00104   // FIXME: use saveposition object in case exceptions are thrown?
00105   Storage *self = const_cast<Storage *> (this);
00106   IOOffset here = position ();
00107   self->position (0, END);
00108   IOOffset size = position ();
00109   self->position (here); // FIXME: VERIFY()?
00110   return size;
00111 }
00112 
00113 void
00114 Storage::rewind (void)
00115 { position(0); }
00116 
00118 bool
00119 Storage::prefetch (const IOPosBuffer * /* what */, IOSize /* n */)
00120 { return false; }
00121 
00123 void
00124 Storage::flush (void)
00125 {}
00126 
00127 void
00128 Storage::close (void)
00129 {}
00130 
00132 bool
00133 Storage::eof (void) const
00134 { return position () == size (); }