Belle II Software development
Ds2RawFileModule.cc
1/**************************************************************************
2 * basf2 (Belle II Analysis Software Framework) *
3 * Author: The Belle II Collaboration *
4 * *
5 * See git log for contributors and copyright holders. *
6 * This file is licensed under LGPL-3.0, see LICENSE.md. *
7 **************************************************************************/
8
9#include <daq/storage/modules/Ds2RawFileModule.h>
10
11#include <daq/dataobjects/SendHeader.h>
12#include <daq/dataobjects/SendTrailer.h>
13#include <framework/datastore/DataStore.h>
14#include <framework/datastore/StoreObjPtr.h>
15#include <framework/dataobjects/EventMetaData.h>
16
17#include <fcntl.h>
18
19using namespace std;
20using namespace Belle2;
21
23// static int fdout;
24
25//-----------------------------------------------------------------
26// Register the Module
27//-----------------------------------------------------------------
28REG_MODULE(Ds2RawFile);
29
30//-----------------------------------------------------------------
31// Implementation
32//-----------------------------------------------------------------
33
35{
36 //Set module properties
37 setDescription("Encode DataStore into RingBuffer");
38
39 //addParam("RingBufferName", m_rbufname, "Name of RingBuffer",
40 // string("OutputRbuf"));
41 addParam("CompressionLevel", m_compressionLevel, "Compression level",
42 0);
43
44 //m_rbuf = NULL;
45 m_nsent = 0;
47
48 //Parameter definition
49 B2INFO("Ds2Raw: Constructor done.");
50}
51
52
53Ds2RawFileModule::~Ds2RawFileModule()
54{
55}
56
58{
59
60 // m_rbuf = new RingBuffer(m_rbufname.c_str(), RBUFSIZE);
61 //m_rbuf = new RingBuffer(m_rbufname.c_str());
62 // cppcheck-suppress publicAllocationError ; initialize() is called exactly once per job
64 m_file = open("file.data", O_CREAT | O_RDWR | O_TRUNC, 0644);
65
68
69 B2INFO("Ds2Raw initialized.");
70}
71
72
74{
75 B2INFO("Ds2Raw: beginRun called.");
76}
77
78
80{
81 // Stream DataStore in EvtMessage
82 EvtMessage* msg = m_streamer->streamDataStore(DataStore::c_Event);
83
84 // Event Meta Data
86
87 // Fill Header and Trailer
88 SendHeader hdr;
89 SendTrailer trl;
90
91 // Number of total words
92 int msgsize = (msg->size() - 1) / 4 + 1;
93 int total_nwrds = msgsize + hdr.GetHdrNwords() + trl.GetTrlNwords();
94
95 // Fill header and trailer
96 hdr.SetNwords(total_nwrds);
98 hdr.SetNumNodesinPacket(1);
99 hdr.SetEventNumber(evtmeta->getEvent());
100 // hdr.SetExpRunWord(evtmeta->getRun());
101 hdr.SetSubRunNum(0); // temporary
102 hdr.SetRunNum(evtmeta->getRun());
103 hdr.SetExpNum(evtmeta->getExperiment());
104 hdr.SetNodeID(HLT_SUBSYS_ID);
105 // trl.SetMagicWord();
106
107 // Allocate raw buffer
108 int* buffer = new int[total_nwrds];
109
110 // Fill header
111 memcpy(buffer, hdr.GetBuffer(), hdr.GetHdrNwords()*sizeof(int));
112
113 // Fill EvtMessage
114 memcpy(buffer + hdr.GetHdrNwords(), msg->buffer(), msg->size());
115
116 // Fill trailer
117 memcpy(buffer + hdr.GetHdrNwords() + msgsize, trl.GetBuffer(),
118 trl.GetTrlNwords()*sizeof(int));
119
120 write(m_file, buffer, total_nwrds * 4);
121
122 B2INFO("Ds2Raw: objs sent in buffer. Size = " << msg->size());
123
124 // Release EvtMessage buffer
125 delete[] buffer;
126 delete msg;
127
128 // return
129 m_nsent++;
130
131}
132
134{
135 //fill Run data
136
137 printf("Ds2Raw: endRun called.....\n");
138 B2INFO("Ds2Raw: endRun done.");
139}
140
141
143{
144 delete m_streamer;
145
146 // RingBuffer should not be deleted
147
148 B2INFO("Ds2Raw: terminate called");
149}
150
Stream/restore DataStore objects to/from EvtMessage.
@ c_Event
Different object in each event, all objects/arrays are invalidated after event() function has been ca...
Definition DataStore.h:59
DataStoreStreamer * m_streamer
RingBuffer ID.
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.
void terminate() override
This method is called at the end of the event processing.
Ds2RawFileModule()
Constructor / Destructor.
void beginRun() override
Module functions to be called from event process.
int m_nsent
No. of sent events.
int m_compressionLevel
Compression parameter.
Class to manage streamed object.
Definition EvtMessage.h:59
char * buffer()
Get buffer address.
Definition EvtMessage.cc:76
int size() const
Get size of message including headers.
Definition EvtMessage.cc:94
void setDescription(const std::string &description)
Sets the description of the module.
Definition Module.cc:214
Module()
Constructor.
Definition Module.cc:30
void SetNumEventsinPacket(int num_events)
set contents of Header
Definition SendHeader.cc:61
static int GetHdrNwords()
get contents of Header
void SetNwords(int total_data_nwords)
initialize Header
Definition SendHeader.cc:51
int * GetBuffer(void)
Get Header contents.
Definition SendHeader.cc:32
Type-safe access to single objects in the data store.
Definition StoreObjPtr.h:96
void addParam(const std::string &name, T &paramVariable, const std::string &description, const T &defaultValue)
Adds a new parameter to the module.
Definition Module.h:560
#define REG_MODULE(moduleName)
Register the given module (without 'Module' suffix) with the framework.
Definition Module.h:650
Abstract base class for different kinds of events.
STL namespace.