public final class Utilities
extends java.lang.Object
Constructor and Description |
---|
Utilities() |
Modifier and Type | Method and Description |
---|---|
static void |
bufferToFile(java.lang.String fileName,
java.nio.ByteBuffer buf,
boolean overWriteOK,
boolean addBlockHeader)
This method takes a byte buffer and saves it to the specified file,
overwriting whatever is there.
|
static int |
generateBaseFileName(java.lang.String baseName,
java.lang.String runType,
java.lang.StringBuilder newNameBuilder)
Deprecated.
This method is being replace by a newer version
generateBaseFileNameNew(String, String, StringBuilder)
which returns additional information. |
static int[] |
generateBaseFileNameNew(java.lang.String baseName,
java.lang.String runType,
java.lang.StringBuilder newNameBuilder)
This method generates part of a file name given a base file name as an argument.
|
static java.lang.String |
generateFileName(java.lang.String fileName,
int specifierCount,
int runNumber,
long split,
int splitNumber,
int streamId,
int streamCount)
This method generates a complete file name from the previously determined baseFileName
obtained from calling
generateBaseFileName(String, String, StringBuilder) . |
static DataType |
getDataType(java.lang.String type)
This method returns an XML element name given an evio data type.
|
static EvioEvent |
nodeToEvent(EvioNode node)
This method takes an EvioNode object and converts it to an EvioEvent object.
|
static void |
printBuffer(java.nio.ByteBuffer buf,
int position,
int words,
java.lang.String label)
This method takes a byte buffer and prints out the desired number of words
from the given position.
|
static void |
printBufferBytes(java.nio.ByteBuffer buf,
int position,
int bytes,
java.lang.String label)
This method takes a byte buffer and prints out the desired number of bytes
from the given position.
|
static java.util.List<EvioEvent> |
toEvents(java.lang.String xmlString)
This method takes a string representation of evio events
(each starting with lt; event gt;)
and converts them to a list of EvioEvent objects.
|
static java.util.List<EvioEvent> |
toEvents(java.lang.String xmlString,
int maxEvents,
int skip,
EvioXMLDictionary dictionary,
boolean debug)
This method takes a string representation of evio events
(each starting with lt; event gt;)
and converts them to a list of EvioEvent objects.
|
static java.lang.String |
toXML(EvioNode node,
boolean hex)
This method takes an EvioNode object and converts it to a readable, XML String.
|
@Deprecated public static int generateBaseFileName(java.lang.String baseName, java.lang.String runType, java.lang.StringBuilder newNameBuilder) throws EvioException
generateBaseFileNameNew(String, String, StringBuilder)
which returns additional information.
The base file name may contain up to 2, C-style integer format specifiers
(such as %03d, or %x). If more than 2 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(String, int, int, long, int, int, int)
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.
The base file name may contain characters of the form $(ENV_VAR) 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 withrunType
- run type/configuration namenewNameBuilder
- object which contains generated base file nameEvioException
- if baseName arg is improperly formatted;
if baseName or newNameBuilder arg is nullpublic static int[] generateBaseFileNameNew(java.lang.String baseName, java.lang.String runType, java.lang.StringBuilder newNameBuilder) throws EvioException
The base file name may contain up to 2, C-style integer format specifiers
(such as %03d, or %x). If more than 2 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(String, int, int, long, int, int, int)
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.
The base file name may contain characters of the form $(ENV_VAR) 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 withrunType
- run type/configuration namenewNameBuilder
- object which contains generated base file nameEvioException
- if baseName arg is improperly formatted;
if baseName or newNameBuilder arg is nullpublic static java.lang.String generateFileName(java.lang.String fileName, int specifierCount, int runNumber, long split, int splitNumber, int streamId, int streamCount) throws java.util.IllegalFormatException
generateBaseFileName(String, String, StringBuilder)
.
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. This is because an error would be thrown in the String.format() method.
fileName
- file name to use as a basis for the generated file namespecifierCount
- number of C-style int format specifiers in baseFileName argrunNumber
- CODA run numbersplit
- number of bytes at which to split off evio filesplitNumber
- number of the split filestreamId
- number of the stream idstreamCount
- total number of streamsjava.util.IllegalFormatException
- if the baseFileName arg contains printing format
specifiers which are not compatible with integers
and interfere with formattingpublic static void bufferToFile(java.lang.String fileName, java.nio.ByteBuffer buf, boolean overWriteOK, boolean addBlockHeader) throws java.io.IOException, EvioException
fileName
- name of file to writebuf
- buffer to write to fileoverWriteOK
- if true
, OK to overwrite previously existing fileaddBlockHeader
- if true
, add evio block header for proper evio file formatjava.io.IOException
- if trouble writing to fileEvioException
- if file exists but overwriting is not permitted;
if null arg(s)public static void printBuffer(java.nio.ByteBuffer buf, int position, int words, java.lang.String label)
buf
- buffer to print outposition
- position of data (bytes) in buffer to start printingwords
- number of 32 bit words to print in hexlabel
- a label to print as headerpublic static void printBufferBytes(java.nio.ByteBuffer buf, int position, int bytes, java.lang.String label)
buf
- buffer to print outposition
- position of data (bytes) in buffer to start printingbytes
- number of bytes to print in hexlabel
- a label to print as headerpublic static EvioEvent nodeToEvent(EvioNode node) throws EvioException
node
- EvioNode object to EvioEventEvioException
- if node is not a bank or cannot parse node's bufferpublic static java.util.List<EvioEvent> toEvents(java.lang.String xmlString) throws EvioException
xmlString
- xml format string to parseEvioException
- if xml is not in proper formatpublic static java.util.List<EvioEvent> toEvents(java.lang.String xmlString, int maxEvents, int skip, EvioXMLDictionary dictionary, boolean debug) throws EvioException
xmlString
- xml format string to parsemaxEvents
- max number of events to returnskip
- number of events to initially skip overdictionary
- dictionary objectdebug
- true for debug outputEvioException
- if xml is not in proper formatpublic static DataType getDataType(java.lang.String type)
type
- evio data typepublic static java.lang.String toXML(EvioNode node, boolean hex) throws EvioException
node
- EvioNode object to print outhex
- if true, ints get displayed in hexadecimalEvioException
- if node is not a bank or cannot parse node's buffer