Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-08-06 09:24:07

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