Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:00:08

0001 // -*- C++ -*-
0002 //
0003 // Package:     XMLTools
0004 // Class  :     XMLLUTLoader
0005 //
0006 // Implementation:
0007 //     <Notes on implementation>
0008 //
0009 // Original Author:  Gena Kukartsev, kukarzev@fnal.gov
0010 //         Created:  Tue Oct 23 14:30:20 CDT 2007
0011 //
0012 
0013 // system include files
0014 
0015 // user include files
0016 #include "CaloOnlineTools/HcalOnlineDb/interface/XMLLUTLoader.h"
0017 #include "CalibCalorimetry/HcalTPGAlgos/interface/XMLProcessor.h"
0018 #include <cstdio>
0019 XERCES_CPP_NAMESPACE_USE
0020 
0021 //
0022 // constants, enums and typedefs
0023 //
0024 
0025 //
0026 // static data member definitions
0027 //
0028 
0029 //
0030 // constructors and destructor
0031 //
0032 XMLLUTLoader::lutDBConfig::_lutDBConfig() : XMLProcessor::DBConfig() {
0033   kind_of_part = "HCAL HTR Crate";
0034   name_label = "CRATE17";
0035   trig_prim_lookuptbl_data_file = "testLUT_17.xml";
0036   crate = 17;
0037 }
0038 
0039 XMLLUTLoader::checksumsDBConfig::_checksumsDBConfig() : XMLProcessor::DBConfig() {
0040   comment_description = "checksum for all crates version test:2";
0041   name_label = "CMS-HCAL-ROOT";
0042   trig_prim_lookuptbl_data_file = "./testLUT_checksums.xml";
0043   crate = -1;
0044 }
0045 
0046 XMLLUTLoader::XMLLUTLoader() {}
0047 
0048 XMLLUTLoader::XMLLUTLoader(XMLProcessor::loaderBaseConfig* config, std::string templateBase)
0049     : XMLDOMBlock(templateBase) {
0050   setTagValue("EXTENSION_TABLE_NAME", config->extention_table_name);
0051   setTagValue("NAME", config->name);
0052   setTagAttribute("RUN", "mode", config->run_mode);
0053   setTagAttribute("DATA_SET", "id", config->data_set_id);
0054   setTagAttribute("IOV", "id", config->iov_id);
0055   setTagValue("INTERVAL_OF_VALIDITY_BEGIN", config->iov_begin);
0056   setTagValue("INTERVAL_OF_VALIDITY_END", config->iov_end);
0057   setTagAttribute("TAG", "id", config->tag_id);
0058   setTagAttribute("TAG", "mode", config->tag_mode);
0059   setTagValue("TAG_NAME", config->tag_name);
0060   setTagValue("DETECTOR_NAME", config->detector_name);
0061   setTagValue("COMMENT_DESCRIPTION", config->comment_description);
0062 
0063   setTagAttribute("TAG", "idref", config->tag_id, 1);
0064   setTagAttribute("IOV", "idref", config->iov_id, 1);
0065   setTagAttribute("DATA_SET", "idref", config->data_set_id, 1);
0066 }
0067 
0068 // XMLLUTLoader::XMLLUTLoader(const XMLLUTLoader& rhs)
0069 // {
0070 //    // do actual copying here;
0071 // }
0072 
0073 XMLLUTLoader::~XMLLUTLoader() {}
0074 
0075 //
0076 // assignment operators
0077 //
0078 // const XMLLUTLoader& XMLLUTLoader::operator=(const XMLLUTLoader& rhs)
0079 // {
0080 //   //An exception safe implementation is
0081 //   XMLLUTLoader temp(rhs);
0082 //   swap(rhs);
0083 //
0084 //   return *this;
0085 // }
0086 
0087 //
0088 // member functions
0089 //
0090 int XMLLUTLoader::addLUT(lutDBConfig* config, std::string templateFileName) {
0091   DOMElement* root = document->getDocumentElement();
0092 
0093   XMLDOMBlock dataSetDoc(templateFileName);
0094   DOMDocument* dataSet = dataSetDoc.getDocument();
0095 
0096   // changes to the LUT <data_set> node
0097   setTagValue("VERSION", config->version, 0, dataSet);
0098   setTagValue("SUBVERSION", config->subversion, 0, dataSet);
0099   char timebuf[50];
0100   //strftime( timebuf, 50, "%c", gmtime( &(config -> create_timestamp) ) );
0101   strftime(timebuf, 50, "%Y-%m-%d %H:%M:%S.0", gmtime(&(config->create_timestamp)));
0102   setTagValue("CREATE_TIMESTAMP", timebuf, 0, dataSet);
0103   setTagValue("CREATED_BY_USER", config->created_by_user, 0, dataSet);
0104   setTagValue("KIND_OF_PART", config->kind_of_part, 0, dataSet);
0105   setTagValue("NAME_LABEL", config->name_label, 0, dataSet);
0106   setTagValue("TRIG_PRIM_LOOKUPTBL_DATA_FILE", config->trig_prim_lookuptbl_data_file, 0, dataSet);
0107   setTagValue("CRATE", config->crate, 0, dataSet);
0108 
0109   // copy the <data_set> node into the final XML
0110   DOMNode* cloneDataSet = document->importNode(dataSet->getDocumentElement(), true);
0111   root->appendChild(cloneDataSet);
0112 
0113   return 0;
0114 }
0115 
0116 int XMLLUTLoader::addChecksums(checksumsDBConfig* config, std::string templateFileName) {
0117   DOMElement* root = document->getDocumentElement();
0118 
0119   XMLDOMBlock dataSetDoc(templateFileName);
0120   DOMDocument* dataSet = dataSetDoc.getDocument();
0121 
0122   // changes to the Checksums <data_set> node
0123   setTagValue("VERSION", config->version, 0, dataSet);
0124   setTagValue("SUBVERSION", config->subversion, 0, dataSet);
0125   char timebuf[50];
0126   //strftime( timebuf, 50, "%c", gmtime( &(config -> create_timestamp) ) );
0127   strftime(timebuf, 50, "%Y-%m-%d %H:%M:%S.0", gmtime(&(config->create_timestamp)));
0128   setTagValue("CREATE_TIMESTAMP", timebuf, 0, dataSet);
0129   setTagValue("CREATED_BY_USER", config->created_by_user, 0, dataSet);
0130   setTagValue("COMMENT_DESCRIPTION", config->comment_description, 0, dataSet);
0131   setTagValue("NAME_LABEL", config->name_label, 0, dataSet);
0132   setTagValue("TRIG_PRIM_LOOKUPTBL_DATA_FILE", config->trig_prim_lookuptbl_data_file, 0, dataSet);
0133   setTagValue("CRATE", config->crate, 0, dataSet);
0134 
0135   // copy the <data_set> node into the final XML
0136   DOMNode* cloneDataSet = document->importNode(dataSet->getDocumentElement(), true);
0137   root->appendChild(cloneDataSet);
0138 
0139   return 0;
0140 }
0141 
0142 int XMLLUTLoader::createLoader(const std::vector<int>& crate_number, const std::vector<std::string>& file_name) {
0143   XMLLUTLoader::lutDBConfig conf;
0144   XMLLUTLoader::checksumsDBConfig CSconf;
0145 
0146   for (std::vector<std::string>::const_iterator _file = file_name.begin(); _file != file_name.end(); _file++) {
0147     conf.trig_prim_lookuptbl_data_file = *_file;
0148     conf.trig_prim_lookuptbl_data_file += ".dat";
0149     conf.crate = crate_number[_file - file_name.begin()];
0150 
0151     char _buf[128];
0152     sprintf(_buf, "CRATE%.2d", conf.crate);
0153     std::string _namelabel;
0154     _namelabel.append(_buf);
0155     conf.name_label = _namelabel;
0156     addLUT(&conf);
0157   }
0158 
0159   CSconf.trig_prim_lookuptbl_data_file += ".dat";
0160   addChecksums(&CSconf);
0161   write("LUTLoader.xml");
0162 
0163   return 0;
0164 }
0165 
0166 //
0167 // const member functions
0168 //
0169 
0170 //
0171 // static member functions
0172 //