Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-05-31 04:19:43

0001 /** Example code shows you to write Streamer files.
0002     All values are dummy here, The Init message contains different
0003     values from what Event Header contains, this is only
0004     for the demonstration, obviously.
0005 
0006     Change total number of written events using,
0007 
0008      #define NO_OF_EVENTS 10
0009 
0010     Crank it up to 10000 if you like to scrol your screen ;-).
0011 
0012 Disclaimer: Most of the code here is randomly written during
0013                testing various parts, its not a supported testing code.
0014                Changes can and will be made, when and if required.
0015 */
0016 
0017 #include <iostream>
0018 #include "IOPool/Streamer/interface/MsgTools.h"
0019 #include "IOPool/Streamer/interface/EventMsgBuilder.h"
0020 #include "IOPool/Streamer/interface/InitMsgBuilder.h"
0021 #include "IOPool/Streamer/interface/InitMessage.h"
0022 
0023 #include "FWCore/Utilities/interface/Adler32Calculator.h"
0024 #include "FWCore/Utilities/interface/Exception.h"
0025 #include "IOPool/Streamer/interface/StreamerOutputFile.h"
0026 
0027 #include "zlib.h"
0028 
0029 #define NO_OF_EVENTS 10
0030 
0031 using namespace edm::streamer;
0032 
0033 int main() try {
0034   typedef std::vector<uint8> Buffer;
0035   Buffer buf(1024);
0036   Buffer buf2(11024);
0037 
0038   // ----------- init
0039 
0040   char psetid[] = "1234567890123456";
0041   char test_value[] = "This is a test, This is a";
0042   char test_value_event[] = "This is a test Event, This is a";
0043   Strings hlt_names;
0044   Strings l1_names;
0045 
0046   hlt_names.push_back("a");
0047   hlt_names.push_back("b");
0048   hlt_names.push_back("c");
0049   hlt_names.push_back("d");
0050   hlt_names.push_back("e");
0051   hlt_names.push_back("f");
0052   hlt_names.push_back("g");
0053   hlt_names.push_back("h");
0054   hlt_names.push_back("i");
0055 
0056   l1_names.push_back("t10");
0057   l1_names.push_back("t11");
0058   l1_names.push_back("t12");
0059   l1_names.push_back("t13");
0060   l1_names.push_back("t14");
0061   l1_names.push_back("t15");
0062   l1_names.push_back("t16");
0063   l1_names.push_back("t17");
0064   l1_names.push_back("t18");
0065   l1_names.push_back("t19");
0066   l1_names.push_back("t20");
0067 
0068   char reltag[] = "CMSSW_0_8_0_pre7";
0069   std::string processName = "HLT";
0070   std::string outputModuleLabel = "HLTOutput";
0071 
0072   uLong crc = crc32(0L, Z_NULL, 0);
0073   Bytef* crcbuf = (Bytef*)outputModuleLabel.data();
0074   crc = crc32(crc, crcbuf, outputModuleLabel.length());
0075 
0076   uint32 adler32_chksum = (uint32)cms::Adler32((char*)&test_value[0], sizeof(test_value));
0077 
0078   InitMsgBuilder init(&buf[0],
0079                       buf.size(),
0080                       12,
0081                       Version((const uint8*)psetid),
0082                       (const char*)reltag,
0083                       processName.c_str(),
0084                       outputModuleLabel.c_str(),
0085                       crc,
0086                       hlt_names,
0087                       hlt_names,
0088                       l1_names,
0089                       adler32_chksum);
0090 
0091   init.setDataLength(sizeof(test_value));
0092   std::copy(&test_value[0], &test_value[0] + sizeof(test_value), init.dataAddress());
0093 
0094   //Do a dumpInit here if you need to see the event.
0095 
0096   //Start the Streamer file
0097   std::cout << "Trying to Write a Streamer file" << std::endl;
0098   std::string initfilename = "teststreamfile.dat";
0099   StreamerOutputFile stream_writer(initfilename);
0100 
0101   std::cout << "Trying to Write Out The Init message into Streamer File: " << initfilename << std::endl;
0102   stream_writer.write(init);
0103 
0104   // ------- event
0105 
0106   std::vector<bool> l1bit(11);
0107   uint8 hltbits[] = "4567";
0108   const int hltsize = 9; /** I am interested in 9 bits only */
0109 
0110   l1bit[0] = true;
0111   l1bit[4] = true;
0112   l1bit[8] = false;  //l1bit[12]=true;
0113   l1bit[1] = true;
0114   l1bit[5] = false;
0115   l1bit[9] = false;  //l1bit[13]=false;
0116   l1bit[2] = false;
0117   l1bit[6] = true;
0118   l1bit[10] = true;  //l1bit[14]=false;
0119   l1bit[3] = false;
0120   l1bit[7] = false;  //l1bit[11]=true;  //l1bit[15]=true;
0121   //l1bit[16]=false;  l1bit[17]=false;  l1bit[18]=true;  l1bit[19]=true;
0122 
0123   //Lets Build 10 Events and then Write them into Streamer file.
0124 
0125   adler32_chksum = (uint32)cms::Adler32((char*)&test_value_event[0], sizeof(test_value_event));
0126   std::string host_name = "mytestnode.cms";
0127 
0128   for (uint32 eventId = 2000; eventId != 2000 + NO_OF_EVENTS; ++eventId) {
0129     EventMsgBuilder emb(
0130         &buf2[0], buf2.size(), 45, eventId, 2, 0xdeadbeef, 3, l1bit, hltbits, hltsize, adler32_chksum, host_name.c_str());
0131     emb.setOrigDataSize(78);
0132     emb.setEventLength(sizeof(test_value_event));
0133     std::copy(&test_value_event[0], &test_value_event[0] + sizeof(test_value_event), emb.eventAddr());
0134 
0135     //Lets write this to our streamer file .
0136     std::cout << "Writing Event# : " << eventId << " To Streamer file" << std::endl;
0137     stream_writer.write(emb);
0138   }
0139 
0140   return 0;
0141 } catch (cms::Exception const& e) {
0142   std::cerr << e.explainSelf() << std::endl;
0143   return 1;
0144 }