Back to home page

Project CMSSW displayed by LXR

 
 

    


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

0001 /*sageTest and 
0002     Reads and comapres them.
0003 
0004    The Init/EventMessage(s) are ONLY dumped if they are different 
0005    (Shouldn't be in this original code).
0006 
0007 Disclaimer: Most of the code here is randomly written during
0008                testing various parts, its not a supported testing code.
0009                Changes can and will be made, when and if required.
0010 
0011 */
0012 
0013 #include <iostream>
0014 #include "IOPool/Streamer/interface/MsgTools.h"
0015 #include "IOPool/Streamer/interface/EventMsgBuilder.h"
0016 #include "IOPool/Streamer/interface/InitMsgBuilder.h"
0017 #include "IOPool/Streamer/interface/InitMessage.h"
0018 #include "IOPool/Streamer/interface/EventMessage.h"
0019 
0020 #include "FWCore/Utilities/interface/Adler32Calculator.h"
0021 #include "FWCore/Utilities/interface/Exception.h"
0022 #include "IOPool/Streamer/interface/DumpTools.h"
0023 #include "zlib.h"
0024 
0025 int main() try {
0026   typedef std::vector<uint8> Buffer;
0027   Buffer buf(2024);
0028   Buffer buf2(2024);
0029 
0030   // ----------- init
0031 
0032   char psetid[] = "1234567890123456";
0033   char test_value[] = "This is a test, This is a";
0034   Strings hlt_names;
0035   Strings l1_names;
0036 
0037   hlt_names.push_back("a");
0038   hlt_names.push_back("b");
0039   hlt_names.push_back("c");
0040   hlt_names.push_back("d");
0041   hlt_names.push_back("e");
0042   hlt_names.push_back("f");
0043   hlt_names.push_back("g");
0044   hlt_names.push_back("h");
0045   hlt_names.push_back("i");
0046 
0047   l1_names.push_back("t10");
0048   l1_names.push_back("t11");
0049   l1_names.push_back("t12");
0050   l1_names.push_back("t13");
0051   l1_names.push_back("t14");
0052   l1_names.push_back("t15");
0053   l1_names.push_back("t16");
0054   l1_names.push_back("t17");
0055   l1_names.push_back("t18");
0056   l1_names.push_back("t19");
0057   l1_names.push_back("t20");
0058 
0059   char reltag[] = "CMSSW_0_8_0_pre7";
0060   std::string processName = "HLT";
0061   std::string outputModuleLabel = "HLTOutput";
0062 
0063   uLong crc = crc32(0L, Z_NULL, 0);
0064   Bytef* crcbuf = (Bytef*)outputModuleLabel.data();
0065   crc = crc32(crc, crcbuf, outputModuleLabel.length());
0066 
0067   uint32 adler32_chksum = (uint32)cms::Adler32((char*)&test_value[0], sizeof(test_value));
0068 
0069   InitMsgBuilder init(&buf[0],
0070                       buf.size(),
0071                       12,
0072                       Version((const uint8*)psetid),
0073                       (const char*)reltag,
0074                       processName.c_str(),
0075                       outputModuleLabel.c_str(),
0076                       crc,
0077                       hlt_names,
0078                       hlt_names,
0079                       l1_names,
0080                       adler32_chksum);
0081 
0082   init.setDataLength(sizeof(test_value));
0083   std::copy(&test_value[0], &test_value[0] + sizeof(test_value), init.dataAddress());
0084 
0085   InitMsgView view(&buf[0]);
0086   uint8 psetid2[16];
0087   Strings hlt2;
0088   Strings l12;
0089   view.pset(psetid2);
0090   view.hltTriggerNames(hlt2);
0091   view.l1TriggerNames(l12);
0092 
0093   uint32 adler32_2 = view.adler32_chksum();
0094 
0095   InitMsgBuilder init2(&buf2[0],
0096                        buf2.size(),
0097                        view.run(),
0098                        Version((const uint8*)psetid2),
0099                        view.releaseTag().c_str(),
0100                        processName.c_str(),
0101                        outputModuleLabel.c_str(),
0102                        crc,
0103                        hlt2,
0104                        hlt2,
0105                        l12,
0106                        adler32_2);
0107 
0108   init2.setDataLength(view.descLength());
0109   std::copy(view.descData(), view.descData() + view.size(), init2.dataAddress());
0110 
0111   if (equal(&buf[0], &buf[0] + view.size(), buf2.begin()) == false) {
0112     std::cerr << "Init buffers not the same!\n";
0113     dumpInit(&buf[0]);
0114     dumpInit(&buf2[0]);
0115     abort();
0116   }
0117 
0118   // ------- event
0119 
0120   std::vector<bool> l1bit(16);
0121   uint8 hltbits[] = "4567";
0122   const int hltsize = (sizeof(hltbits) - 1) * 4;
0123 
0124   l1bit[0] = true;
0125   l1bit[4] = true;
0126   l1bit[8] = false;
0127   l1bit[12] = true;
0128   l1bit[1] = true;
0129   l1bit[5] = false;
0130   l1bit[9] = false;
0131   l1bit[13] = false;
0132   l1bit[2] = false;
0133   l1bit[6] = true;
0134   l1bit[10] = true;
0135   l1bit[14] = false;
0136   l1bit[3] = false;
0137   l1bit[7] = false;
0138   l1bit[11] = true;
0139   l1bit[15] = true;
0140 
0141   adler32_chksum = (uint32)cms::Adler32((char*)&test_value[0], sizeof(test_value));
0142   std::string host_name = "mytestnode.cms";
0143 
0144   EventMsgBuilder emb(
0145       &buf[0], buf.size(), 45, 2020, 2, 0xdeadbeef, 3, l1bit, hltbits, hltsize, adler32_chksum, host_name.c_str());
0146 
0147   emb.setOrigDataSize(78);
0148   emb.setEventLength(sizeof(test_value));
0149   std::copy(&test_value[0], &test_value[0] + sizeof(test_value), emb.eventAddr());
0150 
0151   // ------ check for sameness
0152 
0153   EventMsgView eview(&buf[0]);
0154 
0155   std::vector<bool> l1_out;
0156   uint8 hlt_out[10];
0157   eview.l1TriggerBits(l1_out);
0158   eview.hltTriggerBits(hlt_out);
0159   adler32_2 = eview.adler32_chksum();
0160   std::string host_name2 = eview.hostName();
0161 
0162   EventMsgBuilder emb2(&buf2[0],
0163                        buf.size(),
0164                        eview.run(),
0165                        eview.event(),
0166                        eview.lumi(),
0167                        eview.outModId(),
0168                        eview.droppedEventsCount(),
0169                        l1_out,
0170                        hlt_out,
0171                        hltsize,
0172                        adler32_2,
0173                        host_name2.c_str());
0174 
0175   emb2.setOrigDataSize(eview.origDataSize());
0176   emb2.setEventLength(eview.eventLength());
0177   std::copy(eview.eventData(), eview.eventData() + eview.eventLength(), emb2.eventAddr());
0178 
0179   if (equal(&buf[0], &buf[0] + emb.size(), buf2.begin()) == false) {
0180     std::cerr << "event messages not the same\n";
0181     std::cerr << "size 1st=" << emb.size() << "\n"
0182               << "size 2nd=" << emb2.size() << "\n";
0183 
0184     dumpEvent(&buf[0]);
0185     dumpEvent(&buf2[0]);
0186     abort();
0187   }
0188   return 0;
0189 } catch (cms::Exception const& e) {
0190   std::cerr << e.explainSelf() << std::endl;
0191   return 1;
0192 }