ThePEG  1.8.0
TreeFactory.h
1 // -*- C++ -*-
2 //
3 // TreeFactory.h is a part of ThePEG - Toolkit for HEP Event Generation
4 // Copyright (C) 1999-2011 Leif Lonnblad
5 //
6 // ThePEG is licenced under version 2 of the GPL, see COPYING for details.
7 // Please respect the MCnet academic guidelines, see GUIDELINES for details.
8 //
9 #ifndef LWH_TreeFactory_H
10 #define LWH_TreeFactory_H
11 //
12 // This is the declaration of the TreeFactory class.
13 //
14 
15 #include "AITreeFactory.h"
16 #include <string>
17 #include <stdexcept>
18 #include "Tree.h"
19 
20 namespace LWH {
21 
22 using namespace AIDA;
23 
27 class TreeFactory: public ITreeFactory {
28 
29 public:
30 
32  virtual ~TreeFactory() {
33  clear();
34  }
35 
39  ITree * create() {
40  Tree * tree = new Tree;
41  trees.insert(tree);
42  return tree;
43  }
44 
53  Tree * createTree(const std::string & storeName) {
54  return new Tree(storeName);
55  }
56 
68  ITree * create(const std::string & storeName,
69  const std::string & storeType = "",
70  bool readOnly = false, bool createNew = false,
71  const std::string & = "") {
72  if ( storeType != "xml" && storeType != "" && storeType != "flat" )
73  throw std::runtime_error("Can only store trees in xml or flat format.");
74  if ( readOnly || !createNew )
75  throw std::runtime_error("Cannot read in trees.");
76  return new Tree(storeName, storeType != "flat");
77  }
78 
79 private:
80 
82  void clear() {
83  for ( std::set<Tree *>::iterator it = trees.begin();
84  it != trees.end(); ++it ) delete *it;
85  trees.clear();
86  }
87 
89  std::set<Tree *> trees;
90 
91 };
92 
93 }
94 
95 #endif /* LWH_TreeFactory_H */