1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325
|
// -*- C++ -*-
//
// Repository.h is a part of ThePEG - Toolkit for HEP Event Generation
// Copyright (C) 1999-2011 Leif Lonnblad
//
// ThePEG is licenced under version 2 of the GPL, see COPYING for details.
// Please respect the MCnet academic guidelines, see GUIDELINES for details.
//
#ifndef ThePEG_Repository_H
#define ThePEG_Repository_H
// This is the declaration of the Repository class.
#include "ThePEG/Config/ThePEG.h"
#include "BaseRepository.h"
#include "EventGenerator.h"
#include "ThePEG/PDT/ParticleData.h"
#include "ThePEG/PDT/MatcherBase.h"
namespace ThePEG {
/**
* Repository inherits from the BaseRepository class. While
* BaseRepository is fairly general and could in principle be used for
* any program where sets of InterfacedBase objects are managed, the
* Repository is ThePEG specific in that it deals with ParticleData,
* ParticleMatchers and EventGenerators.
*
* One main function is to write an EventGenerator to disk using
* saveRun(). Here all objects needed for the run, including the
* EventGenerator is cloned and isolated from the other objects in the
* Repository (and are hence not handled by the Repository anymore)
* before they are all persistently written out to disk.
*
* The Register() function simply pass the objects to the corresonding
* method in BaseRepository, but if the object is a ParticleData or a
* ParticleMatcher, they are stored separately.
*
* @see BaseRepository
* @see InterfacedBase
* @see ParticleData
* @see ParticleMatcher
* @see EventGenerator
*
*/
class Repository: public BaseRepository {
public:
/** A map of EventGenerator objects indexed by their run name. */
typedef map<string,EGPtr> GeneratorMap;
public:
/** @name Standsrd constructors and destructors */
//@{
/**
* The default constructor is the only one that should be used.
*/
Repository();
/**
* The destructor will do some clean-up when the last Repository is
* deleted.
*/
~Repository();
public:
/** @name Functions for register objects in the Repository. */
//@{
/**
* Register an object with BaseRepository::Register() and add it to
* the list of particles or matchers if of any of those
* types.
*/
static void Register(IBPtr);
/**
* Register an object with BaseRepository::Register() and add it to
* the list of particles or matchers if of any of those
* types.
*/
static void Register(IBPtr, string newName);
//@}
/** @name Access ParticleData and MatcherBase objects in the
Repository. */
//@{
/**
* Add a particle to the list of default ones. If one of the same
* type alredy existed, it is removed from the list (but not from
* the repository).
*/
static void defaultParticle(tPDPtr);
/**
* Get a pointer to the default particle of the given type or
* generic name.
*/
static PDPtr defaultParticle(PID id);
/**
* Get a pointer to a particle based on the given path or name. The
* argument is first treated as a path to an object. If no such
* particle object is found, the argument is treated as a generic
* particle PDGName and is searched for among the default set of
* particles.
*/
static tPDPtr findParticle(string name);
/**
* Return the set of all particles in the repository.
*/
static const ParticleDataSet & allParticles() { return particles(); }
/**
* Return the set of all matchers in the repository.
*/
static const MatcherSet & allMatchers() { return matchers(); }
/**
* Find a matcher with a given generic name
*/
static tPMPtr findMatcher(string name);
/**
* Special function for copying particles. Also corresponding
* anti-particle is copied to the same directory. In addition, their
* decay modes are copied.
*/
static string copyParticle(tPDPtr, string);
//@}
/** @name Functions to isolate Eventgenerator objects. */
//@{
/**
* Isolate an event generator, \a eg, and save it to disk in a file
* named \a name (with <code>.run</code> appended.
*/
static EGPtr makeRun(tEGPtr eg, string name);
/**
* Isolate an event generatorn, named \a EGname, set its run \a name
* and save it to a file named \a filename.
*/
static void saveRun(string EGname, string name, string filename);
//@}
/** @name I/O functions for the Repository. */
//@{
/**
* Load a whole repository from the given file. All objects
* previously in the Repository are discarded. Any errors will be
* reported in the returned string.
*/
static string load(string filename);
/**
* Save the repository to the given file.
*/
static void save(string filename);
/**
* Save the repository to the default file.
*/
static void save() { save(currentFileName()); }
/**
* Write some statistics about the repository to the standard output.
*/
static void stats(ostream &);
//@}
/** @name Command-line interface functions. */
//@{
/**
* Print out a help message. Extended text for a specific command if given.
*/
static void help(string command, ostream & os);
/**
* Remove the given object from the repository. If the object was
* not present nothing will happen.
*/
static void remove(tIBPtr);
/**
* Remove objects. Remove the objects in \a rmset if there are no
* other objects in the repository referring to them, otherwise
* return an error message and the names of the objects refering to
* them separated by new-line characters.
*/
static string remove(const ObjectSet & rmset);
/**
* Read commands from a stream and send them one by one to exec().
*
* @param is the stream from which to read commands.
* @param os the stream where output is written.
* @param prompt before reading a command from \a is, this string is
* written to \a os.
*/
static void read(istream & is, ostream & os, string prompt = "");
/**
* Read commands from a file and send them one by one to exec().
*
* Passes the call through to read(istream, ostream), but also sets
* currentReadDirStack() correctly.
*
* Returns possible messages.
*
* @param filename the file from which to read commands.
* @param os the stream where output is written.
*/
static string read(string filename, ostream & os);
/**
* Interpret the command in \a cmd and return possible
* messages. This is the main function for the command-line
* interface. The syntax is described elsewhere. The ostream
* argument is currently unused.
*/
static string exec(string cmd, ostream &);
//@}
/**
* Return the version number of ThePEG.
*/
static string version();
/**
* Return a string with a ThePEG banner.
*/
static string banner();
private:
/**
* Used by Register.
*/
static void registerParticle(tPDPtr);
/**
* Used by Register.
*/
static void registerMatcher(tPMPtr);
/**
* Used by read()
*/
static void execAndCheckReply(string, ostream &);
protected:
/** @name Functions containing the static instances of objects used
by the repository. */
//@{
/**
* The set of default particles.
*/
static ParticleMap & defaultParticles();
/**
* The set of all particles.
*/
static ParticleDataSet & particles();
/**
* The set of all matchers.
*/
static MatcherSet & matchers();
/**
* All isolated generators mapped to their run name.
*/
static GeneratorMap & generators();
/**
* The default file name used by save().
*/
static string & currentFileName();
public:
/**
* If non-zero the setup program will exit with this error code as
* soon as an error is encountered.
*/
static int & exitOnError();
/**
* Call this function to clean up the repository at the end of your
* program if you are using the static functions directly without
* going through a Repository object. There, the destructor would do
* the job.
*/
static void cleanup();
//@}
private:
/**
* It makes no sense to copy a Repository, so this constructor is
* not implemented
*/
Repository(const Repository &);
/**
* It makes no sense to copy a Repository, so this assignment is
* not implemented
*/
Repository & operator=(const Repository &);
/**
* Count the number of repositorys instantiated.
*/
static int ninstances;
};
}
#endif /* ThePEG_Repository_H */
|