43 static const char *
glabMet[] = {
"#files",
"size" };
47 const char *excsrvs = 0,
int met = 0,
const char *fnout = 0,
48 TList *distinfo = 0,
const char *outfile = 0,
const char *infile = 0);
53 #define SDELTWO(x,y) { SafeDelete(x); SafeDelete(y); } 54 #define SDELTRE(x,y,z) { SafeDelete(x); SafeDelete(y); SafeDelete(z); } 55 #define SDELETE(x,y,z,w,t) { SafeDelete(x); SafeDelete(y); SafeDelete(z); SafeDelete(w); SafeDelete(t); } 71 void do_ls(
const char *ds,
const char *opt)
84 const char *action = (server && strlen(server) > 0) ?
"pq2-ls-files-server" :
"pq2-ls-files";
89 if (server && strlen(server) > 0) {
98 Printf(
"%s: ERROR: problems retrieving info about dataset '%s'", action, ds);
103 if (server && strlen(server) > 0) {
104 Printf(
"%s: dataset '%s' has %d files on server: %s",
114 TString met(
"#Objs Obj|Type|Entries, ...");
119 const char *unit[4] = {
"kB",
"MB",
"GB",
"TB"};
129 uu = fi->GetCurrentUrl()->GetUrl();
130 if (uu.Length() < 80) uu.
Resize(80);
135 while (xsz > 1024 && k < 3) {
138 xsz = (
Long64_t) (fi->GetSize() / refsz);
142 if (fi->GetMetaDataList()) {
143 meta.
Form(
" %d ", fi->GetMetaDataList()->GetSize());
145 TIter nxm(fi->GetMetaDataList());
148 if (!firstObj) meta +=
",";
149 name = fim->GetObject();
150 if (strcmp(fim->GetDirectory(),
"/")) name = fim->GetName();
151 meta +=
Form(
"%s|%s|%lld", name.
Data(), fim->GetClass(), fim->GetEntries());
157 Printf(
"%s: %5d %s %8lld %s %s", action, nf, uu.Data(), xsz, unit[k], meta.
Data());
159 Printf(
"%s: %5d %s N/A N/A", action, nf, uu.Data());
193 Printf(
"+++ %5d. %s", ++nf, fi->GetCurrentUrl()->GetUrl());
195 Printf(
"+++ %5d. %s", ++nf, fi->GetCurrentUrl()->GetFile());
206 const char *action =
"pq2-info-server";
216 Printf(
"%s: ERROR: problems retrieving info about datasets for server '%s'", action, server);
251 if ((itb = o.Index(
"tree:")) !=
kNPOS) {
252 deftree = o(itb + 5, o.Length());
258 if (o.Contains(
"staged|")) {
260 o.ReplaceAll(
"staged|",
"");
278 void do_put(
const char *files,
const char *opt)
280 const char *action =
"pq2-put";
283 if (!files || strlen(files) <= 0) {
286 Printf(
"%s: ERROR: path files not defined!", action);
314 Int_t ndp = 0, nd = 0;
326 Printf(
"%s: WARNING: dataset '%s' already exists - ignoring request", action, dsname.
Data());
327 Printf(
"%s: (use '-o O' to overwrite, '-o U' to update)", action);
329 Printf(
"%s: ERROR: problems registering '%s' from '%s'", action, dsname.
Data(), files);
340 Printf(
"%s: ERROR: could not open directory '%s'", action, dir.
Data());
350 if (!strcmp(ent,
".") || !strcmp(ent,
".."))
continue;
356 file.
Form(
"%s/%s", dir.
Data(), ent);
363 Printf(
"%s: ERROR: problems registering '%s' from '%s'", action, ent, file.
Data());
365 Printf(
"%s: WARNING: dataset '%s' already exists - ignoring request", action, ent);
366 Printf(
"%s: (use '-o O' to overwrite, '-o U' to update)", action);
376 Printf(
"%s: WARNING: problems with %d dataset(s)", action, ndp);
379 Printf(
"%s: %d dataset(s) registered", action, nd);
390 const char *action =
"pq2-ds";
402 Printf(
"%s: ERROR: problems removing dataset '%s'", action, dsname);
415 Printf(
"%s: ERROR: problems retrieving info about datasets", action);
423 while ((os = dynamic_cast<TObjString*>(nxd()))) {
432 Printf(
"%s: ERROR: problems removing dataset '%s'", action, ds.
Data());
442 Printf(
"%s: WARNING: no matching dataset found!", action);
444 Printf(
"%s: %d dataset(s) removed", action, nd);
456 int do_verify(
const char *dsname,
const char *opt,
const char *redir)
458 const char *action =
"pq2-verify";
460 Int_t nd = 0, rc = -1;
468 Printf(
"%s: ERROR: problems verifing dataset '%s'", action, dsname);
472 Printf(
"%s: WARNING: %s: some files not yet online (staged)", action, dsname);
480 Printf(
"%s: ERROR: problems retrieving info about datasets", action);
488 while ((os = dynamic_cast<TObjString*>(nxd()))) {
491 Printf(
"%s: start verification of dataset '%s' ...", action, os->
GetName());
495 Printf(
"%s: ERROR: problems verifying dataset '%s'", action, os->
GetName());
497 }
else if (xrc > 0) {
501 Printf(
"%s: WARNING: %s: some files not yet online (staged)", action, os->
GetName());
511 Printf(
"%s: WARNING: no matching dataset found!", action);
513 Printf(
"%s: %d dataset(s) verified", action, nd);
527 void do_anadist(
const char *ds,
const char *servers,
const char *ignsrvs,
528 const char *excsrvs,
const char *
metrics,
const char *fnout,
529 const char *plot,
const char *outfile,
const char *infile)
531 const char *action =
"pq2-ana-dist";
544 while (dss.Tokenize(d, from,
",")) {
551 while ((k = nxds())) {
562 if (!fcmap || fcmap->
GetSize() <= 0) {
566 Printf(
"%s: ERROR: problems retrieving info about dataset '%s' (or empty dataset)", action, ds);
574 if (metrics && !strcmp(metrics,
"S")) optMet = 1;
581 if (
do_anadist_ds(0, 0, 0, 0, optMet, 0, &distinfo, 0, infile) != 0) {
582 Printf(
"%s: problems getting dist info from '%s'", action, infile);
608 optMet, fnout, &distinfo, outfile, infile) != 0) {
609 Printf(
"%s: problems analysing dataset '%s'", action, fc ? fc->
GetName() :
"<undef>");
618 if (!(fileplot.IsNull())) {
619 if (fileplot.Contains(
".")) {
620 gext = fileplot(fileplot.Last(
'.') + 1, fileplot.Length());
624 const char *fmts[9] = {
"png",
"eps",
"ps",
"pdf",
"svg",
"gif",
"xpm",
"jpg",
"tiff" };
626 while (iplot < 9 && gext != fmts[iplot]) { iplot++; }
628 Printf(
"%s: graphics format '%s' not supported: switching to 'png'", action, gext.
Data());
631 if (!(fileplot.EndsWith(gext))) {
632 if (!(fileplot.EndsWith(
"."))) fileplot +=
".";
639 TIter nxs(&distinfo);
646 nnn.ReplaceAll(
".",
"");
653 Printf(
"%s: plot requested but no server found (info list is empty)!", action);
666 FILE *ftmp = fopen(filetmp.
Data(),
"w");
668 fprintf(ftmp,
"%s %s %s", filehist.
Data(), fileplot.Data(),
glabMet[optMet]);
671 Printf(
"%s: problems opening temp file '%s' (errno: %d)", action, filetmp.
Data(), errno);
672 Printf(
"%s: relevant info: %s %s %s (input to pq2PlotDist.C)",
673 action, filehist.
Data(), fileplot.Data(),
glabMet[optMet]);
676 Printf(
"%s: problems opening file '%s'", action, filehist.
Data());
679 Printf(
"%s: histogram requested but not found", action);
691 const char *excsrvs,
int met,
const char *fnout,
692 TList *distinfo,
const char *outfile,
const char *infile)
694 const char *action =
"pq2-ana-dist-ds";
697 Bool_t distonly_m = (!fc && distinfo && infile && strlen(infile) > 0) ?
kTRUE :
kFALSE;
698 const char *dsname = 0;
701 Printf(
"%s: dataset undefined!", action);
706 Printf(
"%s: dataset '%s' is empty", action, dsname);
713 THashList *ignore = 0, *targets = 0, *exclude = 0;
719 if (ignsrvs && strlen(ignsrvs)) {
731 if (excsrvs && strlen(excsrvs)) {
745 if (servers && strlen(servers)) {
764 Int_t targets_size = -1;
765 if (infile && strlen(infile)) {
768 Printf(
"%s: reading info from file '%s' ", action, infile);
769 if (!(fcsls = (
THashList *) flist->
Get(
"FileDistList"))) {
770 Printf(
"%s: could not find starting file distribution 'FileDistList' in input file '%s' ",
774 SDELTRE(ignore, targets, exclude);
778 fcsls_title = (
TNamed *) flist->
Get(
"FileDistList_Title");
781 if (psz) targets_size = psz->
GetVal();
786 if (distinfo && fcsls_title && strlen(fcsls_title->
GetTitle()) > 0) {
788 if (strcmp(distinfo->
GetName(),
"TList")) {
789 if (!(runt.IsNull())) runt +=
",";
796 Printf(
"%s: problems opening input file '%s' ", action, infile);
797 SDELTRE(ignore, targets, exclude);
803 fcsls->
SetName(
"FileDistList");
804 fcsls_title =
new TNamed(
"FileDistList_Title", distinfo ? distinfo->
GetName() :
"");
826 if (ignore && ignore->
FindObject(key))
continue;
830 Printf(
"%s:%s: found server '%s' ... ", action, dsname, key.
Data());
841 Printf(
"%s:%s: add new target server '%s' ...", action, dsname, key.
Data());
846 if (fcs) fcs->
Add(fi);
854 if (targets->GetSize() <= 0) {
855 Printf(
"%s:%s: target servers list is empty!", action, dsname);
856 SDELETE(ignore, targets, exclude, fcsls, fcsls_title);
859 Printf(
"%s:%s: %d target servers found", action, dsname, targets->GetSize());
868 targets_size = (targets) ? targets->
GetSize() : targets_size;
870 if (targets_size > 0) {
871 avgfiles = (
Double_t)totfiles / targets_size;
872 avgsize = (
Double_t)totsz / targets_size / 1024. / 1024. / 1024.;
873 Printf(
"%s:%s: %d servers found, %lld files; in average: %.3f files / %.3f GBs per server",
874 action, dsname, fcsls->
GetSize(), totfiles, avgfiles, avgsize);
877 Printf(
"%s:%s: target size is null or negative", action, dsname);
878 SDELETE(ignore, targets, exclude, fcsls, fcsls_title);
882 if (
gverbose > 0)
Printf(
"\n%s:%s: Before redistribution:", action, dsname);
900 }
else if (met == 1) {
905 Printf(
"%s:%s: server %s: %lld files (diff: %lld, %.3f) - %.3f GBs (diff: %.3f, %.3f)",
906 action, dsname, fcs->
GetName(), fcs->
GetNFiles(), nfexcess, xdf, fcsz, szexcess, xdsz);
910 if (targets && targets->FindObject(fcs->
GetName())) {
912 if (nfexcess > 0.) isExcess =
kTRUE;
913 }
else if (met == 1) {
914 if (szexcess > 0.) isExcess =
kTRUE;
927 if (outfile && strlen(outfile)) {
931 Printf(
"%s: saving info to file '%s' ", action, outfile);
941 Printf(
"%s: problems opening output file '%s' ", action, outfile);
951 SDELETE(targets, fcsls, fcsls_title, excls, defls);
957 Printf(
"%s:%s: %d servers found in excess", action, dsname, excls->
GetSize());
959 Printf(
"%s:%s: %d servers found in defect", action, dsname, defls->
GetSize());
962 Printf(
"%s:%s: %d servers found in excess, %d in defect", action, dsname, excls->
GetSize(), defls->
GetSize());
967 if (fnout && strlen(fnout) > 0) {
968 if (!(fout = fopen(fnout,
"a"))) {
969 Printf(
"%s: problems opening output file '%s' (errno: %d)", action, fnout, errno);
970 SDELETE(targets, fcsls, fcsls_title, excls, defls);
989 Printf(
"%s:%s: WARNING: processing list in excess '%s': no more lists in deficit!",
990 action, dsname, fcs->
GetName());
995 fcsz += (fi->
GetSize() / 1024. / 1024. / 1024.) ;
997 (((met == 0) && (fcfiles > avgfiles)) || ((met == 1) && (fcsz > avgsize)))) {
1003 php.
Remove(php.Index(u.GetFile()));
1005 if (php.EndsWith(
"/") && ((ilst = php.Last(
'/')) !=
kNPOS)) php.Remove(ilst);
1007 fprintf(fout,
"%s %s %s\n", u.GetFile(), php.Data(), fcd->
GetName());
1009 if (printheader)
Printf(
" File Source_Server Destination_Server");
1010 Printf(
"%s %s %s", u.GetFile(), php.Data(), fcd->
GetName());
1029 if ((xfcsz / 1024. / 1024. / 1024.) > avgsize) getnext =
kTRUE;
1039 if ((fclose(fout)) != 0)
1040 Printf(
"%s: problems closing output file '%s' (errno: %d)", action, fnout, errno);
1042 Printf(
"%s:%s: %d files should be moved to make the distribution even (metrics: %s)",
1043 action, dsname, mvfiles,
glabMet[met]);
1047 Printf(
"\n%s:%s: After redistribution:", action, dsname);
1052 Double_t xdf = nfexcess / avgfiles;
1054 Double_t szexcess = fcsz - avgsize;
1055 Double_t xdsz = szexcess / avgsize;
1056 Printf(
"%s:%s: Server %s: %lld files (diff: %lld, %.3f) - %.3f GBs (diff: %.3f, %.3f)",
1057 action, dsname, fcs->
GetName(), fcs->
GetNFiles(), nfexcess, xdf, fcsz, szexcess, xdsz);
1063 Double_t xdf = nfexcess / avgfiles;
1065 Double_t szexcess = fcsz - avgsize;
1066 Double_t xdsz = szexcess / avgsize;
1067 Printf(
"%s:%s: server %s: %lld files (diff: %lld, %.3f) - %.3f GBs (diff: %.3f, %.3f)",
1068 action, dsname, fcs->
GetName(), fcs->
GetNFiles(), nfexcess, xdf, fcsz, szexcess, xdsz);
1072 SDELETE(targets, fcsls, fcsls_title, excls, defls);
1103 gProtoPortMap.
Add(php);
1120 Printf(
"do_anadist_plot: will be doing a plot here ... ");
1123 Printf(
"do_anadist_plot: we save the histo for now (to testhist.root)");
virtual Bool_t cd(const char *path=0)
Change current directory to "this" directory.
virtual const char * BaseName(const char *pathname)
Base name of a file name. Base name of /user/root is root.
virtual const char * GetName() const
Returns name of object.
virtual Int_t Write(const char *name=0, Int_t option=0, Int_t bufsize=0)
Write this object to the current directory.
virtual Int_t FindBin(Double_t x, Double_t y=0, Double_t z=0)
Return Global bin number corresponding to x,y,z.
virtual Int_t Fill(Double_t x)
Increment bin with abscissa X by 1.
Int_t RemoveDataSet(const char *dsname)
RemoveDataSet wrapper.
void do_anadist(const char *ds, const char *servers, const char *ignsrvs, const char *excsrvs, const char *metrics, const char *fnout, const char *plot, const char *outfile, const char *infile)
Execute 'analyze-distribution' for the dataset(s) described by 'ds'.
void SetProtocol(const char *proto, Bool_t setDefaultPort=kFALSE)
Set protocol and, optionally, change the port accordingly.
Collectable string class.
static const char * glabMet[]
Long64_t GetTotalSize() const
This class represents a WWW compatible URL.
TString & ReplaceAll(const TString &s1, const TString &s2)
int GetPathInfo(const char *path, Long_t *id, Long_t *size, Long_t *flags, Long_t *modtime)
Get info about a file: id, size, flags, modification time.
TUrl * GetCurrentUrl() const
Return the current url.
const char * GetProtocol() const
TFileCollection * GetDataSet(const char *ds, const char *server)
GetDataSet wrapper.
virtual void SetOwner(Bool_t enable=kTRUE)
Set whether this collection is the owner (enable==true) of its content.
A ROOT file is a suite of consecutive data records (TKey instances) with a well defined format...
void ToUpper()
Change string to upper case.
Regular expression class.
const char * GetName() const
Returns name of object.
virtual TObject * Get(const char *namecycle)
Return pointer to object identified by namecycle.
overwrite existing object with same name
void Add(TObject *obj)
This function may not be used (but we need to provide it since it is a pure virtual in TCollection)...
Ssiz_t Index(const char *pat, Ssiz_t i=0, ECaseCompare cmp=kExact) const
void SetVal(const AParamType &val)
void do_rm(const char *dsname)
Execute 'rm'.
virtual const char * DirName(const char *pathname)
Return the directory name in pathname.
TObject * FindObject(const char *name) const
Find object using its name.
Int_t RegisterDataSet(const char *dsname, TFileCollection *fc, const char *opt)
RegisterDataSet wrapper.
TString & Insert(Ssiz_t pos, const char *s)
const char * GetUrl(Bool_t withDeflt=kFALSE) const
Return full URL.
virtual TObject * FindObject(const char *name) const
Delete a TObjLink object.
int do_anadist_ds(TFileCollection *fc, const char *newsrvs=0, const char *ignsrvs=0, const char *excsrvs=0, int met=0, const char *fnout=0, TList *distinfo=0, const char *outfile=0, const char *infile=0)
Do analysis of dataset 'fc'.
static TFile * Open(const char *name, Option_t *option="", const char *ftitle="", Int_t compress=1, Int_t netopt=0)
Create / open a file.
virtual int Rename(const char *from, const char *to)
Rename a file.
static struct mg_connection * fc(struct mg_context *ctx)
const char * GetHost() const
Int_t Update(Long64_t avgsize=-1)
Update accumulated information about the elements of the collection (e.g.
virtual const char * GetDirEntry(void *dirp)
Get a directory entry. Returns 0 if no more entries.
virtual int Unlink(const char *name)
Unlink, i.e. remove, a file.
static TString Format(const char *fmt,...)
Static method which formats a string using a printf style format descriptor and return a TString...
THashList implements a hybrid collection class consisting of a hash table and a list to store TObject...
The TNamed class is the base class for all named ROOT classes.
Bool_t EndsWith(const char *pat, ECaseCompare cmp=kExact) const
Return true if string ends with the specified string.
Ssiz_t First(char c) const
Find first occurrence of a character c.
virtual const char * TempDirectory() const
Return a user configured or systemwide directory to create temporary files in.
const char * GetName() const
Returns name of object.
Named parameter, streamable and storable.
TObjString * ExportInfo(const char *name=0, Int_t popt=0)
Export the relevant info as a string; use 'name' as collection name, if defined, else use GetName()...
virtual TObject * FindObject(const char *name) const
Must be redefined in derived classes.
R__EXTERN TSystem * gSystem
write collection with single key
TObject * Remove(TObject *key)
Remove the (key,value) pair with key from the map.
Int_t Add(TFileInfo *info)
Add TFileInfo to the collection.
Long64_t GetNFiles() const
Bool_t BeginsWith(const char *s, ECaseCompare cmp=kExact) const
TObject * Remove(TObject *obj)
Remove object from the list.
Bool_t ExistsDataSet(const char *dsname)
ExistsDataSet wrapper.
void Form(const char *fmt,...)
Formats a string using a printf style format descriptor.
Int_t pq2register(const char *dsname, const char *files, const char *opt)
char * Form(const char *fmt,...)
void do_info_server(const char *server)
Execute 'info-server'.
#define SDELETE(x, y, z, w, t)
void SetName(const char *name)
1-D histogram with a double per channel (see TH1 documentation)}
TMap * GetDataSets(const char *owner, const char *server, const char *opt)
GetDataSets wrapper.
virtual void SetLabelSize(Float_t size=0.04)
Set size of axis labels The size is expressed in per cent of the pad width.
int do_anadist_plot(TH1D *h1d, const char *)
Create the plot for the histogram, and save to 'fnout'.
virtual void FreeDirectory(void *dirp)
Free a directory.
void do_cache(bool clear, const char *ds)
Execute 'cache'.
TString & Remove(Ssiz_t pos)
int do_verify(const char *dsname, const char *opt, const char *redir)
Execute 'verify'.
void SetAnchor(const char *anchor)
TObjArray * Tokenize(const TString &delim) const
This function is used to isolate sequential tokens in a TString.
void SetDefaultTreeName(const char *treeName)
Ssiz_t Last(char c) const
Find last occurrence of a character c.
TMap implements an associative array of (key,value) pairs using a THashTable for efficient retrieval ...
Bool_t Contains(const char *pat, ECaseCompare cmp=kExact) const
Int_t VerifyDataSet(const char *dsname, const char *opt, const char *redir)
VerifyDataSet wrapper.
virtual void SetBinLabel(Int_t bin, const char *label)
Set label for bin.
void DataSetCache(bool clear, const char *ds)
ShowCache wrapper.
void do_put(const char *files, const char *opt)
Execute 'put'.
Mother of all ROOT objects.
Bool_t R_ISDIR(Int_t mode)
virtual void Add(TObject *obj)
Class that contains a list of TFileInfo's and accumulated meta data information about its entries...
void printDataSet(TFileCollection *fc, Int_t popt)
Formatted printout of the content of TFileCollection 'fc'.
THist< 1, double, THistStatContent, THistStatUncertainty > TH1D
virtual void * OpenDirectory(const char *name)
Open a directory. Returns 0 if directory does not exist.
TObject * GetValue(const char *keyname) const
Returns a pointer to the value associated with keyname as name of the key.
void ShowDataSets(const char *ds, const char *opt)
ShowDataSets wrapper.
const AParamType & GetVal() const
Class describing a generic file including meta information.
void do_ls(const char *ds, const char *opt)
Execute 'ls'.
virtual void Print(Option_t *option="") const
Default print for collections, calls Print(option, 1).
void do_anadist_getkey(const char *p, TString &key)
Get the key corresponding to path 'p'.
virtual Int_t GetSize() const
Return the capacity of the collection, i.e.
virtual void SetTitle(const char *title="")
Set the title of the TNamed.
void SetBitAll(UInt_t f)
Set the bit for all TFileInfos.
virtual Int_t Write(const char *name=0, Int_t option=0, Int_t bufsize=0)
Write all objects in this collection.
TAxis * GetXaxis()
Get the behaviour adopted by the object about the statoverflows. See EStatOverflows for more informat...
virtual const char * GetName() const
Return name of this collection.
void Resize(Ssiz_t n)
Resize the string. Truncate or add blanks as necessary.
virtual const char * GetTitle() const
Returns title of object.
virtual void Close(Option_t *option="")
Close a file.
void do_ls_files_server(const char *ds, const char *server)
Execute 'ls-files'.
const char * Data() const