/search.css" rel="stylesheet" type="text/css"/> /search.js">
| Classes | Job Modules | Data Objects | Services | Algorithms | Tools | Packages | Directories | Tracs |

In This Package:

Public Member Functions | Public Attributes | Static Public Attributes | Properties
RollingGainAuto::cnf::Cnf Class Reference

List of all members.

Public Member Functions

def __init__
def juice_path
def args_
def cr
def writer
def __repr__

Public Attributes

 path
 expand envvars or twiddles
 args
 site
 simflag
 subsite
 namedict
 timestart
 timeend
 dbno
 dummy
 sitemask
 simmask

Static Public Attributes

string ptt = "^(?P<site>All|DayaBay|Far|LingAo|Mid|SAB)_(?P<subsite>AD1|AD2|AD3|AD4|All|IWS|OWS|RPC|Unknown)_(?P<simflag>MC|Data)\.csv"

Properties

 ptn = property(lambda self:re.compile(self.ptt))

Detailed Description

Collect params needed to feed to the ``wrt.ctx``
usage example

Auto preparation of context requires a standard naming convention for ``.csv`` files that are
matched by the regexp ``Cnf.ptt``, for example:

#. SAB_AD1_Data.csv
#. SAB_AD2_Data.csv
    
Note that the basename of files are matched, so if you want to express some more
metadata about the file like who it is from etc... do that via the directory you keep it in.
Remember that using SVN means that the entire history of a file remains available to you
together with brief and informative commit messages describing changes, so you do not need
to name files silly things like:

* "new_12b_tweaked_extended_corrected_from_zeyuan_accepted_confirmed.csv"


Definition at line 25 of file cnf.py.


Constructor & Destructor Documentation

def RollingGainAuto::cnf::Cnf::__init__ (   self)
Parse system arguments, storing results into this dict 
The mandatory path to a csv file is pattern matched to extract 
`site`, `subsite` and `simflag`

Definition at line 49 of file cnf.py.

00050                       :
00051         """
00052         Parse system arguments, storing results into this dict 
00053         The mandatory path to a csv file is pattern matched to extract 
00054         `site`, `subsite` and `simflag`
00055         
00056         """
00057         args = self.args_()
00058         log.info( args )
00059 
00060         os.environ['DBCONF'] = args.dbconf 
00061         dbconf = os.environ.get('DBCONF')
00062         log.warn("DBCONF set to %s " % dbconf )
00063 
00064         path = os.path.expandvars(os.path.expanduser(args.path))  ## expand envvars or twiddles
00065         self.juice_path( path )
00066 
00067         self.path = path
00068         self.args = args


Member Function Documentation

def RollingGainAuto::cnf::Cnf::juice_path (   self,
  path 
)
Extract context metadata from the path 

:param path: path to .csv source file

Definition at line 69 of file cnf.py.

00070                                :
00071         """
00072         Extract context metadata from the path 
00073 
00074         :param path: path to .csv source file
00075         """ 
00076         name = os.path.basename( path )
00077         # To do: enforce it match
00078         # Why do you need to know the file name
00079         name = 'All_All_Data.csv'
00080         #
00081         print name
00082         match = self.ptn.match(  name )
00083         assert match,  "failed to match name %s with pattern %s " % ( name , self.ptt ) 
00084         nd = match.groupdict()
00085 
00086         from DybDbi import Site, DetectorId, SimFlag
00087 
00088         self.site = Site.FromString( nd['site'] )
00089         self.simflag  = SimFlag.FromString( nd['simflag'] )
00090         self.subsite = DetectorId.FromString( nd['subsite'] )
00091        
00092         self.namedict = nd

def RollingGainAuto::cnf::Cnf::args_ (   self)
Parses script arguments

#. contructs namespace object containing the values 
#. configures logging 
#. converts datetimes into DBI TimeStamps
 

Definition at line 93 of file cnf.py.

00094                    :
00095         """
00096         Parses script arguments
00097 
00098         #. contructs namespace object containing the values 
00099         #. configures logging 
00100         #. converts datetimes into DBI TimeStamps
00101  
00102         """
00103         ap = argparse.ArgumentParser(description=__doc__)
00104         ap.add_argument('path',                help='path to csv file, mandatory argument')
00105         ap.add_argument('-l','--loglevel',     help='logging level INFO,WARN,DEBUG... Default %(default)s ')
00106         ap.add_argument(     "--logpath",      help="Path to write log file to. Default %(default)s ")
00107         ap.add_argument(     "--logformat",  help="Used by logger. Default %(default)s ")
00108         ap.add_argument(     '--task',         help='set non zero for testing non-default algorithms. Default %(default)s ')
00109         ap.add_argument(     '--timeformat',   help='format for times. Default %(default)s ')
00110         ap.add_argument(     '--timestart',    help='contextrange start time in UTC. Default %(default)s corresponds to TimeStamp.GetBOT  ', action=TimeAction )
00111         ap.add_argument(     '--timeend',      help='contextrange end time in UTC. Default %(default)s corresponds to TimeStamp.GetEOT ', action=TimeAction )
00112         ap.add_argument(     '--dbconf',       help='Section of ~/.my.cnf file. Default %(default)s ')
00113         ap.add_argument(     '--dbno', type=int,help='DB number in cascade. Default %(default)s ')
00114         ap.add_argument('-n','--dummy',        help='Dummy run. Default %(default)s ', action="store_true" )
00115         ap.set_defaults(
00116              loglevel="INFO", 
00117                  task=0, 
00118             timeformat="%Y-%m-%d %H:%M:%S", 
00119              timestart=None, 
00120                timeend=None,
00121                dbconf="tmp_offline_db",
00122                   dbno=0, 
00123                dummy=False,
00124            logformat='%(asctime)s %(name)s %(levelname)-8s %(message)s',
00125              logpath=None,
00126          )
00127 
00128         args = ap.parse_args()
00129 
00130         loglevel = getattr(logging,args.loglevel.upper())
00131         logging.basicConfig( level=loglevel )
00132 
00133         sh = logging.StreamHandler()
00134         sh.setLevel(loglevel)
00135         fmtr = logging.Formatter(args.logformat)
00136         sh.setFormatter(fmtr)
00137         log.addHandler(sh)
00138 
00139         if args.logpath:
00140             fh = logging.FileHandler(args.logpath,mode="w")
00141             fh.setFormatter(fmtr)
00142             fh.setLevel(loglevel)
00143             log.addHandler(fh)
00144 
00145 
00146         from DybDbi import TimeStamp
00147         timestart = args.timestart
00148         timestart = TimeStamp.fromAssumedUTCDatetime( timestart ) if timestart else TimeStamp.GetBOT()
00149 
00150         timeend   = args.timeend
00151         timeend = TimeStamp.fromAssumedUTCDatetime( timeend ) if timeend else TimeStamp.GetEOT()
00152         
00153         self.timestart = timestart
00154         self.timeend = timeend
00155 
00156         self.dbno = args.dbno 
00157         self.dummy = args.dummy
00158         return args

def RollingGainAuto::cnf::Cnf::cr (   self)
Convert the strings into enum value, and datetimes into TimeStamps in
order to create the ContextRange instance 

:return: context range instance 

Definition at line 159 of file cnf.py.

00160                 :
00161         """
00162         Convert the strings into enum value, and datetimes into TimeStamps in
00163         order to create the ContextRange instance 
00164 
00165         :return: context range instance 
00166         """ 
00167         from DybDbi import ContextRange
00168         self.sitemask = self.site
00169         self.simmask = self.simflag
00170         return ContextRange( self.sitemask, self.simmask, self.timestart, self.timeend )
00171 

def RollingGainAuto::cnf::Cnf::writer (   self,
  kls 
)
Create a pre-configured DybDbi writer based on 
arguments and source csv filename parsing and 
creates the corresponding DB table if it does not exist.

:param kls: DybDbi class, eg GCalibPmtHighGain

Definition at line 172 of file cnf.py.

00173                           :
00174         """
00175         Create a pre-configured DybDbi writer based on 
00176         arguments and source csv filename parsing and 
00177         creates the corresponding DB table if it does not exist.
00178 
00179         :param kls: DybDbi class, eg GCalibPmtHighGain
00180 
00181         """
00182         from DybDbi import TimeStamp
00183 
00184         assert kls.__name__[0] == 'G', "DybDbi classes must start with 'G' unlike %s " % kls.__name__
00185         name = kls.__name__[1:]
00186         assert self.dbno == 0 , "unexpected dbno %s " % self.dbno
00187 
00188         log.info("creating DB tables for %s in dbno %s  " % ( name , self.dbno )) 
00189         kls().CreateDatabaseTables( self.dbno , name )
00190 
00191         wrt = kls.Wrt() 
00192         wrt.ctx( 
00193              contextrange=self.cr(), 
00194              dbno=self.dbno ,
00195              versiondate=TimeStamp(0,0),       
00196              subsite=self.subsite,
00197         )
00198         return wrt

def RollingGainAuto::cnf::Cnf::__repr__ (   self)

Definition at line 199 of file cnf.py.

00200                       :
00201         return self.__class__.__name__ + "\n" + pformat(vars(self)) 
00202 
00203 


Member Data Documentation

string RollingGainAuto::cnf::Cnf::ptt = "^(?P<site>All|DayaBay|Far|LingAo|Mid|SAB)_(?P<subsite>AD1|AD2|AD3|AD4|All|IWS|OWS|RPC|Unknown)_(?P<simflag>MC|Data)\.csv" [static]

Definition at line 46 of file cnf.py.

expand envvars or twiddles

Definition at line 55 of file cnf.py.

Definition at line 55 of file cnf.py.

Definition at line 73 of file cnf.py.

Definition at line 73 of file cnf.py.

Definition at line 73 of file cnf.py.

Definition at line 73 of file cnf.py.

Definition at line 100 of file cnf.py.

Definition at line 100 of file cnf.py.

Definition at line 100 of file cnf.py.

Definition at line 100 of file cnf.py.

Definition at line 164 of file cnf.py.

Definition at line 164 of file cnf.py.


Property Documentation

RollingGainAuto::cnf::Cnf::ptn = property(lambda self:re.compile(self.ptt)) [static]

Definition at line 47 of file cnf.py.


The documentation for this class was generated from the following file:
| Classes | Job Modules | Data Objects | Services | Algorithms | Tools | Packages | Directories | Tracs |

Generated on Fri May 16 2014 09:59:50 for RollingGainAuto by doxygen 1.7.4