void OCIOColorSpace::_validate(bool for_real) { input0().validate(for_real); if(!m_hasColorSpaces) { error("No colorspaces available for input and/or output."); return; } int inputColorSpaceCount = static_cast<int>(m_inputColorSpaceCstrNames.size()) - 1; if(m_inputColorSpaceIndex < 0 || m_inputColorSpaceIndex >= inputColorSpaceCount) { std::ostringstream err; err << "Input colorspace index (" << m_inputColorSpaceIndex << ") out of range."; error(err.str().c_str()); return; } int outputColorSpaceCount = static_cast<int>(m_outputColorSpaceCstrNames.size()) - 1; if(m_outputColorSpaceIndex < 0 || m_outputColorSpaceIndex >= outputColorSpaceCount) { std::ostringstream err; err << "Output colorspace index (" << m_outputColorSpaceIndex << ") out of range."; error(err.str().c_str()); return; } try { const char * inputName = m_inputColorSpaceCstrNames[m_inputColorSpaceIndex]; const char * outputName = m_outputColorSpaceCstrNames[m_outputColorSpaceIndex]; OCIO::ConstConfigRcPtr config = OCIO::GetCurrentConfig(); config->sanityCheck(); OCIO::ConstContextRcPtr context = getLocalContext(); m_processor = config->getProcessor(context, inputName, outputName); } catch(OCIO::Exception &e) { error(e.what()); return; } if(m_processor->isNoOp()) { // TODO or call disable() ? set_out_channels(DD::Image::Mask_None); // prevents engine() from being called copy_info(); return; } set_out_channels(DD::Image::Mask_All); DD::Image::PixelIop::_validate(for_real); }
void RunPP(const char *jobid="test") { Int_t nev=99999999; //TString input0("/star/u/russcher/gamma/analysis/data/pp05/ppProduction.root"); TString input0("/star/u/russcher/gamma/analysis/data/pp05/ppProduction_rcf_0.root"); TString input1("/star/u/russcher/gamma/analysis/data/pp05/ppProduction_rcf_1.root"); TString input2("/star/u/russcher/gamma/analysis/data/pp05/ppProduction_rcf_2.root"); TString input3("/star/u/russcher/gamma/analysis/data/pp05/ppProduction_rcf_3.root"); TString input4("/star/u/russcher/gamma/analysis/data/pp05/ppProductionMinBias.root"); TString outdir("/star/u/russcher/gamma/analysis/output/pp05/"); TString psout("pi0_pp05.ps"); TString psout2("eta_pp05.ps"); TString rootout("pi0_pp05.root"); psout.Prepend(jobid); rootout.Prepend(jobid); TString command("mkdir "); command.Append(outdir.Data()); command.Append(jobid); gSystem->Exec(command.Data()); cout<<endl<<"storing results in: "<<command.Data()<<endl<<endl; outdir.Append(jobid); outdir.Append("/"); psout.Prepend(outdir.Data()); psout2.Prepend(outdir.Data()); rootout.Prepend(outdir.Data()); gSystem->Load("$HOME/MyEvent/MyEvent.so"); gSystem->Load("$HOME/gamma/analysis/lib/AnaCuts.so"); gSystem->Load("$HOME/gamma/analysis/lib/EventMixer.so"); gSystem->Load("$HOME/gamma/analysis/lib/Pi0Analysis.so"); Pi0Analysis *pi0=new Pi0Analysis(psout.Data(),psout2.Data(),"pp05"); pi0->setMC(kFALSE); pi0->init(rootout.Data()); pi0->make(nev,input0.Data()); pi0->make(nev,input1.Data()); pi0->make(nev,input2.Data()); pi0->make(nev,input3.Data()); pi0->printPrescales(); cout<<"****** starting with minbias *********"<<endl; pi0->make(nev,input4.Data()); pi0->printPrescales(); pi0->getYield(); pi0->finish(); }
void OCIOFileTransform::_validate(bool for_real) { input0().validate(for_real); if(!src) { error("The source file must be specified."); return; } try { OCIO::ConstConfigRcPtr config = OCIO::GetCurrentConfig(); config->sanityCheck(); OCIO::FileTransformRcPtr transform = OCIO::FileTransform::Create(); transform->setSrc(src); // TODO: For some reason, cccid is NOT incorporated in this node's hash. // Until then, cccid is considered broken. Figure out why. transform->setCCCId(cccid.c_str()); if(dirindex == 0) transform->setDirection(OCIO::TRANSFORM_DIR_FORWARD); else transform->setDirection(OCIO::TRANSFORM_DIR_INVERSE); if(interpindex == 0) transform->setInterpolation(OCIO::INTERP_NEAREST); else transform->setInterpolation(OCIO::INTERP_LINEAR); processor = config->getProcessor(transform, OCIO::TRANSFORM_DIR_FORWARD); } catch(OCIO::Exception &e) { error(e.what()); return; } if(processor->isNoOp()) { // TODO or call disable() ? set_out_channels(DD::Image::Mask_None); // prevents engine() from being called copy_info(); return; } set_out_channels(DD::Image::Mask_All); DD::Image::PixelIop::_validate(for_real); }
Server::Server(const std::string &pathToVectorSpaceData, uint16_t portNr) : _sockFd(0), _newSockFd(0), _topKQueueNRD(), _compressionBlockRows(3), _compressionBlockCols(1), _compressionLevels(2) { std::ifstream input0(pathToVectorSpaceData); std::cout << "Using index file " << pathToVectorSpaceData << std::endl; int i = 0; for( std::string line; getline( input0, line ); i++){ vec vector = vec(); util::stringToVec(line,vector); _topKQueueNRD.addVector(util::getJsonInt(line, "id"),vector); } _topKQueueNRD.buildIndex(_compressionBlockRows, _compressionBlockCols, _compressionLevels); std::cout << _topKQueueNRD.getVectorSpaceSize() << " vectors of length " << _topKQueueNRD.getVectorSpace().getVectorSpacePyramide()[0][0].size() << std::endl; struct sockaddr_in serv_addr; #ifdef _WIN32 /* Initialisiere TCP für Windows ("winsock"). */ WORD wVersionRequested; WSADATA wsaData; wVersionRequested = MAKEWORD(1, 1); if (WSAStartup(wVersionRequested, &wsaData) != 0){ fprintf(stderr, "%s: %d\n", "Fehler beim Initialisieren von Winsock", WSAGetLastError()); } #endif _sockFd = socket(AF_INET, SOCK_STREAM, 0); if (_sockFd < 0) { std::cout << "ERROR opening socket" << std::endl; } memset( &serv_addr, 0, sizeof(serv_addr)); serv_addr.sin_family = AF_INET; serv_addr.sin_addr.s_addr = INADDR_ANY; serv_addr.sin_port = htons(portNr); if (bind(_sockFd, (struct sockaddr *) &serv_addr, sizeof(serv_addr)) < 0) { std::cout << "ERROR on binding" << std::endl; return; } listen(_sockFd,5); std::cout << "Listening on port " << portNr << std::endl; }
void OCIOCDLTransform::_validate(bool for_real) { input0().validate(for_real); try { OCIO::ConstConfigRcPtr config = OCIO::GetCurrentConfig(); config->sanityCheck(); OCIO::CDLTransformRcPtr cc = OCIO::CDLTransform::Create(); cc->setSlope(m_slope); cc->setOffset(m_offset); cc->setPower(m_power); cc->setSat(m_saturation); if(m_dirindex == 0) cc->setDirection(OCIO::TRANSFORM_DIR_FORWARD); else cc->setDirection(OCIO::TRANSFORM_DIR_INVERSE); m_processor = config->getProcessor(cc); } catch(OCIO::Exception &e) { error(e.what()); return; } if(m_processor->isNoOp()) { // TODO or call disable() ? set_out_channels(DD::Image::Mask_None); // prevents engine() from being called copy_info(); return; } set_out_channels(DD::Image::Mask_All); DD::Image::PixelIop::_validate(for_real); }
int main(int argc, char *argv[]) { #if __TBB_FLOW_GRAPH_CPP11_FEATURES try { utility::thread_number_range threads(get_default_num_threads); utility::parse_cli_arguments(argc, argv, utility::cli_argument_pack() //"-h" option for displaying help is present implicitly .positional_arg(threads,"#threads",utility::thread_number_range_desc) .arg(verbose,"verbose"," print diagnostic output to screen") .arg(silent,"silent"," limits output to timing info; overrides verbose") ); if (silent) verbose = false; // make silent override verbose tick_count start = tick_count::now(); for(int p = threads.first; p <= threads.last; p = threads.step(p)) { task_scheduler_init init(p); if (!silent) cout << "graph test running on " << p << " threads.\n"; graph g; { // test buffer: 0, 1 buffer b(g); toggle input(g); led output(g, "OUTPUT", false); // false means we will explicitly call display to see LED make_edge(input.get_out(), input_port<0>(b)); make_edge(output_port<0>(b), output.get_in()); if (!silent) printf("Testing buffer...\n"); input.activate(); // 0 g.wait_for_all(); if (!silent) output.display(); assert(output.get_value() == low); input.flip(); // 1 g.wait_for_all(); if (!silent) output.display(); assert(output.get_value() == high); } { // test not_gate: 0, 1 not_gate n(g); toggle input(g); led output(g, "OUTPUT", false); make_edge(input.get_out(), input_port<0>(n)); make_edge(output_port<0>(n), output.get_in()); if (!silent) printf("Testing not_gate...\n"); input.activate(); // 0 g.wait_for_all(); if (!silent) output.display(); assert(output.get_value() == high); input.flip(); // 1 g.wait_for_all(); if (!silent) output.display(); assert(output.get_value() == low); } { // test two-input and_gate: 00, 01, 10, 11 and_gate<2> a(g); toggle input0(g); toggle input1(g); led output(g, "OUTPUT", false); make_edge(input0.get_out(), input_port<0>(a)); make_edge(input1.get_out(), input_port<1>(a)); make_edge(output_port<0>(a), output.get_in()); if (!silent) printf("Testing and_gate...\n"); input1.activate(); input0.activate(); // 0 0 g.wait_for_all(); if (!silent) output.display(); assert(output.get_value() == low); input0.flip(); // 0 1 g.wait_for_all(); if (!silent) output.display(); assert(output.get_value() == low); input1.flip(); input0.flip(); // 1 0 g.wait_for_all(); if (!silent) output.display(); assert(output.get_value() == low); input0.flip(); // 1 1 g.wait_for_all(); if (!silent) output.display(); assert(output.get_value() == high); } { // test three-input or_gate: 000, 001, 010, 100, 011, 101, 110, 111 or_gate<3> o(g); toggle input0(g); toggle input1(g); toggle input2(g); led output(g, "OUTPUT", false); make_edge(input0.get_out(), input_port<0>(o)); make_edge(input1.get_out(), input_port<1>(o)); make_edge(input2.get_out(), input_port<2>(o)); make_edge(output_port<0>(o), output.get_in()); if (!silent) printf("Testing or_gate...\n"); input2.activate(); input1.activate(); input0.activate(); // 0 0 0 g.wait_for_all(); if (!silent) output.display(); assert(output.get_value() == low); input0.flip(); // 0 0 1 g.wait_for_all(); if (!silent) output.display(); assert(output.get_value() == high); input1.flip(); input0.flip(); // 0 1 0 g.wait_for_all(); if (!silent) output.display(); assert(output.get_value() == high); input2.flip(); input1.flip(); // 1 0 0 g.wait_for_all(); if (!silent) output.display(); assert(output.get_value() == high); input2.flip(); input1.flip(); input0.flip(); // 0 1 1 g.wait_for_all(); if (!silent) output.display(); assert(output.get_value() == high); input2.flip(); input1.flip(); // 1 0 1 g.wait_for_all(); if (!silent) output.display(); assert(output.get_value() == high); input1.flip(); input0.flip(); // 1 1 0 g.wait_for_all(); if (!silent) output.display(); assert(output.get_value() == high); input0.flip(); // 1 1 1 g.wait_for_all(); if (!silent) output.display(); assert(output.get_value() == high); } { // test two-input xor_gate: 00, 01, 10, 11 xor_gate<2> x(g); toggle input0(g); toggle input1(g); led output(g, "OUTPUT", false); make_edge(input0.get_out(), input_port<0>(x)); make_edge(input1.get_out(), input_port<1>(x)); make_edge(output_port<0>(x), output.get_in()); if (!silent) printf("Testing xor_gate...\n"); input1.activate(); input0.activate(); // 0 0 g.wait_for_all(); if (!silent) output.display(); assert(output.get_value() == low); input0.flip(); // 0 1 g.wait_for_all(); if (!silent) output.display(); assert(output.get_value() == high); input1.flip(); input0.flip(); // 1 0 g.wait_for_all(); if (!silent) output.display(); assert(output.get_value() == high); input0.flip(); // 1 1 g.wait_for_all(); if (!silent) output.display(); assert(output.get_value() == low); } { // test two-input nor_gate: 00, 01, 10, 11 nor_gate<2> n(g); toggle input0(g); toggle input1(g); led output(g, "OUTPUT", false); make_edge(input0.get_out(), input_port<0>(n)); make_edge(input1.get_out(), input_port<1>(n)); make_edge(output_port<0>(n), output.get_in()); if (!silent) printf("Testing nor_gate...\n"); input1.activate(); input0.activate(); // 0 0 g.wait_for_all(); if (!silent) output.display(); assert(output.get_value() == high); input0.flip(); // 0 1 g.wait_for_all(); if (!silent) output.display(); assert(output.get_value() == low); input1.flip(); input0.flip(); // 1 0 g.wait_for_all(); if (!silent) output.display(); assert(output.get_value() == low); input0.flip(); // 1 1 g.wait_for_all(); if (!silent) output.display(); assert(output.get_value() == low); } { // test steady_signal and digit steady_signal input0(g, high); steady_signal input1(g, low); and_gate<2> a(g); or_gate<2> o(g); xor_gate<2> x(g); nor_gate<2> n(g); digit output(g, "OUTPUT", false); make_edge(input0.get_out(), input_port<0>(a)); make_edge(input1.get_out(), input_port<1>(a)); make_edge(output_port<0>(a), input_port<0>(output)); make_edge(input0.get_out(), input_port<0>(o)); make_edge(input1.get_out(), input_port<1>(o)); make_edge(output_port<0>(o), input_port<1>(output)); make_edge(input0.get_out(), input_port<0>(x)); make_edge(input1.get_out(), input_port<1>(x)); make_edge(output_port<0>(x), input_port<2>(output)); make_edge(input0.get_out(), input_port<0>(n)); make_edge(input1.get_out(), input_port<1>(n)); make_edge(output_port<0>(n), input_port<3>(output)); if (!silent) printf("Testing steady_signal...\n"); input0.activate(); // 1 input1.activate(); // 0 g.wait_for_all(); if (!silent) output.display(); assert(output.get_value() == 6); } { // test push_button push_button p(g); buffer b(g); led output(g, "OUTPUT", !silent); // true means print all LED state changes make_edge(p.get_out(), input_port<0>(b)); make_edge(output_port<0>(b), output.get_in()); if (!silent) printf("Testing push_button...\n"); p.press(); p.release(); p.press(); p.release(); g.wait_for_all(); } { // test one_bit_adder one_bit_adder my_adder(g); toggle A(g); toggle B(g); toggle CarryIN(g); led Sum(g, "SUM"); led CarryOUT(g, "CarryOUT"); make_edge(A.get_out(), input_port<P::A0>(my_adder)); make_edge(B.get_out(), input_port<P::B0>(my_adder)); make_edge(CarryIN.get_out(), input_port<P::CI>(my_adder)); make_edge(output_port<P::S0>(my_adder), Sum.get_in()); make_edge(output_port<1>(my_adder), CarryOUT.get_in()); A.activate(); B.activate(); CarryIN.activate(); if (!silent) printf("A on\n"); A.flip(); g.wait_for_all(); if (!silent) Sum.display(); if (!silent) CarryOUT.display(); assert((Sum.get_value() == high) && (CarryOUT.get_value() == low)); if (!silent) printf("A off\n"); A.flip(); g.wait_for_all(); if (!silent) Sum.display(); if (!silent) CarryOUT.display(); assert((Sum.get_value() == low) && (CarryOUT.get_value() == low)); if (!silent) printf("B on\n"); B.flip(); g.wait_for_all(); if (!silent) Sum.display(); if (!silent) CarryOUT.display(); assert((Sum.get_value() == high) && (CarryOUT.get_value() == low)); if (!silent) printf("B off\n"); B.flip(); g.wait_for_all(); if (!silent) Sum.display(); if (!silent) CarryOUT.display(); assert((Sum.get_value() == low) && (CarryOUT.get_value() == low)); if (!silent) printf("CarryIN on\n"); CarryIN.flip(); g.wait_for_all(); if (!silent) Sum.display(); if (!silent) CarryOUT.display(); assert((Sum.get_value() == high) && (CarryOUT.get_value() == low)); if (!silent) printf("CarryIN off\n"); CarryIN.flip(); g.wait_for_all(); if (!silent) Sum.display(); if (!silent) CarryOUT.display(); assert((Sum.get_value() == low) && (CarryOUT.get_value() == low)); if (!silent) printf("A&B on\n"); A.flip(); B.flip(); g.wait_for_all(); if (!silent) Sum.display(); if (!silent) CarryOUT.display(); assert((Sum.get_value() == low) && (CarryOUT.get_value() == high)); if (!silent) printf("A&B off\n"); A.flip(); B.flip(); g.wait_for_all(); if (!silent) Sum.display(); if (!silent) CarryOUT.display(); assert((Sum.get_value() == low) && (CarryOUT.get_value() == low)); if (!silent) printf("A&CarryIN on\n"); A.flip(); CarryIN.flip(); g.wait_for_all(); if (!silent) Sum.display(); if (!silent) CarryOUT.display(); assert((Sum.get_value() == low) && (CarryOUT.get_value() == high)); if (!silent) printf("A&CarryIN off\n"); A.flip(); CarryIN.flip(); g.wait_for_all(); if (!silent) Sum.display(); if (!silent) CarryOUT.display(); assert((Sum.get_value() == low) && (CarryOUT.get_value() == low)); if (!silent) printf("B&CarryIN on\n"); B.flip(); CarryIN.flip(); g.wait_for_all(); if (!silent) Sum.display(); if (!silent) CarryOUT.display(); assert((Sum.get_value() == low) && (CarryOUT.get_value() == high)); if (!silent) printf("B&CarryIN off\n"); B.flip(); CarryIN.flip(); g.wait_for_all(); if (!silent) Sum.display(); if (!silent) CarryOUT.display(); assert((Sum.get_value() == low) && (CarryOUT.get_value() == low)); if (!silent) printf("A&B&CarryIN on\n"); A.flip(); B.flip(); CarryIN.flip(); g.wait_for_all(); if (!silent) Sum.display(); if (!silent) CarryOUT.display(); assert((Sum.get_value() == high) && (CarryOUT.get_value() == high)); if (!silent) printf("A&B&CarryIN off\n"); A.flip(); B.flip(); CarryIN.flip(); g.wait_for_all(); if (!silent) Sum.display(); if (!silent) CarryOUT.display(); assert((Sum.get_value() == low) && (CarryOUT.get_value() == low)); } #if USE_TWO_BIT_FULL_ADDER { // test two_bit_adder if (!silent) printf("testing two_bit adder\n"); two_bit_adder two_adder(g); std::vector<toggle> A(2, toggle(g)); std::vector<toggle> B(2, toggle(g)); toggle CarryIN(g); digit Sum(g, "SUM"); led CarryOUT(g, "CarryOUT"); make_edge(A[0].get_out(), input_port<P::A0>(two_adder)); make_edge(B[0].get_out(), input_port<P::B0>(two_adder)); make_edge(output_port<P::S0>(two_adder), input_port<0>(Sum)); make_edge(A[1].get_out(), input_port<P::A1>(two_adder)); make_edge(B[1].get_out(), input_port<P::B1>(two_adder)); make_edge(output_port<P::S1>(two_adder), input_port<1>(Sum)); make_edge(CarryIN.get_out(), input_port<P::CI>(two_adder)); make_edge(output_port<P::CO>(two_adder), CarryOUT.get_in()); // Activate all switches at low state for (int i=0; i<2; ++i) { A[i].activate(); B[i].activate(); } CarryIN.activate(); if (!silent) printf("1+0\n"); A[0].flip(); g.wait_for_all(); if (!silent) Sum.display(); if (!silent) CarryOUT.display(); assert((Sum.get_value() == 1) && (CarryOUT.get_value() == low)); if (!silent) printf("0+1\n"); A[0].flip(); B[0].flip(); g.wait_for_all(); if (!silent) Sum.display(); if (!silent) CarryOUT.display(); assert((Sum.get_value() == 1) && (CarryOUT.get_value() == low)); } #else { // test four_bit_adder four_bit_adder four_adder(g); std::vector<toggle> A(4, toggle(g)); std::vector<toggle> B(4, toggle(g)); toggle CarryIN(g); digit Sum(g, "SUM"); led CarryOUT(g, "CarryOUT"); make_edge(A[0].get_out(), input_port<P::A0>(four_adder)); make_edge(B[0].get_out(), input_port<P::B0>(four_adder)); make_edge(output_port<P::S0>(four_adder), input_port<0>(Sum)); make_edge(A[1].get_out(), input_port<P::A1>(four_adder)); make_edge(B[1].get_out(), input_port<P::B1>(four_adder)); make_edge(output_port<P::S1>(four_adder), input_port<1>(Sum)); make_edge(A[2].get_out(), input_port<P::A2>(four_adder)); make_edge(B[2].get_out(), input_port<P::B2>(four_adder)); make_edge(output_port<P::S2>(four_adder), input_port<2>(Sum)); make_edge(A[3].get_out(), input_port<P::A3>(four_adder)); make_edge(B[3].get_out(), input_port<P::B3>(four_adder)); make_edge(output_port<P::S3>(four_adder), input_port<3>(Sum)); make_edge(CarryIN.get_out(), input_port<P::CI>(four_adder)); make_edge(output_port<P::CO>(four_adder), CarryOUT.get_in()); // Activate all switches at low state for (int i=0; i<4; ++i) { A[i].activate(); B[i].activate(); } CarryIN.activate(); if (!silent) printf("1+0\n"); A[0].flip(); g.wait_for_all(); if (!silent) Sum.display(); if (!silent) CarryOUT.display(); assert((Sum.get_value() == 1) && (CarryOUT.get_value() == low)); if (!silent) printf("0+1\n"); A[0].flip(); B[0].flip(); g.wait_for_all(); if (!silent) Sum.display(); if (!silent) CarryOUT.display(); assert((Sum.get_value() == 1) && (CarryOUT.get_value() == low)); if (!silent) printf("3+4\n"); A[0].flip(); A[1].flip(); B[0].flip(); B[2].flip(); g.wait_for_all(); if (!silent) Sum.display(); if (!silent) CarryOUT.display(); assert((Sum.get_value() == 7) && (CarryOUT.get_value() == low)); if (!silent) printf("6+1\n"); A[0].flip(); A[2].flip(); B[0].flip(); B[2].flip(); g.wait_for_all(); if (!silent) Sum.display(); if (!silent) CarryOUT.display(); assert((Sum.get_value() == 7) && (CarryOUT.get_value() == low)); if (!silent) printf("0+0+carry\n"); A[1].flip(); A[2].flip(); B[0].flip(); CarryIN.flip(); g.wait_for_all(); if (!silent) Sum.display(); if (!silent) CarryOUT.display(); assert((Sum.get_value() == 1) && (CarryOUT.get_value() == low)); if (!silent) printf("15+15+carry\n"); A[0].flip(); A[1].flip(); A[2].flip(); A[3].flip(); B[0].flip(); B[1].flip(); B[2].flip(); B[3].flip(); g.wait_for_all(); if (!silent) Sum.display(); if (!silent) CarryOUT.display(); assert((Sum.get_value() == 0xf) && (CarryOUT.get_value() == high)); if (!silent) printf("8+8\n"); A[0].flip(); A[1].flip(); A[2].flip(); B[0].flip(); B[1].flip(); B[2].flip(); CarryIN.flip(); g.wait_for_all(); if (!silent) Sum.display(); if (!silent) CarryOUT.display(); assert((Sum.get_value() == 0) && (CarryOUT.get_value() == high)); if (!silent) printf("0+0\n"); A[3].flip(); B[3].flip(); g.wait_for_all(); if (!silent) Sum.display(); if (!silent) CarryOUT.display(); assert((Sum.get_value() == 0) && (CarryOUT.get_value() == low)); } #endif { // test D_latch D_latch my_d_latch(g); toggle D(g); pulse E(g, 500, 4); // clock changes every 500ms; stops after 4 changes led Q(g, " Q", verbose); // if true, LEDs print at every state change led notQ(g, "~Q", verbose); make_edge(D.get_out(), input_port<0>(my_d_latch)); make_edge(E.get_out(), input_port<1>(my_d_latch)); make_edge(output_port<0>(my_d_latch), Q.get_in()); make_edge(output_port<1>(my_d_latch), notQ.get_in()); D.activate(); if (!silent) printf("Toggling D\n"); E.activate(); D.flip(); g.wait_for_all(); if (!silent && !verbose) { Q.display(); notQ.display(); } assert((Q.get_value() == high) && (notQ.get_value() == low)); E.reset(); if (!silent) printf("Toggling D\n"); E.activate(); D.flip(); g.wait_for_all(); if (!silent && !verbose) { Q.display(); notQ.display(); } assert((Q.get_value() == low) && (notQ.get_value() == high)); E.reset(); if (!silent) printf("Toggling D\n"); E.activate(); D.flip(); g.wait_for_all(); if (!silent && !verbose) { Q.display(); notQ.display(); } assert((Q.get_value() == high) && (notQ.get_value() == low)); E.reset(); if (!silent) printf("Toggling D\n"); E.activate(); D.flip(); g.wait_for_all(); if (!silent && !verbose) { Q.display(); notQ.display(); } assert((Q.get_value() == low) && (notQ.get_value() == high)); E.reset(); if (!silent) printf("Toggling D\n"); E.activate(); D.flip(); g.wait_for_all(); if (!silent && !verbose) { Q.display(); notQ.display(); } assert((Q.get_value() == high) && (notQ.get_value() == low)); } } utility::report_elapsed_time((tbb::tick_count::now() - start).seconds()); return 0; } catch(std::exception& e) { cerr<<"error occurred. error text is :\"" <<e.what()<<"\"\n"; return 1; } #else utility::report_skipped(); return 0; #endif // __TBB_FLOW_GRAPH_CPP11_FEATURES }
int yylex() { int r, c, c2, d; int radix; char extPath[MAXPATHLEN]; // for error reporting yylen = 0; // finite state machine to parse input stream into tokens if (lexCmdLine == 1) { lexCmdLine = 2; r = INTERPRET; goto leave; } start: c = input(); if (c == 0) { r = 0; goto leave; } else if (c==' ' || c=='\t' || c=='\n' || c=='\r' || c=='\v' || c=='\f') { yylen = 0; goto start; } else if ((c >= 'A' && c <= 'Z') || (c >= 'a' && c <= 'z') || c == '_') goto ident; else if (c == '/') { c = input(); if (c == '/') goto comment1; else if (c == '*') goto comment2; else { unput(c); goto binop; } } else if (c >= '0' && c <= '9') goto digits_1; else if (c == OPENPAREN || c == OPENSQUAR || c == OPENCURLY) { pushls(&brackets, (int)c); if (c == OPENCURLY) { pushls(&closedFuncCharNo, linestarts[lineno] + charno - 1); } r = c; goto leave; } else if (c == CLOSSQUAR) { if (!emptyls(&brackets)) { if ((d = popls(&brackets)) != OPENSQUAR) { fatal(); post("opening bracket was a '%c', but found a '%c'\n",d,c); goto error2; } } else { fatal(); post("unmatched '%c'\n",c); goto error2; } r = c; goto leave; } else if (c == CLOSPAREN) { if (!emptyls(&brackets)) { if ((d = popls(&brackets)) != OPENPAREN) { fatal(); post("opening bracket was a '%c', but found a '%c'\n",d,c); goto error2; } } else { fatal(); post("unmatched '%c'\n",c); goto error2; } r = c; goto leave; } else if (c == CLOSCURLY) { if (!emptyls(&brackets)) { if ((d = popls(&brackets)) != OPENCURLY) { fatal(); post("opening bracket was a '%c', but found a '%c'\n",d,c); goto error2; } lastClosedFuncCharNo = popls(&closedFuncCharNo); } else { fatal(); post("unmatched '%c'\n",c); goto error2; } r = c; goto leave; } else if (c == '^') { r = c; goto leave; } else if (c == '~') { r = c; goto leave; } else if (c == ';') { r = c; goto leave; } else if (c == ':') { r = c; goto leave; } else if (c == '`') { r = c; goto leave; } else if (c == '\\') goto symbol1; else if (c == '\'') goto symbol3; else if (c == '"') goto string1; else if (c == '.') { if ((c = input()) == '.') { if ((c = input()) == '.') { r = ELLIPSIS; goto leave; } else { r = DOTDOT; unput(c); goto leave; } } else { unput(c); r = '.'; goto leave; } } else if (c == '#') { if ((c = input()) == OPENCURLY) { pushls(&brackets, OPENCURLY); pushls(&closedFuncCharNo, linestarts[lineno] + charno - 2); r = BEGINCLOSEDFUNC; } else { unput(c); r = '#'; } goto leave; } else if (c == '$') { c = input(); if (c == '\\') { c = input(); switch (c) { case 'n' : c = '\n'; break; case 'r' : c = '\r'; break; case 't' : c = '\t'; break; case 'f' : c = '\f'; break; case 'v' : c = '\v'; break; } } r = processchar(c); goto leave; } else if (c == ',') { r = c; goto leave; } else if (c == '=') { c = input(); if (strchr(binopchars, c)) goto binop; else { unput(c); r = '='; goto leave; } } else if (strchr(binopchars, c)) goto binop; else if(!(isprint(c) || isspace(c) || c == 0)) { yylen = 0; goto start; } else goto error1; ident: c = input(); if ((c >= 'A' && c <= 'Z') || (c >= 'a' && c <= 'z') || c == '_' || (c >= '0' && c <= '9')) goto ident; else if (c == ':') { yytext[yylen] = 0; r = processkeywordbinop(yytext) ; goto leave; } else { unput(c); yytext[yylen] = 0; r = processident(yytext) ; goto leave; } symbol1: c = input(); if ((c >= 'A' && c <= 'Z') || (c >= 'a' && c <= 'z') || c == '_') goto symbol2; else if (c >= '0' && c <= '9') goto symbol4; else { unput(c); yytext[yylen] = 0; r = processsymbol(yytext) ; goto leave; } symbol2: c = input(); if ((c >= 'A' && c <= 'Z') || (c >= 'a' && c <= 'z') || c == '_' || (c >= '0' && c <= '9')) goto symbol2; else { unput(c); yytext[yylen] = 0; r = processsymbol(yytext) ; goto leave; } symbol4: c = input(); if (c >= '0' && c <= '9') goto symbol4; else { unput(c); yytext[yylen] = 0; r = processsymbol(yytext) ; goto leave; } binop: c = input(); if (c == 0) goto binop2; if (strchr(binopchars, c)) goto binop; else { binop2: unput(c); yytext[yylen] = 0; r = processbinop(yytext) ; goto leave; } radix_digits_1: c = input(); if (c >= '0' && c <= '0' + sc_min(10,radix) - 1) goto radix_digits_1; if (c >= 'a' && c <= 'a' + sc_min(36,radix) - 11) goto radix_digits_1; if (c >= 'A' && c <= 'A' + sc_min(36,radix) - 11) goto radix_digits_1; if (c == '.') { goto radix_digits_2; } unput(c); yytext[yylen] = 0; r = processintradix(yytext, yylen, radix); goto leave; radix_digits_2: c = input(); if (c >= '0' && c <= '0' + sc_min(10,radix) - 1) goto radix_digits_2; if (c >= 'A' && c <= 'A' + sc_min(36,radix) - 11) goto radix_digits_2; // do not allow lower case after decimal point. unput(c); yytext[yylen] = 0; r = processfloatradix(yytext, yylen, radix); goto leave; hexdigits: c = input(); if (c >= '0' && c <= '9') goto hexdigits; if (c >= 'a' && c <= 'f') goto hexdigits; if (c >= 'A' && c <= 'F') goto hexdigits; unput(c); yytext[yylen] = 0; r = processhex(yytext); goto leave; digits_1: /* number started with digits */ c = input(); if (c >= '0' && c <= '9') goto digits_1; else if (c == 'r') { radix = sc_strtoi(yytext, yylen-1, 10); yylen = 0; goto radix_digits_1; } else if (c == 'e' || c == 'E') goto expon_1; else if (c == '.') { c2 = input(); if (c2 >= '0' && c2 <= '9') goto digits_2; else { unput(c2); unput(c); yytext[yylen] = 0; r = processint(yytext); goto leave; } } else if (c == 'b' || c == 's') { d = input(); if (d >= '0' && d <= '9') goto accidental1; if (d == c) goto accidental2; goto accidental3; accidental1: d = input(); if (d >= '0' && d <= '9') goto accidental1; unput(d); yytext[yylen] = 0; r = processaccidental1(yytext); goto leave; accidental2: d = input(); if (d == c) goto accidental2; accidental3: unput(d); yytext[yylen] = 0; r = processaccidental2(yytext); goto leave; } else if (c == 'x') { yylen = 0; goto hexdigits; } else { unput(c); yytext[yylen] = 0; r = processint(yytext); goto leave; } digits_2: c = input(); if (c >= '0' && c <= '9') goto digits_2; else if (c == 'e' || c == 'E') goto expon_1; // else if (c == 'π' || c == '∏') { // --yylen; // yytext[yylen] = 0; // r = processfloat(yytext, 1); // goto leave; // } else { unput(c); yytext[yylen] = 0; r = processfloat(yytext, 0); goto leave; } expon_1: /* e has been seen, need digits */ c = input(); if (c >= '0' && c <= '9') goto expon_3; else if (c == '+' || c == '-') goto expon_2; else goto error1; expon_2: /* + or - seen but still need digits */ c = input(); if (c >= '0' && c <= '9') goto expon_3; else goto error1; expon_3: c = input(); if (c >= '0' && c <= '9') goto expon_3; // else if (c == 'π' || c == '∏') { // --yylen; // yytext[yylen] = 0; // r = processfloat(yytext, 1); // goto leave; // } else { unput(c); yytext[yylen] = 0; r = processfloat(yytext, 0); goto leave; } symbol3 : { int startline, endchar; startline = lineno; endchar = '\''; /*do { c = input(); } while (c != endchar && c != 0);*/ for (;yylen<MAXYYLEN;) { c = input(); if (c == '\n' || c == '\r') { asRelativePath(curfilename,extPath); post("Symbol open at end of line on line %d in file '%s'\n", startline+errLineOffset, extPath); yylen = 0; r = 0; goto leave; } if (c == '\\') { yylen--; c = input(); } else if (c == endchar) break; if (c == 0) break; } if (c == 0) { asRelativePath(curfilename,extPath); post("Open ended symbol ... started on line %d in file '%s'\n", startline+errLineOffset, extPath); yylen = 0; r = 0; goto leave; } yytext[yylen] = 0; yytext[yylen-1] = 0; r = processsymbol(yytext); goto leave; } string1 : { int startline, endchar; startline = lineno; endchar = '"'; for (;yylen<MAXYYLEN;) { c = input(); if (c == '\\') { yylen--; c = input(); switch (c) { case 'n' : yytext[yylen-1] = '\n'; break; case 'r' : yytext[yylen-1] = '\r'; break; case 't' : yytext[yylen-1] = '\t'; break; case 'f' : yytext[yylen-1] = '\f'; break; case 'v' : yytext[yylen-1] = '\v'; break; } } else if (c == '\r') c = '\n'; else if (c == endchar) break; if (c == 0) break; } if (c == 0) { asRelativePath(curfilename,extPath); post("Open ended string ... started on line %d in file '%s'\n", startline+errLineOffset, extPath); yylen = 0; r = 0; goto leave; } yylen--; do { c = input0(); } while (c && isspace(c)); if (c == '"') goto string1; else if (c) unput0(c); yytext[yylen] = 0; r = processstring(yytext); goto leave; } comment1: /* comment -- to end of line */ do { c = input0(); } while (c != '\n' && c != '\r' && c != 0); yylen = 0; if (c == 0) { r = 0; goto leave; } else goto start; comment2 : { int startline, clevel, prevc; startline = lineno; prevc = 0; clevel = 1; do { c = input0(); if (c == '/' && prevc == '*') { if (--clevel <= 0) break; } else if (c == '*' && prevc == '/') clevel++; prevc = c; } while (c != 0); yylen = 0; if (c == 0) { asRelativePath(curfilename,extPath); post("Open ended comment ... started on line %d in file '%s'\n", startline+errLineOffset, extPath); r = 0; goto leave; } goto start; } error1: yytext[yylen] = 0; asRelativePath(curfilename, extPath); post("illegal input string '%s' \n at '%s' line %d char %d\n", yytext, extPath, lineno+errLineOffset, charno); post("code %d\n", c); //postfl(" '%c' '%s'\n", c, binopchars); //postfl("%d\n", strchr(binopchars, c)); error2: asRelativePath(curfilename, extPath); post(" in file '%s' line %d char %d\n", extPath, lineno+errLineOffset, charno); r = BADTOKEN; goto leave; leave: yytext[yylen] = 0; #if DEBUGLEX if (gDebugLexer) postfl("yylex: %d '%s'\n",r,yytext); #endif //if (lexCmdLine>0) postfl("yylex: %d '%s'\n",r,yytext); return r; }
bool scanForClosingBracket() { int r, c, d, startLevel; bool res = true; // finite state machine to parse input stream into tokens #if DEBUGLEX if (gDebugLexer) postfl("->scanForClosingBracket\n"); #endif startLevel = brackets.num; start: c = input0(); if (c == 0) goto leave; else if (c==' ' || c=='\t' || c=='\n' || c=='\r' || c=='\v' || c=='\f') { goto start; } else if (c == '\'') goto symbol3; else if (c == '"') goto string1; else if (c == '/') { c = input0(); if (c == '/') goto comment1; else if (c == '*') goto comment2; else { unput(c); goto start; } } else if (c == '$') { c = input0(); if (c == '\\') { c = input0(); switch (c) { case 'n' : c = '\n'; break; case 'r' : c = '\r'; break; case 't' : c = '\t'; break; case 'f' : c = '\f'; break; case 'v' : c = '\v'; break; } } goto start; } else if (c == OPENPAREN || c == OPENSQUAR || c == OPENCURLY) { pushls(&brackets, (int)c); r = c; goto start; } else if (c == CLOSSQUAR) { if (!emptyls(&brackets)) { if ((d = popls(&brackets)) != OPENSQUAR) { fatal(); post("opening bracket was a '%c', but found a '%c'\n",d,c); goto error1; } } else { fatal(); post("unmatched '%c'\n",c); goto error1; } r = c; if (brackets.num < startLevel) goto leave; else goto start; } else if (c == CLOSPAREN) { if (!emptyls(&brackets)) { if ((d = popls(&brackets)) != OPENPAREN) { fatal(); post("opening bracket was a '%c', but found a '%c'\n",d,c); goto error1; } } else { fatal(); post("unmatched '%c'\n",c); goto error1; } if (brackets.num < startLevel) goto leave; else goto start; } else if (c == CLOSCURLY) { if (!emptyls(&brackets)) { if ((d = popls(&brackets)) != OPENCURLY) { fatal(); post("opening bracket was a '%c', but found a '%c'\n",d,c); goto error1; } } else { fatal(); post("unmatched '%c'\n",c); goto error1; } if (brackets.num < startLevel) goto leave; else goto start; } else { goto start; } symbol3 : { int startline, endchar; startline = lineno; endchar = '\''; do { c = input0(); if (c == '\\') { c = input0(); } } while (c != endchar && c != 0); if (c == 0) { char extPath[MAXPATHLEN]; asRelativePath(curfilename, extPath); post("Open ended symbol ... started on line %d in file '%s'\n", startline, extPath); goto error2; } goto start; } string1 : { int startline, endchar; startline = lineno; endchar = '\"'; do { c = input0(); if (c == '\\') { c = input0(); } } while (c != endchar && c != 0); if (c == 0) { char extPath[MAXPATHLEN]; asRelativePath(curfilename, extPath); post("Open ended string ... started on line %d in file '%s'\n", startline, extPath); goto error2; } goto start; } comment1: /* comment -- to end of line */ do { c = input0(); } while (c != '\n' && c != '\r' && c != 0); if (c == 0) { goto leave; } else goto start; comment2 : { int startline, clevel, prevc; startline = lineno; prevc = 0; clevel = 1; do { c = input0(); if (c == '/' && prevc == '*') { if (--clevel <= 0) break; } else if (c == '*' && prevc == '/') clevel++; prevc = c; } while (c != 0); if (c == 0) { char extPath[MAXPATHLEN]; asRelativePath(curfilename, extPath); post("Open ended comment ... started on line %d in file '%s'\n", startline, extPath); goto error2; } goto start; } error1: char extPath[MAXPATHLEN]; asRelativePath(curfilename, extPath); post(" in file '%s' line %d char %d\n", extPath, lineno, charno); res = false; goto leave; error2: res = false; goto leave; leave: #if DEBUGLEX if (gDebugLexer) postfl("<-scanForClosingBracket\n"); #endif return res; }
int main(int argc, char *argv[]) { try { utility::thread_number_range threads(get_default_num_threads); utility::parse_cli_arguments(argc, argv, utility::cli_argument_pack() //"-h" option for for displaying help is present implicitly .positional_arg(threads,"#threads"," number of threads to use; a range of the " "form low[:high]\n where low and optional high are " "non-negative integers,\n or 'auto' for the TBB " "default") .arg(verbose,"verbose"," print diagnostic output to screen") .arg(silent,"silent"," limits output to timing info; overrides verbose") ); if (silent) verbose = false; // make silent override verbose tick_count start = tick_count::now(); for(int p = threads.first; p <= threads.last; ++p ) { task_scheduler_init init(p); if (!silent) cout << "graph test running on " << p << " threads.\n"; graph g; { // test buffer: 0, 1 buffer b(g); toggle input(g); led output(g, "OUTPUT", false); // false means we will explicitly call display to see LED make_edge(input.get_out(), b.get_in(0)); make_edge(b.get_out(), output.get_in()); if (!silent) printf("Testing buffer...\n"); input.activate(); // 0 g.wait_for_all(); if (!silent) output.display(); assert(output.get_value() == low); input.flip(); // 1 g.wait_for_all(); if (!silent) output.display(); assert(output.get_value() == high); } { // test not_gate: 0, 1 not_gate n(g); toggle input(g); led output(g, "OUTPUT", false); make_edge(input.get_out(), n.get_in(0)); make_edge(n.get_out(), output.get_in()); if (!silent) printf("Testing not_gate...\n"); input.activate(); // 0 g.wait_for_all(); if (!silent) output.display(); assert(output.get_value() == high); input.flip(); // 1 g.wait_for_all(); if (!silent) output.display(); assert(output.get_value() == low); } { // test two-input and_gate: 00, 01, 10, 11 and_gate<two_input> a(g); toggle input0(g); toggle input1(g); led output(g, "OUTPUT", false); make_edge(input0.get_out(), a.get_in(0)); make_edge(input1.get_out(), a.get_in(1)); make_edge(a.get_out(), output.get_in()); if (!silent) printf("Testing and_gate...\n"); input1.activate(); input0.activate(); // 0 0 g.wait_for_all(); if (!silent) output.display(); assert(output.get_value() == low); input0.flip(); // 0 1 g.wait_for_all(); if (!silent) output.display(); assert(output.get_value() == low); input1.flip(); input0.flip(); // 1 0 g.wait_for_all(); if (!silent) output.display(); assert(output.get_value() == low); input0.flip(); // 1 1 g.wait_for_all(); if (!silent) output.display(); assert(output.get_value() == high); } { // test three-input or_gate: 000, 001, 010, 100, 011, 101, 110, 111 or_gate<three_input> o(g); toggle input0(g); toggle input1(g); toggle input2(g); led output(g, "OUTPUT", false); make_edge(input0.get_out(), o.get_in(0)); make_edge(input1.get_out(), o.get_in(1)); make_edge(input2.get_out(), o.get_in(2)); make_edge(o.get_out(), output.get_in()); if (!silent) printf("Testing or_gate...\n"); input2.activate(); input1.activate(); input0.activate(); // 0 0 0 g.wait_for_all(); if (!silent) output.display(); assert(output.get_value() == low); input0.flip(); // 0 0 1 g.wait_for_all(); if (!silent) output.display(); assert(output.get_value() == high); input1.flip(); input0.flip(); // 0 1 0 g.wait_for_all(); if (!silent) output.display(); assert(output.get_value() == high); input2.flip(); input1.flip(); // 1 0 0 g.wait_for_all(); if (!silent) output.display(); assert(output.get_value() == high); input2.flip(); input1.flip(); input0.flip(); // 0 1 1 g.wait_for_all(); if (!silent) output.display(); assert(output.get_value() == high); input2.flip(); input1.flip(); // 1 0 1 g.wait_for_all(); if (!silent) output.display(); assert(output.get_value() == high); input1.flip(); input0.flip(); // 1 1 0 g.wait_for_all(); if (!silent) output.display(); assert(output.get_value() == high); input0.flip(); // 1 1 1 g.wait_for_all(); if (!silent) output.display(); assert(output.get_value() == high); } { // test two-input xor_gate: 00, 01, 10, 11 xor_gate<two_input> x(g); toggle input0(g); toggle input1(g); led output(g, "OUTPUT", false); make_edge(input0.get_out(), x.get_in(0)); make_edge(input1.get_out(), x.get_in(1)); make_edge(x.get_out(), output.get_in()); if (!silent) printf("Testing xor_gate...\n"); input1.activate(); input0.activate(); // 0 0 g.wait_for_all(); if (!silent) output.display(); assert(output.get_value() == low); input0.flip(); // 0 1 g.wait_for_all(); if (!silent) output.display(); assert(output.get_value() == high); input1.flip(); input0.flip(); // 1 0 g.wait_for_all(); if (!silent) output.display(); assert(output.get_value() == high); input0.flip(); // 1 1 g.wait_for_all(); if (!silent) output.display(); assert(output.get_value() == low); } { // test two-input nor_gate: 00, 01, 10, 11 nor_gate<two_input> n(g); toggle input0(g); toggle input1(g); led output(g, "OUTPUT", false); make_edge(input0.get_out(), n.get_in(0)); make_edge(input1.get_out(), n.get_in(1)); make_edge(n.get_out(), output.get_in()); if (!silent) printf("Testing nor_gate...\n"); input1.activate(); input0.activate(); // 0 0 g.wait_for_all(); if (!silent) output.display(); assert(output.get_value() == high); input0.flip(); // 0 1 g.wait_for_all(); if (!silent) output.display(); assert(output.get_value() == low); input1.flip(); input0.flip(); // 1 0 g.wait_for_all(); if (!silent) output.display(); assert(output.get_value() == low); input0.flip(); // 1 1 g.wait_for_all(); if (!silent) output.display(); assert(output.get_value() == low); } { // test steady_signal and digit steady_signal input0(g, high); steady_signal input1(g, low); and_gate<two_input> a(g); or_gate<two_input> o(g); xor_gate<two_input> x(g); nor_gate<two_input> n(g); digit output(g, "OUTPUT", false); make_edge(input0.get_out(), a.get_in(0)); make_edge(input1.get_out(), a.get_in(1)); make_edge(a.get_out(), output.get_in(0)); make_edge(input0.get_out(), o.get_in(0)); make_edge(input1.get_out(), o.get_in(1)); make_edge(o.get_out(), output.get_in(1)); make_edge(input0.get_out(), x.get_in(0)); make_edge(input1.get_out(), x.get_in(1)); make_edge(x.get_out(), output.get_in(2)); make_edge(input0.get_out(), n.get_in(0)); make_edge(input1.get_out(), n.get_in(1)); make_edge(n.get_out(), output.get_in(3)); if (!silent) printf("Testing steady_signal...\n"); input0.activate(); // 1 input1.activate(); // 0 g.wait_for_all(); if (!silent) output.display(); assert(output.get_value() == 6); } { // test push_button push_button p(g); buffer b(g); led output(g, "OUTPUT", !silent); // true means print all LED state changes make_edge(p.get_out(), b.get_in(0)); make_edge(b.get_out(), output.get_in()); if (!silent) printf("Testing push_button...\n"); p.press(); p.release(); p.press(); p.release(); g.wait_for_all(); } { // test one_bit_adder one_bit_adder my_adder(g); toggle A(g); toggle B(g); toggle CarryIN(g); led Sum(g, "SUM"); led CarryOUT(g, "CarryOUT"); make_edge(A.get_out(), my_adder.get_A()); make_edge(B.get_out(), my_adder.get_B()); make_edge(CarryIN.get_out(), my_adder.get_CI()); make_edge(my_adder.get_out(), Sum.get_in()); make_edge(my_adder.get_CO(), CarryOUT.get_in()); A.activate(); B.activate(); CarryIN.activate(); if (!silent) printf("A on\n"); A.flip(); g.wait_for_all(); if (!silent) Sum.display(); if (!silent) CarryOUT.display(); assert((Sum.get_value() == high) && (CarryOUT.get_value() == low)); if (!silent) printf("A off\n"); A.flip(); g.wait_for_all(); if (!silent) Sum.display(); if (!silent) CarryOUT.display(); assert((Sum.get_value() == low) && (CarryOUT.get_value() == low)); if (!silent) printf("B on\n"); B.flip(); g.wait_for_all(); if (!silent) Sum.display(); if (!silent) CarryOUT.display(); assert((Sum.get_value() == high) && (CarryOUT.get_value() == low)); if (!silent) printf("B off\n"); B.flip(); g.wait_for_all(); if (!silent) Sum.display(); if (!silent) CarryOUT.display(); assert((Sum.get_value() == low) && (CarryOUT.get_value() == low)); if (!silent) printf("CarryIN on\n"); CarryIN.flip(); g.wait_for_all(); if (!silent) Sum.display(); if (!silent) CarryOUT.display(); assert((Sum.get_value() == high) && (CarryOUT.get_value() == low)); if (!silent) printf("CarryIN off\n"); CarryIN.flip(); g.wait_for_all(); if (!silent) Sum.display(); if (!silent) CarryOUT.display(); assert((Sum.get_value() == low) && (CarryOUT.get_value() == low)); if (!silent) printf("A&B on\n"); A.flip(); B.flip(); g.wait_for_all(); if (!silent) Sum.display(); if (!silent) CarryOUT.display(); assert((Sum.get_value() == low) && (CarryOUT.get_value() == high)); if (!silent) printf("A&B off\n"); A.flip(); B.flip(); g.wait_for_all(); if (!silent) Sum.display(); if (!silent) CarryOUT.display(); assert((Sum.get_value() == low) && (CarryOUT.get_value() == low)); if (!silent) printf("A&CarryIN on\n"); A.flip(); CarryIN.flip(); g.wait_for_all(); if (!silent) Sum.display(); if (!silent) CarryOUT.display(); assert((Sum.get_value() == low) && (CarryOUT.get_value() == high)); if (!silent) printf("A&CarryIN off\n"); A.flip(); CarryIN.flip(); g.wait_for_all(); if (!silent) Sum.display(); if (!silent) CarryOUT.display(); assert((Sum.get_value() == low) && (CarryOUT.get_value() == low)); if (!silent) printf("B&CarryIN on\n"); B.flip(); CarryIN.flip(); g.wait_for_all(); if (!silent) Sum.display(); if (!silent) CarryOUT.display(); assert((Sum.get_value() == low) && (CarryOUT.get_value() == high)); if (!silent) printf("B&CarryIN off\n"); B.flip(); CarryIN.flip(); g.wait_for_all(); if (!silent) Sum.display(); if (!silent) CarryOUT.display(); assert((Sum.get_value() == low) && (CarryOUT.get_value() == low)); if (!silent) printf("A&B&CarryIN on\n"); A.flip(); B.flip(); CarryIN.flip(); g.wait_for_all(); if (!silent) Sum.display(); if (!silent) CarryOUT.display(); assert((Sum.get_value() == high) && (CarryOUT.get_value() == high)); if (!silent) printf("A&B&CarryIN off\n"); A.flip(); B.flip(); CarryIN.flip(); g.wait_for_all(); if (!silent) Sum.display(); if (!silent) CarryOUT.display(); assert((Sum.get_value() == low) && (CarryOUT.get_value() == low)); } { // test four_bit_adder four_bit_adder four_adder(g); std::vector<toggle> A(4, toggle(g)); std::vector<toggle> B(4, toggle(g)); toggle CarryIN(g); digit Sum(g, "SUM"); led CarryOUT(g, "CarryOUT"); for (int i=0; i<4; ++i) { make_edge(A[i].get_out(), four_adder.get_A(i)); make_edge(B[i].get_out(), four_adder.get_B(i)); make_edge(four_adder.get_out(i), Sum.get_in(i)); } make_edge(CarryIN.get_out(), four_adder.get_CI()); make_edge(four_adder.get_CO(), CarryOUT.get_in()); // Activate all switches at low state for (int i=0; i<4; ++i) { A[i].activate(); B[i].activate(); } CarryIN.activate(); if (!silent) printf("1+0\n"); A[0].flip(); g.wait_for_all(); if (!silent) Sum.display(); if (!silent) CarryOUT.display(); assert((Sum.get_value() == 1) && (CarryOUT.get_value() == low)); if (!silent) printf("0+1\n"); A[0].flip(); B[0].flip(); g.wait_for_all(); if (!silent) Sum.display(); if (!silent) CarryOUT.display(); assert((Sum.get_value() == 1) && (CarryOUT.get_value() == low)); if (!silent) printf("3+4\n"); A[0].flip(); A[1].flip(); B[0].flip(); B[2].flip(); g.wait_for_all(); if (!silent) Sum.display(); if (!silent) CarryOUT.display(); assert((Sum.get_value() == 7) && (CarryOUT.get_value() == low)); if (!silent) printf("6+1\n"); A[0].flip(); A[2].flip(); B[0].flip(); B[2].flip(); g.wait_for_all(); if (!silent) Sum.display(); if (!silent) CarryOUT.display(); assert((Sum.get_value() == 7) && (CarryOUT.get_value() == low)); if (!silent) printf("0+0+carry\n"); A[1].flip(); A[2].flip(); B[0].flip(); CarryIN.flip(); g.wait_for_all(); if (!silent) Sum.display(); if (!silent) CarryOUT.display(); assert((Sum.get_value() == 1) && (CarryOUT.get_value() == low)); if (!silent) printf("15+15+carry\n"); A[0].flip(); A[1].flip(); A[2].flip(); A[3].flip(); B[0].flip(); B[1].flip(); B[2].flip(); B[3].flip(); g.wait_for_all(); if (!silent) Sum.display(); if (!silent) CarryOUT.display(); assert((Sum.get_value() == 0xf) && (CarryOUT.get_value() == high)); if (!silent) printf("8+8\n"); A[0].flip(); A[1].flip(); A[2].flip(); B[0].flip(); B[1].flip(); B[2].flip(); CarryIN.flip(); g.wait_for_all(); if (!silent) Sum.display(); if (!silent) CarryOUT.display(); assert((Sum.get_value() == 0) && (CarryOUT.get_value() == high)); if (!silent) printf("0+0\n"); A[3].flip(); B[3].flip(); g.wait_for_all(); if (!silent) Sum.display(); if (!silent) CarryOUT.display(); assert((Sum.get_value() == 0) && (CarryOUT.get_value() == low)); } { // test D_latch D_latch my_d_latch(g); toggle D(g); pulse E(g, 500, 4); // clock changes every 500ms; stops after 4 changes led Q(g, " Q", verbose); // if true, LEDs print at every state change led notQ(g, "~Q", verbose); make_edge(D.get_out(), my_d_latch.get_D()); make_edge(E.get_out(), my_d_latch.get_E()); make_edge(my_d_latch.get_Q(), Q.get_in()); make_edge(my_d_latch.get_notQ(), notQ.get_in()); D.activate(); if (!silent) printf("Toggling D\n"); E.activate(); D.flip(); g.wait_for_all(); if (!silent && !verbose) { Q.display(); notQ.display(); } assert((Q.get_value() == high) && (notQ.get_value() == low)); E.reset(); if (!silent) printf("Toggling D\n"); E.activate(); D.flip(); g.wait_for_all(); if (!silent && !verbose) { Q.display(); notQ.display(); } assert((Q.get_value() == low) && (notQ.get_value() == high)); E.reset(); if (!silent) printf("Toggling D\n"); E.activate(); D.flip(); g.wait_for_all(); if (!silent && !verbose) { Q.display(); notQ.display(); } assert((Q.get_value() == high) && (notQ.get_value() == low)); E.reset(); if (!silent) printf("Toggling D\n"); E.activate(); D.flip(); g.wait_for_all(); if (!silent && !verbose) { Q.display(); notQ.display(); } assert((Q.get_value() == low) && (notQ.get_value() == high)); E.reset(); if (!silent) printf("Toggling D\n"); E.activate(); D.flip(); g.wait_for_all(); if (!silent && !verbose) { Q.display(); notQ.display(); } assert((Q.get_value() == high) && (notQ.get_value() == low)); } } utility::report_elapsed_time((tbb::tick_count::now() - start).seconds()); return 0; } catch(std::exception& e) { cerr<<"error occurred. error text is :\"" <<e.what()<<"\"\n"; return 1; } }
void OCIOLookTransform::_validate(bool for_real) { input0().validate(for_real); if(!m_hasColorSpaces) { error("No colorspaces available for input and/or output."); return; } int inputColorSpaceCount = static_cast<int>(m_inputColorSpaceCstrNames.size()) - 1; if(m_inputColorSpaceIndex < 0 || m_inputColorSpaceIndex >= inputColorSpaceCount) { std::ostringstream err; err << "Input colorspace index (" << m_inputColorSpaceIndex << ") out of range."; error(err.str().c_str()); return; } int outputColorSpaceCount = static_cast<int>(m_outputColorSpaceCstrNames.size()) - 1; if(m_outputColorSpaceIndex < 0 || m_outputColorSpaceIndex >= outputColorSpaceCount) { std::ostringstream err; err << "Output colorspace index (" << m_outputColorSpaceIndex << ") out of range."; error(err.str().c_str()); return; } try { const char * inputName = m_inputColorSpaceCstrNames[m_inputColorSpaceIndex]; const char * outputName = m_outputColorSpaceCstrNames[m_outputColorSpaceIndex]; OCIO::ConstConfigRcPtr config = OCIO::GetCurrentConfig(); config->sanityCheck(); OCIO::LookTransformRcPtr transform = OCIO::LookTransform::Create(); const char * look = m_lookCstrNames[m_lookIndex]; if(look != NULL) { transform->setLooks(look); } OCIO::ConstContextRcPtr context = getLocalContext(); OCIO::TransformDirection direction = OCIO::TRANSFORM_DIR_UNKNOWN; bool invertTransform = (m_dirIndex == 0) ? false : true; // Forward if(!invertTransform) { transform->setSrc(inputName); transform->setDst(outputName); direction = OCIO::TRANSFORM_DIR_FORWARD; } else { // The TRANSFORM_DIR_INVERSE applies an inverse for the end-to-end transform, // which would otherwise do dst->inv look -> src. // This is an unintuitive result for the artist (who would expect in, out to // remain unchanged), so we account for that here by flipping src/dst transform->setSrc(outputName); transform->setDst(inputName); direction = OCIO::TRANSFORM_DIR_INVERSE; } try { m_processor = config->getProcessor(context, transform, direction); } // We only catch the exceptions for missing files, and try to succeed // in this case. All other errors represent more serious problems and // should fail through. catch(const OCIO::ExceptionMissingFile &e) { if(!m_ignoreErrors) throw; m_processor = config->getProcessor(context, inputName, outputName); } } catch(const OCIO::Exception &e) { error(e.what()); return; } catch (...) { error("OCIOLookTransform: Unknown exception during _validate."); return; } if(m_processor->isNoOp()) { // TODO or call disable() ? set_out_channels(DD::Image::Mask_None); // prevents engine() from being called copy_info(); return; } set_out_channels(DD::Image::Mask_All); DD::Image::PixelIop::_validate(for_real); }