XrdProofGroup.h

Go to the documentation of this file.
00001 // @(#)root/proofd:$Id: XrdProofGroup.h 33458 2010-05-11 07:31:07Z ganis $
00002 // Author: Gerardo Ganis  June 2007
00003 
00004 /*************************************************************************
00005  * Copyright (C) 1995-2005, Rene Brun and Fons Rademakers.               *
00006  * All rights reserved.                                                  *
00007  *                                                                       *
00008  * For the licensing terms see $ROOTSYS/LICENSE.                         *
00009  * For the list of contributors see $ROOTSYS/README/CREDITS.             *
00010  *************************************************************************/
00011 
00012 #ifndef ROOT_XrdProofGroup
00013 #define ROOT_XrdProofGroup
00014 
00015 //////////////////////////////////////////////////////////////////////////
00016 //                                                                      //
00017 // XrdProofGroup                                                        //
00018 //                                                                      //
00019 // Authors: G. Ganis, CERN, 2007                                        //
00020 //                                                                      //
00021 // Class describing groups                                              //
00022 //                                                                      //
00023 //////////////////////////////////////////////////////////////////////////
00024 
00025 #ifdef OLDXRDOUC
00026 #  include "XrdSysToOuc.h"
00027 #  include "XrdOuc/XrdOucPthread.hh"
00028 #else
00029 #  include "XrdSys/XrdSysPthread.hh"
00030 #endif
00031 #include "XrdOuc/XrdOucHash.hh"
00032 #include "XrdOuc/XrdOucString.hh"
00033 #include "XrdProofdAux.h"
00034 
00035 //
00036 // Group Member class
00037 //
00038 class XrdProofGroupMember {
00039 private:
00040    XrdOucString  fName;    // Name of the member
00041    int           fActive;  // Number of member's active sessions
00042 
00043 public:
00044    XrdProofGroupMember(const char *n) : fName(n) { fActive = 0; }
00045    virtual ~XrdProofGroupMember() { }
00046 
00047    int           Active() const { return fActive; }
00048    void          Count(int n) { fActive += n; }
00049    const char   *Name() const { return fName.c_str(); }
00050 };
00051 
00052 class XrdProofGroup {
00053 friend class XrdProofGroupMgr;
00054 private:
00055    XrdOucString  fName;    // group name
00056 
00057    XrdOucString  fMembers; // comma-separated list of members
00058    int           fSize;    // Number of members
00059    XrdOucHash<XrdProofGroupMember> fActives;  // Keeps track of members having active sessions
00060 
00061    // Properties
00062    float         fPriority; // Arbitrary number indicating the priority of this group
00063    int           fFraction; // Resource fraction in % (nominal)
00064    float         fFracEff;  // Resource fraction in % (effective)
00065 
00066    XrdSysRecMutex *fMutex; // Local mutex
00067 
00068    void          AddMember(const char *usr) { XrdSysMutexHelper mhp(fMutex);
00069                                               fMembers += usr; fMembers += ","; fSize++; }
00070    XrdProofGroup(const char *n, const char *m = 0);
00071 
00072 public:
00073    ~XrdProofGroup();
00074 
00075    int           Active(const char *usr = 0);
00076    bool          HasMember(const char *usr);
00077 
00078    inline const char *Members() const { XrdSysMutexHelper mhp(fMutex); return fMembers.c_str(); }
00079    inline const char *Name() const { XrdSysMutexHelper mhp(fMutex); return fName.c_str(); }
00080    inline int    Size() const { XrdSysMutexHelper mhp(fMutex); return fSize; }
00081 
00082    inline int    Fraction() const { XrdSysMutexHelper mhp(fMutex); return fFraction; }
00083    inline float  FracEff() const { XrdSysMutexHelper mhp(fMutex); return fFracEff; }
00084    inline float  Priority() const { XrdSysMutexHelper mhp(fMutex); return fPriority; }
00085    void          SetFracEff(float f) { XrdSysMutexHelper mhp(fMutex); fFracEff = f; }
00086    void          SetFraction(int f) { XrdSysMutexHelper mhp(fMutex); fFraction = f; }
00087    void          SetPriority(float p) { XrdSysMutexHelper mhp(fMutex); fPriority = p; }
00088 
00089    void          Count(const char *usr, int n = 1);
00090    void          Print();
00091 };
00092 
00093 
00094 //
00095 // Group Manager class
00096 //
00097 class XrdProofGroupMgr {
00098 private:
00099    XrdOucString              fIterator; // Keeps track of groups already processed 
00100    XrdOucHash<XrdProofGroup> fGroups;  // Keeps track of groups managed by this instance
00101    XrdSysRecMutex            fMutex;   // Mutex to protect access to fGroups
00102 
00103    XrdProofdFile             fCfgFile; // Last used group configuration file
00104    XrdProofdFile             fPriorityFile; // Last used file with priorities
00105 
00106    int           ParseInfoFrom(const char *fn);
00107 
00108 public:
00109    XrdProofGroupMgr(const char *fn = 0);
00110    ~XrdProofGroupMgr() { }
00111 
00112    int            Config(const char *fn);
00113 
00114    int            ReadPriorities();
00115    int            SetEffectiveFractions(bool optprio);
00116 
00117    XrdProofGroup *Apply(int (*f)(const char *, XrdProofGroup *, void *), void *arg);
00118 
00119    XrdOucString   Export(const char *grp);
00120    int            Num() { return fGroups.Num(); }
00121    void           Print(const char *grp);
00122 
00123    XrdProofGroup *GetGroup(const char *grp);
00124    XrdProofGroup *GetUserGroup(const char *usr, const char *grp = 0);
00125 
00126    const char    *GetCfgFile() const { return fCfgFile.fName.c_str(); }
00127 
00128    // Pseudo-iterator functionality
00129    void           ResetIter() { fIterator = "getnextgrp:"; }
00130    XrdProofGroup *Next();
00131 };
00132 
00133 // Auc structures for scan through operations
00134 typedef struct {
00135    float prmax;
00136    float prmin;
00137    int nofrac;
00138    float totfrac;
00139 } XpdGroupGlobal_t;
00140 
00141 typedef struct {
00142    int opt;
00143    XpdGroupGlobal_t *glo;
00144    float cut;
00145    float norm;
00146 } XpdGroupEff_t;
00147 
00148 #endif

Generated on Tue Jul 5 14:51:50 2011 for ROOT_528-00b_version by  doxygen 1.5.1