def MONGODB_TEST_SETUP(self): self.conn, collection = utils.conn(host=masarconfig.get('mongodb', 'host'), port=masarconfig.get('mongodb', 'port'), db=masarconfig.get('mongodb', 'database')) self.conn.drop_database(masarconfig.get('mongodb', 'database')) name = "SR_All_20140421" params = {"desc": "SR daily SCR setpoint without IS kick and septum: SR and RF", "system": "SR", "status": "active", "version": 20140421, } newid = saveconfig(self.conn, collection, name, **params) # res0 = retrieveconfig(self.conn, collection, name) pvs = ["masarExample0000", "masarExample0001", # "masarExampleBoUninit", "masarExampleMbboUninit", "masarExample0002", "masarExample0003", "masarExample0004", "masarExampleCharArray", "masarExampleShortArray", "masarExampleLongArray", "masarExampleStringArray", "masarExampleFloatArray", "masarExampleDoubleArray", "masarExampleMbboUninitTest"] # TODO: Save will fail if list contains only 1 PV updateconfig(self.conn, collection, name, pvlist={"names": pvs}) # res3 = retrieveconfig(self.conn, collection, name, withpvs=True) return self.conn
def saveMongoService(json): conn, collection = utils.conn(host=masarconfig.get('mongodb', 'host'), port=masarconfig.get('mongodb', 'port'), db=masarconfig.get('mongodb', 'database')) for conf in json['configs']: params = {"desc": conf['config_desc'], "system": conf['system'], "status": "active"} try: saveconfig(conn, collection, conf['config_name'], **params) except: # TODO: This should be more specific print ("configuration name (%s) exists already." % (conf['config_name'])) pvgroups = {} # {"pvgname":["pv1","pv2"]} for pvgroup in json['pvgroups']: pvlist = [] pv_file = pvgroup['pvlist'] if os.path.exists(pv_file): with open(pv_file) as file: for line in file: pvlist.append(line.strip()) pvgroups[pvgroup['name']] = pvlist for conf in json['pvg2config']: pvs = [] for pvgroup in conf['pvgroups']: pvs = pvs + pvgroups[pvgroup] updateconfig(conn, collection, conf['config_name'], pvlist={"names": pvs})
def mongoSetUp(): # DB SETUP conn, collection = utils.conn(host=masarconfig.get('mongodb', 'host'), port=masarconfig.get('mongodb', 'port'), db=masarconfig.get('mongodb', 'database')) conn.drop_database(masarconfig.get('mongodb', 'database')) name = "SR_All_20140421" params = { "desc": "SR daily SCR setpoint without IS kick and septum: SR and RF", "system": "SR", "status": "active", "version": 20140421, } newid = saveconfig(conn, collection, name, **params) # res0 = retrieveconfig(self.conn, collection, name) pvs = [ "masarExample0000", "masarExample0001", # "masarExampleBoUninit", "masarExampleMbboUninit", "masarExample0002", "masarExample0003", "masarExample0004", "masarExampleCharArray", "masarExampleShortArray", "masarExampleLongArray", "masarExampleStringArray", "masarExampleFloatArray", "masarExampleDoubleArray", "masarExampleMbboUninitTest" ] # TODO: Save will fail if list contains only 1 PV updateconfig(conn, collection, name, pvlist={"names": pvs})
def retrieveChannelNames(self, params): """Retrieve PV name list of given configuration(s). :param params: a dictionary to carry query condition with structure like: :: {"configname": , # configuration name, wildcast allowed with * for multiple characters matching } :returns: list of pv name like: :: [pv1, pv2, ...] :raises: ValueError """ key = ['configname', "comment"] config, _ = self._parseParams(params, key) if config is not None: mongoconn, collection = utils.conn(host=os.environ["MASAR_MONGO_HOST"], port=os.environ["MASAR_MONGO_PORT"], db=os.environ["MASAR_MONGO_DB"]) result = pymasar.retrieveconfig(mongoconn, collection, name=config, withpvs=True) utils.close(mongoconn) else: raise ValueError("Known configuration name.") results = [] for res in result: results = results + res["pvlist"]["names"] return results
def saveMongoService(json): conn, collection = utils.conn(host=masarconfig.get('mongodb', 'host'), port=masarconfig.get('mongodb', 'port'), db=masarconfig.get('mongodb', 'database')) for conf in json['configs']: params = { "desc": conf['config_desc'], "system": conf['system'], "status": "active" } try: saveconfig(conn, collection, conf['config_name'], **params) except: # TODO: This should be more specific print("configuration name (%s) exists already." % (conf['config_name'])) pvgroups = {} # {"pvgname":["pv1","pv2"]} for pvgroup in json['pvgroups']: pvlist = [] pv_file = pvgroup['pvlist'] if os.path.exists(pv_file): with open(pv_file) as file: for line in file: pvlist.append(line.strip()) pvgroups[pvgroup['name']] = pvlist for conf in json['pvg2config']: pvs = [] for pvgroup in conf['pvgroups']: pvs = pvs + pvgroups[pvgroup] updateconfig(conn, collection, conf['config_name'], pvlist={"names": pvs})
def testConfiguration(self): channel = 'masarService' self.mc = masarClient.client(channelname=channel) # DB SETUP self.conn, collection = utils.conn( host=masarconfig.get('mongodb', 'host'), port=masarconfig.get('mongodb', 'port'), db=masarconfig.get('mongodb', 'database')) self.conn.drop_database(masarconfig.get('mongodb', 'database')) name = "SR_All_20140421" test_status = 'active' test_version = 20140421 test_system = 'SR' test_desc = "SR daily SCR setpoint without IS kick and septum: SR and RF" params = { "desc": test_desc, "system": test_system, "status": test_status, "version": test_version, } newid = saveconfig(self.conn, collection, name, **params) self.assertNotEqual(None, newid) res0 = retrieveconfig(self.conn, collection, name) self.assertEqual(test_status, res0[0]['status']) self.assertEqual(1, res0[0]['configidx']) self.assertEqual(name, res0[0]['name']) self.assertEqual(test_system, res0[0]['system']) self.assertNotEqual(None, res0[0]['created_on']) # The following 2 tests are to confirm the date string is in the correct format self.assertEqual(3, len(res0[0]['created_on'].split('-'))) self.assertEqual(3, len(res0[0]['created_on'].split(':'))) self.assertEqual(test_version, res0[0]['version']) self.assertEqual(test_desc, res0[0]['desc']) pvs = ["masarExampleDoubleArray"] pvlist = {"names": pvs} res = updateconfig(self.conn, collection, name, pvlist=pvlist) self.assertEqual(True, res) res3 = retrieveconfig(self.conn, collection, name, withpvs=True) self.assertEqual(test_status, res3[0]['status']) self.assertEqual(1, res3[0]['configidx']) self.assertEqual(name, res3[0]['name']) self.assertEqual(test_system, res3[0]['system']) self.assertNotEqual(None, res3[0]['created_on']) # The following 2 tests are to confirm the date string is in the correct format self.assertEqual(3, len(res3[0]['created_on'].split('-'))) self.assertEqual(3, len(res3[0]['created_on'].split(':'))) self.assertEqual(test_version, res3[0]['version']) self.assertEqual(test_desc, res3[0]['desc']) self.assertEqual(pvlist, res3[0]['pvlist']) self.assertNotEqual(None, res3[0]['updated_on']) # The following 2 tests are to confirm the date string is in the correct format self.assertEqual(3, len(res3[0]['updated_on'].split('-'))) self.assertEqual(3, len(res3[0]['updated_on'].split(':'))) # drop DB self.conn.drop_database(masarconfig.get('mongodb', 'database')) utils.close(self.conn)
def testConfiguration(self): channel = 'masarService' self.mc = masarClient.client(channelname=channel) # DB SETUP self.conn, collection = utils.conn(host=masarconfig.get('mongodb', 'host'), port=masarconfig.get('mongodb', 'port'), db=masarconfig.get('mongodb', 'database')) self.conn.drop_database(masarconfig.get('mongodb', 'database')) name = "SR_All_20140421" test_status = 'active' test_version = 20140421 test_system = 'SR' test_desc = "SR daily SCR setpoint without IS kick and septum: SR and RF" params = {"desc": test_desc, "system": test_system, "status": test_status, "version": test_version, } newid = saveconfig(self.conn, collection, name, **params) self.assertNotEqual(None, newid) res0 = retrieveconfig(self.conn, collection, name) self.assertEqual(test_status, res0[0]['status']) self.assertEqual(1, res0[0]['configidx']) self.assertEqual(name, res0[0]['name']) self.assertEqual(test_system, res0[0]['system']) self.assertNotEqual(None, res0[0]['created_on']) # The following 2 tests are to confirm the date string is in the correct format self.assertEqual(3, len(res0[0]['created_on'].split('-'))) self.assertEqual(3, len(res0[0]['created_on'].split(':'))) self.assertEqual(test_version, res0[0]['version']) self.assertEqual(test_desc, res0[0]['desc']) pvs = ["masarExampleDoubleArray"] pvlist = {"names": pvs} res = updateconfig(self.conn, collection, name, pvlist=pvlist) self.assertEqual(True, res) res3 = retrieveconfig(self.conn, collection, name, withpvs=True) self.assertEqual(test_status, res3[0]['status']) self.assertEqual(1, res3[0]['configidx']) self.assertEqual(name, res3[0]['name']) self.assertEqual(test_system, res3[0]['system']) self.assertNotEqual(None, res3[0]['created_on']) # The following 2 tests are to confirm the date string is in the correct format self.assertEqual(3, len(res3[0]['created_on'].split('-'))) self.assertEqual(3, len(res3[0]['created_on'].split(':'))) self.assertEqual(test_version, res3[0]['version']) self.assertEqual(test_desc, res3[0]['desc']) self.assertEqual(pvlist, res3[0]['pvlist']) self.assertNotEqual(None,res3[0]['updated_on']) # The following 2 tests are to confirm the date string is in the correct format self.assertEqual(3, len(res3[0]['updated_on'].split('-'))) self.assertEqual(3, len(res3[0]['updated_on'].split(':'))) # drop DB self.conn.drop_database(masarconfig.get('mongodb', 'database')) utils.close(self.conn)
def testSaveMasarMongoDB(self): app = QtGui.QApplication(sys.argv) ui = dbmanagerUI() ui.dbsource = 1 # Called normally with menu selection ui.defaultmongodb() ui.test_in_progress_flag = 1 ui.savemasarmongodb() masarconf = 'newcfgname' conn, collection = utils.conn(host=masarconfig.get('mongodb', 'host'), port=masarconfig.get('mongodb', 'port'), db=masarconfig.get('mongodb', 'database')) res3 = retrieveconfig(conn, collection, masarconf, withpvs=True) self.assertEqual('newcfgname', res3[0]['name']) self.assertEqual('newmsystem', res3[0]['system']) self.assertEqual('newcfgdesc', res3[0]['desc'])
def testUpdateMasarConfigStatus(self): app = QtGui.QApplication(sys.argv) ui = dbmanagerUI() ui.dbsource = 1 # Called normally with menu selection ui.defaultmongodb() masarconf = 'SR_All_20140421' conn, collection = utils.conn(host=masarconfig.get('mongodb', 'host'), port=masarconfig.get('mongodb', 'port'), db=masarconfig.get('mongodb', 'database')) ui.updatemasarconfigstatus("inactive", 1) res3 = retrieveconfig(conn, collection, masarconf, withpvs=True) self.assertEqual("inactive", res3[0]['status']) ui.updatemasarconfigstatus("active",1) res3 = retrieveconfig(conn, collection, masarconf, withpvs=True) self.assertEqual("active", res3[0]['status'])
def testSaveMasarMongoDB(self): app = QtGui.QApplication(sys.argv) ui = dbmanagerUI() ui.dbsource = 1 # Called normally with menu selection ui.defaultmongodb() ui.test_in_progress_flag = 1 ui.savemasarmongodb() masarconf = 'newcfgname' conn, collection = utils.conn(host=masarconfig.get('mongodb', 'host'), port=masarconfig.get('mongodb', 'port'), db=masarconfig.get( 'mongodb', 'database')) res3 = retrieveconfig(conn, collection, masarconf, withpvs=True) self.assertEqual('newcfgname', res3[0]['name']) self.assertEqual('newmsystem', res3[0]['system']) self.assertEqual('newcfgdesc', res3[0]['desc'])
def testUpdateMasarConfigStatus(self): app = QtGui.QApplication(sys.argv) ui = dbmanagerUI() ui.dbsource = 1 # Called normally with menu selection ui.defaultmongodb() masarconf = 'SR_All_20140421' conn, collection = utils.conn(host=masarconfig.get('mongodb', 'host'), port=masarconfig.get('mongodb', 'port'), db=masarconfig.get( 'mongodb', 'database')) ui.updatemasarconfigstatus("inactive", 1) res3 = retrieveconfig(conn, collection, masarconf, withpvs=True) self.assertEqual("inactive", res3[0]['status']) ui.updatemasarconfigstatus("active", 1) res3 = retrieveconfig(conn, collection, masarconf, withpvs=True) self.assertEqual("active", res3[0]['status'])
def retrieveServiceConfigs(self, params): """Retrieve configurations :param params: a dictionary to carry query condition with structure like: :: {"configname": [optional], # configuration name, wildcast allowed with * for multiple characters matching "system": [optional], # system name, wildcast allowed with * for multiple characters matching "configversion": [optional], # configuration version number "status": [optional], # either active or inactive, otherwise reset to None } or {'eventid': , # event index number to get which configuration this event belongs to} :returns: list with tuple with header description for each field. Structure like: :: [('config_idx', 'config_name', 'config_desc', 'config_create_date', 'config_version', 'status'), ...] :raises: """ key = ['configname', 'configversion', 'system', 'status', 'eventid'] configname, version, system, status, eventid = self._parseParams(params, key) if isinstance(eventid, (str, unicode)): eventid = int(eventid) if status is not None: status = status.lower() if status not in ["active", "inactive"]: status = None if system is not None and system.lower() == "all": system = None mongoconn, collection = utils.conn(host=os.environ["MASAR_MONGO_HOST"], port=os.environ["MASAR_MONGO_PORT"], db=os.environ["MASAR_MONGO_DB"]) if eventid is not None: result = pymasar.retrieveconfig(mongoconn, collection, eventidx=eventid) elif system is None and configname is None: result = pymasar.retrieveconfig(mongoconn, collection, status=status) elif system is None: result = pymasar.retrieveconfig(mongoconn, collection, name=configname, status=status) else: result = pymasar.retrieveconfig(mongoconn, collection, system=system, status=status) utils.close(mongoconn) results = [('config_idx', 'config_name', 'config_desc', 'config_create_date', 'config_version', 'status')] for res in result: results.append((res["configidx"], res["name"], res["desc"], res["created_on"], res["version"], res["status"])) return results
def testSaveMongoServiceConfigs(self): conn, collection = utils.conn(host=masarconfig.get('mongodb', 'host'), port=masarconfig.get('mongodb', 'port'), db=masarconfig.get('mongodb', 'database')) conn.drop_database(masarconfig.get('mongodb', 'database')) saveMongoService(self.parsed_json) res3 = retrieveconfig(conn, collection, 'BR_MG_SCR_20130419', withpvs=True) self.assertEqual(res3[0]['status'], 'active') self.assertEqual('BR_MG_SCR_20130419', res3[0]['name']) self.assertEqual(res3[0]['pvlist']['names'], [u'masarExample0000', u'masarExample0001', u'masarExampleBoUninit', u'masarExampleMbboUninit', u'masarExample0002', u'masarExample0003', u'masarExample0004', u'masarExampleCharArray', u'masarExampleShortArray', u'masarExampleLongArray', u'masarExampleStringArray', u'masarExampleFloatArray', u'masarExampleDoubleArray', u'masarExampleMbboUninitTest']) self.assertEqual('BR', res3[0]['system']) self.assertEqual(3, len(res3[0]['created_on'].split('-'))) # Date format test self.assertEqual(3, len(res3[0]['created_on'].split(':'))) # 2016-07-28 18:18:36 self.assertEqual(None, res3[0]['version']) self.assertEqual(3, len(res3[0]['updated_on'].split('-'))) # Date format test self.assertEqual(3, len(res3[0]['updated_on'].split(':'))) # 2016-07-28 18:18:36 self.assertNotEqual(None, res3[0]['_id']) self.assertEqual('BR ramping PS daily SCR setpoint', res3[0]['desc'])
def retrieveServiceEvents(self, params): """Retrieve events :param params: a dictionary to carry query condition with structure like: :: {"configid": , # configuration index number "start": [optional], # start time string for time window based search with format: "%Y-%m-%d %H:%M:%S" "end": [optional], # end time string for time window based search with format: "%Y-%m-%d %H:%M:%S" "comment": [optional], # comments, wildcast allowed with * for multiple characters matching "user": [optional], # user name, wildcast allowed with * for multiple characters matching "approval": , # data set status, default is True } :returns: list with tuple with header description for each field. Structure like: :: [(event_id, config_id, comments, event_time, event_serial_tag), ...] :raises: """ key = ['configid', 'eventid', 'start', 'end', 'comment', 'user', 'approval'] cid, eid, start, end, comment, user, approval = self._parseParams(params, key) if approval is None: approval = True else: approval = bool(json.loads(str(approval).lower())) if isinstance(cid, (str, unicode)): cid = int(cid) if isinstance(eid, (str, unicode)): eid = int(eid) mongoconn, collection = utils.conn(host=os.environ["MASAR_MONGO_HOST"], port=os.environ["MASAR_MONGO_PORT"], db=os.environ["MASAR_MONGO_DB"]) result = pymasar.retrieveevents(mongoconn, collection, configidx=cid, eventidx=eid, start=start, end=end, comment=comment, username=user, approval=approval) utils.close(mongoconn) results = [("event_id", "config_id", "comments", "event_time", "user_name")] for res in result: results.append((res["eventidx"], res["configidx"], res["comment"], res["created_on"], res["username"])) return results
def retrieveSnapshot(self, params): """Retrieve snapshot data :param params: a dictionary to carry query condition with structure like: :: {"eventid": , # event index number} :returns: 2-d list with tuple with header description for each field. Structure like: :: [[('user tag', 'event time', 'service config name', 'service name'), ('pv name', 'string value', 'double value', 'long value', 'dbr type', 'isConnected', 'secondsPastEpoch', 'nanoSeconds', 'timeStampTag', 'alarmSeverity', 'alarmStatus', 'alarmMessage', 'is_array', 'array_value')], # header information to determine returning data [(comment, date, config name, None), (value for pv1 as described above), (value for pv2), ...] :raises: """ key = ['eventid', 'comment'] eid, _ = self._parseParams(params, key) result = [[('user tag', 'event time', 'service config name', 'service name'), ('pv name', 'string value', 'double value', 'long value', 'dbr type', 'isConnected', 'secondsPastEpoch', 'nanoSeconds', 'timeStampTag', 'alarmSeverity', 'alarmStatus', 'alarmMessage', 'is_array', 'array_value')]] if eid is not None: if isinstance(eid, (str, unicode)): eid = int(eid) mongoconn, collection = utils.conn(host=os.environ["MASAR_MONGO_HOST"], port=os.environ["MASAR_MONGO_PORT"], db=os.environ["MASAR_MONGO_DB"]) eiddata = pymasar.retrievesnapshot(mongoconn, collection, eid) configname = pymasar.retrieveconfig(mongoconn, collection, configidx=eiddata["configidx"])[0]["name"] utils.close(mongoconn) temp = [(eiddata["comment"], eiddata["created_on"], configname, None), ] for d in eiddata["masar_data"]: temp.append(tuple(d)) result.append(temp) return result
def approveSnapshotEvent(self, params): """Approve a new snapshot :param params: a dictionary to carry query condition with structure like: :: {"eventid": , # event index number "user": [optional], # user name, wildcast allowed with * for multiple characters matching "desc": [optional], # brief description } :returns: list as below: :: succeeded: [0, eventid] fail: [-1, eventid] exception: [-2, eventid] :raises: None """ key = ['eventid', 'user', 'desc'] eid, user, desc = self._parseParams(params, key) try: result = False if eid is not None: if isinstance(eid, (str, unicode)): eid = int(eid) mongoconn, collection = utils.conn(host=os.environ["MASAR_MONGO_HOST"], port=os.environ["MASAR_MONGO_PORT"], db=os.environ["MASAR_MONGO_DB"]) result = pymasar.updateevent(mongoconn, collection, eventidx=eid, approval=True, username=user, comment=desc) utils.close(mongoconn) if result: return [0, eid] else: return [-1, eid] except: return [-2, eid]
def retrieveSystems(self, params): """Retrieve system list :param params: a dictionary to carry query condition with structure like: :: {"system": [optional], # system name, wildcast allowed with * for multiple characters matching "configname": [optional], # configuration name, wildcast allowed with * for multiple characters matching } :returns: list with tuple with header description for each field. Structure like: :: [('config_id', 'config_idx', 'system_key', 'system_val'), ...] :raises: """ key = ['system', 'configname'] system, configname = self._parseParams(params, key) mongoconn, collection = utils.conn(host=os.environ["MASAR_MONGO_HOST"], port=os.environ["MASAR_MONGO_PORT"], db=os.environ["MASAR_MONGO_DB"]) if system is None and configname is None: result = pymasar.retrieveconfig(mongoconn, collection) elif system is None: result = pymasar.retrieveconfig(mongoconn, collection, name=configname) else: if system.lower() == "all": result = pymasar.retrieveconfig(mongoconn, collection) else: result = pymasar.retrieveconfig(mongoconn, collection, system=system) utils.close(mongoconn) results = [('config_prop_id', 'config_idx', 'system_key', 'system_val')] for res in result: results.append((int(str(res["_id"]), 16), res["configidx"], "system", res["system"])) return results
"""An example shows how to create one MongoDB masar configuration.""" __author__ = 'shengb' import numpy as np from pymasarmongo.db import utils import pymasarmongo def saveconfig2mongo(mongoconn, collection, name, desc, system, pvlist): pymasarmongo.pymasarmongo.pymasar.saveconfig(mongoconn, collection, name, desc=desc, system=system, pvlist=pvlist) if __name__ == "__main__": mongoconn, collection = utils.conn() #print mongoconn saveconfig2mongo(mongoconn, collection, "test configuration", desc="this is for test only", system="test", pvlist={"names": list(np.loadtxt("examplepvlist.txt", dtype=str, comments="#"))}) utils.close(mongoconn)
from pymasarmongo.db import utils import pymasarmongo def saveconfig2mongo(mongoconn, collection, name, desc, system, pvlist): pymasarmongo.pymasarmongo.pymasar.saveconfig(mongoconn, collection, name, desc=desc, system=system, pvlist=pvlist) if __name__ == "__main__": mongoconn, collection = utils.conn() #print mongoconn saveconfig2mongo(mongoconn, collection, "test configuration", desc="this is for test only", system="test", pvlist={ "names": list( np.loadtxt("examplepvlist.txt", dtype=str, comments="#")) })
def setUp(self): self.conn, self.collection = utils.conn( host=masarconfig.get('mongodb', 'host'), port=masarconfig.get('mongodb', 'port'), db=masarconfig.get('mongodb', 'database'))
def setUp(self): self.conn, self.collection = utils.conn(host=masarconfig.get('mongodb','host'), port=masarconfig.get('mongodb','port'), db=masarconfig.get('mongodb','database'))
def setUp(self): self.conn, self.collection = utils.conn()
def saveSnapshot(self, params): """Save event with data. :param params: a dictionary to carry query condition with structure like: :: [[(channel name,), (string value,),(double value,),(long value,),(dbr type),(is connected), (second past epoch,),(nano seconds,),(time stamp tag,), (alarm severity,),(alarm status,),(alarm message,), (is_array), (array_value) ], {"configname": , # configuration name which the new data set belongs to "comment": [optional], # comment description for this new data set "approval": [optional], # approval status, False is not provided "username": [optional], # user name who commands this action } ] :returns: list with tuple with header description for each field. Structure like: :: [event_id] or [-1] if fault :raises: ValueError """ key = ['configname', 'comment', 'approval', 'username'] config, comment, approval, username = self._parseParams(params[1], key) if config is None: raise ValueError("Unknown configuration when saving a new snapshot event.") if approval is None: approval = False else: approval = bool(json.loads(str(approval).lower())) result = NTMultiChannel(params[0]) dataLen = result.getNumberChannel() if dataLen == 0: raise RuntimeError("No available snapshot data.") # values format: the value is raw data from IOC # [(channel name,), (value,), (dbr type), (is connected), # (second past epoch,), (nano seconds,), (time stamp tag,), # (alarm severity,), (alarm status,), (alarm message,)] pvnames = result.getChannelName() values = result.getValue() dbrtype = result.getDbrType() isconnected = result.getIsConnected() severity = result.getSeverity() status = result.getStatus() message = result.getMessage() sec = result.getSecondsPastEpoch() nanosec = result.getNanoseconds() usertag = result.getUserTag() # data format: the data is prepared to save into rdb # rawdata format # [('channel name', 'string value', 'double value', 'long value', 'dbr type', 'is connected', # 'seconds past epoch', 'nano seconds', 'time stamp tag', 'alarm severity', 'alarm status', # 'alarm message', 'is_array', 'array_value'), # ... # ] datas = [] # get IOC raw data for i in range(dataLen): tmp = [] if isinstance(values[i], (list, tuple)): tmp = [pvnames[i], "", None, None, dbrtype[i], isconnected[i], sec[i], nanosec[i], usertag[i], severity[i], status[i], message[i], 1, values[i]] else: if dbrtype[i] in self.epicsString: tmp = [pvnames[i], values[i], None, None, dbrtype[i], isconnected[i], sec[i], nanosec[i], usertag[i], severity[i], status[i], message[i], 0, None] else: tmp = [pvnames[i], str(values[i]), values[i], values[i], dbrtype[i], isconnected[i], sec[i], nanosec[i], usertag[i], severity[i], status[i], message[i], 0, None] datas.append(tmp) # save into database try: mongoconn, collection = utils.conn(host=os.environ["MASAR_MONGO_HOST"], port=os.environ["MASAR_MONGO_PORT"], db=os.environ["MASAR_MONGO_DB"]) configs = pymasar.retrieveconfig(mongoconn, collection, name=config) if len(configs) != 1: raise RuntimeError("Cannot find a unique configuration.") eid = pymasar.saveevent(mongoconn, collection, configidx=configs[0]["configidx"], comment=comment, approval=approval, username=username, masar_data=datas) utils.close(mongoconn) return [eid, ] except: # keep the same format with a normal operation return [-1]