Back to home page

EIC code displayed by LXR

 
 

    


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

0001 // -*- C++ -*-
0002 //
0003 // LesHouchesFileReader.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_LesHouchesFileReader_H
0010 #define THEPEG_LesHouchesFileReader_H
0011 // This is the declaration of the LesHouchesFileReader class.
0012 
0013 #include "LesHouchesReader.h"
0014 #include "LesHouchesFileReader.fh"
0015 #include "ThePEG/PDT/Decayer.h"
0016 #include "ThePEG/Utilities/CFileLineReader.h"
0017 #include <string>
0018 #include <stdio.h>
0019 
0020 namespace ThePEG {
0021 
0022 
0023 /**
0024  * LesHouchesFileReader is an base class to be used for objects which
0025  * reads event files from matrix element generators. It inherits from
0026  * LesHouchesReader and extends it by defining a file handle to be
0027  * read from, which is opened and closed by the open() and close()
0028  * functions. Note that the file handle is a standard C filehandle and
0029  * not a C++ stream. This is because there is no standard way in C++
0030  * to connect a pipe to a stream for reading eg. gzipped files. This
0031  * class is able to read plain event files conforming to the Les
0032  * Houches Event File accord.
0033  *
0034  * @see \ref LesHouchesFileReaderInterfaces "Th1e interfaces"
0035  * defined for LesHouchesFileReader.
0036  * @see Event
0037  * @see LesHouchesReader
0038  */
0039 class LesHouchesFileReader: public LesHouchesReader {
0040 
0041 public:
0042 
0043   /** @name Standard constructors and destructors. */
0044   //@{
0045   /**
0046    * Default constructor.
0047    */
0048   LesHouchesFileReader() : neve(0), ieve(0), theQNumbers(false),
0049                theIncludeFxFxTags(false),
0050                theIncludeCentral(false) {}
0051 
0052   /**
0053    * Copy-constructor. Note that a file which is opened in the object
0054    * copied from will have to be reopened in this.
0055    */
0056   LesHouchesFileReader(const LesHouchesFileReader &);
0057 
0058   /**
0059    * Destructor.
0060    */
0061   virtual ~LesHouchesFileReader();
0062   //@}
0063 
0064 public:
0065 
0066   /** @name Virtual functions specified by the LesHouchesReader base class. */
0067   //@{
0068   /**
0069    * Initialize. This function is called by the LesHouchesEventHandler
0070    * to which this object is assigned.
0071    */
0072   virtual void initialize(LesHouchesEventHandler & eh);
0073 
0074   /**
0075    * Open a file with events. Derived classes should overwrite it and
0076    * first calling it before reading in the run information into the
0077    * corresponding protected variables.
0078    */
0079   virtual void open();
0080 
0081   /**
0082    * Close the file from which events have been read.
0083    */
0084   virtual void close();
0085  
0086 
0087   /**
0088    * Read the next event from the file or stream into the
0089    * corresponding protected variables. Return false if there is no
0090    * more events or if this was not a LHF event file.
0091    */
0092   virtual bool doReadEvent();
0093   //@}
0094 
0095   /**
0096    * Return the name of the file from where to read events.
0097    */
0098   string filename() const { return theFileName; }
0099 
0100   /** 
0101    * Return the optional weights information string ("Names")
0102    */
0103 
0104   virtual vector<string> optWeightsNamesFunc();
0105   
0106 
0107 public:
0108 
0109   /** @name Functions used by the persistent I/O system. */
0110   //@{
0111   /**
0112    * Function used to write out object persistently.
0113    * @param os the persistent output stream written to.
0114    */
0115   void persistentOutput(PersistentOStream & os) const;
0116 
0117   /**
0118    * Function used to read in object persistently.
0119    * @param is the persistent input stream read from.
0120    * @param version the version number of the object when written.
0121    */
0122   void persistentInput(PersistentIStream & is, int version);
0123   //@}
0124 
0125   /**
0126    * Standard Init function used to initialize the interfaces.
0127    */
0128   static void Init();
0129 
0130 
0131   /** 
0132    * Erases all occurences of a substring from a string 
0133    */
0134   
0135   void erase_substr(std::string& subject, const std::string& search);
0136 
0137 
0138 protected:
0139 
0140   /** @name Clone Methods. */
0141   //@{
0142   /**
0143    * Make a simple clone of this object.
0144    * @return a pointer to the new object.
0145    */
0146   virtual IBPtr clone() const;
0147 
0148   /** Make a clone of this object, possibly modifying the cloned object
0149    * to make it sane.
0150    * @return a pointer to the new object.
0151    */
0152   virtual IBPtr fullclone() const;
0153   //@}
0154 
0155   /** @name Standard (and non-standard) Interfaced functions. */
0156   //@{
0157   /**
0158    * Initialize this object after the setup phase before saving an
0159    * EventGenerator to disk.
0160    * @throws InitException if object could not be initialized properly.
0161    */
0162   virtual void doinit();
0163 
0164   /**
0165    * Return true if this object needs to be initialized before all
0166    * other objects because it needs to extract PDFs from the event file.
0167    */
0168   virtual bool preInitialize() const;
0169   //@
0170 
0171 protected:
0172 
0173   /**
0174    * The wrapper around the C FILE stream from which to read
0175    */
0176   CFileLineReader cfile;
0177 
0178 protected:
0179 
0180   /**
0181    * The number of events in this file.
0182    */
0183   long neve;
0184 
0185   /**
0186    * The current event number.
0187    */
0188   long ieve;
0189 
0190   /**
0191    * If the file is a standard Les Houches formatted file (LHF) this
0192    * is its version number. If empty, this is not a Les Houches
0193    * formatted file
0194    */
0195   string LHFVersion;
0196 
0197   /**
0198    * If LHF. All lines (since the last open() or readEvent()) outside
0199    * the header, init and event tags.
0200    */
0201   string outsideBlock;
0202 
0203   /**
0204    * If LHF. All lines from the header block.
0205    */
0206   string headerBlock;
0207 
0208   /**
0209    * If LHF. Additional comments found in the init block.
0210    */
0211   string initComments;
0212 
0213   /**
0214    * If LHF. Map of attributes (name-value pairs) found in the init
0215    * tag.
0216    */
0217   map<string,string> initAttributes;
0218 
0219   /**
0220    * If LHF. Additional comments found with the last read event.
0221    */
0222   string eventComments;
0223 
0224   /**
0225    * If LHF. Map of attributes (name-value pairs) found in the last
0226    * event tag.
0227    */
0228   map<string,string> eventAttributes;
0229 
0230 private:
0231 
0232   /**
0233    * The name of the file from where to read events.
0234    */
0235   string theFileName;
0236 
0237   /**
0238    *  Whether or not to search for QNUMBERS stuff
0239    */
0240   bool theQNumbers;
0241 
0242   /**
0243    * Include/Read FxFx tags
0244    */
0245   bool theIncludeFxFxTags;
0246 
0247   /**
0248    * Include central weight (for backup use)
0249    */
0250   bool theIncludeCentral;
0251 
0252   /**
0253    *  Decayer for any decay modes read from the file
0254    */
0255   DecayerPtr theDecayer;
0256   
0257   /**
0258    * Further information on the weights
0259    */
0260   map<string,string> scalemap;
0261 
0262   /**
0263    * Temporary holder for optional weights
0264    */
0265   
0266   map<string,double> optionalWeightsTemp;
0267 
0268 
0269 private:
0270 
0271   /**
0272    * Describe an abstract base class with persistent data.
0273    */
0274   static ClassDescription<LesHouchesFileReader> initLesHouchesFileReader;
0275 
0276   /**
0277    * Private and non-existent assignment operator.
0278    */
0279   LesHouchesFileReader & operator=(const LesHouchesFileReader &) = delete;
0280 
0281 public:
0282 
0283   /** @cond EXCEPTIONCLASSES */
0284   /** Exception class used by LesHouchesFileReader if reading the file
0285    *  fails. */
0286   class LesHouchesFileError: public Exception {};
0287   /** @endcond */
0288 
0289 };
0290 
0291 }
0292 
0293 
0294 #include "ThePEG/Utilities/ClassTraits.h"
0295 
0296 namespace ThePEG {
0297 
0298 /** @cond TRAITSPECIALIZATIONS */
0299 
0300 /**
0301  * This template specialization informs ThePEG about the
0302  * base class of LesHouchesFileReader.
0303  */
0304 template <>
0305 struct BaseClassTrait<LesHouchesFileReader,1>: public ClassTraitsType {
0306   /** Typedef of the base class of LesHouchesFileReader. */
0307   typedef LesHouchesReader NthBase;
0308 };
0309 
0310 /**
0311  * This template specialization informs ThePEG about the name of the
0312  * LesHouchesFileReader class and the shared object where it is
0313  * defined.
0314  */
0315 template <>
0316 struct ClassTraits<LesHouchesFileReader>
0317   : public ClassTraitsBase<LesHouchesFileReader> {
0318   /**
0319    * Return the class name.
0320    */
0321   static string className() { return "ThePEG::LesHouchesFileReader"; }
0322   /**
0323    * Return the name of the shared library to be loaded to get access
0324    * to the LesHouchesFileReader class and every other class it uses
0325    * (except the base class).
0326    */
0327   static string library() { return "LesHouches.so"; }
0328 
0329 };
0330 
0331 /** @endcond */
0332 
0333 }
0334 
0335 #endif /* THEPEG_LesHouchesFileReader_H */