evio
6.0
|
Class containing static methods of general purpose. More...
#include <Util.h>
Static Public Member Functions | |
static uint32_t | getWords (uint32_t length) |
Returns length padded to 4-byte boundary for given length in bytes. More... | |
static uint32_t | getPadding (uint32_t length) |
Returns number of bytes needed to pad to 4-byte boundary for the given length. More... | |
static bool | iStrEquals (const std::string &a, const std::string &b) |
Case insensitive compare for 2 strings. More... | |
static const DataType & | getDataType (const std::string &type) |
This method returns an XML element name given an evio data type. More... | |
static void | toIntArray (char const *data, uint32_t dataLen, const ByteOrder &byteOrder, uint32_t *dest) |
Turn byte array into an int array. More... | |
static uint32_t | toInt (char b1, char b2, char b3, char b4, const ByteOrder &byteOrder) |
Turn 4 bytes into an unsigned 32 bit int. More... | |
static uint32_t | toInt (uint8_t const *data, ByteOrder const &byteOrder) |
Turn 4 bytes into an unsigned 32 bit int. More... | |
static uint64_t | toLong (uint8_t const *data, ByteOrder const &byteOrder) |
Turn 4 bytes into an unsigned 32 bit int. More... | |
static void | toBytes (uint32_t data, const ByteOrder &byteOrder, uint8_t *dest) |
Write int into byte array. More... | |
static void | toBytes (uint64_t data, const ByteOrder &byteOrder, uint8_t *dest) |
Turn long into byte array. More... | |
static void | toBytes (uint32_t data, const ByteOrder &byteOrder, std::vector< uint8_t > &dest, size_t off) |
Write int into byte vector. More... | |
static void | toBytes (uint16_t data, const ByteOrder &byteOrder, uint8_t *dest) |
Write short into byte array. More... | |
static void | toBytes (uint16_t data, const ByteOrder &byteOrder, std::vector< uint8_t > &dest, size_t off) |
Write short into byte vector. More... | |
static const std::string & | NO_NAME_STRING () |
Get a string used to indicate that no name can be determined. More... | |
static uint32_t | findEvioVersion (ByteBuffer &bb, size_t initialPos) |
Reads a couple things in a block/record header in order to determine the evio version and endianness of a buffer/file. More... | |
static void | printBytes (const std::shared_ptr< ByteBuffer > buf, uint32_t position, uint32_t bytes, const std::string &label) |
This method takes a byte buffer and prints out the desired number of bytes from the given position, in hex. More... | |
static void | printBytes (const ByteBuffer &buf, uint32_t position, uint32_t bytes, const std::string &label) |
This method takes a byte buffer and prints out the desired number of bytes from the given position, in hex. More... | |
static void | printBytes (uint8_t const *data, uint32_t bytes, const std::string &label) |
This method takes a pointer and prints out the desired number of bytes from the given position, in hex. More... | |
static void | printBytes (const std::string &fileName, uint64_t offset, uint32_t bytes, const std::string &label) |
This method takes a file and prints out the desired number of bytes from the given offset, in hex. More... | |
static void | writeBytes (const std::string &fileName, ByteBuffer &buf) |
This method takes a ByteBuffer and writes its data to a file. More... | |
static void | readBytes (const std::string &fileName, ByteBuffer &buf) |
This method reads part of a file into a ByteBuffer. More... | |
static int | powerOfTwo (int x, bool roundUp) |
Return the power of 2 closest to the given argument. More... | |
static void | stringToASCII (const std::string &input, std::vector< uint8_t > &array) |
Return an input string as ASCII in which each character is one byte. More... | |
static void | stringToASCII (const std::string &input, ByteBuffer &buf) |
Return an input string as ASCII in which each character is one byte. More... | |
static uint32_t | stringsToRawSize (std::vector< std::string > const &strings) |
This method returns the number of bytes in a raw evio format of the given string array, not including header. More... | |
static uint32_t | stringToRawSize (const std::string &str) |
This method returns the number of bytes in a raw evio format of the given string array (with a single string), not including header. More... | |
static void | stringsToRawBytes (std::vector< std::string > &strings, std::vector< uint8_t > &bytes) |
This method transforms an array/vector of strings into raw evio format data, not including header. More... | |
static void | unpackRawBytesToStrings (std::vector< uint8_t > &bytes, size_t offset, std::vector< std::string > &strData) |
This method extracts an array of strings from byte array of raw evio string data. More... | |
static void | unpackRawBytesToStrings (std::vector< uint8_t > &bytes, size_t offset, size_t maxLength, std::vector< std::string > &strData) |
This method extracts an array of strings from byte array of raw evio string data. More... | |
static void | unpackRawBytesToStrings (uint8_t *bytes, size_t length, std::vector< std::string > &strData) |
This method extracts an array of strings from byte array of raw evio string data. More... | |
static void | unpackRawBytesToStrings (ByteBuffer &buffer, size_t pos, size_t length, std::vector< std::string > &strData) |
This method extracts an array of strings from buffer containing raw evio string data. More... | |
static void | stringBuilderToStrings (std::string const &strData, bool onlyGoodChars, std::vector< std::string > &strings) |
This method extracts an array of strings from a string containing evio string data. More... | |
static void | expandEnvironmentalVariables (std::string &text) |
Substitute environmental variables in a given string when they come in the form, . More... | |
static uint32_t | countAndFixIntSpecifiers (std::string &text) |
Count the number of integer specifiers (e.g. More... | |
static int | generateBaseFileName (const std::string &baseName, const std::string &runType, std::string &modifiedBaseName) |
This method generates part of a file name given a base file name as an argument. More... | |
static std::string | generateFileName (std::string fileName, uint32_t specifierCount, uint32_t runNumber, uint64_t split, uint32_t splitNumber, uint32_t streamId, uint32_t streamCount) |
This method does NOT work on its own. More... | |
Class containing static methods of general purpose.
|
inlinestatic |
Count the number of integer specifiers (e.g.
%34d, %07x) in the given string, making sure any number preceding "x" or "d" starts with a 0. This is done so there will be no empty spaces in the resulting string (i.e. file name) when final substitutions are made for these specifiers.
text | string to analyze. |
Referenced by generateBaseFileName().
|
inlinestatic |
Substitute environmental variables in a given string when they come in the form, .
text | string to analyze. |
Referenced by generateBaseFileName().
|
inlinestatic |
Reads a couple things in a block/record header in order to determine the evio version and endianness of a buffer/file.
The endianness can be read from the given ByteBuffer by calling, bb.order(). This does not change any parameters of the given buffer.
bb | ByteBuffer to read from. |
initialPos | position in bb to start reading. |
underflow_error | if not enough data in buffer. |
EvioException | bad magic number in header. |
References evio::IBlockHeader::BIT_INFO_OFFSET, evio::ByteOrder::ENDIAN_BIG, evio::ByteOrder::ENDIAN_LITTLE, evio::ByteBuffer::getInt(), evio::ByteBuffer::getUInt(), evio::ByteBuffer::limit(), evio::IBlockHeader::MAGIC_NUMBER, evio::IBlockHeader::MAGIC_OFFSET, evio::ByteBuffer::order(), and evio::IBlockHeader::VERSION_MASK.
Referenced by evio::EvioCompactReader::EvioCompactReader(), and evio::EvioReader::EvioReader().
|
inlinestatic |
This method generates part of a file name given a base file name as an argument.
The base file name may contain up to 3, C-style integer format specifiers (such as %03d, or x). If more than 3 are found, an exception will be thrown. If no "0" precedes any integer between the "%" and the "d" or "x" of the format specifier, it will be added automatically in order to avoid spaces in the returned string. In the generateFileName(std::string, uint32_t, uint32_t, uint64_t, uint32_t, uint32_t, uint32_t) method, the first occurrence will be substituted with the given runNumber value. If the file is being split, the second will be substituted with the split number. If there are multiple streams, the third will be substituted with the stream id.
The base file name may contain characters of the form which will be substituted with the value of the associated environmental variable or a blank string if none is found.
Finally, the base file name may contain occurrences of the string "%s" which will be substituted with the value of the runType arg or nothing if the runType is null.
baseName | file name to start with |
runType | run type/configuration name |
modifiedBaseName | final generated base file name |
EvioException | if baseName arg is improperly formatted or blank |
References countAndFixIntSpecifiers(), and expandEnvironmentalVariables().
Referenced by evio::EventWriter::EventWriter().
|
inlinestatic |
This method does NOT work on its own.
It generates a complete file name from the previously determined baseFileName obtained from calling generateBaseFileName. If evio data is to be split up into multiple files (split > 0), numbers are used to distinguish between the split files with splitNumber. If baseFileName contains C-style int format specifiers (specifierCount > 0), then the first occurrence will be substituted with the given runNumber value. If the file is being split, the second will be substituted with the splitNumber. If there are multiple streams, the third will be substituted with the stream id.
If no specifier for the splitNumber exists, it is tacked onto the end of the file name. If no specifier for the stream id exists, it is tacked onto the end of the file name, after the splitNumber. No run numbers are ever tacked on without a specifier.
For splitting: if there is only 1 stream, no stream ids are used and any third specifier is removed. For non-splitting: if there is only 1 stream, no stream ids are used and any second and third specifiers are removed. For multiple streams, the second specifier is removed and the 3rd substituted with the stream id. For all cases: if there are more than 3 specifiers, NO SUBSTITUTIONS ARE DONE.
fileName | file name to use as a basis for the generated file name |
specifierCount | number of C-style int format specifiers in baseFileName arg |
runNumber | CODA run number |
split | number of bytes at which to split off evio file |
splitNumber | number of the split file |
streamId | number of the stream id |
streamCount | total number of streams |
EvioException | if the baseFileName arg contains printing format specifiers which are not compatible with integers and interfere with formatting. |
Referenced by evio::EventWriter::EventWriter().
|
inlinestatic |
This method returns an XML element name given an evio data type.
type | evio data type |
References evio::DataType::ALSOBANK, evio::DataType::ALSOSEGMENT, evio::DataType::CHAR8, evio::DataType::CHARSTAR8, evio::DataType::COMPOSITE, evio::DataType::DOUBLE64, evio::DataType::FLOAT32, evio::DataType::INT32, iStrEquals(), evio::DataType::LONG64, evio::DataType::NOT_A_VALID_TYPE, evio::DataType::SHORT16, evio::DataType::TAGSEGMENT, evio::DataType::UCHAR8, evio::DataType::UINT32, evio::DataType::ULONG64, evio::DataType::UNKNOWN32, and evio::DataType::USHORT16.
Referenced by evio::EvioXMLDictionary::parseXML().
|
inlinestatic |
Returns number of bytes needed to pad to 4-byte boundary for the given length.
length | length in bytes. |
Array to help find number of bytes to pad data.
Referenced by getWords(), and evio::FileHeader::setUserHeaderLength().
|
inlinestatic |
Returns length padded to 4-byte boundary for given length in bytes.
length | length in bytes. |
References getPadding().
Referenced by evio::FileHeader::setUserHeaderLength().
|
inlinestatic |
Case insensitive compare for 2 strings.
a | first string. |
b | second string. |
Referenced by getDataType(), and evio::EvioXMLDictionary::parseXML().
|
inlinestatic |
Get a string used to indicate that no name can be determined.
Referenced by evio::EvioXMLDictionary::NO_NAME_STRING().
|
inlinestatic |
Return the power of 2 closest to the given argument.
x | value to get the power of 2 closest to. |
roundUp | if true, round up, else down |
Referenced by evio::EventWriter::EventWriter().
|
inlinestatic |
This method takes a byte buffer and prints out the desired number of bytes from the given position, in hex.
Prints all bytes.
buf | buffer to print out |
position | position of data (bytes) in buffer to start printing |
bytes | number of bytes to print in hex |
label | a label to print as header |
Referenced by printBytes().
|
inlinestatic |
This method takes a byte buffer and prints out the desired number of bytes from the given position, in hex.
Prints all bytes.
buf | buffer to print out |
position | position of data (bytes) in buffer to start printing |
bytes | number of bytes to print in hex |
label | a label to print as header |
References evio::ByteBuffer::capacity().
|
inlinestatic |
This method takes a pointer and prints out the desired number of bytes from the given position, in hex.
data | data to print out |
bytes | number of bytes to print in hex |
label | a label to print as header |
|
inlinestatic |
This method takes a file and prints out the desired number of bytes from the given offset, in hex.
fileName | file to print out |
offset | offset into file to start printing |
bytes | number of bytes to print in hex |
label | a label to print as header |
References evio::ByteBuffer::array(), and printBytes().
|
inlinestatic |
This method reads part of a file into a ByteBuffer.
The buffer's position will be at the end of the data that is read. The caller will have to flip the buffer to read it.
fileName | file to read from. |
buf | buffer to write into. |
EvioException | bad file name or unable to do I/O. |
References evio::ByteBuffer::array(), evio::ByteBuffer::arrayOffset(), evio::ByteBuffer::limit(), evio::ByteBuffer::position(), and evio::ByteBuffer::remaining().
|
inlinestatic |
This method extracts an array of strings from a string containing evio string data.
If non-printable chars are found (besides those used to terminate strings), then 1 string with all characters will be returned. However, if the "onlyGoodChars" flag is true, 1 string is returned in truncated form without the bad characters at the end.
The name of this method is taken from the java and has little to do with C++. That's done for ease of code maintenance.
strData | containing string data |
onlyGoodChars | if true and non-printable chars found, only 1 string with printable ASCII chars will be returned. |
strings | vector in which to place extracted strings. |
Referenced by unpackRawBytesToStrings().
|
inlinestatic |
This method transforms an array/vector of strings into raw evio format data, not including header.
strings | vector of strings to transform. |
bytes | vector of bytes to contain evio formatted strings. |
References stringsToRawSize().
Referenced by evio::CompactEventBuilder::addStringData(), evio::CompositeData::dataToRawBytes(), and evio::CompositeData::stringsToFormat().
|
inlinestatic |
This method returns the number of bytes in a raw evio format of the given string array, not including header.
strings | vector of strings to size |
Referenced by evio::CompositeData::Data::addString(), evio::BaseStructure::stringsToRawBytes(), and stringsToRawBytes().
|
inlinestatic |
Return an input string as ASCII in which each character is one byte.
input | input string. |
array | vector in which to place ASCII. |
|
inlinestatic |
Return an input string as ASCII in which each character is one byte.
input | input string. |
buf | ByteBuffer in which to place ASCII. Clears existing data and may expand internal storage. |
References evio::ByteBuffer::clear(), evio::ByteBuffer::expand(), and evio::ByteBuffer::put().
|
inlinestatic |
This method returns the number of bytes in a raw evio format of the given string array (with a single string), not including header.
str | single string to size |
Referenced by evio::TagSegmentHeader::TagSegmentHeader().
|
inlinestatic |
Write int into byte array.
data | int to convert. |
byteOrder | byte order of written bytes. |
dest | array in which to write int. |
EvioException | if dest is null or too small. |
References evio::ByteOrder::ENDIAN_BIG.
Referenced by evio::SegmentHeader::write(), evio::TagSegmentHeader::write(), and evio::BankHeader::write().
|
inlinestatic |
Turn long into byte array.
data | long to convert. |
byteOrder | byte order of written bytes. |
dest | array in which to write long. |
EvioException | if dest is null or too small |
References evio::ByteOrder::ENDIAN_BIG.
|
inlinestatic |
Write int into byte vector.
data | int to convert. |
byteOrder | byte order of vector. |
dest | vector in which to write int. |
off | offset into vector where int is to be written. |
References evio::ByteOrder::ENDIAN_BIG.
|
inlinestatic |
Write short into byte array.
data | short to convert. |
byteOrder | byte order of array. |
dest | array in which to write short. |
EvioException | if dest is null or too small. |
References evio::ByteOrder::ENDIAN_BIG.
|
inlinestatic |
Write short into byte vector.
data | short to convert. |
byteOrder | byte order of vector. |
dest | vector in which to write short. |
off | offset into vector where short is to be written. |
References evio::ByteOrder::ENDIAN_BIG.
|
inlinestatic |
Turn 4 bytes into an unsigned 32 bit int.
b1 | 1st byte |
b2 | 2nd byte |
b3 | 3rd byte |
b4 | 4th byte |
byteOrder | if big endian, 1st byte is most significant & 4th is least |
References evio::ByteOrder::ENDIAN_BIG.
Referenced by evio::EvioReader::getEvent(), and toIntArray().
|
inlinestatic |
Turn 4 bytes into an unsigned 32 bit int.
data | pointer to bytes to convert. |
byteOrder | byte order of bytes. |
EvioException | if data is null. |
References evio::ByteOrder::ENDIAN_BIG.
|
inlinestatic |
Turn byte array into an int array.
Number of int array elements = number of bytes / 4.
data | char array to convert. |
dataLen | number of bytes to convert. |
byteOrder | byte order of supplied bytes. |
dest | array in which to write converted bytes. |
EvioException | if data or dest is null |
References toInt().
Referenced by evio::EventHeaderParser::createBankHeader(), evio::EventHeaderParser::createSegmentHeader(), evio::EventHeaderParser::createTagSegmentHeader(), and evio::Reader::scanFile().
|
inlinestatic |
Turn 4 bytes into an unsigned 32 bit int.
data | pointer to bytes to convert |
byteOrder | byte order of bytes. |
EvioException | if data is null. |
References evio::ByteOrder::ENDIAN_BIG.
|
inlinestatic |
This method extracts an array of strings from byte array of raw evio string data.
bytes | raw evio string data. |
offset | offset into raw data array. |
strData | vector in which to place extracted strings. |
Referenced by evio::CompositeData::parse(), evio::CompositeData::process(), evio::CompositeData::swapAll(), and evio::CompositeData::toString().
|
inlinestatic |
This method extracts an array of strings from byte array of raw evio string data.
Don't go beyond the specified max character limit and stop at the first non-character value.
bytes | raw evio string data |
offset | offset into raw data vector |
maxLength | max length in bytes of valid data in bytes vector |
strData | vector in which to place extracted strings. |
References stringBuilderToStrings().
|
inlinestatic |
This method extracts an array of strings from byte array of raw evio string data.
Don't go beyond the specified max character limit and stop at the first non-character value.
bytes | raw evio string data |
length | length in bytes of valid data in bytes vector |
strData | vector in which to place extracted strings. |
References stringBuilderToStrings().
|
inlinestatic |
This method extracts an array of strings from buffer containing raw evio string data.
buffer | buffer containing evio string data |
pos | position of string data in buffer |
length | length of string data in buffer in bytes |
strData | vector in which to place extracted strings. |
References evio::ByteBuffer::array(), evio::ByteBuffer::arrayOffset(), and stringBuilderToStrings().
|
inlinestatic |
This method takes a ByteBuffer and writes its data to a file.
This will overwrite any existing file of the same name.
fileName | file to write to. |
buf | buffer to write into the file. |
EvioException | bad file name or unable to write. |
References evio::ByteBuffer::array(), evio::ByteBuffer::arrayOffset(), evio::ByteBuffer::position(), and evio::ByteBuffer::remaining().