Ejemplo n.º 1
0
    def incrementCounters(self, countertype):
        """Increment the counters for the given *countertype*.

        This should update the counter files accordingly.

        Returns a list of (counterattribute, value) tuples to set on the
        dataset.
        """
        exp = session.experiment
        if not path.isfile(path.join(exp.dataroot, exp.counterfile)):
            session.log.warning('creating new empty file counter file at %s',
                                path.join(exp.dataroot, exp.counterfile))
        # Keep track of which files we have already updated, since the proposal
        # and the sample specific counter might be the same file.
        seen = set()
        result = []
        for directory, attr in [(exp.dataroot, 'counter'),
                                (exp.proposalpath, 'propcounter'),
                                (exp.samplepath, 'samplecounter')]:
            counterpath = path.normpath(path.join(directory, exp.counterfile))
            nextnum = readFileCounter(counterpath, countertype) + 1
            if counterpath not in seen:
                updateFileCounter(counterpath, countertype, nextnum)
                seen.add(counterpath)
            else:
                nextnum -= 1
            result.append((attr, nextnum))
        return result
Ejemplo n.º 2
0
 def setScanCounter(self, session, no):
     dataroot = path.join(config.nicos_root, self.datadir)
     counter = path.join(dataroot, session.experiment.counterfile)
     open(counter, 'w').close()
     updateFileCounter(counter, 'scan', no)
     # print('SetCounter')
     updateFileCounter(counter, 'point', 167)
Ejemplo n.º 3
0
def setup_module(session):
    """Setup dataroot and generate a dataset by scanning"""
    exp = session.experiment
    dataroot = path.join(config.nicos_root, 'testdata')
    os.makedirs(dataroot)

    counter = path.join(dataroot, exp.counterfile)
    open(counter, 'w').close()
    updateFileCounter(counter, 'scan', 42)
    updateFileCounter(counter, 'point', 167)

    exp._setROParam('dataroot', dataroot)
    exp.new(1234, user='******', localcontact=exp.localcontact)
    exp.sample.new({'name': 'mysample'})
    assert path.abspath(exp.datapath) == \
        path.abspath(path.join(config.nicos_root, 'testdata',
                               year, 'p1234', 'data'))
    m = session.getDevice('motor2')
    det = session.getDevice('det')
    tdev = session.getDevice('tdev')
    session.experiment.setEnvironment([])

    scan(m, 0, 1, 5, det, tdev, t=0.005)

    yield
Ejemplo n.º 4
0
def dataroot(request, session):
    """Dataroot handling fixture"""

    exp = session.experiment
    dataroot = path.join(config.nicos_root, request.module.exp_dataroot)
    os.makedirs(dataroot)

    counter = path.join(dataroot, exp.counterfile)
    open(counter, 'w').close()
    updateFileCounter(counter, 'scan', 42)
    updateFileCounter(counter, 'point', 42)

    exp._setROParam('dataroot', dataroot)
    exp.new(1234, user='******')
    exp.sample.new({'name': 'mysample'})

    return dataroot
Ejemplo n.º 5
0
    def _assignCounter(self):
        # Adapted from DataManager.assignCounter function
        if self.dataset.counter != 0:
            return

        exp = session.experiment
        if not path.isfile(path.join(exp.dataroot, exp.counterfile)):
            session.log.warning('creating new empty file counter file at %s',
                                path.join(exp.dataroot, exp.counterfile))

        if session.mode == SIMULATION:
            raise ProgrammingError('assignCounter should not be called in '
                                   'simulation mode')

        # Read the counter from SICS file
        counter = exp.sicscounter + 1

        # Keep track of which files we have already updated, since the proposal
        # and the sample specific counter might be the same file.
        seen = set()
        for directory, attr in [(exp.dataroot, 'counter'),
                                (exp.proposalpath, 'propcounter'),
                                (exp.samplepath, 'samplecounter')]:
            counterpath = path.normpath(path.join(directory, exp.counterfile))
            readFileCounter(counterpath, self.dataset.countertype)
            if counterpath not in seen:
                updateFileCounter(counterpath, self.dataset.countertype,
                                  counter)
                seen.add(counterpath)

            setattr(self.dataset, attr, counter)

        # Update the counter in SICS file
        exp.updateSicsCounterFile(counter)

        session.experiment._setROParam('lastpoint', self.dataset.counter)