Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 14:21:22

0001 #include "HtrXmlPatternWriter.h"
0002 
0003 static const char* tabbing(int level) {
0004   static char tab[50];
0005   for (int i = 0; i < level * 2; i++)
0006     tab[i] = ' ';
0007   tab[level * 2] = 0;
0008   return tab;
0009 }
0010 
0011 HtrXmlPatternWriter::HtrXmlPatternWriter() {
0012   // set the timestamp!
0013   time_t now1 = time(nullptr);
0014   struct tm* now = localtime(&now1);
0015 
0016   char buffer[1024];
0017   strftime(buffer, 1024, "%Y-%m-%d %H:%M:%S", now);
0018 
0019   m_stamp = buffer;
0020 }
0021 
0022 void HtrXmlPatternWriter::writePattern(HalfHtrData* spigotData, int fiber, std::ostream& os, int level) {
0023   os << tabbing(level) << "<CFGBrick>" << std::endl;
0024   os << tabbing(level + 1) << "<Parameter name='DCC' type='int'>" << std::dec << spigotData->getDCC() << "</Parameter>"
0025      << std::endl;
0026   os << tabbing(level + 1) << "<Parameter name='SPIGOT' type='int'>" << std::dec << spigotData->getSpigot()
0027      << "</Parameter>" << std::endl;
0028   os << tabbing(level + 1) << "<Parameter name='CRATE' type='int'>" << std::dec << spigotData->getCrate()
0029      << "</Parameter>" << std::endl;
0030   os << tabbing(level + 1) << "<Parameter name='SLOT' type='int'>" << spigotData->getSlot() << "</Parameter>"
0031      << std::endl;
0032   os << tabbing(level + 1) << "<Parameter name='TOPBOTTOM' type='int'>" << spigotData->getTB() << "</Parameter>"
0033      << std::endl;
0034   os << tabbing(level + 1) << "<Parameter name='FIBER' type='int'>" << fiber << "</Parameter>" << std::endl;
0035 
0036   int genIndex = fiber + (spigotData->getTB() * 10) + (spigotData->getSlot() * 100) + (spigotData->getCrate() * 10000);
0037   os << tabbing(level + 1) << "<Parameter name='GENERALIZEDINDEX' type='int'>" << std::dec << genIndex << "</Parameter>"
0038      << std::endl;
0039   os << tabbing(level + 1) << "<Parameter name='CREATIONTAG' type='string'>" << m_tagName << "</Parameter>"
0040      << std::endl;
0041   os << tabbing(level + 1) << "<Parameter name='CREATIONSTAMP' type='string'>" << m_stamp << "</Parameter>"
0042      << std::endl;
0043   os << tabbing(level + 1) << "<Parameter name='PATTERN_SPEC_NAME' type='string'>" << m_tagName << "</Parameter>"
0044      << std::endl;
0045 
0046   // CREATIONTAG, CREATIONSTAMP, PATTERN_SPEC_NAME
0047 
0048   os << tabbing(level + 1) << "<Data elements='1024' encoding='hex'>" << std::endl;
0049 
0050   ChannelPattern* p1 = spigotData->getPattern((fiber - 1) * 3 + 1);
0051   ChannelPattern* p2 = spigotData->getPattern((fiber - 1) * 3 + 2);
0052   ChannelPattern* p3 = spigotData->getPattern((fiber - 1) * 3 + 3);
0053 
0054   unsigned int w1, w2;
0055   for (int i = 0; i < 512; i++) {
0056     packWordsStd(p1->getCoded(i), p2->getCoded(i), p3->getCoded(i), i % 4, w1, w2);
0057     os << std::hex << w1 << ' ' << std::hex << w2 << ' ';
0058   }
0059 
0060   os << std::endl << tabbing(level + 1) << "</Data>" << std::endl;
0061 
0062   os << tabbing(level) << "</CFGBrick>" << std::endl;
0063 }
0064 
0065 void HtrXmlPatternWriter::packWordsStd(int adc0, int adc1, int adc2, int capid, unsigned int& w1, unsigned int& w2) {
0066   w1 = 0x3;
0067   w1 |= (capid & 0x3) << 3;
0068   w1 |= (capid & 0x3) << 5;
0069   w1 |= (capid & 0x3) << 7;
0070   w1 |= adc2 << 9;
0071   w1 |= 0x10000;  // data valid
0072   w2 = adc1 << 1;
0073   w2 |= adc0 << 9;
0074   w2 |= 0x10000;  // data valid
0075 }