FairRoot
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
FairRemoteSource.cxx
Go to the documentation of this file.
1 /********************************************************************************
2  * Copyright (C) 2014 GSI Helmholtzzentrum fuer Schwerionenforschung GmbH *
3  * *
4  * This software is distributed under the terms of the *
5  * GNU Lesser General Public Licence (LGPL) version 3, *
6  * copied verbatim in the file "LICENSE" *
7  ********************************************************************************/
8 // -----------------------------------------------------------------------------
9 // ----- -----
10 // ----- FairRemoteSource -----
11 // ----- Created 12.04.2013 by D.Kresan -----
12 // -----------------------------------------------------------------------------
13 #include "FairRemoteSource.h"
14 
15 #include "MRevBuffer.h"
16 #include "ptrevmbsdef.h" // MBS data definitions
17 
18 #include <TSocket.h>
19 #include <unistd.h> // usleep
20 
22  : FairMbsSource()
23  , fNode(node)
24  , fSocket(nullptr)
25  , fBuffer(new MRevBuffer(1))
26  , fREvent(nullptr)
27 {}
28 
30  : FairMbsSource(source)
31  , fNode(const_cast<char*>(source.GetNode()))
32  , fSocket(nullptr)
33  , fBuffer(new MRevBuffer(1))
34  , fREvent(nullptr)
35 {}
36 
38 
40 {
41  fBuffer->RevStatus(0);
42  fSocket = fBuffer->RevOpen(fNode, 6003, 0);
43  fBuffer->RevStatus(0);
44  if (!fSocket) {
45  return kFALSE;
46  }
47  return kTRUE;
48 }
49 
51 {
52  usleep(10000);
53  fREvent = fBuffer->RevGet(fSocket, 0, 0);
54  fBuffer->RevStatus(0);
55  if (!fREvent) {
56  return 1;
57  }
58 
59  // Decode event header
60  Bool_t result = Unpack(fREvent->GetData(), sizeof(sMbsEv101), -2, -2, -2, -2, -2);
61 
62  for (Int_t i = 0; i < fREvent->nSubEvt; i++) {
63  if (Unpack(fREvent->pSubEvt[i],
64  fREvent->subEvtSize[i],
65  fREvent->subEvtType[i],
66  fREvent->subEvtSubType[i],
67  fREvent->subEvtProcId[i],
68  fREvent->subEvtSubCrate[i],
69  fREvent->subEvtControl[i])) {
70  result = kTRUE;
71  }
72  }
73 
74  if (!result) {
75  return 2;
76  }
77 
78  return 0;
79 }
80 
82 {
83  fBuffer->RevClose(fSocket);
84  fBuffer->RevStatus(0);
85 }
86 
Short_t subEvtSubType[100]
Definition: MRevBuffer.h:57
Int_t * GetData()
Definition: MRevBuffer.h:52
Int_t RevStatus(Int_t iOut)
Definition: MRevBuffer.cxx:817
Int_t subEvtSize[100]
Definition: MRevBuffer.h:55
Bool_t Unpack(Int_t *data, Int_t size, Short_t type, Short_t subType, Short_t procId, Short_t subCrate, Short_t control)
Short_t subEvtProcId[100]
Definition: MRevBuffer.h:58
void RevClose(TSocket *pSocket)
Definition: MRevBuffer.cxx:849
Short_t subEvtSubCrate[100]
Definition: MRevBuffer.h:59
virtual ~FairRemoteSource()
Short_t subEvtType[100]
Definition: MRevBuffer.h:56
virtual void Close()
ClassImp(FairEventBuilder)
Short_t subEvtControl[100]
Definition: MRevBuffer.h:60
virtual Bool_t Init()
FairRemoteSource(char *node)
REvent * RevGet(TSocket *pSocket, Int_t iFlush, Int_t iSkip)
Definition: MRevBuffer.cxx:233
Int_t nSubEvt
Definition: MRevBuffer.h:54
TSocket * RevOpen(char *pNode, Int_t iPort, Int_t iEvent)
Definition: MRevBuffer.cxx:162
virtual Int_t ReadEvent(UInt_t=0)
Int_t * pSubEvt[100]
Definition: MRevBuffer.h:61