CMS 3D CMS Logo

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.

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 }
std::string SherpackLocation
std::string SherpackChecksum
std::string SherpaProcess
spf::SherpackFetcher::~SherpackFetcher ( )

Definition at line 102 of file SherpackFetcher.cc.

103 {
104 }

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 86 of file SherpackFetcher.cc.

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

Referenced by Fetch().

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 }
list command
Definition: mps_check.py:23
Definition: pipe.py:1
int spf::SherpackFetcher::Fetch ( )

Definition at line 20 of file SherpackFetcher.cc.

References CopyFile(), gather_cfg::cout, Exception, FetchSherpack, FrontierConditions_GlobalTag_cff::file, gen::k, spu::md5_File(), TSGForRoadSearch_cfi::option, callgraph::path, SherpackChecksum, SherpackLocation, SherpaPath, SherpaProcess, AlCaHLTBitMon_QueryRunRegistry::string, spu::Untar(), and spu::Unzip().

Referenced by SherpaHadronizer::SherpaHadronizer().

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 }
void md5_File(std::string, char *)
std::string SherpackLocation
int CopyFile(std::string pathstring)
Definition: Electron.h:6
std::string SherpackChecksum
void Untar(FILE *, const char *)
int k[5][pyjets_maxn]
std::string SherpaProcess
int Unzip(std::string, std::string)

Member Data Documentation

bool spf::SherpackFetcher::FetchSherpack
private

Definition at line 33 of file SherpackFetcher.h.

Referenced by Fetch(), and SherpackFetcher().

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

Definition at line 32 of file SherpackFetcher.h.

Referenced by Fetch(), and SherpackFetcher().

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

Definition at line 31 of file SherpackFetcher.h.

Referenced by Fetch(), and SherpackFetcher().

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

Definition at line 34 of file SherpackFetcher.h.

Referenced by Fetch(), and SherpackFetcher().

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

Definition at line 30 of file SherpackFetcher.h.

Referenced by Fetch(), and SherpackFetcher().