9 #include <daq/rfarm/event/modules/rawinputModule.h>
11 #include <daq/dataobjects/SendHeader.h>
12 #include <daq/dataobjects/SendTrailer.h>
31 setDescription(
"Raw data file input module");
38 addParam(
"inputFileName" , m_inputFileName,
"Raw file name.",
string(
"RawInput.root"));
40 B2DEBUG(1,
"RawInput: Constructor done.");
44 RawInputModule::~RawInputModule()
48 void RawInputModule::initialize()
50 gSystem->Load(
"libdataobjects");
53 m_eventMetaData.registerInDataStore();
56 m_rawDataBlock.registerInDataStore();
57 m_rawCOPPER.registerInDataStore();
58 m_rawSVD.registerInDataStore();
59 m_rawCDC.registerInDataStore();
60 m_rawTOP.registerInDataStore();
61 m_rawARICH.registerInDataStore();
62 m_rawECL.registerInDataStore();
63 m_rawKLM.registerInDataStore();
64 m_rawTRG.registerInDataStore();
65 m_rawFTSW.registerInDataStore();
68 printf(
"RawInput : Opening file %s\n", m_inputFileName.c_str());
69 m_fd = open(m_inputFileName.c_str(), O_RDONLY);
74 printf(
"Done. m_fd = %d\n", m_fd);
82 B2INFO(
"RawInput: initialized.");
87 void RawInputModule::beginRun()
90 B2INFO(
"RawInput: beginRun called.");
94 void RawInputModule::event()
98 if (m_nevt == 0)
return;
100 registerRawCOPPERs();
103 void RawInputModule::registerRawCOPPERs()
108 char* evtbuf =
new char[MAXEVTSIZE];
110 int sstat = read(m_fd, evtbuf,
sizeof(
int));
115 int* recsize = (
int*)evtbuf;
116 int rstat = read(m_fd, evtbuf +
sizeof(
int), (*recsize - 1) * 4);
122 B2INFO(
"RawInput: got an event from a file, size=" << recsize <<
123 " (proc= " << (
int)getpid() <<
")");
131 if (npackedevts != 1) {
132 B2FATAL(
"Raw2DsModule::number of events in packet is not 1 " << npackedevts);
134 int ncprs = sndhdr.GetNumNodesinPacket();
135 int nwords = sndhdr.GetTotalNwords() - SendHeader::SENDHDR_NWORDS - SendTrailer::SENDTRL_NWORDS;
136 B2INFO(
"RawInput: Ncprs=" << ncprs <<
" Nwords=" << nwords);
139 int* bufbody = (
int*)evtbuf + SendHeader::SENDHDR_NWORDS;
147 tempdblk.
SetBuffer(bufbody, nwords,
false, npackedevts, ncprs);
150 for (
int cprid = 0; cprid < ncprs * npackedevts; cprid++) {
153 int* cprbuf =
new int[nwds_buf];
154 memcpy(cprbuf, tempdblk.
GetBuffer(cprid), nwds_buf * 4);
159 (ary.
appendNew())->SetBuffer(cprbuf, nwds_buf, 1, 1, 1);
165 tempcpr.
SetBuffer(cprbuf, nwds_buf,
false, 1, 1);
173 if ((subsysid & DETECTOR_MASK) == CDC_ID) {
175 (ary.
appendNew())->SetBuffer(cprbuf, nwds_buf, 1, 1, 1);
176 }
else if ((subsysid & DETECTOR_MASK) == SVD_ID) {
178 (ary.
appendNew())->SetBuffer(cprbuf, nwds_buf, 1, 1, 1);
179 }
else if ((subsysid & DETECTOR_MASK) == BECL_ID) {
181 (ary.
appendNew())->SetBuffer(cprbuf, nwds_buf, 1, 1, 1);
182 }
else if ((subsysid & DETECTOR_MASK) == EECL_ID) {
184 (ary.
appendNew())->SetBuffer(cprbuf, nwds_buf, 1, 1, 1);
185 }
else if ((subsysid & DETECTOR_MASK) == TOP_ID) {
187 (ary.
appendNew())->SetBuffer(cprbuf, nwds_buf, 1, 1, 1);
188 }
else if ((subsysid & DETECTOR_MASK) == ARICH_ID) {
190 (ary.
appendNew())->SetBuffer(cprbuf, nwds_buf, 1, 1, 1);
191 }
else if ((subsysid & DETECTOR_MASK) == BKLM_ID) {
193 (ary.
appendNew())->SetBuffer(cprbuf, nwds_buf, 1, 1, 1);
194 }
else if ((subsysid & DETECTOR_MASK) == EKLM_ID) {
196 (ary.
appendNew())->SetBuffer(cprbuf, nwds_buf, 1, 1, 1);
197 }
else if (((subsysid & DETECTOR_MASK) & 0xF0000000) == TRGDATA_ID) {
199 (ary.
appendNew())->SetBuffer(cprbuf, nwds_buf, 1, 1, 1);
202 (ary.
appendNew())->SetBuffer(cprbuf, nwds_buf, 1, 1, 1);
209 evtmetadata->setExperiment(sndhdr.GetExpNum());
210 evtmetadata->setRun(sndhdr.GetRunNum());
211 evtmetadata->setSubrun(sndhdr.GetSubRunNum());
212 evtmetadata->setEvent(sndhdr.GetEventNumber());
213 if (error_flag) evtmetadata->addErrorFlag(EventMetaData::c_B2LinkEventCRCError);
218 B2INFO(
"RawInput: DataStore Restored!!");
223 void RawInputModule::endRun()
225 B2INFO(
"RawInput: endRun done.");
229 void RawInputModule::terminate()
232 B2INFO(
"RawInput: terminate called");
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
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.
int GetEventCRCError(int n)
check CRC event Error
unsigned int GetNodeID(int n)
get node-ID from data
Abstract base class for different kinds of events.