def doStartupChecks():

    global doStartFromPAT

    log.output("********** Checking environment **********")

    log.output("--> Checking if you have a "+options.cmssw_ver+" release.")

    if (os.path.isdir(options.cmssw_ver)):
        log.output(" ---> Ok, the release is present!")
        cmd ='cd '+options.cmssw_ver+'; cmsenv'
        pExe = Popen(cmd, shell=True, stdin=PIPE, stdout=PIPE, stderr=STDOUT, close_fds=True)
    else:
        log.output(" ---> ERROR: Please scram the proper release first! (Exiting)")
        dieOnError("Environment: resquested CMSSW version is not found in the working directory")

    log.output("--> Checking if "+options.cmssw_ver+" contains the TopTreeProducer package.")

    if (os.path.isdir(options.cmssw_ver+TopTreeProducerDir)):
        log.output(" ---> Ok, the "+TopTreeProducerDir+" directory exists!")
    else:
        log.output(" ---> ERROR: Please ensure that you have the TopTreeProducer package installed! (Exiting)")
        dieOnError("Environment: resquested CMSSW version does not contain the TopTreeProducer package")


    log.output("--> Checking if "+options.cmssw_ver+" contains the PatAlgos package.")

    if (os.path.isdir(options.cmssw_ver+PatDir)):
        log.output(" ---> Ok, the "+PatDir+" directory exists!")
    else:
        log.output(" ---> ERROR: Please ensure that you have the PatAlgos package installed! (Exiting)")
        dieOnError("Environment: resquested CMSSW version does not contain the PatAlgos package")


    log.output("--> Checking DBS to see wether the requested Dataset exists")

    if dbsInst == "":
        dbsMgr = DBSHandler("cms_dbs_prod_global");
    else:
        dbsMgr = DBSHandler(dbsInst);

    if doStartFromPAT:

        dbsMgr.setDBSInst("cms_dbs_ph_analysis_02")

    if not dbsMgr.datasetExists(options.dataset):
        log.output(" ---> ERROR: "+options.dataset+" was not found in DBS! (Exiting)")
        dieOnError("Dataset: DBS query for your dataset returned an empty set.")

    else:
        log.output(" ---> Ok, Dataset was found!")

    log.output("--> Checking status of CRABServer (not yet implemented)")

    crab = CRABHandler("","","",log)

    crab.checkGridProxy(False)

    crab.checkCredentials(False)
import re

# interacting with the os
import subprocess
from subprocess import Popen, PIPE, STDOUT

import os, os.path

import sys

import math

from DBSHandler import DBSHandler


dbs = DBSHandler("cms_dbs_prod_global")

if not dbs.datasetExists(sys.argv[1]):

    print "ERROR: Dataset does not exist in DBS"
    sys.exit(0)
    
else:

    print "Total nEvents: "+str(dbs.getTotalEvents(sys.argv[1],[]))

for line in open(sys.argv[2],"r"):
        
    runs = line.strip().split(",")

    #print runs
def doStartupChecks():

    global doStartFromPAT

    log.output("********** Checking environment **********")

    log.output("--> Checking if you have a " + options.cmssw_ver + " release.")

    if (os.path.isdir(options.cmssw_ver)):
        log.output(" ---> Ok, the release is present!")
        cmd = 'cd ' + options.cmssw_ver + '; cmsenv'
        pExe = Popen(cmd,
                     shell=True,
                     stdin=PIPE,
                     stdout=PIPE,
                     stderr=STDOUT,
                     close_fds=True)
    else:
        log.output(
            " ---> ERROR: Please scram the proper release first! (Exiting)")
        dieOnError(
            "Environment: resquested CMSSW version is not found in the working directory"
        )

    log.output("--> Checking if " + options.cmssw_ver +
               " contains the TopTreeProducer package.")

    if (os.path.isdir(options.cmssw_ver + TopTreeProducerDir)):
        log.output(" ---> Ok, the " + TopTreeProducerDir +
                   " directory exists!")
    else:
        log.output(
            " ---> ERROR: Please ensure that you have the TopTreeProducer package installed! (Exiting)"
        )
        dieOnError(
            "Environment: resquested CMSSW version does not contain the TopTreeProducer package"
        )

    log.output("--> Checking if " + options.cmssw_ver +
               " contains the PatAlgos package.")

    if (os.path.isdir(options.cmssw_ver + PatDir)):
        log.output(" ---> Ok, the " + PatDir + " directory exists!")
    else:
        log.output(
            " ---> ERROR: Please ensure that you have the PatAlgos package installed! (Exiting)"
        )
        dieOnError(
            "Environment: resquested CMSSW version does not contain the PatAlgos package"
        )

    log.output("--> Checking DBS to see wether the requested Dataset exists")

    if dbsInst == "":
        dbsMgr = DBSHandler("cms_dbs_prod_global")
    else:
        dbsMgr = DBSHandler(dbsInst)

    if doStartFromPAT:

        dbsMgr.setDBSInst("cms_dbs_ph_analysis_02")

    if not dbsMgr.datasetExists(options.dataset):
        log.output(" ---> ERROR: " + options.dataset +
                   " was not found in DBS! (Exiting)")
        dieOnError(
            "Dataset: DBS query for your dataset returned an empty set.")

    else:
        log.output(" ---> Ok, Dataset was found!")

    log.output("--> Checking status of CRABServer (not yet implemented)")

    crab = CRABHandler("", "", "", log)

    crab.checkGridProxy(False)

    crab.checkCredentials(False)