CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros 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 Fetch ()
 
int FnFileGet (std::string)
 
 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 28 of file SherpackFetcher.h.

Constructor & Destructor Documentation

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

Definition at line 14 of file SherpackFetcher.cc.

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

15 {
16  if (!pset.exists("SherpaProcess")) SherpaProcess="";
17  else SherpaProcess=pset.getParameter<std::string>("SherpaProcess");
18  if (!pset.exists("SherpackLocation")) SherpackLocation="";
19  else SherpackLocation=pset.getParameter<std::string>("SherpackLocation");
20  if (!pset.exists("SherpackChecksum")) SherpackChecksum="";
21  else SherpackChecksum=pset.getParameter<std::string>("SherpackChecksum");
22  if (!pset.exists("FetchSherpack")) FetchSherpack=false;
23  else FetchSherpack=pset.getParameter<bool>("FetchSherpack");
24  if (!pset.exists("SherpaPath")) SherpaPath="";
25  else SherpaPath=pset.getParameter<std::string>("SherpaPath");
26 
27 }
std::string SherpackLocation
std::string SherpackChecksum
std::string SherpaProcess
spf::SherpackFetcher::~SherpackFetcher ( )

Definition at line 206 of file SherpackFetcher.cc.

207 {
208 }

Member Function Documentation

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

Definition at line 34 of file SherpackFetcher.h.

34 { return "SherpackFetcher"; }
int spf::SherpackFetcher::Fetch ( )

Definition at line 29 of file SherpackFetcher.cc.

References gather_cfg::cout, FetchSherpack, mergeVDriftHistosByStation::file, FnFileGet(), gen::k, spu::md5_File(), cmsHarvester::path, SherpackChecksum, SherpackLocation, SherpaPath, SherpaProcess, AlCaHLTBitMon_QueryRunRegistry::string, spu::Untar(), and spu::Unzip().

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

Definition at line 95 of file SherpackFetcher.cc.

References dtNoiseDBValidation_cfg::cerr, HDQMDatabaseProducer::config, lumiQueryAPI::connectstr, edm::ServiceRegistry::createContaining(), alignCSCRings::e, cms::Exception::explainSelf(), edm::SiteLocalConfig::lookupCalibConnect(), n, NULL, cmsPerfStripChart::operate(), AlCaHLTBitMon_ParallelJobs::p, cmsHarvester::path, AlCaHLTBitMon_QueryRunRegistry::string, and TablePrint::write.

Referenced by Fetch().

96 {
97  int ec;
98  unsigned long channel;
99  FrontierConfig *config;
100 
102  try {
103  std::auto_ptr<edm::SiteLocalConfig> slcptr(new edm::service::SiteLocalConfigService(edm::ParameterSet()));
104  boost::shared_ptr<edm::serviceregistry::ServiceWrapper<edm::SiteLocalConfig> > slc(new edm::serviceregistry::ServiceWrapper<edm::SiteLocalConfig>(slcptr));
107 
108  edm::Service<edm::SiteLocalConfig> localconfservice;
109  localconfservice->lookupCalibConnect("frontier://smallfiles");
110  connectstr=localconfservice->lookupCalibConnect("frontier://smallfiles");
111  } catch(cms::Exception const& e) {
112  std::cerr << e.explainSelf() << std::endl;
113  return 2;
114  }
115 
116  if(frontier_init(malloc,free)!=0)
117  {
118  fprintf(stderr,"Error initializing frontier client: %s\n",frontier_getErrorMsg());
119  return 2;
120  }
121  ec=FRONTIER_OK;
122  //~ config=frontierConfig_get(connectstr,"",&ec);
123  config=frontierConfig_get(connectstr.c_str(),"",&ec);
124  if(ec!=FRONTIER_OK)
125  {
126  fprintf(stderr,"Error getting frontierConfig object: %s\n",frontier_getErrorMsg());
127  return 2;
128  }
129  channel=frontier_createChannel2(config,&ec);
130  if(ec!=FRONTIER_OK)
131  {
132  fprintf(stderr,"Error creating frontier channel: %s\n",frontier_getErrorMsg());
133  return 2;
134  }
135 
136 
137  char uribuf[4096];
138  FrontierRSBlob *frsb;
139  int fd;
140  int n;
141  char *p;
142  const char *localname;
143 
144  const char *path=pathstring.c_str();
145  snprintf(uribuf,sizeof(uribuf)-1, "Frontier/type=frontier_file:1:DEFAULT&encoding=BLOB&p1=%s",path);
146  ec=frontier_getRawData(channel,uribuf);
147  if(ec!=FRONTIER_OK)
148  {
149  fprintf(stderr,"Error getting data for %s: %s\n",path,frontier_getErrorMsg());
150  return 3;
151  }
152  frsb=frontierRSBlob_open(channel,0,1,&ec);
153  if(ec!=FRONTIER_OK)
154  {
155  fprintf(stderr,"Error opening result blob for %s: %s\n",path,frontier_getErrorMsg());
156  return 3;
157  }
158  // ignore the result type, will always be an array
159  (void)frontierRSBlob_getByte(frsb,&ec);
160  if(ec!=FRONTIER_OK)
161  {
162  fprintf(stderr,"Error getting result type for %s: %s\n",path,frontier_getErrorMsg());
163  return 3;
164  }
165  n=frontierRSBlob_getInt(frsb,&ec);
166  if(ec!=FRONTIER_OK)
167  {
168  fprintf(stderr,"Error getting result size for %s: %s\n",path,frontier_getErrorMsg());
169  return 3;
170  }
171  p=frontierRSBlob_getByteArray(frsb,n,&ec);
172  if(ec!=FRONTIER_OK)
173  {
174  fprintf(stderr,"Error getting result data for %s: %s\n",path,frontier_getErrorMsg());
175  return 3;
176  }
177  localname=strrchr(path,'/');
178  if(localname==NULL)
179  localname=pathstring.c_str();
180  else
181  localname++;
182  fd=open(localname,O_CREAT|O_TRUNC|O_WRONLY,0666);
183  if(fd==-1)
184  {
185  fprintf(stderr,"Error creating %s: %s\n",localname,strerror(errno));
186  ec=-1;
187  return 3;
188  }
189  if(write(fd,p,n)<0)
190  {
191  fprintf(stderr,"Error writing to %s: %s\n",localname,strerror(errno));
192  ec=-1;
193  close(fd);
194  return 3;
195  }
196  close(fd);
197  printf("%d bytes written to %s\n",n,localname);
198  frontierRSBlob_close(frsb,&ec);
199 
200 
201  frontier_closeChannel(channel);
202 
203  return (ec==FRONTIER_OK);
204 }
virtual std::string explainSelf() const
Definition: Exception.cc:146
#define NULL
Definition: scimark2.h:8
virtual std::string const lookupCalibConnect(std::string const &input) const =0
static ServiceToken createContaining(std::auto_ptr< T > iService)
create a service token that holds the service defined by iService
tuple path
else: Piece not in the list, fine.
string connectstr

Member Data Documentation

bool spf::SherpackFetcher::FetchSherpack
private

Definition at line 41 of file SherpackFetcher.h.

Referenced by Fetch(), and SherpackFetcher().

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

Definition at line 40 of file SherpackFetcher.h.

Referenced by Fetch(), and SherpackFetcher().

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

Definition at line 39 of file SherpackFetcher.h.

Referenced by Fetch(), and SherpackFetcher().

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

Definition at line 42 of file SherpackFetcher.h.

Referenced by Fetch(), and SherpackFetcher().

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

Definition at line 38 of file SherpackFetcher.h.

Referenced by Fetch(), and SherpackFetcher().