00001
00002
00003
00004
00005
00006
00007
00008 #include "meas/inline/abs_inline_measurement_factory.h"
00009 #include "meas/inline/io/inline_xml_write_obj.h"
00010 #include "meas/inline/io/named_objmap.h"
00011 #include "meas/inline/io/xml_write_obj_funcmap.h"
00012
00013 namespace Chroma
00014 {
00015 namespace InlineXMLWriteNamedObjEnv
00016 {
00017 namespace
00018 {
00019 AbsInlineMeasurement* createMeasurement(XMLReader& xml_in,
00020 const std::string& path)
00021 {
00022 return new InlineXMLWriteNamedObj(InlineXMLWriteNamedObjParams(xml_in, path));
00023 }
00024
00025
00026 bool registered = false;
00027 }
00028
00029 const std::string name = "XML_WRITE_NAMED_OBJECT";
00030
00031
00032 bool registerAll()
00033 {
00034 bool success = true;
00035 if (! registered)
00036 {
00037
00038 success &= XMLWriteObjCallMapEnv::registerAll();
00039
00040
00041 success &= TheInlineMeasurementFactory::Instance().registerObject(name, createMeasurement);
00042
00043 registered = true;
00044 }
00045 return success;
00046 }
00047 }
00048
00049
00050
00051 void write(XMLWriter& xml, const string& path, const InlineXMLWriteNamedObjParams::NamedObject_t& input)
00052 {
00053 push(xml, path);
00054
00055 write(xml, "object_id", input.object_id);
00056 write(xml, "object_type", input.object_type);
00057
00058 pop(xml);
00059 }
00060
00061
00062 void write(XMLWriter& xml, const string& path, const InlineXMLWriteNamedObjParams::File_t& input)
00063 {
00064 push(xml, path);
00065
00066 write(xml, "file_name", input.file_name);
00067
00068 pop(xml);
00069 }
00070
00071
00072
00073 void read(XMLReader& xml, const string& path, InlineXMLWriteNamedObjParams::NamedObject_t& input)
00074 {
00075 XMLReader inputtop(xml, path);
00076
00077 read(inputtop, "object_id", input.object_id);
00078 read(inputtop, "object_type", input.object_type);
00079 }
00080
00081
00082 void read(XMLReader& xml, const string& path, InlineXMLWriteNamedObjParams::File_t& input)
00083 {
00084 XMLReader inputtop(xml, path);
00085
00086 read(inputtop, "file_name", input.file_name);
00087 }
00088
00089
00090
00091 InlineXMLWriteNamedObjParams::InlineXMLWriteNamedObjParams() { frequency = 0; }
00092
00093 InlineXMLWriteNamedObjParams::InlineXMLWriteNamedObjParams(XMLReader& xml_in, const std::string& path)
00094 {
00095 try
00096 {
00097 XMLReader paramtop(xml_in, path);
00098
00099 if (paramtop.count("Frequency") == 1)
00100 read(paramtop, "Frequency", frequency);
00101 else
00102 frequency = 1;
00103
00104
00105 read(paramtop, "NamedObject", named_obj);
00106
00107
00108 read(paramtop, "File", file);
00109 }
00110 catch(const std::string& e)
00111 {
00112 QDPIO::cerr << __func__ << ": caught Exception reading XML: " << e << endl;
00113 QDP_abort(1);
00114 }
00115 }
00116
00117
00118 void
00119 InlineXMLWriteNamedObjParams::write(XMLWriter& xml_out, const std::string& path)
00120 {
00121 push(xml_out, path);
00122
00123
00124 Chroma::write(xml_out, "NamedObject", named_obj);
00125
00126
00127 Chroma::write(xml_out, "File", file);
00128
00129 pop(xml_out);
00130 }
00131
00132
00133 void
00134 InlineXMLWriteNamedObj::operator()(unsigned long update_no,
00135 XMLWriter& xml_out)
00136 {
00137 START_CODE();
00138
00139 push(xml_out, "xml_write_named_obj");
00140 write(xml_out, "update_no", update_no);
00141
00142 QDPIO::cout << InlineXMLWriteNamedObjEnv::name << ": object writer" << endl;
00143 StopWatch swatch;
00144
00145
00146
00147
00148 QDPIO::cout << "Attempt to write object name = " << params.named_obj.object_id << endl;
00149 write(xml_out, "object_id", params.named_obj.object_id);
00150 try
00151 {
00152 swatch.reset();
00153
00154
00155 swatch.start();
00156 XMLWriteObjCallMapEnv::TheXMLWriteObjFuncMap::Instance().callFunction(params.named_obj.object_type,
00157 params.named_obj.object_id,
00158 params.file.file_name);
00159 swatch.stop();
00160
00161 QDPIO::cout << "Object successfully written: time= "
00162 << swatch.getTimeInSeconds()
00163 << " secs" << endl;
00164 }
00165 catch( std::bad_cast )
00166 {
00167 QDPIO::cerr << InlineXMLWriteNamedObjEnv::name << ": cast error"
00168 << endl;
00169 QDP_abort(1);
00170 }
00171 catch (const string& e)
00172 {
00173 QDPIO::cerr << InlineXMLWriteNamedObjEnv::name << ": error message: " << e
00174 << endl;
00175 QDP_abort(1);
00176 }
00177
00178 QDPIO::cout << InlineXMLWriteNamedObjEnv::name << ": ran successfully" << endl;
00179
00180 pop(xml_out);
00181
00182 END_CODE();
00183 }
00184
00185 };