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
46 string(
"/cdc/data/ch_map.dat"));
61 B2INFO(
"CDCPacker: initialize() Called.");
77 B2INFO(
"CDCPacker: beginRun() called.");
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);
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;
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();
128 printf(
"Hit WireID %8d SL %3d IL %3d WI %4d BOARD %3d CH %3d\n",
129 (
int)(hit.getID()), sly, ily, iwire,
134 if (hit.is2ndHit() ==
false) {
136 tot_chdata_bytes[
m_fee_board[ sly ][ ily ][ iwire] ] += ch_data_bytes;
138 chData.push_back(chd);
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);
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++) {
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;
198 *(buf[j] + 0) = (type << 24) | (ver << 16) | fee_id;
200 *(buf[j] + 1) = ((trigTime << 16) | dataLength);
201 *(buf[j] + 2) = trigNum;
203 short* sbuf =
reinterpret_cast<short*
>(buf[j] + 3);
205 bool halfOffset =
false;
206 short reservedValue = 0xcccc;
207 for (
const auto& c : chData) {
208 const int board = c.getBoard();
209 const int ch = c.getChannel();
210 const int len = c.getDataLength();
211 if (board == fee_id) {
213 if (halfOffset ==
false) {
214 *sbuf++ = c.getTOT();
215 *sbuf++ = ((ch << 8) | len);
216 *sbuf++ = c.getTDCCount();
217 *sbuf++ = c.getADCCount();
219 reservedValue = c.getTDCCount2ndHit();
223 *sbuf++ = ((ch << 8) | len);
224 *sbuf++ = reservedValue;
225 *sbuf++ = c.getADCCount();
226 *sbuf++ = c.getTOT();
228 *sbuf++ = c.getTDCCount2ndHit();
229 *sbuf++ = c.getTDCCount();
232 reservedValue = c.getTDCCount();
237 if (halfOffset ==
true) {
239 *sbuf = reservedValue;
250 for (
int j = 0; j < 4; j++) {
251 if (buf[j] !=
nullptr)
delete [] buf[j];
260 B2INFO(
"CDCPacker : End run.");
265 B2INFO(
"CDCPacker : Terminated.");
271 return m_map[iBoard][iCh];
280 for (
int i = 0 ; i < 9; ++i) {
281 for (
int j = 0 ; j < 8; ++j) {
282 for (
int k = 0 ; k < 384; ++k) {
293 std::cout << fileName << std::endl;
294 if (fileName ==
"") {
300 ifs.open(fileName.c_str());
309 ifs >> isl >> il >> iw >> iBoard >> iCh;
310 if (isl >= 9)
continue;
311 const WireID wireId(isl, il, iw);
312 m_map[iBoard][iCh] = wireId;
319 const int isl = cm.getISuperLayer();
320 if (isl >= 9)
continue;
321 const int il = cm.getILayer();
322 const int iw = cm.getIWire();
323 const int iBoard = cm.getBoardID();
324 const int iCh = cm.getBoardChannel();
325 const WireID wireId(isl, il, iw);
326 m_map[iBoard][iCh] = wireId;
StoreArray< RawCDC > m_rawCDCs
Raw CDC array.
int m_fee_ch[9][8][384]
Assignment map of FE board channel to the cell.
bool m_enableDatabase
Enable/Disable to read the channel map from the database.
std::string m_rawCDCName
Name of the RawCDC dataobject (suppressed mode).
void initialize() override
Initializes the Module.
DBArray< CDCChannelMap > m_channelMapFromDB
Channel map retrieved from DB.
void event() override
Event action (main routine).
int getFEEID(int copper_id, int slot_id)
Getter for Front End Electronics ID.
int m_fee_board[9][8][384]
Assignment map of FE board ID to the cell.
StoreArray< CDCRawHit > m_CDCRawHits
CDC raw hits.
void endRun() override
End run action.
const WireID getWireID(int iBoard, int iCh)
Getter of Wire ID.
void terminate() override
Termination action.
int m_fadcThreshold
FADC threshold.
std::string m_xmlMapFileName
Name of the assignment map of FE board channel to the cell.
WireID m_map[300][48]
Assignment map of FE board channel to the cell.
CDCPackerModule()
Constructor of the module.
std::string m_cdcRawHitName
Name of the CDCRawHit dataobject (suppressed mode).
void beginRun() override
Begin run action.
bool m_enableStoreCDCRawHit
Number of good blocks.
void loadMap()
Load FE channel to cell ID map.
bool m_enablePrintOut
Enable/Disable to print out the data to the terminal.
virtual ~CDCPackerModule() override
Destructor of the module.
std::string m_cdcHitName
Tree name of the CDCHit object.
StoreArray< CDCHit > m_CDCHits
CDC hits.
static std::string findFile(const std::string &path, bool silent=false)
Search for given file or directory in local or central release directory, and return absolute path if...
void setDescription(const std::string &description)
Sets the description of the module.
void setPropertyFlags(unsigned int propertyFlags)
Sets the flags for the module properties.
@ c_ParallelProcessingCertified
This module can be run in parallel processing mode safely (All I/O must be done through the data stor...
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.
void addParam(const std::string &name, T ¶mVariable, const std::string &description, const T &defaultValue)
Adds a new parameter to the module.
#define REG_MODULE(moduleName)
Register the given module (without 'Module' suffix) with the framework.
Abstract base class for different kinds of events.