Back to home page

EIC code displayed by LXR

 
 

    


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

0001 // -*- C++ -*-
0002 //
0003 // Repository.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 ThePEG_Repository_H
0010 #define ThePEG_Repository_H
0011 // This is the declaration of the Repository class.
0012 
0013 #include "ThePEG/Config/ThePEG.h"
0014 #include "BaseRepository.h"
0015 #include "EventGenerator.h"
0016 #include "ThePEG/PDT/ParticleData.h"
0017 #include "ThePEG/PDT/MatcherBase.h"
0018 
0019 namespace ThePEG {
0020 
0021 /**
0022  * Repository inherits from the BaseRepository class. While
0023  * BaseRepository is fairly general and could in principle be used for
0024  * any program where sets of InterfacedBase objects are managed, the
0025  * Repository is ThePEG specific in that it deals with ParticleData,
0026  * ParticleMatchers and EventGenerators.
0027  *
0028  * One main function is to write an EventGenerator to disk using
0029  * saveRun(). Here all objects needed for the run, including the
0030  * EventGenerator is cloned and isolated from the other objects in the
0031  * Repository (and are hence not handled by the Repository anymore)
0032  * before they are all persistently written out to disk.
0033  *
0034  * The Register() function simply pass the objects to the corresonding
0035  * method in BaseRepository, but if the object is a ParticleData or a
0036  * ParticleMatcher, they are stored separately.
0037  *
0038  * @see BaseRepository
0039  * @see InterfacedBase
0040  * @see ParticleData
0041  * @see ParticleMatcher
0042  * @see EventGenerator
0043  * 
0044  */
0045 class Repository: public BaseRepository {
0046 
0047 public:
0048 
0049   /** A map of EventGenerator objects indexed by their run name. */
0050   typedef map<string,EGPtr> GeneratorMap;
0051 
0052 public:
0053 
0054   /** @name Standsrd constructors and destructors */
0055   //@{
0056   /**
0057    * The default constructor is the only one that should be used.
0058    */
0059   Repository();
0060 
0061   /**
0062    * The destructor will do some clean-up when the last Repository is
0063    * deleted.
0064    */
0065   ~Repository();
0066 
0067 public:
0068 
0069   /** @name Functions for register objects in the Repository. */
0070   //@{
0071   /**
0072    * Register an object with BaseRepository::Register() and add it to
0073    * the list of particles or matchers if of any of those
0074    * types.
0075    */
0076   static void Register(IBPtr);
0077 
0078   /**
0079    * Register an object with BaseRepository::Register() and add it to
0080    * the list of particles or matchers if of any of those
0081    * types.
0082    */
0083   static void Register(IBPtr, string newName);
0084   //@}
0085 
0086   /** @name Access ParticleData and MatcherBase objects in the
0087       Repository. */
0088   //@{
0089   /**
0090    * Add a particle to the list of default ones. If one of the same
0091    * type alredy existed, it is removed from the list (but not from
0092    * the repository).
0093    */
0094   static void defaultParticle(tPDPtr);
0095 
0096   /**
0097    * Get a pointer to the default particle of the given type or
0098    * generic name.
0099    */
0100   static PDPtr defaultParticle(PID id);
0101 
0102   /**
0103    * Get a pointer to a particle based on the given path or name. The
0104    * argument is first treated as a path to an object. If no such
0105    * particle object is found, the argument is treated as a generic
0106    * particle PDGName and is searched for among the default set of
0107    * particles.
0108    */
0109   static tPDPtr findParticle(string name);
0110 
0111   /**
0112    * Return the set of all particles in the repository.
0113    */
0114   static const ParticleDataSet & allParticles() { return particles(); }
0115 
0116   /**
0117    * Return the set of all matchers in the repository.
0118    */
0119   static const MatcherSet & allMatchers() { return matchers(); }
0120 
0121   /**
0122    * Find a matcher with a given generic name
0123    */
0124   static tPMPtr findMatcher(string name);
0125 
0126   /**
0127    * Special function for copying particles. Also corresponding
0128    * anti-particle is copied to the same directory. In addition, their
0129    * decay modes are copied.
0130    */
0131   static string copyParticle(tPDPtr, string);
0132   //@}
0133 
0134   /** @name Functions to isolate Eventgenerator objects. */
0135   //@{
0136   /**
0137    * Isolate an event generator, \a eg, and save it to disk in a file
0138    * named \a name (with <code>.run</code> appended.
0139    */
0140   static EGPtr makeRun(tEGPtr eg, string name);
0141 
0142   /**
0143    * Isolate an event generatorn, named \a EGname, set its run \a name
0144    * and save it to a file named \a filename.
0145    */
0146   static void saveRun(string EGname, string name, string filename);
0147   //@}
0148 
0149   /** @name I/O functions for the Repository. */
0150   //@{
0151   /**
0152    * Load a whole repository from the given file. All objects
0153    * previously in the Repository are discarded. Any errors will be
0154    * reported in the returned string.
0155    */
0156   static string load(string filename);
0157 
0158   /**
0159    * Save the repository to the given file.
0160    */
0161   static void save(string filename);
0162 
0163   /**
0164    * Save the repository to the default file.
0165    */
0166   static void save() { save(currentFileName()); }
0167 
0168   /**
0169    * Write some statistics about the repository to the standard output.
0170    */
0171   static void stats(ostream &);
0172   //@}
0173 
0174   /** @name Command-line interface functions. */
0175   //@{
0176   /**
0177    * Print out a help message. Extended text for a specific command if given.
0178    */
0179   static void help(string command, ostream & os);
0180 
0181   /**
0182    * Remove the given object from the repository. If the object was
0183    * not present nothing will happen.
0184    */
0185   static void remove(tIBPtr);
0186 
0187   /**
0188    * Remove objects. Remove the objects in \a rmset if there are no
0189    * other objects in the repository referring to them, otherwise
0190    * return an error message and the names of the objects refering to
0191    * them separated by new-line characters.
0192    */
0193   static string remove(const ObjectSet & rmset);
0194 
0195   /**
0196    * Read commands from a stream and send them one by one to exec().
0197    *
0198    * @param is the stream from which to read commands.
0199    * @param os the stream where output is written.
0200    * @param prompt before reading a command from \a is, this string is
0201    * written to \a os.
0202    */
0203   static void read(istream & is, ostream & os, string prompt = "");
0204 
0205   /**
0206    * Read commands from a file and send them one by one to exec().
0207    *
0208    * Passes the call through to read(istream, ostream), but also sets
0209    * currentReadDirStack() correctly.
0210    *
0211    * Returns possible messages.
0212    *
0213    * @param filename the file from which to read commands.
0214    * @param os the stream where output is written.
0215    */
0216   static string read(string filename, ostream & os);
0217 
0218   /**
0219    * Interpret the command in \a cmd and return possible
0220    * messages. This is the main function for the command-line
0221    * interface. The syntax is described elsewhere. The ostream
0222    * argument is currently unused.
0223    */
0224   static string exec(string cmd, ostream &);
0225 
0226   /**
0227    * Insert the given EventGenerator and its dependent Interfaced
0228    * objects into the repository and read commands to modify its
0229    * interfaces. Any line accepted by the command-line interface will
0230    * be executed, but the main purpose of this function is to modify
0231    * an already saved and initialized EventGenerator before running
0232    * without re-initializing. If an interface which does not have the
0233    * dependencySafe() flag set, a warning will be emitted.
0234    */
0235   static string modifyEventGenerator(EventGenerator & eg, string filename, 
0236                      ostream & os, bool initOnly = false);  
0237 
0238   /**
0239    * Reset the given EventGenerator; equivalent to
0240    * modifyEventGenerator without reading an input file.
0241    */
0242   static void resetEventGenerator(EventGenerator & eg);  
0243   //@}
0244 
0245   /**
0246    * Return the version number of ThePEG.
0247    */
0248   static string version();
0249 
0250   /**
0251    * Return a string with a ThePEG banner.
0252    */
0253   static string banner();
0254 
0255 private:
0256 
0257   /**
0258    * Used by Register.
0259    */
0260   static void registerParticle(tPDPtr);
0261 
0262   /**
0263    * Used by Register.
0264    */
0265   static void registerMatcher(tPMPtr);
0266 
0267   /** 
0268    * Used by read()
0269    */
0270   static void execAndCheckReply(string, ostream &);
0271 
0272 protected:
0273 
0274   /** @name Functions containing the static instances of objects used
0275       by the repository. */
0276   //@{
0277   /**
0278    * The set of default particles.
0279    */
0280   static ParticleMap & defaultParticles();
0281 
0282   /**
0283    * The set of all particles.
0284    */
0285   static ParticleDataSet & particles();
0286 
0287   /**
0288    * The set of all matchers.
0289    */
0290   static MatcherSet & matchers();
0291 
0292   /**
0293    * All isolated generators mapped to their run name.
0294    */
0295   static GeneratorMap & generators();
0296 
0297   /**
0298    * The default file name used by save().
0299    */
0300   static string & currentFileName();
0301 
0302 public:
0303 
0304   /**
0305    * If non-zero the setup program will exit with this error code as
0306    * soon as an error is encountered.
0307    */
0308   static int & exitOnError();
0309 
0310   /**
0311    * Call this function to clean up the repository at the end of your
0312    * program if you are using the static functions directly without
0313    * going through a Repository object. There, the destructor would do
0314    * the job.
0315    */
0316   static void cleanup();
0317   //@}
0318 
0319 private:
0320 
0321   /**
0322    * It makes no sense to copy a Repository, so this constructor is
0323    * not implemented
0324    */
0325   Repository(const Repository &);
0326 
0327   /**
0328    * It makes no sense to copy a Repository, so this assignment is
0329    * not implemented
0330    */
0331   Repository & operator=(const Repository &) = delete;
0332 
0333   /**
0334    * Count the number of repositorys instantiated.
0335    */
0336   static int ninstances;
0337   
0338 
0339 };
0340 
0341 }
0342 
0343 #endif /* ThePEG_Repository_H */