EUDAQ
 All Classes Namespaces Files Functions Variables Pages
FileWriter.hh
1 #ifndef EUDAQ_INCLUDED_FileWriter
2 #define EUDAQ_INCLUDED_FileWriter
3 
4 #include "eudaq/DetectorEvent.hh"
5 #include <vector>
6 #include <string>
7 
8 namespace eudaq {
9 
10  class DLLEXPORT FileWriter {
11  public:
12  FileWriter();
13  virtual void StartRun(unsigned runnumber) = 0;
14  virtual void WriteEvent(const DetectorEvent &) = 0;
15  virtual uint64_t FileBytes() const = 0;
16  void SetFilePattern(const std::string &p) { m_filepattern = p; }
17  virtual ~FileWriter() {}
18 
19  protected:
20  std::string m_filepattern;
21  };
22 
23  class DLLEXPORT FileWriterFactory {
24  public:
25  static FileWriter *Create(const std::string &name,
26  const std::string &params = "");
27  template <typename T> static void Register(const std::string &name) {
28  do_register(name, filewriterfactory<T>);
29  }
30  typedef FileWriter *(*factoryfunc)(const std::string &);
31  static std::vector<std::string> GetTypes();
32 
33  private:
34  template <typename T>
35  static FileWriter *filewriterfactory(const std::string &params) {
36  return new T(params);
37  }
38  static void do_register(const std::string &name, factoryfunc);
39  };
40 
41  template <typename T> class RegisterFileWriter {
42  public:
43  RegisterFileWriter(const std::string &name) {
44  FileWriterFactory::Register<T>(name);
45  }
46  };
47 }
48 
49 #endif // EUDAQ_INCLUDED_FileWriter
Definition: FileWriter.hh:23
Definition: FileWriter.hh:41
Definition: DetectorEvent.hh:12
Definition: FileWriter.hh:10