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 <cstdlib>
29
30
31
32////////////////////////////////////////////////////////////////////////////////
33/// Specify the archive name and member name.
34///
35/// \param[in] archive Name of the archive file
36/// \param[in] member Name of the ROOT file or integer number
37/// \param[in] file Address of the TFile instance from where the call takes place
38///
39/// The member can be a decimal
40/// number which allows to access the n-th sub-file. This method is
41/// normally only called via TFile.
42
43TArchiveFile::TArchiveFile(const char *archive, const char *member, TFile *file)
44{
45 if (!file)
46 Error("TArchiveFile", "must specify a valid TFile");
47
48 fFile = file;
51 fMemberIndex = -1;
52 if (fMemberName.IsDigit())
54 fMembers = new TObjArray;
56 fCurMember = 0;
57}
58
59////////////////////////////////////////////////////////////////////////////////
60/// Dtor.
61
66
67////////////////////////////////////////////////////////////////////////////////
68/// Return position in archive of current member.
69
74
75////////////////////////////////////////////////////////////////////////////////
76/// Returns number of members in archive.
77
82
83////////////////////////////////////////////////////////////////////////////////
84/// Explicitely make the specified member the current member.
85/// Returns -1 in case of error, 0 otherwise.
86
88{
90 fMemberIndex = -1;
91
92 return SetCurrentMember();
93}
94
95////////////////////////////////////////////////////////////////////////////////
96/// Explicitely make the member with the specified index the current member.
97/// Returns -1 in case of error, 0 otherwise.
98
100{
101 fMemberName = "";
102 fMemberIndex = idx;
103
104 return SetCurrentMember();
105}
106
107////////////////////////////////////////////////////////////////////////////////
108/// Return proper archive file handler depending on passed url.
109///
110/// The handler is loaded via the plugin manager and is triggered by
111/// the extension of the archive file. In case no handler is found 0
112/// is returned. The file argument is used to access the archive.
113/// The archive should be specified as url with the member name as the
114/// anchor, e.g. "root://pcsalo.cern.ch/alice/event_1.zip#tpc.root",
115/// where tpc.root is the file in the archive to be opened.
116/// Alternatively the sub-file can be specified via its index number,
117/// e.g. "root://pcsalo.cern.ch/alice/event_1.zip#3".
118/// This function is normally only called via TFile::Open().
119
121{
122 if (!file) {
123 ::Error("TArchiveFile::Open", "must specify a valid TFile to access %s",
124 url);
125 return 0;
126 }
127
129
130 if (!ParseUrl(url, archive, member, type))
131 return 0;
132
133 TArchiveFile *f = 0;
135 if ((h = gROOT->GetPluginManager()->FindHandler("TArchiveFile", type))) {
136 if (h->LoadPlugin() == -1)
137 return 0;
138 f = (TArchiveFile*) h->ExecPlugin(3, archive.Data(), member.Data(), file);
139 }
140
141 return f;
142}
143
144////////////////////////////////////////////////////////////////////////////////
145/// Try to determine if url contains an anchor specifying an archive member.
146/// Returns kFALSE in case of an error.
147
149 TString &type)
150{
151 TUrl u(url, kTRUE);
152
153 archive = "";
154 member = "";
155 type = "";
156
157 // get the options and see, if the archive was specified by an option
158 // FIXME: hard coded for "zip" archive format
159 TString urloptions = u.GetOptions();
160 TObjArray *objOptions = urloptions.Tokenize("&");
161 for (Int_t n = 0; n < objOptions->GetEntriesFast(); n++) {
162
164 TObjArray *objTags = loption.Tokenize("=");
165 if (objTags->GetEntries() == 2) {
166
167 TString key = ((TObjString*)objTags->At(0))->GetName();
168 TString value = ((TObjString*)objTags->At(1))->GetName();
169
170 if (!key.CompareTo("zip", TString::kIgnoreCase)) {
171 archive = u.GetFile();
172 member = value;
173 type = "dummy.zip";
174 }
175 }
176 delete objTags;
177 }
178 delete objOptions;
179
180 if (member != "") {
181 // member set by an option
182 return kTRUE;
183 }
184
185 if (!strlen(u.GetAnchor())) {
186 archive = u.GetFile();
187 type = archive;
188 return kTRUE;
189 }
190
191 archive = u.GetFile();
192 member = u.GetAnchor();
193 type = archive;
194
195 if (archive == "" || member == "") {
196 archive = "";
197 member = "";
198 type = "";
199 return kFALSE;
200 }
201 return kTRUE;
202}
203
204
205
206////////////////////////////////////////////////////////////////////////////////
207/// Default ctor.
208
210{
211 fName = "";
212 fComment = "";
213 fPosition = 0;
214 fFilePosition = 0;
215 fCsize = 0;
216 fDsize = 0;
218}
219
220////////////////////////////////////////////////////////////////////////////////
221/// Create an archive member file.
222
224{
225 fName = name;
226 fComment = "";
227 fPosition = 0;
228 fFilePosition = 0;
229 fCsize = 0;
230 fDsize = 0;
232}
233
234////////////////////////////////////////////////////////////////////////////////
235/// Copy ctor.
236
238 : TObject(member)
239{
240 fName = member.fName;
241 fComment = member.fComment;
242 fModTime = member.fModTime;
243 fPosition = member.fPosition;
244 fFilePosition = member.fFilePosition;
245 fCsize = member.fCsize;
246 fDsize = member.fDsize;
247 fDirectory = member.fDirectory;
248}
249
250////////////////////////////////////////////////////////////////////////////////
251/// Assignment operator.
252
254{
255 if (this != &rhs) {
257 fName = rhs.fName;
258 fComment = rhs.fComment;
259 fModTime = rhs.fModTime;
260 fPosition = rhs.fPosition;
261 fFilePosition = rhs.fFilePosition;
262 fCsize = rhs.fCsize;
263 fDsize = rhs.fDsize;
264 fDirectory = rhs.fDirectory;
265 }
266 return *this;
267}
#define f(i)
Definition RSha256.hxx:104
#define h(i)
Definition RSha256.hxx:106
constexpr Bool_t kFALSE
Definition RtypesCore.h:108
constexpr Bool_t kTRUE
Definition RtypesCore.h:107
ROOT::Detail::TRangeCast< T, true > TRangeDynCast
TRangeDynCast is an adapter class that allows the typed iteration through a TCollection.
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:411
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:131
An array of TObjects.
Definition TObjArray.h:31
Int_t GetEntriesFast() const
Definition TObjArray.h:58
Collectable string class.
Definition TObjString.h:28
Mother of all ROOT objects.
Definition TObject.h:41
TObject & operator=(const TObject &rhs) noexcept
TObject assignment operator.
Definition TObject.h:299
virtual const char * GetName() const
Returns name of object.
Definition TObject.cxx:457
virtual void Error(const char *method, const char *msgfmt,...) const
Issue error message.
Definition TObject.cxx:1071
Longptr_t ExecPlugin(int nargs)
Basic string class.
Definition TString.h:138
int CompareTo(const char *cs, ECaseCompare cmp=kExact) const
Compare a string to char *cs2.
Definition TString.cxx:464
Bool_t IsDigit() const
Returns true if all characters in string are digits (0-9) or white spaces, i.e.
Definition TString.cxx:1836
@ kIgnoreCase
Definition TString.h:285
This class represents a WWW compatible URL.
Definition TUrl.h:33
const Int_t n
Definition legend1.C:16