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
26#include <fcntl.h>
27
28using namespace std;
29using namespace Belle2;
30
31//#define DEBUG
32
33//-----------------------------------------------------------------
34// Register the Module
35//-----------------------------------------------------------------
36REG_MODULE(Root2Raw);
37
38//-----------------------------------------------------------------
39// Implementation
40//-----------------------------------------------------------------
41
43{
44 addParam("outputFileName", m_filename, "Output binary filename", string("datafile.binary"));
45 addParam("expno", m_expno, "experiment number for output raw file", 0);
46 addParam("runno", m_runno, "run number for output raw file", 0);
47}
48
49Root2RawModule::~Root2RawModule()
50{
51}
52
54{
55 B2INFO("Root2Raw: initialize() started.");
56
57 m_file = open(m_filename.c_str(), O_CREAT | O_RDWR | O_TRUNC, 0644);
58 if (m_file <= 0) {
59 perror("open");
60 exit(-1);
61 }
62
63 B2INFO("Root2Raw: initialize() done.");
64}
65
67{
68 //fill Run data
69 // fclose( m_fp_out );
70 B2INFO("endRun done.");
71}
72
73
75{
76 close(m_file);
77 B2INFO("terminate called");
78}
79
80
82{
83
84
85 B2INFO("Root2Raw: event() started.");
86
87 // Prepare SendHeader
88 SendHeader hdr;
89 hdr.Initialize();
90 SendTrailer trl;
91 trl.Initialize();
92
93 int* evtbuf = (int*) malloc(MAXEVTSIZE);
94 int* databuf = evtbuf + hdr.GetHdrNwords();
95
96 int nwords = hdr.GetHdrNwords();
97 int nblock = 0;
98
99
100 // Fill PXD
101 /*
102 StoreArray<RawPXD> pxdarray;
103 for (int i = 0; i < pxdarray.getEntries(); i++) {
104 // for ( int i=0; i< 1; i++ ) {
105 RawPXD* pxd = pxdarray[i];
106 // printf ( "SVD COPPER %d to be filled\n", i );
107 memcpy(databuf, pxd->GetBuffer(0), pxd->GetBlockNwords(0)*sizeof(int));
108 nwords += pxd->GetBlockNwords(0);
109 databuf += pxd->GetBlockNwords(0);
110 nblock++;
111 }
112 */
113
114 // Fill SVD
115 StoreArray<RawSVD> svdarray;
116 for (int i = 0; i < svdarray.getEntries(); i++) {
117 // for ( int i=0; i< 1; i++ ) {
118 RawSVD* svd = svdarray[i];
119 // printf ( "SVD COPPER %d to be filled\n", i );
120 memcpy(databuf, svd->GetBuffer(0), svd->GetBlockNwords(0)*sizeof(int));
121 nwords += svd->GetBlockNwords(0);
122 databuf += svd->GetBlockNwords(0);
123 nblock++;
124 }
125
126 // Fill CDC
127 StoreArray<RawCDC> cdcarray;
128 for (int i = 0; i < cdcarray.getEntries(); i++) {
129 // for ( int i=0; i< 1; i++ ) {
130 RawCDC* cdc = cdcarray[i];
131 // printf ( "SVD COPPER %d to be filled\n", i );
132 memcpy(databuf, cdc->GetBuffer(0), cdc->GetBlockNwords(0)*sizeof(int));
133 nwords += cdc->GetBlockNwords(0);
134 databuf += cdc->GetBlockNwords(0);
135 nblock++;
136 }
137
138 // Fill TOP
139 StoreArray<RawTOP> toparray;
140 for (int i = 0; i < toparray.getEntries(); i++) {
141 // for ( int i=0; i< 1; i++ ) {
142 RawTOP* top = toparray[i];
143 // printf ( "SVD COPPER %d to be filled\n", i );
144 memcpy(databuf, top->GetBuffer(0), top->GetBlockNwords(0)*sizeof(int));
145 nwords += top->GetBlockNwords(0);
146 databuf += top->GetBlockNwords(0);
147 nblock++;
148 }
149
150 // Fill ARICH
151 StoreArray<RawARICH> aricharray;
152 for (int i = 0; i < aricharray.getEntries(); i++) {
153 // for ( int i=0; i< 1; i++ ) {
154 RawARICH* arich = aricharray[i];
155 // printf ( "SVD COPPER %d to be filled\n", i );
156 memcpy(databuf, arich->GetBuffer(0), arich->GetBlockNwords(0)*sizeof(int));
157 nwords += arich->GetBlockNwords(0);
158 databuf += arich->GetBlockNwords(0);
159 nblock++;
160 }
161
162 // Fill ECL
163 StoreArray<RawECL> eclarray;
164 for (int i = 0; i < eclarray.getEntries(); i++) {
165 // for ( int i=0; i< 1; i++ ) {
166 RawECL* ecl = eclarray[i];
167 // printf ( "SVD COPPER %d to be filled\n", i );
168 memcpy(databuf, ecl->GetBuffer(0), ecl->GetBlockNwords(0)*sizeof(int));
169 nwords += ecl->GetBlockNwords(0);
170 databuf += ecl->GetBlockNwords(0);
171 nblock++;
172 }
173
174 // Fill KLM
175 StoreArray<RawKLM> klmarray;
176 for (int i = 0; i < klmarray.getEntries(); i++) {
177 // for ( int i=0; i< 1; i++ ) {
178 RawKLM* klm = klmarray[i];
179 // printf ( "SVD COPPER %d to be filled\n", i );
180 memcpy(databuf, klm->GetBuffer(0), klm->GetBlockNwords(0)*sizeof(int));
181 nwords += klm->GetBlockNwords(0);
182 databuf += klm->GetBlockNwords(0);
183 nblock++;
184 }
185
186 // Fill FTSW
187 StoreArray<RawFTSW> ftswarray;
188 for (int i = 0; i < ftswarray.getEntries(); i++) {
189 // for ( int i=0; i< 1; i++ ) {
190 RawFTSW* ftsw = ftswarray[i];
191 // printf ( "SVD COPPER %d to be filled\n", i );
192 memcpy(databuf, ftsw->GetBuffer(0), ftsw->GetBlockNwords(0)*sizeof(int));
193 nwords += ftsw->GetBlockNwords(0);
194 databuf += ftsw->GetBlockNwords(0);
195 nblock++;
196 }
197
198 /*
199 // Fill FTSW
200 StoreArray<RawFTSW> ftswarray;
201 RawFTSW* ftsw = ftswarray[0];
202 memcpy(databuf, ftsw->GetBuffer(0), ftsw->GetBlockNwords(0)*sizeof(int));
203 nwords += ftsw->GetBlockNwords(0);
204 databuf += ftsw->GetBlockNwords(0);
205 nblock++;
206 */
207
208 // skip empty events, mostly discarded from HLT
209 if (svdarray.getEntries() < 1 &&
210 cdcarray.getEntries() < 1 &&
211 toparray.getEntries() < 1 &&
212 aricharray.getEntries() < 1 &&
213 eclarray.getEntries() < 1 &&
214 klmarray.getEntries() < 1) {
215 return;
216 }
217
218 // printf ( "COPPERs filling completed\n" );
219
220 // Fill SendHeader/Trailer
221
222 nwords += trl.GetTrlNwords();
223
224 // printf ( "nwords = %d\n", nwords );
225
226 hdr.SetNwords(nwords);
228 hdr.SetNodeID(0);
229 hdr.SetNumNodesinPacket(nblock);
230
231 RawHeader_v1 rhdr;
232 rhdr.SetBuffer(cdcarray[0]->GetBuffer(0));
233 hdr.SetEventNumber(rhdr.GetEveNo());
234 hdr.SetNodeID(0);
235 hdr.SetExpRunWord(rhdr.GetExpRunSubrun());
236
237 // int* hdrbuf = hdr.GetBuffer();
238 // printf ( "%8.8x %8.8x %8.8x %8.8x ", *hdrbuf, *(hdrbuf+1), *(hdrbuf+2), *(hdrbuf+3) );
239 // printf ( "%8.8x %8.8x %8.8x %8.8x\n", *(hdrbuf+4), *(hdrbuf+5), *(hdrbuf+6), *(hdrbuf+7) );
240
241 // Set exp/rnu number explicitly if there are parameters
242 if (m_expno != 0 && m_runno != 0) {
243 hdr.SetExpNum(m_expno);
244 hdr.SetRunNum(m_runno);
245 }
246
247 memcpy(evtbuf, hdr.GetBuffer(), hdr.GetHdrNwords()*sizeof(int));
248 memcpy(databuf, trl.GetBuffer(), trl.GetTrlNwords()*sizeof(int));
249
250 write(m_file, evtbuf, nwords * sizeof(int));
251 // databuf = evtbuf+ hdr.GetHdrNwords();
252 // int datanwords = nwords - hdr.GetHdrNwords() - trl.GetTrlNwords();
253 // int is = write ( m_file, databuf, datanwords*sizeof(int) );
254 return;
255
256}
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
Definition: RawDataBlock.h:53
virtual int GetBlockNwords(int n)
get size of a data block
Definition: RawDataBlock.h:94
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...
Definition: RawHeader_v1.h:31
void SetBuffer(int *bufin)
set buffer
Definition: RawHeader_v1.h:47
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
Root2RawModule()
Constructor / Destructor.
Definition: Root2Raw.cc:42
void initialize() override
Module functions to be called from main process.
Definition: Root2Raw.cc:53
void event() override
Module functions to be called from event process.
Definition: Root2Raw.cc:81
void endRun() override
This method is called if the current run ends.
Definition: Root2Raw.cc:66
void terminate() override
This method is called at the end of the event processing.
Definition: Root2Raw.cc:74
void SetNumEventsinPacket(int num_events)
set contents of Header
Definition: SendHeader.cc:61
int GetHdrNwords()
get contents of Header
Definition: SendHeader.cc:124
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
Definition: SendTrailer.cc:43
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:560
#define REG_MODULE(moduleName)
Register the given module (without 'Module' suffix) with the framework.
Definition: Module.h:650
unsigned int GetEveNo()
get restart #(8bit)
Definition: RawHeader_v1.h:381
unsigned int GetExpRunSubrun()
get contents of header
Definition: RawHeader_v1.h:374
Abstract base class for different kinds of events.
STL namespace.