00001 00028 #include <vector> 00029 00030 # include "Utilities/StorageFactory/interface/IOPosBuffer.h" 00031 00032 class ReadRepacker { 00033 00034 public: 00035 00036 // Returns the number of input buffers it was able to pack into the IO operation. 00037 int 00038 pack(long long int *pos, // An array of file offsets to read. 00039 int *len, // An array of lengths to read. 00040 int nbuf, // Size of the pos and len array. 00041 char *buf, // Temporary buffer to hold I/O result. 00042 IOSize buffer_size); // Size of the temporary buffer. 00043 00044 void 00045 unpack(char *buf); // Buffer to unpack the I/O results into. Not the temporayr buffer and result buffer may overlap. 00046 00047 std::vector<IOPosBuffer> & iov() { return m_iov; } // Returns the IO vector, optimized for storage. 00048 00049 IOSize bufferUsed() const {return m_buffer_used;} // Returns the total amount of space in the temp buffer used. 00050 IOSize extraBytes() const {return m_extra_bytes;} // Returns the number of extra bytes to be issued to the I/O system 00051 // Note that (buffer_used - extra_bytes) should equal the number of "real" bytes serviced. 00052 IOSize realBytesProcessed() const {return m_buffer_used-m_extra_bytes;} // Return the number of bytes of the input request that would be processed by the IO vector 00053 00054 // Two reads distanced by less than READ_COALESCE_SIZE will turn into one 00055 // large read. 00056 static const IOSize TEMPORARY_BUFFER_SIZE = 256 * 1024; 00057 00058 // A read larger than BIG_READ_SIZE will not be coalesced. 00059 static const IOSize READ_COALESCE_SIZE = 32 * 1024; 00060 00061 // The size of the temporary holding buffer for read-coalescing. 00062 static const IOSize BIG_READ_SIZE = 256 * 1024; 00063 00064 private: 00065 00066 int packInternal(long long int *pos, int *len, int nbuf, char *buf, IOSize buffer_size); // Heart of the implementation of Pack; because we pack up to 2 buffers, 00067 // its easier to break the method into two. 00068 00069 void reset(unsigned int nbuf); // Reset all the internal counters and arrays. Resize arrays to be about nbuf long. 00070 00071 std::vector<int> m_idx_to_iopb; // Mapping from idx in the input array to the iopb in the IO vector 00072 std::vector<int> m_idx_to_iopb_offset; // Mapping from idx in the input array to the data offset in the results of the iopb. 00073 std::vector<IOPosBuffer> m_iov; // Vector of IO for the storage system to perform. 00074 int *m_len; // Pointed to the array of read sizes. 00075 IOSize m_buffer_used; // Bytes in the temporary buffer used. 00076 IOSize m_extra_bytes; // Number of bytes read from storage that will be discarded. 00077 std::vector<char> m_spare_buffer; // The spare buffer; allocated if we cannot fit the I/O results into the ROOT buffer. 00078 00079 }; 00080