CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
List of all members | Public Member Functions | Private Attributes
spf::SherpackFetcher Class Reference

#include <SherpackFetcher.h>

Public Member Functions

const char * classname () const
 
int CopyFile (std::string pathstring)
 
int Fetch ()
 
 SherpackFetcher (edm::ParameterSet const &)
 
 ~SherpackFetcher ()
 

Private Attributes

bool FetchSherpack
 
std::string SherpackChecksum
 
std::string SherpackLocation
 
std::string SherpaPath
 
std::string SherpaProcess
 

Detailed Description

Definition at line 20 of file SherpackFetcher.h.

Constructor & Destructor Documentation

spf::SherpackFetcher::SherpackFetcher ( edm::ParameterSet const &  pset)

Definition at line 5 of file SherpackFetcher.cc.

References edm::ParameterSet::exists(), FetchSherpack, edm::ParameterSet::getParameter(), SherpackChecksum, SherpackLocation, SherpaPath, SherpaProcess, and AlCaHLTBitMon_QueryRunRegistry::string.

5  {
6  if (!pset.exists("SherpaProcess"))
7  SherpaProcess = "";
8  else
9  SherpaProcess = pset.getParameter<std::string>("SherpaProcess");
10  if (!pset.exists("SherpackLocation"))
11  SherpackLocation = "";
12  else
13  SherpackLocation = pset.getParameter<std::string>("SherpackLocation");
14  if (!pset.exists("SherpackChecksum"))
15  SherpackChecksum = "";
16  else
17  SherpackChecksum = pset.getParameter<std::string>("SherpackChecksum");
18  if (!pset.exists("FetchSherpack"))
19  FetchSherpack = false;
20  else
21  FetchSherpack = pset.getParameter<bool>("FetchSherpack");
22  if (!pset.exists("SherpaPath"))
23  SherpaPath = "";
24  else
25  SherpaPath = pset.getParameter<std::string>("SherpaPath");
26  }
std::string SherpackLocation
std::string SherpackChecksum
std::string SherpaProcess
spf::SherpackFetcher::~SherpackFetcher ( )

Definition at line 109 of file SherpackFetcher.cc.

109 {}

Member Function Documentation

const char* spf::SherpackFetcher::classname ( ) const
inline

Definition at line 26 of file SherpackFetcher.h.

26 { return "SherpackFetcher"; }
int spf::SherpackFetcher::CopyFile ( std::string  pathstring)

Definition at line 94 of file SherpackFetcher.cc.

References mps_check::command, gather_cfg::cout, Exception, pipe::pipe(), and AlCaHLTBitMon_QueryRunRegistry::string.

Referenced by Fetch().

94  {
95  //No need to backwards compatibility with the FnFileGet method, throw exception if only the relative path is given
96  if ((pathstring.find("slc6_amd64_gcc") == 0) || (pathstring.find("slc5_amd64_gcc") == 0)) {
97  throw cms::Exception("SherpaInterface") << "Old method of sherpack retrieving used, please use /cvmfs to store "
98  "files and specify the full path to the sherpack directory";
99  }
100  std::cout << "Trying to copy file " << pathstring << std::endl;
101  std::string command = "cp " + pathstring + " .";
102  FILE *pipe = popen(command.c_str(), "r");
103  if (!pipe)
104  throw cms::Exception("SherpaInterface") << "failed to copy Sherpack ";
105  pclose(pipe);
106  return 1;
107  }
def pipe
Definition: pipe.py:5
list command
Definition: mps_check.py:25
tuple cout
Definition: gather_cfg.py:144
int spf::SherpackFetcher::Fetch ( )

Definition at line 28 of file SherpackFetcher.cc.

References CopyFile(), gather_cfg::cout, Exception, FetchSherpack, mergeVDriftHistosByStation::file, isotrackApplyRegressor::k, spu::md5_File(), fed_dqm_sourceclient-live_cfg::path, SherpackChecksum, SherpackLocation, SherpaPath, SherpaProcess, AlCaHLTBitMon_QueryRunRegistry::string, spu::Untar(), and spu::Unzip().

Referenced by SherpaHadronizer::SherpaHadronizer().

28  {
29  std::string option = "-c";
30  std::string constr = "`cmsGetFnConnect frontier://smallfiles`";
31  std::string sherpack = "sherpa_" + SherpaProcess + "_MASTER.tgz";
32  std::string sherpackunzip = "sherpa_" + SherpaProcess + "_MASTER.tar";
33  std::string path = SherpackLocation + "/" + sherpack;
34 
35  if (FetchSherpack == true) {
36  std::cout << "SherpackFetcher: Trying to fetch the Sherpack " << sherpack << std::endl;
37  int res = -1;
38 
39  res = CopyFile(path);
40 
41  if (res != 1) {
42  throw cms::Exception("SherpaInterface")
43  << "SherpackFetcher: Fetching of Sherpack did not succeed, terminating" << std::endl;
44  return -1;
45  }
46  std::cout << "SherpackFetcher: Fetching successful" << std::endl;
47  }
48 
49  std::ifstream my_file(sherpack.c_str());
50  if (!my_file.good()) {
51  throw cms::Exception("SherpaInterface") << "SherpackFetcher: No Sherpack found" << std::endl;
52  return -2;
53  }
54  my_file.close();
55  std::cout << "SherpackFetcher: Sherpack found" << std::endl;
56 
57  if (!SherpackChecksum.empty()) {
58  char md5checksum[33];
59  spu::md5_File(sherpack, md5checksum);
60  for (int k = 0; k < 33; k++) {
61  if (md5checksum[k] != SherpackChecksum[k]) {
62  throw cms::Exception("SherpaInterface")
63  << "SherpackFetcher: failure, calculated and specified checksums differ!" << std::endl;
64  return -3;
65  }
66  }
67  std::cout << "SherpackFetcher: Calculated checksum of the Sherpack is " << md5checksum << " and matches"
68  << std::endl;
69  } else {
70  std::cout << "SherpackFetcher: Ignoring Checksum" << std::endl;
71  }
72 
73  std::cout << "SherpackFetcher: Trying to unzip the Sherpack" << std::endl;
74  int res = spu::Unzip(sherpack, sherpackunzip);
75  if (res != 0) {
76  throw cms::Exception("SherpaInterface") << "SherpackFetcher: Decompressing failed " << std::endl;
77  return -4;
78  }
79  std::cout << "SherpackFetcher: Decompressing successful " << std::endl;
80 
81  FILE *file = fopen(const_cast<char *>(sherpackunzip.c_str()), "r");
82  if (file) {
83  std::cout << "SherpackFetcher: Decompressed Sherpack exists with name " << sherpackunzip
84  << " starting to untar it" << std::endl;
85  spu::Untar(file, SherpaPath.c_str());
86  } else {
87  throw cms::Exception("SherpaInterface") << "SherpackFetcher: Could not open decompressed Sherpack" << std::endl;
88  return -5;
89  }
90  fclose(file);
91  return 0;
92  }
void md5_File(std::string, char *)
std::string SherpackLocation
int CopyFile(std::string pathstring)
std::string SherpackChecksum
void Untar(FILE *, const char *)
tuple cout
Definition: gather_cfg.py:144
std::string SherpaProcess
int Unzip(std::string, std::string)

Member Data Documentation

bool spf::SherpackFetcher::FetchSherpack
private

Definition at line 32 of file SherpackFetcher.h.

Referenced by Fetch(), and SherpackFetcher().

std::string spf::SherpackFetcher::SherpackChecksum
private

Definition at line 31 of file SherpackFetcher.h.

Referenced by Fetch(), and SherpackFetcher().

std::string spf::SherpackFetcher::SherpackLocation
private

Definition at line 30 of file SherpackFetcher.h.

Referenced by Fetch(), and SherpackFetcher().

std::string spf::SherpackFetcher::SherpaPath
private

Definition at line 33 of file SherpackFetcher.h.

Referenced by Fetch(), and SherpackFetcher().

std::string spf::SherpackFetcher::SherpaProcess
private

Definition at line 29 of file SherpackFetcher.h.

Referenced by Fetch(), and SherpackFetcher().