Back to home page

Project CMSSW displayed by LXR

 
 

    


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

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   if (argc < 2) {
0012     std::cerr << "No command line argument given, expected path/filename.\n";
0013     return 1;
0014   }
0015 
0016   std::string filename(argv[1]);
0017   std::ifstream file(filename.c_str(), std::ios::in | std::ios::binary | std::ios::ate);
0018   if (!file.is_open()) {
0019     std::cerr << "File " << filename << " could not be opened.\n";
0020     return 1;
0021   }
0022 
0023   std::ifstream::pos_type size = file.tellg();
0024   file.seekg(0, std::ios::beg);
0025 
0026   auto ptr = std::make_unique<char[]>(1024 * 1024);
0027   uint32_t a = 1, b = 0;
0028 
0029   std::ifstream::pos_type rsize = 0;
0030   while (rsize < size) {
0031     file.read(ptr.get(), 1024 * 1024);
0032     rsize += 1024 * 1024;
0033     //std::cout << file.tellg() << " " << rsize << " " << size << " - " << file.gcount() << std::endl;
0034     if (file.gcount()) {
0035       cms::Adler32(ptr.get(), file.gcount(), a, b);
0036     } else {
0037       break;
0038     }
0039   }
0040 
0041   uint32 adler = (b << 16) | a;
0042   std::cout << std::hex << adler << std::dec << " " << filename << std::endl;
0043 
0044   file.close();
0045   return 0;
0046 }