56static const std::string
VERSION =
"0.2.0";
59" TDavixFile/" +
VERSION +
" davix/" + Davix::version();
62#define ENVPFX "Davix."
88 if (!str)
return false;
90 if (!strcmp(str,
"n") || !strcmp(str,
"no") || !strcmp(str,
"0") || !strcmp(str,
"false"))
return true;
97 if(!str)
return defvalue;
99 if(strcmp(str,
"n") == 0 || strcmp(str,
"no") == 0 || strcmp(str,
"0") == 0 || strcmp(str,
"false") == 0)
return false;
100 if(strcmp(str,
"y") == 0 || strcmp(str,
"yes") == 0 || strcmp(str,
"1") == 0 || strcmp(str,
"true") == 0)
return true;
110 old_flag |= O_RDONLY;
113 old_flag |= (O_CREAT | O_WRONLY | O_TRUNC);
116 old_flag |= (O_RDWR);
129 davix_set_log_level(0);
132 davix_set_log_level(DAVIX_LOG_WARNING);
135 davix_set_log_level(DAVIX_LOG_VERBOSE);
138 davix_set_log_level(DAVIX_LOG_DEBUG);
141 davix_set_log_level(DAVIX_LOG_ALL);
153 char default_proxy[64];
154 const char *genvvar = 0, *genvvar1 = 0;
156 genvvar =
gEnv->
GetValue(
"Davix.GSI.UserProxy", (
const char *) NULL);
158 ucert = ukey = genvvar;
160 Info(
"TDavixFile_http_get_ucert",
"Found proxy in gEnv");
165 if (getenv(
"X509_USER_PROXY")) {
167 Info(
"TDavixFile_http_get_ucert",
"Found proxy in X509_USER_PROXY");
168 ucert = ukey = getenv(
"X509_USER_PROXY");
173 snprintf(default_proxy,
sizeof(default_proxy),
"/tmp/x509up_u%d",
176 if (access(default_proxy, R_OK) == 0) {
178 Info(
"TDavixFile_http_get_ucert",
"Found proxy in /tmp");
179 ucert = ukey = default_proxy;
184 genvvar =
gEnv->
GetValue(
"Davix.GSI.UserCert", (
const char *) NULL);
185 genvvar1 =
gEnv->
GetValue(
"Davix.GSI.UserKey", (
const char *) NULL);
186 if (genvvar || genvvar1) {
188 Info(
"TDavixFile_http_get_ucert",
"Found cert and key in gEnv");
196 if (getenv(
"X509_USER_CERT"))
197 ucert = getenv(
"X509_USER_CERT");
198 if (getenv(
"X509_USER_KEY"))
199 ukey = getenv(
"X509_USER_KEY");
201 if ((ucert.size() > 0) || (ukey.size() > 0)) {
203 Info(
"TDavixFile_http_get_ucert",
"Found cert and key in gEnv");
212 Davix::X509Credential *cert, Davix::DavixError **err)
216 std::string ucert, ukey;
219 if (ucert.empty() || ukey.empty()) {
220 Davix::DavixError::setupError(err,
"TDavixFile",
221 Davix::StatusCode::AuthentificationError,
222 "Could not set the user's proxy or certificate");
225 return cert->loadFromFilePEM(ukey, ucert,
"", err);
254 DavixError *davixErr = NULL;
262 DavixError *davixErr2 = NULL;
265 std::vector<DavFile> replicasLocal =
file.getReplicas(NULL, &davixErr2);
266 for(
size_t i = 0; i < replicasLocal.size(); i++) {
267 replicas.push_back(replicasLocal[i].getUri().getString());
271 DavixError::clearError(&davixErr2);
276 Error(
"DavixOpen",
"can not open file \"%s\" with davix: %s (%d)",
278 davixErr->getErrMsg().c_str(), davixErr->getStatus());
280 DavixError::clearError(&davixErr);
283 davixPosix->fadvise(fd, 0, 300, Davix::AdviseRandom);
293 DavixError *davixErr = NULL;
295 Error(
"DavixClose",
"can not to close file with davix: %s (%d)",
296 davixErr->getErrMsg().c_str(), davixErr->getStatus());
297 DavixError::clearError(&davixErr);
305 const char *env_var = NULL;
308 Info(
"enableGridMode",
" grid mode enabled !");
310 if( ( env_var = getenv(
"X509_CERT_DIR")) == NULL){
311 env_var=
"/etc/grid-security/certificates/";
313 davixParam->addCertificateAuthorityPath(env_var);
315 Info(
"enableGridMode",
"Adding CAdir %s", env_var);
328template<
typename TRequestParams = Davix::RequestParams>
329static auto awsRegion(TRequestParams *parameters,
const char *region)
330 ->
decltype(parameters->setAwsRegion(region),
void())
332 if (
gDebug > 1)
Info(
"awsRegion",
"Setting S3 Region to '%s' - v4 signature will be used", region);
333 parameters->setAwsRegion(region);
336template<
typename TRequestParams = Davix::RequestParams>
338 Warning(
"setAwsRegion",
"Unable to set AWS region, not supported by this version of davix");
342template<
typename TRequestParams = Davix::RequestParams>
343static auto awsToken(TRequestParams *parameters,
const char *token)
344 ->
decltype(parameters->setAwsToken(token),
void())
346 if (
gDebug > 1)
Info(
"awsToken",
"Setting S3 STS temporary credentials");
347 parameters->setAwsToken(token);
350template<
typename TRequestParams = Davix::RequestParams>
352 Warning(
"awsToken",
"Unable to set AWS token, not supported by this version of davix");
356template<
typename TRequestParams = Davix::RequestParams>
358 ->
decltype(parameters->setAwsAlternate(option),
void())
360 if (
gDebug > 1)
Info(
"awsAlternate",
"Setting S3 path-based bucket option (s3alternate)");
361 parameters->setAwsAlternate(option);
364template<
typename TRequestParams = Davix::RequestParams>
366 Warning(
"awsAlternate",
"Unable to set AWS path-based bucket option (s3alternate), not supported by this version of davix");
370 if(!region.empty()) {
387 const std::string ®ion,
const std::string &token)
390 Info(
"setS3Auth",
" Aws S3 tokens configured");
392 davixParam->setAwsAuthorizationKeys(secret, access);
393 davixParam->setProtocol(RequestProtocol::AwsS3);
403 const char *env_var = NULL, *env_var2 = NULL;
405 davixParam->setTransparentRedirectionSupport(
true);
409 env_var =
gEnv->
GetValue(
"Davix.GSI.CAdir", (
const char *) NULL);
411 davixParam->addCertificateAuthorityPath(env_var);
413 Info(
"parseConfig",
"Add CAdir: %s", env_var);
416 bool ca_check_local = !
isno(
gEnv->
GetValue(
"Davix.GSI.CACheck", (
const char *)
"y"));
419 Info(
"parseConfig",
"Setting CAcheck to %s", ((ca_check_local) ? (
"true") : (
"false")));
422 if (((env_var =
gEnv->
GetValue(
"Davix.S3.SecretKey", getenv(
"S3_SECRET_KEY"))) != NULL)
423 && ((env_var2 =
gEnv->
GetValue(
"Davix.S3.AccessKey", getenv(
"S3_ACCESS_KEY"))) != NULL)) {
424 Info(
"parseConfig",
"Setting S3 SecretKey and AccessKey. Access Key : %s ", env_var2);
425 davixParam->setAwsAuthorizationKeys(env_var, env_var2);
428 if ( (env_var =
gEnv->
GetValue(
"Davix.S3.Region", getenv(
"S3_REGION"))) != NULL) {
432 if( (env_var =
gEnv->
GetValue(
"Davix.S3.Token", getenv(
"S3_TOKEN"))) != NULL) {
436 if( (env_var =
gEnv->
GetValue(
"Davix.S3.Alternate", getenv(
"S3_ALTERNATE"))) != NULL) {
441 env_var =
gEnv->
GetValue(
"Davix.GSI.GridMode", (
const char *)
"y");
451 std::stringstream ss(option);
453 std::vector<std::string> parsed_options;
455 std::string s3seckey, s3acckey, s3region, s3token;
457 while (std::getline(ss, item,
' ')) {
458 parsed_options.push_back(item);
461 for (std::vector<std::string>::iterator it = parsed_options.begin(); it < parsed_options.end(); ++it) {
484 s3token = std::string(it->c_str() + strlen(
s3_token_opt));
494 if (s3seckey.size() > 0) {
495 setS3Auth(s3seckey, s3acckey, s3region, s3token);
509 davixParam->setMetalinkMode(Davix::MetalinkMode::Disable);
519 DavixError *davixErr = NULL;
523 Error(
"DavixStat",
"can not stat the file with davix: %s (%d)",
524 davixErr->getErrMsg().c_str(), davixErr->getStatus());
525 DavixError::clearError(&davixErr);
572 if(!replicas.empty()) {
573 std::stringstream ss;
574 for(
size_t i = 0; i < replicas.size(); i++) {
576 if(i != replicas.size()-1) ss <<
"|";
599 Error(
"Seek",
"seeking from end in archive is not (yet) supported");
605 Info(
"Seek",
" move cursor to %lld"
624 Info(
"ReadBuffer",
"%lld bytes of data read sequentially"
625 " (%d requested)", ret, len);
643 Info(
"ReadBuffer",
"%lld bytes of data read from offset"
644 " %lld (%d requested)", ret, pos, len);
656 d_ptr->
davixPosix->fadvise(fd,
static_cast<dav_off_t
>(offs),
static_cast<dav_size_t
>(len), Davix::AdviseRandom);
659 Info(
"ReadBufferAsync",
"%d bytes of data prefected from offset"
660 " %lld ", len, offs);
677 Info(
"ReadBuffers",
"%lld bytes of data read from a list of %d buffers",
696 Info(
"WriteBuffer",
"%lld bytes of data write"
697 " %d requested", ret, len);
720 std::vector<void *>::iterator
f = std::find(
dirdVec.begin(),
dirdVec.end(), fd);
737 std::vector<void *>::iterator
f = std::find(
dirdVec.begin(),
dirdVec.end(), fd);
750 Info(
"GetSize",
"file size requested: %lld", (
Long64_t)st.st_size);
789 DavixError *davixErr = NULL;
794 Error(
"DavixReadBuffer",
"can not read data with davix: %s (%d)",
795 davixErr->getErrMsg().c_str(), davixErr->getStatus());
796 DavixError::clearError(&davixErr);
809 DavixError *davixErr = NULL;
814 Error(
"DavixWriteBuffer",
"can not write data with davix: %s (%d)",
815 davixErr->getErrMsg().c_str(), davixErr->getStatus());
816 DavixError::clearError(&davixErr);
829 DavixError *davixErr = NULL;
834 Error(
"DavixPReadBuffer",
"can not read data with davix: %s (%d)",
835 davixErr->getErrMsg().c_str(), davixErr->getStatus());
836 DavixError::clearError(&davixErr);
849 DavixError *davixErr = NULL;
851 DavIOVecInput in[nbuf];
852 DavIOVecOuput out[nbuf];
855 for (
Int_t i = 0; i < nbuf; ++i) {
856 in[i].diov_buffer = &buf[lastPos];
857 in[i].diov_offset = pos[i];
858 in[i].diov_size = len[i];
864 Error(
"DavixReadBuffers",
"can not read data with davix: %s (%d)",
865 davixErr->getErrMsg().c_str(), davixErr->getStatus());
866 DavixError::clearError(&davixErr);
const char * s3_seckey_opt
static const std::string VERSION
static void ConfigureDavixLogLevel()
static auto awsRegion(TRequestParams *parameters, const char *region) -> decltype(parameters->setAwsRegion(region), void())
static auto awsAlternate(TRequestParams *parameters, bool option) -> decltype(parameters->setAwsAlternate(option), void())
static int TDavixFile_http_authn_cert_X509(void *userdata, const Davix::SessionInfo &info, Davix::X509Credential *cert, Davix::DavixError **err)
const char * s3_alternate_opt
static auto awsToken(TRequestParams *parameters, const char *token) -> decltype(parameters->setAwsToken(token), void())
const char * s3_token_opt
bool isno(const char *str)
const char * ca_check_opt
const char * open_mode_new
const char * open_mode_update
const char * open_mode_create
const char * s3_acckey_opt
static Context * davix_context_s
const char * grid_mode_opt
int configure_open_flag(const std::string &str, int old_flag)
static void TDavixFile_http_get_ucert(std::string &ucert, std::string &ukey)
static const std::string gUserAgent
bool strToBool(const char *str, bool defvalue)
const char * s3_region_opt
const char * open_mode_read
void Info(const char *location, const char *msgfmt,...)
void Error(const char *location, const char *msgfmt,...)
void Warning(const char *location, const char *msgfmt,...)
typedef void((*Func_t)())
Davix::RequestParams * davixParam
std::vector< void * > dirdVec
void setAwsToken(const std::string &token)
void setS3Auth(const std::string &secret, const std::string &access, const std::string ®ion, const std::string &token)
void setAwsAlternate(const bool &option)
static Davix::Context * getDavixInstance()
Davix::DavPosix * davixPosix
void parseParams(Option_t *option)
intput params
std::vector< std::string > getReplicas()
Int_t DavixStat(const char *url, struct stat *st)
Davix_fd * getDavixFileInstance()
Davix::Context * davixContext
void setAwsRegion(const std::string ®ion)
std::vector< std::string > replicas
void removeDird(void *fd)
virtual Long64_t GetSize() const
Returns the current file size.
void Init(Bool_t init)
Initialize a TFile object.
Long64_t DavixReadBuffers(Davix_fd *fd, char *buf, Long64_t *pos, Int_t *len, Int_t nbuf)
Long64_t DavixReadBuffer(Davix_fd *fd, char *buf, Int_t len)
Long64_t DavixPReadBuffer(Davix_fd *fd, char *buf, Long64_t pos, Int_t len)
virtual Bool_t WriteBuffer(const char *buffer, Int_t bufferLength)
Write a buffer to the file.
virtual TString GetNewUrl()
Long64_t DavixWriteBuffer(Davix_fd *fd, const char *buf, Int_t len)
virtual Bool_t ReadBufferAsync(Long64_t offs, Int_t len)
virtual Bool_t ReadBuffer(char *buf, Int_t len)
Read specified byte range from remote file via HTTP.
TDavixFile(const char *url, Option_t *option="", const char *ftitle="", Int_t compress=ROOT::RCompressionSetting::EDefaults::kUseCompiledDefault)
Open function for TDavixFile.
void enableGridMode()
Enable the grid mode The grid Mode configure automatically all grid-CA path, VOMS authentication and ...
virtual void Seek(Long64_t offset, ERelativeTo pos=kBeg)
Set position from where to start reading.
TDavixFileInternal * d_ptr
virtual Bool_t ReadBuffers(char *buf, Long64_t *pos, Int_t *len, Int_t nbuf)
Read the nbuf blocks described in arrays pos and len.
void eventStop(Double_t t, Long64_t len, bool read=true)
set TFile state info
void setCACheck(Bool_t check)
Enable or disable certificate authority check.
virtual Int_t GetValue(const char *name, Int_t dflt) const
Returns the integer value for a resource.
A ROOT file is a suite of consecutive data records (TKey instances) with a well defined format.
Int_t fReadCalls
Number of read calls ( not counting the cache calls )
static void SetFileBytesWritten(Long64_t bytes=0)
Long64_t fBytesRead
Number of bytes read from this file.
static Long64_t GetFileBytesWritten()
Static function returning the total number of bytes written to all files.
static void SetFileBytesRead(Long64_t bytes=0)
static void SetFileReadCalls(Int_t readcalls=0)
static Long64_t GetFileBytesRead()
Static function returning the total number of bytes read from all files.
Long64_t fArchiveOffset
!Offset at which file starts in archive
virtual void Init(Bool_t create)
Initialize a TFile object.
Long64_t fBytesWrite
Number of bytes written to this file.
Long64_t fOffset
!Seek offset cache
Long64_t fEND
Last used byte in file.
static Int_t GetFileReadCalls()
Static function returning the total number of read calls from all files.
virtual void Error(const char *method, const char *msgfmt,...) const
Issue error message.
virtual void Info(const char *method, const char *msgfmt,...) const
Issue info message.
The TTimeStamp encapsulates seconds and ns since EPOCH.
const char * GetUrl(Bool_t withDeflt=kFALSE) const
Return full URL.
EvaluateInfo init(std::vector< RooRealProxy > parameters, std::vector< ArrayWrapper * > wrappers, std::vector< double * > arrays, size_t begin, size_t batchSize)