28#include <XrdCl/XrdClURL.hh>
29#include <XrdCl/XrdClFile.hh>
30#include <XrdCl/XrdClXRootDResponses.hh>
31#include <XrdCl/XrdClDefaultEnv.hh>
32#include <XrdVersion.hh>
57 XrdCl::AnyObject *response)
99 XrdCl::AnyObject *response)
132 TNetXNGFile(url,0,mode,title,compress,netopt,parallelopen){}
136 :
TFile((lurl ? lurl : url),
137 strstr(mode,
"_WITHOUT_GLOBALREGISTRATION") != nullptr ?
"NET_WITHOUT_GLOBALREGISTRATION" :
"NET", title,
140 using namespace XrdCl;
145 if (!val.
IsNull()) XrdCl::DefaultEnv::SetLogLevel(val.
Data());
151 TUrl urlnoanchor(url);
153 fUrl =
new URL(std::string(urlnoanchor.
GetUrl()));
158 fUrl->SetProtocol(std::string(
"root"));
164 Error(
"Open",
"could not parse open mode %s", mode);
186 status =
fFile->Open(
fUrl->GetURL(),
fMode, Access::None, handler);
187 if (!status.IsOK()) {
188 Error(
"Open",
"%s", status.ToStr().c_str());
196 if (!status.IsOK()) {
197#if XrdVNUMBER >= 40000
198 if( status.code == errRedirect )
199 fNewUrl = status.GetErrorMessage().c_str();
201 Error(
"Open",
"%s", status.ToStr().c_str());
203 Error(
"Open",
"%s", status.ToStr().c_str());
209 if( (
fMode & OpenFlags::New) || (
fMode & OpenFlags::Delete) ||
210 (
fMode & OpenFlags::Update) )
215 if( (
fMode & OpenFlags::New) || (
fMode & OpenFlags::Delete) )
240 using namespace XrdCl;
243 if (
gDebug > 1)
Info(
"Init",
"TFile::Init already called once");
279 using namespace XrdCl;
285 bool forceStat =
true;
286 if(
fMode == XrdCl::OpenFlags::Read )
290 if( !
fFile->Stat( forceStat, info ).IsOK() )
325 XrdCl::XRootDStatus status =
fFile->Close();
326 if (!status.IsOK()) {
327 Error(
"Close",
"%s", status.ToStr().c_str());
345 using namespace XrdCl;
347 OpenFlags::Flags mode;
352 if (parseres<0 || (mode != OpenFlags::Read && mode != OpenFlags::Update)) {
353 Error(
"ReOpen",
"mode must be either READ or UPDATE, not %s", modestr);
358 if (mode ==
fMode || (mode == OpenFlags::Update
359 &&
fMode == OpenFlags::New)) {
363 XRootDStatus st =
fFile->Close();
365 Error(
"ReOpen",
"%s", st.ToStr().c_str());
373 Error(
"ReOpen",
"%s", st.ToStr().c_str());
402 using namespace XrdCl;
404 Info(
"ReadBuffer",
"offset: %lld length: %d", position, length);
423 uint32_t bytesRead = 0;
424 XRootDStatus st =
fFile->Read(
fOffset, length, buffer, bytesRead);
426 Info(
"ReadBuffer",
"%s bytes read: %u", st.ToStr().c_str(), bytesRead);
429 Error(
"ReadBuffer",
"%s", st.ToStr().c_str());
433 if ((
Int_t)bytesRead != length) {
434 Error(
"ReadBuffer",
"error reading all requested bytes, got %u of %d",
470 using namespace XrdCl;
476 std::vector<ChunkList> chunkLists;
478 std::vector<XRootDStatus*> *statuses;
480 Int_t totalBytes = 0;
482 char *cursor = buffer;
488 for (
Int_t i = 0; i < nbuffs; i++)
492 for (
Int_t i = 0; i < nbuffs; ++i) {
493 totalBytes += length[i];
502 for (j = 0; j < nsplit; ++j) {
504 chunks.push_back(ChunkInfo(offset,
fReadvIorMax, cursor));
510 chunks.push_back(ChunkInfo(offset, rem, cursor));
513 chunks.push_back(ChunkInfo(position[i], length[i], cursor));
519 chunkLists.push_back(chunks);
520 chunks = ChunkList();
522 chunkLists.push_back(ChunkList(chunks.begin(),
524 chunks = ChunkList(chunks.begin() +
fReadvIovMax, chunks.end());
529 if( !chunks.empty() )
530 chunkLists.push_back(chunks);
535 statuses =
new std::vector<XRootDStatus*>(chunkLists.size());
538 std::vector<ChunkList>::iterator it;
539 for (it = chunkLists.begin(); it != chunkLists.end(); ++it)
543 status =
fFile->VectorRead(*it, 0, handler);
545 if (!status.IsOK()) {
546 Error(
"ReadBuffers",
"%s", status.ToStr().c_str());
552 for (it = chunkLists.begin(); it != chunkLists.end(); ++it) {
557 for (it = chunkLists.begin(); it != chunkLists.end(); ++it) {
558 XRootDStatus *st = statuses->at(it - chunkLists.begin());
561 Error(
"ReadBuffers",
"%s", st->ToStr().c_str());
562 for( ; it != chunkLists.end(); ++it )
564 st = statuses->at( it - chunkLists.begin() );
583 gPerfStats->FileReadEvent(
this, totalBytes, start);
603 using namespace XrdCl;
611 Info(
"WriteBuffer",
"file not writable");
624 XRootDStatus st =
fFile->Write(
fOffset, length, buffer);
626 Error(
"WriteBuffer",
"%s", st.ToStr().c_str());
647 Info(
"Flush",
"file not writable - do nothing");
655 XrdCl::XRootDStatus status =
fFile->Sync();
657 Error(
"Flush",
"%s", status.ToStr().c_str());
660 Info(
"Flush",
"XrdClient::Sync succeeded.");
686 XrdCl::OpenFlags::Flags &mode,
689 using namespace XrdCl;
692 if (modestr ==
"NEW" || modestr ==
"CREATE") mode = OpenFlags::New;
693 else if (modestr ==
"RECREATE") mode = OpenFlags::Delete;
694 else if (modestr ==
"UPDATE") mode = OpenFlags::Update;
695 else if (modestr ==
"READ") mode = OpenFlags::Read;
701 mode = OpenFlags::Read;
713 Error(
"TNetXNGFile",
"Object is in 'zombie' state");
718 Error(
"TNetXNGFile",
"The remote file is not open");
731 using namespace XrdCl;
740#if XrdVNUMBER >= 40000
742 fFile->GetProperty(
"LastURL",lasturl);
746 if(lrl.GetProtocol().compare(
"file") == 0 &&
747 lrl.GetHostId().compare(
"localhost") == 0){
749 Info(
"GetVectorReadLimits",
"Local redirect, using default values");
753 std::string dataServerStr;
754 if( !
fFile->GetProperty(
"DataServer", dataServerStr ) )
756 URL dataServer(dataServerStr);
758 URL dataServer(
fFile->GetDataServer());
760 FileSystem fs(dataServer);
763 arg.FromString(std::string(
"readv_ior_max readv_iov_max"));
765 XRootDStatus status = fs.Query(QueryCode::Config, arg, response);
772 std::vector<TString> resps;
774 resps.push_back(token);
776 if (resps.size() != 2)
779 if (resps[0].IsDigit())
782 if (resps[1].IsDigit())
803 XrdCl::Env *env = XrdCl::DefaultEnv::GetEnv();
804 const char *cenv = 0;
809 || strlen(cenv) <= 0))
810 env->PutInt(
"ConnectionWindow", val.
Atoi());
814 || strlen(cenv) <= 0))
815 env->PutInt(
"RequestTimeout", val.
Atoi());
819 || strlen(cenv) <= 0))
820 env->PutInt(
"RequestTimeout", val.
Atoi());
822 val =
gEnv->
GetValue(
"NetXNG.SubStreamsPerChannel",
"");
824 || strlen(cenv) <= 0))
825 env->PutInt(
"SubStreamsPerChannel", val.
Atoi());
829 || strlen(cenv) <= 0))
830 env->PutInt(
"TimeoutResolution", val.
Atoi());
834 || strlen(cenv) <= 0))
835 env->PutInt(
"StreamErrorWindow", val.
Atoi());
839 || strlen(cenv) <= 0))
840 env->PutInt(
"RunForkHandler", val.
Atoi());
844 || strlen(cenv) <= 0))
845 env->PutInt(
"RedirectLimit", val.
Atoi());
849 || strlen(cenv) <= 0))
850 env->PutInt(
"WorkerThreads", val.
Atoi());
854 || strlen(cenv) <= 0))
855 env->PutInt(
"CPChunkSize", val.
Atoi());
859 || strlen(cenv) <= 0))
860 env->PutInt(
"CPParallelChunks", val.
Atoi());
864 || strlen(cenv) <= 0))
865 env->PutString(
"PollerPreference", val.
Data());
869 || strlen(cenv) <= 0))
870 env->PutString(
"ClientMonitor", val.
Data());
874 || strlen(cenv) <= 0))
875 env->PutString(
"ClientMonitorParam", val.
Data());
878 env->PutInt(
"MultiProtocol",
gEnv->
GetValue(
"TFile.CrossProtocolRedirects", 1));
928 || strlen(cenv) <= 0))
933 || strlen(cenv) <= 0))
938 || strlen(cenv) <= 0))
943 || strlen(cenv) <= 0))
948 || strlen(cenv) <= 0))
953 || strlen(cenv) <= 0))
size_t size(const MatrixT &matrix)
retrieve the size of a square matrix
void Info(const char *location, const char *msgfmt,...)
Use this function for informational messages.
void Error(const char *location, const char *msgfmt,...)
Use this function in case an error occurred.
TString ToUpper(const TString &s)
Return an upper-case version of str.
R__EXTERN TSystem * gSystem
R__EXTERN TVirtualMonitoringWriter * gMonitoringWriter
TArchiveMember * GetMember() const
Long64_t GetDecompressedSize() const
virtual void HandleResponse(XrdCl::XRootDStatus *status, XrdCl::AnyObject *response)
TAsyncOpenHandler(TNetXNGFile *file)
virtual void HandleResponse(XrdCl::XRootDStatus *status, XrdCl::AnyObject *response)
std::vector< XrdCl::XRootDStatus * > * fStatuses
TAsyncReadvHandler(std::vector< XrdCl::XRootDStatus * > *statuses, Int_t statusIndex, TSemaphore *semaphore)
virtual void SetOwner(Bool_t enable=kTRUE)
Set whether this collection is the owner (enable==true) of its content.
Bool_t fWritable
True if directory is writable.
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.
static std::atomic< Long64_t > fgBytesRead
Number of bytes read by all TFile objects.
Int_t fReadCalls
Number of read calls ( not counting the cache calls )
Long64_t fBytesRead
Number of bytes read from this file.
TArchiveFile * fArchive
!Archive file from which we read this file
TList * fOpenPhases
!Time info about open phases
Int_t WriteBufferViaCache(const char *buf, Int_t len)
Write buffer via cache.
Int_t ReadBufferViaCache(char *buf, Int_t len)
Read buffer via cache.
Long64_t fArchiveOffset
!Offset at which file starts in archive
virtual void Init(Bool_t create)
Initialize a TFile object.
Long64_t GetRelOffset() const
TString fOption
File options.
EAsyncOpenStatus
Asynchronous open request status.
Bool_t FlushWriteCache()
Flush the write cache if active.
Long64_t fBytesWrite
Number of bytes written to this file.
Bool_t fInitDone
!True if the file has been initialized
virtual void SetOffset(Long64_t offset, ERelativeTo pos=kBeg)
Set position from where to start reading.
Long64_t fOffset
!Seek offset cache
static std::atomic< Long64_t > fgBytesWrite
Number of bytes written by all TFile objects.
EAsyncOpenStatus fAsyncOpenStatus
!Status of an asynchronous open request
void Close(Option_t *option="") override
Close a file.
static std::atomic< Int_t > fgReadCalls
Number of bytes read from all TFile objects.
virtual void SetEnv()
Map ROOT and xrootd environment variables.
virtual Bool_t IsUseable() const
Check the file is open and isn't a zombie.
virtual void SetAsyncOpenStatus(EAsyncOpenStatus status)
Set the status of an asynchronous file open.
XrdCl::OpenFlags::Flags fMode
virtual void Close(const Option_t *option="")
Close the file.
Int_t ParseOpenMode(Option_t *in, TString &modestr, XrdCl::OpenFlags::Flags &mode, Bool_t assumeRead)
Parse a file open mode given as a string into a canonically formatted output mode string and an integ...
virtual Int_t ReOpen(Option_t *modestr)
Reopen the file with the new access mode.
virtual Bool_t WriteBuffer(const char *buffer, Int_t length)
Write a data chunk.
virtual Bool_t ReadBuffer(char *buffer, Int_t length)
Read a data chunk of the given size.
virtual Bool_t ReadBuffers(char *buffer, Long64_t *position, Int_t *length, Int_t nbuffs)
Read scattered data chunks in one operation.
virtual Long64_t GetSize() const
Get the file size.
XrdSysCondVar * fInitCondVar
virtual Bool_t IsOpen() const
Check if the file is open.
virtual void Init(Bool_t create)
Initialize the file.
virtual ~TNetXNGFile()
Destructor.
virtual void Flush()
Synchronize a file's in-memory and on-disk states.
virtual Bool_t GetVectorReadLimits()
Find the server-specific readv config params.
virtual void Seek(Long64_t offset, ERelativeTo position=kBeg)
Set the position within the file.
R__ALWAYS_INLINE Bool_t IsZombie() const
Int_t Post()
Increment the value of the semaphore.
Int_t Wait()
If the semaphore value is > 0 then decrement it and carry on, else block, waiting on the condition un...
Int_t Atoi() const
Return integer value of string.
const char * Data() const
TObjArray * Tokenize(const TString &delim) const
This function is used to isolate sequential tokens in a TString.
void Form(const char *fmt,...)
Formats a string using a printf style format descriptor.
virtual const char * Getenv(const char *env)
Get environment variable.
virtual void Setenv(const char *name, const char *value)
Set environment variable.
virtual const char * HomeDirectory(const char *userName=nullptr)
Return the user's home directory.
The TTimeStamp encapsulates seconds and ns since EPOCH.
This class represents a WWW compatible URL.
const char * GetUrl(Bool_t withDeflt=kFALSE) const
Return full URL.
void SetAnchor(const char *anchor)
virtual Bool_t SendFileOpenProgress(TFile *, TList *, const char *, Bool_t=kFALSE)
virtual Bool_t SendFileReadProgress(TFile *)