Belle II Software development
Convert2RawDet.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 <rawdata/modules/Convert2RawDet.h>
10#include <TSystem.h>
11#include <stdlib.h>
12
13// #define DESY
14
15using namespace std;
16using namespace Belle2;
17
18//-----------------------------------------------------------------
19// Register the Module
20//-----------------------------------------------------------------
21REG_MODULE(Convert2RawDet);
22
23//-----------------------------------------------------------------
24// Implementation
25//-----------------------------------------------------------------
26
28{
29 //Set module properties
30 setDescription("convert from RawCOPPER or RawDataBlock to RawDetector objects");
32 m_nevt = 0;
33}
34
35
37{
38}
39
41{
42 gSystem->Load("libdataobjects");
43
44 // Initialize EvtMetaData
45
46 // Initialize Array of RawCOPPER
47 m_rawDataBlock.registerInDataStore();
48 m_rawCOPPER.registerInDataStore();
49 m_rawSVD.registerInDataStore();
50 m_rawCDC.registerInDataStore();
51 m_rawTOP.registerInDataStore();
52 m_rawARICH.registerInDataStore();
53 m_rawECL.registerInDataStore();
54 m_rawKLM.registerInDataStore();
55 m_rawTRG.registerInDataStore();
56 m_rawFTSW.registerInDataStore();
57
58
59 // Read the first event in RingBuffer and restore in DataStore.
60 // This is necessary to create object tables before TTree initialization
61 // if used together with SimpleOutput.
62 // ---- Prefetch the first event
63 // registerRawCOPPERs();
64}
65
66
68{
69 B2INFO("beginRun called.");
70}
71
72
74{
75 // B2INFO("Event " << m_nevt);
76
77 vector<unsigned int> cpr_id;
78
79 //
80 // Check if COPPER ID is duplicated.
81 //
82 StoreArray<RawSVD> raw_svdarray;
83 for (int i = 0; i < raw_svdarray.getEntries(); i++) {
84 for (int j = 0; j < raw_svdarray[ i ]->GetNumEntries(); j++) {
85 cpr_id.push_back(raw_svdarray[ i ]->GetNodeID(j));
86 }
87 }
88
89 StoreArray<RawCDC> raw_cdcarray;
90 for (int i = 0; i < raw_cdcarray.getEntries(); i++) {
91 for (int j = 0; j < raw_cdcarray[ i ]->GetNumEntries(); j++) {
92 cpr_id.push_back(raw_cdcarray[ i ]->GetNodeID(j));
93 }
94 }
95
96 StoreArray<RawTOP> raw_toparray;
97 for (int i = 0; i < raw_toparray.getEntries(); i++) {
98 for (int j = 0; j < raw_toparray[ i ]->GetNumEntries(); j++) {
99 cpr_id.push_back(raw_toparray[ i ]->GetNodeID(j));
100 }
101 }
102
103 StoreArray<RawARICH> raw_aricharray;
104 for (int i = 0; i < raw_aricharray.getEntries(); i++) {
105 for (int j = 0; j < raw_aricharray[ i ]->GetNumEntries(); j++) {
106 cpr_id.push_back(raw_aricharray[ i ]->GetNodeID(j));
107 }
108 }
109
110 StoreArray<RawECL> raw_eclarray;
111 for (int i = 0; i < raw_eclarray.getEntries(); i++) {
112 for (int j = 0; j < raw_eclarray[ i ]->GetNumEntries(); j++) {
113 cpr_id.push_back(raw_eclarray[ i ]->GetNodeID(j));
114 }
115 }
116
117 StoreArray<RawKLM> raw_klmarray;
118 for (int i = 0; i < raw_klmarray.getEntries(); i++) {
119 for (int j = 0; j < raw_klmarray[ i ]->GetNumEntries(); j++) {
120 cpr_id.push_back(raw_klmarray[ i ]->GetNodeID(j));
121 }
122 }
123
124 StoreArray<RawTRG> raw_trgarray;
125 for (int i = 0; i < raw_trgarray.getEntries(); i++) {
126 for (int j = 0; j < raw_trgarray[ i ]->GetNumEntries(); j++) {
127 cpr_id.push_back(raw_trgarray[ i ]->GetNodeID(j));
128 }
129 }
130
131
132 StoreArray<RawDataBlock> raw_datablkarray;
133 for (int i = 0; i < raw_datablkarray.getEntries(); i++) {
134 convertDataObject(raw_datablkarray[ i ], cpr_id);
135 }
136 raw_datablkarray.clear();
137
138 StoreArray<RawCOPPER> raw_cprarray;
139 for (int i = 0; i < raw_cprarray.getEntries(); i++) {
140 convertDataObject((RawDataBlock*)(raw_cprarray[ i ]), cpr_id);
141 }
142 raw_cprarray.clear();
143
144
145 for (unsigned int i = 0; i < cpr_id.size(); i++) {
146 for (unsigned int j = i + 1; j < cpr_id.size(); j++) {
147 // printf("[DEBUG] eve %d i %d 0x%.8x j %d 0x%.8x\n", m_nevt, i, cpr_id[i], j, cpr_id[j] );
148 if (cpr_id[ i ] == cpr_id[ j ]) {
149 B2FATAL("Duplicated COPPER object is found. ID=0x" << hex << cpr_id[ i ] << " Exiting...");
150 }
151 }
152 }
153 m_nevt++;
154
155}
156
157
158void Convert2RawDetModule::convertDataObject(RawDataBlock* raw_dblk, std::vector<unsigned int>& cpr_id)
159{
160 //
161 // Convert RawDataBlock to Raw***
162 //
163
164 int num_eve = raw_dblk->GetNumEvents();
165 if (num_eve != 1) {
166 printf("[FATAL] %s : This module should be used for data with num_eve = 1\n", __PRETTY_FUNCTION__);
167 exit(1);
168 }
169
170 int num_nodes = raw_dblk->GetNumNodes();
171
172
173 // {
174 // int nwords = raw_dblk->TotalBufNwords();
175 // int* temp_buf = new int[ nwords ];
176 // memcpy( temp_buf, raw_dblk->GetWholeBuffer(), nwords*sizeof(int) );
177 // StoreArray<RawCOPPER> ary;
178 // (ary.appendNew())->SetBuffer(temp_buf, nwords, 1, num_eve, num_nodes);
179 // }
180 // return;
181
182 for (int j = 0; j < num_eve; j++) {
183 for (int k = 0; k < num_nodes; k++) {
184 // index of blkidries
185 int blkid = j * num_nodes + k;
186
187 // allocate a new buffer
188 int nwords = raw_dblk->GetBlockNwords(blkid);
189 int* temp_buf = new int[ nwords ];
190 memcpy(temp_buf, raw_dblk->GetBuffer(blkid), nwords * sizeof(int));
191
192
193 // Set buffer to RawCOPPER class to access detector ID
194 RawCOPPER tempcpr;
195 const int temp_num_eve = 1;
196 const int temp_num_nodes = 1;
197 int delete_flag;
198 delete_flag = 0; // this buffer will not be deleted in RawCOPPER destructor.
199 tempcpr.SetBuffer(temp_buf, nwords, delete_flag, temp_num_eve, temp_num_nodes);
200 int subsys_id = tempcpr.GetNodeID(0);
201
202 // store COPPER ID for check
203 cpr_id.push_back((unsigned int)subsys_id);
204
205 delete_flag = 1; // this buffer will be deleted in Raw*** destructor.
206
207
208
209 if ((subsys_id & DETECTOR_MASK) == SVD_ID) {
211 (ary.appendNew())->SetBuffer(temp_buf, nwords, delete_flag, temp_num_eve, temp_num_nodes);
212 } else if ((subsys_id & DETECTOR_MASK) == CDC_ID) {
214 (ary.appendNew())->SetBuffer(temp_buf, nwords, delete_flag, temp_num_eve, temp_num_nodes);
215 } else if ((subsys_id & DETECTOR_MASK) == TOP_ID) {
217 (ary.appendNew())->SetBuffer(temp_buf, nwords, delete_flag, temp_num_eve, temp_num_nodes);
218 } else if ((subsys_id & DETECTOR_MASK) == ARICH_ID) {
220 (ary.appendNew())->SetBuffer(temp_buf, nwords, delete_flag, temp_num_eve, temp_num_nodes);
221 } else if ((subsys_id & DETECTOR_MASK) == BECL_ID) {
223 (ary.appendNew())->SetBuffer(temp_buf, nwords, delete_flag, temp_num_eve, temp_num_nodes);
224 } else if ((subsys_id & DETECTOR_MASK) == EECL_ID) {
226 (ary.appendNew())->SetBuffer(temp_buf, nwords, delete_flag, temp_num_eve, temp_num_nodes);
227 } else if ((subsys_id & DETECTOR_MASK) == BKLM_ID) {
229 (ary.appendNew())->SetBuffer(temp_buf, nwords, delete_flag, temp_num_eve, temp_num_nodes);
230 } else if ((subsys_id & DETECTOR_MASK) == EKLM_ID) {
232 (ary.appendNew())->SetBuffer(temp_buf, nwords, delete_flag, temp_num_eve, temp_num_nodes);
233 } else if (((subsys_id & DETECTOR_MASK) & 0xF0000000) == TRGDATA_ID) {
235 (ary.appendNew())->SetBuffer(temp_buf, nwords, delete_flag, temp_num_eve, temp_num_nodes);
236 } else {
237 printf("[FATAL] Undefined detector ID(0x%.8x). Exiting...\n", subsys_id);
238 exit(1);
239 }
240
241
242
243 }
244 }
245
246
247 return;
248}
249
250
252{
253 //fill Run data
254
255 B2INFO("Convert2RawDet: endRun done.");
256}
257
258
260{
261 B2INFO("Convert2RawDet: terminate called");
262}
263
int m_nevt
No. of sent events.
StoreArray< RawSVD > m_rawSVD
Array for RawCOPPER
virtual void initialize() override
Called at the beginning of data processing.
virtual void event() override
Called for each event.
virtual void endRun() override
Called if the current run ends.
StoreArray< RawFTSW > m_rawFTSW
Array for RawTRG
virtual void terminate() override
Called at the end of data processing.
virtual void convertDataObject(RawDataBlock *raw_dblk, std::vector< unsigned int > &cpr_id)
function to register data buffer in DataStore as RawDetector
StoreArray< RawCOPPER > m_rawCOPPER
Array for RawDataBlock.
StoreArray< RawARICH > m_rawARICH
Array for RawTOP
virtual ~Convert2RawDetModule()
Destructor.
StoreArray< RawTRG > m_rawTRG
Array for RawKLM
virtual void beginRun() override
Called when entering a new run.
StoreArray< RawKLM > m_rawKLM
Array for RawECL
StoreArray< RawTOP > m_rawTOP
Array for RawCDC
StoreArray< RawDataBlock > m_rawDataBlock
Data members.
StoreArray< RawECL > m_rawECL
Array for RawARICH
StoreArray< RawCDC > m_rawCDC
Array for RawSVD
Base class for Modules.
Definition: Module.h:72
void setDescription(const std::string &description)
Sets the description of the module.
Definition: Module.cc:214
void setPropertyFlags(unsigned int propertyFlags)
Sets the flags for the module properties.
Definition: Module.cc:208
@ c_Input
This module is an input module (reads data).
Definition: Module.h:78
The Raw COPPER class This class stores data received by COPPER via belle2linkt Data from all detector...
Definition: RawCOPPER.h:52
void SetBuffer(int *bufin, int nwords, int delete_flag, int num_events, int num_nodes) OVERRIDE_CPP17
set buffer ( delete_flag : m_buffer is freeed( = 0 )/ not freeed( = 1 ) in Destructer )
Definition: RawCOPPER.cc:141
The RawDataBlock class Base class for rawdata handling.
Definition: RawDataBlock.h:27
virtual int * GetBuffer(int n)
get nth buffer pointer
Definition: RawDataBlock.h:53
virtual int GetNumNodes()
get # of data sources(e.g. # of COPPER boards) in m_buffer
Definition: RawDataBlock.h:74
virtual int GetBlockNwords(int n)
get size of a data block
Definition: RawDataBlock.h:94
virtual int GetNumEvents()
get # of events in m_buffer
Definition: RawDataBlock.h:81
Accessor to arrays stored in the data store.
Definition: StoreArray.h:113
T * appendNew()
Construct a new T object at the end of the array.
Definition: StoreArray.h:246
int getEntries() const
Get the number of objects in the array.
Definition: StoreArray.h:216
void clear() override
Delete all entries in this array.
Definition: StoreArray.h:207
#define REG_MODULE(moduleName)
Register the given module (without 'Module' suffix) with the framework.
Definition: Module.h:650
unsigned int GetNodeID(int n)
get node-ID from data
Definition: RawCOPPER.h:397
Abstract base class for different kinds of events.
STL namespace.