Belle II Software  release-08-01-10
MakeDumHSLBData.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/DAQConsts.h>
10 
11 #include <rawdata/dataobjects/RawPXD.h>
12 #include <rawdata/modules/MakeDumHSLBData.h>
13 
14 #include <fcntl.h>
15 #include <sys/stat.h>
16 #include <sys/types.h>
17 #include <unistd.h>
18 
19 
20 using namespace std;
21 using namespace Belle2;
22 
23 //#define DEBUG
24 
25 //-----------------------------------------------------------------
26 // Register the Module
27 //-----------------------------------------------------------------
28 REG_MODULE(MakeDumHSLBData);
29 
30 //-----------------------------------------------------------------
31 // Implementation
32 //-----------------------------------------------------------------
33 
34 MakeDumHSLBDataModule::MakeDumHSLBDataModule() : PrintDataTemplateModule()
35 {
36  addParam("OutputFileName", m_out_fname, "Name of an output file", string("dumhslb.dat"));
37  m_filefd = 0;
38 }
39 
40 MakeDumHSLBDataModule::~MakeDumHSLBDataModule()
41 {
42 }
43 
45 {
46  B2INFO("MakeDumHSLBData: initialize() started.");
47 
48  struct stat statbuf;
49  m_filefd = open(m_out_fname.c_str(), O_WRONLY | O_CREAT);
50  if (m_filefd < 0) {
51  printf("Error : cannot open %s: %s\n", m_out_fname.c_str(), strerror(errno));
52  exit(1);
53  }
54  if (fstat(m_filefd, &statbuf) < 0) {
55  perror("fstat");
56  exit(1);
57  }
58 
59  B2INFO("MakeDumHSLBData: initialize() done.");
60 
61 }
62 
64 {
65  unsigned int eve_num = raw_copper->GetEveNo(i);
66  unsigned int cpr_id = raw_copper->GetNodeID(i);
67  for (int j = 0 ; j < 4; j++) {
68  int nwords = raw_copper->GetDetectorNwords(i, j);
69  if (nwords > 0) {
70  printf("===== Detector Buffer(FINESSE A) 0x%x words \n", raw_copper->GetDetectorNwords(i, 0));
71  int header = 0xCAFEBABE;
72  int len = 0;
73  if ((len = write(m_filefd, &header, sizeof(int))) != sizeof(int)) {
74  perror("write error");
75  exit(1);
76  }
77  if ((len = write(m_filefd, &eve_num, sizeof(int))) != sizeof(int)) {
78  perror("write error");
79  exit(1);
80  }
81  if ((len = write(m_filefd, &cpr_id, sizeof(int))) != sizeof(int)) {
82  perror("write error");
83  exit(1);
84  }
85  if ((len = write(m_filefd, &nwords, sizeof(int))) != sizeof(int)) {
86  perror("write error");
87  exit(1);
88  }
89  write(m_filefd, raw_copper->GetDetectorBuffer(i, 0), sizeof(int)*nwords);
90  printf("hdr 0x%.8x eve %10u cprid 0x%.8x nwrods %d\n", header, eve_num, cpr_id, nwords);
91  }
92  }
93 }
94 
96 {
97 
98 
99  B2INFO("MakeDumHSLBData: event() started.");
100  //
101  // Data from COPPER ( data from any detectors(e.g. CDC, SVD, ... ))
102  //
103  StoreArray<RawCOPPER> rawcprarray;
104  for (int i = 0; i < rawcprarray.getEntries(); i++) {
105  for (int j = 0; j < rawcprarray[ i ]->GetNumEntries(); j++) {
106  printf("\n===== DataBlock(RawCOPPER): Block # %d ", i);
107  writeData(rawcprarray[ i ], j);
108  }
109  }
110 
111  //
112  // Data from COPPER named as RawSVD by software
113  //
114  StoreArray<RawSVD> raw_svdarray;
115  for (int i = 0; i < raw_svdarray.getEntries(); i++) {
116  for (int j = 0; j < raw_svdarray[ i ]->GetNumEntries(); j++) {
117  printf("\n===== DataBlock(RawSVD) : Block # %d ", i);
118  writeData(raw_svdarray[ i ], j);
119  }
120  }
121 
122  //
123  // Data from COPPER named as RawCDC by software
124  //
125  StoreArray<RawCDC> raw_cdcarray;
126  for (int i = 0; i < raw_cdcarray.getEntries(); i++) {
127  for (int j = 0; j < raw_cdcarray[ i ]->GetNumEntries(); j++) {
128  printf("\n===== DataBlock(RawCDC) : Block # %d ", i);
129  writeData(raw_cdcarray[ i ], j);
130  }
131  }
132 
133  //
134  // Data from COPPER named as RawPXD by software
135  //
136  StoreArray<RawPXD> raw_pxdarray;
137  for (int i = 0; i < raw_pxdarray.getEntries(); i++) {
138  printf("\n===== DataBlock(RawPXD) : Block # %d ", i);
139  printPXDEvent(raw_pxdarray[ i ]);
140  }
141 
142  StoreArray<RawTOP> raw_bpidarray;
143  for (int i = 0; i < raw_bpidarray.getEntries(); i++) {
144  for (int j = 0; j < raw_bpidarray[ i ]->GetNumEntries(); j++) {
145  printf("\n===== DataBlock(RawTOP) : Block # %d ", i);
146  writeData(raw_bpidarray[ i ], j);
147  }
148  }
149 
150  StoreArray<RawARICH> raw_epidarray;
151  for (int i = 0; i < raw_epidarray.getEntries(); i++) {
152  for (int j = 0; j < raw_epidarray[ i ]->GetNumEntries(); j++) {
153  printf("\n===== DataBlock(RawARICH) : Block # %d ", i);
154  writeData(raw_epidarray[ i ], j);
155  }
156  }
157 
158  StoreArray<RawKLM> raw_klmarray;
159  for (int i = 0; i < raw_klmarray.getEntries(); i++) {
160  for (int j = 0; j < raw_klmarray[ i ]->GetNumEntries(); j++) {
161  printf("\n===== DataBlock(RawKLM) : Block # %d ", i);
162  writeData(raw_klmarray[ i ], j);
163  }
164  }
165 
166  StoreArray<RawECL> raw_eclarray;
167  for (int i = 0; i < raw_eclarray.getEntries(); i++) {
168  for (int j = 0; j < raw_eclarray[ i ]->GetNumEntries(); j++) {
169  printf("\n===== DataBlock(RawECL) : Block # %d ", i);
170  writeData(raw_eclarray[ i ], j);
171  }
172  }
173 
174  StoreArray<RawTRG> raw_trgarray;
175  for (int i = 0; i < raw_trgarray.getEntries(); i++) {
176  for (int j = 0; j < raw_trgarray[ i ]->GetNumEntries(); j++) {
177  printf("\n===== DataBlock(RawTRG) : Block # %d ", i);
178  writeData(raw_trgarray[ i ], j);
179  }
180  }
181 
182  // printf("loop %d\n", n_basf2evt);
183  n_basf2evt++;
184 
185 }
virtual void initialize() override
initialization
virtual void writeData(RawCOPPER *raw_copper, int i)
write data
virtual void event() override
event module
int m_filefd
File descripter.
std::string m_out_fname
Output file name.
Module to get data from DataStore and send it to another network node.
int n_basf2evt
No. of sent events.
virtual void printPXDEvent(RawPXD *raw_pxd)
print a PXD event
The Raw COPPER class This class stores data received by COPPER via belle2linkt Data from all detector...
Definition: RawCOPPER.h:52
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(int n)
get subrun #(8bit)
Definition: RawCOPPER.h:390
int GetDetectorNwords(int n, int finesse_num)
get Detector buffer length
Definition: RawCOPPER.h:657
int * GetDetectorBuffer(int n, int finesse_num)
get Detector buffer
Definition: RawCOPPER.h:681
unsigned int GetNodeID(int n)
get node-ID from data
Definition: RawCOPPER.h:397
Abstract base class for different kinds of events.