CMS 3D CMS Logo

SherpackFetcher.cc
Go to the documentation of this file.
2 
3 namespace spf {
4 
6 {
7  if (!pset.exists("SherpaProcess")) SherpaProcess="";
8  else SherpaProcess=pset.getParameter<std::string>("SherpaProcess");
9  if (!pset.exists("SherpackLocation")) SherpackLocation="";
10  else SherpackLocation=pset.getParameter<std::string>("SherpackLocation");
11  if (!pset.exists("SherpackChecksum")) SherpackChecksum="";
12  else SherpackChecksum=pset.getParameter<std::string>("SherpackChecksum");
13  if (!pset.exists("FetchSherpack")) FetchSherpack=false;
14  else FetchSherpack=pset.getParameter<bool>("FetchSherpack");
15  if (!pset.exists("SherpaPath")) SherpaPath="";
16  else SherpaPath=pset.getParameter<std::string>("SherpaPath");
17 
18 }
19 
21 {
22 
23  std::string option = "-c";
24  std::string constr = "`cmsGetFnConnect frontier://smallfiles`";
25  std::string sherpack = "sherpa_" + SherpaProcess + "_MASTER.tgz";
26  std::string sherpackunzip = "sherpa_" + SherpaProcess + "_MASTER.tar";
27  std::string path = SherpackLocation + "/" + sherpack;
28 
29  if(FetchSherpack == true){
30  std::cout << "SherpackFetcher: Trying to fetch the Sherpack " << sherpack << std::endl;
31  int res=-1;
32 
33  res =CopyFile(path);
34 
35  if (res!=1) {
36  throw cms::Exception("SherpaInterface") <<"SherpackFetcher: Fetching of Sherpack did not succeed, terminating" << std::endl;
37  return -1;
38  }
39  std::cout << "SherpackFetcher: Fetching successful" << std::endl;
40  }
41 
42  std::ifstream my_file(sherpack.c_str());
43  if (!my_file.good())
44  {
45  throw cms::Exception("SherpaInterface") << "SherpackFetcher: No Sherpack found" << std::endl;
46  return -2;
47  }
48  my_file.close();
49  std::cout << "SherpackFetcher: Sherpack found" << std::endl;
50 
51  if(SherpackChecksum!=""){
52  char md5checksum[33];
53  spu::md5_File(sherpack, md5checksum);
54  for (int k=0; k<33; k++){
55  if (md5checksum[k]!= SherpackChecksum[k]) {
56  throw cms::Exception("SherpaInterface") << "SherpackFetcher: failure, calculated and specified checksums differ!" << std::endl;
57  return -3;
58  }
59  }
60  std::cout << "SherpackFetcher: Calculated checksum of the Sherpack is " << md5checksum << " and matches" << std::endl;
61  } else {
62  std::cout << "SherpackFetcher: Ignoring Checksum" << std::endl;
63  }
64 
65 
66  std::cout << "SherpackFetcher: Trying to unzip the Sherpack" << std::endl;
67  int res=spu::Unzip(sherpack,sherpackunzip);
68  if (res!=0) {
69  throw cms::Exception("SherpaInterface") << "SherpackFetcher: Decompressing failed " << std::endl;
70  return -4;
71  }
72  std::cout << "SherpackFetcher: Decompressing successful " << std::endl;
73 
74  FILE *file = fopen(const_cast<char*>(sherpackunzip.c_str()),"r");
75  if( file ) {
76  std::cout << "SherpackFetcher: Decompressed Sherpack exists with name " << sherpackunzip << " starting to untar it"<<std::endl;
77  spu::Untar(file,SherpaPath.c_str());
78  } else {
79  throw cms::Exception("SherpaInterface") << "SherpackFetcher: Could not open decompressed Sherpack" << std::endl;
80  return -5;
81  }
82  fclose(file);
83  return 0;
84 }
85 
87 {
88  //No need to backwards compatibility with the FnFileGet method, throw exception if only the relative path is given
89  if ( (pathstring.find("slc6_amd64_gcc")==0) || (pathstring.find("slc5_amd64_gcc")==0) ){
90  throw cms::Exception("SherpaInterface") << "Old method of sherpack retrieving used, please use /cvmfs to store files and specify the full path to the sherpack directory";
91  }
92  std::cout << "Trying to copy file " << pathstring << std::endl;
93  std::string command="cp " +pathstring + " .";
94  FILE *pipe = popen(command.c_str(), "r");
95  if(!pipe)
96  throw cms::Exception("SherpaInterface") << "failed to copy Sherpack ";
97  pclose(pipe);
98  return 1;
99 }
100 
101 
103 {
104 }
105 
106 } // end of namespace definition
107 
108 //~ using spf::SherpackFetcher;
109 //~ 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:4
std::string SherpackChecksum
void Untar(FILE *, const char *)
int k[5][pyjets_maxn]
SherpackFetcher(edm::ParameterSet const &)
list command
Definition: mps_check.py:23
Definition: pipe.py:1
std::string SherpaProcess
int Unzip(std::string, std::string)