00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015 #include "CaloOnlineTools/HcalOnlineDb/interface/LutXml.h"
00016 #include "CaloOnlineTools/HcalOnlineDb/interface/XMLProcessor.h"
00017
00018 #include <iostream>
00019 #include <string>
00020 #include <vector>
00021 #include <sstream>
00022
00023 using namespace std;
00024
00025 LutXml::Config::_Config()
00026 {
00027 ieta = -1000;
00028 iphi = -1000;
00029 depth = -1;
00030 crate = -1;
00031 slot = -1;
00032 topbottom = -1;
00033 fiber = -1;
00034 fiberchan = -1;
00035 lut_type = -1;
00036 creationtag = "default_tag";
00037
00038 char timebuf[50];
00039 time_t _time = time( NULL );
00040
00041
00042 strftime( timebuf, 50, "%Y-%m-%d %H:%M:%S", gmtime( &_time ) );
00043 creationstamp = timebuf;
00044
00045 formatrevision = "default_revision";
00046 targetfirmware = "default_revision";
00047 generalizedindex = -1;
00048 }
00049
00050 LutXml::LutXml() : XMLDOMBlock( "CFGBrickSet", 1 )
00051 {
00052 init();
00053 }
00054
00055
00056 LutXml::~LutXml()
00057 {
00058
00059 }
00060
00061
00062 void LutXml::init( void )
00063 {
00064 brickElem = NULL;
00065 }
00066
00067
00068 void LutXml::addLut( LutXml::Config & _config )
00069 {
00070 DOMElement * rootElem = document -> getDocumentElement();
00071
00072 brickElem = document->createElement( XMLProcessor::_toXMLCh("CFGBrick") );
00073 rootElem->appendChild(brickElem);
00074
00075 addParameter( "IETA", "int", _config.ieta );
00076 addParameter( "IPHI", "int", _config.iphi );
00077 addParameter( "DEPTH", "int", _config.depth );
00078 addParameter( "CRATE", "int", _config.crate );
00079 addParameter( "SLOT", "int", _config.slot );
00080 addParameter( "TOPBOTTOM", "int", _config.topbottom );
00081 addParameter( "FIBER", "int", _config.fiber );
00082 addParameter( "FIBERCHAN", "int", _config.fiberchan );
00083 addParameter( "LUT_TYPE", "int", _config.lut_type );
00084 addParameter( "CREATIONTAG", "string", _config.creationtag );
00085 addParameter( "CREATIONSTAMP", "string", _config.creationstamp );
00086 addParameter( "FORMATREVISION", "string", _config.formatrevision );
00087 addParameter( "TARGETFIRMWARE", "string", _config.targetfirmware );
00088 addParameter( "GENERALIZEDINDEX", "int", _config.generalizedindex );
00089 addData( "128", "hex", _config.lut );
00090 }
00091
00092 DOMElement * LutXml::addData( string _elements, string _encoding, std::vector<unsigned int> _lut )
00093 {
00094 DOMElement * child = document -> createElement( XMLProcessor::_toXMLCh( "Data" ) );
00095 child -> setAttribute( XMLProcessor::_toXMLCh("elements"), XMLProcessor::_toXMLCh( _elements ) );
00096 child -> setAttribute( XMLProcessor::_toXMLCh("encoding"), XMLProcessor::_toXMLCh( _encoding ) );
00097
00098 stringstream buf;
00099
00100 for (std::vector<unsigned int>::const_iterator iter = _lut.begin();iter!=_lut.end();iter++){
00101 char buf2[8];
00102 sprintf(buf2,"%x",(*iter));
00103 buf << buf2 << " ";
00104
00105 }
00106
00107 string _value = buf . str();
00108
00109 DOMText * data_value = document -> createTextNode( XMLProcessor::_toXMLCh(_value));
00110 child -> appendChild( data_value );
00111
00112 brickElem -> appendChild( child );
00113
00114 return child;
00115 }
00116
00117
00118
00119 DOMElement * LutXml::addParameter( string _name, string _type, string _value )
00120 {
00121 DOMElement * child = document -> createElement( XMLProcessor::_toXMLCh( "Parameter" ) );
00122 child -> setAttribute( XMLProcessor::_toXMLCh("name"), XMLProcessor::_toXMLCh( _name ) );
00123 child -> setAttribute( XMLProcessor::_toXMLCh("type"), XMLProcessor::_toXMLCh( _type ) );
00124 DOMText * parameter_value = document -> createTextNode( XMLProcessor::_toXMLCh(_value));
00125 child -> appendChild( parameter_value );
00126
00127 brickElem -> appendChild( child );
00128
00129 return child;
00130 }
00131
00132
00133
00134 DOMElement * LutXml::addParameter( string _name, string _type, int _value )
00135 {
00136 char buf[128];
00137 sprintf(buf, "%d", _value);
00138 string str_value = buf;
00139 return addParameter( _name, _type, str_value );
00140 }
00141
00142
00143
00144
00145 std::string & LutXml::getCurrentBrick( void )
00146 {
00147 return getString( brickElem );
00148 }