BOSS 7.1.2
BESIII Offline Software System
Loading...
Searching...
No Matches
util.cxx
Go to the documentation of this file.
1//Dear emacs, this is -*- c++ -*-
2
3/**
4 * @file util.cxx
5 * @author <a href="mailto:[email protected]>Andr� Rabello dos
6 * ANJOS</a>
7 * $Author: maqm $
8 * $Revision: 1.2 $
9 * $Date: 2022/01/06 21:15:37 $
10 *
11 * @brief Implements a set of utilities common to many event operations.
12 */
13
14#include "eformat/util.h"
15#include "eformat/ROBFragment.h"
16#include "eformat/ROSFragment.h"
19#include "ers/StreamFactory.h"
21
22using namespace eformat;
23
24uint32_t* eformat::next_fragment (std::fstream& fs, uint32_t* addr,
25 size_t size)
26{
27 using namespace eformat;
28
29 off_t offset = fs.tellg();
30 ERS_DEBUG_3("Current stream position is 0x%lx", offset);
31
32 uint32_t data[2];
33 if (fs && fs.good() && ! fs.eof()) {
34 //soft check, so we don't make mistakes
35 fs.read((char*)data, 8);
36 if (!fs.good() || fs.eof()) return 0; // end-of-file
37 switch((HeaderMarker)data[0]) {
38 case FULL_EVENT:
39 case SUB_DETECTOR:
40 case ROS:
41 case ROB:
42 case ROD:
43 break;
44 default:
45 //stop!
46 std::cout << "Word at offset " << HEX(offset) << " is not one of "
47 << HEX(FULL_EVENT) << ", "
48 << HEX(SUB_DETECTOR) << ", "
49 << HEX(ROS) << ", "
50 << HEX(ROB) << "or "
51 << HEX(ROS) << ". Stopping execution..." << std::endl;
52 return 0;
53 }
54 }
55 else return 0; //file is over
56
57 //data[1] is the fragment size, in words. Take it and read the fragment
58 ERS_DEBUG_3("Resetting stream position to 0x%lx...", offset);
59 fs.seekg(offset);
60 if (addr && (size >= (data[1]*4))) {
61 //space is preallocated and checked
62 ERS_DEBUG_3("Reading fragment data...");
63 fs.read((char*)addr, data[1]*4);
64 ERS_DEBUG_2("Size of fragment readout is %u bytes", 4*data[1]);
65 ERS_DEBUG_3("Stream position is 0x%lx", offset = fs.tellg());
66 return addr;
67 }
68 else if (addr) {
69 std::cout << "The fragment at offset " << HEX(offset) << " has "
70 << data[1]*4 << " bytes and you provided only "
71 << size << " bytes in your buffer. Stopping execution..."
72 << std::endl;
73 return 0;
74 }
75
76 //if I get here, is because I have to allocate space myself
77 ERS_DEBUG_3("Allocating fragment data storage of size %ud bytes", 4*data[1]);
78 uint32_t* retval = new uint32_t[data[1]];
79 ERS_DEBUG_3("Reading fragment data...");
80 fs.read((char*)retval, data[1]*4);
81 ERS_DEBUG_2("Size of fragment readout is %u bytes", 4*data[1]);
82 ERS_DEBUG_3("Stream position is 0x%lx", offset = fs.tellg());
83 return retval;
84}
85
86size_t eformat::find_rods (const uint32_t* block_start, size_t block_size,
87 const uint32_t** rod, uint32_t* rod_size,
88 size_t max_count)
89{
90 const uint32_t* block_end = block_start + block_size;
91 size_t counter = 0;
92 while (block_end > block_start) {
93 uint32_t curr_rod_size = 12; //< base size for a ROD as eformat 2.4
94 curr_rod_size += *(block_end-3) + *(block_end-2); //status and data sizes
95 block_end -= curr_rod_size;
96 if (rod && counter < max_count) {
97 if (block_end[0] != eformat::ROD)
98 throw EFORMAT_WRONG_MARKER(block_end[0], eformat::ROD);
99 rod_size[counter] = curr_rod_size;
100 rod[counter] = block_end;
101 }
102 ++counter;
103 }
104 return counter;
105}
106
107size_t eformat::get_robs (const uint32_t* fragment, const uint32_t** rob,
108 size_t max_count)
109{
110 using namespace eformat;
111 ERS_DEBUG_1("Getting all ROB's from 0x%x...", fragment[0]);
112
113 size_t counter = 0;
114 switch ((eformat::HeaderMarker)(fragment[0])) {
115 case ROD:
116 return 0;
117 case ROB:
118 {
119 if ( max_count > 0 ) {
120 rob[0] = fragment;
121 ++counter;
122 }
123 else return 0; //not enough space
124 }
125 break;
126 case ROS:
127 {
129 counter += ros.children(rob, max_count);
130 ERS_DEBUG_1("ROS 0x%x contains %d ROB's", ros.source_id(), counter);
131 }
132 break;
133 case SUB_DETECTOR:
134 {
136 const uint32_t* ros[256];
137 size_t ros_counter = sd.children(ros, 256);
138 for (size_t i=0; i<ros_counter; ++i)
139 counter += get_robs(ros[i], &rob[counter], max_count - counter);
140 ERS_DEBUG_1("Subdetector 0x%x contains %d ROB's", sd.source_id(),
141 counter);
142 }
143 break;
144 case FULL_EVENT:
145 {
147 const uint32_t* sd[64];
148 size_t sd_counter = fe.children(sd, 64);
149 for (size_t i=0; i<sd_counter; ++i)
150 counter += get_robs(sd[i], &rob[counter], max_count - counter);
151 ERS_DEBUG_1("Fullevent 0x%x contains %d ROB's", fe.source_id(), counter);
152 }
153 break;
154 }
155
156 return counter;
157}
#define fs
TTree * data
Defines the Event Fragment entity. The definition is based on the update of ATL-DAQ-98-129,...
Defines the ROB fragment entity as described in the Event Format note.
Describes the ROS fragment as defined in the Event Format note.
#define ERS_DEBUG_1(...)
#define ERS_DEBUG_3(...)
#define ERS_DEBUG_2(...)
Defines the subdetector fragment entity. The definition is based on the update of ATL-DAQ-98-129,...
Defines the wrong-marker exception, to be used when the wrong marker is found on the event stream.
#define EFORMAT_WRONG_MARKER(current, expected)
virtual uint32_t children(TPointer *p, size_t max) const
Definition Header.h:293
uint32_t source_id() const
Definition Header.h:116
@ SUB_DETECTOR
The SubDet. marker.
@ ROB
The ROB marker.
@ ROD
The ROD marker.
@ ROS
The ROS marker.
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
Defines a set of utilities common to many event operations.
#define HEX(m)
Definition util.h:107