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;
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;
248 for (
int j = 0; j < 4; j++) {
249 if (buf[j] !=
nullptr)
delete [] buf[j];
258 B2INFO(
"CDCPacker : End run.");
263 B2INFO(
"CDCPacker : Terminated.");
269 return m_map[iBoard][iCh];
278 for (
int i = 0 ; i < 9; ++i) {
279 for (
int j = 0 ; j < 8; ++j) {
280 for (
int k = 0 ; k < 384; ++k) {
291 std::cout << fileName << std::endl;
292 if (fileName ==
"") {
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;
317 const int isl = cm.getISuperLayer();
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;
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.
virtual ~CDCPackerModule()
Destructor of the module.
std::string m_rawCDCName
Name of the RawCDC dataobject (supressed 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 (supressed mode).
void beginRun() override
Begin run action.
bool m_enableStoreCDCRawHit
**
void loadMap()
Load FE channel to cell ID map.
bool m_enablePrintOut
Enable/Disable to print out the data to the terminal.
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.