Ejemplo n.º 1
0
  void runToyTest()
  {
    srand(0);
    OsmMap::resetCounters();
    Settings::getInstance().clear();

    FileUtils::removeDir("test-output/conflate/TileConflatorTest.osm-cache");

    shared_ptr<TileWorker2> worker(new LocalTileWorker2());
    FourPassManager uut(worker);
    // ~240m
    uut.setBuffer(8.0 / 3600.0);
    uut.setMaxNodesPerBox(5000);
    Envelope env(-77.039, -77.033, 38.892, 38.896);
    shared_ptr<OpList> op(new OpList());
    op->addOp(shared_ptr<OsmMapOperation>(new MapCropper(env)));
    op->addOp(shared_ptr<OsmMapOperation>(new SuperfluousNodeRemover()));
    op->addOp(shared_ptr<OsmMapOperation>(new MergeNearbyNodes(10)));
    uut.setOperation(op);

    uut.setSources("test-files/DcGisRoads.osm", "test-files/DcTigerRoads.osm");

    uut.apply("test-output/fourpass/FourPassManagerTest.osm");

    HOOT_FILE_EQUALS("test-files/fourpass/FourPassManagerTest.osm",
                     "test-output/fourpass/FourPassManagerTest.osm");
  }
Ejemplo n.º 2
0
/**
 * \brief tests the wait method with an inital count not set to zero
 */
TEST(Semaphore, waitTest){
    OS::SSemaphore uut(1);
    CHECK_EQUAL(uut.getSemaphoreCount(), 1);
    uut.wait();
    CHECK_EQUAL(uut.getSemaphoreCount(), 0);
    //If it gets here, the test was successful, as the program didn't hang (no blocking should happen when semahpore count greater than zero
}
  void runBuildingMatchCandidateCountTest()
  {
    OsmReader reader;
    shared_ptr<OsmMap> map(new OsmMap());
    OsmMap::resetCounters();
    reader.setDefaultStatus(Status::Unknown1);
    reader.read("test-files/conflate/unified/AllDataTypesA.osm", map);
    reader.setDefaultStatus(Status::Unknown2);
    reader.read("test-files/conflate/unified/AllDataTypesB.osm", map);
    MapProjector::projectToPlanar(map);

    QStringList matchCreators;

    matchCreators.clear();
    matchCreators.append("hoot::BuildingMatchCreator");
    MatchFactory::getInstance().reset();
    MatchFactory::_setMatchCreators(matchCreators);
    MatchCandidateCountVisitor uut(MatchFactory::getInstance().getCreators());
    map->visitRo(uut);
    CPPUNIT_ASSERT_EQUAL((int)18, (int)uut.getStat());
    QMap<QString, long> matchCandidateCountsByMatchCreator =
      any_cast<QMap<QString, long> >(uut.getData());
    CPPUNIT_ASSERT_EQUAL(1, matchCandidateCountsByMatchCreator.size());
    CPPUNIT_ASSERT_EQUAL((long)18, matchCandidateCountsByMatchCreator["hoot::BuildingMatchCreator"]);
  }
Ejemplo n.º 4
0
/**
 * \brief tests the tryWait method
 */
TEST(Semaphore, tryWaitTestGreaterThanZero){
    OS::SSemaphore uut(1);
    CHECK_EQUAL(uut.getSemaphoreCount(), 1);
    CHECK(uut.tryWait()); //Should return true, as the count is greater than zero.
    CHECK(!uut.tryWait()); //Should return false, as the count is zero.
    //The program should NOT hang
}
Ejemplo n.º 5
0
  void runTest()
  {
    /*
     *              | <unassigned> | California | Hostel | in  | Hollywood
     * <unassigned> | -            | .8         | 1      | 0.5 | 1
     * Hotel        | 1            | 0.98       | 0.1    | 1   | 0.8
     * California   | 0.8          | 0.0        | 0.98   | 1   | 0.99
     */

    ScoreMatrix uut(5, 3);

    uut.set(0, 1, 1);
    uut.set(0, 2, 0.8);

    uut.set(1, 0, .8);
    uut.set(1, 1, .98);
    uut.set(1, 2, 0.0);

    uut.set(2, 0, 1);
    uut.set(2, 1, .1);
    uut.set(2, 2, .98);

    uut.set(3, 0, .5);
    uut.set(3, 1, 1);
    uut.set(3, 2, 1);

    uut.set(4, 0, 1);
    uut.set(4, 1, .8);
    uut.set(4, 2, .99);

    HOOT_STR_EQUALS(1.6, uut.minSumScore());
  }
  void individualManipulationsTest()
  {
    OsmReader reader;

    shared_ptr<OsmMap> map(new OsmMap());
    OsmMap::resetCounters();
    reader.read("test-files/manipulators/WayMergeManipulation.osm", map);

    MapReprojector::reprojectToOrthographic(map);

    long left = map->findWays("note", "3")[0];
    long right = map->findWays("note", "4")[0];

    map->getWay(left)->setStatus(Status::Unknown1);
    map->getWay(right)->setStatus(Status::Unknown2);

    WayMergeManipulation uut(left, right, map, 10.0);
    set<ElementId> ignored1, ignored2;
    shared_ptr<OsmMap> after(new OsmMap(map));
    uut.applyManipulation(after, ignored1, ignored2);

    MapReprojector::reprojectToWgs84(after);

    QDir().mkpath("test-output/manipulators/");

    OsmWriter writer;
    writer.setIncludeCompatibilityTags(false);
    writer.write(after, "test-output/manipulators/WayMergeManipulation.osm");

    HOOT_FILE_EQUALS("test-output/manipulators/WayMergeManipulation.osm",
                     "test-files/manipulators/WayMergeManipulationOutput.osm");
  }
  void runBuildingsTest()
  {
    OsmReader reader;

    OsmMap::resetCounters();
    shared_ptr<OsmMap> map(new OsmMap());
    reader.setDefaultStatus(Status::Unknown1);
    reader.read("test-files/ToyBuildingsTestA.osm", map);
    reader.setDefaultStatus(Status::Unknown2);
    reader.read("test-files/ToyBuildingsTestB.osm", map);

    MapReprojector::reprojectToPlanar(map);

    vector<long> r1 = map->findWays("REF1", "Target");
    vector<long> r2 = map->findWays("name", "Target Grocery");

    shared_ptr<const Way> w1 = map->getWay(r1[0]);
    shared_ptr<const Way> w2 = map->getWay(r2[0]);

    EdgeDistanceExtractor uut(new MeanAggregator(), 5.0);
    CPPUNIT_ASSERT_DOUBLES_EQUAL(28.9069, uut.distance(*map, w1, w2), 0.01);

    EdgeDistanceExtractor uut2(new RmseAggregator(), 5.0);
    CPPUNIT_ASSERT_DOUBLES_EQUAL(41.2179, uut2.distance(*map, w1, w2), 0.01);

    EdgeDistanceExtractor uut3(new MinAggregator(), 5.0);
    CPPUNIT_ASSERT_DOUBLES_EQUAL(0.380561, uut3.distance(*map, w1, w2), 0.01);

    EdgeDistanceExtractor uut4(new QuantileAggregator(0.5), 5.0);
    CPPUNIT_ASSERT_DOUBLES_EQUAL(7.28364, uut4.distance(*map, w1, w2), 0.01);

    EdgeDistanceExtractor uut5(new QuantileAggregator(0.1), 5.0);
    CPPUNIT_ASSERT_DOUBLES_EQUAL(1.34317, uut5.distance(*map, w1, w2), 0.01);
  }
Ejemplo n.º 8
0
  void memoryTest()
  {
    MemoryPageStore uut(100);

    CPPUNIT_ASSERT_EQUAL(100, uut.getPageSize());
    
    testPageStore(uut);
  }
Ejemplo n.º 9
0
/**
 * \brief tests the timedWait method not At zero
 */
TEST(Semaphore, timedWaitTestNotAtZero){
    OS::SSemaphore uut(1);
    CHECK_EQUAL(uut.getSemaphoreCount(), 1);
    CHECK(uut.timedWait(10));
    CHECK_EQUAL(uut.getSemaphoreCount(), 0);
    CHECK(!uut.timedWait(10));
    CHECK_EQUAL(uut.getSemaphoreCount(), 0);
}
Ejemplo n.º 10
0
  void testAll()
  {
    string outDir = "test-output/hadoop/HadoopTileWorker2Test/";
    Hdfs fs;
    if (fs.exists(outDir))
    {
      fs.deletePath(outDir, true);
    }
    fs.copyFromLocal("test-files/DcTigerRoads.pbf", outDir + "in1.pbf/DcTigerRoads.pbf");
    fs.copyFromLocal("test-files/DcGisRoads.pbf", outDir + "in2.pbf/DcGisRoads.pbf");

    shared_ptr<TileWorker2> worker(new HadoopTileWorker2());
    FourPassManager uut(worker);
    // ~240m
    uut.setBuffer(8.0 / 3600.0);
    uut.setMaxNodesPerBox(5000);

    uut.setSources(QString::fromStdString(outDir) + "in1.pbf",
                   QString::fromStdString(outDir) + "in2.pbf");

    Envelope env(-77.039, -77.033, 38.892, 38.896);
    shared_ptr<OpList> op(new OpList());
    op->addOp(shared_ptr<OsmMapOperation>(new MapCropper(env)));
    op->addOp(shared_ptr<OsmMapOperation>(new MergeNearbyNodes(10)));

    uut.setOperation(op);
    uut.apply(QString::fromStdString(outDir) + "HadoopTileWorker2Test.pbf");

    shared_ptr<OsmMap> map(new OsmMap);
    PbfReader reader(true);
    reader.setUseFileStatus(true);
    std::vector<FileStatus> status = fs.listStatus(outDir + "HadoopTileWorker2Test.pbf");
    for (size_t i = 0; i < status.size(); i++)
    {
      const string& path = status[i].getPath();
      LOG_INFO(path);
      if (QString::fromStdString(path).endsWith(".pbf"))
      {
        shared_ptr<istream> is(fs.open(path));
        reader.parse(is.get(), map);
      }
    }

    QDir().mkpath(QString::fromStdString(outDir));

    OsmWriter writer;
    writer.setIncludeHootInfo(true);
    writer.write(map, QString::fromStdString(outDir + "/result.osm"));

    HOOT_FILE_EQUALS("test-files/hadoop/HadoopTileWorker2Test/result.osm",
                     "test-output/hadoop/HadoopTileWorker2Test/result.osm");
  }
Ejemplo n.º 11
0
  void testAll()
  {
    srand(0);
    OsmMap::resetCounters();
    Settings::getInstance().clear();
    conf().set(ConfigOptions().getUuidHelperRepeatableKey(), true);
    conf().set(ConfigOptions().getUnifyOptimizerTimeLimitKey(), -1);

    string outDir = "test-output/hadoop/HadoopTileWorkerTest/";
    Hdfs fs;
    if (fs.exists(outDir))
    {
      fs.deletePath(outDir, true);
    }
    fs.copyFromLocal("test-files/DcTigerRoads.pbf", outDir + "in1.pbf/DcTigerRoads.pbf");
    fs.copyFromLocal("test-files/DcGisRoads.pbf", outDir + "in2.pbf/DcGisRoads.pbf");

    shared_ptr<TileWorker> worker(new HadoopTileWorker());
    TileConflator uut(worker);
    // ~240m
    uut.setBuffer(8.0 / 3600.0);
    uut.setMaxNodesPerBox(5000);

    uut.setSources(QString::fromStdString(outDir) + "in1.pbf",
                   QString::fromStdString(outDir) + "in2.pbf");

    uut.conflate(QString::fromStdString(outDir) + "HadoopTileWorkerTest.pbf");

    shared_ptr<OsmMap> map(new OsmMap);
    PbfReader reader(true);
    reader.setUseFileStatus(true);
    std::vector<FileStatus> status = fs.listStatus(outDir + "HadoopTileWorkerTest.pbf", true);
    for (size_t i = 0; i < status.size(); i++)
    {
      const string& path = status[i].getPath();
      LOG_INFO(path);
      if (QString::fromStdString(path).endsWith(".pbf"))
      {
        shared_ptr<istream> is(fs.open(path));
        reader.parse(is.get(), map);
      }
    }

    QDir().mkpath(QString::fromStdString(outDir));

    OsmWriter writer;
    writer.setIncludeHootInfo(true);
    writer.write(map, QString::fromStdString(outDir + "/result.osm"));

    HOOT_FILE_EQUALS("test-files/hadoop/HadoopTileWorkerTest/result.osm",
                     "test-output/hadoop/HadoopTileWorkerTest/result.osm");
  }
Ejemplo n.º 12
0
  void fileTest()
  {
    if (QFile::exists("dum.dat"))
    {
      QFile::remove("dum.dat");
    }
    {
      FilePageStore uut(100, "dum.dat");

      CPPUNIT_ASSERT_EQUAL(100, uut.getPageSize());

      testPageStore(uut);
    }
    {
      FilePageStore uut(100, "dum.dat", true);

      for (int i = 0; i < 100; i++)
      {
        boost::shared_ptr<Page> p = uut.getPage(_ids[i]);
        verifyPage(p);
      }
    }
  }
Ejemplo n.º 13
0
  void runLayerNameFilterTest()
  {
    // Great bit of code taken from TranslatedTagDifferencer.cpp
    // We just need a standard ScriptTranslator for this test.
    shared_ptr<ScriptTranslator> uut(ScriptTranslatorFactory::getInstance().createTranslator(
                                      "test-files/io/SampleTranslation.js"));

    if (!uut)
    {
      throw HootException("Error allocating translator.");
    }

    // Check that we can access a value from a Javascript function
    HOOT_STR_EQUALS("Papa Smurf",uut->getLayerNameFilter());
  }
Ejemplo n.º 14
0
/* rotate
 *
 * Multiply the active matrix by a rotation matrix.
 */
void canvashdl::rotate(float angle, vec3f axis)
{
	vec3f u = norm(axis);
	mat3f S(0.0, -u[2], u[1],
			u[2], 0.0, -u[0],
			-u[1], u[0], 0.0);
	mat3f uut(axis[0]*axis[0], axis[0]*axis[1], axis[0]*axis[2],
			  axis[0]*axis[1], axis[1]*axis[1], axis[1]*axis[2],
			  axis[0]*axis[2], axis[1]*axis[2], axis[2]*axis[2]);

	mat4f R = identity<float, 4, 4>();
	R.set(0,3,0,3, uut + (float)cos(angle)*(identity<float, 3, 3>() - uut) + (float)sin(angle)*S);

	matrices[active_matrix] = matrices[active_matrix]*R;
}
  void individualManipulationsTest()
  {
    OsmReader reader;

    shared_ptr<OsmMap> map(new OsmMap());
    OsmMap::resetCounters();
    reader.setDefaultStatus(Status::Unknown1);
    reader.read("test-files/DividedHighway.osm", map);
    reader.setDefaultStatus(Status::Unknown2);
    reader.read("test-files/UndividedHighway.osm", map);

    MapReprojector::reprojectToOrthographic(map);

    long left = map->findWays("note", "0")[0];
    long right = map->findWays("note", "1")[0];
    long mid = map->findWays("note", "2")[0];

    DividedHighwayManipulation uut(left, right, mid, map, 10.0);
    qDebug() << uut.getScoreEstimate();
    qDebug() << uut.calculateScore(map);
    set<ElementId> ignored1, ignored2;
    shared_ptr<OsmMap> after(new OsmMap(map));
    uut.applyManipulation(after, ignored1, ignored2);

    left = map->findWays("note", "3")[0];
    right = map->findWays("note", "4")[0];
    mid = map->findWays("note", "5")[0];

    DividedHighwayManipulation uut2(left, right, mid, after, 10.0);
    qDebug() << uut2.getScoreEstimate();
    qDebug() << uut2.calculateScore(after);
    uut2.applyManipulation(after, ignored1, ignored2);

    left = map->findWays("note", "6")[0];
    right = map->findWays("note", "7")[0];
    mid = map->findWays("note", "8")[0];

    DividedHighwayManipulation uut3(left, right, mid, after, 10.0);
    qDebug() << uut3.getScoreEstimate();
    qDebug() << uut3.calculateScore(after);
    uut3.applyManipulation(after, ignored1, ignored2);

    MapReprojector::reprojectToWgs84(after);

    OsmWriter writer;
    writer.write(after, "test-output/DividedHighwayManipulatorTest.osm");
  }
Ejemplo n.º 16
0
void WriteMetadataTest::testWritingAfterTypeWritten(void)
{
    QFETCH(QString, entryId);
    QFETCH(QString, message);
    QFETCH(int, tokenType);
    QFETCH(int, hash);
    QFETCH(int, keyEncoding);

    const QString dummyTable(QLatin1String("fake"));

    QHash<QString,QVariant> metadata;
    QHash<QString,QString> paramToTables;

    paramToTables.insert(otp::parameters::hashing::ALGORITHM, dummyTable);
    paramToTables.insert(otp::parameters::key::ENCODING, otp::storage::db::MetadataStorageHandler::OTP_ENTRY_TABLE);
    paramToTables.insert(otp::dummy::parameters::MESSAGE, dummyTable);
    paramToTables.insert(otp::storage::db::MetadataStorageHandler::OTP_ENTRY_TYPE, otp::storage::db::MetadataStorageHandler::OTP_ENTRY_TABLE);

    QSharedPointer<otp::storage::db::MetadataDbManager> db = test::storage::db::prepareFakeMetadataDB(entryId, (otp::storage::OTPTokenType) tokenType, metadata, paramToTables);

    otp::storage::db::Metadata uut(entryId, db);
    QVERIFY2(uut.exists(), "The entry should be considered to exist.");
    QVERIFY2(uut.writeTokenType((otp::storage::OTPTokenType) tokenType), "Writing the token type to an empty metadata object should succeed");

    const QVariant messageValue(message);
    QVERIFY2(uut.writeParam(otp::dummy::parameters::MESSAGE, messageValue), "Writing the message should succeed");

    const QVariant hashValue(hash);
    QVERIFY2(uut.writeParam(otp::parameters::hashing::ALGORITHM, hashValue), "Writing hash algorithm should succeed");

    const QVariant encodingValue(keyEncoding);
    QVERIFY2(uut.writeParam(otp::parameters::key::ENCODING, encodingValue), "Writing the key encoding/type should succeed");

    QVERIFY2(metadata.contains(otp::parameters::hashing::ALGORITHM) == false, "Original metadata storage should not reflect changes to hash algoirthm prior to commit()");
    QVERIFY2(metadata.contains(otp::parameters::key::ENCODING) == false, "Original metadata storage should not reflect changes to key encoding/type prior to commit()");
    QVERIFY2(metadata.contains(otp::dummy::parameters::MESSAGE) == false, "Original metadata storage should not reflect changes to the message prior to commit()");

    test::storage::db::checkType(uut, (otp::storage::OTPTokenType) tokenType, "Reading token type should succeed");
    test::storage::db::checkInt(uut, otp::parameters::hashing::ALGORITHM, hash, "Reading the hash algorithm parameter should succeed");
    test::storage::db::checkInt(uut, otp::parameters::key::ENCODING, keyEncoding, "Reading the key encoding/type parameter should succeed");
    test::storage::db::checkString(uut, otp::dummy::parameters::MESSAGE, message, "Reading the message parameter should succeed");
}
Ejemplo n.º 17
0
  void simpleTest()
  {
    DisjointSet uut(10);

    uut.join(0, 1);
    CPPUNIT_ASSERT_EQUAL(1, uut.find(0));
    uut.join(1, 2);
    CPPUNIT_ASSERT_EQUAL(1, uut.find(0));
    uut.join(2, 0);
    CPPUNIT_ASSERT_EQUAL(1, uut.find(0));
    uut.join(4, 3);
    uut.join(5, 3);
    uut.join(6, 3);
    CPPUNIT_ASSERT_EQUAL(3, uut.find(4));
    uut.join(6, 0);
    CPPUNIT_ASSERT_EQUAL(1, uut.find(0));
    CPPUNIT_ASSERT_EQUAL(1, uut.find(3));
    CPPUNIT_ASSERT_EQUAL(1, uut.find(4));
    CPPUNIT_ASSERT_EQUAL(1, uut.find(6));
  }
Ejemplo n.º 18
0
  void runToyTest()
  {
    srand(0);
    OsmMap::resetCounters();
    Settings::getInstance().clear();

    FileUtils::removeDir("test-output/conflate/TileConflatorTest.osm-cache");

    shared_ptr<TileWorker> worker(new LocalTileWorker());
    TileConflator uut(worker);
    // ~240m
    uut.setBuffer(8.0 / 3600.0);
    uut.setMaxNodesPerBox(5000);

    uut.setSources("test-files/DcGisRoads.osm", "test-files/DcTigerRoads.osm");

    uut.conflate("test-output/conflate/TileConflatorTest.osm");

    CPPUNIT_ASSERT_EQUAL(true, TestUtils::compareMaps("test-files/conflate/TileConflatorTest.osm",
      "test-output/conflate/TileConflatorTest.osm"));
  }
  void simpleTest()
  {
    Tgs::Random::instance()->seed(0);
    KernelEstimationInterpolator uut(.1);

    shared_ptr<DataFrame> dfPtr(new DataFrame());
    DataFrame& df = *dfPtr;
    vector<string> labels;
    labels.push_back("x");
    labels.push_back("y");
    labels.push_back("h");
    vector<int> types(3, DataFrame::Numerical);
    df.setFactorLabels(labels);
    df.setFactorTypes(types);

    // is there a cleaner way?
    vector<double> d(3);

    for (size_t i = 0; i < 500; i++)
    {
      d[0] = Random::instance()->generateUniform() * 2 - 1;
      d[1] = Random::instance()->generateUniform() * 2 - 1;
      d[2] = Normal::normal(d[0], .5);
      df.addDataVector("", d);
    }

    uut.setData(dfPtr);
    vector<string> ind;
    ind.push_back("x");
    //ind.push_back("y");
    uut.setIndependentColumns(ind);
    vector<string> dep;
    dep.push_back("h");
    uut.setDependentColumns(dep);

    uut.setSigma(0.002);
    CPPUNIT_ASSERT_DOUBLES_EQUAL(0.3247, uut.estimateError(), 0.0001);
    uut.setSigma(0.008);
    CPPUNIT_ASSERT_DOUBLES_EQUAL(0.0721615, uut.estimateError(), 0.00001);
  }
  void runTest()
  {
    //test highway (linestring)
    shared_ptr<OsmMap> map(new OsmMap());
    _map = map;

    shared_ptr<Way> w1(new Way(Status::Unknown1, map->createNextWayId(), 13.0));
    w1->setTag("highway", "track");
    w1->setTag("name", "w1");
    w1->addNode(createNode(-104.9, 38.855)->getId());
    w1->addNode(createNode(-104.899, 38.8549)->getId());
    _map->addWay(w1);

    shared_ptr<Way> w2(new Way(Status::Unknown1, map->createNextWayId(), 13.0));
    w2->setTag("highway", "road");
    w2->setTag("name", "w2");
    w2->addNode(createNode(-104.9, 38.8545)->getId());
    w2->addNode(createNode(-104.8988, 38.8555)->getId());
     _map->addWay(w2);

    shared_ptr<Way> w3(new Way(Status::Unknown1, map->createNextWayId(), 13.0));
    w3->setTag("highway", "track");
    w3->setTag("name", "w1");
    w3->addNode(createNode(-104.9, 38.855)->getId());
    w3->addNode(createNode(-104.899, 38.8549)->getId());
    _map->addWay(w3);

    WeightedMetricDistanceExtractor uut(0, 0, 0.1);
    const OsmMap* constMap = const_cast<const OsmMap*>(_map.get());

    CPPUNIT_ASSERT_DOUBLES_EQUAL(0.00384111,
                                 uut.extract(*constMap, boost::const_pointer_cast<const Way>(w1), boost::const_pointer_cast<const Way>(w2)),
                                 0.00001);

   //test same features, should return 0
    CPPUNIT_ASSERT_DOUBLES_EQUAL(0.0,
                                 uut.extract(*constMap, boost::const_pointer_cast<const Way>(w1), boost::const_pointer_cast<const Way>(w3)),
                                 0.0);
  }
Ejemplo n.º 21
0
void sp_wrap::run
(
	unsigned q__io[5][9][2],
	unsigned wg__io[5][9][2],
	unsigned hstr__io[5][9][2],
	unsigned cpat__io[5][9][2],

	unsigned bt_phi__io [3],
	unsigned bt_theta__io [3],
	unsigned bt_cpattern__io [3],
	// ph and th deltas from best stations
	// [best_track_num], last index: [0] - best pair of stations, [1] - second best pair
	unsigned bt_delta_ph__io [3][2],
	unsigned bt_delta_th__io [3][2], 
	unsigned bt_sign_ph__io[3][2],
	unsigned bt_sign_th__io[3][2],
	// ranks [best_track_num]
	unsigned bt_rank__io [3],
	// segment IDs
	// [best_track_num][station 0-3]
	unsigned bt_vi__io [3][5], // valid
	unsigned bt_hi__io [3][5], // bx index
	unsigned bt_ci__io [3][5], // chamber
	unsigned bt_si__io [3][5] // segment
)
{

  static bool first_time = true;

  if (!built)
    {
      	sim_lib_init();
		seg_ch = 2;
		bw_ph = 8;
		bw_th = 7;
		bw_fph = 12;
		bw_fth = 8;
		bw_wg = 7;
		bw_ds = 7;
		bw_hs = 8;
		pat_w_st3 = 3;
		pat_w_st1 = pat_w_st3 + 1;
		full_pat_w_st3 = (1 << (pat_w_st3+1)) - 1;
		full_pat_w_st1 = (1 << (pat_w_st1+1)) - 1;
		padding_w_st1 = full_pat_w_st1 / 2;
		padding_w_st3 = full_pat_w_st3 / 2;
		red_pat_w_st3 = pat_w_st3 * 2 + 1;
		red_pat_w_st1 = pat_w_st1 * 2 + 1;
		fold = 4;
		th_ch11 = seg_ch*seg_ch;
		bw_q = 4;
		bw_addr = 7;
		ph_raw_w = (1 << pat_w_st3) * 15;
		th_raw_w = (1 << bw_th);
		max_drift = 3;
		bw_phi = 12;
		bw_eta = 7;
		ph_hit_w = 40+4;
		ph_hit_w20 = ph_hit_w;
		ph_hit_w10 = 20+4;
		th_hit_w = 56 + 8;
		endcap = 1;
		n_strips = (station <= 1 && cscid <= 2) ? 64 :
						 (station <= 1 && cscid >= 6) ? 64 : 80;
		n_wg = (station <= 1 && cscid <= 3) ? 48  :
					 (station <= 1 && cscid >= 6) ? 32  :
					 (station == 2 && cscid <= 3) ? 112 :
					 (station >= 3 && cscid <= 3) ? 96  : 64;
		th_coverage = (station <= 1 && cscid <= 2) ? 45  :
						 (station <= 1 && cscid >= 6) ? 27  :
						 (station <= 1 && cscid >= 3) ? 39  :
						 (station == 2 && cscid <= 2) ? 43  :
						 (station == 2 && cscid >= 3) ? 56  :
						 (station == 3 && cscid <= 2) ? 34  :
						 (station == 3 && cscid >= 3) ? 52  :
						 (station == 4 && cscid <= 2) ? 28  :
						 (station == 4 && cscid >= 3) ? 50  : 0;
		ph_coverage = (station <= 1 && cscid >= 6) ? 15 : //30 :
						   (station >= 2 && cscid <= 2) ? 40 : 20;
		th_ch = (station <= 1 && cscid <= 2) ? (seg_ch*seg_ch) : seg_ch;
		ph_reverse = (endcap == 1 && station >= 3) ? 1 : 
			   			   (endcap == 2 && station <  3) ? 1 : 0;
		th_mem_sz = (1 << bw_addr);
		th_corr_mem_sz = (1 << bw_addr);
		mult_bw = bw_fph + 11;
		ph_zone_bnd1 = (station <= 1 && cscid <= 2) ? 41 :
							(station == 2 && cscid <= 2) ? 41 :
							(station == 2 && cscid >  2) ? 87 :
							(station == 3 && cscid >  2) ? 49 :
							(station == 4 && cscid >  2) ? 49 : 127;
		ph_zone_bnd2 = (station == 3 && cscid >  2) ? 87 : 127;
		zone_overlap = 2;
		bwr = 6;
		bpow = 6;
		cnr = (1 << bpow);
		cnrex = ph_raw_w;
		build();
    }

  	if (first_time)
    {
		first_time = false;

		iadr = 0;
		s = 0;
		i = 0;
		j = 0;
		good_ev_cnt = 0;
		found_tr = 0;
		found_cand = 0;

		uut
			(
				qi,
				wgi,
				hstri,
		        cpati,
				csi,
				pps_csi,
				seli,
				addri,
				r_ini,
				r_outo,
				wei,
				bt_phi,
				bt_theta,
                bt_cpattern,
				bt_delta_ph,
				bt_delta_th,
				bt_sign_ph,
				bt_sign_th,
				bt_rank,
				bt_vi,
				bt_hi,
				bt_ci,
				bt_si,
				clki,
				clki
				); 

			// fill th LUTs
			Sreadmemh(edm::FileInPath("L1Trigger/CSCTrackFinder/data/core_upgrade/vl_lut/vl_th_corr_lut_endcap_1_sec_1_sub_1_st_1_ch_1.lut").fullPath().c_str(), uut.pcs.genblk.station11[0].csc11[0].pc11.th_corr_mem);
			Sreadmemh(edm::FileInPath("L1Trigger/CSCTrackFinder/data/core_upgrade/vl_lut/vl_th_corr_lut_endcap_1_sec_1_sub_1_st_1_ch_2.lut").fullPath().c_str(), uut.pcs.genblk.station11[0].csc11[1].pc11.th_corr_mem);
			Sreadmemh(edm::FileInPath("L1Trigger/CSCTrackFinder/data/core_upgrade/vl_lut/vl_th_corr_lut_endcap_1_sec_1_sub_1_st_1_ch_3.lut").fullPath().c_str(), uut.pcs.genblk.station11[0].csc11[2].pc11.th_corr_mem);
			Sreadmemh(edm::FileInPath("L1Trigger/CSCTrackFinder/data/core_upgrade/vl_lut/vl_th_corr_lut_endcap_1_sec_1_sub_2_st_1_ch_1.lut").fullPath().c_str(), uut.pcs.genblk.station11[1].csc11[0].pc11.th_corr_mem);
			Sreadmemh(edm::FileInPath("L1Trigger/CSCTrackFinder/data/core_upgrade/vl_lut/vl_th_corr_lut_endcap_1_sec_1_sub_2_st_1_ch_2.lut").fullPath().c_str(), uut.pcs.genblk.station11[1].csc11[1].pc11.th_corr_mem);
			Sreadmemh(edm::FileInPath("L1Trigger/CSCTrackFinder/data/core_upgrade/vl_lut/vl_th_corr_lut_endcap_1_sec_1_sub_2_st_1_ch_3.lut").fullPath().c_str(), uut.pcs.genblk.station11[1].csc11[2].pc11.th_corr_mem);

			Sreadmemh(edm::FileInPath("L1Trigger/CSCTrackFinder/data/core_upgrade/vl_lut/vl_th_lut_endcap_1_sec_1_sub_1_st_1_ch_1.lut").fullPath().c_str(), uut.pcs.genblk.station11[0].csc11[0].pc11.th_mem);
			Sreadmemh(edm::FileInPath("L1Trigger/CSCTrackFinder/data/core_upgrade/vl_lut/vl_th_lut_endcap_1_sec_1_sub_1_st_1_ch_2.lut").fullPath().c_str(), uut.pcs.genblk.station11[0].csc11[1].pc11.th_mem);
			Sreadmemh(edm::FileInPath("L1Trigger/CSCTrackFinder/data/core_upgrade/vl_lut/vl_th_lut_endcap_1_sec_1_sub_1_st_1_ch_3.lut").fullPath().c_str(), uut.pcs.genblk.station11[0].csc11[2].pc11.th_mem);
			Sreadmemh(edm::FileInPath("L1Trigger/CSCTrackFinder/data/core_upgrade/vl_lut/vl_th_lut_endcap_1_sec_1_sub_1_st_1_ch_4.lut").fullPath().c_str(), uut.pcs.genblk.station12[0].csc12[3].pc12.th_mem);
			Sreadmemh(edm::FileInPath("L1Trigger/CSCTrackFinder/data/core_upgrade/vl_lut/vl_th_lut_endcap_1_sec_1_sub_1_st_1_ch_5.lut").fullPath().c_str(), uut.pcs.genblk.station12[0].csc12[4].pc12.th_mem);
			Sreadmemh(edm::FileInPath("L1Trigger/CSCTrackFinder/data/core_upgrade/vl_lut/vl_th_lut_endcap_1_sec_1_sub_1_st_1_ch_6.lut").fullPath().c_str(), uut.pcs.genblk.station12[0].csc12[5].pc12.th_mem);
			Sreadmemh(edm::FileInPath("L1Trigger/CSCTrackFinder/data/core_upgrade/vl_lut/vl_th_lut_endcap_1_sec_1_sub_1_st_1_ch_7.lut").fullPath().c_str(), uut.pcs.genblk.station12[0].csc12[6].pc12.th_mem);
			Sreadmemh(edm::FileInPath("L1Trigger/CSCTrackFinder/data/core_upgrade/vl_lut/vl_th_lut_endcap_1_sec_1_sub_1_st_1_ch_8.lut").fullPath().c_str(), uut.pcs.genblk.station12[0].csc12[7].pc12.th_mem);
			Sreadmemh(edm::FileInPath("L1Trigger/CSCTrackFinder/data/core_upgrade/vl_lut/vl_th_lut_endcap_1_sec_1_sub_1_st_1_ch_9.lut").fullPath().c_str(), uut.pcs.genblk.station12[0].csc12[8].pc12.th_mem);
			
			Sreadmemh(edm::FileInPath("L1Trigger/CSCTrackFinder/data/core_upgrade/vl_lut/vl_th_lut_endcap_1_sec_1_sub_2_st_1_ch_1.lut").fullPath().c_str(), uut.pcs.genblk.station11[1].csc11[0].pc11.th_mem);
			Sreadmemh(edm::FileInPath("L1Trigger/CSCTrackFinder/data/core_upgrade/vl_lut/vl_th_lut_endcap_1_sec_1_sub_2_st_1_ch_2.lut").fullPath().c_str(), uut.pcs.genblk.station11[1].csc11[1].pc11.th_mem);
			Sreadmemh(edm::FileInPath("L1Trigger/CSCTrackFinder/data/core_upgrade/vl_lut/vl_th_lut_endcap_1_sec_1_sub_2_st_1_ch_3.lut").fullPath().c_str(), uut.pcs.genblk.station11[1].csc11[2].pc11.th_mem);
			Sreadmemh(edm::FileInPath("L1Trigger/CSCTrackFinder/data/core_upgrade/vl_lut/vl_th_lut_endcap_1_sec_1_sub_2_st_1_ch_4.lut").fullPath().c_str(), uut.pcs.genblk.station12[1].csc12[3].pc12.th_mem);
			Sreadmemh(edm::FileInPath("L1Trigger/CSCTrackFinder/data/core_upgrade/vl_lut/vl_th_lut_endcap_1_sec_1_sub_2_st_1_ch_5.lut").fullPath().c_str(), uut.pcs.genblk.station12[1].csc12[4].pc12.th_mem);
			Sreadmemh(edm::FileInPath("L1Trigger/CSCTrackFinder/data/core_upgrade/vl_lut/vl_th_lut_endcap_1_sec_1_sub_2_st_1_ch_6.lut").fullPath().c_str(), uut.pcs.genblk.station12[1].csc12[5].pc12.th_mem);
			Sreadmemh(edm::FileInPath("L1Trigger/CSCTrackFinder/data/core_upgrade/vl_lut/vl_th_lut_endcap_1_sec_1_sub_2_st_1_ch_7.lut").fullPath().c_str(), uut.pcs.genblk.station12[1].csc12[6].pc12.th_mem);
			Sreadmemh(edm::FileInPath("L1Trigger/CSCTrackFinder/data/core_upgrade/vl_lut/vl_th_lut_endcap_1_sec_1_sub_2_st_1_ch_8.lut").fullPath().c_str(), uut.pcs.genblk.station12[1].csc12[7].pc12.th_mem);
			Sreadmemh(edm::FileInPath("L1Trigger/CSCTrackFinder/data/core_upgrade/vl_lut/vl_th_lut_endcap_1_sec_1_sub_2_st_1_ch_9.lut").fullPath().c_str(), uut.pcs.genblk.station12[1].csc12[8].pc12.th_mem);

			Sreadmemh(edm::FileInPath("L1Trigger/CSCTrackFinder/data/core_upgrade/vl_lut/vl_th_lut_endcap_1_sec_1_st_2_ch_1.lut").fullPath().c_str(), uut.pcs.genblk.station[2].csc[0].pc.th_mem);
			Sreadmemh(edm::FileInPath("L1Trigger/CSCTrackFinder/data/core_upgrade/vl_lut/vl_th_lut_endcap_1_sec_1_st_2_ch_2.lut").fullPath().c_str(), uut.pcs.genblk.station[2].csc[1].pc.th_mem);
			Sreadmemh(edm::FileInPath("L1Trigger/CSCTrackFinder/data/core_upgrade/vl_lut/vl_th_lut_endcap_1_sec_1_st_2_ch_3.lut").fullPath().c_str(), uut.pcs.genblk.station[2].csc[2].pc.th_mem);
			Sreadmemh(edm::FileInPath("L1Trigger/CSCTrackFinder/data/core_upgrade/vl_lut/vl_th_lut_endcap_1_sec_1_st_2_ch_4.lut").fullPath().c_str(), uut.pcs.genblk.station[2].csc[3].pc.th_mem);
			Sreadmemh(edm::FileInPath("L1Trigger/CSCTrackFinder/data/core_upgrade/vl_lut/vl_th_lut_endcap_1_sec_1_st_2_ch_5.lut").fullPath().c_str(), uut.pcs.genblk.station[2].csc[4].pc.th_mem);
			Sreadmemh(edm::FileInPath("L1Trigger/CSCTrackFinder/data/core_upgrade/vl_lut/vl_th_lut_endcap_1_sec_1_st_2_ch_6.lut").fullPath().c_str(), uut.pcs.genblk.station[2].csc[5].pc.th_mem);
			Sreadmemh(edm::FileInPath("L1Trigger/CSCTrackFinder/data/core_upgrade/vl_lut/vl_th_lut_endcap_1_sec_1_st_2_ch_7.lut").fullPath().c_str(), uut.pcs.genblk.station[2].csc[6].pc.th_mem);
			Sreadmemh(edm::FileInPath("L1Trigger/CSCTrackFinder/data/core_upgrade/vl_lut/vl_th_lut_endcap_1_sec_1_st_2_ch_8.lut").fullPath().c_str(), uut.pcs.genblk.station[2].csc[7].pc.th_mem);
			Sreadmemh(edm::FileInPath("L1Trigger/CSCTrackFinder/data/core_upgrade/vl_lut/vl_th_lut_endcap_1_sec_1_st_2_ch_9.lut").fullPath().c_str(), uut.pcs.genblk.station[2].csc[8].pc.th_mem);
			
			Sreadmemh(edm::FileInPath("L1Trigger/CSCTrackFinder/data/core_upgrade/vl_lut/vl_th_lut_endcap_1_sec_1_st_3_ch_1.lut").fullPath().c_str(), uut.pcs.genblk.station[3].csc[0].pc.th_mem);
			Sreadmemh(edm::FileInPath("L1Trigger/CSCTrackFinder/data/core_upgrade/vl_lut/vl_th_lut_endcap_1_sec_1_st_3_ch_2.lut").fullPath().c_str(), uut.pcs.genblk.station[3].csc[1].pc.th_mem);
			Sreadmemh(edm::FileInPath("L1Trigger/CSCTrackFinder/data/core_upgrade/vl_lut/vl_th_lut_endcap_1_sec_1_st_3_ch_3.lut").fullPath().c_str(), uut.pcs.genblk.station[3].csc[2].pc.th_mem);
			Sreadmemh(edm::FileInPath("L1Trigger/CSCTrackFinder/data/core_upgrade/vl_lut/vl_th_lut_endcap_1_sec_1_st_3_ch_4.lut").fullPath().c_str(), uut.pcs.genblk.station[3].csc[3].pc.th_mem);
			Sreadmemh(edm::FileInPath("L1Trigger/CSCTrackFinder/data/core_upgrade/vl_lut/vl_th_lut_endcap_1_sec_1_st_3_ch_5.lut").fullPath().c_str(), uut.pcs.genblk.station[3].csc[4].pc.th_mem);
			Sreadmemh(edm::FileInPath("L1Trigger/CSCTrackFinder/data/core_upgrade/vl_lut/vl_th_lut_endcap_1_sec_1_st_3_ch_6.lut").fullPath().c_str(), uut.pcs.genblk.station[3].csc[5].pc.th_mem);
			Sreadmemh(edm::FileInPath("L1Trigger/CSCTrackFinder/data/core_upgrade/vl_lut/vl_th_lut_endcap_1_sec_1_st_3_ch_7.lut").fullPath().c_str(), uut.pcs.genblk.station[3].csc[6].pc.th_mem);
			Sreadmemh(edm::FileInPath("L1Trigger/CSCTrackFinder/data/core_upgrade/vl_lut/vl_th_lut_endcap_1_sec_1_st_3_ch_8.lut").fullPath().c_str(), uut.pcs.genblk.station[3].csc[7].pc.th_mem);
			Sreadmemh(edm::FileInPath("L1Trigger/CSCTrackFinder/data/core_upgrade/vl_lut/vl_th_lut_endcap_1_sec_1_st_3_ch_9.lut").fullPath().c_str(), uut.pcs.genblk.station[3].csc[8].pc.th_mem);
			
			Sreadmemh(edm::FileInPath("L1Trigger/CSCTrackFinder/data/core_upgrade/vl_lut/vl_th_lut_endcap_1_sec_1_st_4_ch_1.lut").fullPath().c_str(), uut.pcs.genblk.station[4].csc[0].pc.th_mem);
			Sreadmemh(edm::FileInPath("L1Trigger/CSCTrackFinder/data/core_upgrade/vl_lut/vl_th_lut_endcap_1_sec_1_st_4_ch_2.lut").fullPath().c_str(), uut.pcs.genblk.station[4].csc[1].pc.th_mem);
			Sreadmemh(edm::FileInPath("L1Trigger/CSCTrackFinder/data/core_upgrade/vl_lut/vl_th_lut_endcap_1_sec_1_st_4_ch_3.lut").fullPath().c_str(), uut.pcs.genblk.station[4].csc[2].pc.th_mem);
			Sreadmemh(edm::FileInPath("L1Trigger/CSCTrackFinder/data/core_upgrade/vl_lut/vl_th_lut_endcap_1_sec_1_st_4_ch_4.lut").fullPath().c_str(), uut.pcs.genblk.station[4].csc[3].pc.th_mem);
			Sreadmemh(edm::FileInPath("L1Trigger/CSCTrackFinder/data/core_upgrade/vl_lut/vl_th_lut_endcap_1_sec_1_st_4_ch_5.lut").fullPath().c_str(), uut.pcs.genblk.station[4].csc[4].pc.th_mem);
			Sreadmemh(edm::FileInPath("L1Trigger/CSCTrackFinder/data/core_upgrade/vl_lut/vl_th_lut_endcap_1_sec_1_st_4_ch_6.lut").fullPath().c_str(), uut.pcs.genblk.station[4].csc[5].pc.th_mem);
			Sreadmemh(edm::FileInPath("L1Trigger/CSCTrackFinder/data/core_upgrade/vl_lut/vl_th_lut_endcap_1_sec_1_st_4_ch_7.lut").fullPath().c_str(), uut.pcs.genblk.station[4].csc[6].pc.th_mem);
			Sreadmemh(edm::FileInPath("L1Trigger/CSCTrackFinder/data/core_upgrade/vl_lut/vl_th_lut_endcap_1_sec_1_st_4_ch_8.lut").fullPath().c_str(), uut.pcs.genblk.station[4].csc[7].pc.th_mem);
			Sreadmemh(edm::FileInPath("L1Trigger/CSCTrackFinder/data/core_upgrade/vl_lut/vl_th_lut_endcap_1_sec_1_st_4_ch_9.lut").fullPath().c_str(), uut.pcs.genblk.station[4].csc[8].pc.th_mem);

			//Sreadmemh(edm::FileInPath("L1Trigger/CSCTrackFinder/data/core_upgrade/vl_lut/ph_init_endcap_1_sect_1.lut").fullPath().c_str(), ph_init);
			Sreadmemh(edm::FileInPath("L1Trigger/CSCTrackFinder/data/core_upgrade/vl_lut/th_init_endcap_1_sect_1.lut").fullPath().c_str(), th_init);
			Sreadmemh(edm::FileInPath("L1Trigger/CSCTrackFinder/data/core_upgrade/vl_lut/ph_disp_endcap_1_sect_1.lut").fullPath().c_str(), ph_disp);
			Sreadmemh(edm::FileInPath("L1Trigger/CSCTrackFinder/data/core_upgrade/vl_lut/th_disp_endcap_1_sect_1.lut").fullPath().c_str(), th_disp);

			Sreadmemh(edm::FileInPath("L1Trigger/CSCTrackFinder/data/core_upgrade/vl_lut/ph_init_full_endcap_1_sect_1_st_0.lut").fullPath().c_str(), ph_init[0]);
			Sreadmemh(edm::FileInPath("L1Trigger/CSCTrackFinder/data/core_upgrade/vl_lut/ph_init_full_endcap_1_sect_1_st_1.lut").fullPath().c_str(), ph_init[1]);
			Sreadmemh(edm::FileInPath("L1Trigger/CSCTrackFinder/data/core_upgrade/vl_lut/ph_init_full_endcap_1_sect_1_st_2.lut").fullPath().c_str(), ph_init[2]);
			Sreadmemh(edm::FileInPath("L1Trigger/CSCTrackFinder/data/core_upgrade/vl_lut/ph_init_full_endcap_1_sect_1_st_3.lut").fullPath().c_str(), ph_init[3]);
			Sreadmemh(edm::FileInPath("L1Trigger/CSCTrackFinder/data/core_upgrade/vl_lut/ph_init_full_endcap_1_sect_1_st_4.lut").fullPath().c_str(), ph_init[4]);

		for (i = 0; i < 180; i = i+1)
		{

			wei = 0;
			for (k = 0; k < 5; k = k+1)
				csi[k] = 0;

				// write ph_init and th_init parameters into ME1/1 only
				if (i < 36)
				{
					csi[i/18][(i/6)%3] = 1;//[station][chamber]
					seli = 0;
					wei = 1;
					addri = i%6;
					if (( (addri) == 0)) { r_ini = ph_init[i/18][(i/6)%3]; } else 
					if (( (addri) == // ph_init_b
						1)) { r_ini = ph_disp[(i/18)*12 + (i/6)%3]; } else 
					if (( (addri) == // ph_disp_b
						2)) { r_ini = ph_init[i/18][(i/6)%3 + 9]; } else 
					if (( (addri) == // ph_init_a
						3)) { r_ini = ph_disp[(i/18)*12 + (i/6)%3 + 9]; } else 
					if (( (addri) == // ph_disp_a
						4)) { r_ini = th_init[(i/18)*12 + (i/6)%3]; } else 
					if (( (addri) == // th_init
						5)) { r_ini = th_disp[(i/18)*12 + (i/6)%3]; } 
				}

				// all other ME1 chambers
				if (i >= 36 && i < 36+48)
				{
					ii = i - 36;
					csi[ii/24][(ii/4)%6+3] = 1;//[station][chamber]
					seli = 0;
					wei = 1;
					addri = ii % 4;
					if (( (addri) == 0)) { r_ini = ph_init[ii/24][(ii/4)%6+3]; } else 
					if (( (addri) == // ph_init
						1)) { r_ini = th_init[(ii/24)*12 + (ii/4)%6+3]; } else 
					if (( (addri) == // th_init
						2)) { r_ini = ph_disp[(ii/24)*12 + (ii/4)%6+3]; } else 
					if (( (addri) == // ph_disp
						3)) { r_ini = th_disp[(ii/24)*12 + (ii/4)%6+3]; } 
				}

				// ME2,3,4 chambers
				if (i >= 36+48 && i < 36+48+108)
				{
					ii = i - (36+48);
					csi[ii/36+2][(ii/4)%9] = 1; //[station][chamber]
					seli = 0;
					wei = 1;
					addri = ii % 4;
					if (( (addri) == 0)) { r_ini = ph_init[ii/36+2][(ii/4)%9]; } else 
					if (( (addri) == // ph_init
						1)) { r_ini = th_init[(ii/36)*9 + (ii/4)%9 + 24]; } else 
					if (( (addri) == // th_init
						2)) { r_ini = ph_disp[(ii/36)*9 + (ii/4)%9 + 24]; } else 
					if (( (addri) == // ph_disp
						3)) { r_ini = th_disp[(ii/36)*9 + (ii/4)%9 + 24]; } 
				}


			for (j = 0; j < 2; j = j+1)
			{
				clk_drive(clki, j);

				while(true)
				{
					__glob_change__ = false;
					init();
					if (!__glob_change__) break;
					uut
						(
							qi,
							wgi,
							hstri,
							cpati,
							csi,
							pps_csi,
							seli,
							addri,
							r_ini,
							r_outo,
							wei,
							bt_phi,
							bt_theta,
							bt_cpattern,
							bt_delta_ph,
							bt_delta_th,
							bt_sign_ph,
							bt_sign_th,
							bt_rank,
							bt_vi,
							bt_hi,
							bt_ci,
							bt_si,
							clki,
							clki
							);

				}
			}
		}
    } // first time processing done

  // copy inputs to signals
  for (unsigned mi0 = 0; mi0 <= 4; mi0++)
    for (unsigned mi1 = 0; mi1 <= 8; mi1++)
      for (unsigned mi2 = 0; mi2 <= seg_ch-1; mi2++)
	qi[mi0][mi1][mi2] = q__io[mi0][mi1][mi2];
  for (unsigned mi0 = 0; mi0 <= 4; mi0++)
    for (unsigned mi1 = 0; mi1 <= 8; mi1++)
      for (unsigned mi2 = 0; mi2 <= seg_ch-1; mi2++)
	wgi[mi0][mi1][mi2] = wg__io[mi0][mi1][mi2];
  for (unsigned mi0 = 0; mi0 <= 4; mi0++)
    for (unsigned mi1 = 0; mi1 <= 8; mi1++)
      for (unsigned mi2 = 0; mi2 <= seg_ch-1; mi2++)
	hstri[mi0][mi1][mi2] = hstr__io[mi0][mi1][mi2];
  for (unsigned mi0 = 0; mi0 <= 4; mi0++)
    for (unsigned mi1 = 0; mi1 <= 8; mi1++)
      for (unsigned mi2 = 0; mi2 <= seg_ch-1; mi2++)
	cpati[mi0][mi1][mi2] = cpat__io[mi0][mi1][mi2];

  wei = 0;
	
  for (j = 0; j < 2; j = j+1)
  {
      clk_drive(clki, j);

      while(true)
	  {
		  __glob_change__ = false;
		  init();
		  if (!__glob_change__) break;
		  uut
			  (
				  qi,
				  wgi,
				  hstri,
				  cpati,
				  csi,
				  pps_csi,
				  seli,
				  addri,
				  r_ini,
				  r_outo,
				  wei,
				  bt_phi,
				  bt_theta,
				  bt_cpattern,
				  bt_delta_ph,
				  bt_delta_th,
				  bt_sign_ph,
				  bt_sign_th,
				  bt_rank,
				  bt_vi,
				  bt_hi,
				  bt_ci,
				  bt_si,
				  clki,
				  clki
				  );
	  }
  }
  // copy output signals to io
  for (unsigned mi0 = 0; mi0 <= 2; mi0++)
  {
	  bt_phi__io [mi0] =         bt_phi [mi0];
	  bt_theta__io [mi0] =		 bt_theta [mi0];
	  bt_cpattern__io [mi0] =	 bt_cpattern [mi0];
	  bt_rank__io [mi0] =		 bt_rank [mi0];

	  for (unsigned mi1 = 0; mi1 <= 1; mi1++)
	  {
		  bt_delta_ph__io [mi0][mi1] = bt_delta_ph [mi0][mi1];
		  bt_delta_th__io [mi0][mi1] = bt_delta_th [mi0][mi1]; 
		  bt_sign_ph__io[mi0][mi1] =	 bt_sign_ph[mi0][mi1];
		  bt_sign_th__io[mi0][mi1] =	 bt_sign_th[mi0][mi1];
	  }
	  for (unsigned mi1 = 0; mi1 <= 4; mi1++)
	  {
		  bt_vi__io [mi0][mi1] =		 bt_vi [mi0][mi1];
		  bt_hi__io [mi0][mi1] =		 bt_hi [mi0][mi1];
		  bt_ci__io [mi0][mi1] =		 bt_ci [mi0][mi1];
		  bt_si__io [mi0][mi1] =		 bt_si [mi0][mi1];
	  }
  }


}
Ejemplo n.º 22
0
int main(){
    {

      
      // dynamic object can be a fundamental type
      dynamic::DynamicObject uut = 33;
      assert(33 == (int)uut);



    }
  {
    // dynamic object can be a complex type
    dynamic::DynamicObject uut = std::string("hello");
    std::string res = uut;
    assert("hello" == res);
  }
  {
    // dynamic object can be reassigned
    dynamic::DynamicObject uut = 33;
    assert(33 == (int)uut);
    uut = std::string("hello");
    std::string res = uut;
    assert("hello" == res);
  }
  {
    //dynamic object can be a functor
    dynamic::DynamicObject uut = [](int i, int j){return i + j; };
    int result = uut(3, 4);
    assert(result == 7);
  }

  {
    // dynamic object can be an expando object
    dynamic::DynamicObject uut;
    uut["prop1"] = 33;
    uut["prop2"] = std::string("hello");
    uut["prop3"]["prop31"] = 5;
    uut["prop4"] = [](int i, int j){return i + j; };
    int prop1 = uut["prop1"];
    std::string prop2 = uut["prop2"];
    int prop31 = uut["prop3"]["prop31"];
    int result = uut["prop4"](5, 6);

    assert(prop1 == 33);
    assert(prop2 == "hello");
    assert(prop31 == 5);
    assert(result == 11);
  }

  {
    // you can create a custom dynamic object implementation:
    class MyImp : public dynamic::DynamicObjectImplementationBase{
    protected:
      virtual bool tryMemberGet(const get_member_context & context, result_type & result)override
      {
        if (context.name == "prop1"){
          result = 44;
          return true;
        }
        if (context.name == "prop2"){
          result = std::string("asd");
          return true;
        }

        return false;
      }
    };
    // initialization is still a bit complex 
    dynamic::DynamicObject uut = 
      std::dynamic_pointer_cast<dynamic::IDynamicObjectImplementation>(std::make_shared<MyImp>());
    int a = uut["prop1"];
    std::string b = uut["prop2"];

    assert(a == 44);
    assert(b == "asd");

  }



}
Ejemplo n.º 23
0
int sc_main (int argc, char **argv)
{
  sc_report_handler::set_actions("/IEEE_Std_1666/deprecated", SC_DO_NOTHING); 
  int NVAL;

  if (argc != 2)
  {
    printf("Use: %s <N>\n", argv[0]);
    return 1;
  }

  NVAL = atoi(argv[1]);


  sc_signal<bool> RST_n_tb; /// asynchronous reset
  sc_signal<bool> CLEAR_tb; /// synchronous clear port
  sc_signal< sc_int<Cbit> > C0_tb; 
  sc_signal< sc_int<Cbit> > C1_tb;
  sc_signal< sc_int<Abit> > A0_tb;
  sc_signal< sc_int<Abit> > A1_tb;
  sc_signal< sc_int<Abit> > A2_tb;
  sc_signal< sc_int<Abit> > A3_tb;


  sc_clock CLK("CLK", TB_CLK_PERIOD);
  starter sta("sta", TB_CLK_PERIOD, TB_TPD);
  data_gen dg("dg", TB_CLK_PERIOD, TB_TPD, NVAL);
  data_writer dw("dw", TB_CLK_PERIOD, NVAL);
  ACS4 uut("uut", TB_TPD, TB_TCO);


  /// starter
  sta.CLK(CLK);
  sta.RST_n(RST_n_tb);

  /// data gen
  dg.CLK(CLK);
  dg.CLEAR(CLEAR_tb);
  dg.C0(C0_tb);
  dg.C1(C1_tb);

  /// uut
  uut.CLK(CLK);
  uut.RST_n(RST_n_tb);
  uut.CLEAR(CLEAR_tb);
  uut.C0(C0_tb);
  uut.C1(C1_tb);
  uut.A0(A0_tb);
  uut.A1(A1_tb);
  uut.A2(A2_tb);
  uut.A3(A3_tb);

	
  /// write results
  dw.CLK(CLK);
  dw.A1(A1_tb);
  dw.A2(A2_tb);
  dw.A3(A3_tb);
  dw.A0(A0_tb);

  sc_trace_file *tf = sc_create_vcd_trace_file("uut");
  ((vcd_trace_file*)tf)->sc_set_vcd_time_unit(-9);

  sc_trace(tf, CLK, "CLK");
  sc_trace(tf, RST_n_tb, "RST_n_tb");
  sc_trace(tf, CLEAR_tb, "CLEAR_tb");
  sc_trace(tf, C0_tb, "C0_tb");
  sc_trace(tf, C1_tb, "C1_tb");
  sc_trace(tf, A0_tb, "A0_tb");
  sc_trace(tf, A1_tb, "A1_tb");
  sc_trace(tf, A2_tb, "A2_tb");
  sc_trace(tf, A3_tb, "A3_tb");

  sc_start((NVAL+SIM_CYCLES_OFFSET)*TB_CLK_PERIOD, SC_NS);

  sc_close_vcd_trace_file(tf);

  return 0;
}
Ejemplo n.º 24
0
int sc_main(int,char**)
{
    sc_report_handler::set_actions( "ID1", SC_DISPLAY | SC_CACHE_REPORT );
    sc_report_handler::set_actions( "ID2", SC_DISPLAY );

    sc_signal<bool> emit;
    sc_signal<const char*> ID;
    sc_signal<bool> ofs;
    M uut("M");
    uut( emit,ID,ofs );

    emit = 0;
    ID="ID3";
    ofs=0;
    sc_start( 1,SC_NS );

    // dump initial cached reports
    cout << "Initial status:\n";
    uut.t1.notify();
    uut.m1.notify();
    uut.t2.notify();
    uut.m2.notify();
    dump_cached_report("global");
    sc_start( 1, SC_NS );

    // emit report ID1 everywhere
    emit = 1;
    ID="ID1";
    sc_start( 1,SC_NS );
    cout << "\n\nEmit ID1\n";
    uut.t1.notify();
    uut.m1.notify();
    sc_start( 1, SC_NS );
    sc_report_handler::report(SC_INFO, ID.read(), "cc", "file_g", 300);
    uut.t2.notify();
    uut.m2.notify();
    sc_start( 1, SC_NS );
    
    // emit report ID2 everywhere
    cout << "\n\nEmit ID2\n";
    emit = 1;
    ID="ID2";
    ofs=1;
    sc_start( 1,SC_NS );
    uut.t1.notify();
    uut.m1.notify();
    sc_start( 1, SC_NS );
    sc_report_handler::report(SC_INFO, ID.read(), "c", "file_g", 310);
    uut.t2.notify();
    uut.m2.notify();
    sc_start( 1, SC_NS );
    
    // dump cached reports: should be all ID1
    emit = 0;
    sc_start( 1,SC_NS );
    cout << "\n\nStatus:\n";
    uut.t1.notify();
    uut.t2.notify();
    uut.m1.notify();
    uut.m2.notify();
    dump_cached_report("global");
    sc_start( 1, SC_NS );

    // dump cached reports again
    // (should be all empty because dump clears cached report)
    cout << "\n\nStatus:\n";
    uut.t1.notify();
    uut.t2.notify();
    uut.m1.notify();
    uut.m2.notify();
    dump_cached_report("global");
    sc_start( 1, SC_NS );

    return 0;
}