Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-08-06 09:38:19

0001 // -*- C++ -*-
0002 //
0003 // TreeFactory.h is a part of ThePEG - Toolkit for HEP Event Generation
0004 // Copyright (C) 1999-2019 Leif Lonnblad
0005 //
0006 // ThePEG is licenced under version 3 of the GPL, see COPYING for details.
0007 // Please respect the MCnet academic guidelines, see GUIDELINES for details.
0008 //
0009 #ifndef LWH_TreeFactory_H
0010 #define LWH_TreeFactory_H
0011 //
0012 // This is the declaration of the TreeFactory class.
0013 //
0014 
0015 #include "AITreeFactory.h"
0016 #include <string>
0017 #include <stdexcept>
0018 #include "Tree.h"
0019 
0020 namespace LWH {
0021 
0022 using namespace AIDA;
0023 
0024 /**
0025  * The creator of trees.
0026  */
0027 class TreeFactory: public ITreeFactory {
0028 
0029 public:
0030 
0031   /// Destructor.
0032   virtual ~TreeFactory() {
0033     clear();
0034   }
0035 
0036   /**
0037    * Creates a new tree that is not associated with a store.
0038    */
0039   ITree * create() {
0040     Tree * tree = new Tree;
0041     trees.insert(tree);
0042     return tree;
0043   }
0044 
0045   /**
0046    * Creates a new Tree and associates it with a store.
0047    * The store is assumed to be write-only.
0048    * The store will be created.
0049    * @param storeName The name of the store, if empty (""), the tree is
0050    *                  created in memory and therefore will not be associated
0051    *                  with a file.
0052    */
0053   Tree * createTree(const std::string & storeName) {
0054     return new Tree(storeName);
0055   }
0056 
0057   /**
0058    * Creates a new Tree and associates it with a store.
0059    * The store is assumed to be write-only.
0060    * The store will be created.
0061    * @param storeName The name of the store, if empty (""), the tree is
0062    *                  created in memory and therefore will not be associated
0063    *                  with a file.
0064    * @param storeType must be "xml".
0065    * @param readOnly  must be false since we cannot read in trees.
0066    * @param createNew must be true indicating that the file will be created
0067    */
0068   ITree * create(const std::string & storeName,
0069          const std::string & storeType = "",
0070          bool readOnly = false, bool createNew = false,
0071          const std::string & = "") {
0072     if ( storeType != "xml" && storeType != "" && storeType != "flat" )
0073       throw std::runtime_error("Can only store trees in xml or flat format.");
0074     if ( readOnly || !createNew )
0075       throw std::runtime_error("Cannot read in trees.");
0076     return new Tree(storeName, storeType != "flat");
0077   }
0078 
0079 private:
0080 
0081   /** Delete all trees. */
0082   void clear() {
0083     for ( std::set<Tree *>::iterator it = trees.begin();
0084       it != trees.end(); ++it ) delete *it;
0085     trees.clear();
0086   }
0087 
0088   /** The created trees. */
0089   std::set<Tree *> trees;
0090 
0091 };
0092 
0093 }
0094 
0095 #endif /* LWH_TreeFactory_H */