Belle II Software  release-08-01-10
FileHandler.h
1 /**************************************************************************
2  * basf2 (Belle II Analysis Software Framework) *
3  * Author: The Belle II Collaboration *
4  * *
5  * See git log for contributors and copyright holders. *
6  * This file is licensed under LGPL-3.0, see LICENSE.md. *
7  **************************************************************************/
8 
9 #pragma once
10 
11 #include <framework/gearbox/InputHandler.h>
12 #include <boost/iostreams/filtering_stream.hpp>
13 #include <boost/format.hpp>
14 
15 namespace Belle2 {
20  namespace gearbox {
21 
23  class FileContext: public InputContext {
24  public:
29  FileContext(const std::string& filename, bool compressed);
31  virtual int readXmlData(char* buffer, int buffsize) override
32  {
33  m_stream.read(buffer, buffsize);
34  return m_stream.gcount();
35  }
37  virtual ~FileContext() {}
38  protected:
40  boost::iostreams::filtering_istream m_stream;
41  };
42 
67  class FileHandler: public InputHandler {
68  public:
73  explicit FileHandler(const std::string& uri);
75  virtual ~FileHandler() {}
80  virtual InputContext* open(const std::string& path) override;
81  protected:
83  std::string m_path;
85  boost::format m_pathformat;
87  bool m_rundependence {false};
88  };
89  } //namespace gearbox
91 } //namespace Belle2
InputContext which serves the content of a plain file.
Definition: FileHandler.h:23
virtual int readXmlData(char *buffer, int buffsize) override
Return a block of the data.
Definition: FileHandler.h:31
boost::iostreams::filtering_istream m_stream
stream to read data from
Definition: FileHandler.h:40
FileContext(const std::string &filename, bool compressed)
Open the given filename.
Definition: FileHandler.cc:28
virtual ~FileContext()
Close the file.
Definition: FileHandler.h:37
InputHandler which will read XML from plain files, optionally gzip compressed.
Definition: FileHandler.h:67
virtual ~FileHandler()
empty, virtual destructor
Definition: FileHandler.h:75
std::string m_path
Search path to look for files.
Definition: FileHandler.h:83
virtual InputContext * open(const std::string &path) override
create a new FileContext by searching the file system for a file named like path.
Definition: FileHandler.cc:64
FileHandler(const std::string &uri)
Instantiate a new file handler, using the uri as base search path.
Definition: FileHandler.cc:35
boost::format m_pathformat
format object in case of run-dependent data path
Definition: FileHandler.h:85
bool m_rundependence
bool indicating whether the data path is run-dependent
Definition: FileHandler.h:87
Class representing a resource context for gearbox.
Definition: InputHandler.h:25
Class to provide an InputContext for a given XML resource name.
Definition: InputHandler.h:47
Abstract base class for different kinds of events.