36 #include <rawdata/modules/HexDataPacker.h>
55 setDescription(
"an Example to pack data to a RawCOPPER object");
56 addParam(
"inputFileName", m_fileName,
"Output binary filename",
string(
""));
57 B2INFO(
"HexDataPacker: Constructor done.");
64 HexDataPackerModule::~HexDataPackerModule()
70 void HexDataPackerModule::initialize()
72 B2INFO(
"HexDataPacker: initialize() started.");
78 m_eventMetaDataPtr.registerInDataStore();
80 m_raw_cprarray.registerInDataStore();
81 m_raw_svdarray.registerInDataStore();
82 m_raw_cdcarray.registerInDataStore();
83 m_raw_bpidarray.registerInDataStore();
84 m_raw_epidarray.registerInDataStore();
85 m_raw_eclarray.registerInDataStore();
86 m_raw_klmarray.registerInDataStore();
88 B2INFO(
"HexDataPacker: initialize() done.");
90 if (m_fileName ==
"") {
91 B2FATAL(
"HexDataPacker can't fine a filename: ");
94 m_ifs.open(m_fileName.c_str());
96 B2FATAL(
"HexDataPacker can't open a file " << m_fileName.c_str());
103 void HexDataPackerModule::event()
106 const int MAX_CPRBUF_WORDS = 5000;
107 int* evtbuf =
new int[MAX_CPRBUF_WORDS];
108 char char1[50], char2[50], char3[50], char4[50];
110 unsigned int val[10];
122 getline(m_ifs, strin);
123 sscanf(strin.c_str(),
"%49s %49s %49s %49s",
124 char1, char2, char3, char4);
125 if (strcmp(char1,
"data") == 0) {
126 if (strcmp(char4,
"Trailer") == 0) {
129 if (strcmp(char2,
"0") == 0) {
131 }
else if (strcmp(char2,
"7") == 0) {
132 sscanf(strin.c_str(),
"%49s %u %49s %x %x %x %x %x %x %x %x",
133 char1, &(val[0]), char2, &(val[1]), &(val[2]), &(val[3]), &(val[4]), &(val[5]), &(val[6]), &(val[7]), &(val[8]));
135 val[2] = val[2] | 0x00008000;
136 if (size < 0 || size > MAX_CPRBUF_WORDS) {
137 B2FATAL(
"The size of an event =(" << size <<
") is too large. Exiting...");
140 sscanf(strin.c_str(),
"%20s %u %20s %x %x %x %x %x %x %x %x",
141 char1, &(val[0]), char2, &(val[1]), &(val[2]), &(val[3]), &(val[4]), &(val[5]), &(val[6]), &(val[7]), &(val[8]));
144 B2FATAL(
"The size of an event (=" << size <<
") is too large. Exiting...");
146 for (
int i = 1; i <= 8 ; i++) {
147 if (word_count >= MAX_CPRBUF_WORDS) {
148 B2FATAL(
"The size of an event (=" << size <<
") is too large. Exiting...");
150 evtbuf[word_count] = val[i];
152 if (word_count == size) {
157 if (event_end == 1) {
break;}
163 if (size > 0 && size < MAX_CPRBUF_WORDS) {
164 for (
int i = 0; i < size; i++) {
165 printf(
"%.8x ", evtbuf[i]);
166 if (i % 8 == 7) printf(
"\n");
173 (ary.
appendNew())->SetBuffer(evtbuf, size, 1, 1, 1);
179 tempcpr.
SetBuffer(evtbuf, size,
false, 1, 1);
182 evtmetadata.create();
183 evtmetadata->setExperiment(tempcpr.
GetExpNo(0));
184 evtmetadata->setRun(tempcpr.
GetRunNo(0));
186 evtmetadata->setEvent(tempcpr.
GetEveNo(0));
191 evtmetadata.create();
192 evtmetadata->setEndOfData();
195 printf(
"Event counter %8d\n", n_basf2evt); fflush(stdout);