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");
58 B2INFO(
"Rx: Constructor done.");
62Raw2DsModule::~Raw2DsModule()
68 gSystem->Load(
"libdataobjects");
93 B2INFO(
"Rx initialized.");
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.");
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);
277 B2INFO(
"Raw2Ds: endRun done.");
283 B2INFO(
"Raw2Ds: terminate called");
290 if (error_flag & RawHeader_latest::B2LINK_PACKET_CRC_ERROR) {
294 if (error_flag & RawHeader_latest::B2LINK_EVENT_CRC_ERROR) {
298 if (error_set) B2INFO(
"Raw2Ds: Error flag was set in EventMetaData.");
static Environment & Instance()
Static method to get a reference to the Environment instance.
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_Input
This module is an input module (reads data).
void registerRawCOPPERs()
function to register data buffer in DataStore as RawCOPPERs
int m_nevt
No. of sent events.
StoreArray< RawSVD > m_rawSVD
RawSVD.
void initialize() override
Module functions to be called from main process.
void event() override
This method is the core of the module.
void endRun() override
This method is called if the current run ends.
StoreArray< RawFTSW > m_rawFTSW
RawFTSW.
void terminate() override
This method is called at the end of the event processing.
StoreObjPtr< EventMetaData > m_eventMetaData
EventMetaData.
StoreArray< RawCOPPER > m_rawCOPPER
RawCOPPER.
StoreArray< RawARICH > m_rawARICH
RawARICH.
StoreArray< RawTRG > m_rawTRG
RawTRG.
Raw2DsModule()
Constructor / Destructor.
void beginRun() override
Module functions to be called from event process.
StoreArray< RawKLM > m_rawKLM
RawKLM.
StoreArray< RawTOP > m_rawTOP
RawTOP.
StoreArray< RawDataBlock > m_rawDataBlock
RawDataBlock.
StoreArray< RawECL > m_rawECL
RawECL.
StoreArray< RawCDC > m_rawCDC
RawCDC.
std::string m_rbufname
RingBuffer ID.
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 * GetBuffer(int n)
get nth buffer pointer
virtual int CheckFTSWID(int n)
get FTSW ID to check whether this data block is FTSW data or not
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.
int remq(int *buf)
Pick up a buffer from the RingBuffer.
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.
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.
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.