CMS 3D CMS Logo

SherpackFetcher.cc
Go to the documentation of this file.
2 
3 namespace spf {
4 
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  }
27 
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  }
93 
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  }
108 
110 
111 } // namespace spf
112 
113 //~ using spf::SherpackFetcher;
114 //~ DEFINE_FWK_MODULE(SherpackFetcher);
T getParameter(std::string const &) const
void md5_File(std::string, char *)
std::string SherpackLocation
int CopyFile(std::string pathstring)
bool exists(std::string const &parameterName) const
checks if a parameter exists
Definition: Electron.h:6
std::string SherpackChecksum
void Untar(FILE *, const char *)
SherpackFetcher(edm::ParameterSet const &)
list command
Definition: mps_check.py:25
Definition: pipe.py:1
std::string SherpaProcess
int Unzip(std::string, std::string)