KaliVeda
Toolkit for HIC analysis
Loading...
Searching...
No Matches
KVDatedFileManager.cpp
1/*
2$Id: KVDatedFileManager.cpp,v 1.3 2007/06/14 10:39:55 franklan Exp $
3$Revision: 1.3 $
4$Date: 2007/06/14 10:39:55 $
5*/
6
7//Created by KVClassFactory on Wed May 2 14:50:40 2007
8//Author: franklan
9
10#include "KVDatedFileManager.h"
11#include "TSystemDirectory.h"
12#include "TSystem.h"
13#include "KVError.h"
14
16
17
18
19
24
25KVDatedFileManager::KVDatedFileManager(const Char_t* base, const Char_t* dir): fBaseName(base), fDirectory(dir)
26{
27 //Read all versions of file with basename 'base' in directory 'dir' and put them
28 //in a list sorted according to their timestamps
29 //Environment variables ($KVROOT) and other special symbols ('~') can be used
30 //in the directory name.
31 ReadFiles();
32}
33
34
35
36
40
42{
43 //Read all versions of file with given basename in directory and put them
44 //in a list sorted according to their timestamps
46 TSystemDirectory DIR("dir", fDirectory.Data());
47 TList* files = DIR.GetListOfFiles();
48 if (!files) {
49 Error(KV__ERROR(ReadFiles), "Cannot read directory %s", fDirectory.Data());
50 return;
51 }
52 TIter next(files);
54 while ((file = next())) {
55 KVString nom(file->GetName());
57 }
58 delete files;
60}
61
62
63
64
71
73{
74 //Returns name of file with timestamp immediately prior to the given name.
75 //Example:
76 // to know the name of the most recent backup version, give the base name of the file
77 //
78 //If no older version exists, returns empty string
79
81 if (!obj) {
82 Error(KV__ERROR(GetPreviousVersion), "File %s does not exist", name);
83 return "";
84 }
86 if (index == (fFileList.GetEntries() - 1)) {
87 //file is already oldest version
88 Warning(KV__ERROR(GetPreviousVersion), "File %s is oldest known version", name);
89 return "";
90 }
91 return fFileList.At(index + 1)->GetName();
92}
93
94
95
96
99
101{
102 //Returns name of file with earliest timestamp
103 return fFileList.Last()->GetName();
104}
105
106
107
108
111
113{
114 //Updates list of files
116 ReadFiles();
117}
118
119
120
122
123
124// BEGIN_HTML <!--
125/* -->
126<h2>KVSortableDatedFile</h2>
127<h4>A filename with an SQL-format date extension which can be used to sort a list according to date</h4>
128<!-- */
129// --> END_HTML
131
132
133
141
142KVSortableDatedFile::KVSortableDatedFile(const Char_t* filename, const Char_t* basename)
143 : TNamed(filename, basename)
144{
145 //filename = full name of file (including timestamp)
146 //basename = basename of file
147 //Example:
148 // KVSortableDatedFile("Runlist.csv.2007-05-02_14:15:58", "Runlist.csv")
149 //The timestamp extension is extracted from the filename.
150 //If the filename given is the same as the basename (i.e. no timestamp in name),
151 //the timestamps is set to the current date & time
152 KVString f(filename), b(basename);
153 if (f != b) {
154 f.Remove(0, b.Length() + 1);
155 f.ReplaceAll("_", " ");
156 fTimestamp.SetSQLDate(f.Data());
157 }
158}
159
160
161
162
166
168{
169 // Compare two files according to their timestamp.
170 // Used to sort lists, most recent files appear first
171
173 dynamic_cast < KVSortableDatedFile* >(const_cast < TObject* >(obj));
174 return (f->fTimestamp == fTimestamp ? 0 : (f->fTimestamp > fTimestamp ? 1 : -1));
175}
176
177
178
179
182
184{
185 //Two files are the same if they have the same basename and timestamp
186
188 dynamic_cast < KVSortableDatedFile* >(const_cast < TObject* >(obj));
189 return (f->fTimestamp == fTimestamp && !strcmp(GetName(), obj->GetName()));
190}
191
192
int Int_t
#define f(i)
bool Bool_t
char Char_t
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 filename
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 b
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t index
char name[80]
R__EXTERN TSystem * gSystem
Handles a set of different versions of files with the same base name and a timestamp.
KVString fDirectory
the directory containg the files
const Char_t * GetPreviousVersion(const Char_t *name)
void Update()
Updates list of files.
KVString fBaseName
the base name of the file
const Char_t * GetOldestVersion()
Returns name of file with earliest timestamp.
KVList fFileList
list of files sorted by timestamp
void Sort(Bool_t order=kSortAscending)
Definition KVList.h:35
virtual TObject * FindObject(const char *name) const
virtual void Clear(Option_t *option="")
virtual TObject * Last() const
virtual TObject * At(Int_t idx) const
virtual void Add(TObject *obj)
A filename with an SQL-format date extension which can be used to sort a list according to date.
virtual Bool_t IsEqual(const TObject *obj) const
Two files are the same if they have the same basename and timestamp.
KVDatime fTimestamp
timestamp extracted from filename
virtual Int_t Compare(const TObject *obj) const
Extension of ROOT TString class which allows backwards compatibility with ROOT v3....
Definition KVString.h:73
virtual Int_t GetEntries() const
const char * GetName() const override
virtual const char * GetName() const
virtual Int_t IndexOf(const TObject *obj) const
const char * Data() const
Bool_t BeginsWith(const char *s, ECaseCompare cmp=kExact) const
virtual TList * GetListOfFiles() const
virtual char * ExpandPathName(const char *path)
void Error(const char *location, const char *fmt,...)
void Warning(const char *location, const char *fmt,...)
ClassImp(TPyArg)