FairRoot
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
FairMbsStreamSource.cxx
Go to the documentation of this file.
1 // -----------------------------------------------------------------------------
2 // ----- FairMbsStreamSource source file -----
3 // ----- -----
4 // ----- created by C. Simon on 2014-09-12 -----
5 // ----- -----
6 // ----- based on FairLmdSource by D. Kresan -----
7 // ----- -----
8 // ----- revision 24905, 2014-05-12 -----
9 // -----------------------------------------------------------------------------
10 
11 #include "FairMbsStreamSource.h"
12 
13 #include "FairLogger.h"
14 
16  : FairMbsSource()
17  , fServerName(tServerName)
18  , fxInputChannel(nullptr)
19  , fxEvent(nullptr)
20  , fxBuffer(nullptr)
21  , fxEventData(nullptr)
22  , fxSubEvent(nullptr)
23 {}
24 
26  : FairMbsSource(source)
27  , fServerName(source.GetServerName())
28  , fxInputChannel(nullptr)
29  , fxEvent(nullptr)
30  , fxBuffer(nullptr)
31  , fxEventData(nullptr)
32  , fxSubEvent(nullptr)
33 {}
34 
36 
38 {
39  if (!ConnectToServer()) {
40  return kFALSE;
41  }
42 
43  return kTRUE;
44 }
45 
46 Bool_t FairMbsStreamSource::ConnectToServer()
47 {
48  Int_t inputMode = GETEVT__STREAM;
49  fxInputChannel = new s_evt_channel;
50  s_filhe fxInfoHeader;
51  void* headptr = &fxInfoHeader;
52  INTS4 status;
53 
54  LOG(info) << "FairMbsStreamSource::ConnectToServer()";
55  LOG(info) << Form("- open connection to MBS stream server %s...", fServerName.Data());
56 
57  status = f_evt_get_open(
58  inputMode, const_cast<char*>(fServerName.Data()), fxInputChannel, static_cast<Char_t**>(headptr), 1, 1);
59 
60  CHARS* sErrorString = nullptr;
61  f_evt_error(status, sErrorString, 0);
62 
63  if (GETEVT__SUCCESS != status) {
64  return kFALSE;
65  }
66 
67  LOG(info) << Form("- connection to MBS stream server %s established.", fServerName.Data());
68 
69  return kTRUE;
70 }
71 
73 {
74  void* evtptr = &fxEvent;
75  void* buffptr = &fxBuffer;
76 
77  LOG(debug2) << "FairLmdSource::ReadEvent => New event ";
78 
79  Int_t status = f_evt_get_event(fxInputChannel, static_cast<INTS4**>(evtptr), static_cast<INTS4**>(buffptr));
80 
81  LOG(debug2) << "FairLmdSource::ReadEvent => f_evt_get_event status: " << status;
82 
83  if (GETEVT__SUCCESS != status) {
84  LOG(info) << "FairMbsStreamSource::ReadEvent()";
85 
86  CHARS* sErrorString = nullptr;
87  f_evt_error(status, sErrorString, 0);
88 
89  return 1;
90  }
91 
92  Int_t nrSubEvts = f_evt_get_subevent(fxEvent, 0, nullptr, nullptr, nullptr);
93 
94  Int_t sebuflength;
95  Short_t setype;
96  Short_t sesubtype;
97  Short_t seprocid;
98  Short_t sesubcrate;
99  Short_t secontrol;
100 
101  LOG(debug2) << "FairLmdSource::ReadEvent => Found " << nrSubEvts << " Sub-event ";
102 
103  for (Int_t i = 1; i <= nrSubEvts; i++) {
104  void* SubEvtptr = &fxSubEvent;
105  void* EvtDataptr = &fxEventData;
106  Int_t nrlongwords;
107 
108  status = f_evt_get_subevent(
109  fxEvent, i, static_cast<Int_t**>(SubEvtptr), static_cast<Int_t**>(EvtDataptr), &nrlongwords);
110 
111  sebuflength = nrlongwords;
112  setype = fxSubEvent->i_type;
113  sesubtype = fxSubEvent->i_subtype;
114  seprocid = fxSubEvent->i_procid;
115  sesubcrate = fxSubEvent->h_subcrate;
116  secontrol = fxSubEvent->h_control;
117 
118  if (!Unpack(fxEventData, sebuflength, setype, sesubtype, seprocid, sesubcrate, secontrol)) {
119  return 2;
120  }
121  }
122 
123  return 0;
124 }
125 
127 {
128  Int_t status = f_evt_get_close(fxInputChannel);
129 
130  LOG(info) << "FairMbsStreamSource::Close()";
131 
132  CHARS* sErrorString = nullptr;
133  f_evt_error(status, sErrorString, 0);
134 }
135 
#define GETEVT__SUCCESS
Definition: f_evt.h:130
INTS4 f_evt_get_subevent(s_ve10_1 *ps_ve10_1, INTS4 l_subevent, INTS4 **pl_se, INTS4 **pl_d, INTS4 *pl_lwords)
Definition: f_evt.c:228
INTS4 f_evt_get_close(s_evt_channel *ps_chan)
Definition: f_evt.c:1189
CHARS h_subcrate
Definition: s_ves10_1.h:35
INTS4 f_evt_get_open(INTS4 l_mode, CHARS *pc_server, s_evt_channel *ps_chan, CHARS **ps_info, INTS4 l_sample, INTS4 l_param)
Definition: f_evt.c:555
Bool_t Unpack(Int_t *data, Int_t size, Short_t type, Short_t subType, Short_t procId, Short_t subCrate, Short_t control)
INTS2 i_procid
Definition: s_ves10_1.h:34
INTS4 f_evt_error(INTS4 l_error, CHARS *pc_dest, INTS4 l_out)
Definition: f_evt.c:1756
ClassImp(FairEventBuilder)
FairMbsStreamSource(TString tServerName)
int INTS4
Definition: typedefs.h:21
virtual Int_t ReadEvent(UInt_t=0)
INTS2 i_type
Definition: s_ves10_1.h:32
char CHARS
Definition: typedefs.h:15
INTS4 f_evt_get_event(s_evt_channel *ps_chan, INTS4 **ppl_buffer, INTS4 **ppl_goobuf)
Definition: f_evt.c:987
INTS2 i_subtype
Definition: s_ves10_1.h:33
#define GETEVT__STREAM
Definition: f_evt.h:120
CHARS h_control
Definition: s_ves10_1.h:36