9 #include <daq/rfarm/event/modules/Raw2DsModule.h>
10 #include <daq/dataobjects/SendHeader.h>
11 #include <daq/dataobjects/SendTrailer.h>
17 #include "framework/datastore/StoreObjPtr.h"
18 #include "framework/dataobjects/EventMetaData.h"
19 #include "framework/core/Environment.h"
25 static int signalled = 0;
26 static void signalHandler(
int sig)
29 printf(
"Raw2Ds : Signal received\n");
48 setDescription(
"Encode DataStore into RingBuffer");
51 addParam(
"RingBufferName", m_rbufname,
"Name of RingBuffer",
58 B2INFO(
"Rx: Constructor done.");
62 Raw2DsModule::~Raw2DsModule()
66 void Raw2DsModule::initialize()
68 gSystem->Load(
"libdataobjects");
73 m_eventMetaData.registerInDataStore();
76 m_rawDataBlock.registerInDataStore();
77 m_rawCOPPER.registerInDataStore();
78 m_rawSVD.registerInDataStore();
79 m_rawCDC.registerInDataStore();
80 m_rawTOP.registerInDataStore();
81 m_rawARICH.registerInDataStore();
82 m_rawECL.registerInDataStore();
83 m_rawKLM.registerInDataStore();
84 m_rawTRG.registerInDataStore();
85 m_rawFTSW.registerInDataStore();
93 B2INFO(
"Rx initialized.");
97 void Raw2DsModule::beginRun()
99 if (Environment::Instance().getNumberProcesses() != 0) {
101 memset(&s,
'\0',
sizeof(s));
102 s.sa_handler = signalHandler;
103 sigemptyset(&s.sa_mask);
104 if (sigaction(SIGINT, &s, NULL) != 0) {
105 B2FATAL(
"Rbuf2Ds: Error to connect signal handler");
107 printf(
"Raw2Ds : Signal Handler installed.\n");
109 B2INFO(
"beginRun called.");
113 void Raw2DsModule::event()
117 if (m_nevt == 0)
return;
119 registerRawCOPPERs();
122 void Raw2DsModule::registerRawCOPPERs()
127 unsigned int error_flag = 0;
129 int* evtbuf =
new int[MAXEVTSIZE];
130 while ((size = m_rbuf->remq((
int*)evtbuf)) == 0) {
133 if (signalled != 0)
return;
143 if (npackedevts != 1) {
144 printf(
"[WARNING] strange SendHeader : ");
146 for (
int i = 0; i < 10; i++) {
147 printf(
"0x%.8x ", *(sndhdr.
GetBuffer() + i));
149 printf(
"\n"); fflush(stdout);
151 B2WARNING(
"Raw2DsModule::number of events in packet is not 1. This process gets stuck here. Please ABORT the system. (Please see discussion of daqcore channel in https://b2rc.kek.jp/ on 2017. Nov. 30. about why this is not FATAL message.");
154 int ncprs = sndhdr.GetNumNodesinPacket();
155 int nwords = sndhdr.GetTotalNwords() - SendHeader::SENDHDR_NWORDS - SendTrailer::SENDTRL_NWORDS;
160 int* bufbody = evtbuf + SendHeader::SENDHDR_NWORDS;
164 tempdblk.
SetBuffer(bufbody, nwords,
false, npackedevts, ncprs);
166 unsigned int utime = 0;
167 unsigned int ctime = 0;
168 unsigned long long int mtime = 0;
170 int store_time_flag = 0;
173 for (
int cprid = 0; cprid < ncprs * npackedevts; cprid++) {
176 int* cprbuf =
new int[nwds_buf];
177 memcpy(cprbuf, tempdblk.
GetBuffer(cprid), nwds_buf * 4);
183 ftsw->
SetBuffer(cprbuf, nwds_buf, 1, 1, 1);
188 mtime = 1000000000 * (
unsigned long long int)utime + (
unsigned long long int)(std::round(ctime / 0.127216));
191 }
else if (store_time_flag == 0) {
195 tempcpr_time.
SetBuffer(cprbuf, nwds_buf,
false, 1, 1);
196 utime = (
unsigned int)(tempcpr_time.
GetTTUtime(0));
197 ctime = (
unsigned int)(tempcpr_time.
GetTTCtime(0));
198 mtime = 1000000000 * (
unsigned long long int)utime + (
unsigned long long int)(std::round(ctime / 0.127216));
204 tempcpr.
SetBuffer(cprbuf, nwds_buf,
false, 1, 1);
207 error_flag |= (
unsigned int)(tempcpr.
GetDataType(0));
210 if ((subsysid & DETECTOR_MASK) == CDC_ID) {
212 (ary.
appendNew())->SetBuffer(cprbuf, nwds_buf, 1, 1, 1);
213 }
else if ((subsysid & DETECTOR_MASK) == SVD_ID) {
215 (ary.
appendNew())->SetBuffer(cprbuf, nwds_buf, 1, 1, 1);
216 }
else if ((subsysid & DETECTOR_MASK) == BECL_ID) {
218 (ary.
appendNew())->SetBuffer(cprbuf, nwds_buf, 1, 1, 1);
219 }
else if ((subsysid & DETECTOR_MASK) == EECL_ID) {
221 (ary.
appendNew())->SetBuffer(cprbuf, nwds_buf, 1, 1, 1);
222 }
else if ((subsysid & DETECTOR_MASK) == TOP_ID) {
224 (ary.
appendNew())->SetBuffer(cprbuf, nwds_buf, 1, 1, 1);
225 }
else if ((subsysid & DETECTOR_MASK) == ARICH_ID) {
227 (ary.
appendNew())->SetBuffer(cprbuf, nwds_buf, 1, 1, 1);
228 }
else if ((subsysid & DETECTOR_MASK) == BKLM_ID) {
230 (ary.
appendNew())->SetBuffer(cprbuf, nwds_buf, 1, 1, 1);
231 }
else if ((subsysid & DETECTOR_MASK) == EKLM_ID) {
233 (ary.
appendNew())->SetBuffer(cprbuf, nwds_buf, 1, 1, 1);
234 }
else if (((subsysid & DETECTOR_MASK) & 0xF0000000) == TRGDATA_ID) {
236 (ary.
appendNew())->SetBuffer(cprbuf, nwds_buf, 1, 1, 1);
240 printf(
"[WARNING] Unknown COPPER ID : ");
241 for (
int i = 0; i < 12; i++) {
242 printf(
"0x%.8x ", cprbuf[ i ]);
245 B2FATAL(
"Unknown COPPER ID is found. CPRID = " << hex << subsysid <<
" Please check. Exiting...");
253 if (store_time_flag != 1) {
254 B2FATAL(
"No time information could be extracted from Data. That should not happen. Exiting...");
258 evtmetadata->setExperiment(sndhdr.GetExpNum());
259 evtmetadata->setRun(sndhdr.GetRunNum());
260 evtmetadata->setSubrun(sndhdr.GetSubRunNum());
261 evtmetadata->setEvent(sndhdr.GetEventNumber());
262 evtmetadata->setTime(mtime);
265 if (error_flag) setErrorFlag(error_flag, evtmetadata);
273 void Raw2DsModule::endRun()
277 B2INFO(
"Raw2Ds: endRun done.");
281 void Raw2DsModule::terminate()
283 B2INFO(
"Raw2Ds: terminate called");
290 if (error_flag & RawHeader_latest::B2LINK_PACKET_CRC_ERROR) {
291 evtmetadata->addErrorFlag(EventMetaData::c_B2LinkPacketCRCError);
294 if (error_flag & RawHeader_latest::B2LINK_EVENT_CRC_ERROR) {
295 evtmetadata->addErrorFlag(EventMetaData::c_B2LinkEventCRCError);
298 if (error_set) B2INFO(
"Raw2Ds: Error flag was set in EventMetaData.");
A class definition of an input module for Sequential ROOT I/O.
The Raw COPPER class This class stores data received by COPPER via belle2linkt Data from all detector...
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 )
The RawDataBlock class Base class for rawdata handling.
virtual int CheckFTSWID(int n)
get FTSW ID to check whether this data block is FTSW data or not
virtual int * GetBuffer(int n)
get nth buffer pointer
virtual void SetBuffer(int *bufin, int nwords, int delete_flag, int num_events, int num_nodes)
set buffer ( delete_flag : m_buffer is freeed( = 0 )/ not freeed( = 1 ) in Destructer )
virtual int GetBlockNwords(int n)
get size of a data block
unsigned int GetTTUtime(int n)
get unixtime of the trigger
int GetTTCtime(int n)
Get ctime of the trigger.
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 )
Class to manage a Ring Buffer placed in an IPC shared memory.
bool create(bool replace=false)
Create a default object in the data store.
Accessor to arrays stored in the data store.
T * appendNew()
Construct a new T object at the end of the array.
Type-safe access to single objects in the data store.
#define REG_MODULE(moduleName)
Register the given module (without 'Module' suffix) with the framework.
unsigned int GetTTUtime(int n)
Check if COPPER Magic words are correct.
int GetDataType(int n)
get contents of header
int GetTTCtime(int n)
Get ctime.
unsigned int GetNodeID(int n)
get node-ID from data
Abstract base class for different kinds of events.