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