DABC (Data Acquisition Backbone Core)  2.9.9
HldInput.cxx
Go to the documentation of this file.
1 // $Id: HldInput.cxx 4480 2020-04-15 14:40:06Z 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/HldInput.h"
17 
18 #include <cstring>
19 #include <cstdlib>
20 
21 #include "dabc/Manager.h"
22 
23 #include "hadaq/HadaqTypeDefs.h"
24 
25 
27  dabc::FileInput(url),
28  fFile()
29 {
30  if (url.HasOption("rfio"))
31  fFile.SetIO((dabc::FileInterface*) dabc::mgr.CreateAny("rfio::FileInterface"), true);
32  else if (url.HasOption("ltsm"))
33  fFile.SetIO((dabc::FileInterface*) dabc::mgr.CreateAny("ltsm::FileInterface"), true);
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.OpenRead(CurrentFileName().c_str())) {
55  EOUT("Cannot open file %s for reading", CurrentFileName().c_str());
56  return false;
57  }
58 
59  DOUT1("Open hld 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  if (!fFile.isReading()) return dabc::di_Error;
75 
76  if (fFile.eof())
77  if (!OpenNextFile()) return dabc::di_EndOfStream;
78 
79  return dabc::di_DfltBufSize;
80 }
81 
83 {
84  if (fFile.eof()) {
85  EOUT("EOF should not happen when buffer reading should be started");
86  return dabc::di_Error;
87  }
88 
89  // only first segment can be used for reading
90  uint32_t bufsize = ((uint32_t) (buf.SegmentSize(0) * fReduce) / 4) * 4;
91 
92  if (!fFile.ReadBuffer(buf.SegmentPtr(0), &bufsize)) {
93  // if by chance reading of buffer leads to eof, skip buffer and let switch file on the next turn
94  if (fFile.eof()) return dabc::di_SkipBuffer;
95  CloseFile();
96  return dabc::di_Error;
97  }
98 
100  buf.SetTotalSize(bufsize);
101  DOUT3("HLD file read %u bytes from %s file", (unsigned) bufsize, CurrentFileName().c_str());
102 
103  return dabc::di_Ok;
104 }
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
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
virtual unsigned Read_Complete(dabc::Buffer &buf)
Complete reading of the buffer from source,.
Definition: HldInput.cxx:82
bool OpenNextFile()
Definition: HldInput.cxx:48
virtual ~HldInput()
Definition: HldInput.cxx:36
bool CloseFile()
Definition: HldInput.cxx:65
virtual unsigned Read_Size()
Defines required buffer size for next operation.
Definition: HldInput.cxx:72
hadaq::HldFile fFile
Definition: HldInput.h:34
virtual bool Read_Init(const dabc::WorkerRef &wrk, const dabc::Command &cmd)
Initialize data input, using port and command.
Definition: HldInput.cxx:41
HldInput(const dabc::Url &ulr)
Definition: HldInput.cxx:26
#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_SkipBuffer
Definition: DataIO.h:41
@ di_Error
Definition: DataIO.h:40
@ di_EndOfStream
Definition: DataIO.h:37
@ mbt_HadaqEvents
Definition: HadaqTypeDefs.h:24