#Panoramix configuration script import sys,getopt,os,time #---Enable Tab completion----------------------------------------- try: import rlcompleter, readline readline.parse_and_bind( 'tab: complete' ) readline.parse_and_bind( 'set show-all-if-ambiguous On' ) except: pass #---------------------------------------------------------------------------------- def myPanoramix_usage() : print 'Usage:' print ' python myPanoramix.py [--outputlevel] [--DataType] [--Full_rec] [--Hlt] [--Phys] -u -f -x [-c] [-h] [--L0]' print ' or [-o] [-D] [-F] [-H] [-P] -u -f -x [-c] [-h]' #---------------------------------------------------------------------------------- def myPanoramix_help() : myPanoramix_usage() print 'Example cases:' print ' python myPanoramix.py : read default Dst' print ' python myPanoramix.py -D 2011 : use 2011 geometry' print ' python myPanoramix.py -D 2011L : use 2011 geometry and latest tags (default) ' print ' python myPanoramix.py -D MC2010 : use 2010 MC geometry ' print ' python myPanoramix.py -D -f myFile.dst : read myFile.dst ' print ' python myPanoramix.py -f myFile.raw : read raw data' print ' python myPanoramix.py -F -f myFile.dst : run full reconstruction on myFile.dst' print ' python myPanoramix.py --Cosmics -f myFile.raw : run reconstruction for cosmics on raw data' print ' python myPanoramix.py --SingleBeam : run reconstruction with field off / Velo open' print ' python myPanoramix.py --FirstCollisions : run reconstruction with field on / Velo open' print ' python myPanoramix.py --L0 -f myFile.dst : emulate L0sequence on myFile.dst' print ' python myPanoramix.py -F -H -f myFile.digi : run full reconstruction and Hlt on myFile.digi' print ' python myPanoramix.py -f none : no event file, only detector geometry' print ' python myPanoramix.py -c : overwrite default configuration with myPanoramixConfig.py' print ' python myPanoramix.py --BareConfig 1 : start with bare configuration for GUI only, read DST' print ' python myPanoramix.py -c anotherConfig : overwrite default configuration with anotherConfig.py' print ' python myPanoramix.py -u user.opts : use an user option file loaded last' print ' python myPanoramix.py --qt : use Qt for graphics, now default' print ' python myPanoramix.py --om : use OpenMotif for graphics' print ' python myPanoramix.py --Oracle : use the OracleDB rather than SQLDDDB' print '-----------------------------------------------------------------------------' print 'Example configuration file:' print ' (values will be overwritten by options specified on command line)' print 'Full_rec = False' print 'Hlt = True' print 'Dst = True' print 'Phys = False' print 'User_opts = ''' print 'User_file = \'$PANORAMIXDATA/Bs2JpsiPhi_MC09.dst\'' print 'xml_catalogue = ''' print '-----------------------------------------------------------------------------' print 'The last used configuration is stored in last_settings.py ' #---------------------------------------------------------------------------------- import os os.environ['PYTHONINSPECT'] = '1' config = {} config['Full_rec'] = False config['Hlt'] = False config['L0'] = False config['Phys'] = False config['User_opts'] = '' config['User_opts_first'] = '' config['User_file'] = [] config['xml_catalogue'] = '' config['User_config'] = '' config['outputlevel'] = '4' config['qt'] = True config['om'] = False config['Cosmics'] = False config['SingleBeam'] = False config['DC06'] = False config['DataType'] = '2011' config['FEST'] = False config['BareConfig'] = 0 config['Oracle'] = False config['latestTag'] = True config['simulation'] = False try: opts, args = getopt.getopt(sys.argv[1:], "o:D:FHPu:f:x:c:hqv:sl", ["outputlevel=","DataType=", "Fu/LHCb_data/00004827_00000033_1.dstll_rec", "Hlt", "Phys","User_opts=","User_file=", "xml_catalogue=","User_config=","help","qt","om","User_opts_first=","Cosmics","SingleBeam","FirstCollisions","2008","2009", "DC06","L0","FEST","tcmalloc","BareConfig=","Oracle"]) except getopt.GetoptError: # print help information and exit: myPanoramix_usage() print ' Try "myPanoramix.py -h" for more information.' sys.exit() for o, a in opts: if o in ("-c", "--User_config="): User_config = 'myPanoramixConfig.py' if a : User_config = a if User_config.find('.py') < 0 : User_config+='.py' config['User_config'] = User_config if o in ("-h", "--help"): myPanoramix_help() sys.exit() if config['User_config'] : # get configuration from a user file f=file(config['User_config']) all = f.readlines() f.close() for l in all : sl = l.split('=') if len(sl) > 1 : key = sl[0].split(' ')[0] value = sl[1].replace('\n','') value = value.replace(' ','') value = value.replace("'","") if value == 'False' : value = False if value == 'True' : value = True try : x = config[key] except : print 'myPanoramix config: key unknown',key,value sys.exit() config[key] = value for o, a in opts: if o in ("-o", "--outputlevel"): # set Output Level: 2=DEBUG, 3=INFO, 4=WARNING, 5=ERROR, 6=FATAL xx = 4 if type(a) == type('a'): if a.lower()=='debug' : xx = 2 if a.lower()=='info' : xx = 3 if a.lower()=='warning' : xx = 4 if a.lower()=='error' : xx = 5 elif type(a) == type(1) : xx = int(a) config['outputlevel'] = xx if o in ("-u", "--User_opts="): config['User_opts'] = a if o in ("--BareConfig="): config['BareConfig'] = int(a) if o in ("-v", "--User_opts_first="): config['User_opts_first'] = a if o in ("-f", "--User_file="): if a.find(',') : tmp = a.split(',') else : tmp = [a] for y in tmp: x = y.replace(' ','') if x.find('PFN')==-1 and x.lower() != 'none' and x.find('.raw')==-1 and x.lower()!='online': config['User_file'].append('PFN:'+x) else : config['User_file'].append(a) if o in ("-D", "--DataType"): print 'D ',a if a.find('L')>-1: config['latestTag'] = True else: config['latestTag'] = False if a.find('MC')>-1: config['simulation'] = True ab = a.replace('MC','') config['DataType'] = ab.replace('L','') if o in ("-F", "--Full_rec"): config['Full_rec'] = True if o in ("-H", "--Hlt"): config['Hlt'] = True if o in ("--L0"): config['L0'] = True if o in ("--Cosmics"): config['Cosmics'] = True config['DataType'] = '2009' if o in ("--SingleBeam","--FirstCollisions"): if o.find('First')==-1 : config['SingleBeam'] = True else : config['FirstCollisions'] = True config['DataType'] = '2009' config['Full_rec'] = True if o in ("--2008"): config['DataType'] = '2008' if o in ("--2009"): config['DataType'] = '2009' if o in ("--DC06"): config['DC06'] = True if o in ("-P", "--Phys"): if a == '': config['Phys'] = True else : config['Phys'] = False if o in ("-x", "--xml_catalogue="): config['xml_catalogue'] = a if o in ("-q", "--qt"): config['qt'] = True if o == "--om": config['om'] = True config['qt'] = False if o == "--FEST" : config['FEST'] = True if o == "--Oracle" : config['Oracle'] = True # do something with ROOT first # this is a very nasty hack to be able to use Qt if config['qt']: os.putenv('ROOTENV_NO_HOME','1') try: tmp = open('.rootrc','r') text = tmp.readlines() found = False for line in text: zline = line.replace(' ','') if zline.find("X11.XInitThread:no")>-1 : found = True break if not found : print 'Error: Using Qt requires to have "X11.XInitThread: no" in your .rootrc file' print ' otherwise problem with multihreading, ROOT, GAUDI, Qt' print 'Error: Panoramix does not know how to continue. Stop here' exit() except IOError: tmp = open('.rootrc','w') tmp.write("X11.XInitThread: no \n") tmp.close() from ROOT import TBrowser os.system('rm .rootrc') a = time.time() aa = time.clock() from ROOT import TH1F, TBrowser import LHCbMath.Types LHCbMath = LHCbMath.Types.Gaudi # start Panoramix configurable from Gaudi.Configuration import * from Configurables import LHCbApp,CondDB if config['Oracle']: CondDB(UseOracle = True) DDDBtag = "velopix-mul-20100909" CondDBtag = "sim-20100510-vc-md100" lhcbApp = LHCbApp() # use default tag == latest tag # for simulation, tag should be the same as used in Gauss lhcbApp.DDDBtag = DDDBtag lhcbApp.CondDBtag = CondDBtag realdata = config['FEST'] or config['Cosmics'] or ( config['DataType'].find('MC')<0 and config['DataType']!='DC06') if config['DataType'] != 'DC06' : config['DC06'] = False lhcbApp.DataType = config['DataType'] if not realdata and config['DataType']!='DC06' : lhcbApp.Simulation = True else : lhcbApp.Simulation = False for f in config['User_file']: if f.lower().find('online') > -1 : lhcbApp.Simulation = False lhcbApp.DataType = '2011' # now import user opts first if len(config['User_opts_first'])>0 : if type(config['User_opts_first']) == type([]) : for o in config['User_opts_first'] : importOptions(o) else : importOptions(config['User_opts_first']) from PanoramixSys.Configuration import * # configure the logging if config['outputlevel'] < 4 : import logging from GaudiKernel.ProcessJobOptions import InstallRootLoggingHandler level = logging.INFO if config['outputlevel'] < 3 : level = logging.DEBUG InstallRootLoggingHandler("# ", level = level) root_logger = logging.getLogger() #translate config to configuration slots for c in config: PanoramixSys().setProp(c,config[c]) if c == 'Cosmics' : if config[c] : PanoramixSys().setProp('Cosmics',True) if config['outputlevel'] < 4 : print 'conf copy: ',c,':',PanoramixSys().getProp(c) for f in config['User_file'] : if f.lower().find('.sim') > -1 : PanoramixSys().setProp('Sim',True) if realdata: PanoramixSys().setProp("withMC",False) else: PanoramixSys().setProp("withMC",True) #--Geometry dependent options, use information from SIMCOND for positions privatedb_path = "$HOME/VELOPIX/dddb-velopix-mul-20100909/" from Configurables import DDDBConf DDDBConf(DbRoot = privatedb_path + "lhcb.xml") # now import user opts def user_changes(): if len(config['User_opts'])>0 : if type(config['User_opts']) == type([]) : for o in config['User_opts'] : importOptions(o) else : importOptions(config['User_opts']) appConf = ApplicationMgr(OutputLevel = int(config['outputlevel']), AppName = 'Panoramix') # for rDSTs rDST = False from Configurables import L0DUFromRawAlg,L0DUFromRawTool,HltDecReportsDecoder,ANNDispatchSvc for f in config['User_file'] : if f.lower().find('.rdst') > -1 : rDST = True if rDST : l0alg = L0DUFromRawAlg('L0DUFromRaw') l0alg.addTool(L0DUFromRawTool('L0DUFromRawTool')) l0alg.L0DUFromRawTool.RawLocation = 'pRec/RawEvent' HltDecReportsDecoder().InputRawEventLocation = "pRec/RawEvent" ANNDispatchSvc().RawEventLocation = "pRec/RawEvent" # fix Hlt interference from Configurables import ( DataOnDemandSvc,RawBankToSTClusterAlg, RawBankToSTLiteClusterAlg,TrackSys ) # instrument decoding of Hlt if config['BareConfig'] != 1 and not config['Hlt'] : from Configurables import HltDecReportsDecoder,HltSelReportsDecoder,HltVertexReportsDecoder DataOnDemandSvc().AlgMap["Hlt/DecReports"] = HltDecReportsDecoder( OutputLevel = 4) DataOnDemandSvc().AlgMap["Hlt/SelReports"] = HltSelReportsDecoder( OutputLevel = 4) DataOnDemandSvc().AlgMap["Hlt/VertexReports"] = HltVertexReportsDecoder( OutputLevel = 4) def doTAEChanges(): RawBankToSTClusterAlg("CreateITClusters").rawEventLocation = 'Next1/DAQ/RawEvent' RawBankToSTLiteClusterAlg("CreateITLiteClusters").rawEventLocation = 'Next1/DAQ/RawEvent' RawBankToSTClusterAlg("CreateTTClusters").rawEventLocation = 'Prev1/DAQ/RawEvent' RawBankToSTLiteClusterAlg("CreateTTLiteClusters").rawEventLocation = 'Prev1/DAQ/RawEvent' def removeLoKiMessage(): from Configurables import LoKiSvc LoKiSvc().Welcome = False def doMyChanges(): DataOnDemandSvc().AlgMap["Raw/Velo/LiteClusters"] = "DecodeVeloRawBuffer/createVeloLiteClusters" DataOnDemandSvc().AlgMap["Raw/TT/LiteClusters"] = "RawBankToSTLiteClusterAlg/createTTLiteClusters" DataOnDemandSvc().AlgMap["Raw/IT/LiteClusters"] = "RawBankToSTLiteClusterAlg/createITLiteClusters" DataOnDemandSvc().AlgMap["Raw/OT/Times"] = "OTTimeCreator" DataOnDemandSvc().AlgMap["DAQ/ODIN"] = "createODIN" RawBankToSTLiteClusterAlg("createITLiteClusters").DetType = "IT" DataOnDemandSvc().AlgMap["Raw/Spd/Digits"] = "CaloDigitsFromRaw/SpdFromRaw" DataOnDemandSvc().AlgMap["Raw/Prs/Digits"] = "CaloDigitsFromRaw/PrsFromRaw" DataOnDemandSvc().AlgMap["Raw/Ecal/Digits"] = "CaloZSupAlg/EcalZSup" DataOnDemandSvc().AlgMap["Raw/Hcal/Digits"] = "CaloZSupAlg/HcalZSup" DataOnDemandSvc().AlgMap["Trig/L0/FullCalo"] = "L0CaloCandidatesFromRaw/L0CaloFromRaw" DataOnDemandSvc().AlgMap["Trig/L0/Calo"] = "L0CaloCandidatesFromRaw/L0CaloFromRaw" # some problems with this one: DataOnDemandSvc().AlgMap["Trig/L0/MuonCtrl"] = "L0MuonCandidatesFromRaw/L0MuonFromRaw" DataOnDemandSvc().AlgMap["Trig/L0/L0DUReport"] = "L0DUFromRawAlg" if config['Hlt'] : appendPostConfigAction(doMyChanges) if config['BareConfig'] != 1 : appendPostConfigAction(removeLoKiMessage) if len(config['User_opts'])>0 : appendPostConfigAction(user_changes) # if config['SingleBeam'] : appendPostConfigAction(doTAEChanges) # Use TimingAuditor for timing, suppress printout from SequencerTimerTool from Configurables import (AuditorSvc,SequencerTimerTool) appConf.ExtSvc += [ 'ToolSvc', 'AuditorSvc' ] appConf.AuditAlgorithms = True AuditorSvc().Auditors += [ 'TimingAuditor' ] SequencerTimerTool().OutputLevel = INFO import GaudiPython # now get ROOT stuff, if done before, it screws up the getopts # from ROOT import TCanvas,TH1F,TH2F,TBrowser,gROOT, gSystem appMgr = GaudiPython.AppMgr() appMgr.initialize() from panoramixmodule import * ufile = PanoramixSys().getProp('User_file') mdf = PanoramixSys().getProp('Mdf') online = PanoramixSys().getProp('Online') if len(ufile) > 0 : if ufile[0].lower() != 'none' and ufile[0].lower() != 'default'and not mdf and not online : sel.open(ufile) appMgr.start() # stop decoding of Calo, wait for ondemand: appMgr.algorithm("DigiSeq").Enable = False # don't strip off states by default appMgr.algorithm("OutputDSTSeq").Enable = False appMgr.algorithm("PanoDstWriter").Enable = False appMgr.algorithm("PanoEventSequence").Enable = False appMgr.algorithm("Pano_HltTrackConverter").Enable = False if not config['Full_rec'] : # disable reconstruction sequence by default appMgr.algorithm("PanoRecoSequencer").Enable = False try: rc = appMgr.algorithms().index('CleanUpSequence') appMgr.algorithm("CleanUpSequence").Enable = False except: rc = -1 if not config['Phys'] : appMgr.algorithm("PhysSeq").Enable = False # Panoramix will probably never run with files on the GRID # disabling avoids error message about not able to load GFale appMgr.service('IODataManager').UseGFAL = False # at exit enable all algorithms for proper finalize def _my_Action_() : from GaudiPython.Bindings import AppMgr appMgr = AppMgr() for a in appMgr.algorithms() : appMgr.algorithm(a).Enable = True appMgr.exit() import atexit if not config['Full_rec'] : atexit.register ( _my_Action_ ) # try to load dictionary for FSR GaudiPython.loaddict('LumiEvent') #print some information about the session configuration : if config['User_opts'] =='' : config['User_opts'] = 'None' print '--> Your settings: DataType =',config['DataType'],'| Full reconstruction =', config['Full_rec'],'| Hlt =',config['Hlt'],'| Phys =',config['Phys'],'| User options =',config['User_opts'] print '--> ','| DC06 =', config['DC06'] # get input files: flist = sel.properties()['Input'].value() txt = [] if len(flist) > 0 : if len(flist)==1 : txt.append('--> input file: ') else : txt.append('--> input files: ') for f in flist : print '%s'%(f) if config['User_opts'] =='None' : config['User_opts'] = '' #store last configuration f=file('last_settings.py','w') for i in config : if type(config[i]) == type(True) : if config[i] : f.write(i + '=' + 'True'+'\n') if not config[i] : f.write(i + '=' + 'False'+'\n') elif type(config[i]) == type([]) : first = True for k in config[i] : if first : first = False f.write(i + '=' + k+'\n') else : f.write(',' + k+'\n') else: if type(config[i]) != type('s') : f.write(i + '=' + str(config[i])+'\n') else : f.write(i + '=' + config[i]+'\n') f.close() from Configurables import OnXSvc if OnXSvc().File.find('Online')!=-1 : from OnlineSetup import * b = time.time() bb = time.clock() print 'lost time in initialization',b-a,bb-aa # Give control to the GUI : toui()