Logo ROOT  
Reference Guide
TFileStager.cxx
Go to the documentation of this file.
1// @(#)root/net:$Id$
2// Author: A. Peters, G. Ganis 7/2/2007
3
4/*************************************************************************
5 * Copyright (C) 1995-2002, Rene Brun and Fons Rademakers. *
6 * All rights reserved. *
7 * *
8 * For the licensing terms see $ROOTSYS/LICENSE. *
9 * For the list of contributors see $ROOTSYS/README/CREDITS. *
10 *************************************************************************/
11
12//////////////////////////////////////////////////////////////////////////
13// //
14// TFileStager //
15// //
16// Abstract base class defining an interface to a stager. //
17// //
18// To open a connection to a stager use the static method //
19// Open("<stager>"), where <stager> contains a keyword allowing to load //
20// the relevant plug-in, e.g. //
21// TFileStager::Open("root://lxb6064.cern.ch") //
22// will load TXNetFileStager and initialize it for the redirector at //
23// lxb6046.cern.ch . //
24// //
25//////////////////////////////////////////////////////////////////////////
26
27#include "TError.h"
28#include "TFileInfo.h"
29#include "TFile.h"
30#include "TFileStager.h"
31#include "TObjString.h"
32#include "TPluginManager.h"
33#include "TROOT.h"
34#include "TSystem.h"
35#include "TUrl.h"
36#include "TCollection.h"
37#include "TFileCollection.h"
38#include "THashList.h"
39
40////////////////////////////////////////////////////////////////////////////////
41/// Retrieves the staging (online) status for a list of path names. Path names
42/// must be of type TUrl, TFileInfo or TObjString. The returned list is the list
43/// of staged files as TObjString (we use TObjString, because you can do a FindObject
44/// on that list using the file name, which is not possible with TUrl objects.
45
47{
48 if (!pathlist) {
49 Error("GetStaged", "list of pathnames was not specified!");
50 return 0;
51 }
52
53 TList* stagedlist = new TList();
54 TIter nxt(pathlist);
55 TObject* o = 0;
56 Bool_t local = (!strcmp(GetName(), "local")) ? kTRUE : kFALSE;
57 while ((o = nxt())) {
59 if (pn == "") {
60 Warning("GetStaged", "object is of unexpected type %s - ignoring", o->ClassName());
61 } else if (local || IsStaged(pn))
62 stagedlist->Add(new TObjString(pn));
63 }
64
65 // List of online files
66 stagedlist->SetOwner(kTRUE);
67 Info("GetStaged", "%d files staged", stagedlist->GetSize());
68 return stagedlist;
69}
70
71////////////////////////////////////////////////////////////////////////////////
72/// Issue a stage request for a list of files.
73/// Return the '&' of all single Prepare commands.
74
76{
77 TIter nxt(pathlist);
78 TObject *o = 0;
79 Bool_t success = kFALSE;
80
81 while ((o = nxt())) {
83 if (pn == "") {
84 Warning("Stage", "found object of unexpected type %s - ignoring",
85 o->ClassName());
86 continue;
87 }
88
89 // Issue to prepare
90 success &= Stage(pn, opt);
91 }
92
93 // return global flag
94 return success;
95}
96
97////////////////////////////////////////////////////////////////////////////////
98/// Open a stager, after having loaded the relevant plug-in.
99/// The format of 'stager' depends on the plug-in.
100
101TFileStager *TFileStager::Open(const char *stager)
102{
104 TFileStager *s = 0;
105
106 if (!stager) {
107 ::Error("TFileStager::Open", "stager name missing: do nothing");
108 return 0;
109 }
110
111 if (!gSystem->IsPathLocal(stager) &&
112 (h = gROOT->GetPluginManager()->FindHandler("TFileStager", stager))) {
113 if (h->LoadPlugin() == -1)
114 return 0;
115 s = (TFileStager *) h->ExecPlugin(1, stager);
116 } else
117 s = new TFileStager("local");
118
119 return s;
120}
121
122////////////////////////////////////////////////////////////////////////////////
123/// Just check if the file exists locally
124
126{
127 // The safest is to open in raw mode
128 TUrl u(f);
129 u.SetOptions("filetype=raw");
130 TFile *ff = TFile::Open(u.GetUrl());
131 Bool_t rc = kTRUE;
132 if (!ff || ff->IsZombie()) {
133 rc = kFALSE;
134 }
135 if (ff) {
136 ff->Close();
137 delete ff;
138 }
139 // Done
140 return rc;
141}
142
143////////////////////////////////////////////////////////////////////////////////
144/// Just check if the file exists locally
145
147{
148 if (!IsStaged(u))
149 return -1;
150 f = u;
151 return 0;
152}
153
154////////////////////////////////////////////////////////////////////////////////
155/// Massive location of files. Returns < 0 on error, or number of files
156/// processed. Results are returned on the TFileCollection itself
157
159{
160 TFileInfo *fi;
161 TString endp;
162 TIter it(fc->GetList());
163 Int_t count = 0;
164
165 while ((fi = dynamic_cast<TFileInfo *>(it.Next()))) {
166 const char *ourl = fi->GetCurrentUrl()->GetUrl();
167 if (!ourl) continue;
168
169 if (Locate(ourl, endp) == 0) {
170 fi->AddUrl(endp.Data(), kTRUE);
172 fi->ResetUrl();
173 }
174 else {
176 }
177
178 count++;
179 }
180
181 return count;
182}
183
184////////////////////////////////////////////////////////////////////////////////
185/// Return the path name contained in object 'o' allowing for
186/// TUrl, TObjString or TFileInfo
187
189{
190 TString pathname;
191 TString cn(o->ClassName());
192 if (cn == "TUrl") {
193 pathname = ((TUrl*)o)->GetUrl();
194 } else if (cn == "TObjString") {
195 pathname = ((TObjString*)o)->GetName();
196 } else if (cn == "TFileInfo") {
197 TFileInfo *fi = (TFileInfo *)o;
198 pathname = (fi->GetCurrentUrl()) ? fi->GetCurrentUrl()->GetUrl() : "";
199 if (fi->GetCurrentUrl()) {
200 if (strlen(fi->GetCurrentUrl()->GetAnchor()) > 0) {
201 TUrl url(*(fi->GetCurrentUrl()));
202 url.SetAnchor("");
203 pathname = url.GetUrl();
204 }
205 } else {
206 pathname = fi->GetCurrentUrl()->GetUrl();
207 }
208 }
209
210 // Done
211 return pathname;
212}
#define f(i)
Definition: RSha256.hxx:104
#define h(i)
Definition: RSha256.hxx:106
int Int_t
Definition: RtypesCore.h:43
const Bool_t kFALSE
Definition: RtypesCore.h:90
bool Bool_t
Definition: RtypesCore.h:61
const Bool_t kTRUE
Definition: RtypesCore.h:89
const char Option_t
Definition: RtypesCore.h:64
#define gROOT
Definition: TROOT.h:406
R__EXTERN TSystem * gSystem
Definition: TSystem.h:556
static struct mg_connection * fc(struct mg_context *ctx)
Definition: civetweb.c:3728
Collection abstract base class.
Definition: TCollection.h:63
virtual void SetOwner(Bool_t enable=kTRUE)
Set whether this collection is the owner (enable==true) of its content.
virtual Int_t GetSize() const
Return the capacity of the collection, i.e.
Definition: TCollection.h:182
Class that contains a list of TFileInfo's and accumulated meta data information about its entries.
Class describing a generic file including meta information.
Definition: TFileInfo.h:36
Bool_t AddUrl(const char *url, Bool_t infront=kFALSE)
Add a new URL.
Definition: TFileInfo.cxx:295
void ResetUrl()
Definition: TFileInfo.h:66
TUrl * GetCurrentUrl() const
Return the current url.
Definition: TFileInfo.cxx:248
TFileStager(const char *stager)
Definition: TFileStager.h:39
virtual Int_t LocateCollection(TFileCollection *fc, Bool_t addDummyUrl=kFALSE)
Massive location of files.
virtual Bool_t IsStaged(const char *)
Just check if the file exists locally.
virtual Bool_t Stage(const char *, Option_t *=0)
Definition: TFileStager.h:47
static TString GetPathName(TObject *o)
Return the path name contained in object 'o' allowing for TUrl, TObjString or TFileInfo.
static TFileStager * Open(const char *stager)
Open a stager, after having loaded the relevant plug-in.
virtual TList * GetStaged(TCollection *pathlist)
Retrieves the staging (online) status for a list of path names.
Definition: TFileStager.cxx:46
virtual Int_t Locate(const char *u, TString &f)
Just check if the file exists locally.
A ROOT file is a suite of consecutive data records (TKey instances) with a well defined format.
Definition: TFile.h:53
static TFile * Open(const char *name, Option_t *option="", const char *ftitle="", Int_t compress=ROOT::RCompressionSetting::EDefaults::kUseCompiledDefault, Int_t netopt=0)
Create / open a file.
Definition: TFile.cxx:3942
void Close(Option_t *option="") override
Close a file.
Definition: TFile.cxx:873
TObject * Next()
Definition: TCollection.h:249
A doubly linked list.
Definition: TList.h:44
virtual void Add(TObject *obj)
Definition: TList.h:87
virtual const char * GetName() const
Returns name of object.
Definition: TNamed.h:47
Collectable string class.
Definition: TObjString.h:28
Mother of all ROOT objects.
Definition: TObject.h:37
virtual const char * ClassName() const
Returns name of class to which the object belongs.
Definition: TObject.cxx:128
virtual void Warning(const char *method, const char *msgfmt,...) const
Issue warning message.
Definition: TObject.cxx:877
R__ALWAYS_INLINE Bool_t IsZombie() const
Definition: TObject.h:149
void SetBit(UInt_t f, Bool_t set)
Set or unset the user status bits as specified in f.
Definition: TObject.cxx:694
virtual void Error(const char *method, const char *msgfmt,...) const
Issue error message.
Definition: TObject.cxx:891
void ResetBit(UInt_t f)
Definition: TObject.h:186
virtual void Info(const char *method, const char *msgfmt,...) const
Issue info message.
Definition: TObject.cxx:865
Basic string class.
Definition: TString.h:131
const char * Data() const
Definition: TString.h:364
virtual Bool_t IsPathLocal(const char *path)
Returns TRUE if the url in 'path' points to the local file system.
Definition: TSystem.cxx:1300
This class represents a WWW compatible URL.
Definition: TUrl.h:35
const char * GetAnchor() const
Definition: TUrl.h:72
const char * GetUrl(Bool_t withDeflt=kFALSE) const
Return full URL.
Definition: TUrl.cxx:387
void SetAnchor(const char *anchor)
Definition: TUrl.h:88
void SetOptions(const char *opt)
Definition: TUrl.h:89
static constexpr double s