CMS 3D CMS Logo

Functions
calculateIdMD5.cc File Reference
#include <iostream>
#include <TSystem.h>
#include "FWCore/FWLite/interface/FWLiteEnabler.h"
#include "FWCore/Utilities/interface/Exception.h"
#include "FWCore/ParameterSet/interface/ParameterSet.h"
#include "FWCore/ParameterSetReader/interface/ParameterSetReader.h"
#include "Utilities/OpenSSL/interface/openssl_init.h"

Go to the source code of this file.

Functions

int main (int argc, char **argv)
 

Function Documentation

◆ main()

int main ( int  argc,
char **  argv 
)

Definition at line 14 of file calculateIdMD5.cc.

References dir2webdir::argc, GCPpyPlots::argv, gather_cfg::cout, edm::ParameterSet::dump(), FWLiteEnabler::enable(), EVP_MD_CTX_free, EVP_MD_CTX_new, Exception, beamvalidation::exit(), mps_fire::i, cms::openssl_init(), edm::readPSetsFrom(), AlCaHLTBitMon_QueryRunRegistry::string, edm::ParameterSet::trackedPart(), and Types::untracked.

14  {
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
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="")