9 #include <cdc/modules/cdcPacker/CDCPackerModule.h>
10 #include <cdc/modules/cdcPacker/CDCChannelData.h>
11 #include <cdc/dbobjects/CDCChannelMap.h>
13 #include <framework/logging/Logger.h>
14 #include <framework/utilities/FileSystem.h>
16 #include <framework/database/DBArray.h>
25 #define NUM_CDC_COPPER 75
38 setDescription(
"Generate RawCDC object from CDCHit");
39 setPropertyFlags(c_ParallelProcessingCertified);
41 addParam(
"rawCDCName", m_rawCDCName,
"Name of the RawCDC List name..",
string(
""));
42 addParam(
"cdcRawHitName", m_cdcRawHitName,
"Name of the CDCRawHit (Suppressed mode).",
string(
""));
43 addParam(
"cdcHitName", m_cdcHitName,
"Name of the CDCHit List name..",
string(
""));
44 addParam(
"fadcThreshold", m_fadcThreshold,
"Threshold voltage (mV).", 10);
45 addParam(
"xmlMapFileName", m_xmlMapFileName,
"path+name of the xml file",
46 string(
"/cdc/data/ch_map.dat"));
47 addParam(
"enableStoreRawCDC", m_enableStoreCDCRawHit,
"Enable to store to the RawCDC object",
true);
48 addParam(
"enablePrintOut", m_enablePrintOut,
"Enable to print out the data to the terminal",
true);
49 addParam(
"enableDatabase", m_enableDatabase,
"Enable database to read the channel map.",
true);
51 m_channelMapFromDB.addCallback(
this, &CDCPackerModule::loadMap);
54 CDCPackerModule::~CDCPackerModule()
58 void CDCPackerModule::initialize()
61 B2INFO(
"CDCPacker: initialize() Called.");
63 m_rawCDCs.registerInDataStore(m_rawCDCName);
64 m_CDCRawHits.registerInDataStore(m_cdcRawHitName);
65 m_CDCHits.registerInDataStore(m_cdcHitName);
69 B2INFO(
"CDCPacker: FADC threshold: " << m_fadcThreshold);
75 void CDCPackerModule::beginRun()
77 B2INFO(
"CDCPacker: beginRun() called.");
80 int CDCPackerModule::getFEEID(
int copper_id,
int slot_id)
89 return (copper_id * 4 + slot_id);
94 return (copper_id + slot_id * NUM_CDC_COPPER);
99 return ((copper_id / 15) * 60 + (copper_id % 15) + slot_id * 15);
104 void CDCPackerModule::event()
108 int tot_chdata_bytes[302];
109 memset(tot_chdata_bytes, 0,
sizeof(
int) * 302);
111 const int ch_data_bytes = 8;
113 std::vector<CDCChannelData> chData;
116 for (
const auto& hit : m_CDCHits) {
117 int eWire = (int)(hit.getID());
118 int sly = eWire / 4096;
119 int ily = (eWire % 4096) / 512;
120 int iwire = (eWire % 512);
121 short tdc = hit.getTDCCount();
122 short adc = hit.getADCCount();
123 unsigned short tot = hit.getTOT();
127 if (m_fee_board[ sly ][ ily ][ iwire] < 0 || m_fee_ch[ sly ][ ily ][ iwire] < 0) {
128 printf(
"Hit WireID %8d SL %3d IL %3d WI %4d BOARD %3d CH %3d\n",
129 (
int)(hit.getID()), sly, ily , iwire,
130 m_fee_board[ sly ][ ily ][ iwire], m_fee_ch[ sly ][ ily ][ iwire]);
134 if (hit.is2ndHit() ==
false) {
136 tot_chdata_bytes[ m_fee_board[ sly ][ ily ][ iwire] ] += ch_data_bytes;
137 CDCChannelData chd(m_fee_board[sly][ily][iwire], m_fee_ch[sly][ily][iwire], 8, tot, adc, tdc);
138 chData.push_back(chd);
141 const int boardId = m_fee_board[sly][ily][iwire];
142 const int channel = m_fee_ch[sly][ily][iwire];
143 auto fi = std::find_if(chData.begin(), chData.end(),
145 return (ch.getBoard() == boardId && ch.getChannel() == channel);
147 if (fi != chData.end()) {
148 tot_chdata_bytes[ m_fee_board[ sly ][ ily ][ iwire] ] += 2;
149 const size_t index = std::distance(chData.begin(), fi);
150 chData[index].setTDC2ndHit(tdc);
156 for (
const auto& c : chData) {
157 int board = c.getBoard();
158 int ch = c.getChannel();
159 bool flag = c.is2ndHit();
160 int len = c.getDataLength();
161 if (!((len == 8 && flag ==
false) ||
162 (len == 10 && flag ==
true))) {
163 B2ERROR(
"inconsistent data object board : " << board <<
" ch " << ch);
171 rawcprpacker_info.
eve_num = m_event;
172 rawcprpacker_info.
tt_ctime = 0x7123456;
173 rawcprpacker_info.
tt_utime = 0xF1234567;
176 const int packet_header_words = 3;
178 for (
int i = 0 ; i < NUM_CDC_COPPER; i++) {
180 rawcprpacker_info.
node_id = 0x02000000 + i + 1;
181 int nwords[4] = {0, 0, 0, 0};
182 int* buf[4] = {0, 0, 0, 0};
184 for (
int j = 0; j < 4; j++) {
185 int fee_id = getFEEID(i, j);
186 nwords[ j ] = ((tot_chdata_bytes[ fee_id ] + 3) / 4) + packet_header_words;
188 buf[ j ] =
new int[ nwords[ j ] ];
191 const char type = 0x20;
192 const char ver = 0x0;
193 const short trigTime = 0x0;
194 const short dataLength = nwords[j] * 4 - packet_header_words * 4;
195 const int trigNum = m_event;
197 *(buf[j] + 0) = (type << 24) | (ver << 16) | fee_id;
198 *(buf[j] + 1) = ((trigTime << 16) | dataLength);
199 *(buf[j] + 2) = trigNum;
201 short* sbuf = (
short*)(buf[j] + 3);
203 bool halfOffset =
false;
204 short reservedValue = 0xcccc;
205 for (
const auto& c : chData) {
206 const int board = c.getBoard();
207 const int ch = c.getChannel();
208 const int len = c.getDataLength();
209 if (board == fee_id) {
211 if (halfOffset ==
false) {
212 *sbuf++ = c.getTOT();
213 *sbuf++ = ((ch << 8) | len);
214 *sbuf++ = c.getTDCCount();
215 *sbuf++ = c.getADCCount();
217 reservedValue = c.getTDCCount2ndHit();
221 *sbuf++ = ((ch << 8) | len);
222 *sbuf++ = reservedValue;
223 *sbuf++ = c.getADCCount();
224 *sbuf++ = c.getTOT();
226 *sbuf++ = c.getTDCCount2ndHit();
227 *sbuf++ = c.getTDCCount();
230 reservedValue = c.getTDCCount();
235 if (halfOffset ==
true) {
237 *sbuf = reservedValue;
241 RawCDC* raw_cdc = m_rawCDCs.appendNew();
248 for (
int j = 0; j < 4; j++) {
249 if (buf[j] !=
nullptr)
delete [] buf[j];
256 void CDCPackerModule::endRun()
258 B2INFO(
"CDCPacker : End run.");
261 void CDCPackerModule::terminate()
263 B2INFO(
"CDCPacker : Terminated.");
267 const WireID CDCPackerModule::getWireID(
int iBoard,
int iCh)
269 return m_map[iBoard][iCh];
272 void CDCPackerModule::loadMap()
278 for (
int i = 0 ; i < 9; ++i) {
279 for (
int j = 0 ; j < 8; ++j) {
280 for (
int k = 0 ; k < 384; ++k) {
281 m_fee_board[i][j][k] = -1;
282 m_fee_ch[i][j][k] = -1;
287 if (m_enableDatabase ==
false) {
290 std::string fileName = FileSystem::findFile(m_xmlMapFileName);
291 std::cout << fileName << std::endl;
292 if (fileName ==
"") {
293 B2ERROR(
"CDCPacker can't fine a filename: " << m_xmlMapFileName);
298 ifs.open(fileName.c_str());
307 ifs >> isl >> il >> iw >> iBoard >> iCh;
308 if (isl >= 9)
continue;
309 const WireID wireId(isl, il, iw);
310 m_map[iBoard][iCh] = wireId;
311 m_fee_board[isl][il][iw] = iBoard;
312 m_fee_ch[isl][il][iw] = iCh;
316 for (
const auto& cm : m_channelMapFromDB) {
318 if (isl >= 9)
continue;
319 const int il = cm.getILayer();
320 const int iw = cm.getIWire();
321 const int iBoard = cm.getBoardID();
322 const int iCh = cm.getBoardChannel();
323 const WireID wireId(isl, il, iw);
324 m_map[iBoard][iCh] = wireId;
325 m_fee_board[isl][il][iw] = iBoard;
326 m_fee_ch[isl][il][iw] = iCh;
CDCPackerModule: The CDC Raw Hits Decoder.
The Raw CDC class Class for RawCOPPER class data taken by CDC Currently, this class is almost same as...
struct to contain header information used by RawCOPPERFormat::Packer()
unsigned int b2l_ctime
32bit unitx time at trigger timing distributed by FTSW. For details, see Nakao-san's belle2link user ...
unsigned int eve_num
Run # and subrun # ( 22bit )
unsigned int tt_ctime
Node ID (32bit)
unsigned int tt_utime
27bit clock ticks at trigger timing distributed by FTSW. For details, see Nakao-san's belle2link user...
unsigned int node_id
Event Number (32bit)
unsigned int run_subrun_num
Experiment number (10bit)
unsigned int exp_num
Experiment number (10bit)
void PackDetectorBuf(int *detector_buf_1st, int nwords_1st, int *detector_buf_2nd, int nwords_2nd, int *detector_buf_3rd, int nwords_3rd, int *detector_buf_4th, int nwords_4th, RawCOPPERPackerInfo rawcprpacker_info)
Packer for RawCOPPER class Pack data (format ver.
Class to identify a wire inside the CDC.
unsigned short getISuperLayer() const
Getter for Super-Layer.
#define REG_MODULE(moduleName)
Register the given module (without 'Module' suffix) with the framework.
Abstract base class for different kinds of events.