Пример #1
0
    def finalize(self):
        print "INFO: finalize"
        # dump the histograms to a file
        self.output['histograms'].dump(opts.histofile)

        numAlignEvents = self.output['derivatives'].equations().numEvents()
        print 'INFO: number of events in derivatives: ', self.output[
            'derivatives'].equations().numEvents()
        if numAlignEvents > 0:
            # write the derivative file
            if len(opts.derivativefile) > 0:
                self.output['derivatives'].equations().writeToFile(
                    derivativefile)

            from GaudiPython.Bindings import AppMgr
            appMgr = AppMgr()
            # we want to reinitialize, but we don't want to initialize all
            # the reco algorithms, so we add just the alignment sequence:
            appMgr.setAlgorithms(['GaudiSequencer/AlignSequence'])
            appMgr.configure()
            appMgr.initialize()
            # update the geometry
            # updatetool = appMgr.toolsvc().create( typ = "Al::AlignUpdateTool", name = "ToolSvc.AlignUpdateTool", interface = "IAlignUpdateTool" )
            updatetool = appMgr.toolsvc().create(
                "Al::AlignUpdateTool", interface="Al::IAlignUpdateTool")
            updatetool.process(self.output['derivatives'].equations(),
                               opts.iter, 1)
            # call the xml writer tool
            writertool = appMgr.toolsvc().create(
                "WriteMultiAlignmentConditionsTool",
                interface="IWriteAlignmentConditionsTool")
            writertool.write()
            # now call finalize to write the conditions. there must be a better way.
            det = appMgr.detsvc()
            if self.output['otmonodata'] and det['OTMonoLayerAlignData']:
                det['OTMonoLayerAlignData'].add(self.output['otmonodata'])

            appMgr.finalize()
            # finally create a database layer
            import os
            os.system(
                "copy_files_to_db.py -c sqlite_file:Alignment.db{0} -s xml".
                format(condtag))
Пример #2
0
def run(input_files, output_file):

    ## Bit of extra configuration
    from GaudiConf import IOHelper
    IOHelper().inputFiles(input_files)
    HistogramPersistencySvc().OutputFile = output_file.replace('.root', '_histos.root')

    ## GaudiPython
    import GaudiPython
    import cppyy
    cppyy.load_reflection_info('libLinkerEvent')
    cppyy.load_reflection_info('libLinkerInstancesDict')

    from GaudiPython.Bindings import AppMgr
    appMgr = AppMgr(outputlevel = 3)
    appMgr.config()

    appMgr.HistogramPersistency = 'ROOT'
    ntSvc = GaudiPython.iService('NTupleSvc')
    ntSvc.Output = ["MATCHZERRLUN DATAFILE='{0}' OPT='NEW'".format(output_file)]

    from Hlt1Muons.MatchAlgo import MatchResidualAlgo
    match_algo = MatchResidualAlgo("MatchResidualAlgo", MatchVeloMuon = mvm.getFullName())
    match_algo.NTupleLUN = 'MATCHZERRLUN'
    appMgr.addAlgorithm(match_algo)

    from Hlt1Muons.MatchAlgo import MatchChi2Algo
    chi2_algo = MatchChi2Algo("MatchChi2Algo", MatchVeloMuon = mvm_chi2.getFullName())
    chi2_algo.NTupleLUN = 'MATCHZERRLUN'
    appMgr.addAlgorithm(chi2_algo)

    if mvm_old:
        chi2_algo_old = MatchChi2Algo("MatchChi2AlgoOld", MatchVeloMuon = mvm_old.getFullName())
        chi2_algo_old.NTupleLUN = 'MATCHZERRLUN'
        appMgr.addAlgorithm(chi2_algo_old)

    appMgr.initialize()
    appMgr.run(options.nevents)
    appMgr.stop()
    appMgr.finalize()
    appMgr.exit()
Пример #3
0
    def run(self):
        if lambdas == 'None':
            kali = firstPass(
                ##-- cuts and filters
                PtGamma=250 * MeV,  ## selection cuts
                ## event multiplicity filter
                Filter=
                "(650. > CONTAINS('Raw/Spd/Digits')) & ( CONTAINS('Rec/Vertex/Primary') > 0.) & ( CONTAINS('Rec/Vertex/Primary') < 5.)",

                ##-- output
                NTupleProduce=True,  # produce NTuples
                NTuple=self.__dsname + '.root',  # NTuple name
                Histograms=False,  # do not produce Histograms
                FemtoDST=self.__dsname + '.fmDST',  # output fmDST name

                ##-- general (configuring DaVinci)
                DataType='2015',  # data type
                EvtMax=self.__nevt,  # number of events to run
                OutputLevel=ERROR)
        else:
            kali = secondPass(
                ##
                DestroyTES=False,
                ## ``Physics''
                PtGamma=250 * MeV,
                Pi0Cut="PT > 550 * MeV",
                ## IO
                NTupleProduce=True,  # produce NTuples
                NTuple=self.__dsname + '.root',  # NTuple name
                Histograms=False,  # do not produce Histograms
                FemtoDST="",
                ## Calibration
                KaliDB={
                    'name': lambdas,
                    'ecal': 'ecal'
                },
                ## general
                DataType='2015',
                EvtMax=self.__nevt,
                OutputLevel=ERROR)

        from Configurables import CondDB
        CondDB().Simulation = False
        CondDB().UseDBSnapshot = True
        CondDB().DBSnapshotDirectory = "/group/online/hlt/conditions"
        CondDB().EnableRunChangeHandler = True
        CondDB().Tags["ONLINE"] = 'fake'
        CondDB().setProp("IgnoreHeartBeat", True)
        CondDB().Online = True

        try:
            import AllHlt1
        except ImportError:
            rd = '/group/online/hlt/conditions/RunChangeHandler'
            sys.path.append(rd)
            import AllHlt1

        import AllHlt1
        CondDB().RunChangeHandlerConditions = AllHlt1.ConditionMap

        Online = importOnline()

        ## ======== input data type - 'SDST' ============
        from Configurables import DaVinci
        DaVinci().InputType = 'DST'  # use SDSTs as an input
        DaVinci().CondDBtag = Online.CondDBTag
        DaVinci().DDDBtag = Online.DDDBTag

        from GaudiConf import IOHelper
        IOHelper('ROOT').inputFiles(self.__inputs)

        from GaudiPython.Bindings import AppMgr
        gaudi = AppMgr()
        gaudi.initialize()
        gaudi.run(self.__nevt)
        gaudi.stop()
        gaudi.finalize()
        gaudi.exit()
Пример #4
0
stat = Gaudi.initialize()
print "===================== Running the XML conversion ========================"
stat = Gaudi.run(1)
print "============= Status :",stat
if stat.isFailure():
  sys.exit(44)
print "============= Gaudi.ReturnCode :",Gaudi.ReturnCode
if Gaudi.ReturnCode != 0:
  sys.exit(44)
print "===================== Stopping the XML conversion ========================"
stat = Gaudi.stop()
print "============= Status :",stat
if stat.isFailure():
  sys.exit(44)
print "===================== Finalizing the XML conversion ========================"
stat = Gaudi.finalize()
print "============= Status :",stat
if stat.isFailure():
  sys.exit(44)
print "===================== Exiting the XML conversion ========================"
stat = Gaudi.exit()
print "============= Status :",stat
if stat.isFailure():
  sys.exit(44)
print "===================== Updating the Database ========================"
import CondDBUI
import CondDBUI.Admin
DBString = "CondDBOnline(owner)/ONLINE" # use the central Oracle Database...
####DBString = "sqlite_file:./CONDDB.db/ONLINE"
db = CondDBUI.CondDB(DBString, create_new_db = False, readOnly=False)
import time
Пример #5
0
    def run(self):
        from Configurables import Brunel
    
        ## Brunel parameters
        Brunel().Detectors   = ['Spd', 'Prs', 'Ecal', 'Hcal' ]
        Brunel().DataType    = "2015"
        Brunel().InputType   = "MDF"
        Brunel().OutputType  = "DST"
        Brunel().EvtMax      = self.__nevt
        Brunel().WriteFSR    = False
        Brunel().Histograms  = "Online"
        Brunel().OnlineMode  = True
        Brunel().PrintFreq   = 1000
        Brunel().DatasetName = self.__dsname

        ## use the conditions database
        ## configuration for online
        from Configurables import CondDB
        CondDB().Simulation = False
        CondDB().UseDBSnapshot = True
        CondDB().DBSnapshotDirectory = "/group/online/hlt/conditions"
        CondDB().EnableRunChangeHandler = True
        CondDB().Tags["ONLINE"] = 'fake'
        CondDB().setProp("IgnoreHeartBeat", True)
        CondDB().Online = True

        try:
            import AllHlt1
        except ImportError:
            rd = '/group/online/hlt/conditions/RunChangeHandler'
            sys.path.append(rd)
            import AllHlt1

        import AllHlt1
        CondDB().RunChangeHandlerConditions = AllHlt1.ConditionMap

        Online = importOnline()
        Brunel().CondDBtag = Online.CondDBTag
        Brunel().DDDBtag   = Online.DDDBTag

        """
        Messages in the online get redirected.
        Setup here the FMC message service
    
        @author M.Frank
        """
        app=Gaudi.ApplicationMgr()
        #Configs.AuditorSvc().Auditors = []
        app.MessageSvcType = 'LHCb::FmcMessageSvc'
        if Gaudi.allConfigurables.has_key('MessageSvc'):
            del Gaudi.allConfigurables['MessageSvc']
        msg = Configs.LHCb__FmcMessageSvc('MessageSvc')
        msg.fifoPath      = os.environ['LOGFIFO']
        msg.LoggerOnly    = True
        msg.doPrintAlways = False
        msg.OutputLevel   = MSG_INFO # Online.OutputLevel

        from GaudiConf import IOHelper
        IOHelper('MDF').inputFiles(self.__inputs)

        from GaudiPython.Bindings import AppMgr    
        gaudi = AppMgr()
        gaudi.initialize()
        gaudi.run(self.__nevt)
        gaudi.stop()
        gaudi.finalize()
        gaudi.exit()
Пример #6
0
def CreateLifetimeMapCode(config=None, bRetLists=False):
    global codePreamble, codeMakePair, codePostamble, outStream, analysisName, timestampFormat, dataType, dddbTag, bUseLatestCondDB
    if not config is None:
        dataType = config[0]  #year
        dddbTag = config[1]  #DDDB tag
    lbApp = LHCbApp()
    lbApp.DDDBtag = dddbTag
    DDDBConf(DataType=dataType)
    if bUseLatestCondDB:
        CondDB().UseLatestTags = [dataType]
    gaudi = AppMgr()
    gaudi.initialize()
    pps = gaudi.ppSvc()
    if len(pps.all()) == 0:
        eprint(
            "ERROR: No particles returned from Particle Property Service!\n",
            'err')
        return False
    pmap = {}
    pids = []
    for p in pps.all():
        #if p.name().startswith('anti-'):
        #    continue
        pid = p.pid().pid()
        if pid < 0 or pmap.has_key(pid):
            apid = ((pid < 0) and (-pid) or pid)
            if pmap.has_key(apid):
                nlft = "%.8E" % (p.lifetime() / SystemOfUnits.s)
                olft = "%.8E" % (pmap[apid])
                if nlft.startswith(olft):
                    continue
                else:
                    eprint(
                        "(anti-)/Particle lifetimes differ [%d] (%s vs. %s). Use asymmetric algorithm with PID:Lifetime map."
                        % (pid, nlft, olft), 'warn')
                    if pid > 0:
                        pmap[-pid] = pmap[pid]
                        del pmap[pid]
            else:
                pid = apid
        #if len(str(pid)) > 7: #????
        #    print ("Ignored " + str(p))
        #    continue
        if pid > 79 and pid < 101:
            eprint('Ignoring generator dependent PIDs in interval [80-100].')
            eprint(str(p))
            continue
        if len(str(pid)) > 9:  #ignore nuclei
            eprint("Ignoring nucleus " + str(p))
            continue
        lft = p.lifetime()
        if lft < 0.0:
            eprint("Negative lifetime! " + str(p), 'err')
            continue
        if pmap.has_key(pid):
            eprint("Duplicate particle in list with PID " + str(pid), 'warn')
            continue
        if lft < 1.0e-32:
            if not pid in pids:
                pids.append(pid)
            continue
        #express lifetime in seconds
        lft = lft / SystemOfUnits.s
        pmap[pid] = lft
    if not bRetLists:
        if not outStream is None:
            if os.path.isfile(outStream):
                eprint("File '%s' already exists." % (outStream))
                ans = raw_input('Do you really want to overwrite (yes/no)? ')
                if ans.lower() == 'no':
                    eprint('Aborting execution. Please, rename output file.',
                           'warn')
                    exit(9)
            fp = open(outStream, "w")
        else:
            fp = sys.stdout
        fp.write(codePreamble %
                 (dddbTag, dataType,
                  datetime.datetime.utcnow().strftime(timestampFormat)))
        fp.write("  ")
        sortedKeys = pmap.keys()
        sortedKeys.sort()
        k = 2
        for pdgid in sortedKeys:
            svdbl = "%.8E" % (pmap[pdgid])
            smant = svdbl[0:svdbl.rfind('E') - 1]
            sexp = svdbl[svdbl.rfind('E'):]
            smant = smant.rstrip('0')
            svdbl = (smant + sexp)
            spair = codeMakePair % (pdgid, svdbl)
            lts = len(spair)
            k += lts
            if k > 80:
                k = lts
                fp.write("\n  ")
            fp.write(spair)
        fp.write("\n  return true;\n}\n")
        fp.flush()
        if len(pids) > 0:
            pids.sort()
            fp.write(codePreamble2 % (len(pids), analysisName, len(pids)))
            k = 0
            jj = 0
            for jj in xrange(0, len(pids)):
                ii = pids[jj]
                #ignore partons and particle ids below 100
                if ii <= 100:
                    continue
                spid = "%u" % (ii)
                if jj < len(pids) - 1:
                    spid += ","
                k += len(spid)
                fp.write(spid)
                if k > 80:
                    fp.write("\n")
                    k = 0
            fp.write("};\n")
        if not outStream is None:
            fp.flush()
            fp.close()
    gaudi.finalize()
    gaudi.exit()
    del gaudi, lbApp
    return (pmap, pids)
AlignAlgorithm('Alignment').InputDataFiles = derivativefiles
AlignAlgorithm('Alignment').OutputDataFile = ''

# set the database layer
if opts.aligndb:
    counter = 1
    for db in opts.aligndb:
        from Configurables import (CondDB, CondDBAccessSvc)
        alignCond = CondDBAccessSvc('AlignCond' + str(counter))
        alignCond.ConnectionString = 'sqlite_file:' + db + '/LHCBCOND'
        CondDB().addLayer(alignCond)
        counter += 1
    print 'added databases: ', opts.aligndb

from GaudiPython.Bindings import AppMgr
appMgr = AppMgr()
# we want to reinitialize, but we don't want to initialize all
# the reco algorithms, so we add just the alignment sequence:
appMgr.setAlgorithms(['AlignAlgorithm/Alignment'])
appMgr.configure()
appMgr.initialize()
# update the geometry
# updatetool = appMgr.toolsvc().create( typ = "Al::AlignUpdateTool", name = "ToolSvc.AlignUpdateTool", interface = "IAlignUpdateTool" )
#updatetool = appMgr.toolsvc().create( "Al::AlignUpdateTool", interface = "Al::IAlignUpdateTool" )
#updatetool.process(  self.output['derivatives'].equations(), opts.iter, 1)
# now call finalize to write the conditions. there must be a better way.
appMgr.finalize()
# finally create a database layer
import os
os.system("copy_files_to_db.py -c sqlite_file:Alignment.db/LHCBCOND -s xml")