File indexing completed on 2024-05-31 04:19:41
0001 #include "FWCore/Utilities/interface/Exception.h"
0002 #include "IOPool/Streamer/interface/DumpTools.h"
0003 #include "IOPool/Streamer/interface/EventMessage.h"
0004 #include "IOPool/Streamer/interface/InitMessage.h"
0005 #include "IOPool/Streamer/interface/MsgTools.h"
0006 #include "IOPool/Streamer/interface/StreamerInputFile.h"
0007 #include "IOPool/Streamer/interface/StreamerOutputFile.h"
0008
0009
0010
0011
0012 using namespace edm::streamer;
0013
0014 void help();
0015 void mergefile(StreamerOutputFile&, std::string const&, bool);
0016
0017
0018 int main(int argc, char* argv[]) {
0019 if (argc < 3) {
0020 std::cout << "No command line argument supplied\n";
0021 help();
0022 return 1;
0023 }
0024
0025 std::string outfile(argv[1]);
0026 std::vector<std::string> streamfiles(argv + 2, argv + argc);
0027
0028 StreamerOutputFile stream_output(outfile);
0029 bool first = true;
0030 for (auto const& sf : streamfiles) {
0031 mergefile(stream_output, sf, first);
0032 first = false;
0033 }
0034
0035 return 0;
0036 }
0037
0038
0039 void help() {
0040 std::cout << "Usage: CatStreamerFile output_file_name streamer_file_name"
0041 << " [streamer_file_name ...]" << std::endl;
0042 }
0043
0044
0045 void mergefile(StreamerOutputFile& stream_output, std::string const& filename, bool includeheader) {
0046 uint32 num_events(0);
0047
0048 try {
0049 StreamerInputFile stream_reader(filename);
0050
0051 std::cout << "Trying to Read The Init message from Streamer File: " << std::endl << filename << std::endl;
0052 InitMsgView const* init = stream_reader.startMessage();
0053 if (includeheader) {
0054 std::cout << "Writing Init message to output file" << std::endl;
0055 stream_output.write(*init);
0056 }
0057
0058 std::cout << "Trying to read the Event messages" << std::endl;
0059 EventMsgView const* eview(nullptr);
0060 while (StreamerInputFile::Next::kEvent == stream_reader.next()) {
0061 eview = stream_reader.currentRecord();
0062 ++num_events;
0063 stream_output.write(*eview);
0064 }
0065 std::cout << "Finished processing " << num_events << " events" << std::endl;
0066 } catch (cms::Exception& e) {
0067 std::cerr << "Exception caught: " << e.what() << std::endl
0068 << "After reading " << num_events << "from file " << filename << std::endl;
0069 }
0070 }