Belle II Software development
Root2Raw.cc
1/**************************************************************************
2 * basf2 (Belle II Analysis Software Framework) *
3 * Author: The Belle II Collaboration *
4 * *
5 * See git log for contributors and copyright holders. *
6 * This file is licensed under LGPL-3.0, see LICENSE.md. *
7 **************************************************************************/
8
9#include <daq/rawdata/modules/Root2Raw.h>
10
11#include <daq/dataobjects/SendHeader.h>
12#include <daq/dataobjects/SendTrailer.h>
13#include <framework/core/Module.h>
14#include <framework/core/ModuleParamBase.h>
15#include <framework/datastore/StoreArray.h>
16#include <framework/logging/Logger.h>
17#include <rawdata/dataobjects/RawARICH.h>
18#include <rawdata/dataobjects/RawCDC.h>
19#include <rawdata/dataobjects/RawECL.h>
20#include <rawdata/dataobjects/RawFTSW.h>
21#include <rawdata/dataobjects/RawHeader_v1.h>
22#include <rawdata/dataobjects/RawKLM.h>
23#include <rawdata/dataobjects/RawSVD.h>
24#include <rawdata/dataobjects/RawTOP.h>
25#include <rawdata/dataobjects/RawTRG.h>
26
27#include <fcntl.h>
28
29using namespace std;
30using namespace Belle2;
31
32//#define DEBUG
33
34//-----------------------------------------------------------------
35// Register the Module
36//-----------------------------------------------------------------
37REG_MODULE(Root2Raw);
38
39//-----------------------------------------------------------------
40// Implementation
41//-----------------------------------------------------------------
42
44{
45 addParam("outputFileName", m_filename, "Output binary filename", string("datafile.binary"));
46 addParam("expno", m_expno, "experiment number for output raw file", 0);
47 addParam("runno", m_runno, "run number for output raw file", 0);
48}
49
50Root2RawModule::~Root2RawModule()
51{
52}
53
55{
56 B2INFO("Root2Raw: initialize() started.");
57
58 m_file = open(m_filename.c_str(), O_CREAT | O_RDWR | O_TRUNC, 0644);
59 if (m_file <= 0) {
60 perror("open");
61 exit(-1);
62 }
63
64 B2INFO("Root2Raw: initialize() done.");
65}
66
68{
69 //fill Run data
70 // fclose( m_fp_out );
71 B2INFO("endRun done.");
72}
73
74
76{
77 close(m_file);
78 B2INFO("terminate called");
79}
80
81
83{
84
85
86 B2INFO("Root2Raw: event() started.");
87
88 // Prepare SendHeader
89 SendHeader hdr;
90 hdr.Initialize();
91 SendTrailer trl;
92 trl.Initialize();
93
94 int* evtbuf = (int*) malloc(MAXEVTSIZE);
95 int* databuf = evtbuf + hdr.GetHdrNwords();
96
97 int nwords = hdr.GetHdrNwords();
98 int nblock = 0;
99
100
101 // Fill PXD
102 /*
103 StoreArray<RawPXD> pxdarray;
104 for (int i = 0; i < pxdarray.getEntries(); i++) {
105 // for ( int i=0; i< 1; i++ ) {
106 RawPXD* pxd = pxdarray[i];
107 // printf ( "SVD COPPER %d to be filled\n", i );
108 memcpy(databuf, pxd->GetBuffer(0), pxd->GetBlockNwords(0)*sizeof(int));
109 nwords += pxd->GetBlockNwords(0);
110 databuf += pxd->GetBlockNwords(0);
111 nblock++;
112 }
113 */
114
115 // Fill SVD
116 StoreArray<RawSVD> svdarray;
117 for (int i = 0; i < svdarray.getEntries(); i++) {
118 // for ( int i=0; i< 1; i++ ) {
119 RawSVD* svd = svdarray[i];
120 // printf ( "SVD COPPER %d to be filled\n", i );
121 memcpy(databuf, svd->GetBuffer(0), svd->GetBlockNwords(0)*sizeof(int));
122 nwords += svd->GetBlockNwords(0);
123 databuf += svd->GetBlockNwords(0);
124 nblock++;
125 }
126
127 // Fill CDC
128 StoreArray<RawCDC> cdcarray;
129 for (int i = 0; i < cdcarray.getEntries(); i++) {
130 // for ( int i=0; i< 1; i++ ) {
131 RawCDC* cdc = cdcarray[i];
132 // printf ( "SVD COPPER %d to be filled\n", i );
133 memcpy(databuf, cdc->GetBuffer(0), cdc->GetBlockNwords(0)*sizeof(int));
134 nwords += cdc->GetBlockNwords(0);
135 databuf += cdc->GetBlockNwords(0);
136 nblock++;
137 }
138
139 // Fill TOP
140 StoreArray<RawTOP> toparray;
141 for (int i = 0; i < toparray.getEntries(); i++) {
142 // for ( int i=0; i< 1; i++ ) {
143 RawTOP* top = toparray[i];
144 // printf ( "SVD COPPER %d to be filled\n", i );
145 memcpy(databuf, top->GetBuffer(0), top->GetBlockNwords(0)*sizeof(int));
146 nwords += top->GetBlockNwords(0);
147 databuf += top->GetBlockNwords(0);
148 nblock++;
149 }
150
151 // Fill ARICH
152 StoreArray<RawARICH> aricharray;
153 for (int i = 0; i < aricharray.getEntries(); i++) {
154 // for ( int i=0; i< 1; i++ ) {
155 RawARICH* arich = aricharray[i];
156 // printf ( "SVD COPPER %d to be filled\n", i );
157 memcpy(databuf, arich->GetBuffer(0), arich->GetBlockNwords(0)*sizeof(int));
158 nwords += arich->GetBlockNwords(0);
159 databuf += arich->GetBlockNwords(0);
160 nblock++;
161 }
162
163 // Fill ECL
164 StoreArray<RawECL> eclarray;
165 for (int i = 0; i < eclarray.getEntries(); i++) {
166 // for ( int i=0; i< 1; i++ ) {
167 RawECL* ecl = eclarray[i];
168 // printf ( "SVD COPPER %d to be filled\n", i );
169 memcpy(databuf, ecl->GetBuffer(0), ecl->GetBlockNwords(0)*sizeof(int));
170 nwords += ecl->GetBlockNwords(0);
171 databuf += ecl->GetBlockNwords(0);
172 nblock++;
173 }
174
175 // Fill KLM
176 StoreArray<RawKLM> klmarray;
177 for (int i = 0; i < klmarray.getEntries(); i++) {
178 // for ( int i=0; i< 1; i++ ) {
179 RawKLM* klm = klmarray[i];
180 // printf ( "SVD COPPER %d to be filled\n", i );
181 memcpy(databuf, klm->GetBuffer(0), klm->GetBlockNwords(0)*sizeof(int));
182 nwords += klm->GetBlockNwords(0);
183 databuf += klm->GetBlockNwords(0);
184 nblock++;
185 }
186
187 // Fill TRG
188 StoreArray<RawTRG> trgarray;
189 for (int i = 0; i < trgarray.getEntries(); i++) {
190 // for ( int i=0; i< 1; i++ ) {
191 RawTRG* trg = trgarray[i];
192 // printf ( "SVD COPPER %d to be filled\n", i );
193 memcpy(databuf, trg->GetBuffer(0), trg->GetBlockNwords(0)*sizeof(int));
194 nwords += trg->GetBlockNwords(0);
195 databuf += trg->GetBlockNwords(0);
196 nblock++;
197 }
198
199 // Fill FTSW
200 StoreArray<RawFTSW> ftswarray;
201 for (int i = 0; i < ftswarray.getEntries(); i++) {
202 // for ( int i=0; i< 1; i++ ) {
203 RawFTSW* ftsw = ftswarray[i];
204 // printf ( "SVD COPPER %d to be filled\n", i );
205 memcpy(databuf, ftsw->GetBuffer(0), ftsw->GetBlockNwords(0)*sizeof(int));
206 nwords += ftsw->GetBlockNwords(0);
207 databuf += ftsw->GetBlockNwords(0);
208 nblock++;
209 }
210
211 /*
212 // Fill FTSW
213 StoreArray<RawFTSW> ftswarray;
214 RawFTSW* ftsw = ftswarray[0];
215 memcpy(databuf, ftsw->GetBuffer(0), ftsw->GetBlockNwords(0)*sizeof(int));
216 nwords += ftsw->GetBlockNwords(0);
217 databuf += ftsw->GetBlockNwords(0);
218 nblock++;
219 */
220
221 // skip empty events, mostly discarded from HLT
222 if (svdarray.getEntries() < 1 &&
223 cdcarray.getEntries() < 1 &&
224 toparray.getEntries() < 1 &&
225 aricharray.getEntries() < 1 &&
226 eclarray.getEntries() < 1 &&
227 klmarray.getEntries() < 1 &&
228 trgarray.getEntries() < 1) {
229 return;
230 }
231
232 // printf ( "COPPERs filling completed\n" );
233
234 // Fill SendHeader/Trailer
235
236 nwords += trl.GetTrlNwords();
237
238 // printf ( "nwords = %d\n", nwords );
239
240 hdr.SetNwords(nwords);
242 hdr.SetNodeID(0);
243 hdr.SetNumNodesinPacket(nblock);
244
245 RawHeader_v1 rhdr;
246 rhdr.SetBuffer(cdcarray[0]->GetBuffer(0));
247 hdr.SetEventNumber(rhdr.GetEveNo());
248 hdr.SetNodeID(0);
249 hdr.SetExpRunWord(rhdr.GetExpRunSubrun());
250
251 // int* hdrbuf = hdr.GetBuffer();
252 // printf ( "%8.8x %8.8x %8.8x %8.8x ", *hdrbuf, *(hdrbuf+1), *(hdrbuf+2), *(hdrbuf+3) );
253 // printf ( "%8.8x %8.8x %8.8x %8.8x\n", *(hdrbuf+4), *(hdrbuf+5), *(hdrbuf+6), *(hdrbuf+7) );
254
255 // Set exp/rnu number explicitly if there are parameters
256 if (m_expno != 0 && m_runno != 0) {
257 hdr.SetExpNum(m_expno);
258 hdr.SetRunNum(m_runno);
259 }
260
261 memcpy(evtbuf, hdr.GetBuffer(), hdr.GetHdrNwords()*sizeof(int));
262 memcpy(databuf, trl.GetBuffer(), trl.GetTrlNwords()*sizeof(int));
263
264 write(m_file, evtbuf, nwords * sizeof(int));
265 // databuf = evtbuf+ hdr.GetHdrNwords();
266 // int datanwords = nwords - hdr.GetHdrNwords() - trl.GetTrlNwords();
267 // int is = write ( m_file, databuf, datanwords*sizeof(int) );
268 return;
269
270}
The Raw ARICH class Class for RawCOPPER class data taken by ARICH Currently, this class is almost sam...
Definition RawARICH.h:27
The Raw CDC class Class for RawCOPPER class data taken by CDC Currently, this class is almost same as...
Definition RawCDC.h:27
virtual int * GetBuffer(int n)
get nth buffer pointer
virtual int GetBlockNwords(int n)
get size of a data block
The Raw ECL class Class for RawCOPPER class data taken by ECL Currently, this class is almost same as...
Definition RawECL.h:26
The Raw FTSW class.
Definition RawFTSW.h:30
The Raw Header class ver.1 ( the latest version since May, 2014 ) This class defines the format of th...
void SetBuffer(int *bufin)
set buffer
The Raw KLM class Class for RawCOPPER class data taken by KLM.
Definition RawKLM.h:27
The Raw SVD class Class for RawCOPPER class data taken by SVD Currently, this class is almost same as...
Definition RawSVD.h:26
The Raw TOP class Class for RawCOPPER class data taken by TOP Currently, this class is almost same as...
Definition RawTOP.h:27
The Raw TOP class Class for RawCOPPER class data taken by TOP Currently, this class is almost same as...
Definition RawTRG.h:27
Root2RawModule()
Constructor / Destructor.
Definition Root2Raw.cc:43
void initialize() override
Module functions to be called from main process.
Definition Root2Raw.cc:54
void event() override
Module functions to be called from event process.
Definition Root2Raw.cc:82
void endRun() override
This method is called if the current run ends.
Definition Root2Raw.cc:67
void terminate() override
This method is called at the end of the event processing.
Definition Root2Raw.cc:75
void SetNumEventsinPacket(int num_events)
set contents of Header
Definition SendHeader.cc:61
int GetHdrNwords()
get contents of Header
void SetNwords(int total_data_nwords)
initialize Header
Definition SendHeader.cc:51
int * GetBuffer(void)
Get Header contents.
Definition SendHeader.cc:32
void Initialize()
set buffer
Accessor to arrays stored in the data store.
Definition StoreArray.h:113
int getEntries() const
Get the number of objects in the array.
Definition StoreArray.h:216
void addParam(const std::string &name, T &paramVariable, const std::string &description, const T &defaultValue)
Adds a new parameter to the module.
Definition Module.h:559
#define REG_MODULE(moduleName)
Register the given module (without 'Module' suffix) with the framework.
Definition Module.h:649
unsigned int GetEveNo()
get restart #(8bit)
unsigned int GetExpRunSubrun()
get contents of header
Abstract base class for different kinds of events.
STL namespace.