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());
63 m_file = open("file.data", O_CREAT | O_RDWR | O_TRUNC, 0644);
64
67
68 B2INFO("Ds2Raw initialized.");
69}
70
71
73{
74 B2INFO("Ds2Raw: beginRun called.");
75}
76
77
79{
80 // Stream DataStore in EvtMessage
82
83 // Event Meta Data
85
86 // Fill Header and Trailer
87 SendHeader hdr;
88 SendTrailer trl;
89
90 // Number of total words
91 int msgsize = (msg->size() - 1) / 4 + 1;
92 int total_nwrds = msgsize + hdr.GetHdrNwords() + trl.GetTrlNwords();
93
94 // Fill header and trailer
95 hdr.SetNwords(total_nwrds);
97 hdr.SetNumNodesinPacket(1);
98 hdr.SetEventNumber(evtmeta->getEvent());
99 // hdr.SetExpRunWord(evtmeta->getRun());
100 hdr.SetSubRunNum(0); // temporary
101 hdr.SetRunNum(evtmeta->getRun());
102 hdr.SetExpNum(evtmeta->getExperiment());
103 hdr.SetNodeID(HLT_SUBSYS_ID);
104 // trl.SetMagicWord();
105
106 // Allocate raw buffer
107 int* buffer = new int[total_nwrds];
108
109 // Fill header
110 memcpy(buffer, hdr.GetBuffer(), hdr.GetHdrNwords()*sizeof(int));
111
112 // Fill EvtMessage
113 memcpy(buffer + hdr.GetHdrNwords(), msg->buffer(), msg->size());
114
115 // Fill trailer
116 memcpy(buffer + hdr.GetHdrNwords() + msgsize, trl.GetBuffer(),
117 trl.GetTrlNwords()*sizeof(int));
118
119 write(m_file, buffer, total_nwrds * 4);
120
121 B2INFO("Ds2Raw: objs sent in buffer. Size = " << msg->size());
122
123 // Release EvtMessage buffer
124 delete[] buffer;
125 delete msg;
126
127 // return
128 m_nsent++;
129
130}
131
133{
134 //fill Run data
135
136 printf("Ds2Raw: endRun called.....\n");
137 B2INFO("Ds2Raw: endRun done.");
138}
139
140
142{
143 delete m_streamer;
144
145 // RingBuffer should not be deleted
146
147 B2INFO("Ds2Raw: terminate called");
148}
149
Stream/restore DataStore objects to/from EvtMessage.
EvtMessage * streamDataStore(bool addPersistentDurability, bool streamTransientObjects=false)
Store DataStore objects in 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
Base class for Modules.
Definition: Module.h:72
void setDescription(const std::string &description)
Sets the description of the module.
Definition: Module.cc:214
void SetNumEventsinPacket(int num_events)
set contents of Header
Definition: SendHeader.cc:61
int GetHdrNwords()
get contents of Header
Definition: SendHeader.cc:124
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.