CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_4_1_8_patch9/src/IORawData/CaloPatterns/src/HtrXmlPatternWriter.cc

Go to the documentation of this file.
00001 #include "HtrXmlPatternWriter.h"
00002 
00003 static const char* tabbing(int level) {
00004   static char tab[50];
00005   for (int i=0; i<level*2; i++)
00006     tab[i]=' ';
00007   tab[level*2]=0;
00008   return tab;
00009 }
00010 
00011 HtrXmlPatternWriter::HtrXmlPatternWriter() {
00012   // set the timestamp!
00013   time_t now1=time(0);
00014   struct tm* now=localtime(&now1);
00015 
00016   char buffer[1024];
00017   strftime(buffer,1024,"%Y-%m-%d %H:%M:%S",now);
00018 
00019   m_stamp=buffer;
00020 }
00021 
00022 void HtrXmlPatternWriter::writePattern(HalfHtrData* spigotData, int fiber, std::ostream& os, int level) {
00023 
00024   os << tabbing(level) << "<CFGBrick>" << std::endl;
00025   os << tabbing(level+1) << "<Parameter name='DCC' type='int'>" << std::dec << spigotData->getDCC() << "</Parameter>" << std::endl;
00026   os << tabbing(level+1) << "<Parameter name='SPIGOT' type='int'>" << std::dec << spigotData->getSpigot() << "</Parameter>" << std::endl;
00027   os << tabbing(level+1) << "<Parameter name='CRATE' type='int'>" << std::dec << spigotData->getCrate() << "</Parameter>" << std::endl;
00028   os << tabbing(level+1) << "<Parameter name='SLOT' type='int'>" << spigotData->getSlot() << "</Parameter>" << std::endl;
00029   os << tabbing(level+1) << "<Parameter name='TOPBOTTOM' type='int'>" << spigotData->getTB() << "</Parameter>" << std::endl;
00030   os << tabbing(level+1) << "<Parameter name='FIBER' type='int'>" << fiber << "</Parameter>" << std::endl;
00031   
00032   int genIndex=fiber+(spigotData->getTB()*10)+(spigotData->getSlot()*100)+(spigotData->getCrate()*10000);
00033   os << tabbing(level+1) << "<Parameter name='GENERALIZEDINDEX' type='int'>" << std::dec << genIndex << "</Parameter>" << std::endl;
00034   os << tabbing(level+1) << "<Parameter name='CREATIONTAG' type='string'>" << m_tagName << "</Parameter>" << std::endl;
00035   os << tabbing(level+1) << "<Parameter name='CREATIONSTAMP' type='string'>" << m_stamp << "</Parameter>" << std::endl;
00036   os << tabbing(level+1) << "<Parameter name='PATTERN_SPEC_NAME' type='string'>" << m_tagName << "</Parameter>" << std::endl;
00037   
00038 
00039   // CREATIONTAG, CREATIONSTAMP, PATTERN_SPEC_NAME
00040   
00041   os << tabbing(level+1) << "<Data elements='1024' encoding='hex'>" << std::endl;
00042   
00043   ChannelPattern* p1=spigotData->getPattern((fiber-1)*3+1);
00044   ChannelPattern* p2=spigotData->getPattern((fiber-1)*3+2);
00045   ChannelPattern* p3=spigotData->getPattern((fiber-1)*3+3);
00046 
00047 
00048   unsigned int w1,w2;
00049   for (int i=0; i<512; i++) {
00050     packWordsStd(p1->getCoded(i),p2->getCoded(i),p3->getCoded(i),i%4,w1,w2);
00051     os << std::hex << w1 << ' ' << std::hex << w2 << ' ';
00052   }
00053 
00054   os << std::endl << tabbing(level+1) << "</Data>" << std::endl;
00055   
00056   os << tabbing(level) << "</CFGBrick>" << std::endl;
00057 }
00058 
00059 void HtrXmlPatternWriter::packWordsStd(int adc0, int adc1, int adc2, int capid, unsigned int& w1, unsigned int& w2) {
00060   w1=0x3;
00061   w1|=(capid&0x3)<<3;
00062   w1|=(capid&0x3)<<5;
00063   w1|=(capid&0x3)<<7;
00064   w1|=adc2<<9;
00065   w1|=0x10000; // data valid
00066   w2=adc1<<1;
00067   w2|=adc0<<9;
00068   w2|=0x10000; // data valid
00069 }
00070   
00071 
00072