Beispiel #1
0
    def __init__(self, fv):
        # superclass defines some variables for us, like logger
        super(ANA, self).__init__(fv)

        # Find out what proposal ID we are logged in under
        self.propid = None
        username = pwd.getpwuid(os.getuid()).pw_name
        match = re.match(r'^[uo](\d{5})$', username)
        if match:
            self.propid = 'o' + match.group(1)
        else:
            if os.path.exists(propid_file):
                try:
                    with open(propid_file, 'r') as in_f:
                        self.propid = in_f.read().strip()
                except Exception:
                    pass
        if self.propid is None:
            raise AnaError("Unable to determine prop-id for ANA operation")
        match = re.match(r'^o(\d{5})$', self.propid)
        if not match:
            raise AnaError(
                "PROP-ID ({}) doesn't match expected format (oNNMMM)")

        # find out our hostname
        self.host = ro.get_myhost(short=True)
        self.ro_host = os.environ['GEN2HOST']

        ro.init([self.ro_host])

        # construct our service name
        self.svcname = "ANA-{}-{}".format(self.propid, self.host)

        # for looking up instrument names
        self.insconfig = INSconfig.INSdata()

        self.data_dir = os.path.join('/data', self.propid)

        # make a name and port for our monitor
        mymonname = '{}.mon'.format(self.svcname)
        self.monport = 10000 + int(self.propid[-3:])
        self.port = 9000 + int(self.propid[-3:])
        #self.channels = ['g2task']

        threadPool = self.fv.get_threadPool()

        # Create a local pub sub instance
        self.monitor = Monitor.Monitor(mymonname,
                                       self.logger,
                                       threadPool=threadPool,
                                       ev_quit=self.fv.ev_quit)

        # some of the other plugins expect this handle to be available
        # via fv
        self.fv.controller = self
Beispiel #2
0
def main(options, args):

    # Create top level logger.
    logger = ssdlog.make_logger(options.svcname, options)

    # Initialize remote objects subsystem.
    try:
        ro.init()

    except ro.remoteObjectError, e:
        logger.error("Error initializing remote objects subsystem: %s" % str(e))
        sys.exit(1)
Beispiel #3
0
    def update_current_conditions_cb(self, widget):
        # Fetch current filter, Az, El from Gen2 status service and
        # update first row in schedule sheet. Also, update start time.
        self.logger.debug('update_current_conditions_cb')
        try:
            ro.init()
            stobj = ro.remoteObjectProxy('status')
            result = stobj.fetch({'FITS.HSC.FILTER': 0, 'TSCS.AZ': 0, 'TSCS.EL': 0})
        except ro.remoteObjectError as e:
            self.logger.error('Unexpected error in update_current_conditions_cb: %s' % str(e))
            return

        self.logger.info('From Gen2 current HSC filter %s Az %f El %f' % (result['FITS.HSC.FILTER'], result['TSCS.AZ'], result['TSCS.EL']))
        if self.schedule_qf is None:
            self.logger.error('Unexpected error in update_current_conditions_cb: schedule_qf is None')
            return

        self.logger.debug('Before update, schedule_qf.rows:%s' % self.schedule_qf.rows)
        rownum = 0 # Update only the first row

        cur_filter = result['FITS.HSC.FILTER']
        if cur_filter not in (STATNONE, STATERROR, '0'):
            # Filter name special cases
            if 'HSC-' in cur_filter:
                cur_filter = cur_filter.replace('HSC-', '')
            if cur_filter == 'Y':
                cur_filter = 'y'
            if 'NB0' in cur_filter:
                cur_filter = cur_filter.replace('NB0', 'NB')
            if 'IB0' in cur_filter:
                cur_filter = cur_filter.replace('IB0', 'IB')
            # Set all 'NB' and 'IB' filters to lower-case
            if ('NB' in cur_filter) or ('IB' in cur_filter):
                cur_filter = cur_filter.lower()
            self.logger.info('Current filter %s' % (cur_filter))
            self.schedule_qf.update(rownum, 'Cur Filter', cur_filter, False)

        if result['TSCS.AZ'] not in (STATNONE, STATERROR):
            cur_az = '%8.2f' % result['TSCS.AZ']
            cur_az = cur_az.strip()
            self.schedule_qf.update(rownum, 'Cur Az', cur_az, False)

        if result['TSCS.EL'] not in (STATNONE, STATERROR):
            cur_el = '%8.2f' % result['TSCS.EL']
            cur_el = cur_el.strip()
            self.schedule_qf.update(rownum, 'Cur El', cur_el, False)

        now = datetime.datetime.now().strftime('%H:%M:%S')
        self.schedule_qf.update(rownum, 'start time', now, True)

        self.logger.debug('After update, schedule_qf.rows: %s' % self.schedule_qf.rows)
        self.model.set_schedule_qf(self.schedule_qf)
from g2base.remoteObjects import remoteObjects as ro
from time import sleep
import time
import sys

# First arg is how many frameids to get. But it will only print the first one

t0 = time.time()

#gen2host = 'g2sim1.subaru.nao.ac.jp'
gen2host = 'g2ins1.sum.subaru.nao.ac.jp'

nfrmids = int(sys.argv[1])
camcode = sys.argv[2]

ro.init([gen2host])
g2proxy = ro.remoteObjectProxy('SCEXAO')

# want to allocate some frames.
g2proxy.executeCmd('SCEXAO', 'foo', 'get_frames', camcode, dict(num=nfrmids))

# frames will be stored one per line in /tmp/frames.txt
sleep(0.1)
with open("/tmp/frames_%s.txt" % (camcode, ), 'r') as in_f:
    frames = in_f.read().split('\n')
assert len(frames) > 0, Exception("Frames file is empty!")
print(frames)
print(time.time() - t0)
Beispiel #5
0
    def start_server(self, rohosts, options):
        # Initialize remoteObjects subsystem
        try:
            ro.init(rohosts)

        except ro.remoteObjectError as e:
            self.logger.error("Error initializing remote objects subsystem: %s" % \
                         str(e))
            return

        # channels we are interested in
        channels = ['sound']

        self.ev_quit = threading.Event()
        self.server_exited = threading.Event()

        # Create a local pub sub instance
        # mymon = PubSub.PubSub('%s.mon' % self.basename, self.logger,
        #                       numthreads=30)
        monname = '%s.mon' % self.basename
        mymon = Monitor.Monitor(monname,
                                self.logger,
                                numthreads=options.numthreads,
                                ev_quit=self.ev_quit)
        self.monitor = mymon

        self.soundsink = soundsink.SoundSink(monitor=mymon,
                                             logger=self.logger,
                                             ev_quit=self.ev_quit)
        self.soundsource = soundsink.SoundSource(monitor=mymon,
                                                 logger=self.logger,
                                                 channels=['sound'])

        # Subscribe our callback functions to the local monitor
        mymon.subscribe_cb(self.soundsink.anon_arr, channels)

        self.mon_server_started = False
        self.ro_server_started = False

        # Startup monitor threadpool
        mymon.start(wait=True)
        mymon.start_server(wait=True, port=options.monport)
        self.mon_server_started = True

        self.threadPool = self.monitor.get_threadPool()

        # subscribe our monitor to the central monitor hub
        mymon.subscribe_remote(options.monitor, channels, ())

        # publish to central monitor hub
        #mymon.subscribe(options.monitor, channels, ())
        mymon.publish_to(options.monitor, ['sound'], {})

        self.svc = ro.remoteObjectServer(
            svcname=self.basename,
            obj=self,
            logger=self.logger,
            port=options.port,
            ev_quit=self.ev_quit,
            threadPool=self.threadPool,
            #auth=None,
            usethread=True)
        self.svc.ro_start(wait=True)
        self.ro_server_started = True
Beispiel #6
0
 def start(self):
     if have_gen2:
         ro.init()
         self.ig = ro.remoteObjectProxy(self.svcname)
Beispiel #7
0
def main(options, args):

    basename = options.svcname
    logger = ssdlog.make_logger(basename, options)

    # Initialize remote objects subsystem
    args = ['localhost']
    if options.rohosts is not None:
        args = options.rohosts.split(',')
    try:
        ro.init(args)

    except ro.remoteObjectError as e:
        logger.error("Error initializing remote objects subsystem: %s" % \
                     str(e))
        sys.exit(1)

    ev_quit = threading.Event()

    # Create a local pub sub instance
    monname = '%s.mon' % basename
    minimon = Monitor.Monitor(monname, logger, numthreads=options.numthreads)

    threadPool = minimon.get_threadPool()

    queue = Queue.Queue()

    channels = options.channels.split(',')

    # Make our callback object/remote object
    if options.soundsink:
        mobj = SoundSink(monitor=minimon, logger=logger, queue=queue,
                         channels=channels, ev_quit=ev_quit,
                         dst=options.destination)
    else:
        mobj = SoundSource(monitor=minimon, logger=logger, queue=queue,
                           channels=channels, ev_quit=ev_quit,
                           compress=options.compress)

    svc = ro.remoteObjectServer(svcname=basename,
                                obj=mobj, logger=logger,
                                port=options.port,
                                ev_quit=ev_quit,
                                usethread=True, threadPool=threadPool)

    mon_server_started = False
    ro_server_started = False
    try:
        # Startup monitor threadpool
        minimon.start(wait=True)
        minimon.start_server(wait=True, port=options.monport)
        mon_server_started = True

        # Configure logger for logging via our monitor
        # if options.logmon:
        #     minimon.logmon(logger, options.logmon, ['logs'])

        if options.soundsink:
            # Subscribe our callback functions to the local monitor
            minimon.subscribe_cb(mobj.anon_arr, channels)
            minimon.subscribe_remote(options.monitor, channels, {})
        else:
            # publish our channels to the specified monitor
            minimon.publish_to(options.monitor, channels, {})


        svc.ro_start(wait=True)
        ro_server_started = True

        try:
            mobj.server_loop()

        except KeyboardInterrupt:
            logger.error("Received keyboard interrupt!")

    finally:
        ev_quit.set()
        if mon_server_started:
            minimon.stop_server(wait=True)
        if ro_server_started:
            svc.ro_stop(wait=True)
        minimon.stop(wait=True)

    logger.info("%s exiting..." % basename)