DABC (Data Acquisition Backbone Core)  2.9.9
api.cxx
Go to the documentation of this file.
1 // $Id: api.cxx 4692 2021-02-23 10:13:13Z linev $
2 
3 /************************************************************
4  * The Data Acquisition Backbone Core (DABC) *
5  ************************************************************
6  * Copyright (C) 2009 - *
7  * GSI Helmholtzzentrum fuer Schwerionenforschung GmbH *
8  * Planckstr. 1, 64291 Darmstadt, Germany *
9  * Contact: http://dabc.gsi.de *
10  ************************************************************
11  * This software can be used under the GPL license *
12  * agreements as stated in LICENSE.txt file *
13  * which is part of the distribution. *
14  ************************************************************/
15 
16 #include "hadaq/api.h"
17 
18 hadaq::ReadoutModule::ReadoutModule(const std::string &name, dabc::Command cmd) :
19  mbs::ReadoutModule(name, cmd),
20  fIter2()
21 {
22 }
23 
25 {
26  if (fIter2.Reset(buf))
27  return dabc::cmd_true;
28 
29  return dabc::cmd_false;
30 }
31 
32 // =========================================================================
33 
34 
36 {
37  std::string newurl = src;
38 
39  if (((newurl.find(".hld") != std::string::npos) || (newurl.find(".HLD") != std::string::npos)) &&
40  (newurl.find("hld://") == std::string::npos))
41  newurl = std::string("hld://") + src;
42 
43  return DoConnect(newurl, "hadaq::ReadoutModule");
44 }
45 
46 
47 hadaq::RawEvent *hadaq::ReadoutHandle::NextEvent(double tmout, double maxage)
48 {
49  if (null()) return nullptr;
50 
51  bool intime = GetObject()->GetEventInTime(maxage);
52 
53  // check that HADAQ event can be produced
54  // while hadaq events can be read only from file, ignore maxage parameter here
55  if (intime && GetObject()->fIter2.NextEvent())
56  return GetObject()->fIter2.evnt();
57 
58  // this is a case, when hadaq event packed into MBS event
59  if (mbs::ReadoutHandle::NextEvent(tmout, maxage))
61 
62  // check again that HADAQ event can be produced
63  if (GetObject()->fIter2.NextEvent())
64  return GetObject()->fIter2.evnt();
65 
66  return nullptr;
67 }
68 
70 {
71  if (null()) return nullptr;
72 
73  if (GetObject()->fIter2.evnt()) return GetObject()->fIter2.evnt();
74 
76 
77  if (!mbsev) return nullptr;
78 
79  mbs::SubeventHeader *mbssub = mbsev->NextSubEvent(0);
80 
81  if (mbssub && (mbssub->FullSize() == mbsev->SubEventsSize())) {
82  hadaq::RawEvent *raw = (hadaq::RawEvent*) mbssub->RawData();
83 
84  if (raw && (raw->GetSize() == mbssub->RawDataSize())) return raw;
85  }
86  return nullptr;
87 }
Reference on memory from memory pool.
Definition: Buffer.h:135
Represents command with its arguments.
Definition: Command.h:99
bool Reset(const dabc::Buffer &buf)
Initialize iterator on the beginning of the buffer, buffer instance should exists until end of iterat...
Definition: Iterator.cxx:59
hadaq::RawEvent * GetEvent()
Get current event pointer.
Definition: api.cxx:69
hadaq::RawEvent * NextEvent(double tm=1.0, double maxage=-1.)
Retrieve next event from the server.
Definition: api.cxx:47
static ReadoutHandle Connect(const std::string &url)
Connect with data source.
Definition: api.cxx:35
ReadoutModule(const std::string &name, dabc::Command cmd)
Definition: api.cxx:18
hadaq::ReadIterator fIter2
iterator over HADAQ buffers
Definition: api.h:36
int AcceptBuffer(dabc::Buffer &buf)
Definition: api.cxx:24
mbs::EventHeader * GetEvent()
Get current event pointer.
Definition: api.cxx:211
mbs::EventHeader * NextEvent(double tmout=1.0, double maxage=-1.)
Retrieve next event from the server One could specify timeout (how long one should wait for next even...
Definition: api.cxx:190
@ cmd_false
Definition: Command.h:37
@ cmd_true
Definition: Command.h:38
Support for MBS - standard GSI DAQ.
Definition: api.h:36
uint32_t GetSize() const
Definition: defines.h:182
Hadaq event structure.
Definition: defines.h:443
SubeventHeader * NextSubEvent(SubeventHeader *prev) const
Definition: MbsTypeDefs.h:136
uint32_t SubEventsSize() const
Definition: MbsTypeDefs.h:130
uint32_t FullSize() const
Definition: LmdTypeDefs.h:55
MBS subevent
Definition: MbsTypeDefs.h:40
void * RawData() const
Definition: MbsTypeDefs.h:75
uint32_t RawDataSize() const
Definition: MbsTypeDefs.h:78