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