Belle II Software  release-08-01-10
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 
12 using namespace std;
13 using namespace Belle2;
14 
15 //-----------------------------------------------------------------
16 // Register the Module
17 //-----------------------------------------------------------------
18 REG_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;
33  m_compressionLevel = 0;
34  m_buffer = new int[MAXEVTSIZE];
35  // events_processed = 0;
36  //Parameter definition
37  B2DEBUG(0, "DeSerializerPXDModule: Constructor done.");
38 }
39 
40 
41 DeSerializerPXDModule::~DeSerializerPXDModule()
42 {
43  delete[] m_buffer;
44 }
45 
46 void DeSerializerPXDModule::initialize()
47 {
48  if (m_hosts.size() != m_ports.size()) {
49  B2ERROR("DeSerializerPXDModule: Parameter error. Hosts and Ports need the same number of entries!");
50  DeSerializerPXDModule::terminate();
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 
68 void DeSerializerPXDModule::beginRun()
69 {
70  B2DEBUG(0, "beginRun called.");
71 }
72 
73 void DeSerializerPXDModule::event()
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);
83  DeSerializerPXDModule::endRun();
84  DeSerializerPXDModule::terminate();
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 
107 void DeSerializerPXDModule::endRun()
108 {
109  //fill Run data
110 
111  B2DEBUG(0, "endRun done.");
112 }
113 
114 
115 void DeSerializerPXDModule::terminate()
116 {
117  B2INFO("terminate called");
118 }
119 
A class definition of an input module for Sequential ROOT I/O.
Base class for Modules.
Definition: Module.h:72
#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.