28#include <XrdCl/XrdClURL.hh>
29#include <XrdCl/XrdClFile.hh>
30#include <XrdCl/XrdClXRootDResponses.hh>
31#include <XrdCl/XrdClDefaultEnv.hh>
32#include <XrdCl/XrdClFileSystem.hh>
33#include <XrdVersion.hh>
66 XrdCl::AnyObject *response)
override
108 XrdCl::AnyObject *response)
override
128 fMode(
XrdCl::OpenFlags::None),
129 fInitCondVar(nullptr),
155 :
TFile((lurl ? lurl : url),
156 strstr(
mode,
"_WITHOUT_GLOBALREGISTRATION") != nullptr ?
"NET_WITHOUT_GLOBALREGISTRATION" :
"NET", title,
159 using namespace XrdCl;
164 if (!val.
IsNull()) XrdCl::DefaultEnv::SetLogLevel(val.
Data());
170 TUrl urlnoanchor(url);
172 fUrl =
new URL(std::string(urlnoanchor.
GetUrl()));
183 Error(
"Open",
"could not parse open mode %s",
mode);
205 status =
fFile->Open(
fUrl->GetURL(),
static_cast<XrdCl::OpenFlags::Flags
>(
fMode), Access::None, handler);
206 if (!status.IsOK()) {
207 Error(
"Open",
"%s", status.ToStr().c_str());
214 status =
fFile->Open(
fUrl->GetURL(),
static_cast<XrdCl::OpenFlags::Flags
>(
fMode));
215 if (!status.IsOK()) {
216#if XrdVNUMBER >= 40000
217 if( status.code == errRedirect )
218 fNewUrl = status.GetErrorMessage().c_str();
220 Error(
"Open",
"%s", status.ToStr().c_str());
222 Error(
"Open",
"%s", status.ToStr().c_str());
228 if( (
fMode & OpenFlags::New) || (
fMode & OpenFlags::Delete) ||
229 (
fMode & OpenFlags::Update) )
234 if( (
fMode & OpenFlags::New) || (
fMode & OpenFlags::Delete) )
259 using namespace XrdCl;
262 if (
gDebug > 1)
Info(
"Init",
"TFile::Init already called once");
298 using namespace XrdCl;
304 bool forceStat =
true;
305 if(
fMode == XrdCl::OpenFlags::Read )
309 if( !
fFile->Stat( forceStat, info ).IsOK() )
346 XrdCl::XRootDStatus status =
fFile->Close();
347 if (!status.IsOK()) {
348 Error(
"Close",
"%s", status.ToStr().c_str());
366 using namespace XrdCl;
373 if (parseres<0 || (
mode != OpenFlags::Read &&
mode != OpenFlags::Update)) {
374 Error(
"ReOpen",
"mode must be either READ or UPDATE, not %s", modestr);
380 &&
fMode == OpenFlags::New)) {
384 XRootDStatus st =
fFile->Close();
386 Error(
"ReOpen",
"%s", st.ToStr().c_str());
392 st =
fFile->Open(
fUrl->GetURL(),
static_cast<XrdCl::OpenFlags::Flags
>(
fMode));
394 Error(
"ReOpen",
"%s", st.ToStr().c_str());
423 using namespace XrdCl;
425 Info(
"ReadBuffer",
"offset: %lld length: %d", position,
length);
444 uint32_t bytesRead = 0;
447 Info(
"ReadBuffer",
"%s bytes read: %u", st.ToStr().c_str(), bytesRead);
450 Error(
"ReadBuffer",
"%s", st.ToStr().c_str());
455 Error(
"ReadBuffer",
"error reading all requested bytes, got %u of %d",
491 using namespace XrdCl;
497 std::vector<ChunkList> chunkLists;
499 std::vector<XRootDStatus*> *statuses;
501 Int_t totalBytes = 0;
509 for (
Int_t i = 0; i < nbuffs; i++)
513 for (
Int_t i = 0; i < nbuffs; ++i) {
523 for (j = 0; j < nsplit; ++j) {
534 chunks.push_back(ChunkInfo(position[i],
length[i],
cursor));
540 chunkLists.push_back(chunks);
541 chunks = ChunkList();
543 chunkLists.push_back(ChunkList(chunks.begin(),
545 chunks = ChunkList(chunks.begin() +
fReadvIovMax, chunks.end());
550 if( !chunks.empty() )
551 chunkLists.push_back(chunks);
556 statuses =
new std::vector<XRootDStatus*>(chunkLists.size());
559 std::vector<ChunkList>::iterator it;
560 for (it = chunkLists.begin(); it != chunkLists.end(); ++it)
564 status =
fFile->VectorRead(*it, 0, handler);
566 if (!status.IsOK()) {
567 Error(
"ReadBuffers",
"%s", status.ToStr().c_str());
573 for (it = chunkLists.begin(); it != chunkLists.end(); ++it) {
578 for (it = chunkLists.begin(); it != chunkLists.end(); ++it) {
579 XRootDStatus *st = statuses->at(it - chunkLists.begin());
582 Error(
"ReadBuffers",
"%s", st->ToStr().c_str());
583 for( ; it != chunkLists.end(); ++it )
585 st = statuses->at( it - chunkLists.begin() );
604 gPerfStats->FileReadEvent(
this, totalBytes, start);
624 using namespace XrdCl;
632 Info(
"WriteBuffer",
"file not writable");
647 Error(
"WriteBuffer",
"%s", st.ToStr().c_str());
668 Info(
"Flush",
"file not writable - do nothing");
676 XrdCl::XRootDStatus status =
fFile->Sync();
678 Error(
"Flush",
"%s", status.ToStr().c_str());
681 Info(
"Flush",
"XrdClient::Sync succeeded.");
710 using namespace XrdCl;
713 const static std::unordered_map<std::string, OpenFlags::Flags> strToFlagMap{{
"CREATE", OpenFlags::New},
714 {
"NEW", OpenFlags::New},
715 {
"READ", OpenFlags::Read},
716 {
"RECREATE", OpenFlags::Delete},
717 {
"UPDATE", OpenFlags::Update}};
719 const auto tokens =
ROOT::Split(modestr,
"_ ",
true);
720 for (
const auto &token : tokens) {
721 if (
auto it = strToFlagMap.find(token); it != strToFlagMap.end()) {
733 mode = OpenFlags::Read;
748 Error(
"TNetXNGFile",
"Object is in 'zombie' state");
753 Error(
"TNetXNGFile",
"The remote file is not open");
766 using namespace XrdCl;
775#if XrdVNUMBER >= 40000
777 fFile->GetProperty(
"LastURL",lasturl);
781 if(lrl.GetProtocol().compare(
"file") == 0 &&
782 lrl.GetHostId().compare(
"localhost") == 0){
784 Info(
"GetVectorReadLimits",
"Local redirect, using default values");
788 std::string dataServerStr;
789 if( !
fFile->GetProperty(
"DataServer", dataServerStr ) )
791 URL dataServer(dataServerStr);
793 URL dataServer(
fFile->GetDataServer());
795 FileSystem
fs(dataServer);
798 arg.FromString(std::string(
"readv_ior_max readv_iov_max"));
800 XRootDStatus status =
fs.Query(QueryCode::Config, arg, response);
807 std::vector<TString> resps;
809 resps.push_back(token);
811 if (resps.size() != 2)
814 if (resps[0].IsDigit())
817 if (resps[1].IsDigit())
838 XrdCl::Env *env = XrdCl::DefaultEnv::GetEnv();
839 const char *cenv = 0;
844 || strlen(cenv) <= 0))
845 env->PutInt(
"ConnectionWindow", val.
Atoi());
849 || strlen(cenv) <= 0))
850 env->PutInt(
"RequestTimeout", val.
Atoi());
854 || strlen(cenv) <= 0))
855 env->PutInt(
"RequestTimeout", val.
Atoi());
857 val =
gEnv->
GetValue(
"NetXNG.SubStreamsPerChannel",
"");
859 || strlen(cenv) <= 0))
860 env->PutInt(
"SubStreamsPerChannel", val.
Atoi());
864 || strlen(cenv) <= 0))
865 env->PutInt(
"TimeoutResolution", val.
Atoi());
869 || strlen(cenv) <= 0))
870 env->PutInt(
"StreamErrorWindow", val.
Atoi());
874 || strlen(cenv) <= 0))
875 env->PutInt(
"RunForkHandler", val.
Atoi());
879 || strlen(cenv) <= 0))
880 env->PutInt(
"RedirectLimit", val.
Atoi());
884 || strlen(cenv) <= 0))
885 env->PutInt(
"WorkerThreads", val.
Atoi());
889 || strlen(cenv) <= 0))
890 env->PutInt(
"CPChunkSize", val.
Atoi());
894 || strlen(cenv) <= 0))
895 env->PutInt(
"CPParallelChunks", val.
Atoi());
899 || strlen(cenv) <= 0))
900 env->PutString(
"PollerPreference", val.
Data());
904 || strlen(cenv) <= 0))
905 env->PutString(
"ClientMonitor", val.
Data());
909 || strlen(cenv) <= 0))
910 env->PutString(
"ClientMonitorParam", val.
Data());
913 env->PutInt(
"MultiProtocol",
gEnv->
GetValue(
"TFile.CrossProtocolRedirects", 1));
963 || strlen(cenv) <= 0))
968 || strlen(cenv) <= 0))
973 || strlen(cenv) <= 0))
978 || strlen(cenv) <= 0))
983 || strlen(cenv) <= 0))
988 || strlen(cenv) <= 0))
size_t size(const MatrixT &matrix)
retrieve the size of a square matrix
bool Bool_t
Boolean (0=false, 1=true) (bool)
int Int_t
Signed integer 4 bytes (int)
long long Long64_t
Portable signed long integer 8 bytes.
const char Option_t
Option string (const char)
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.
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t cursor
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t Int_t Int_t Window_t TString Int_t GCValues_t GetPrimarySelectionOwner GetDisplay GetScreen GetColormap GetNativeEvent const char const char dpyName wid window const char font_name cursor keysym reg const char only_if_exist regb h Point_t winding char text const char depth char const char Int_t count const char ColorStruct_t color const char Pixmap_t Pixmap_t PictureAttributes_t attr const char char ret_data h unsigned char height h offset
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t Int_t Int_t Window_t TString Int_t GCValues_t GetPrimarySelectionOwner GetDisplay GetScreen GetColormap GetNativeEvent const char const char dpyName wid window const char font_name cursor keysym reg const char only_if_exist regb h Point_t winding char text const char depth char const char Int_t count const char ColorStruct_t color const char Pixmap_t Pixmap_t PictureAttributes_t attr const char char ret_data h unsigned char height h length
Option_t Option_t TPoint TPoint const char mode
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize fs
Int_t gDebug
Global variable setting the debug level. Set to 0 to disable, increase it in steps of 1 to increase t...
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
void HandleResponse(XrdCl::XRootDStatus *status, XrdCl::AnyObject *response) override
TAsyncOpenHandler(TNetXNGFile *file)
std::vector< XrdCl::XRootDStatus * > * fStatuses
TAsyncReadvHandler(std::vector< XrdCl::XRootDStatus * > *statuses, Int_t statusIndex, TSemaphore *semaphore)
void HandleResponse(XrdCl::XRootDStatus *status, XrdCl::AnyObject *response) override
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 file, usually with extension .root, that stores data and code in the form of serialized objects in ...
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.
Enables access to XRootD files using the new client.
void Seek(Long64_t offset, ERelativeTo position=kBeg) override
Set the position within the file.
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.
Bool_t ReadBuffer(char *buffer, Int_t length) override
Read a data chunk of the given size.
void Close(const Option_t *option="") override
Close the file.
Bool_t ReadBuffers(char *buffer, Long64_t *position, Int_t *length, Int_t nbuffs) override
Read scattered data chunks in one operation.
void Flush() override
Synchronize a file's in-memory and on-disk states.
Bool_t WriteBuffer(const char *buffer, Int_t length) override
Write a data chunk.
Int_t ReOpen(Option_t *modestr) override
Reopen the file with the new access mode.
XrdSysCondVar * fInitCondVar
Long64_t GetSize() const override
Get the file size.
virtual ~TNetXNGFile()
Destructor.
void Init(Bool_t create) override
Initialize the file.
virtual Bool_t GetVectorReadLimits()
Find the server-specific readv config params.
Bool_t IsOpen() const override
Check if the file is open.
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 *)
std::vector< std::string > Split(std::string_view str, std::string_view delims, bool skipEmpty=false)
Splits a string at each character in delims.