CMS 3D CMS Logo

calculateIdMD5.cc
Go to the documentation of this file.
1 #include <iostream>
2 #include <TSystem.h>
3 
6 
9 
11 
12 using namespace std;
13 
14 int main(int argc, char** argv) {
15  // load framework libraries
16  gSystem->Load("libFWCoreFWLite");
18 
19  if (argc < 3) {
20  std::cout << "Usage : " << argv[0] << " [your_cutflow_only.py] "
21  << "[cutflow_name] " << std::endl;
22  return 0;
23  }
24 
25  if (!edm::readPSetsFrom(argv[1])->existsAs<edm::ParameterSet>(argv[2])) {
26  std::cout << " ERROR: ParametersSet '" << argv[2] << "' is missing in your configuration file" << std::endl;
27  exit(0);
28  }
29 
30  edm::ParameterSet conf = edm::readPSetsFrom(argv[1])->getParameterSet(argv[2]);
31  edm::ParameterSet trackedconf = conf.trackedPart();
32 
33  std::string tracked(trackedconf.dump()), untracked(conf.dump());
34 
35  if (tracked != untracked) {
36  throw cms::Exception("InvalidConfiguration") << "IDs are not allowed to have untracked parameters"
37  << " in the configuration ParameterSet!";
38  }
39 
40  // now setup the md5 and cute accessor functions
42  EVP_MD_CTX* mdctx = EVP_MD_CTX_new();
43  const EVP_MD* md = EVP_get_digestbyname("SHA1");
44  unsigned int md_len = 0;
45  unsigned char id_md5_[EVP_MAX_MD_SIZE];
46 
47  EVP_DigestInit_ex(mdctx, md, nullptr);
48  EVP_DigestUpdate(mdctx, (const unsigned char*)tracked.c_str(), tracked.size());
49  EVP_DigestFinal_ex(mdctx, id_md5_, &md_len);
50  EVP_MD_CTX_free(mdctx);
51 
52  printf("%s : ", argv[2]);
53  for (unsigned i = 0; i < md_len; ++i) {
54  printf("%02x", id_md5_[i]);
55  }
56  printf("\n");
57 
58  return 0;
59 }
void openssl_init()
Definition: openssl_init.cc:5
untracked
Definition: Types.py:34
ParameterSet trackedPart() const
#define EVP_MD_CTX_free
Definition: openssl_init.h:7
#define EVP_MD_CTX_new
Definition: openssl_init.h:6
int main(int argc, char **argv)
static void enable()
enable automatic library loading
std::unique_ptr< edm::ParameterSet > readPSetsFrom(std::string const &fileOrString)
std::string dump(unsigned int indent=0) const
def exit(msg="")