ATLAS Offline Software
CrestApiBase.cxx
Go to the documentation of this file.
1 #include <CrestApi/picosha2.h>
2 #include <iostream>
4 
5 namespace Crest
6 {
7 
8  std::string CrestApiBase::getHashForFile(const std::string &file)
9  {
10  std::ifstream ifs(file);
11  if (!ifs)
12  {
13  throw CrestException(
14  "ERROR in CrestFsClient::getHashForFile cannot open file \"" + file + "\".");
15  }
16 
18  std::vector<char> buffer(1024 * 1024); // use 1M memory
19  while (ifs.read(buffer.data(), static_cast<std::streamsize>(buffer.size())))
20  {
21  std::cout << "#" << std::flush;
22  hasher.process(buffer.begin(), buffer.end());
23  }
24  // process remains
25  hasher.process(buffer.begin(), buffer.begin() + static_cast<int>(ifs.gcount()));
26  hasher.finish();
27 
28  std::string hash = picosha2::get_hash_hex_string(hasher);
29  return hash;
30  }
31 
32  std::string CrestApiBase::getHash(std::string_view str)
33  {
34  std::string hash_hex_str = picosha2::hash256_hex_string(str.begin(), str.end());
35  return hash_hex_str;
36  }
37 
38  const std::string& CrestApiBase::getClientVersion()
39  {
41  }
42 
43 } // namespace Crest
picosha2::get_hash_hex_string
void get_hash_hex_string(const hash256_one_by_one &hasher, std::string &hex_str)
Definition: picosha2.h:281
CrestApiBase.h
Header file for CREST C++ Client Library.
FullCPAlgorithmsTest_eljob.flush
flush
Definition: FullCPAlgorithmsTest_eljob.py:182
picosha2::hash256_hex_string
void hash256_hex_string(InIter first, InIter last, std::string &hex_str)
Definition: picosha2.h:353
picosha2::hash256_one_by_one::finish
void finish()
Definition: picosha2.h:207
Crest
Definition: CrestApi.h:30
Crest::CrestApiBase::getHash
std::string getHash(std::string_view str)
This method method calculates the hash for string.
Definition: CrestApiBase.cxx:32
createCoolChannelIdFile.buffer
buffer
Definition: createCoolChannelIdFile.py:12
file
TFile * file
Definition: tile_monitor.h:29
picosha2::hash256_one_by_one::process
void process(RaIter first, RaIter last)
Definition: picosha2.h:196
picosha2::hash256_one_by_one
Definition: picosha2.h:184
CaloCondBlobAlgs_fillNoiseFromASCII.hash
dictionary hash
Definition: CaloCondBlobAlgs_fillNoiseFromASCII.py:109
Crest::CrestApiBase::getClientVersion
const std::string & getClientVersion()
This method returns the full CrestApi version.
Definition: CrestApiBase.cxx:38
picosha2.h
str
Definition: BTagTrackIpAccessor.cxx:11
Crest::CrestApiBase::getHashForFile
std::string getHashForFile(const std::string &file)
This method method calculates the hash for a file.
Definition: CrestApiBase.cxx:8
Crest::CrestApiBase::s_CREST_CLIENT_VERSION
static const std::string s_CREST_CLIENT_VERSION
Definition: CrestApiBase.h:36
Crest::CrestException
Definition: CrestException.h:9