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);
377 Printf(
"%s: WARNING: problems with %d dataset(s)", action, ndp);
379 Printf(
"%s: WARNING: some problems occured", action);
382 Printf(
"%s: %d dataset(s) registered", action, nd);
393 const char *action =
"pq2-ds";
405 Printf(
"%s: ERROR: problems removing dataset '%s'", action, dsname);
418 Printf(
"%s: ERROR: problems retrieving info about datasets", action);
426 while ((os = dynamic_cast<TObjString*>(nxd()))) {
435 Printf(
"%s: ERROR: problems removing dataset '%s'", action, ds.
Data());
445 Printf(
"%s: WARNING: no matching dataset found!", action);
447 Printf(
"%s: %d dataset(s) removed", action, nd);
459 int do_verify(
const char *dsname,
const char *opt,
const char *redir)
461 const char *action =
"pq2-verify";
463 Int_t nd = 0, rc = -1;
471 Printf(
"%s: ERROR: problems verifing dataset '%s'", action, dsname);
475 Printf(
"%s: WARNING: %s: some files not yet online (staged)", action, dsname);
483 Printf(
"%s: ERROR: problems retrieving info about datasets", action);
491 while ((os = dynamic_cast<TObjString*>(nxd()))) {
494 Printf(
"%s: start verification of dataset '%s' ...", action, os->
GetName());
498 Printf(
"%s: ERROR: problems verifying dataset '%s'", action, os->
GetName());
500 }
else if (xrc > 0) {
504 Printf(
"%s: WARNING: %s: some files not yet online (staged)", action, os->
GetName());
514 Printf(
"%s: WARNING: no matching dataset found!", action);
516 Printf(
"%s: %d dataset(s) verified", action, nd);
530 void do_anadist(
const char *ds,
const char *servers,
const char *ignsrvs,
531 const char *excsrvs,
const char *
metrics,
const char *fnout,
532 const char *plot,
const char *outfile,
const char *infile)
534 const char *action =
"pq2-ana-dist";
547 while (dss.Tokenize(d, from,
",")) {
554 while ((k = nxds())) {
565 if (!fcmap || fcmap->
GetSize() <= 0) {
569 Printf(
"%s: ERROR: problems retrieving info about dataset '%s' (or empty dataset)", action, ds);
577 if (metrics && !strcmp(metrics,
"S")) optMet = 1;
584 if (
do_anadist_ds(0, 0, 0, 0, optMet, 0, &distinfo, 0, infile) != 0) {
585 Printf(
"%s: problems getting dist info from '%s'", action, infile);
611 optMet, fnout, &distinfo, outfile, infile) != 0) {
612 Printf(
"%s: problems analysing dataset '%s'", action, fc ? fc->
GetName() :
"<undef>");
621 if (!(fileplot.IsNull())) {
622 if (fileplot.Contains(
".")) {
623 gext = fileplot(fileplot.Last(
'.') + 1, fileplot.Length());
627 const char *fmts[9] = {
"png",
"eps",
"ps",
"pdf",
"svg",
"gif",
"xpm",
"jpg",
"tiff" };
629 while (iplot < 9 && gext != fmts[iplot]) { iplot++; }
631 Printf(
"%s: graphics format '%s' not supported: switching to 'png'", action, gext.
Data());
634 if (!(fileplot.EndsWith(gext))) {
635 if (!(fileplot.EndsWith(
"."))) fileplot +=
".";
642 TIter nxs(&distinfo);
649 nnn.ReplaceAll(
".",
"");
656 Printf(
"%s: plot requested but no server found (info list is empty)!", action);
669 FILE *ftmp = fopen(filetmp.
Data(),
"w");
671 fprintf(ftmp,
"%s %s %s", filehist.
Data(), fileplot.Data(),
glabMet[optMet]);
674 Printf(
"%s: problems opening temp file '%s' (errno: %d)", action, filetmp.
Data(), errno);
675 Printf(
"%s: relevant info: %s %s %s (input to pq2PlotDist.C)",
676 action, filehist.
Data(), fileplot.Data(),
glabMet[optMet]);
679 Printf(
"%s: problems opening file '%s'", action, filehist.
Data());
682 Printf(
"%s: histogram requested but not found", action);
694 const char *excsrvs,
int met,
const char *fnout,
695 TList *distinfo,
const char *outfile,
const char *infile)
697 const char *action =
"pq2-ana-dist-ds";
700 Bool_t distonly_m = (!fc && distinfo && infile && strlen(infile) > 0) ?
kTRUE :
kFALSE;
701 const char *dsname = 0;
704 Printf(
"%s: dataset undefined!", action);
709 Printf(
"%s: dataset '%s' is empty", action, dsname);
716 THashList *ignore = 0, *targets = 0, *exclude = 0;
722 if (ignsrvs && strlen(ignsrvs)) {
734 if (excsrvs && strlen(excsrvs)) {
748 if (servers && strlen(servers)) {
767 Int_t targets_size = -1;
768 if (infile && strlen(infile)) {
771 Printf(
"%s: reading info from file '%s' ", action, infile);
772 if (!(fcsls = (
THashList *) flist->
Get(
"FileDistList"))) {
773 Printf(
"%s: could not find starting file distribution 'FileDistList' in input file '%s' ",
777 SDELTRE(ignore, targets, exclude);
781 fcsls_title = (
TNamed *) flist->
Get(
"FileDistList_Title");
784 if (psz) targets_size = psz->
GetVal();
789 if (distinfo && fcsls_title && strlen(fcsls_title->
GetTitle()) > 0) {
791 if (strcmp(distinfo->
GetName(),
"TList")) {
792 if (!(runt.IsNull())) runt +=
",";
799 Printf(
"%s: problems opening input file '%s' ", action, infile);
800 SDELTRE(ignore, targets, exclude);
806 fcsls->
SetName(
"FileDistList");
807 fcsls_title =
new TNamed(
"FileDistList_Title", distinfo ? distinfo->
GetName() :
"");
829 if (ignore && ignore->
FindObject(key))
continue;
833 Printf(
"%s:%s: found server '%s' ... ", action, dsname, key.
Data());
844 Printf(
"%s:%s: add new target server '%s' ...", action, dsname, key.
Data());
849 if (fcs) fcs->
Add(fi);
857 if (targets->GetSize() <= 0) {
858 Printf(
"%s:%s: target servers list is empty!", action, dsname);
859 SDELETE(ignore, targets, exclude, fcsls, fcsls_title);
862 Printf(
"%s:%s: %d target servers found", action, dsname, targets->GetSize());
871 targets_size = (targets) ? targets->
GetSize() : targets_size;
873 if (targets_size > 0) {
874 avgfiles = (
Double_t)totfiles / targets_size;
875 avgsize = (
Double_t)totsz / targets_size / 1024. / 1024. / 1024.;
876 Printf(
"%s:%s: %d servers found, %lld files; in average: %.3f files / %.3f GBs per server",
877 action, dsname, fcsls->
GetSize(), totfiles, avgfiles, avgsize);
880 Printf(
"%s:%s: target size is null or negative", action, dsname);
881 SDELETE(ignore, targets, exclude, fcsls, fcsls_title);
885 if (
gverbose > 0)
Printf(
"\n%s:%s: Before redistribution:", action, dsname);
903 }
else if (met == 1) {
908 Printf(
"%s:%s: server %s: %lld files (diff: %lld, %.3f) - %.3f GBs (diff: %.3f, %.3f)",
909 action, dsname, fcs->
GetName(), fcs->
GetNFiles(), nfexcess, xdf, fcsz, szexcess, xdsz);
913 if (targets && targets->FindObject(fcs->
GetName())) {
915 if (nfexcess > 0.) isExcess =
kTRUE;
916 }
else if (met == 1) {
917 if (szexcess > 0.) isExcess =
kTRUE;
930 if (outfile && strlen(outfile)) {
934 Printf(
"%s: saving info to file '%s' ", action, outfile);
944 Printf(
"%s: problems opening output file '%s' ", action, outfile);
954 SDELETE(targets, fcsls, fcsls_title, excls, defls);
960 Printf(
"%s:%s: %d servers found in excess", action, dsname, excls->
GetSize());
962 Printf(
"%s:%s: %d servers found in defect", action, dsname, defls->
GetSize());
965 Printf(
"%s:%s: %d servers found in excess, %d in defect", action, dsname, excls->
GetSize(), defls->
GetSize());
970 if (fnout && strlen(fnout) > 0) {
971 if (!(fout = fopen(fnout,
"a"))) {
972 Printf(
"%s: problems opening output file '%s' (errno: %d)", action, fnout, errno);
973 SDELETE(targets, fcsls, fcsls_title, excls, defls);
992 Printf(
"%s:%s: WARNING: processing list in excess '%s': no more lists in deficit!",
993 action, dsname, fcs->
GetName());
998 fcsz += (fi->
GetSize() / 1024. / 1024. / 1024.) ;
1000 (((met == 0) && (fcfiles > avgfiles)) || ((met == 1) && (fcsz > avgsize)))) {
1006 php.
Remove(php.Index(u.GetFile()));
1008 if (php.EndsWith(
"/") && ((ilst = php.Last(
'/')) !=
kNPOS)) php.Remove(ilst);
1010 fprintf(fout,
"%s %s %s\n", u.GetFile(), php.Data(), fcd->
GetName());
1012 if (printheader)
Printf(
" File Source_Server Destination_Server");
1013 Printf(
"%s %s %s", u.GetFile(), php.Data(), fcd->
GetName());
1032 if ((xfcsz / 1024. / 1024. / 1024.) > avgsize) getnext =
kTRUE;
1042 if ((fclose(fout)) != 0)
1043 Printf(
"%s: problems closing output file '%s' (errno: %d)", action, fnout, errno);
1045 Printf(
"%s:%s: %d files should be moved to make the distribution even (metrics: %s)",
1046 action, dsname, mvfiles,
glabMet[met]);
1050 Printf(
"\n%s:%s: After redistribution:", action, dsname);
1055 Double_t xdf = nfexcess / avgfiles;
1057 Double_t szexcess = fcsz - avgsize;
1058 Double_t xdsz = szexcess / avgsize;
1059 Printf(
"%s:%s: Server %s: %lld files (diff: %lld, %.3f) - %.3f GBs (diff: %.3f, %.3f)",
1060 action, dsname, fcs->
GetName(), fcs->
GetNFiles(), nfexcess, xdf, fcsz, szexcess, xdsz);
1066 Double_t xdf = nfexcess / avgfiles;
1068 Double_t szexcess = fcsz - avgsize;
1069 Double_t xdsz = szexcess / avgsize;
1070 Printf(
"%s:%s: server %s: %lld files (diff: %lld, %.3f) - %.3f GBs (diff: %.3f, %.3f)",
1071 action, dsname, fcs->
GetName(), fcs->
GetNFiles(), nfexcess, xdf, fcsz, szexcess, xdsz);
1075 SDELETE(targets, fcsls, fcsls_title, excls, defls);
1106 gProtoPortMap.
Add(php);
1123 Printf(
"do_anadist_plot: will be doing a plot here ... ");
1126 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.
TMap * GetDataSets(const char *owner="", const char *server="", const char *opt=0)
GetDataSets wrapper.
virtual Int_t Fill(Double_t x)
Increment bin with abscissa X by 1.
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
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.
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.
Int_t VerifyDataSet(const char *dsname, const char *opt=0, const char *redir=0)
VerifyDataSet wrapper.
TObject * FindObject(const char *name) const
Find object using its name.
TString & Insert(Ssiz_t pos, const char *s)
overwrite existing object with same name
const char * GetUrl(Bool_t withDeflt=kFALSE) const
Return full URL.
virtual TObject * FindObject(const char *name) const
Find an object in this list using its name.
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.
void DataSetCache(bool clear, const char *ds)
ShowCache wrapper.
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.
Int_t RemoveDataSet(const char *dsname)
RemoveDataSet wrapper.
TFileCollection * GetDataSet(const char *ds, const char *server="")
GetDataSet wrapper.
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
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.
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)
write collection with single key
void SetName(const char *name)
tomato 1-D histogram with a double per channel (see TH1 documentation)}
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
virtual void SetBinLabel(Int_t bin, const char *label)
Set label for bin.
void ShowDataSets(const char *ds, const char *opt="")
ShowDataSets 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.
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
virtual void SetTitle(const char *title="")
Set the title of the TNamed.
Int_t RegisterDataSet(const char *dsname, TFileCollection *fc, const char *opt="")
RegisterDataSet wrapper.
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.
Bool_t ExistsDataSet(const char *dsname)
ExistsDataSet wrapper.
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