"""
Usage:
  brilcalc lumi [options] 

Options:
  -h, --help                    Show this screen
  -c CONNECT                    Service name [default: offline]
  -p AUTHPATH                   Authentication file
  -n SCALEFACTOR                Scale factor to results [default: 1.0]
  -f FILLNUM                    Fill number
  -r RUNNUMBER                  Run number
  -i INPUTFILE                  Input selection json file or string
  -o OUTPUTFILE                 Output csv file. Special file '-' for stdout.
  -b BEAMSTATUS                 Beam mode. FLAT TOP,SQUEEZE,ADJUST,STABLE BEAMS
  -u UNIT                       Lumi unit. hz/ub,1e30/cm2s,/nb,1e33/cm2 [default: /ub]
  --amodetag AMODETAG           Accelerator mode 
  --beamenergy BEAMENERGY       Target single beam energy in GeV
  --minBiasXsec MINBIASXSEC     Minbias cross-section in ub [default: 80000.0]
  --datatag DATATAG             Data tag name
  --normtag NORMTAG             correction tag or combined correction tag selection file or string
  --begin BEGIN                 Min start time (MM/DD/YY HH24:MI:SS)/fill/run 
  --end END                     Max start time (MM/DD/YY HH24:MI:SS)/fill/run
  --output-style OSTYLE         Screen output style. tab, html, csv [default: tab]
  --type LUMITYPE               Luminosity type. hfoc,bcm1f,pltzero,pxl,dt
  --hltpath HLTPATH             HLT path name or fnmatch pattern
  --byls                        Show result in ls granularity
  --xing                        Show result in bx granularity
  --without-correction          Show raw data without calibration
  --ignore-mask                 Ignore l1 trgger bit mask for --hltpath specific luminosity
  --cerntime                    Show time in CERN local time
  --tssec                       Show time as second since Epoch
  --xingId BXID                 Filter bunches by id, "1,2,3" or file
  --xingTr BXTHRESHOLD          Filter bunches by percentage of max lumi, 0-1 
  --xingMin XINGMIN             Filter bunches by min lumi value   
  --checkjson                   Check total returned lumi sections against input json file    

"""

import os,sys
from docopt import docopt
from schema import Schema
from brilws.cli import clicommonargs

def validate(optdict):
    result={}
    #extract sub argdict here
    myvalidables = ['-c','-n','-f','-r','-i','-o','--amodetag','-b','--beamenergy','--minBiasXsec','--datatag','--normtag','--begin','--end','--output-style','--type','--hltpath','--xingId','--xingTr','--xingMin',str]
    argdict = dict((k,v) for k,v in clicommonargs.argvalidators.iteritems() if k in myvalidables)
    schema = Schema(argdict)
    result = schema.validate(optdict)

    if not result['-i'] and not result['-f'] and not result['-r'] and not result['--begin']:
        print 'Error: at least one time selection option in %s is required'%(','.join(['-i','-f','-r','--begin']))
        sys.exit(0)
    if result['--checkjson']:
        if not result['-i']:
            print 'Error: --checkjson switch must be used together with -i option'
            sys.exit(0)            
    return result

if __name__ == '__main__':
    args = docopt(__doc__,options_first=True)
    print args


@@ -2024,16 +2024,24 @@
    %0A  --
+without-
 checkjso
@@ -2056,17 +2056,16 @@
     
-        C
+Do not c
 heck
@@ -2117,18 +2117,17 @@
 son file
-  
+.
   %0A%0A%22%22%22%0A
@@ -2913,178 +2913,8 @@
 t(0)
-%0A    if result%5B'--checkjson'%5D:%0A        if not result%5B'-i'%5D:%0A            print 'Error: --checkjson switch must be used together with -i option'%0A            sys.exit(0)    
     

change --checkjson to --without-checkjson