Belle II Software development
DeSerializerPXD.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/rawdata/modules/DeSerializerPXD.h>
10
11
12using namespace std;
13using namespace Belle2;
14
15//-----------------------------------------------------------------
16// Register the Module
17//-----------------------------------------------------------------
18REG_MODULE(DeSerializerPXD);
19
20//-----------------------------------------------------------------
21// Implementation
22//-----------------------------------------------------------------
23
25{
26 //Set module properties
27 setDescription("Receives PXD-Data from ONSEN (or a simulator) and stores it as RawPXD in Data Store");
28 //setPropertyFlags(c_Input | c_ParallelProcessingCertified);
29
30 addParam("Ports", m_ports, "default port number");
31 addParam("Hosts", m_hosts, "default host names");
32 m_nEvents = 0;
34 m_buffer = new int[MAXEVTSIZE];
35 // events_processed = 0;
36 //Parameter definition
37 B2DEBUG(0, "DeSerializerPXDModule: Constructor done.");
38}
39
40
41DeSerializerPXDModule::~DeSerializerPXDModule()
42{
43 delete[] m_buffer;
44}
45
47{
48 if (m_hosts.size() != m_ports.size()) {
49 B2ERROR("DeSerializerPXDModule: Parameter error. Hosts and Ports need the same number of entries!");
51 return;
52 }
53
54 // Open receiver sockets
55 for (int i = 0; i < (int)(m_hosts.size()); i++) {
56 m_recvs.push_back(new EvtSocketSend(m_hosts[i], m_ports[i]));
57 }
58
59 // Initialize EvtMetaData
60 m_eventMetaDataPtr.registerInDataStore();
61
62 // Initialize Array of RawCOPPER
63 rawpxdary.registerInDataStore();
64
65 B2DEBUG(0, "DeSerializerPXDModule: initialized.");
66}
67
69{
70 B2DEBUG(0, "beginRun called.");
71}
72
74{
75
76 // Get a record from socket
77 int stat = 0;
78 for (auto& it : m_recvs) {
79 do {
80 stat = it->recv_pxd_buffer((char*)m_buffer);
81 if (stat <= 0) {
82 B2INFO("DeserializerPXD Socket failed: stat = " << stat);
85 return;
86 };
87 } while (stat == 0);
88
89 // Put RawPXD in DataStore, stat=lenght_in_Bytes
90 rawpxdary.appendNew(m_buffer, stat);
91
92 // What we do NOT check here (yet) is, if all Packets belong to the same event! TODO
93 }
94
95
96 // Create EventMetaData - warning, this is only o.k. if this module is the only one!
97 m_eventMetaDataPtr.create();
98 m_eventMetaDataPtr->setExperiment(1);
99 m_eventMetaDataPtr->setRun(1);
100 m_eventMetaDataPtr->setEvent(m_nEvents);
101
102 m_nEvents++;
103
104 return;
105}
106
108{
109 //fill Run data
110
111 B2DEBUG(0, "endRun done.");
112}
113
114
116{
117 B2INFO("terminate called");
118}
119
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.
DeSerializerPXDModule()
Constructor / Destructor.
void beginRun() override
Module functions to be called from event process.
std::vector< int > m_ports
Receiver Port.
int m_compressionLevel
Compression Level.
std::vector< EvtSocketSend * > m_recvs
Receiver Sockets.
std::vector< std::string > m_hosts
Sender Names.
int m_nEvents
No. of rcvd events.
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 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.