inline_rng.cc

Go to the documentation of this file.
00001 // $Id: inline_rng.cc,v 3.1 2008/09/14 02:26:11 edwards Exp $
00002 /*! \file
00003  * \brief Inline task to read and write RNG seed
00004  */
00005 
00006 #include "chromabase.h"
00007 #include "meas/inline/abs_inline_measurement_factory.h"
00008 #include "meas/inline/io/inline_rng.h"
00009 
00010 namespace Chroma 
00011 { 
00012   namespace InlineSetRNGEnv 
00013   { 
00014     namespace
00015     {
00016       AbsInlineMeasurement* createMeasurement(XMLReader& xml_in, 
00017                                               const std::string& path) 
00018       {
00019         return new InlineMeas(Params(xml_in, path));
00020       }
00021 
00022       //! Local registration flag
00023       bool registered = false;
00024     }
00025 
00026     const std::string name = "SET_RNG";
00027 
00028     //! Register all the factories
00029     bool registerAll() 
00030     {
00031       bool success = true; 
00032       if (! registered)
00033       {
00034         success &= TheInlineMeasurementFactory::Instance().registerObject(name, createMeasurement);
00035         registered = true;
00036       }
00037       return success;
00038     }
00039     // Param stuff
00040     Params::Params() { frequency = 0; }
00041 
00042     Params::Params(XMLReader& xml_in, const std::string& path) 
00043     {
00044       try 
00045       {
00046         XMLReader paramtop(xml_in, path);
00047 
00048         if (paramtop.count("Frequency") == 1)
00049           read(paramtop, "Frequency", frequency);
00050         else
00051           frequency = 1;
00052 
00053         // Parameters for source construction
00054         read(paramtop, "RNG", ran_seed);
00055       }
00056       catch(const std::string& e) 
00057       {
00058         QDPIO::cerr << __func__ << ": caught Exception reading XML: " << e << endl;
00059         QDP_abort(1);
00060       }
00061     }
00062 
00063 
00064     void
00065     Params::writeXML(XMLWriter& xml_out, const std::string& path) 
00066     {
00067       push(xml_out, path);
00068     
00069       // Parameters for source construction
00070       write(xml_out, "RNG", ran_seed);
00071 
00072       pop(xml_out);
00073     }
00074 
00075 
00076     void 
00077     InlineMeas::operator()(unsigned long update_no, XMLWriter& xml_out) 
00078     {
00079       START_CODE();
00080 
00081       push(xml_out, "SetRNG");
00082       write(xml_out, "update_no", update_no);
00083 
00084       // Set the RNG seed
00085       QDP::RNG::setrn(params.ran_seed);
00086       write(xml_out,"RNG", params.ran_seed);
00087     
00088       QDPIO::cout << name << ": ran successfully" << endl;
00089 
00090       pop(xml_out);  // read_named_obj
00091 
00092       END_CODE();
00093     } 
00094 
00095   }
00096 }

Generated on Sun Nov 22 04:33:03 2009 for CHROMA by  doxygen 1.4.7