DABC (Data Acquisition Backbone Core)  2.9.9
LmdInput.cxx
Go to the documentation of this file.
1 // $Id: LmdInput.cxx 4479 2020-04-15 14:30:52Z 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 "mbs/LmdInput.h"
17 
18 #include <cstring>
19 #include <cstdlib>
20 
21 #include "dabc/Manager.h"
22 
23 #include "mbs/MbsTypeDefs.h"
24 
26  dabc::FileInput(url),
27  fFile()
28 {
29  if (url.HasOption("rfio"))
30  fFile.SetIO((dabc::FileInterface*) dabc::mgr.CreateAny("rfio::FileInterface"), true);
31  else if (url.HasOption("ltsm"))
32  fFile.SetIO((dabc::FileInterface*) dabc::mgr.CreateAny("ltsm::FileInterface"), true);
33 
34 }
35 
37 {
38  CloseFile();
39 }
40 
42 {
43  if (!dabc::FileInput::Read_Init(wrk, cmd)) return false;
44 
45  return OpenNextFile();
46 }
47 
49 {
50  CloseFile();
51 
52  if (!TakeNextFileName()) return false;
53 
54  if (!fFile.OpenReading(CurrentFileName().c_str())) {
55  EOUT("Cannot open file %s for reading", CurrentFileName().c_str());
56  return false;
57  }
58 
59  DOUT1("Open lmd file %s for reading", CurrentFileName().c_str());
60 
61  return true;
62 }
63 
64 
66 {
67  fFile.Close();
68  ClearCurrentFileName();
69  return true;
70 }
71 
73 {
74  // get size of the buffer which should be read from the file
75 
76  if (!fFile.isReading())
77  if (!OpenNextFile()) return dabc::di_EndOfStream;
78 
79  return dabc::di_DfltBufSize;
80 }
81 
83 {
84  uint64_t bufsize = 0;
85 
86  while (true) {
87 
88  if (!fFile.isReading()) return dabc::di_Error;
89 
90  // TODO: read into segmented buffer
91 
92  bufsize = ((uint64_t) (buf.SegmentSize(0) * fReduce))/8*8;
93 
94  if (!fFile.ReadBuffer(buf.SegmentPtr(0), &bufsize)) {
95  DOUT3("File %s return 0 numev for buffer %u - end of file", CurrentFileName().c_str(), buf.GetTotalSize());
96  if (!OpenNextFile()) return dabc::di_EndOfStream;
97  }
98 
99  if (bufsize==0) return dabc::di_Error;
100  break;
101  }
102 
103  // DOUT0("Read buffer of size %u total %u", (unsigned) bufsize, (unsigned) buf.SegmentSize(0));
104 
105  buf.SetTotalSize(bufsize);
107 
108  return dabc::di_Ok;
109 }
void SetIO(FileInterface *_io, bool _ioowner=false)
Definition: BinaryFile.h:114
Reference on memory from memory pool.
Definition: Buffer.h:135
unsigned SegmentSize(unsigned n=0) const
Returns size on the segment, no any boundary checks.
Definition: Buffer.h:174
void SetTotalSize(BufferSize_t len)
Set total length of the buffer to specified value Size cannot be bigger than original size of the buf...
Definition: Buffer.cxx:99
BufferSize_t GetTotalSize() const
Return total size of all buffer segments.
Definition: Buffer.cxx:91
void SetTypeId(unsigned tid)
Definition: Buffer.h:151
void * SegmentPtr(unsigned n=0) const
Returns pointer on the segment, no any boundary checks.
Definition: Buffer.h:171
Represents command with its arguments.
Definition: Command.h:99
virtual bool Read_Init(const WorkerRef &wrk, const Command &cmd)
Initialize data input, using port and command.
Definition: DataIO.cxx:139
Defines and implements basic POSIX file interface.
Definition: BinaryFile.h:33
Uniform Resource Locator interpreter.
Definition: Url.h:33
bool HasOption(const std::string &optname) const
Definition: Url.h:70
Reference on dabc::Worker
Definition: Worker.h:466
bool OpenNextFile()
Definition: LmdInput.cxx:48
bool CloseFile()
Definition: LmdInput.cxx:65
LmdInput(const dabc::Url &url)
Definition: LmdInput.cxx:25
virtual bool Read_Init(const dabc::WorkerRef &wrk, const dabc::Command &cmd)
Initialize data input, using port and command.
Definition: LmdInput.cxx:41
virtual unsigned Read_Complete(dabc::Buffer &buf)
Complete reading of the buffer from source,.
Definition: LmdInput.cxx:82
mbs::LmdFile fFile
Definition: LmdInput.h:34
virtual ~LmdInput()
Definition: LmdInput.cxx:36
virtual unsigned Read_Size()
Defines required buffer size for next operation.
Definition: LmdInput.cxx:72
#define DOUT3(args ...)
Definition: logging.h:176
#define EOUT(args ...)
Definition: logging.h:150
#define DOUT1(args ...)
Definition: logging.h:162
Event manipulation API.
Definition: api.h:23
ManagerRef mgr
Definition: Manager.cxx:42
@ di_Ok
Definition: DataIO.h:38
@ di_DfltBufSize
Definition: DataIO.h:42
@ di_Error
Definition: DataIO.h:40
@ di_EndOfStream
Definition: DataIO.h:37
@ mbt_MbsEvents
Definition: MbsTypeDefs.h:348