Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
TArchiveFile.cxx
Go to the documentation of this file.
1// @(#)root/io:$Id$
2// Author: Fons Rademakers 30/6/04
3
4/*************************************************************************
5 * Copyright (C) 1995-2004, 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\file TArchiveFile.cxx
14\class TArchiveFile
15\ingroup IO
16
17Class describing an archive file containing multiple sub-files, like a ZIP
18or TAR archive.
19*/
20
21#include "TArchiveFile.h"
22#include "TPluginManager.h"
23#include "TROOT.h"
24#include "TObjArray.h"
25#include "TObjString.h"
26#include "TError.h"
27#include "TUrl.h"
28#include <stdlib.h>
29
30
32
33////////////////////////////////////////////////////////////////////////////////
34/// Specify the archive name and member name.
35///
36/// \param[in] archive Name of the archive file
37/// \param[in] member Name of the ROOT file or integer number
38/// \param[in] file Address of the TFile instance from where the call takes place
39///
40/// The member can be a decimal
41/// number which allows to access the n-th sub-file. This method is
42/// normally only called via TFile.
43
44TArchiveFile::TArchiveFile(const char *archive, const char *member, TFile *file)
45{
46 if (!file)
47 Error("TArchiveFile", "must specify a valid TFile");
48
49 fFile = file;
50 fArchiveName = archive;
51 fMemberName = member;
52 fMemberIndex = -1;
53 if (fMemberName.IsDigit())
55 fMembers = new TObjArray;
57 fCurMember = 0;
58}
59
60////////////////////////////////////////////////////////////////////////////////
61/// Dtor.
62
64{
65 delete fMembers;
66}
67
68////////////////////////////////////////////////////////////////////////////////
69/// Return position in archive of current member.
70
72{
74}
75
76////////////////////////////////////////////////////////////////////////////////
77/// Returns number of members in archive.
78
80{
81 return fMembers->GetEntriesFast();
82}
83
84////////////////////////////////////////////////////////////////////////////////
85/// Explicitely make the specified member the current member.
86/// Returns -1 in case of error, 0 otherwise.
87
88Int_t TArchiveFile::SetMember(const char *member)
89{
90 fMemberName = member;
91 fMemberIndex = -1;
92
93 return SetCurrentMember();
94}
95
96////////////////////////////////////////////////////////////////////////////////
97/// Explicitely make the member with the specified index the current member.
98/// Returns -1 in case of error, 0 otherwise.
99
101{
102 fMemberName = "";
103 fMemberIndex = idx;
104
105 return SetCurrentMember();
106}
107
108////////////////////////////////////////////////////////////////////////////////
109/// Return proper archive file handler depending on passed url.
110///
111/// The handler is loaded via the plugin manager and is triggered by
112/// the extension of the archive file. In case no handler is found 0
113/// is returned. The file argument is used to access the archive.
114/// The archive should be specified as url with the member name as the
115/// anchor, e.g. "root://pcsalo.cern.ch/alice/event_1.zip#tpc.root",
116/// where tpc.root is the file in the archive to be opened.
117/// Alternatively the sub-file can be specified via its index number,
118/// e.g. "root://pcsalo.cern.ch/alice/event_1.zip#3".
119/// This function is normally only called via TFile::Open().
120
121TArchiveFile *TArchiveFile::Open(const char *url, TFile *file)
122{
123 if (!file) {
124 ::Error("TArchiveFile::Open", "must specify a valid TFile to access %s",
125 url);
126 return 0;
127 }
128
129 TString archive, member, type;
130
131 if (!ParseUrl(url, archive, member, type))
132 return 0;
133
134 TArchiveFile *f = 0;
136 if ((h = gROOT->GetPluginManager()->FindHandler("TArchiveFile", type))) {
137 if (h->LoadPlugin() == -1)
138 return 0;
139 f = (TArchiveFile*) h->ExecPlugin(3, archive.Data(), member.Data(), file);
140 }
141
142 return f;
143}
144
145////////////////////////////////////////////////////////////////////////////////
146/// Try to determine if url contains an anchor specifying an archive member.
147/// Returns kFALSE in case of an error.
148
149Bool_t TArchiveFile::ParseUrl(const char *url, TString &archive, TString &member,
150 TString &type)
151{
152 TUrl u(url, kTRUE);
153
154 archive = "";
155 member = "";
156 type = "";
157
158 // get the options and see, if the archive was specified by an option
159 // FIXME: hard coded for "zip" archive format
160 TString urloptions = u.GetOptions();
161 TObjArray *objOptions = urloptions.Tokenize("&");
162 for (Int_t n = 0; n < objOptions->GetEntriesFast(); n++) {
163
164 TString loption = ((TObjString*)objOptions->At(n))->GetName();
165 TObjArray *objTags = loption.Tokenize("=");
166 if (objTags->GetEntries() == 2) {
167
168 TString key = ((TObjString*)objTags->At(0))->GetName();
169 TString value = ((TObjString*)objTags->At(1))->GetName();
170
171 if (!key.CompareTo("zip", TString::kIgnoreCase)) {
172 archive = u.GetFile();
173 member = value;
174 type = "dummy.zip";
175 }
176 }
177 delete objTags;
178 }
179 delete objOptions;
180
181 if (member != "") {
182 // member set by an option
183 return kTRUE;
184 }
185
186 if (!strlen(u.GetAnchor())) {
187 archive = u.GetFile();
188 type = archive;
189 return kTRUE;
190 }
191
192 archive = u.GetFile();
193 member = u.GetAnchor();
194 type = archive;
195
196 if (archive == "" || member == "") {
197 archive = "";
198 member = "";
199 type = "";
200 return kFALSE;
201 }
202 return kTRUE;
203}
204
205
207
208////////////////////////////////////////////////////////////////////////////////
209/// Default ctor.
210
212{
213 fName = "";
214 fComment = "";
215 fPosition = 0;
216 fFilePosition = 0;
217 fCsize = 0;
218 fDsize = 0;
220}
221
222////////////////////////////////////////////////////////////////////////////////
223/// Create an archive member file.
224
226{
227 fName = name;
228 fComment = "";
229 fPosition = 0;
230 fFilePosition = 0;
231 fCsize = 0;
232 fDsize = 0;
234}
235
236////////////////////////////////////////////////////////////////////////////////
237/// Copy ctor.
238
240 : TObject(member)
241{
242 fName = member.fName;
243 fComment = member.fComment;
244 fModTime = member.fModTime;
245 fPosition = member.fPosition;
247 fCsize = member.fCsize;
248 fDsize = member.fDsize;
249 fDirectory = member.fDirectory;
250}
251
252////////////////////////////////////////////////////////////////////////////////
253/// Assignment operator.
254
256{
257 if (this != &rhs) {
259 fName = rhs.fName;
260 fComment = rhs.fComment;
261 fModTime = rhs.fModTime;
262 fPosition = rhs.fPosition;
264 fCsize = rhs.fCsize;
265 fDsize = rhs.fDsize;
267 }
268 return *this;
269}
#define f(i)
Definition RSha256.hxx:104
#define h(i)
Definition RSha256.hxx:106
constexpr Bool_t kFALSE
Definition RtypesCore.h:94
long long Long64_t
Definition RtypesCore.h:69
constexpr Bool_t kTRUE
Definition RtypesCore.h:93
#define ClassImp(name)
Definition Rtypes.h:382
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void value
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 Atom_t Int_t ULong_t ULong_t unsigned char prop_list Atom_t Atom_t Atom_t Time_t type
char name[80]
Definition TGX11.cxx:110
#define gROOT
Definition TROOT.h:406
Class describing an archive file containing multiple sub-files, like a ZIP or TAR archive.
virtual Int_t SetCurrentMember()=0
~TArchiveFile() override
Dtor.
TArchiveMember * fCurMember
Current archive member.
TString fMemberName
Sub-file name.
static TArchiveFile * Open(const char *url, TFile *file)
Return proper archive file handler depending on passed url.
TString fArchiveName
Archive file name.
static Bool_t ParseUrl(const char *url, TString &archive, TString &member, TString &type)
Try to determine if url contains an anchor specifying an archive member.
Int_t fMemberIndex
Index of sub-file in archive.
Long64_t GetMemberFilePosition() const
Return position in archive of current member.
virtual Int_t SetMember(const char *member)
Explicitely make the specified member the current member.
Int_t GetNumberOfMembers() const
Returns number of members in archive.
TObjArray * fMembers
Members in this archive.
TFile * fFile
File stream used to access the archive.
TString fComment
Comment field.
TDatime fModTime
Modification time.
Long64_t fCsize
Compressed size.
Long64_t fPosition
Byte position in archive.
Long64_t fFilePosition
Byte position in archive where member data starts.
TArchiveMember & operator=(const TArchiveMember &rhs)
Assignment operator.
TString fName
Name of member.
TArchiveMember()
Default ctor.
Bool_t fDirectory
Flag indicating this is a directory.
Long64_t fDsize
Decompressed size.
Long64_t GetFilePosition() const
virtual void SetOwner(Bool_t enable=kTRUE)
Set whether this collection is the owner (enable==true) of its content.
A ROOT file is an on-disk file, usually with extension .root, that stores objects in a file-system-li...
Definition TFile.h:53
An array of TObjects.
Definition TObjArray.h:31
Int_t GetEntriesFast() const
Definition TObjArray.h:58
Int_t GetEntries() const override
Return the number of objects in array (i.e.
TObject * At(Int_t idx) const override
Definition TObjArray.h:164
Collectable string class.
Definition TObjString.h:28
Mother of all ROOT objects.
Definition TObject.h:41
virtual const char * GetName() const
Returns name of object.
Definition TObject.cxx:456
TObject & operator=(const TObject &rhs)
TObject assignment operator.
Definition TObject.h:296
virtual void Error(const char *method, const char *msgfmt,...) const
Issue error message.
Definition TObject.cxx:1005
Longptr_t ExecPlugin(int nargs)
Basic string class.
Definition TString.h:139
int CompareTo(const char *cs, ECaseCompare cmp=kExact) const
Compare a string to char *cs2.
Definition TString.cxx:457
const char * Data() const
Definition TString.h:376
Bool_t IsDigit() const
Returns true if all characters in string are digits (0-9) or white spaces, i.e.
Definition TString.cxx:1830
@ kIgnoreCase
Definition TString.h:277
TObjArray * Tokenize(const TString &delim) const
This function is used to isolate sequential tokens in a TString.
Definition TString.cxx:2264
This class represents a WWW compatible URL.
Definition TUrl.h:33
const char * GetAnchor() const
Definition TUrl.h:70
const char * GetFile() const
Definition TUrl.h:69
const char * GetOptions() const
Definition TUrl.h:71
const Int_t n
Definition legend1.C:16