diff --git a/src/libsrc++/BankHeader.cpp b/src/libsrc++/BankHeader.cpp index 758784cf..b5fcc8bd 100644 --- a/src/libsrc++/BankHeader.cpp +++ b/src/libsrc++/BankHeader.cpp @@ -24,30 +24,10 @@ namespace evio { BaseStructureHeader(tag, dataType, num) {length = 1;} - /** - * Get the length of the structure's data in 32 bit ints (not counting the header words). - * @return Get the length of the structure's data in 32 bit ints (not counting the header words). - */ uint32_t BankHeader::getDataLength() {return length - 1;} - - /** - * Get the length of the structure's header in ints. This includes the first header word itself - * (which contains the length) and in the case of banks, it also includes the second header word. - * @return Get the length of the structure's header in ints. - */ uint32_t BankHeader::getHeaderLength() {return 2;} - - /** - * Write myself out as evio format data - * into the given byte array in the specified byte order. - * - * @param dest array into which evio data is written (destination). - * @param order byte order in which to write the data. - * @return the number of bytes written, which for a BankHeader is 8. - * @throws EvioException if destination array too small to hold data. - */ size_t BankHeader::write(uint8_t *dest, ByteOrder const & order) { // length first Util::toBytes(length, order, dest); @@ -57,26 +37,10 @@ namespace evio { return 8; } - - /** - * Write myself out a byte buffer. - * This write is relative - i.e., it uses the current position of the buffer. - * - * @param byteBuffer the byteBuffer to write to. - * @return the number of bytes written, which for a BankHeader is 8. - */ size_t BankHeader::write(std::shared_ptr byteBuffer) { return write(*(byteBuffer.get())); } - - /** - * Write myself out a byte buffer. - * This write is relative - i.e., it uses the current position of the buffer. - * - * @param dest the byteBuffer to write to. - * @return the number of bytes written, which for a BankHeader is 8. - */ size_t BankHeader::write(ByteBuffer & dest) { dest.putInt(length); diff --git a/src/libsrc++/BaseStructure.h b/src/libsrc++/BaseStructure.h index 83b0737f..0b0059ae 100644 --- a/src/libsrc++/BaseStructure.h +++ b/src/libsrc++/BaseStructure.h @@ -46,30 +46,29 @@ namespace evio { - /////////////////////////////////// DEPTH FIRST ITERATOR - + /** Depth first iterator. */ template class nodeIterator { - // iterator of vector contained shared pointers to node's children + /** Iterator of vector contained shared pointers to node's children. */ typedef typename std::vector::iterator KidIter; protected: - // Stack of pair containing 2 iterators, each iterating over vector - // of node's children (shared pts). - // In each pair, first is current iterator, second is end iterator. + /** Stack of pair containing 2 iterators, each iterating over vector + * of node's children (shared pts). + * In each pair, first is current iterator, second is end iterator. */ std::stack> stack; - // Where we are now in the tree + /** Where we are now in the tree. */ R currentNode; - // Is this the end iterator? + /** Is this the end iterator? */ bool isEnd; public: - // Copy shared pointer arg + /** Constructor that copies shared pointer arg. */ explicit nodeIterator(R &node, bool isEnd) : currentNode(node), isEnd(isEnd) { // store current-element and end of vector in pair if (!node->children.empty()) { @@ -78,8 +77,10 @@ namespace evio { } } + /** Dereference operator. */ R operator*() const { return currentNode; } + /** Equal operator. */ bool operator==(const nodeIterator &other) const { // Identify end iterator if (isEnd && other.isEnd) { @@ -88,6 +89,7 @@ namespace evio { return this == &other; } + /** Not equal operator. */ bool operator!=(const nodeIterator &other) const { // Identify end iterator if (isEnd && other.isEnd) { @@ -96,9 +98,13 @@ namespace evio { return this != &other; } + /** + * Is this the end of the iterator? + * @return true if end of iterator. + */ bool isEndIter() {return isEnd;} - // post increment gets ignored arg of 0 to distinguish from pre, A++ + /** Post increment operator gets ignored arg of 0 to distinguish from pre, A++. */ const nodeIterator operator++(int) { if (isEnd) return *this; @@ -142,7 +148,7 @@ namespace evio { } - // pre increment, ++A + /** Pre increment operator, ++A. */ const nodeIterator &operator++() { if (isEnd) return *this; @@ -183,33 +189,32 @@ namespace evio { }; - /////////////////////////////////// BREADTH FIRST ITERATOR - + /** Breadth first iterator. */ template class nodeBreadthIterator { protected: - // iterator of vector contained shared pointers to node's children + /** iterator of vector contained shared pointers to node's children. */ typedef typename std::vector::iterator KidIter; - // Stack of iterators of vector of shared pointers. + // Queue of iterators of vector of shared pointers. // Each vector contains the children of a node, // thus each iterator gives all a node's kids. - // Stack of iterators over node's children. - // In each pair, first is current iterator, second is end + /** Queue of iterators over node's children. + * In each pair, first is current iterator, second is end. */ std::queue> que; - // Where we are now in the tree + /** Where we are now in the tree. */ R currentNode; - // Is this the end iterator? + /** Is this the end iterator? */ bool isEnd; public: - // Copy shared pointer arg + /** Constructor that copies shared pointer arg. */ nodeBreadthIterator(R & node, bool isEnd) : currentNode(node), isEnd(isEnd) { // store current-element and end of vector in pair if (!node->children.empty()) { @@ -218,8 +223,10 @@ namespace evio { } } + /** Dereference operator. */ R operator*() const { return currentNode; } + /** Equal operator. */ bool operator==(const nodeBreadthIterator &other) const { if (isEnd && other.isEnd) { return true; @@ -227,6 +234,7 @@ namespace evio { return this == &other; } + /** Not equal operator. */ bool operator!=(const nodeBreadthIterator &other) const { if (isEnd && other.isEnd) { return false; @@ -234,11 +242,15 @@ namespace evio { return this != &other; } + /** + * Is this the end of the iterator? + * @return true if end of iterator. + */ bool isEndIter() {return isEnd;} // TODO: How does one handle going too far??? - // post increment gets ignored arg of 0 to distinguish from pre, A++ + /** Post increment operator gets ignored arg of 0 to distinguish from pre, A++. */ nodeBreadthIterator operator++(int) { if (isEnd) { @@ -284,7 +296,7 @@ namespace evio { } - // pre increment, ++A + /** Pre increment operator, ++A. */ nodeBreadthIterator operator++() { if (isEnd) { @@ -358,16 +370,23 @@ namespace evio { public: - // For defining our own iterator + /** For our own iterator, define size type. */ typedef size_t size_type; + /** For our own iterator, define pointer difference type. */ typedef std::ptrdiff_t difference_type; + /** For our own iterator, define iterator category type. */ typedef std::input_iterator_tag iterator_category; + /** For our own iterator, define value type. */ typedef std::shared_ptr value_type; + /** For our own iterator, define reference type. */ typedef std::shared_ptr reference; + /** For our own iterator, define pointer type. */ typedef std::shared_ptr pointer; + /** Depth first iterator for this element in a tree. */ typedef nodeIterator> iterator; + /** Breadth first iterator for this element in a tree. */ typedef nodeBreadthIterator> breadth_iterator; friend class nodeIterator>; @@ -413,8 +432,20 @@ namespace evio { bool allowsChildren = true; public: - + /** + * This methods calls shared_from_this() to obtain a new std::shared_ptr that + * shares ownership of the current object (this). + * @return a new std::shared_ptr that shares ownership of the current object. + */ std::shared_ptr getThis() {return shared_from_this();} + + /** + * This methods calls shared_from_this() to obtain a new std::shared_ptr that + * shares ownership of the current object (this). However that shared pointer + * cannot be used to change the object. + * @return a new std::shared_ptr that shares ownership of the current object + * which is treated as read-only. + */ std::shared_ptr getThisConst() const {return shared_from_this();} protected: @@ -641,6 +672,10 @@ namespace evio { void transform(std::shared_ptr structure); + /** + * Get the type of structure this object represents (bank, seg, tagseg, or unknown). + * @return type of structure this object represents. + */ virtual StructureType getStructureType() const {return StructureType::STRUCT_UNKNOWN32;}; ByteOrder getByteOrder(); diff --git a/src/libsrc++/BaseStructureHeader.h b/src/libsrc++/BaseStructureHeader.h index 2b20fba0..0423ff5e 100644 --- a/src/libsrc++/BaseStructureHeader.h +++ b/src/libsrc++/BaseStructureHeader.h @@ -101,12 +101,56 @@ namespace evio { uint16_t getTag() const; void setTag(uint16_t tag); + /** + * Get the length of the structure's data in 32 bit ints (not counting the header words). + * @return Get the length of the structure's data in 32 bit ints (not counting the header words). + */ virtual uint32_t getDataLength() {return 0;}; + + /** + * Get the length of the structure's header in ints. This includes the first header word itself + * (which contains the length) and in the case of banks, it also includes the second header word. + * @return length of the structure's header in ints (2 for banks, 1 for segments and tagsegments). + */ virtual uint32_t getHeaderLength() {return 0;}; + + /** + * Obtain a string representation of the base structure header. + * @return a string representation of the base structure header. + */ virtual std::string toString() {return "BaseStructureHeader";}; + + /** + * Write myself out into a byte buffer. + * This write is relative - i.e., it uses the current position of the buffer. + * + * @param dest the byteBuffer to write to. + * @return the number of bytes written, which for a BankHeader is 8 and for + * a SegmentHeader or TagSegmentHeader is 4. + */ virtual size_t write(std::shared_ptr dest) {return 0;} + + /** + * Write myself out into a byte buffer. + * This write is relative - i.e., it uses the current position of the buffer. + * + * @param dest the byteBuffer to write to. + * @return the number of bytes written, which for a BankHeader is 8 and for + * a SegmentHeader or TagSegmentHeader is 4. + */ virtual size_t write(ByteBuffer & dest) {return 0;}; + + /** + * Write myself out as evio format data + * into the given byte array in the specified byte order. + * + * @param dest array into which evio data is written (destination). + * @param order byte order in which to write the data. + * @return the number of bytes written, which for a BankHeader is 8 and for + * a SegmentHeader or TagSegmentHeader is 4. + * @throws EvioException if destination array too small to hold data. + */ virtual size_t write(uint8_t *dest, ByteOrder const & order) {return 0;}; }; diff --git a/src/libsrc++/BlockHeaderV4.h b/src/libsrc++/BlockHeaderV4.h index 320c9377..2e69bda1 100644 --- a/src/libsrc++/BlockHeaderV4.h +++ b/src/libsrc++/BlockHeaderV4.h @@ -59,7 +59,6 @@ namespace evio { * | Magic Int | * |_____________________________________| * - * The following bit #s start with 0. * * Block Length = number of ints in block (including this one). * Block Number = id number (starting at 1) @@ -79,7 +78,7 @@ namespace evio { * * * - * Bit info has the following bits defined (bit #s start with 0): + * Bit info has the following bits defined (bit numbers start with 0): * Bit 8 = true if dictionary is included (relevant for first block only) * * Bit 9 = true if this block is the last block in file or network transmission diff --git a/src/libsrc++/ByteBuffer.cpp b/src/libsrc++/ByteBuffer.cpp index 36ce2bef..60eebfa1 100644 --- a/src/libsrc++/ByteBuffer.cpp +++ b/src/libsrc++/ByteBuffer.cpp @@ -13,8 +13,7 @@ namespace evio { - // Define a deleter that does not delete memory for a shared pointer that's - // used with shared memory. + /** Define a deleter that does not delete memory for a shared pointer that's used with shared memory. */ void null_deleter(uint8_t *) {}; @@ -640,7 +639,7 @@ namespace evio { *

The content of the returned buffer will be that of this buffer. Changes * to this buffer's content will be visible in the returned buffer, and vice * versa; the two buffers' position, limit, and mark values will be - * independent. + * independent.

* *

The returned buffer's capacity, limit, position, and mark values will * initially be identical to those of this buffer.

@@ -649,12 +648,12 @@ namespace evio { * To implement this method, one could return a unique pointer to a locally created * ByteBuffer object which would eliminate the need for an argument. However, handling * the new buffer would be different from handling those created by the constructor - * since the caller would have a unique pointer instead of a ByteBuffer reference. + * since the caller would have a unique pointer instead of a ByteBuffer reference.

* *

A cleaner way to do this is for the caller to create their own, new ByteBuffer * object and pass it in as an argument. This method then makes it identical to this * buffer and the data (implemented as a shared pointer) is shared between - * the objects. The buffer passed in as an argument is also the one returned. + * the objects. The buffer passed in as an argument is also the one returned.

* * @param destBuf byte buffer to be made a duplicate of this one. * @return the same byte buffer as passed in as the argument. @@ -683,21 +682,21 @@ namespace evio { *

The content of the returned buffer will be that of this buffer. Changes * to this buffer's content will be visible in the returned buffer, and vice * versa; the two buffers' position, limit, and mark values will be - * independent. + * independent.

* *

The returned buffer's capacity, limit, position, and mark values will - * initially be identical to those of this buffer.

+ * initially be identical to those of this buffer.

* *

The C++ version of this method departs from the Java which has no argument. * To implement this method, one could return a unique pointer to a locally created * ByteBuffer object which would eliminate the need for an argument. However, handling * the new buffer would be different from handling those created by the constructor - * since the caller would have a unique pointer instead of a ByteBuffer reference. + * since the caller would have a unique pointer instead of a ByteBuffer reference.

* *

A cleaner way to do this is for the caller to create their own, new ByteBuffer * object and pass it in as an argument. This method then makes it identical to this * buffer and the data (implemented as a shared pointer) is shared between - * the objects. The buffer passed in as an argument is also the one returned. + * the objects. The buffer passed in as an argument is also the one returned.

* * @param destBuf byte buffer to be made a duplicate of this one. * @return the same byte buffer as passed in as the argument. @@ -715,23 +714,22 @@ namespace evio { *

The content of the returned buffer will be that of this buffer. Changes * to this buffer's content will be visible in the returned buffer, and vice * versa; the two buffers' position, limit, and mark values will be - * independent. + * independent.

* *

The returned buffer's capacity, limit, position, and mark values will - * initially be identical to those of this buffer.

+ * initially be identical to those of this buffer.

* *

The C++ version of this method departs from the Java which has no argument. * To implement this method, one could return a unique pointer to a locally created * ByteBuffer object which would eliminate the need for an argument. However, handling * the new buffer would be different from handling those created by the constructor - * since the caller would have a unique pointer instead of a ByteBuffer reference. + * since the caller would have a unique pointer instead of a ByteBuffer reference.

* *

A cleaner way to do this is for the caller to create their own, new ByteBuffer * object and pass it in as an argument. This method then makes it identical to this * buffer and the data (implemented as a shared pointer) is shared between - * the objects. The buffer passed in as an argument is also the one returned. + * the objects. The buffer passed in as an argument is also the one returned.

* - * @param destBuf byte buffer to be made a duplicate of this one. * @return the same byte buffer as passed in as the argument. */ std::shared_ptr ByteBuffer::duplicate() { @@ -759,11 +757,11 @@ namespace evio { *

The content of the new buffer will start at this buffer's current * position. Changes to this buffer's content will be visible in the new * buffer, and vice versa; the two buffers' position, limit, and mark - * values will be independent. + * values will be independent.

* *

The new buffer's position will be zero, its capacity and its limit * will be the number of bytes remaining in this buffer, and its mark - * will be undefined. + * will be undefined.

* * @return The new byte buffer. */ @@ -796,11 +794,11 @@ namespace evio { *

The content of the given buffer will start at this buffer's current * position. Changes to this buffer's content will be visible in the given * buffer, and vice versa; the two buffers' position, limit, and mark - * values will be independent. + * values will be independent.

* *

The given buffer's position will be zero, its capacity and its limit * will be the number of bytes remaining in this buffer, and its mark - * will be undefined. + * will be undefined.

* * @param destBuf byte buffer to be made a slice of this one. * @return the same byte buffer as passed in as the argument. @@ -827,21 +825,21 @@ namespace evio { /** - * The given (and returned) byte buffer is one whose content is a shared subsequence of - * this buffer's content. - * - *

The content of the given buffer will start at this buffer's current - * position. Changes to this buffer's content will be visible in the given - * buffer, and vice versa; the two buffers' position, limit, and mark - * values will be independent. - * - *

The given buffer's position will be zero, its capacity and its limit - * will be the number of bytes remaining in this buffer, and its mark - * will be undefined. - * + * The given (and returned) byte buffer is one whose content is a shared subsequence of + * this buffer's content. + * + *

The content of the given buffer will start at this buffer's current + * position. Changes to this buffer's content will be visible in the given + * buffer, and vice versa; the two buffers' position, limit, and mark + * values will be independent.

+ * + *

The given buffer's position will be zero, its capacity and its limit + * will be the number of bytes remaining in this buffer, and its mark + * will be undefined.

+ * * @param destBuf byte buffer to be made a slice of this one. * @return the same byte buffer as passed in as the argument. - */ + */ std::shared_ptr ByteBuffer::slice(std::shared_ptr destBuf) { auto & buff = *(destBuf.get()); slice(buff); @@ -858,15 +856,15 @@ namespace evio { /** * Relative bulk get method. * - * This method transfers bytes from this buffer into the given + *

This method transfers bytes from this buffer into the given * destination array. If there are fewer bytes remaining in the * buffer than are required to satisfy the request, then no - * bytes are transferred and an underflow_error is thrown.

+ * bytes are transferred and an underflow_error is thrown.

* - * Otherwise, this method copies length bytes from this + *

Otherwise, this method copies length bytes from this * buffer into the given array, starting at the current position of this * buffer and at the given pointer. The position of this - * buffer is then incremented by length. + * buffer is then incremented by length.

* * @param dst array into which bytes are to be written. * @param length number of bytes to be written to the given @@ -888,15 +886,15 @@ namespace evio { /** * Relative bulk get method. * - * This method transfers bytes from this buffer into the given + *

This method transfers bytes from this buffer into the given * destination vector. If there are fewer bytes remaining in the * buffer than are required to satisfy the request, then no - * bytes are transferred and an underflow_error is thrown.

+ * bytes are transferred and an underflow_error is thrown.

* - * Otherwise, this method copies length bytes from this + *

Otherwise, this method copies length bytes from this * buffer into the given array, starting at the current position of this * buffer and at the given offset in the array. The position of this - * buffer is then incremented by length. + * buffer is then incremented by length.

* * @param dst vector into which bytes are to be written. * @param offset offset (bytes) within the vector of the first byte to be written. @@ -951,7 +949,7 @@ namespace evio { * which is by nature unsigned. * Keeping the name as "getChar" makes it compatible with Java, but be aware * it does NOT get a 8-bit "char" type. - * This method reads the next two bytes at this buffer's current position, + *

This method reads the next two bytes at this buffer's current position, * composing them into a wchar_t value according to the current byte order, * and then increments the position by two.

* @@ -966,7 +964,7 @@ namespace evio { * which is by nature unsigned. Reads at the given index. * Keeping the name as "getChar" makes it compatible with Java, but be aware * it does NOT get a 8-bit "char" type. - * This method reads the next two bytes at the given index, + *

This method reads the next two bytes at the given index, * composing them into a wchar_t value according to the current byte order, * and then increments the position by two.

* @@ -981,7 +979,7 @@ namespace evio { * Relative get method for reading a short value. * Reads the next two bytes at this buffer's current position, * composing them into a short value according to the current - * byte order, and then increments the position by two.

+ * byte order, and then increments the position by two. * * @return short value at buffer's current position. * @throws underflow_error if fewer than two bytes remaining in buffer. @@ -1001,7 +999,7 @@ namespace evio { /** * Absolute get method for reading a short value. * Reads two bytes at the given index, composing them into a - * short value according to the current byte order.

+ * short value according to the current byte order. * * @param index index from which the bytes will be read. * @return short value at the given index. @@ -1020,7 +1018,7 @@ namespace evio { /** - * Relative get method for reading an unsigned short value. + *

Relative get method for reading an unsigned short value. * Reads the next two bytes at this buffer's current position, * composing them into an unsigned short value according to the current * byte order, and then increments the position by two.

@@ -1041,7 +1039,7 @@ namespace evio { /** - * Absolute get method for reading an unsigned short value. + *

Absolute get method for reading an unsigned short value. * Reads two bytes at the given index, composing them into an * unsigned short value according to the current byte order.

* This method is not defined in the Java version. @@ -1066,7 +1064,7 @@ namespace evio { * Relative get method for reading an int value. * Reads the next four bytes at this buffer's current position, * composing them into an int value according to the current - * byte order, and then increments the position by four.

+ * byte order, and then increments the position by four. * * @return int value at buffer's current position. * @throws underflow_error if fewer than four bytes remaining in buffer. @@ -1085,7 +1083,7 @@ namespace evio { /** * Absolute get method for reading an int value. * Reads four bytes at the given index, composing them into an - * int value according to the current byte order.

+ * int value according to the current byte order. * * @param index index from which the bytes will be read. * @return int value at the given index. @@ -1107,7 +1105,7 @@ namespace evio { * Relative get method for reading an unsigned int value. * Reads the next four bytes at this buffer's current position, * composing them into an unsigned int value according to the current - * byte order, and then increments the position by four.

+ * byte order, and then increments the position by four. * * @return unsigned int value at buffer's current position. * @throws underflow_error if fewer than four bytes remaining in buffer. @@ -1126,7 +1124,7 @@ namespace evio { /** * Absolute get method for reading an unsigned int value. * Reads four bytes at the given index, composing them into an - * unsigned int value according to the current byte order.

+ * unsigned int value according to the current byte order. * * @param index index from which the bytes will be read. * @return unsigned int value at the given index. @@ -1148,7 +1146,7 @@ namespace evio { * Relative get method for reading a long long value. * Reads the next eight bytes at this buffer's current position, * composing them into a long long value according to the current - * byte order, and then increments the position by eight.

+ * byte order, and then increments the position by eight. * * @return long long value at buffer's current position. * @throws underflow_error if fewer than eight bytes remaining in buffer. @@ -1167,7 +1165,7 @@ namespace evio { /** * Absolute get method for reading a long long value. * Reads eight bytes at the given index, composing them into a - * long long value according to the current byte order.

+ * long long value according to the current byte order. * * @param index index from which the bytes will be read. * @return long long value at the given index. @@ -1189,7 +1187,7 @@ namespace evio { * Relative get method for reading an unsigned long long value. * Reads the next eight bytes at this buffer's current position, * composing them into an unsigned long long value according to the current - * byte order, and then increments the position by eight.

+ * byte order, and then increments the position by eight. * * @return unsigned long long value at buffer's current position. * @throws underflow_error if fewer than eight bytes remaining in buffer. @@ -1208,7 +1206,7 @@ namespace evio { /** * Absolute get method for reading an unsigned long long value. * Reads eight bytes at the given index, composing them into an - * unsigned long long value according to the current byte order.

+ * unsigned long long value according to the current byte order. * * @param index index from which the bytes will be read. * @return unsigned long long value at the given index. @@ -1230,7 +1228,7 @@ namespace evio { * Relative get method for reading a float value. * Reads the next four bytes at this buffer's current position, * composing them into a float value according to the current - * byte order, and then increments the position by four.

+ * byte order, and then increments the position by four. * * @return float value at buffer's current position. * @throws underflow_error if fewer than four bytes remaining in buffer. @@ -1246,7 +1244,7 @@ namespace evio { /** * Absolute get method for reading a float value. * Reads four bytes at the given index, composing them into a - * float value according to the current byte order.

+ * float value according to the current byte order. * * @param index index from which the bytes will be read. * @return float value at the given index. @@ -1265,7 +1263,7 @@ namespace evio { * Relative get method for reading a double value. * Reads the next eight bytes at this buffer's current position, * composing them into a double value according to the current - * byte order, and then increments the position by eight.

+ * byte order, and then increments the position by eight. * * @return double value at buffer's current position. * @throws underflow_error if fewer than eight bytes remaining in buffer. @@ -1281,7 +1279,7 @@ namespace evio { /** * Absolute get method for reading a double value. * Reads eight bytes at the given index, composing them into a - * double value according to the current byte order.

+ * double value according to the current byte order. * * @param index index from which the bytes will be read. * @return double value at the given index. @@ -1302,18 +1300,18 @@ namespace evio { /** - * Relative bulk put method.

+ * Relative bulk put method. * - * This method transfers the bytes remaining in the given source + *

This method transfers the bytes remaining in the given source * buffer into this buffer. If there are more bytes remaining in the * source buffer than in this buffer, that is, if * src.remaining() > remaining(), - * then no bytes are transferred and a {@link EvioException} is thrown.

+ * then no bytes are transferred and a {@link EvioException} is thrown.

* - * Otherwise, this method copies + *

Otherwise, this method copies * n = src.remaining() bytes from the given * buffer into this buffer, starting at each buffer's current position. - * The positions of both buffers are then incremented by n. + * The positions of both buffers are then incremented by n.

* * @param src source buffer from which bytes are to be read; * must not be this buffer. @@ -1341,18 +1339,18 @@ namespace evio { /** - * Relative bulk put method.

+ * Relative bulk put method. * - * This method transfers the bytes remaining in the given source + *

This method transfers the bytes remaining in the given source * buffer into this buffer. If there are more bytes remaining in the * source buffer than in this buffer, that is, if * src.remaining() > remaining(), - * then no bytes are transferred and a {@link EvioException} is thrown.

+ * then no bytes are transferred and a {@link EvioException} is thrown.

* - * Otherwise, this method copies + *

Otherwise, this method copies * n = src.remaining() bytes from the given * buffer into this buffer, starting at each buffer's current position. - * The positions of both buffers are then incremented by n. + * The positions of both buffers are then incremented by n.

* * @param src source buffer from which bytes are to be read; * must not be this buffer. @@ -1370,19 +1368,19 @@ namespace evio { /** - * Relative bulk put method.

+ * Relative bulk put method. * - * This method transfers bytes into this buffer from the given + *

This method transfers bytes into this buffer from the given * source array. If there are more bytes to be copied from the array * than remain in this buffer, that is, if * length > remaining(), then no * bytes are transferred and a {@link EvioException} is - * thrown.

+ * thrown.

* - * Otherwise, this method copies length bytes from the + *

Otherwise, this method copies length bytes from the * given array into this buffer, starting at the given pointer * and at the current position of this buffer. The position of this buffer - * is then incremented by length. + * is then incremented by length.

* * @param src array from which bytes are to be read * @param length number of bytes to be read from the given array; @@ -1402,19 +1400,19 @@ namespace evio { } /** - * Relative bulk put method.

+ * Relative bulk put method. * - * This method transfers bytes into this buffer from the given + *

This method transfers bytes into this buffer from the given * vector. If there are more bytes to be copied from the vector * than remain in this buffer, that is, if * length > remaining(), then no * bytes are transferred and a {@link EvioException} is - * thrown.

+ * thrown.

* - * Otherwise, this method copies length bytes from the + *

Otherwise, this method copies length bytes from the * given array into this buffer, starting at the given offset in the array * and at the current position of this buffer. The position of this buffer - * is then incremented by length. + * is then incremented by length.

* * @param src array from which bytes are to be read * @param offset offset (bytes) within the array of the first byte to be read; @@ -1439,7 +1437,7 @@ namespace evio { /** * Relative put method. * Writes the given byte into this buffer at the current - * position, and then increments the position by one.

+ * position, and then increments the position by one. * * @param val byte value to be written. * @return this buffer. diff --git a/src/libsrc++/ByteOrder.h b/src/libsrc++/ByteOrder.h index 12d2eb47..46ba48fc 100644 --- a/src/libsrc++/ByteOrder.h +++ b/src/libsrc++/ByteOrder.h @@ -109,12 +109,12 @@ namespace evio { return isBigEndian() ? ENDIAN_LITTLE : ENDIAN_BIG; } - + /** Defines equal operator. */ bool operator==(const ByteOrder &rhs) const; + /** Defines not-equal operator. */ bool operator!=(const ByteOrder &rhs) const; - /** * Get the byte order of the local host. * @return byte order of the local host. diff --git a/src/libsrc++/CompositeData.cpp b/src/libsrc++/CompositeData.cpp index 6819bf8c..d7fe5e3e 100644 --- a/src/libsrc++/CompositeData.cpp +++ b/src/libsrc++/CompositeData.cpp @@ -2182,319 +2182,319 @@ namespace evio { swapData(iarr, iarr, nwrd, ifmt, padding, false); } - - // Following is Sergui's original function (eviofmtswap) which is now implemented immediately above. - - ///** - // * This method converts (swaps) an array of EVIO composite type data - // * between IEEE (big endian) and DECS (little endian) in place. This - // * data does NOT include the composite type's beginning tagsegment and - // * the format string it contains. It also does NOT include the data's - // * bank header words. - // * - // * Converts the data of array (iarr[i], i=0...nwrd-1) - // * using the format code (ifmt[j], j=0...nfmt-1) . - // * - // *

- // * Algorithm description:

- // * Data processed inside while (ib < nwrd) - // * loop, where 'ib' is iarr[] index; - // * loop breaks when 'ib' reaches the number of elements in iarr[] - // * - // * - // * @param iarr pointer to data to be swapped - // * @param nwrd number of data words (32-bit ints) to be swapped - // * @param ifmt unsigned short vector holding translated format - // * @param padding number of bytes to ignore in last data word (starting from data end) - // * - // * @return 0 if success - // * @return -1 if nwrd < 0, or ifmt vector empty. - // */ - //int CompositeData::swapData(int32_t *iarr, int nwrd, const std::vector & ifmt, - // uint32_t padding) { // - // if (nwrd <= 0 || ifmt.empty()) return(-1); - // int nfmt = ifmt.size(); + // Following is Sergui's original function (eviofmtswap) which is now implemented immediately above. // - // int imt = 0; /* ifmt[] index */ - // int ncnf = 0; /* how many times must repeat a format */ - // int lev = 0; /* parenthesis level */ - // int kcnf, mcnf, iterm = 0; - // int64_t *b64, *b64end; - // int32_t *b32, *b32end; - // int16_t *b16, *b16end; - // auto b8 = reinterpret_cast(&iarr[0]); /* beginning of data */ - // auto b8end = reinterpret_cast(&iarr[nwrd]) - padding; /* end of data + 1 - padding */ - // LV lv[10]; + // // /** + // // * This method converts (swaps) an array of EVIO composite type data + // // * between IEEE (big endian) and DECS (little endian) in place. This + // // * data does NOT include the composite type's beginning tagsegment and + // // * the format string it contains. It also does NOT include the data's + // // * bank header words. + // // * + // // * Converts the data of array (iarr[i], i=0...nwrd-1) + // // * using the format code (ifmt[j], j=0...nfmt-1) . + // // * + // // *

+ // // * Algorithm description:

+ // // * Data processed inside while (ib < nwrd) + // // * loop, where 'ib' is iarr[] index; + // // * loop breaks when 'ib' reaches the number of elements in iarr[] + // // * + // // * + // // * @param iarr pointer to data to be swapped + // // * @param nwrd number of data words (32-bit ints) to be swapped + // // * @param ifmt unsigned short vector holding translated format + // // * @param padding number of bytes to ignore in last data word (starting from data end) + // // * + // // * @return 0 if success + // // * @return -1 if nwrd < 0, or ifmt vector empty. + // // */ + // int CompositeData::swapData(int32_t *iarr, int nwrd, const std::vector & ifmt, + // uint32_t padding) { // - //#ifdef COMPOSITE_DEBUG - // std::cout << std::endl << "=== eviofmtswap start ===" << std::endl; - //#endif + // if (nwrd <= 0 || ifmt.empty()) return(-1); + // int nfmt = ifmt.size(); // - // while (b8 < b8end) - // { - //#ifdef COMPOSITE_DEBUG - // std::cout << ""+++ begin = " << std::showbase << std::hex << std::setw(8) << b8 << - // ", end = " << b8end << dec << std::endl; - //#endif - // /* get next format code */ - // while (true) - // { - // imt++; - // /* end of format statement reached, back to iterm - last parenthesis or format begining */ - // if (imt > nfmt) - // { - // imt = 0/*iterm*/; /* sergey: will always start format from the begining - for now ...*/ - //#ifdef COMPOSITE_DEBUG - // std::cout << "1" << std::endl; - //#endif - // } - // /* meet right parenthesis, so we're finished processing format(s) in parenthesis */ - // else if (ifmt[imt-1] == 0) - // { - // /* right parenthesis without preceding left parenthesis? -> illegal format */ - // if (lev == 0) - // return -1; + // int imt = 0; /* ifmt[] index */ + // int ncnf = 0; /* how many times must repeat a format */ + // int lev = 0; /* parenthesis level */ + // int kcnf, mcnf, iterm = 0; + // int64_t *b64, *b64end; + // int32_t *b32, *b32end; + // int16_t *b16, *b16end; + // auto b8 = reinterpret_cast(&iarr[0]); /* beginning of data */ + // auto b8end = reinterpret_cast(&iarr[nwrd]) - padding; /* end of data + 1 - padding */ + // LV lv[10]; // - // /* increment counter */ - // lv[lev-1].irepeat++; + // #ifdef COMPOSITE_DEBUG + // std::cout << std::endl << "=== eviofmtswap start ===" << std::endl; + // #endif // - // /* if format in parenthesis was processed */ - // if (lv[lev-1].irepeat >= lv[lev-1].nrepeat) + // while (b8 < b8end) + // { + // #ifdef COMPOSITE_DEBUG + // std::cout << ""+++ begin = " << std::showbase << std::hex << std::setw(8) << b8 << + // ", end = " << b8end << dec << std::endl; + // #endif + // /* get next format code */ + // while (true) + // { + // imt++; + // /* end of format statement reached, back to iterm - last parenthesis or format begining */ + // if (imt > nfmt) // { - // /* required number of times */ - // - // /* store left parenthesis index minus 1 - // (if will meet end of format, will start from format index imt=iterm; - // by default we continue from the beginning of the format (iterm=0)) */ - // //iterm = lv[lev-1].left - 1; - // lev--; /* done with this level - decrease parenthesis level */ - //#ifdef COMPOSITE_DEBUG - // std::cout << "2" << std::endl; - //#endif + // imt = 0/*iterm*/; /* sergey: will always start format from the begining - for now ...*/ + // #ifdef COMPOSITE_DEBUG + // std::cout << "1" << std::endl; + // #endif // } - // /* go for another round of processing by setting 'imt' to the left parenthesis */ - // else + // /* meet right parenthesis, so we're finished processing format(s) in parenthesis */ + // else if (ifmt[imt-1] == 0) // { - // /* points ifmt[] index to the left parenthesis from the same level 'lev' */ - // imt = lv[lev-1].left; - //#ifdef COMPOSITE_DEBUG - // std::cout << "3" << std::endl; - //#endif - // } - // } - // else - // { - // ncnf = (ifmt[imt-1] >> 8) & 0x3F; /* how many times to repeat format code */ - // kcnf = ifmt[imt-1] & 0xFF; /* format code */ - // mcnf = (ifmt[imt-1] >> 14) & 0x3; /* repeat code */ + // /* right parenthesis without preceding left parenthesis? -> illegal format */ + // if (lev == 0) + // return -1; // - // /* left parenthesis - set new lv[] */ - // if (kcnf == 0) - // { - // /* check repeats for left parenthesis */ + // /* increment counter */ + // lv[lev-1].irepeat++; // - // if(mcnf==1) /* left parenthesis, SPECIAL case: #repeats must be taken from int32 data */ + // /* if format in parenthesis was processed */ + // if (lv[lev-1].irepeat >= lv[lev-1].nrepeat) // { - // mcnf = 0; - // b32 = reinterpret_cast(b8); - // ncnf = *b32 = SWAP_32(*b32); /* get #repeats from data */ - //#ifdef COMPOSITE_PRINT - // std::cout << "ncnf(: " << ncnf << std::endl; - //#endif - // b8 += 4; - //#ifdef COMPOSITE_DEBUG - // std::cout << "ncnf from data = " << ncnf << " (code 15)" << std::endl; - //#endif - // } + // /* required number of times */ // - // if(mcnf==2) /* left parenthesis, SPECIAL case: #repeats must be taken from int16 data */ - // { - // mcnf = 0; - // b16 = reinterpret_cast(b8); - // ncnf = *b16 = SWAP_16(*b16); /* get #repeats from data */ - //#ifdef COMPOSITE_PRINT - // std::cout << "ncnf(: " << ncnf << std::endl; - //#endif - // b8 += 2; - //#ifdef COMPOSITE_DEBUG - // std::cout << "ncnf from data = " << ncnf << " (code 14)" << std::endl; - //#endif + // /* store left parenthesis index minus 1 + // (if will meet end of format, will start from format index imt=iterm; + // by default we continue from the beginning of the format (iterm=0)) */ + // //iterm = lv[lev-1].left - 1; + // lev--; /* done with this level - decrease parenthesis level */ + // #ifdef COMPOSITE_DEBUG + // std::cout << "2" << std::endl; + // #endif // } - // - // if(mcnf==3) /* left parenthesis, SPECIAL case: #repeats must be taken from int8 data */ + // /* go for another round of processing by setting 'imt' to the left parenthesis */ + // else // { - // mcnf = 0; - // ncnf = *((uint8_t *)b8); /* get #repeats from data */ - //#ifdef COMPOSITE_PRINT - // std::cout << "ncnf(: " << ncnf << std::endl; - //#endif - // b8++; - //#ifdef COMPOSITE_DEBUG - // std::cout << "ncnf from data = " << ncnf << " (code 13)" << std::endl; - //#endif + // /* points ifmt[] index to the left parenthesis from the same level 'lev' */ + // imt = lv[lev-1].left; + // #ifdef COMPOSITE_DEBUG + // std::cout << "3" << std::endl; + // #endif // } - // - // - // /* store ifmt[] index */ - // lv[lev].left = imt; - // /* how many time will repeat format code inside parenthesis */ - // lv[lev].nrepeat = ncnf; - // /* cleanup place for the right parenthesis (do not get it yet) */ - // lv[lev].irepeat = 0; - // /* increase parenthesis level */ - // lev++; - //#ifdef COMPOSITE_DEBUG - // std::cout << "4" << std::endl; - //#endif // } - // /* format F or I or ... */ // else // { - // /* there are no parenthesis, just simple format, go to processing */ - // if (lev == 0) { - //#ifdef COMPOSITE_DEBUG - // std::cout << "51" << std::endl; - //#endif - // } - // /* have parenthesis, NOT the pre-last format element (last assumed ')' ?) */ - // else if (imt != (nfmt-1)) { - //#ifdef COMPOSITE_DEBUG - // std::cout << "52: " << imt << " " << (nfmt-1) << std::endl; - //#endif - // } - // /* have parenthesis, NOT the first format after the left parenthesis */ - // else if (imt != lv[lev-1].left+1) { - //#ifdef COMPOSITE_DEBUG - // std::cout << "53: " << imt << " " << (nfmt-1) << std::endl; - //#endif + // ncnf = (ifmt[imt-1] >> 8) & 0x3F; /* how many times to repeat format code */ + // kcnf = ifmt[imt-1] & 0xFF; /* format code */ + // mcnf = (ifmt[imt-1] >> 14) & 0x3; /* repeat code */ + // + // /* left parenthesis - set new lv[] */ + // if (kcnf == 0) + // { + // /* check repeats for left parenthesis */ + // + // if(mcnf==1) /* left parenthesis, SPECIAL case: #repeats must be taken from int32 data */ + // { + // mcnf = 0; + // b32 = reinterpret_cast(b8); + // ncnf = *b32 = SWAP_32(*b32); /* get #repeats from data */ + // #ifdef COMPOSITE_PRINT + // std::cout << "ncnf(: " << ncnf << std::endl; + // #endif + // b8 += 4; + // #ifdef COMPOSITE_DEBUG + // std::cout << "ncnf from data = " << ncnf << " (code 15)" << std::endl; + // #endif + // } + // + // if(mcnf==2) /* left parenthesis, SPECIAL case: #repeats must be taken from int16 data */ + // { + // mcnf = 0; + // b16 = reinterpret_cast(b8); + // ncnf = *b16 = SWAP_16(*b16); /* get #repeats from data */ + // #ifdef COMPOSITE_PRINT + // std::cout << "ncnf(: " << ncnf << std::endl; + // #endif + // b8 += 2; + // #ifdef COMPOSITE_DEBUG + // std::cout << "ncnf from data = " << ncnf << " (code 14)" << std::endl; + // #endif + // } + // + // if(mcnf==3) /* left parenthesis, SPECIAL case: #repeats must be taken from int8 data */ + // { + // mcnf = 0; + // ncnf = *((uint8_t *)b8); /* get #repeats from data */ + // #ifdef COMPOSITE_PRINT + // std::cout << "ncnf(: " << ncnf << std::endl; + // #endif + // b8++; + // #ifdef COMPOSITE_DEBUG + // std::cout << "ncnf from data = " << ncnf << " (code 13)" << std::endl; + // #endif + // } + // + // + // /* store ifmt[] index */ + // lv[lev].left = imt; + // /* how many time will repeat format code inside parenthesis */ + // lv[lev].nrepeat = ncnf; + // /* cleanup place for the right parenthesis (do not get it yet) */ + // lv[lev].irepeat = 0; + // /* increase parenthesis level */ + // lev++; + // #ifdef COMPOSITE_DEBUG + // std::cout << "4" << std::endl; + // #endif // } - // /* if none of above, we are in the end of format */ + // /* format F or I or ... */ // else // { - // /* set format repeat to the big number */ - // ncnf = 999999999; - //#ifdef COMPOSITE_DEBUG - // std::cout << "54" << std::endl; - //#endif + // /* there are no parenthesis, just simple format, go to processing */ + // if (lev == 0) { + // #ifdef COMPOSITE_DEBUG + // std::cout << "51" << std::endl; + // #endif + // } + // /* have parenthesis, NOT the pre-last format element (last assumed ')' ?) */ + // else if (imt != (nfmt-1)) { + // #ifdef COMPOSITE_DEBUG + // std::cout << "52: " << imt << " " << (nfmt-1) << std::endl; + // #endif + // } + // /* have parenthesis, NOT the first format after the left parenthesis */ + // else if (imt != lv[lev-1].left+1) { + // #ifdef COMPOSITE_DEBUG + // std::cout << "53: " << imt << " " << (nfmt-1) << std::endl; + // #endif + // } + // /* if none of above, we are in the end of format */ + // else + // { + // /* set format repeat to the big number */ + // ncnf = 999999999; + // #ifdef COMPOSITE_DEBUG + // std::cout << "54" << std::endl; + // #endif + // } + // break; // } - // break; // } - // } - // } /* while(1) */ + // } /* while(1) */ // - // /* if 'ncnf' is zero, get it from data */ - // /*printf("ncnf=%d\n",ncnf);fflush(stdout);*/ - // if(ncnf==0) - // { - // if(mcnf==1) + // /* if 'ncnf' is zero, get it from data */ + // /*printf("ncnf=%d\n",ncnf);fflush(stdout);*/ + // if(ncnf==0) // { - // b32 = (int *)b8; - // ncnf = *b32 = SWAP_32(*b32); - // /*printf("ncnf32=%d\n",ncnf);fflush(stdout);*/ - // b8 += 4; - // } - // else if(mcnf==2) - // { - // b16 = (short *)b8; - // ncnf = *b16 = SWAP_16(*b16); - // /*printf("ncnf16=%d\n",ncnf);fflush(stdout);*/ - // b8 += 2; - // } - // else if(mcnf==3) - // { - // ncnf = *b8; - // /*printf("ncnf08=%d\n",ncnf);fflush(stdout);*/ - // b8 += 1; - // } - // /*else printf("ncnf00=%d\n",ncnf);fflush(stdout);*/ + // if(mcnf==1) + // { + // b32 = (int *)b8; + // ncnf = *b32 = SWAP_32(*b32); + // /*printf("ncnf32=%d\n",ncnf);fflush(stdout);*/ + // b8 += 4; + // } + // else if(mcnf==2) + // { + // b16 = (short *)b8; + // ncnf = *b16 = SWAP_16(*b16); + // /*printf("ncnf16=%d\n",ncnf);fflush(stdout);*/ + // b8 += 2; + // } + // else if(mcnf==3) + // { + // ncnf = *b8; + // /*printf("ncnf08=%d\n",ncnf);fflush(stdout);*/ + // b8 += 1; + // } + // /*else printf("ncnf00=%d\n",ncnf);fflush(stdout);*/ // - //#ifdef COMPOSITE_DEBUG - // std::cout << "ncnf from data = " << ncnf << std::endl; - //#endif - // } + // #ifdef COMPOSITE_DEBUG + // std::cout << "ncnf from data = " << ncnf << std::endl; + // #endif + // } // // - // /* At this point we are ready to process next piece of data. - // We have following entry info: - // kcnf - format type - // ncnf - how many times format repeated - // b8 - starting data pointer (it comes from previously processed piece) - // */ + // /* At this point we are ready to process next piece of data. + // We have following entry info: + // kcnf - format type + // ncnf - how many times format repeated + // b8 - starting data pointer (it comes from previously processed piece) + // */ // - // /* Convert data in according to type kcnf */ + // /* Convert data in according to type kcnf */ // - // /* 64-bits */ - // if (kcnf == 8 || kcnf == 9 || kcnf == 10) { - // b64 = (int64_t *)b8; - // b64end = b64 + ncnf; - // if (b64end > (int64_t *)b8end) b64end = (int64_t *)b8end; - // while (b64 < b64end) { - // *b64 = SWAP_64(*b64); - // b64++; + // /* 64-bits */ + // if (kcnf == 8 || kcnf == 9 || kcnf == 10) { + // b64 = (int64_t *)b8; + // b64end = b64 + ncnf; + // if (b64end > (int64_t *)b8end) b64end = (int64_t *)b8end; + // while (b64 < b64end) { + // *b64 = SWAP_64(*b64); + // b64++; + // } + // b8 = (int8_t *)b64; + // #ifdef COMPOSITE_DEBUG + // std::cout << "64bit: " << ncnf << " elements" << std::endl; + // #endif // } - // b8 = (int8_t *)b64; - //#ifdef COMPOSITE_DEBUG - // std::cout << "64bit: " << ncnf << " elements" << std::endl; - //#endif - // } - // /* 32-bits */ - // else if ( kcnf == 1 || kcnf == 2 || kcnf == 11 || kcnf == 12) { - // b32 = (int32_t *)b8; - // b32end = b32 + ncnf; - // if (b32end > (int32_t *)b8end) b32end = (int32_t *)b8end; - // while (b32 < b32end) { - // *b32 = SWAP_32(*b32); - // b32++; + // /* 32-bits */ + // else if ( kcnf == 1 || kcnf == 2 || kcnf == 11 || kcnf == 12) { + // b32 = (int32_t *)b8; + // b32end = b32 + ncnf; + // if (b32end > (int32_t *)b8end) b32end = (int32_t *)b8end; + // while (b32 < b32end) { + // *b32 = SWAP_32(*b32); + // b32++; + // } + // b8 = (int8_t *)b32; + // #ifdef COMPOSITE_DEBUG + // std::cout << "32bit: " << ncnf << " elements, b8 = " << std::showbase << + // std::hex << std::setw(8) << b8 << dec << std::endl; + // #endif // } - // b8 = (int8_t *)b32; - //#ifdef COMPOSITE_DEBUG - // std::cout << "32bit: " << ncnf << " elements, b8 = " << std::showbase << - // std::hex << std::setw(8) << b8 << dec << std::endl; - //#endif - // } - // /* 16 bits */ - // else if ( kcnf == 4 || kcnf == 5) { - // b16 = (int16_t *)b8; - // b16end = b16 + ncnf; - // if (b16end > (int16_t *)b8end) b16end = (int16_t *)b8end; - // while (b16 < b16end) { - // *b16 = SWAP_16(*b16); - // b16++; + // /* 16 bits */ + // else if ( kcnf == 4 || kcnf == 5) { + // b16 = (int16_t *)b8; + // b16end = b16 + ncnf; + // if (b16end > (int16_t *)b8end) b16end = (int16_t *)b8end; + // while (b16 < b16end) { + // *b16 = SWAP_16(*b16); + // b16++; + // } + // b8 = (int8_t *)b16; + // #ifdef COMPOSITE_DEBUG + // std::cout << "16bit: " << ncnf << " elements" << std::endl; + // #endif + // } + // /* 8 bits */ + // else if ( kcnf == 6 || kcnf == 7 || kcnf == 3) { + // /* do nothing for characters */ + // b8 += ncnf; + // #ifdef COMPOSITE_DEBUG + // std::cout << "8bit: " << ncnf << " elements" << std::endl; + // #endif // } - // b8 = (int8_t *)b16; - //#ifdef COMPOSITE_DEBUG - // std::cout << "16bit: " << ncnf << " elements" << std::endl; - //#endif - // } - // /* 8 bits */ - // else if ( kcnf == 6 || kcnf == 7 || kcnf == 3) { - // /* do nothing for characters */ - // b8 += ncnf; - //#ifdef COMPOSITE_DEBUG - // std::cout << "8bit: " << ncnf << " elements" << std::endl; - //#endif - // } // - // } /* while(b8 < b8end) */ + // } /* while(b8 < b8end) */ // - //#ifdef COMPOSITE_DEBUG - // std::cout << std::endl << "=== eviofmtswap end ===" << std::endl; - //#endif + // #ifdef COMPOSITE_DEBUG + // std::cout << std::endl << "=== eviofmtswap end ===" << std::endl; + // #endif // - // return(0); - //} + // return(0); + // } /** * This method takes a CompositeData object and a transformed format string * and uses that to write data into a buffer/array in raw form. * - * @param rawBuf data buffer in which to put the raw bytes - * @param data data to convert to raw bytes - * @param ifmt format list as produced by {@link #compositeFormatToInt(const std::string &, std::vector &)} + * @param rawBuf data buffer in which to put the raw bytes. + * @param data data to convert to raw bytes. + * @param ifmt format list as produced by #compositeFormatToInt(const std::string &, std::vector &). * - * @throws EvioException if ifmt size <= 0; if srcBuf or destBuf is too + * @throws EvioException if ifmt size <= 0; if srcBuf or destBuf is too * small; not enough dataItems for the given format */ void CompositeData::dataToRawBytes(ByteBuffer & rawBuf, CompositeData::Data const & data, diff --git a/src/libsrc++/DataType.h b/src/libsrc++/DataType.h index 26a655d4..7c45d274 100644 --- a/src/libsrc++/DataType.h +++ b/src/libsrc++/DataType.h @@ -250,8 +250,10 @@ namespace evio { */ int getBytes() const {return bytes;} + /** Defines equal operator. */ bool operator==(const DataType &rhs) const; + /** Defines not equal operator. */ bool operator!=(const DataType &rhs) const; }; diff --git a/src/libsrc++/EventParser.h b/src/libsrc++/EventParser.h index 59f44a51..1d340ce2 100644 --- a/src/libsrc++/EventParser.h +++ b/src/libsrc++/EventParser.h @@ -63,7 +63,11 @@ namespace evio { protected: + /** Flag determining whether notification of listeners is active. Normally it is. But in some cases it could + * be temporarily suspended. For example, in a "goto event" process, the listeners will not be notified of the + * intervening events as the file is scanned to get to the target event. */ bool notificationActive = true; + /** Mutex for thread safety. */ std::recursive_mutex mtx; diff --git a/src/libsrc++/EventWriter.cpp b/src/libsrc++/EventWriter.cpp index 6c1bb47b..e0dcfea1 100644 --- a/src/libsrc++/EventWriter.cpp +++ b/src/libsrc++/EventWriter.cpp @@ -936,20 +936,6 @@ namespace evio { ByteOrder EventWriter::getByteOrder() const {return byteOrder;} - ///** - // * Set the number with which to start block (record) numbers. - // * This method does nothing if events have already been written. - // * @param startingRecordNumber the number with which to start block - // * (record) numbers. - // */ - //void EventWriter::setStartingBlockNumber(uint32_t startingRecordNumber) { - // // If events have been written already, forget about it - // if (eventsWrittenTotal > 0) return; - // recordNumber = startingRecordNumber; - ////std::cout << "setStartingBLOCKNumber: set to " << recordNumber << std::endl; - //} - - /** * Set the number with which to start record numbers. * This method does nothing if events have already been written. @@ -2020,6 +2006,8 @@ namespace evio { * * @param bank the bank to write. * @param force if writing to disk, force it to write event to the disk. + * @param ownRecord if true, write event in its own record regardless + * of event count and record size limits. * @return if writing to buffer: true if event was added to record, false if buffer full, * or record event count limit exceeded. * @@ -2061,10 +2049,8 @@ namespace evio { * which are both placed in the common record which, in turn, is the * user header part of the file header.

* - * @param bb ByteBuffer representing the event. + * @param bank the bank (as an EvioBank object) to write. * @param force if writing to disk, force it to write event to the disk. - * @param duplicate if true, duplicate bb so its position and limit - * can be changed without issue. * @param ownRecord if true, write event in its own record regardless * of event count and record size limits. * diff --git a/src/libsrc++/EventWriterV4.cpp b/src/libsrc++/EventWriterV4.cpp index d1e9eacc..6f90fb98 100644 --- a/src/libsrc++/EventWriterV4.cpp +++ b/src/libsrc++/EventWriterV4.cpp @@ -109,12 +109,12 @@ namespace evio { * @param split if < 1, do not split file, write to only one file of unlimited size. * Else this is max size in bytes to make a file * before closing it and starting writing another. - * @param maxBlockSize the max blocksize in bytes to use which must be >= {@link #MIN_BLOCK_SIZE} - * and <= {@link #MAX_BLOCK_SIZE}. + * @param maxBlockSize the max blocksize in bytes to use which must be >= #MIN_BLOCK_SIZE + * and <= #MAX_BLOCK_SIZE. * The size of the block will not be larger than this size * unless a single event itself is larger. * @param maxEventCount the max number of events (including dictionary) in a single block - * which must be >= {@link #MIN_BLOCK_COUNT} and <= {@link #MAX_BLOCK_COUNT}. + * which must be >= #MIN_BLOCK_COUNT and <= #MAX_BLOCK_COUNT. * @param byteOrder the byte order in which to write the file. This is ignored * if appending to existing file. * @param xmlDictionary dictionary in xml format or empty if none. @@ -131,6 +131,7 @@ namespace evio { * @param bufferSize number of bytes to make the internal buffer which will * be storing events before writing them to a file. Must be at least * a max block size + 1kB (add a little extra). If not, it is set to that. + * @param bitInfo set of bits to include in first block header. * * @throws EvioException if defined dictionary or first event while appending; * if splitting file while appending; @@ -407,12 +408,12 @@ namespace evio { * Create an EventWriterV4 for writing events to a ByteBuffer. * * @param buf the buffer to write to. - * @param maxBlockSize the max blocksize to use which must be >= {@link #MIN_BLOCK_SIZE} - * and <= {@link #MAX_BLOCK_SIZE} ints. + * @param maxBlockSize the max blocksize to use which must be >= #MIN_BLOCK_SIZE + * and <= #MAX_BLOCK_SIZE ints. * The size of the block will not be larger than this size * unless a single event itself is larger. * @param maxEventCount the max number of events (including dictionary) in a single block - * which must be >= {@link #MIN_BLOCK_COUNT} and <= {@link #MAX_BLOCK_COUNT}. + * which must be >= #MIN_BLOCK_COUNT and <= #MAX_BLOCK_COUNT. * @param xmlDictionary dictionary in xml format or null if none. * @param bitInfo set of bits to include in first block header. * @param reserved1 set the value of the first "reserved" int in first block header. @@ -444,12 +445,12 @@ namespace evio { * The buffer's position is set to 0 before writing. * * @param buf the buffer to write to. - * @param maxBlockSize the max blocksize to use which must be >= {@link #MIN_BLOCK_SIZE} - * and <= {@link #MAX_BLOCK_SIZE} ints. + * @param maxBlockSize the max blocksize to use which must be >= #MIN_BLOCK_SIZE + * and <= #MAX_BLOCK_SIZE ints. * The size of the block will not be larger than this size * unless a single event itself is larger. * @param maxEventCount the max number of events (including dictionary) in a single block - * which must be >= {@link #MIN_BLOCK_COUNT} and <= {@link #MAX_BLOCK_COUNT}. + * which must be >= #MIN_BLOCK_COUNT and <= #MAX_BLOCK_COUNT. * @param xmlDictionary dictionary in xml format or null if none. * @param bitInfo set of bits to include in first block header. * @param reserved1 set the value of the first "reserved" int in first block header. diff --git a/src/libsrc++/EventWriterV4.h b/src/libsrc++/EventWriterV4.h index 9d74538c..f95139e5 100644 --- a/src/libsrc++/EventWriterV4.h +++ b/src/libsrc++/EventWriterV4.h @@ -76,6 +76,11 @@ namespace evio { boost::thread_group threadPool; public: + + /** + * Constructor. + * @param poolSize size of pool of threads to close files. + */ FileCloserV4(int poolSize) { // Create a work object to keep the io_context busy boost::asio::io_context::work work(ioContext); @@ -88,10 +93,16 @@ namespace evio { } } + /** Close this object by ending all threads in pool. */ void close() { threadPool.join_all(); } + /** + * Close file given by filestream after pending write is finished. + * @param afc file stream to close. + * @param future object representing a write that is in progress. + */ void closeAsyncFile(std::shared_ptr afc, std::shared_ptr> future) { ioContext.post([=]() { diff --git a/src/libsrc++/EvioDictionaryEntry.h b/src/libsrc++/EvioDictionaryEntry.h index 573fe85c..2f93af83 100644 --- a/src/libsrc++/EvioDictionaryEntry.h +++ b/src/libsrc++/EvioDictionaryEntry.h @@ -247,7 +247,7 @@ namespace evio { return tagEnd != 0 && entry.tag >= tag && entry.tag <= tagEnd; } - + /** Define equal operator. */ bool operator==(const EvioDictionaryEntry &other) const { if (&other == this) return true; @@ -282,6 +282,7 @@ namespace evio { return match; } + /** Define not equal operator. */ bool operator!=(const EvioDictionaryEntry &rhs) const { return !(rhs == *this); } diff --git a/src/libsrc++/EvioException.h b/src/libsrc++/EvioException.h index 07afb1c0..a5b3cf0f 100644 --- a/src/libsrc++/EvioException.h +++ b/src/libsrc++/EvioException.h @@ -30,9 +30,24 @@ namespace evio { public: + /** + * Constructor. + * @param msg error message. + */ explicit EvioException(const std::string & msg) noexcept : std::runtime_error(msg) {} + + /** + * Constructor. + * @param ex exception that caused this one. + */ explicit EvioException(const std::exception & ex) noexcept : std::runtime_error(ex.what()) {} + /** + * Constructor. + * @param msg error message. + * @param file name of file exception occurred. + * @param line file line exception occurred. + */ EvioException(const std::string & msg, const char *file, int line) noexcept : std::runtime_error(msg) { std::ostringstream o; o << file << ":" << line << ":" << msg; @@ -41,6 +56,7 @@ namespace evio { }; +/** Macro that throws an exception with given message and file, line info. */ #define throwEvioLine(arg) throw EvioException(arg, __FILE__, __LINE__); } diff --git a/src/libsrc++/EvioNode.h b/src/libsrc++/EvioNode.h index 556acf25..d9f03f64 100644 --- a/src/libsrc++/EvioNode.h +++ b/src/libsrc++/EvioNode.h @@ -155,6 +155,12 @@ namespace evio { protected: explicit EvioNode(std::shared_ptr firstNode, int dummy); + + /** + * This methods calls shared_from_this() to obtain a new std::shared_ptr that + * shares ownership of the current object (this). + * @return a new std::shared_ptr that shares ownership of the current object. + */ std::shared_ptr getThis() {return shared_from_this();} public: diff --git a/src/libsrc++/FileEventIndex.cpp b/src/libsrc++/FileEventIndex.cpp index 4d873b0c..4d3e970e 100644 --- a/src/libsrc++/FileEventIndex.cpp +++ b/src/libsrc++/FileEventIndex.cpp @@ -231,6 +231,12 @@ namespace evio { } + /** + * Example use of this class. + * @param argc unused. + * @param argv unused. + * @return + */ int FileEventIndex::main(int argc, char **argv) { FileEventIndex index; diff --git a/src/libsrc++/HeaderType.cpp b/src/libsrc++/HeaderType.cpp index 9241531b..6d66f0ce 100644 --- a/src/libsrc++/HeaderType.cpp +++ b/src/libsrc++/HeaderType.cpp @@ -13,11 +13,12 @@ namespace evio { - + /** Define equal operator. */ bool HeaderType::operator==(const HeaderType &rhs) const { return value == rhs.value; } + /** Define not equal operator. */ bool HeaderType::operator!=(const HeaderType &rhs) const { return value != rhs.value; } diff --git a/src/libsrc++/RecordCompressor.h b/src/libsrc++/RecordCompressor.h index 75285552..85a8b3ea 100644 --- a/src/libsrc++/RecordCompressor.h +++ b/src/libsrc++/RecordCompressor.h @@ -69,6 +69,13 @@ namespace evio { supply(recordSupply) { } + + /** + * Move constructor. + * Used to transfer ownership of resources from one object to another without making a deep copy. + * It is typically used when an object is being moved rather than copied. + * @param obj + */ RecordCompressor(RecordCompressor && obj) noexcept : threadNumber(obj.threadNumber), compressionType(obj.compressionType), @@ -76,6 +83,7 @@ namespace evio { thd(std::move(obj.thd)) { } + /** Define equal operator. */ RecordCompressor & operator=(RecordCompressor && obj) noexcept { if (this != &obj) { threadNumber = obj.threadNumber; @@ -86,6 +94,7 @@ namespace evio { return *this; } + /** Destructor. */ ~RecordCompressor() { thd.interrupt(); if (thd.try_join_for(boost::chrono::milliseconds(500))) { diff --git a/src/libsrc++/RecordHeader.cpp b/src/libsrc++/RecordHeader.cpp index 34f1e19c..8ce5f321 100644 --- a/src/libsrc++/RecordHeader.cpp +++ b/src/libsrc++/RecordHeader.cpp @@ -96,7 +96,7 @@ namespace evio { } } - + /** Define equal operator. */ RecordHeader & RecordHeader::operator=(const RecordHeader& head) { if (this != &head) { diff --git a/src/libsrc++/RecordInput.cpp b/src/libsrc++/RecordInput.cpp index ce09e51b..3ddc625f 100644 --- a/src/libsrc++/RecordInput.cpp +++ b/src/libsrc++/RecordInput.cpp @@ -324,7 +324,6 @@ namespace evio { * * @param buffer buffer to be filled with event. * @param index index of event starting at 0. - * @param bufOffset offset into buffer to place event. * @return buffer buffer arg. * @throws EvioException if index too large, or buffer has insufficient space to * contain event (buffer.capacity() < event size). diff --git a/src/libsrc++/RecordRingItem.cpp b/src/libsrc++/RecordRingItem.cpp index ebd012d3..e4f4f47f 100644 --- a/src/libsrc++/RecordRingItem.cpp +++ b/src/libsrc++/RecordRingItem.cpp @@ -102,29 +102,29 @@ namespace evio { } - ///** - // * Assignment operator. - // * @param other right side object. - // * @return left side object. - // */ - //RecordRingItem & RecordRingItem::operator=(const RecordRingItem& other) { - // - // // Avoid self assignment ... - // if (this != &other) { - // id = other.id; - // order = other.order; - // sequence = other.sequence; - // lastItem.store(other.lastItem); - // checkDisk.store(other.checkDisk); - // forceToDiskBool.store(other.forceToDiskBool); - // splitFileAfterWriteBool.store(other.splitFileAfterWriteBool); - // alreadyReleased = other.alreadyReleased; - // - // // Need to copy construct record & make shared pointer out of it - // record = std::make_shared(*(item.record.get())); - // } - // return *this; - //} + // ///** + // // * Assignment operator. + // // * @param other right side object. + // // * @return left side object. + // // */ + // //RecordRingItem & RecordRingItem::operator=(const RecordRingItem& other) { + // // + // // // Avoid self assignment ... + // // if (this != &other) { + // // id = other.id; + // // order = other.order; + // // sequence = other.sequence; + // // lastItem.store(other.lastItem); + // // checkDisk.store(other.checkDisk); + // // forceToDiskBool.store(other.forceToDiskBool); + // // splitFileAfterWriteBool.store(other.splitFileAfterWriteBool); + // // alreadyReleased = other.alreadyReleased; + // // + // // // Need to copy construct record & make shared pointer out of it + // // record = std::make_shared(*(item.record.get())); + // // } + // // return *this; + // //} /** Method to reset this item each time it is retrieved from the supply. */ diff --git a/src/libsrc++/SegmentHeader.cpp b/src/libsrc++/SegmentHeader.cpp index e22f2c39..703740be 100644 --- a/src/libsrc++/SegmentHeader.cpp +++ b/src/libsrc++/SegmentHeader.cpp @@ -23,30 +23,10 @@ namespace evio { BaseStructureHeader(tag, dataType) {} - /** - * Get the length of the structure's data in 32 bit ints (not counting the header words). - * @return Get the length of the structure's data in 32 bit ints (not counting the header words). - */ uint32_t SegmentHeader::getDataLength() {return length;} - - /** - * Get the length of the structure's header in ints. This includes the first header word itself - * (which contains the length) and in the case of banks, it also includes the second header word. - * @return Get the length of the structure's header in ints. - */ uint32_t SegmentHeader::getHeaderLength() {return 1;} - - /** - * Write myself out as evio format data - * into the given byte array in the specified byte order. - * - * @param dest array into which evio data is written. - * @param order byte order in which to write the data. - * @return the number of bytes written, which for a SegmentHeader is 4. - * @throws EvioException if destination array too small to hold data. - */ size_t SegmentHeader::write(uint8_t *dest, ByteOrder const & order) { auto word = (uint32_t) (tag << 24 | (uint8_t)((dataType.getValue() & 0x3f) | @@ -55,26 +35,10 @@ namespace evio { return 4; } - - /** - * Write myself out a byte buffer. - * This write is relative - i.e., it uses the current position of the buffer. - * - * @param byteBuffer the byteBuffer to write to. - * @return the number of bytes written, which for a SegmentHeader is 4. - */ size_t SegmentHeader::write(std::shared_ptr byteBuffer) { return write(*(byteBuffer.get())); } - - /** - * Write myself out a byte buffer. - * This write is relative - i.e., it uses the current position of the buffer. - * - * @param byteBuffer the byteBuffer to write to. - * @return the number of bytes written, which for a SegmentHeader is 4. - */ size_t SegmentHeader::write(ByteBuffer & byteBuffer) { auto word = (uint32_t) (tag << 24 | (uint8_t)((dataType.getValue() & 0x3f) | diff --git a/src/libsrc++/StructureType.cpp b/src/libsrc++/StructureType.cpp index a18eb1f6..e4af4274 100644 --- a/src/libsrc++/StructureType.cpp +++ b/src/libsrc++/StructureType.cpp @@ -13,11 +13,12 @@ namespace evio { - + /** Define == operator. */ bool StructureType::operator==(const StructureType &rhs) const { return value == rhs.value; } + /** Define not equal operator. */ bool StructureType::operator!=(const StructureType &rhs) const { return value != rhs.value; } diff --git a/src/libsrc++/TagSegmentHeader.cpp b/src/libsrc++/TagSegmentHeader.cpp index 8b4c0f0c..74aa5fda 100644 --- a/src/libsrc++/TagSegmentHeader.cpp +++ b/src/libsrc++/TagSegmentHeader.cpp @@ -35,55 +35,20 @@ namespace evio { } - /** - * Get the length of the structure's data in 32 bit ints (not counting the header words). - * @return Get the length of the structure's data in 32 bit ints (not counting the header words). - */ uint32_t TagSegmentHeader::getDataLength() {return length;} - - /** - * Get the length of the structure's header in ints. This includes the first header word itself - * (which contains the length) and in the case of banks, it also includes the second header word. - * @return Get the length of the structure's header in ints. - */ uint32_t TagSegmentHeader::getHeaderLength() {return 1;} - /** - * Write myself out as evio format data - * into the given byte array in the specified byte order. - * - * @param dest array into which evio data is written (destination). - * @param order byte order in which to write the data. - * @return the number of bytes written, which for a TagSegmentHeader is 4. - * @throws EvioException if destination array too small to hold data. - */ size_t TagSegmentHeader::write(uint8_t *dest, ByteOrder const & order) { auto compositeWord = (uint32_t) (tag << 20 | ((dataType.getValue() & 0xf)) << 16 | (length & 0xffff)); Util::toBytes(compositeWord, order, dest); return 4; } - - /** - * Write myself out a byte buffer. - * This write is relative - i.e., it uses the current position of the buffer. - * - * @param byteBuffer the byteBuffer to write to. - * @return the number of bytes written, which for a TagSegmentHeader is 4. - */ size_t TagSegmentHeader::write(std::shared_ptr byteBuffer) { return write(*(byteBuffer.get())); } - - /** - * Write myself out a byte buffer. - * This write is relative - i.e., it uses the current position of the buffer. - * - * @param byteBuffer the byteBuffer to write to. - * @return the number of bytes written, which for a TagSegmentHeader is 4. - */ size_t TagSegmentHeader::write(ByteBuffer & byteBuffer) { auto compositeWord = (uint32_t) (tag << 20 | ((dataType.getValue() & 0xf)) << 16 | (length & 0xffff)); byteBuffer.putInt(compositeWord);