BOSS 7.1.1
BESIII Offline Software System
Loading...
Searching...
No Matches
util.h
Go to the documentation of this file.
1//Dear emacs, this is -*- c++ -*-
2
3/**
4 * @file eformat/util.h
5 * @author <a href="mailto:[email protected]>Andr� Rabello dos
6 * ANJOS</a>
7 * $Author: zhangy $
8 * $Revision: 1.1.1.1 $
9 * $Date: 2009/06/19 07:35:41 $
10 *
11 * @brief Defines a set of utilities common to many event operations.
12 */
13
14#ifndef EFORMAT_UTIL_H
15#define EFORMAT_UTIL_H
16
17#include <fstream>
18#include <stdint.h>
19#include <cstdlib>
22
23namespace eformat {
24
25 /**
26 * This function will read the next fragment in a normal, already opened,
27 * std::fstream. The space for the fragment will be allocated dynamically and
28 * the user should free it. Otherwise, if the user wants to re-use a
29 * pre-allocated memory space, the second and third arguments can be given,
30 * in which case the function will check if the space is enough. If the space
31 * is not enough, NULL is returned.
32 *
33 * @param fs The input filestream
34 * @param addr The optional user allocated space
35 * @param size The optional size, in bytes, of the allocated space
36 */
37 uint32_t* next_fragment (std::fstream& fs, uint32_t* addr=0, size_t size=0);
38
39 /**
40 * Returns pointers (to words) to the start of each ROD fragment block in a
41 * piece of memory. This is primarily intended for LVL2 supervisor usage.
42 *
43 * @warning This will invert the data order, meaning the last ROD will be the
44 * first in the vector to appear, due to the way the ROD readout has to
45 * happen (back to front of the stream). If that is not satisfactory, you
46 * have to sort back the vector yourself.
47 *
48 * @param block_start The start address of the data block you want to dig the
49 * ROD pointers from
50 * @param block_size The size of the block, in 32-bit words
51 * @param rod A (optional) pointer to set of pre-allocated pointers
52 * @param rod_size A (optional) pointer to set of pre-allocated size_t's,
53 * where the size of each ROD, in words, will be stored.
54 * @param max_count The maximum number of blocks to dig out from
55 * <tt>block_start</tt>, if rod is not NULL. If rod is NULL, this is
56 * meaningless.
57 *
58 * @return The number of ROD fragments the function actually found on the
59 * block, irrespective of max_count.
60 */
61 size_t find_rods (const uint32_t* block_start, size_t block_size,
62 const uint32_t** rod=0, uint32_t* rod_size=0,
63 size_t max_count=0);
64
65 /**
66 * A generic method to find all fragments in a contiguous area of
67 * memory. These fragments cannot be RODFragments. For that, use the
68 * eformat::find_rods().
69 *
70 * @param marker The marker you are searching for.
71 * @param block_start A pointer to the block start
72 * @param block_size The overall size of this block, in 32-bit words
73 * @param frag A (optional) preallocated set of pointers to hold the found
74 * fragments. If frag is NULL, only counts the number of children.
75 * @param max_count The maximum number of fragments I'll search for, if frag
76 * is not NULL. If frag is NULL, this flag has no meaning.
77 *
78 * @return The number of fragments the function actually found, irrespective
79 * of max_count.
80 */
81 template <class TPointer>
83 TPointer block_start, size_t block_size,
84 TPointer* frag=0, size_t max_count=0);
85
86 /**
87 * Gets pointers to all ROB fragments from a fragment of a type which is not
88 * known in advance.
89 *
90 * @param fragment The top level fragment to extract the other ROBFragment's
91 * from.
92 * @param rod A pointer to set of pre-allocated pointers
93 * @param max_count The maximum number of blocks to dig out from
94 * <tt>block_start</tt>.
95 *
96 * @return The number of ROBFragments the function actually found
97 */
98 size_t get_robs (const uint32_t* fragment, const uint32_t** rob,
99 size_t max_count);
100
101}
102
103/**
104 * Prints in hexadecimal format, in an ostream
105 */
106#ifndef HEX
107#define HEX(m) "0x" << std::hex << (int)m << std::dec << " (" << (int)m << ")"
108#endif
109
110template <class TPointer>
112 TPointer block_start, size_t block_size,
113 TPointer* frag, size_t max_count)
114{
115 uint32_t counter = 0;
116 TPointer next = block_start;
117 TPointer endp = block_start;
118 endp += block_size;
119 while (next < endp) {
120 if (next[0] != marker) throw EFORMAT_WRONG_MARKER(next[0], marker);
121 if (frag && counter < max_count) frag[counter] = next;
122 ++counter;
123 next += next[1];
124 }
125 return counter;
126}
127
128
129#endif //EFORMAT_UTIL_H
#define fs
Defines the constants used by Event Fragments.
Defines the wrong-marker exception, to be used when the wrong marker is found on the event stream.
#define EFORMAT_WRONG_MARKER(current, expected)
size_t find_fragments(eformat::HeaderMarker marker, TPointer block_start, size_t block_size, TPointer *frag=0, size_t max_count=0)
Definition util.h:111
uint32_t * next_fragment(std::fstream &fs, uint32_t *addr=0, size_t size=0)
Definition util.cxx:24
size_t get_robs(const uint32_t *fragment, const uint32_t **rob, size_t max_count)
Definition util.cxx:107
size_t find_rods(const uint32_t *block_start, size_t block_size, const uint32_t **rod=0, uint32_t *rod_size=0, size_t max_count=0)
Definition util.cxx:86