if options.action == 'trgbyls':
     session.transaction().start(True)
     result=lumiCalcAPI.trgForRange(session.nominalSchema(),irunlsdict,trgbitname=sname,trgbitnamepattern=spattern,withL1Count=True,withPrescale=True)
     session.transaction().commit()
     if not options.outputfile:
         lumiReport.toScreenLSTrg(result,iresults=iresults,isverbose=isdetail)
     else:
         lumiReport.toCSVLSTrg(result,options.outputfile,iresults=iresults,isverbose=isdetail)
 if options.action == 'hltbyls':
     withL1Pass=False
     withHLTAccept=False
     if options.verbose:
         withL1Pass=True
         withHLTAccept=True
     session.transaction().start(True)
     result=lumiCalcAPI.hltForRange(session.nominalSchema(),irunlsdict,hltpathname=sname,hltpathpattern=spattern,withL1Pass=withL1Pass,withHLTAccept=withHLTAccept)
     session.transaction().commit()
     if not options.outputfile:
         lumiReport.toScreenLSHlt(result,iresults=iresults,isverbose=options.verbose)
     else:
         lumiReport.toCSVLSHlt(result,options.outputfile,iresults,options.verbose)
 if options.action == 'trgconf':
     session.transaction().start(True)
     result=lumiCalcAPI.trgbitsForRange(session.nominalSchema(),irunlsdict,datatag=None)        
     session.transaction().commit()
     if not options.outputfile:
         lumiReport.toScreenConfTrg(result,iresults,options.verbose)
     else:
         lumiReport.toCSVConfTrg(result,options.outputfile,iresults,options.verbose)
 if options.action == 'hltconf':
     session.transaction().start(True)
    withHLTAccept = False

    pattern_results = {}

    for pattern in options.pattern:
        for run in sorted(run_ls.keys()):
            small_run_ls = { run : run_ls[run] }
            sys.stdout.write("Querying pattern: %s in run %i" % (pattern, run))
            sys.stdout.write("                     ")
            sys.stdout.write('\r')
            try:
                session.transaction().start(True)
                result = lumiCalcAPI.hltForRange(
                    session.nominalSchema(),
                    small_run_ls,
                    hltpathname=None,
                    hltpathpattern=pattern,
                    withL1Pass=withL1Pass,
                    withHLTAccept=withHLTAccept)
                pattern_results.setdefault(pattern, {}).update(result)
            except:
                sys.stderr.write(
                    "\nException detected processing run %i, skipping\n" % run)
            finally:
                session.transaction().commit()

    # Now we want tto find, for each run, all the unprescaled triggers.
    # Just go through each run, and check what the lowest prescale is for each
    # pattern.
    run_info = {}
    for pattern, run_ls in pattern_results.iteritems():