Example #1
0
 def create_comms(self):
     this_host = socket.gethostname()
     numComms = len(self.host_list)
     self.comms = []
     s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
     s.bind((HOST, self.port))
     s.listen(5)
     print("[%s]listening to port %d" % (self.this_host, self.port))
     t0 = time.clock()
     self.proc_list = [[]] * numComms
     i = 0
     while (len(self.comms) < numComms) and (
         (time.clock() - t0) < self.timeout):
         conn, addr = s.accept()
         print("[%s] Connected by %s" % (self.this_host, addr))
         name_dir = conn.recv(1024)
         a = name_dir.split(':')
         if len(a) == 2:
             logfile = "controller_%s.lst" % (a[0])
             print(
                 "[%s] new comm: Communicator(conn, self.job_manager, %s, %s, %s, %s"
                 % (self.num_iters, self.this_host, a[0], a[1], logfile))
             new_comm = Communicator.Communicator(conn, self.job_manager,
                                                  self.num_iters, a[0],
                                                  a[1], logfile,
                                                  self.proc_list[i])
             self.comms.append(new_comm)
             #self.comms.append(Communicator(conn, self.job_manager, a[0], a[1], "controller_%s.lst" % (a[0])))
             i = i + 1
         else:
             print("[%s] bad request [%s]" % (self.this_host, str(a)))
         #-- end if
     #-- end while
     s.close()
 def _make_communicator(self) -> Communicator.Communicator:
     ret: tuple[int, tuple] = self.db_interface.retrieve_tokens()
     if ret[0] == -1:  # Failed to retrieve token
         print(ret[1])
         exit(1)
     refresh_token: str = ret[1][0]
     unix_timestamp: int = ret[1][1]
     communicator = Communicator.Communicator(refresh_token, unix_timestamp)
     return communicator
Example #3
0
 def __init__(self, dns_server_ip):
     """
     function constructs server
     args:
         ip: string
         port: int
     """
     self.dns_server_ip = dns_server_ip
     self.communicator = Communicator.Communicator()
     self.dbsp_client_list = Client_List.Client_List()
     self.banned_ip_list = []
Example #4
0
def selectRankingSource(source, conf=None):
    ''' Select an appropriate ranking source depending on the configuration.
    
        Params:
            source    -- specifies the ranking policy to be used
                         admissible values are: none, samehost, odd_even, sis, sis_simple, ip_pre
            conf      -- (optional) configuration instance (from cache or client)
    '''
    if source == 'samehost':
        ranking = SameHostPolicy()
    elif source == 'odd_even':
        ranking = OddEvenPolicy()
    elif source == 'geoip':
        ranking = GeoIPPolicy()
    elif source == 'sis':
        import Communicator
        assert conf != None
        assert conf.get_sis_client_endpoint() != None
        assert conf.get_rating_cache_interval() != None
        ranking = Communicator.Communicator(
            conf.get_sis_client_endpoint(),
            simple=False,
            max_time_in_cache=conf.get_rating_cache_interval())
    elif source == 'sis_simple':
        import Communicator
        assert conf != None
        assert conf.get_sis_client_endpoint() != None
        assert conf.get_rating_cache_interval() != None
        ranking = Communicator.Communicator(
            conf.get_sis_client_endpoint(),
            simple=True,
            max_time_in_cache=conf.get_rating_cache_interval())
    elif source == 'ip_pre':
        assert conf != None
        assert conf.get_ip_prefixes() != None
        ranking = SameIPPrefixPolicy(conf.get_ip_prefixes())
    elif source in (None, 'none', 'None'):
        ranking = DummyPolicy()
    else:
        raise Exception("Unsupported ranking type: " + source)
    return ranking
Example #5
0
def main():
    ap = argparse.ArgumentParser()
    ap.add_argument("--calibrate",
                    action='store_true',
                    default=False,
                    help='Perform camera calibration')
    ap.add_argument("--visualize",
                    action='store_true',
                    default=False,
                    help='Visualize the tracking on a preview window')
    ap.add_argument("--communicate",
                    action='store_true',
                    default=False,
                    help='Transmit data via tcp')
    ap.add_argument("--record",
                    action='store_true',
                    default=False,
                    help="Record robot coordinates in a file for use by sim")
    args = ap.parse_args()

    cal_obj = cal.CameraCalibration(use_precaptured_images=not args.calibrate)
    if args.calibrate:
        cal_obj.calibrate_camera()
    camera_matrix, dist_matrix = cal_obj.extract_existing_calibration_data()
    del (cal_obj)

    field_set_obj = fs.FieldSetter(visualization=True)
    ref_point = field_set_obj.select_playing_field()
    del (field_set_obj)

    com_obj = None
    if args.communicate:
        com_obj = com.Communicator()

    rec_obj = None
    if args.record:
        rec_obj = rec.DataRecorder()

    tracker_obj = tracker.ArucoTracker(camera_matrix,
                                       dist_matrix,
                                       com_obj,
                                       rec_obj,
                                       ref_point,
                                       visualization=args.visualize)
    tracker_obj.track_aruco_markers()
Example #6
0
def run():
    # Start the communicator:
    com = Communicator('ALIGNITER')

    # FSM loop
    state = State.NOT_READY
    com.set_status(state)
    n_it = 0
    while True:
        command = com.get_command()
        if command == 'configure' and state == State.NOT_READY:
            state = State.READY
        elif command == 'start' and state == State.READY:
            state = State.RUNNING
        elif command == 'pause' and state == State.RUNNING:
            state = State.PAUSED
            com.set_status(state)
            if n_it < 4:
                n_it += 1
                print 'iteration %d' % n_it
                state = State.RUNNING
            else:
                print 'iterator done'
                state = State.READY
            sleep(2)
        elif command == 'stop' and state in (State.RUNNING, State.READY):
            state = State.READY
        elif command == 'reset':
            state = State.NOT_READY
            break
        else:
            print 'iterator: bad transition from %s to %s' % (state, command)
            state = State.ERROR
            break
        # Set the status
        com.set_status(state)

    # Set our status one last time
    com.set_status(state)
Example #7
0
def main():
    ap = argparse.ArgumentParser()
    ap.add_argument("--server", type=str, default='localhost',
                    help='server address (default localhost)')
    ap.add_argument("--port", type=int, default=10000,
                    help='server port (default 10000)')
    ap.add_argument("--fps", type=int, default=20,
                    help='data rate in fps for simulator (default 20)')
    args = ap.parse_args()

    com_obj = com.Communicator(server_address=(args.server, args.port))
    if not os.path.exists(gc.g_sim_data_file_name):
        sys.exit("No recorded simulator data found. Quitting . . .")

    data_file = open(gc.g_sim_data_file_name, "r")
    data_contents = data_file.readlines()
    data_file.close()

    print("Transmitting simulator data")
    for line in data_contents:
        json_data = json.loads(line)
        time.sleep((1/args.fps))
        com_obj.transmit_data(json_data)
Example #8
0
def run(index):
    # Start the communicator:
    com = Communicator("ALIGNWORK_%02d" % index)

    with open("/dev/urandom", "rb") as rand_src:
        bytes = rand_src.read(4)
        random.seed(struct.unpack("I", bytes)[0])

    # FSM loop
    state = State.NOT_READY
    com.set_status(state)
    n_it = 0
    while True:
        command = com.get_command()
        if command == 'configure' and state == State.NOT_READY:
            state = State.READY
        elif command == 'start' and state == State.READY:
            state = State.RUNNING
            com.set_status(state)
            sleep(random.uniform(1, 3))
            state = State.PAUSED
        elif command == 'stop' and state == State.PAUSED:
            state = State.READY
        elif command == 'reset':
            state = State.NOT_READY
            break
        else:
            print 'analyzer: bad transition from %s to %s' % (state, command)
            state = State.ERROR
            break

        sleep(random.uniform(0.5, 1.5))
        # Set the status
        com.set_status(state)

    # Set the status one last time.
    com.set_status(state)
Example #9
0
def run(index=0):
    # Start the communicator:
    com = Communicator("ALIGNWORK_%02d" % index)

    # FSM loop
    state = State.NOT_READY
    com.set_status(state)
    n_it = 0
    sleep(0.2)
    while True:
        command = com.get_command()
        if command == 'configure' and state == State.NOT_READY:
            import L0_noHlt1_histosGen_Multi
            state = State.READY

        elif command == 'start' and state == State.READY:
            state = State.RUNNING
            com.set_status(state)
            L0_noHlt1_histosGen_Multi.MultiRun()
            sleep(2)
            state = State.PAUSED
        elif command == 'stop' and state == State.PAUSED:
            state = State.READY
        elif command == 'reset':
            state = State.NOT_READY
            break
        else:
            print 'analyzer: bad transition from %s to %s' % (state, command)
            state = State.ERROR
            break

        sleep(2)
        # Set the status
        com.set_status(state)

    # Set the status one last time.
    com.set_status(state)
Example #10
0
def run():
    # Start the communicator:
    utgid = os.environ.get('UTGID', 'ALIGNITER')
    com = Communicator(utgid)

    # FSM loop
    state = State.NOT_READY
    com.set_status(state)

    DefParameters = std.vector('double')()
    DefParameters.push_back(179.)
    DefParameters.push_back(240.)
    DefParameters.push_back(600.)
    DefParameters.push_back(600.)
    DefParameters.push_back(900.)
    DefParameters.push_back(600.)
    DefParameters.push_back(60.)
    DefParameters.push_back(900.)

    LineNames = std.vector('string')()
    LineNames.push_back('mbias')
    LineNames.push_back('Bs2Dsmunu')
    LineNames.push_back('Lb2pmunu')
    LineNames.push_back('Bs2phigamma')
    LineNames.push_back('Bs2mumu')
    LineNames.push_back('Bs2Kstee')
    LineNames.push_back('Bd2Kstmumu')
    LineNames.push_back('Bd2Kpi')
    LineNames.push_back('Bs2phiphi')
    LineNames.push_back('DD')
    LineNames.push_back('Bs2DsPi')
    LineNames.push_back('Bs2JpsiPhi')
    LineNames.push_back('Bs2Jpsikkpipi')
    LineNames.push_back('D2kkpi')
    LineNames.push_back('Dst2Dpi2kskk')

    LineTypes = std.vector('int')()
    LineTypes.push_back(0)
    LineTypes.push_back(1)
    LineTypes.push_back(1)
    LineTypes.push_back(3)
    LineTypes.push_back(2)
    LineTypes.push_back(3)
    LineTypes.push_back(2)
    LineTypes.push_back(1)
    LineTypes.push_back(1)
    LineTypes.push_back(1)
    LineTypes.push_back(1)
    LineTypes.push_back(2)
    LineTypes.push_back(2)
    LineTypes.push_back(1)
    LineTypes.push_back(1)

    MaxEfficiencies = std.vector('double')()
    MaxEfficiencies.push_back(0.4)
    MaxEfficiencies.push_back(0.9)
    MaxEfficiencies.push_back(0.9)
    MaxEfficiencies.push_back(0.6)
    MaxEfficiencies.push_back(0.9)
    MaxEfficiencies.push_back(0.6)
    MaxEfficiencies.push_back(0.3)
    MaxEfficiencies.push_back(0.3)
    MaxEfficiencies.push_back(0.3)
    MaxEfficiencies.push_back(0.2)
    MaxEfficiencies.push_back(0.7)
    MaxEfficiencies.push_back(0.6)

    name = TString("FitterGA")

    Channels = std.vector('int')()
    Channels.push_back(1)
    Channels.push_back(2)
    # Channels.push_back(3)
    # Channels.push_back(4)
    # Channels.push_back(5)
    # Channels.push_back(6)
    # Channels.push_back(7)
    # Channels.push_back(8)
    # Channels.push_back(9)
    # Channels.push_back(10)
    # Channels.push_back(11)
    # Channels.push_back(12)
    # Channels.push_back(13)
    # Channels.push_back(14)
    # Channels.push_back(15)

    lo = std.vector('double')()
    hi = std.vector('double')()
    lo.push_back(100.)
    hi.push_back(400.)
    # lo.push_back(20.)
    # hi.push_back(100.)
    # lo.push_back(600.)
    # hi.push_back(1300.)

    UsedParameters = std.vector('int')()
    #UsedParameters.push_back(0)
    UsedParameters.push_back(1)
    # UsedParameters.push_back(3)
    # UsedParameters.push_back(4)
    # UsedParameters.push_back(5)
    # UsedParameters.push_back(6)
    # UsedParameters.push_back(7)

    #fitter.CheckForUnusedOptions()

    pars = std.vector('double')(2)
    subprocess.call('rm -rf $OUTPUTDIR/*.root', shell=True)

    cycle = 0
    firstEntry = True
    StartIterationFirstTime = True
    FinishIterationAndStartNew = False

    print type(cycle)
    while True:
        command = com.get_command()
        if command == 'configure' and state == State.NOT_READY:

            import pickle

            f = open('BWTest.pkl')
            channels = pickle.load(f)
            trigger_lines = pickle.load(f)
            trigger_thresholds = pickle.load(f)
            statistics = pickle.load(f)
            f.close()

            opt = TString(
                "PopSize=3:Steps=2:Cycles=2:ConvCrit=0.01:SaveBestCycle=5")
            fitter = TMVA.GeneticFitterMod(name, lo, hi, Channels, opt,
                                           DefParameters, UsedParameters,
                                           MaxEfficiencies, LineNames,
                                           LineTypes)
            fitter.RunInit(pars)
            state = State.READY

        elif command == 'start' and state == State.READY:
            fitter.CycleInit(cycle)
            fitter.ga.WriteParamsToFile(cycle)
            StartIterationFirstTime = True
            FinishIterationAndStartNew = False
            state = State.RUNNING
            print 'WANT TO CALCULATE FITNESS FIRST TIME'

        elif command == 'pause' and state == State.RUNNING:
            state = State.PAUSED
            print 'FITNESS CALCULATED'
            com.set_status(state)
            if cycle < fitter.GenNcycles():
                if StartIterationFirstTime:
                    print 'CYCLE %d' % cycle
                    print 'FIRST ITERATION'
                    #                    subprocess.call('rm -rf $OUTPUTDIR/bwdhistosRESULT.root',shell=True)
                    subprocess.call(
                        'hadd -f $OUTPUTDIR/bwdhistosRESULT.root $OUTPUTDIR/bwdhistosRes*',
                        shell=True)

                    fitter.ga.CalculateFitness()
                    fitter.ga.GetGeneticPopulation().TrimPopulation()
                    fitter.IterationInit(cycle)
                    fitter.ga.WriteParamsToFile(cycle)
                    StartIterationFirstTime = False
                    FinishIterationAndStartNew = True
                    state = State.RUNNING
                    print 'WANT TO CALCULATE FITNESS'
                elif FinishIterationAndStartNew:
                    #                   subprocess.call('rm -rf $OUTPUTDIR/bwdhistosRESULT.root',shell=True)
                    subprocess.call(
                        'hadd -f $OUTPUTDIR/bwdhistosRESULT.root $OUTPUTDIR/bwdhistosRes*',
                        shell=True)
                    fitter.ga.CalculateFitness()
                    fitter.IterationExit(cycle)
                    if not fitter.ga.HasConverged(fitter.GetNsteps(),
                                                  fitter.GetConvCrit()):
                        fitter.IterationInit(cycle)
                        fitter.ga.WriteParamsToFile(cycle)
                        print 'WANT TO CALCULATE FITNESS'
                    else:
                        fitter.CycleExit(cycle)
                        print 'CYCLE  ', cycle, '   FINISHED'
                        cycle += 1
                        if not cycle < fitter.GenNcycles():
                            fitter.gstore.WriteParamsToFile(1)
                            print 'AAAAAAAA 1111'
                        else:
                            fitter.CycleInit(cycle)
                            fitter.ga.WriteParamsToFile(cycle)
                            StartIterationFirstTime = True
                            print 'CYCLE %d' % cycle
                            print 'WANT TO CALCULATE FITNESS FIRST TIME'
                        FinishIterationAndStartNew = False
                        StartIterationFirstTime = True
                        print 'AAAAAAAA 2222'
                    state = State.RUNNING
            else:
                #                subprocess.call('rm -rf $OUTPUTDIR/bwdhistosRESULT.root',shell=True)
                print 'AAAAAAAA 3333'
                subprocess.call(
                    'hadd -f $OUTPUTDIR/bwdhistosRESULT.root $OUTPUTDIR/bwdhistosRes*',
                    shell=True)
                print 'AAAAAAAA 4444'
                fitness = fitter.RunExit()
                print 'AAAAAAAA 5555'
                print 'iterator done'
                state = State.READY
            sleep(2)

        elif command == 'stop' and state in (State.RUNNING, State.READY):
            state = State.READY
        elif command == 'reset':
            state = State.NOT_READY
            break
        else:
            print 'iterator: bad transition from %s to %s' % (state, command)
            state = State.ERROR
            break
        # Set the status
        com.set_status(state)

    # Set our status one last time
    com.set_status(state)
Example #11
0
def run(directory='.'):
    # Start the communicator:
    com = Communicator('AligDrv_0')
    # FSM loop
    state = State.NOT_READY
    com.set_status(state)
    n_it = 0
    i_it = 0
    p_it = 2
    pt = Paths()
    gz_dir = pt.gz_dir
    dst_dir = pt.dst_dir
    store_location = pt.store_location()
    ##filout = open(os.path.join(gz_dir,'printouts.txt'),'w')

    while True:
        command = com.get_command()
        if command == 'configure' and state == State.NOT_READY:
            ## Remove, if something has left from the previous run
            if n_it == 0 and p_it == 2:
                #print 'Exterminate!'
                dbases = [
                    os.path.join(gz_dir, f) for f in os.listdir(gz_dir)
                    if re.match(r'.*\.(db)$', f) or re.match(r'.*\.(gz)$', f)
                ]
                #print 'Exterminate!!!',dbases
                for db in dbases:
                    os.remove(db)
                #stored = [os.path.join(pt.store_location(),f) for f in os.listdir(pt.store_location())]
                #print 'EXTERMINATE!!!',stored
                #for st in stored: os.remove(st)

            state = State.READY

        elif command == 'start' and state == State.READY:
            state = State.RUNNING

        elif command == 'pause' and state == State.RUNNING:
            state = State.PAUSED
            com.set_status(state)
            if n_it < MaxIt:
                n_it += 1
                i_it += 1

                print asctime(
                ), "Hi, I'm the iterator and I'm running", p_it, i_it, n_it

                ## If enough primary iterations are done
                ## Set the new global iteration
                if i_it > PassIt:
                    i_it = 0
                    p_it += 1
                print 'iteration %d, pass %d' % (i_it, p_it)

                lambdas_location = pt.lambdas_location()
                histos = pt.gethistomaps()
                lams = pt.getlambdamaps()

                for i in range(1 + MaxIt / PassIt):
                    if lambdas_location % i in lams:
                        lams.remove(lambdas_location % i)
                        print 'Remove', lambdas_location % i, 'from', lams

                ## if there are any histograms,
                ## split them between the nodes
                ## to prepare for fitting
                if histos:
                    #print "SPLITTING THE HISTOGRAMS"
                    SplitHistos(gz_dir)

                ## if there are any coefficients,
                ## collect them together and save
                if lams:
                    #print "COLLECTING THE LAMBDAS"
                    CollectLambdas(gz_dir)

                state = State.RUNNING
            else:
                print 'iterator done'
                ## create the output plots
                GetOutput(gz_dir)

                ## clear
                dbases = [
                    os.path.join(gz_dir, f) for f in os.listdir(gz_dir)
                    if re.match(r'.*\.(db)$', f)
                ]
                for db in dbases:
                    os.remove(db)

                stored = [
                    os.path.join(pt.store_location(), f)
                    for f in os.listdir(pt.store_location())
                    if re.match(r'.*\.(db)$', f)
                ]
                for st in stored:
                    os.remove(st)

                state = State.READY
            #sleep(2)
        elif command == 'stop' and state in (State.RUNNING, State.READY):
            ##filout.close()
            state = State.READY
        elif command == 'reset':
            state = State.NOT_READY
            break
        else:
            print 'iterator: bad transition from %s to %s' % (state, command)
            state = State.ERROR
            break
        # Set the status
        com.set_status(state)

    # Set our status one last time
    com.set_status(state)
Example #12
0
def run(index, data_directory):
    # Start the communicator:
    com = Communicator("AligWrk_%d" % index)

    # FSM loop
    state = State.NOT_READY
    com.set_status(state)
    n_it = 0
    p_it = 2
    hn = socket.gethostname()
    pt = Paths(index, hn)
    #filout = open(os.path.join(pt.gz_dir,'AnaPrint_%s.txt'%hn),'w')
    while True:
        command = com.get_command()
        if command == 'configure' and state == State.NOT_READY:
            state = State.READY
        elif command == 'start' and state == State.READY:
            state = State.RUNNING
            com.set_status(state)
            n_it += 1

            ## check, if there's anything to fit
            histos = pt.histos_location_an()
            lambdas = pt.lambdas_location_an()

            print "HISTOS", histos
            print "LAMBDAS", lambdas

            ## Clear everything that was
            ## left from the previous run
            ## Uncomment these lines if you feel
            ## that it is necessary
            if n_it == 1 and p_it == 2:
                print "TIME TO REMOVE"
                if os.path.exists(histos):
                    print "HISTOS", histos
                    os.remove(histos)
                if os.path.exists(lambdas):
                    print "AND LAMBDAS", lambdas
                    os.remove(lambdas)
                #os.system('rm /group/calo/CalibWork/*.db')
                rootfiles = pt.getrootfiles()
                fmdstfiles = pt.getfmdstfiles()
                dstfiles = pt.getdstfiles()
                brunelhistos = pt.getbrunelhistos()
                for bh in brunelhistos:
                    os.remove(bh)
                for ds in dstfiles:
                    os.remove(ds)
                for fm in fmdstfiles:
                    os.remove(fm)
                for rf in rootfiles:
                    os.remove(rf)

            ## if there are any histograms - fit them
            if os.path.exists(histos):
                print 'Fitting the histograms from', histos, 'whith no coefficients'
                RunKali(histos, process='Fit', index=index)

            ## if not do whatever is necessary to obtain them
            else:
                ## first check, what files already exist
                fmdstfiles = pt.getfmdstfiles()
                dstfiles = pt.getdstfiles()
                histos_location = pt.histos_location_an()

                ## path to the calibration constants
                lambdas_location = pt.lambdas_location()
                lambdas_db_location = pt.lambdas_db_location()

                ## Run reconstruction if necessary
                list_of_files, first_run, last_run = pt.getinputfiles()
                if not dstfiles:
                    print "Running event reconstruction at first"

                    ## If there are no input files, we have to immediately go to
                    ## paused.
                    if not list_of_files:
                        time.sleep(random.uniform(0.5, 1.5))
                        state = State.PAUSED
                        com.set_status(state)
                        continue

                    RunBrunel(list_of_files, index, first_run, last_run)

                    dstfiles = pt.getdstfiles()
                    rootfiles = pt.getrootfiles()
                    for bh in rootfiles:
                        os.system('chmod a+rwx ' + bh)
                        os.system('mv %s %shist' % (bh, bh))

                ## Creat the fmdsts and root files if necessary
                rootfiles = pt.getrootfiles()
                if not fmdstfiles or not rootfiles:
                    ## If there are no input files, we have to immediately go to
                    ## paused.
                    if not dstfiles:
                        time.sleep(random.uniform(0.5, 1.5))
                        state = State.PAUSED
                        com.set_status(state)
                        continue

                    print "And create the fmDSTs and tuples"
                    fmDSTprod(dstfiles, index=index)
                    rootfiles = pt.getrootfiles()
                    fmdstfiles = pt.getfmdstfiles()
                    for i in range(len(rootfiles)):
                        os.system('chmod a+rwx ' + rootfiles[i])
                        os.system('chmod a+rwx ' + fmdstfiles[i])

                ## Run re-reconstruction, if it's time already
                print "Should the reconstruction start?", n_it, PassIt
                if n_it > PassIt and os.path.exists(
                        lambdas_db_location % p_it):
                    print "==" * 20
                    print "Running the re-reconstruction"
                    print "==" * 20
                    ## If there are no input files, we have to immediately go to
                    ## paused.
                    if not fmdstfiles:
                        time.sleep(random.uniform(0.5, 1.5))
                        state = State.PAUSED
                        com.set_status(state)
                        continue

                    #fmdst = fmdstfiles[0]
                    print lambdas_db_location % p_it
                    fmDSTprod(fmdstfiles, lambdas_db_location % p_it, index)
                    rootfiles = pt.getrootfiles()
                    n_it = 0
                    p_it += 1
                    # get the new root files after the re-reconstruction
                elif n_it > PassIt and not os.path.exists(
                        lambdas_db_location % p_it):
                    print "Can't make re-reconstruction without coefficients"
                    break

                ## check for the calibration constants
                lambdas = None
                if os.path.exists(lambdas_location % p_it):
                    lambdas = lambdas_location % p_it

                ## If there are no input files, we have to immediately go to
                ## paused.
                if not rootfiles:
                    time.sleep(random.uniform(0.5, 1.5))
                    state = State.PAUSED
                    com.set_status(state)
                    continue

                ## fill the histograms from the corresponding root file
                print len(rootfiles)
                RunKali(rootfiles[0], lambdas=lambdas, index=index)

                #if n_it == PassIt and p_it == 2:
                #    rootfiles = [os.path.join(pt.dst_dir,f) for f in os.listdir(pt.dst_dir) if re.match(r'.*\.(root|ROOT)$', f)]
                #    for rf in rootfiles: os.remove(rf)

                #    fmdstfiles = [os.path.join(pt.dst_dir,f) for f in os.listdir(pt.dst_dir) if re.match(r'.*\.(fmdst|fmDST)$', f)]
                #    for fm in fmdstfiles: os.remove(fm)

                #   dstfiles = [os.path.join(pt.dst_dir,f) for f in os.listdir(pt.dst_dir) if re.match(r'.*\.(dst|DST)$', f)]
                #    for ds in dstfiles: os.remove(ds)

            state = State.PAUSED

        elif command == 'stop' and state == State.PAUSED:
            state = State.READY
        elif command == 'reset':
            state = State.NOT_READY
            break
        else:
            print 'analyzer: bad transition from %s to %s' % (state, command)
            state = State.ERROR
            break

        time.sleep(random.uniform(0.5, 1.5))
        # Set the status
        com.set_status(state)

    time.sleep(random.uniform(0.5, 1.5))
    # Set the status one last time.
    com.set_status(state)
Example #13
0
 def __init__(self, db_path: str):
     self.db_interface = DBInterface.DBInterface(db_path)
     self.communicator = Communicator.Communicator(self.db_interface)
     # @TODO Check if communicator is working, else disable API features but work otherwise
     self.model = Model.Model(self.db_interface)
Example #14
0
def run(directory='.'):
    # Start the communicator:
    com = Communicator('ALIGNITER')

    # FSM loop
    state = State.NOT_READY
    com.set_status(state)
    n_it = 0
    i_it = 0
    p_it = 2
    pt = Paths()
    gz_dir = pt.gz_dir
    dst_dir = pt.dst_dir
    #pt = Paths(directory)
    store_location = pt.store_location()
    while True:
        command = com.get_command()
        if command == 'configure' and state == State.NOT_READY:
            ## find the last one saved and
            ## save current as the next one
            if n_it == 0:
                StoredHistoPath = pt.histos_location_it()
                ih = 1
                Pass = 1
                while True:
                    if ih > PassIt / 2:
                        Pass += 1
                        ih = 1
                    if os.path.exists(
                            StoredHistoPath %
                        (Pass, ih)):  ## look through all the existing files
                        ih += 1
                        continue
                    else:  ## write to the file next to the latest existing
                        n_it = ih - 1
                        p_it = Pass
                        break

            state = State.READY
        elif command == 'start' and state == State.READY:
            state = State.RUNNING
        elif command == 'pause' and state == State.RUNNING:
            state = State.PAUSED
            com.set_status(state)
            if n_it < MaxIt:
                n_it += 1
                i_it += 1

                ## If enough primary iterations are done
                ## Set the new global iteration
                if i_it > PassIt:
                    i_it = 0
                    p_it += 1
                print 'iteration %d, pass %d' % (i_it, p_it)

                #RunKali(lambdas_location, 'Fit')
                lambdas_location = pt.lambdas_location()
                #lambdas_location_it= pt.lambdas_location_it()
                histos = pt.gethistomaps()
                lams = pt.getlambdamaps()

                for i in range(1 + MaxIt / PassIt):
                    if lambdas_location % i in lams:
                        lams.remove(lambdas_location % i)
                        print 'Remove', lambdas_location % i, 'from', lams
                #if lambdas_location in lams: lams.remove(lambdas_location) ; print 'Remove', lambdas_location, 'from', lams

                if histos:
                    #print "SPLITTING THE FILLED HISTOGRAMS"
                    #SplitHistos   (directory)
                    SplitHistos(gz_dir)
                    state = State.RUNNING

                if lams:
                    #print "COLLECTING THE CALIBRATION COEFFICIENTS"
                    #CollectLambdas(directory)
                    CollectLambdas(gz_dir)

                #print 'Copying lambdas from ', lambdas_location, ' to ', lambdas_location_it
                #os.system('cp '+lambdas_location+' '+lambdas_location_it)

                state = State.RUNNING
            else:
                print 'iterator done'
                #GetOutput(directory)
                GetOutput(gz_dir)
                ## clear
                dbases = [
                    os.path.join(gz_dir, f) for f in os.listdir(gz_dir)
                    if re.match(r'.*\.(db)$', f)
                ]
                #for db in dbases: os.remove(db)

                rootfiles = [
                    os.path.join(dst_dir, f) for f in os.listdir(dst_dir)
                    if re.match(r'.*\.(root|ROOT)$', f)
                ]
                #for rf in rootfiles: os.remove(rf)

                fmdstfiles = [
                    os.path.join(dst_dir, f) for f in os.listdir(dst_dir)
                    if re.match(r'.*\.(fmdst|fmDST)$', f)
                ]
                #for fm in fmdstfiles: os.remove(fm)

                dstfiles = [
                    os.path.join(dst_dir, f) for f in os.listdir(dst_dir)
                    if re.match(r'.*\.(dst|DST)$', f)
                ]
                #for ds in dstfiles: os.remove(ds)

                stored = [
                    os.path.join(pt.store_location(), f)
                    for f in os.listdir(pt.store_location())
                    if re.match(r'.*\.(gz)$', f)
                ]
                #for st in stored: os.remove(st)

                state = State.READY
            #sleep(2)
        elif command == 'stop' and state in (State.RUNNING, State.READY):
            state = State.READY
        elif command == 'reset':
            state = State.NOT_READY
            break
        else:
            print 'iterator: bad transition from %s to %s' % (state, command)
            state = State.ERROR
            break
        # Set the status
        com.set_status(state)

    # Set our status one last time
    com.set_status(state)
Example #15
0
    def __init__(self):

        self.communicator = Communicator.Communicator("ControlTopic",
                                                      "Control",
                                                      "ControlPython", 10000)
        self.controller = None
Example #16
0
def run(index, input_directory):
    # Start the communicator:
    com = Communicator("ALIGNWORK_%02d" % index)

    # FSM loop
    state = State.NOT_READY
    com.set_status(state)
    n_it = 0
    p_it = 2
    hn = socket.gethostname()
    pt = Paths(index, hn, os.path.dirname(input_directory))
    #pt = Paths(input_file,index,hn)
    while True:
        command = com.get_command()
        if command == 'configure' and state == State.NOT_READY:
            state = State.READY
        elif command == 'start' and state == State.READY:
            state = State.RUNNING
            com.set_status(state)
            n_it += 1

            ## find the last one saved and
            ## save current as the next one
            if n_it == 1:
                StoredHistoPath = pt.histos_location_it()
                ih = 1
                Pass = 1
                while True:
                    if ih > PassIt / 2:
                        Pass += 1
                        ih = 1
                    if os.path.exists(
                            StoredHistoPath %
                        (Pass, ih)):  ## look through all the existing files
                        ih += 1
                        continue
                    else:  ## write to the file next to the latest existing
                        n_it = ih
                        p_it = Pass
                        break

            ## check, if there's anything to fit
            histos = pt.histos_location_an()
            #print histos
            lambdas = pt.lambdas_location_an()
            #if pt.lambdas_location() in lambdas: lambdas.remove(pt.lambdas_location())
            #print lambdas

            if os.path.exists(histos):
                print 'Fitting the histograms from', histos, 'whith no coefficients'
                RunKali(histos, process='Fit', index=index)
                state = State.PAUSED

            # if not, fill the histograms, or do whatever is necessary for it etc.
            else:
                ## first check, what files already exist
                fmdstfiles = pt.getfmdstfiles()
                dstfiles = pt.getdstfiles()
                histos_location = pt.histos_location_an()
                rootfiles = pt.getrootfiles()

                ## path to the calibration constants
                lambdas_location = pt.lambdas_location()
                lambdas_db_location = pt.lambdas_db_location()

                ## Run reconstruction if necessary
                if not dstfiles:
                    print "Running event reconstruction at first"
                    list_of_files = pt.getinputfiles()[index]
                    RunBrunel(list_of_files, index)
                    #RunBrunel(input_file, index)

                    dstfiles = pt.getdstfiles()

                ## Creat the fmdsts and root files if necessary
                #if not fmdstfiles and not rootfiles:
                if not rootfiles:
                    print "And create the fmDSTs and tuples"
                    fmDSTprod(dstfiles[0], index=index)
                    rootfiles = pt.getrootfiles()
                    fmdstfiles = pt.getfmdstfiles()

                ## Run re-reconstruction, if it's time already
                print "Should the reconstruction start?", n_it, PassIt
                if n_it > PassIt and os.path.exists(
                        lambdas_db_location % p_it):
                    print "==" * 20
                    print "Running the re-reconstruction"
                    print "==" * 20
                    fmdsts = pt.getfmdstfiles()
                    #print lambdas_db_location%p_it
                    fmDSTprod(fmdsts[index], lambdas_db_location % p_it, index)
                    rootfiles = pt.getrootfiles()
                    n_it = 0
                    p_it += 1
                    # get the new root files after the re-reconstruction
                elif n_it > PassIt and not os.path.exists(
                        lambdas_db_location % p_it):
                    print "Can't make re-reconstruction without coefficients"
                    break

                ## check for the calibration constants
                lambdas = None
                if os.path.exists(lambdas_location % p_it):
                    lambdas = lambdas_location % p_it

                ## fill the histograms from the corresponding root file
                RunKali(rootfiles[0], lambdas=lambdas, index=index)

                state = State.PAUSED

        elif command == 'stop' and state == State.PAUSED:
            state = State.READY
        elif command == 'reset':
            state = State.NOT_READY
            break
        else:
            print 'analyzer: bad transition from %s to %s' % (state, command)
            state = State.ERROR
            break

        time.sleep(random.uniform(0.5, 1.5))
        # Set the status
        com.set_status(state)

    time.sleep(random.uniform(0.5, 1.5))
    # Set the status one last time.
    com.set_status(state)
Example #17
0
 def __init__(self):
     self.communicator = Communicator.Communicator("WorldStateTopic",
                                                   "WorldState",
                                                   "WorldState", 10012)
     self.controller = None