Belle II Software  release-05-02-19
FileHandler.h
1 /**************************************************************************
2  * BASF2 (Belle Analysis Framework 2) *
3  * Copyright(C) 2010-2011 Belle II Collaboration *
4  * *
5  * Author: The Belle II Collaboration *
6  * Contributors: Martin Ritter *
7  * *
8  * This software is provided "as is" without any warranty. *
9  **************************************************************************/
10 
11 #pragma once
12 
13 #include <framework/gearbox/InputHandler.h>
14 #include <boost/iostreams/filtering_stream.hpp>
15 #include <boost/format.hpp>
16 
17 namespace Belle2 {
22  namespace gearbox {
23 
25  class FileContext: public InputContext {
26  public:
31  FileContext(const std::string& filename, bool compressed);
33  virtual int readXmlData(char* buffer, int buffsize) override
34  {
35  m_stream.read(buffer, buffsize);
36  return m_stream.gcount();
37  }
39  virtual ~FileContext() {}
40  protected:
42  boost::iostreams::filtering_istream m_stream;
43  };
44 
69  class FileHandler: public InputHandler {
70  public:
75  explicit FileHandler(const std::string& uri);
77  virtual ~FileHandler() {}
82  virtual InputContext* open(const std::string& path) override;
83  protected:
85  std::string m_path;
87  boost::format m_pathformat;
89  bool m_rundependence {false};
90  };
91  } //namespace gearbox
93 } //namespace Belle2
Belle2::gearbox::FileHandler::FileHandler
FileHandler(const std::string &uri)
Instantiate a new file handler, using the uri as base search path.
Definition: FileHandler.cc:36
Belle2::gearbox::FileContext::readXmlData
virtual int readXmlData(char *buffer, int buffsize) override
Return a block of the data.
Definition: FileHandler.h:41
Belle2::gearbox::FileHandler::~FileHandler
virtual ~FileHandler()
empty, virtual destructor
Definition: FileHandler.h:85
Belle2::gearbox::FileContext::m_stream
boost::iostreams::filtering_istream m_stream
stream to read data from
Definition: FileHandler.h:50
Belle2
Abstract base class for different kinds of events.
Definition: MillepedeAlgorithm.h:19
FileHandler
Definition: storagerecord.cc:42
Belle2::gearbox::FileContext::FileContext
FileContext(const std::string &filename, bool compressed)
Open the given filename.
Definition: FileHandler.cc:29
Belle2::gearbox::FileHandler::m_path
std::string m_path
Search path to look for files.
Definition: FileHandler.h:93
Belle2::gearbox::InputContext
Class representing a resource context for gearbox.
Definition: InputHandler.h:35
Belle2::gearbox::FileContext::~FileContext
virtual ~FileContext()
Close the file.
Definition: FileHandler.h:47
Belle2::gearbox::FileHandler::m_pathformat
boost::format m_pathformat
format object in case of run-dependent data path
Definition: FileHandler.h:95
Belle2::gearbox::FileHandler::open
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:65
Belle2::gearbox::FileHandler::m_rundependence
bool m_rundependence
bool indicating whether the data path is run-dependent
Definition: FileHandler.h:97