CMS 3D CMS Logo

Hash.cc
Go to the documentation of this file.
5 
6 #include <functional>
7 
8 namespace edm {
9  namespace detail {
10  // This string is the 16-byte, non-printable version.
12  static std::string const invalid = cms::MD5Result().compactForm();
13  return invalid;
14  }
15  } // namespace detail
16 
17  namespace hash_detail {
19  if (isCompactForm_(hash)) {
20  return hash;
21  }
23  fixup_(temp);
24  return temp;
25  }
26 
27  // 'Fix' the string data member of this Hash, i.e., if it is in
28  // the hexified (32 byte) representation, make it be in the
29  // 16-byte (unhexified) representation.
31  switch (hash.size()) {
32  case 16: {
33  break;
34  }
35  case 32: {
37  temp.fromHexifiedString(hash);
38  hash = temp.compactForm();
39  break;
40  }
41  case 0: {
42  throw Exception(errors::LogicError) << "Empty edm::Hash<> instance:\n"
43  << "\nPlease report this to the core framework developers";
44  }
45  default: {
46  throw Exception(errors::LogicError) << "edm::Hash<> instance with data in illegal state:\n"
47  << hash << "\nPlease report this to the core framework developers";
48  }
49  }
50  }
51 
52  size_t smallHash_(value_type const& hash) {
53  //NOTE: In future we could try to xor the first 8bytes into the second 8bytes of the string to make the hash
54  std::hash<std::string> h;
55  if (hash.size() == 16) {
56  return h(hash);
57  }
58  return h(compactForm_(hash));
59  }
60 
61  bool isCompactForm_(value_type const& hash) { return 16 == hash.size(); }
62 
63  bool isValid_(value_type const& hash) {
64  return isCompactForm_(hash) ? (hash != detail::InvalidHash()) : (!hash.empty());
65  }
66 
68  // Fixup not needed here.
69  if (hash.size() % 2 == 1) {
70  throw Exception(errors::LogicError) << "Ill-formed Hash instance. "
71  << "Please report this to the core framework developers";
72  }
73  }
74 
76  value_type temp1(hash);
77  fixup_(temp1);
79  copy_all(temp1, temp.bytes);
80  result += temp.toString();
81  }
82 
83  void toDigest_(cms::Digest& digest, value_type const& hash) {
84  // FIXME: do we really need to go through a temporary value_type???
85  value_type temp1(hash);
86  fixup_(temp1);
88  copy_all(temp1, temp.bytes);
89  digest.append(temp.toString());
90  }
91 
92  std::ostream& print_(std::ostream& os, value_type const& hash) {
93  value_type temp1(hash);
94  fixup_(temp1);
96  copy_all(temp1, temp.bytes);
97  os << temp.toString();
98  return os;
99  }
100  } // namespace hash_detail
101 } // namespace edm
cms::Digest::append
void append(std::string const &s)
Definition: Digest.cc:161
edm::copy_all
Func copy_all(ForwardSequence &s, Func f)
wrappers for copy
Definition: Algorithms.h:20
edm::errors::LogicError
Definition: EDMException.h:37
edm::hash_detail::toString_
void toString_(std::string &result, value_type const &hash)
Definition: Hash.cc:75
cond::hash
Definition: Time.h:19
edm
HLT enums.
Definition: AlignableModifier.h:19
h
FWCore Framework interface EventSetupRecordImplementation h
Helper function to determine trigger accepts.
Definition: L1TUtmAlgorithmRcd.h:4
edm::hash_detail::fixup_
void fixup_(value_type &hash)
Definition: Hash.cc:30
edm::hash_detail::toDigest_
void toDigest_(cms::Digest &digest, value_type const &hash)
Definition: Hash.cc:83
Algorithms.h
edm::hash_detail::isValid_
bool isValid_(value_type const &hash)
Definition: Hash.cc:63
detail
Definition: ConvertingESProducerWithDependenciesT.h:23
groupFilesInBlocks.temp
list temp
Definition: groupFilesInBlocks.py:142
edm::hash_detail::value_type
std::string value_type
Definition: Hash.h:30
EDMException.h
cms::Digest
Definition: Digest.h:46
edm::hash_detail::smallHash_
size_t smallHash_(value_type const &hash)
Definition: Hash.cc:52
AlCaHLTBitMon_QueryRunRegistry.string
string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
cms::MD5Result
Definition: Digest.h:11
edm::hash_detail::compactForm_
value_type compactForm_(value_type const &hash)
Definition: Hash.cc:18
Digest.h
edm::hash_detail::throwIfIllFormed
void throwIfIllFormed(value_type const &hash)
Definition: Hash.cc:67
Exception
Definition: hltDiff.cc:245
cms::MD5Result::compactForm
std::string compactForm() const
Definition: Digest.cc:109
mps_fire.result
result
Definition: mps_fire.py:311
Hash.h
edm::hash_detail::print_
std::ostream & print_(std::ostream &os, value_type const &hash)
Definition: Hash.cc:92
edm::hash_detail::isCompactForm_
bool isCompactForm_(value_type const &hash)
Definition: Hash.cc:61
edm::detail::InvalidHash
std::string const & InvalidHash()
Definition: Hash.cc:11