Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 12:52:33

0001 '''
0002 Update the config-to-payload map table for the fast DAQ O2O.
0003 
0004 @author: hqu
0005 '''
0006 
0007 from CondTools.SiStrip.o2o_db_manager import make_dbtype, DbManager
0008 import os
0009 import logging
0010 import sqlalchemy
0011 
0012 
0013 class ConfigToPayloadMapDef(object):
0014     __tablename__ = 'STRIP_CONFIG_TO_PAYLOAD_MAP'
0015     config_hash = sqlalchemy.Column(sqlalchemy.String(2000), primary_key=True)
0016     payload_hash = sqlalchemy.Column(sqlalchemy.String(2000), nullable=False)
0017     payload_type = sqlalchemy.Column(sqlalchemy.String(2000), nullable=False)
0018     config_string = sqlalchemy.Column(sqlalchemy.String(2000), nullable=False)
0019     insertion_time = sqlalchemy.Column(sqlalchemy.TIMESTAMP, nullable=False)
0020 
0021 
0022 class DbManagerDAQ(DbManager):
0023     def __init__(self, db, authPath=None):
0024         DbManager.__init__(self, db, authPath)
0025         self.ConfigToPayloadMap = make_dbtype(ConfigToPayloadMapDef, self.schema)
0026         if self.schema:
0027             self.ConfigToPayloadMapSqlite = make_dbtype(ConfigToPayloadMapDef, schema=None)
0028         else:
0029             self.ConfigToPayloadMapSqlite = self.ConfigToPayloadMap
0030 
0031     def update_hashmap(self, input_path):
0032         if not os.path.exists(input_path):
0033             logging.info('No config-to-payload map file at %s. Skipping.' % input_path)
0034             return
0035         session = self.connect('sqlite:///%s' % input_path)
0036         entry = session.query(self.ConfigToPayloadMapSqlite).first()
0037         if entry:
0038             self.check_table(ConfigToPayloadMapDef, self.ConfigToPayloadMap)
0039             destSession = self.connect()
0040             cfgmap = self.ConfigToPayloadMap(config_hash=entry.config_hash,
0041                                              payload_hash=entry.payload_hash,
0042                                              payload_type=entry.payload_type,
0043                                              config_string=entry.config_string,
0044                                              insertion_time=entry.insertion_time)
0045             destSession.add(cfgmap)
0046             destSession.commit()
0047             logging.info('Updated config-to-payload map for %s' % cfgmap.payload_type)
0048             logging.info('... config_hash = %s, payload_hash = %s' % (cfgmap.config_hash, cfgmap.payload_hash))
0049         else:
0050             raise RuntimeError('No entry found in config-to-payload map file %s' % input_path)