Belle II Software  release-06-00-14
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 
28 using namespace std;
29 using namespace Belle2;
30 
31 //#define DEBUG
32 
33 //-----------------------------------------------------------------
34 // Register the Module
35 //-----------------------------------------------------------------
36 REG_MODULE(Root2Raw)
37 
38 //-----------------------------------------------------------------
39 // Implementation
40 //-----------------------------------------------------------------
41 
43 {
44  addParam("outputFileName", m_filename, "Output binary filename", string("datafile.binary"));
45 }
46 
47 Root2RawModule::~Root2RawModule()
48 {
49 }
50 
51 void Root2RawModule::initialize()
52 {
53  B2INFO("Root2Raw: initialize() started.");
54 
55  m_file = open(m_filename.c_str(), O_CREAT | O_RDWR | O_TRUNC, 0644);
56  if (m_file <= 0) {
57  perror("open");
58  exit(-1);
59  }
60 
61  B2INFO("Root2Raw: initialize() done.");
62 }
63 
64 void Root2RawModule::endRun()
65 {
66  //fill Run data
67  // fclose( m_fp_out );
68  B2INFO("endRun done.");
69 }
70 
71 
72 void Root2RawModule::terminate()
73 {
74  close(m_file);
75  B2INFO("terminate called");
76 }
77 
78 
79 void Root2RawModule::event()
80 {
81 
82 
83  B2INFO("Root2Raw: event() started.");
84 
85  // Prepare SendHeader
86  SendHeader hdr;
87  hdr.Initialize();
88  SendTrailer trl;
89  trl.Initialize();
90 
91  int* evtbuf = (int*) malloc(MAXEVTSIZE);
92  int* databuf = evtbuf + hdr.GetHdrNwords();
93 
94  int nwords = hdr.GetHdrNwords();
95  int nblock = 0;
96 
97 
98  // Fill PXD
99  /*
100  StoreArray<RawPXD> pxdarray;
101  for (int i = 0; i < pxdarray.getEntries(); i++) {
102  // for ( int i=0; i< 1; i++ ) {
103  RawPXD* pxd = pxdarray[i];
104  // printf ( "SVD COPPER %d to be filled\n", i );
105  memcpy(databuf, pxd->GetBuffer(0), pxd->GetBlockNwords(0)*sizeof(int));
106  nwords += pxd->GetBlockNwords(0);
107  databuf += pxd->GetBlockNwords(0);
108  nblock++;
109  }
110  */
111 
112  // Fill SVD
113  StoreArray<RawSVD> svdarray;
114  for (int i = 0; i < svdarray.getEntries(); i++) {
115  // for ( int i=0; i< 1; i++ ) {
116  RawSVD* svd = svdarray[i];
117  // printf ( "SVD COPPER %d to be filled\n", i );
118  memcpy(databuf, svd->GetBuffer(0), svd->GetBlockNwords(0)*sizeof(int));
119  nwords += svd->GetBlockNwords(0);
120  databuf += svd->GetBlockNwords(0);
121  nblock++;
122  }
123 
124  // Fill CDC
125  StoreArray<RawCDC> cdcarray;
126  for (int i = 0; i < cdcarray.getEntries(); i++) {
127  // for ( int i=0; i< 1; i++ ) {
128  RawCDC* cdc = cdcarray[i];
129  // printf ( "SVD COPPER %d to be filled\n", i );
130  memcpy(databuf, cdc->GetBuffer(0), cdc->GetBlockNwords(0)*sizeof(int));
131  nwords += cdc->GetBlockNwords(0);
132  databuf += cdc->GetBlockNwords(0);
133  nblock++;
134  }
135 
136  // Fill TOP
137  StoreArray<RawTOP> toparray;
138  for (int i = 0; i < toparray.getEntries(); i++) {
139  // for ( int i=0; i< 1; i++ ) {
140  RawTOP* top = toparray[i];
141  // printf ( "SVD COPPER %d to be filled\n", i );
142  memcpy(databuf, top->GetBuffer(0), top->GetBlockNwords(0)*sizeof(int));
143  nwords += top->GetBlockNwords(0);
144  databuf += top->GetBlockNwords(0);
145  nblock++;
146  }
147 
148  // Fill ARICH
149  StoreArray<RawARICH> aricharray;
150  for (int i = 0; i < aricharray.getEntries(); i++) {
151  // for ( int i=0; i< 1; i++ ) {
152  RawARICH* arich = aricharray[i];
153  // printf ( "SVD COPPER %d to be filled\n", i );
154  memcpy(databuf, arich->GetBuffer(0), arich->GetBlockNwords(0)*sizeof(int));
155  nwords += arich->GetBlockNwords(0);
156  databuf += arich->GetBlockNwords(0);
157  nblock++;
158  }
159 
160  // Fill ECL
161  StoreArray<RawECL> eclarray;
162  for (int i = 0; i < eclarray.getEntries(); i++) {
163  // for ( int i=0; i< 1; i++ ) {
164  RawECL* ecl = eclarray[i];
165  // printf ( "SVD COPPER %d to be filled\n", i );
166  memcpy(databuf, ecl->GetBuffer(0), ecl->GetBlockNwords(0)*sizeof(int));
167  nwords += ecl->GetBlockNwords(0);
168  databuf += ecl->GetBlockNwords(0);
169  nblock++;
170  }
171 
172  // Fill KLM
173  StoreArray<RawKLM> klmarray;
174  for (int i = 0; i < klmarray.getEntries(); i++) {
175  // for ( int i=0; i< 1; i++ ) {
176  RawKLM* klm = klmarray[i];
177  // printf ( "SVD COPPER %d to be filled\n", i );
178  memcpy(databuf, klm->GetBuffer(0), klm->GetBlockNwords(0)*sizeof(int));
179  nwords += klm->GetBlockNwords(0);
180  databuf += klm->GetBlockNwords(0);
181  nblock++;
182  }
183 
184  // Fill FTSW
185  StoreArray<RawFTSW> ftswarray;
186  for (int i = 0; i < ftswarray.getEntries(); i++) {
187  // for ( int i=0; i< 1; i++ ) {
188  RawFTSW* ftsw = ftswarray[i];
189  // printf ( "SVD COPPER %d to be filled\n", i );
190  memcpy(databuf, ftsw->GetBuffer(0), ftsw->GetBlockNwords(0)*sizeof(int));
191  nwords += ftsw->GetBlockNwords(0);
192  databuf += ftsw->GetBlockNwords(0);
193  nblock++;
194  }
195 
196  /*
197  // Fill FTSW
198  StoreArray<RawFTSW> ftswarray;
199  RawFTSW* ftsw = ftswarray[0];
200  memcpy(databuf, ftsw->GetBuffer(0), ftsw->GetBlockNwords(0)*sizeof(int));
201  nwords += ftsw->GetBlockNwords(0);
202  databuf += ftsw->GetBlockNwords(0);
203  nblock++;
204  */
205 
206 
207  // printf ( "COPPERs filling completed\n" );
208 
209  // Fill SendHeader/Trailer
210 
211  nwords += trl.GetTrlNwords();
212 
213  // printf ( "nwords = %d\n", nwords );
214 
215  hdr.SetNwords(nwords);
216  hdr.SetNumEventsinPacket(1);
217  hdr.SetNodeID(0);
218  hdr.SetNumNodesinPacket(nblock);
219 
220  RawHeader_v1 rhdr;
221  rhdr.SetBuffer(cdcarray[0]->GetBuffer(0));
222  hdr.SetEventNumber(rhdr.GetEveNo());
223  hdr.SetNodeID(0);
224  hdr.SetExpRunWord(rhdr.GetExpRunSubrun());
225 
226  int* hdrbuf = hdr.GetBuffer();
227  // printf ( "%8.8x %8.8x %8.8x %8.8x ", *hdrbuf, *(hdrbuf+1), *(hdrbuf+2), *(hdrbuf+3) );
228  // printf ( "%8.8x %8.8x %8.8x %8.8x\n", *(hdrbuf+4), *(hdrbuf+5), *(hdrbuf+6), *(hdrbuf+7) );
229 
230 
231  memcpy(evtbuf, hdr.GetBuffer(), hdr.GetHdrNwords()*sizeof(int));
232  memcpy(databuf, trl.GetBuffer(), trl.GetTrlNwords()*sizeof(int));
233 
234  int is = write(m_file, evtbuf, nwords * sizeof(int));
235  // databuf = evtbuf+ hdr.GetHdrNwords();
236  // int datanwords = nwords - hdr.GetHdrNwords() - trl.GetTrlNwords();
237  // int is = write ( m_file, databuf, datanwords*sizeof(int) );
238  return;
239 
240 }
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
A class definition of an input module for Sequential ROOT I/O.
Definition: Root2Raw.h:25
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
#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.