def init(self): self.a4 = OutputStream(open(self.file_name, "w"), "AOD2A4", Event, EventStreamInfo) import PyCintex PyCintex.loadDict("egammaAnalysisTools") self.tool_ciwt = PyAthena.py_tool("CaloIsolationWrapperTool", iface="ICaloIsolationWrapperTool") assert bool(self.tool_ciwt) PyCintex.loadDictionary("TrigMuonEvent") PyCintex.loadDictionary("TrigObjectMatching") self.tmefih = PyCintex.makeClass("TrigMatch::TrigMuonEFInfoHelper") from ROOT import vector PyCintex.loadDictionary("JetUtils") from ROOT import JetCaloHelper, JetCaloQualityUtils, Long, CaloSampling self.jet_emf = lambda jet : JetCaloHelper.jetEMFraction(jet) self.jet_hecF = lambda jet : JetCaloQualityUtils.hecF(jet) ### smax needed for jet cealning #### FIX THIS: don't know either getNumberOfSamplings() or Unknown #### UPDATE: getNumberOfSamplings just returns Unknown! self.jet_smax = Long(CaloSampling.getNumberOfSamplings()) self.jet_fmax = lambda jet : JetCaloQualityUtils.fracSamplingMax(jet, Long(CaloSampling.Unknown)) self.jet_time = lambda jet : JetCaloQualityUtils.jetTimeCells(jet) self.jet_quality_lar = lambda jet : JetCaloQualityUtils.jetQualityLAr(jet) self.jet_quality_hec = lambda jet : JetCaloQualityUtils.jetQualityHEC(jet) self.jet_bad = lambda jet : JetCaloQualityUtils.isBad(jet, False) self.jet_ugly = lambda jet : JetCaloQualityUtils.isUgly(jet, False) PyCintex.loadDictionary("egammaEnumsDict") PyCintex.loadDictionary("muonEventDict") PyCintex.loadDictionary("egammaAnalysisUtils") PyCintex.loadDictionary("MissingETEvent") from ROOT import MuonParameters, egammaParameters, egammaPID from ROOT import ElectronMCChargeCorrector self.MuonParameters = MuonParameters self.egammaParameters = egammaParameters self.egammaPID = egammaPID self.empp_helper = PyCintex.makeClass("isEMPlusPlusHelper")() if self.year == 2010: gROOT.ProcessLine(".L checkOQ.C++") from ROOT import egammaOQ self.egOQ = egammaOQ() self.egOQ.initialize() self.tool_ttv = PyAthena.py_tool("Reco::TrackToVertex", iface="Reco::ITrackToVertex") self.tool_tdt = PyAthena.py_tool('Trig::TrigDecisionTool/TrigDecisionTool') self.tool_tmt = PyAthena.py_tool("TrigMatchTool/TrigMatchTool") self.tool_hfor= PyAthena.py_tool("HforTool",iface="IHforTool") self.tool_timing = PyAthena.py_tool("Rec::MuonCombinedTimingTool/MuonCombinedTimingTool", iface="Rec::IMuonCombinedTimingTool") PyCintex.loadDictionary("TrkSpaceTimePoint")
def __init__(self, poolfile, **args): """An AOD file pointer (not a string) must be given as argument""" self.__dict__.__setitem__("_TriggerConfigARA__curConf", _TrigConfHolder()) self.__currentIOV = {} self.verbose = False if 'verbose' in args: self.verbose = args['verbose'] plcClass = PyCintex.makeClass("IOVPayloadContainer") plcClass.iter = _iter tiClass = PyCintex.makeClass("TrigConf::TriggerItem") tiClass.__str__ = lambda x: "%s (ctpid %i), ps %g" % (x.name(), x.ctpId(), x.ps) chClass = PyCintex.makeClass("TrigConf::HLTChain") chClass.__str__ = _chPrint ROOT.IOVTime.__str__ = lambda x: "%i/%i" % (x.run(),x.event()) ROOT.IOVTime.__lt__ = lambda s,o: s.run()<o.run() or s.run()==o.run() and s.event()<o.event() ROOT.IOVTime.__eq__ = lambda s,o: s.run()==o.run() and s.event()==o.event() ROOT.IOVTime.__le__ = lambda s,o: s<o or s==o ROOT.IOVRange.__str__ = lambda x: "%s - %s" % (x.start(),x.stop()) ROOT.IOVRange.isInRange = lambda x,e: x.start()<=e and e<x.stop() print "Opening file(s) and creating transient metadata ..." if type(poolfile) == list: self._collection = ROOT.AthenaROOTAccess.TChainROOTAccess('MetaData') for file in poolfile: self._collection.Add(file) self.mdt = AthenaROOTAccess.transientTree.makeTree(self._collection, persTreeName = 'MetaData', dhTreeName = 'MetaDataHdr', dhfilt = _elemFilter ) else: treeNames = [k.GetName() for k in poolfile.GetListOfKeys()] if "MetaDataHdrDataHeader" in treeNames: dhTreeName = 'MetaDataHdrDataHeader' # old style else: dhTreeName = 'MetaDataHdr' self.mdt = AthenaROOTAccess.transientTree.makeTree(poolfile, persTreeName = 'MetaData', dhTreeName = dhTreeName, dhfilt = _elemFilter ) for key in self.__class__.__keysInUpdateOrder: if not hasattr(self.mdt,self.__class__.__folderName[key]): print "No key %s in file %s, use checkFile.py to verify" % (self.__class__.__folderName[key],poolfile) sys.exit(0)
def BadChan_GetCoolChannelNameFromHWIdentifier(self, sHWid): """ Get channel name from HW identifier (only for text menu purpose)""" self.class_LArBadChannelState = PyCintex.makeClass( 'LArBadChannelState') inst_larBadChannelState = self.class_LArBadChannelState() sChannelName = "" if self.onlineID.isEMBchannel(sHWid): if self.onlineID.pos_neg(sHWid) == 1: iEnumChannel = inst_larBadChannelState.EMBA else: iEnumChannel = inst_larBadChannelState.EMBC if self.onlineID.isEMECchannel(sHWid): if self.onlineID.pos_neg(sHWid) == 1: iEnumChannel = inst_larBadChannelState.EMECA else: iEnumChannel = inst_larBadChannelState.EMECC if self.onlineID.isHECchannel(sHWid): if self.onlineID.pos_neg(sHWid) == 1: iEnumChannel = inst_larBadChannelState.HECA else: iEnumChannel = inst_larBadChannelState.HECC if self.onlineID.isFCALchannel(sHWid): if self.onlineID.pos_neg(sHWid) == 1: iEnumChannel = inst_larBadChannelState.FCALA else: iEnumChannel = inst_larBadChannelState.FCALC sChannelName = inst_larBadChannelState.coolChannelName( iEnumChannel) + " (" + str(iEnumChannel) + ")" return sChannelName
def getMultiCondContainer(self, channels, attrListColl, iovs) : # Args: # channels - list of channels from COOL # attrListColl - collection of AttributeLists with string address from COOL for each channel # iovs - list of IOVs for each channel # cont - the LArConditionsContainer object # Print out channels and IOV print "Channels, IOV, and string addresses" i = 0 for chan in channels : iov = iovs[i] print "added chan/iov: ", chan, iov.iovPrint() i += 1 # print out collection #attrListColl.dump() # Must set dummy string address to include type name for # AthenaPoolCnvSvc statistics gathering strAddress = self.header # Get IOpaqueAddress print "Create IOpaqueAddress pointer" ioa = PyLCGDict.libPyROOT.MakeNullPointer('GenericAddress') # Get DataBucketBase pointer print "Create DataBucketBase pointer" dbb = PyLCGDict.libPyROOT.MakeNullPointer('DataBucketBase') # Create IOA from string address print "Create IOpaqueAddress for address list" sc = self.iaddr.createAddress( 0, 0, strAddress, ioa ) print "Status code: ", sc # Create CondAttrListCollAddress and add in attribute list CondAttrListCollAddress = PyLCGDict.makeClass('CondAttrListCollAddress') collAddr = CondAttrListCollAddress(ioa) collAddr.setAttrListColl(attrListColl) # Read in object as DataObject (or DatabucketBase) print "Retrieve data object for IOA" sc = self.icnv.createObj(collAddr, dbb) print "Status code: ", sc if sc.isFailure(): raise RuntimeError("Cannot read object") # Cast to correct type and return it print "cast data object to correct type: ",self.typeName result = PyLCGDict.libPyROOT.MakeNullPointer(self.type) self.dbCast.castObject(self.typeName, dbb, result) # Reset iterator to allow a new type - bug in pyroot #self.pyroot_typedef_bug_workaround() return result
def _loadCintexDict(): """Simple wrapper around the loading of dictionary class for the Chain class. """ import PyCintex PyCintex.Cintex.Enable() ## klass = PyCintex.makeClass("HLT::Chain") return klass
def setDescription(self, descr) : self.descr = descr # extract type name and type decoder = DescriptionDecoder(descr) self.typeName = decoder.extract('<typeName>','</typeName>') self.type = PyLCGDict.makeClass(self.typeName) # extract the address header self.header = decoder.extract('<addrHeader>','</addrHeader>') self.header += 'POOLContainer_CondAttrListCollection][CLID=x' print "Type name, type, header ",self.typeName,self.type,self.header
def __init__(self, theApp) : # PersistencySvc pers = theApp.service('EventPersistencySvc') # PersistencySvc via its IConverter interface iConverter = InterfaceRDS('IConverter') self.icnv = iConverter.cast(pers) # PersistencySvc via its IAddressCreator interface iAddrCreator = InterfaceRDS('IAddressCreator') self.iaddr = iAddrCreator.cast(pers) # Create instance of cast object self.dbCast = PyLCGDict.makeClass('DataBucketCast')
def __init__(self, t): # t is either the class name or the class itself if type(t) is str: self.typeName = t t = PyLCGDict.makeClass(t) else: self.typeName = t.type.__name__ # Save type self.type = t # Add on iterators for the different containers self.type.conditionsIter = conditionsIter self.type.correctionsIter = correctionsIter self.type.coolChannelIter = coolChannelIter self.type.coolIOVIter = coolIOVIter
def BadChan_SaveBadChannelCorrectionsToDatabase(self, dbstring, dbSvc, dbFolderName, selectedTag): listKeys = self.dict_vectBadChanEntry.keys() listKeys.sort() # Create LArBadChannel object for defined BadChanEntry vector and coolChan self.class_LArBadChannelState = PyCintex.makeClass( 'LArBadChannelState') inst_larBadChannelState = self.class_LArBadChannelState() # Loop over cool channels bStoreNewCoolChannels = False bNewDBCreated = False for coolChan in listKeys: vect_BadChanEntry = PyCintex.gbl.std.vector( 'std::pair<HWIdentifier,LArBadChannel>')() listHWidKeys = [ x for x in self.dict_vectBadChanEntry[coolChan].keys() ] listHWidKeys.sort() iNbCorrection = 0 for key in listHWidKeys: sHWid = key if self.dict_vectBadChanEntry_Status[coolChan][ sHWid] == STATUS_INIT: badChan_word = self.dict_vectBadChanEntry_Init[coolChan][ sHWid][1] elif self.dict_vectBadChanEntry_Status[coolChan][ sHWid] == STATUS_MODIFIED or self.dict_vectBadChanEntry_Status[ coolChan][sHWid] == STATUS_NEW: iNbCorrection += 1 badChan_word = self.dict_vectBadChanEntry[coolChan][sHWid][ 1] elif self.dict_vectBadChanEntry_Status[coolChan][ sHWid] == STATUS_REMOVED: iNbCorrection += 1 continue obj_HWid = self.class_HWIdentifier() obj_HWid.set(sHWid) larBadChannel = self.class_LArBadChannel(badChan_word) pair_BadChanEntry = PyCintex.gbl.pair( 'HWIdentifier,LArBadChannel')(obj_HWid, larBadChannel) vect_BadChanEntry.push_back(pair_BadChanEntry) # if correction were made => store BadChanEntry vector if iNbCorrection > 0: for sEntry in vect_BadChanEntry: inst_larBadChannelState.add(sEntry, coolChan) bStoreNewCoolChannels = True else: continue # Create object based on new LArBadChannelState (via LArBadChannelDBTools python interface) attrListSpec = PyCintex.gbl.coral.AttributeListSpecification() athenaAttrList = PyCintex.gbl.AthenaAttributeList() attrListSpec = self.nspace_LArBadChannelDBTools.createCoolSpec() athenaAttrList = self.nspace_LArBadChannelDBTools.createPayload( inst_larBadChannelState.coolChannel(coolChan), attrListSpec) # if save DB has not been created => do it if bNewDBCreated == False: import os try: dbSave = dbSvc.createDatabase(dbstring) except Exception, e: print 'Problem opening database', e sys.exit(-1) print "Opened database", dbstring desc = '<timeStamp>run-event</timeStamp><addrHeader><address_header service_type="71" clid="40774348" /></addrHeader><typeName>AthenaAttributeList</typeName>' # Create cool spec from AttributeListSpec coolSpec = cool.RecordSpecification() for iElemt in range(0, attrListSpec.size()): attrSpec = attrListSpec[iElemt] typeName = attrSpec.typeName() if typeName == "unsigned int": coolSpec.extend(attrSpec.name(), cool.StorageType.UInt32) elif typeName == "blob": coolSpec.extend(attrSpec.name(), cool.StorageType.Blob64k) else: print "Undefined cool.StorageType " + typeName # myfolder=dbSave.createFolder(dbFolderName, coolSpec, desc, cool.FolderVersioning.SINGLE_VERSION,True) myfolder = dbSave.createFolder( dbFolderName, coolSpec, desc, cool.FolderVersioning.MULTI_VERSION, True) import string IOVBeginEnd = ["90", "9999999"] beginRun = string.atoi(IOVBeginEnd[0]) << 32 endRun = string.atoi(IOVBeginEnd[1]) << 32 bNewDBCreated = True # Create cool payload from AthenaAttributeList payload coolPayload = cool.Record(coolSpec) for iElemt in range(0, attrListSpec.size()): attrSpec = attrListSpec[iElemt] coolPayload[attrSpec.name()] = athenaAttrList[attrSpec.name()] # Store cool object to folder myfolder.storeObject(beginRun, endRun, coolPayload, coolChan, selectedTag)
from AthenaCommon.Logging import logging mlog = logging.getLogger( 'TrigConfigCheckInPool.py' ) ## get the logger mlog.level=1 MetaDataTree = ROOT.AthenaROOTAccess.TChainROOTAccess('MetaData') def _iter(self) : sequential = self.begin() end = self.end() while sequential != end : yield sequential.__deref__() sequential.__preinc__() raise StopIteration _plcClass = PyCintex.makeClass("IOVPayloadContainer") _plcClass.iter = _iter ROOT.IOVTime.__str__ = lambda x: "%i/%i" % (x.run(),x.event()) ROOT.IOVRange.__str__ = lambda x: "%s - %s" % (x.start(),x.stop()) def checkPoolFileForRunLevel(poolfilename): folderName = { "L1M" : "_TRIGGER_LVL1_Menu", "HLTM" : "_TRIGGER_HLT_Menu", "L1K" : "_TRIGGER_LVL1_Lvl1ConfigKey", "HLTK" : "_TRIGGER_HLT_HltConfigKeys", "L1PS" : "_TRIGGER_LVL1_Prescales" } MetaDataTree.Add(poolfilename+'/MetaData')
def __init__(self, t ) : if type(t) is str : t = PyLCGDict.makeClass(t) # print "type is string: ",t # t = PyLCGDict.makeClass(t) #t = PyLCGDict.makeClass(t) self.type = t
def test25STLIterator(self): vector = PyCintex.makeClass('std::vector<MyA>') self.failUnless(vector) self.failUnless(PyCintex.makeClass('std::vector<MyA>::iterator')) self.failUnless( PyCintex.makeClass('std::vector<MyA>::reverse_iterator'))
def setUp(self): PyCintex.makeClass('A::B::C::MyClass' ) # This is needed to force loading the dictionary self.A = PyCintex.makeNamespace('A') self.std = PyCintex.makeNamespace('std') self.gbl = PyCintex.makeNamespace('')
#=== folder tag suffix tagCon = "LARTimeCorrectionOflNonRunCon-00" tagRun = "LARTimeCorrectionOflRunCon-00" #=== values for the comment channel author = "dhu" comment = "Updated time constant values" #================================================== #=== #=== Code starts below here #=== #================================================== #=== set shortcut g = PyCintex.gbl PyCintex.makeClass('std::vector<float>') #=== get a logger log = CaloCondLogger.getLogger("CaloTimeConsWriter") #=== (re-)create the database db = CaloCondTools.openDb('SQLITE', 'COMP200', 'UPDATE') try: #=== creating folder specifications spec = cool.RecordSpecification() spec.extend('CaloCondBlob16M', cool.StorageType.Blob16M) #=== create the folder folderPath = CaloCondTools.getCaloPrefix( ) + "LAR/TimeCorrectionOfl/NonRunCon"
def test25STLIterator(self): vector = PyCintex.makeClass('std::vector<MyA>') self.failUnless( vector ) self.failUnless( PyCintex.makeClass('std::vector<MyA>::iterator') ) self.failUnless( PyCintex.makeClass('std::vector<MyA>::reverse_iterator') )
def setUp(self): PyCintex.makeClass('A::B::C::MyClass') # This is needed to force loading the dictionary self.A = PyCintex.makeNamespace('A') self.std = PyCintex.makeNamespace('std') self.gbl = PyCintex.makeNamespace('')