Back to home page

Project CMSSW displayed by LXR

 
 

    


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

0001 #include "FWCore/Utilities/interface/Adler32Calculator.h"
0002 #include "IOPool/Streamer/interface/MsgTools.h"
0003 
0004 #include <memory>
0005 
0006 #include <fstream>
0007 #include <iostream>
0008 #include <cstdint>
0009 
0010 int main(int argc, char* argv[]) {
0011   using namespace edm::streamer;
0012 
0013   if (argc < 2) {
0014     std::cerr << "No command line argument given, expected path/filename.\n";
0015     return 1;
0016   }
0017 
0018   std::string filename(argv[1]);
0019   std::ifstream file(filename.c_str(), std::ios::in | std::ios::binary | std::ios::ate);
0020   if (!file.is_open()) {
0021     std::cerr << "File " << filename << " could not be opened.\n";
0022     return 1;
0023   }
0024 
0025   std::ifstream::pos_type size = file.tellg();
0026   file.seekg(0, std::ios::beg);
0027 
0028   auto ptr = std::make_unique<char[]>(1024 * 1024);
0029   uint32_t a = 1, b = 0;
0030 
0031   std::ifstream::pos_type rsize = 0;
0032   while (rsize < size) {
0033     file.read(ptr.get(), 1024 * 1024);
0034     rsize += 1024 * 1024;
0035     //std::cout << file.tellg() << " " << rsize << " " << size << " - " << file.gcount() << std::endl;
0036     if (file.gcount()) {
0037       cms::Adler32(ptr.get(), file.gcount(), a, b);
0038     } else {
0039       break;
0040     }
0041   }
0042 
0043   uint32 adler = (b << 16) | a;
0044   std::cout << std::hex << adler << std::dec << " " << filename << std::endl;
0045 
0046   file.close();
0047   return 0;
0048 }