コード例 #1
0
ファイル: encmain.cpp プロジェクト: cheeyeo/dirac
bool WritePicData (std::ofstream &fdata, dirac_encoder_t *encoder)
{
    dirac_sourceparams_t &sparams = encoder->enc_ctx.src_params;
    dirac_framebuf_t &fbuf = encoder->dec_buf;
    bool ret_stat = true;

    if (encoder->decoded_frame_avail)
    {
        ios::iostate oldExceptions = fdata.exceptions();
        fdata.exceptions (ios::failbit | ios::badbit);
        try
        {
            assert (fbuf.buf[0] != 0);
            fdata.write ((char *)fbuf.buf[0], sparams.width*sparams.height);
            assert (fbuf.buf[1] != 0);
            assert (fbuf.buf[2] != 0);
            fdata.write ((char *)fbuf.buf[1],
            sparams.chroma_width*sparams.chroma_height);
            fdata.write ((char *)fbuf.buf[2],
            sparams.chroma_width*sparams.chroma_height);
        }
        catch (...)
        {
            std::cout << "Incomplete frame " << std::endl;
            ret_stat = false;
        }
        fdata.exceptions (oldExceptions);
    }
    return ret_stat;
}
コード例 #2
0
ファイル: encmain.cpp プロジェクト: cheeyeo/dirac
bool WriteDiagnosticsHeader (std::ofstream &fdata, dirac_encoder_t *encoder)
{
    bool ret_stat = true;
    dirac_sourceparams_t &srcparams = encoder->enc_ctx.src_params;
    ios::iostate oldExceptions = fdata.exceptions();
    fdata.exceptions (ios::failbit | ios::badbit);

    try
    {
        fdata << srcparams.chroma << std::endl;
        fdata << srcparams.width << std::endl;
        fdata << srcparams.height << std::endl;
        fdata << srcparams.source_sampling << std::endl;
        fdata << srcparams.topfieldfirst << std::endl;
        fdata << srcparams.frame_rate.numerator << std::endl;
        fdata << srcparams.frame_rate.denominator << std::endl;
        fdata << srcparams.pix_asr.numerator << std::endl;
        fdata << srcparams.pix_asr.denominator << std::endl;
        fdata << encoder->enc_ctx.enc_params.picture_coding_mode << std::endl;
    }

    catch (...)
    {
        std::cerr << "Error writing sequence info in diagnostics file." << std::endl;
        ret_stat =  false;
    }
    fdata.exceptions (oldExceptions);
    return ret_stat;
}
コード例 #3
0
ファイル: FileSystem.hpp プロジェクト: Nakul/AirSim
    static std::string createLogFile(std::string suffix, std::ofstream& flog)
    {
        std::string filepath = getLogFileNamePath("log_", suffix, ".tsv", true);
        createTextFile(filepath, flog);

        Utils::log(Utils::stringf("log file started: %s", filepath.c_str()));
        flog.exceptions(flog.exceptions() | std::ios::failbit | std::ifstream::badbit);
        return filepath;
    }
コード例 #4
0
ファイル: FileSystem.hpp プロジェクト: Jinwei1/AirSim
    static std::string createLogFile(const std::string& suffix, std::ofstream& flog)
    {
        std::string log_folderpath = common_utils::FileSystem::getLogFolderPath(false);
        std::string filepath = getLogFileNamePath(log_folderpath, "log_", suffix, ".tsv", true);
        createTextFile(filepath, flog);

        Utils::log(Utils::stringf("log file started: %s", filepath.c_str()));
        flog.exceptions(flog.exceptions() | std::ios::failbit | std::ifstream::badbit);
        return filepath;
    }
コード例 #5
0
ファイル: proto_sim.cpp プロジェクト: semajrolyat/tas
/**
    Forks off the controller process at a lower priority than the coordinator
    process
*/
void fork_controller() {
    // Fork the Controller
    controller_pid = fork();
    if (controller_pid < 0) {
        throw std::runtime_error( "Failed to fork controller." ) ;
    }
    if (controller_pid == 0) {
        controller_pid = getpid();
        int priority_result = setpriority( PRIO_PROCESS, controller_pid, sim_priority + 1 );
        int controller_priority = getpriority( PRIO_PROCESS, controller_pid );

        //controller_log.exceptions( std::ofstream::failbit | std::ofstream::badbit );
        controller_log.exceptions( std::ofstream::failbit );

        try {
            controller_log.open("controller.log");
        } catch (std::ofstream::failure ex) {
            printf( "FAILED TO OPEN STREAM.\n" );  // Likely won't print to console
        }

//        if( !controller_log.is_open() )
        //            printf( "FAILED TO OPEN STREAM.\n" );

        if( priority_result < 0 ) {
            controller_log << "ERROR: Failed to set priority: " << priority_result << "\n";
        } else {
            controller_log << "Controller PID: " << controller_pid << "\n";
            controller_log << "Controller Priority: " << controller_priority << "\n";
        }


        controller();
    }
}
コード例 #6
0
ファイル: proto_threading.cpp プロジェクト: gparmer/tas
void fork_controller() {

    controller_pid = fork();
    if (controller_pid < 0) {
        throw std::runtime_error( "Failed to fork controller." ) ;
    }
    if (controller_pid == 0) {
        controller_pid = getpid();

        int priority_result = setpriority( PRIO_PROCESS, controller_pid, sim_priority + 1 );
        int controller_priority = getpriority( PRIO_PROCESS, controller_pid );

        controller_log.exceptions( std::ofstream::failbit );

        try {
            controller_log.open("controller.log");
        } catch (std::ofstream::failure ex) {
            printf( "FAILED TO OPEN STREAM.\n" );  // Likely won't print to console
        }

        if( priority_result < 0 ) {
            controller_log << "ERROR: Failed to set priority: " << priority_result << "\n";
        } else {
            controller_log << "Controller PID: " << controller_pid << "\n";
            controller_log << "Controller Priority: " << controller_priority << "\n";
        }

        // execute the controller program
        execl( "controller", "contoller", 0 );

        // exit on fail to exec
        _exit(1);
    }
}
コード例 #7
0
ファイル: file_writer.hpp プロジェクト: saleyn/utxx
 void open(const std::string& a_fname, bool a_append = false) {
     using std::ios;
     using std::ios_base;
     if (m_open) return;
     m_file.exceptions(ios::failbit | ios::badbit);
     ios_base::openmode l_mode = ios::out | ios::binary;
     if (a_append)
         l_mode |= ios::app;
     else
         l_mode |= ios::trunc;
     m_file.open(a_fname.c_str(), l_mode);
     m_offset = m_file.tellp();
     m_open = true;
     m_fname = a_fname;
     m_buf.reset();
     BOOST_ASSERT(m_buf.capacity() > 0);
 }
コード例 #8
0
ファイル: Log.hpp プロジェクト: sawbg/chip-chip-array
	void Log::Open(auto dir, LogMode mode) {
#ifdef LOG
		// format date and time
		char date[32];
		time_t sec = time(nullptr);
		struct tm * loctime = localtime(&sec);
		strftime(date, 32, "%m-%d_%H-%M-%S", loctime);

		// create temperary strings
		this->dir = std::string(dir);
		std::string datestr = std::string(date);

		// add path separator if necessary
		if(this->dir[this->dir.length() - 1] != PATH_SEP) {
			this->dir += PATH_SEP;
		}

		// add directory for log and images if necessary
		if(mode == LogMode::Multi) this->dir += datestr + PATH_SEP;

		int ret = mkdir(this->dir.c_str(), S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP
				| S_IROTH | S_IWOTH | S_IXUSR | S_IXGRP
				| S_IXOTH);

		filename = this->dir + datestr + ".log";

		// set class mode
		this->mode = mode;

		// Initializing file
		file.exceptions(std::ofstream::failbit
				| std::ofstream::badbit);

		try {
			file.open(filename, std::ofstream::out
					| std::ofstream::app);
		} catch(std::ofstream::failure ex) {
			LogError("Oh, no! An error has occurred opening the "
					"log file.", ex);
		}
#endif
	}
コード例 #9
0
void WindowsFileOpener::OpenOutputStream( std::ofstream &stream, std::ios_base::openmode openModeRequired )
{
	stream.exceptions( std::ifstream::failbit | std::ifstream::badbit | std::ifstream::eofbit );
	stream.open( _filePath.c_str(), openModeRequired );
}
コード例 #10
0
ファイル: encmain.cpp プロジェクト: cheeyeo/dirac
bool WriteDiagnosticsData (std::ofstream &fdata, dirac_encoder_t *encoder)
{
    dirac_instr_t &instr = encoder->instr;
    bool ret_stat = true;

    if (encoder->instr_data_avail)
    {
        ios::iostate oldExceptions = fdata.exceptions();
        fdata.exceptions (ios::failbit | ios::badbit);
        try
        {
            fdata << std::endl << "[frame:" << instr.pnum << "]";
            if (instr.ptype == INTRA_PICTURE)
            {
                fdata << ">intra" << std::endl;
                return true;
            }

            fdata << ">mo_comp";
            fdata << std::endl << std::endl << instr.num_refs << " ";
            for (int i=0; i<instr.num_refs; ++i)
            {
                fdata << instr.refs[i] << " ";
            }
            fdata << instr.ybsep << " " << instr.xbsep << " ";
            fdata << instr.sb_ylen << " " << instr.sb_xlen << " ";
            fdata << instr.mv_ylen << " " << instr.mv_xlen
                    << std::endl << std::endl ;
            for (int j=0; j<instr.sb_ylen; j++)
            {
                for (int i=0; i<instr.sb_xlen; i++)
                    fdata << instr.sb_split_mode[j*instr.sb_xlen + i] << " ";
                fdata << std::endl;
            }
            fdata << std::endl;

            for (int j=0; j<instr.sb_ylen; j++)
            {
                for (int i=0; i<instr.sb_xlen; i++)
                    fdata << instr.sb_costs[j*instr.sb_xlen + i] << " ";
                fdata << std::endl;
            }
            fdata << std::endl;

            for (int j=0; j<instr.mv_ylen; j++)
            {
                for (int i=0; i<instr.mv_xlen; i++)
                    fdata << instr.pred_mode[j*instr.mv_xlen + i] << " ";
                fdata << std::endl;
            }
            fdata << std::endl;

            for (int j=0; j<instr.mv_ylen; j++)
            {
                for (int i=0; i<instr.mv_xlen; i++)
                    fdata << instr.intra_costs[j*instr.mv_xlen + i] << " ";
                fdata << std::endl;
            }
            fdata << std::endl;

            if (instr.num_refs > 1)
            {
                for (int j=0; j<instr.mv_ylen; j++)
                {
                    for (int i=0; i<instr.mv_xlen; i++)
                    {
                        fdata << instr.bipred_costs[j*instr.mv_xlen + i].SAD
                        <<" " << instr.bipred_costs[j*instr.mv_xlen + i].mvcost
                        << " ";;
                    }
                    fdata << std::endl;
                }
            }
            fdata << std::endl;

            for (int j=0; j<instr.mv_ylen; j++)
            {
                for (int i=0; i<instr.mv_xlen; i++)
                    fdata << instr.dc_ycomp[j*instr.mv_xlen + i] << " ";
                fdata << std::endl;
            }

            // FIXME: always expects 3 components
            fdata << std::endl;
            for (int j=0; j<instr.mv_ylen; j++)
            {
                for (int i=0; i<instr.mv_xlen; i++)
                    fdata << instr.dc_ucomp[j*instr.mv_xlen + i] << " ";
                fdata << std::endl;
            }
            fdata << std::endl;
            for (int j=0; j<instr.mv_ylen; j++)
            {
                for (int i=0; i<instr.mv_xlen; i++)
                    fdata << instr.dc_vcomp[j*instr.mv_xlen + i] << " ";
                fdata << std::endl;
            }

            for (int k = 0; k < instr.num_refs; k++)
            {
                fdata << std::endl;
                for (int j=0; j<instr.mv_ylen; j++)
                {
                    for (int i=0; i<instr.mv_xlen; i++)
                    {
                        fdata << instr.mv[k][j*instr.mv_xlen + i].x
                        <<" " << instr.mv[k][j*instr.mv_xlen + i].y
                        << " ";;
                    }
                    fdata << std::endl;
                }
                fdata << std::endl;
                for (int j=0; j<instr.mv_ylen; j++)
                {
                    for (int i=0; i<instr.mv_xlen; i++)
                    {
                        fdata << instr.pred_costs[k][j*instr.mv_xlen + i].SAD
                        <<" " << instr.pred_costs[k][j*instr.mv_xlen + i].mvcost
                        << " ";;
                    }
                    fdata << std::endl;
                }
                fdata << std::endl;
            }
        }
        catch (...)
        {
            std::cout << "Error writing diagnostics data" << std::endl;
            ret_stat = false;
        }
        fdata.exceptions (oldExceptions);
    }
    return ret_stat;
}
コード例 #11
0
ファイル: output.cpp プロジェクト: chuck211991/HWserver
void start_table(std::ofstream &ostr, std::string &filename, bool for_instructor,
                 const std::vector<Student*> &students, int rank, int month, int day, int year) {
  
  ostr.exceptions ( std::ofstream::failbit | std::ofstream::badbit );
  try {
    ostr.open(filename.c_str());
  }
  catch (std::ofstream::failure e) {
    std::cout << "FAILED TO OPEN " << filename << std::endl;
    std::cerr << "Exception opening/reading file";
    exit(0);
  }

  Student* s = NULL;
  if (rank != -1) {
    s = students[rank];
    assert (s != NULL);
  }


  // -------------------------------------------------------------------------------
  // PRINT INSTRUCTOR SUPPLIED MESSAGES
  for (int i = 0; i < MESSAGES.size(); i++) {
    ostr << "" << MESSAGES[i] << "<br>\n";
  }
  // get todays date
  //time_t now = time(0);  
  //struct tm * now2 = localtime( & now );
  if (s != NULL) {
    ostr << "<em>Information last updated: " << s->getLastUpdate() << "</em><br>\n";
  }
  ostr << "<p>&nbsp;</p>\n";


  ostr << "<p>&nbsp;</p>\n";

  // -------------------------------------------------------------------------------
  // BEGIN THE TABLE
  ostr << "<table border=2 cellpadding=5 cellspacing=0>\n";

  // open the title row
  ostr << "<tr>";


  // -------------------------------------------------------------------------------
  // RANK & SECTION
  if (for_instructor) {
    ostr << "<td align=center>#</td>";   
  }
  ostr << "<td align=center>SECTION</td>";   
  
  // -------------------------------------------------------------------------------
  // INSTRUCTOR NOTES
  if (for_instructor && DISPLAY_INSTRUCTOR_NOTES) {
    ostr << "<td align=center>part.</td>" 
         << "<td align=center>under.</td>";
    ostr << "<td align=center>notes</td>";
  }

  
  // -------------------------------------------------------------------------------  
  // NAME
  ostr << "<td align=center>USERNAME</td>";
  ostr << "<td align=center>LAST</td>" 
       << "<td align=center>FIRST</td>";
  
  // -------------------------------------------------------------------------------  
  // EXAM SEATING
  if (DISPLAY_EXAM_SEATING) {
    ostr << "<td align=center bgcolor=888888>&nbsp;</td>";
    ostr << "<td align=center>exam room</td>";
    ostr << "<td align=center>exam zone</td>";
    ostr << "<td align=center>exam time</td>";
  }

  // -------------------------------------------------------------------------------  
  // ICLICKER REMOTE
  if (DISPLAY_ICLICKER && ICLICKER_QUESTION_NAMES.size() > 0) {
    ostr << "<td align=center>iclicker status</td>";
  }

  // -------------------------------------------------------------------------------  
  // GRADE SUMMARY
  if (DISPLAY_GRADE_SUMMARY) {
    if (DISPLAY_FINAL_GRADE) {
      ostr << "<td align=center bgcolor=888888>&nbsp;</td>";
      ostr << "<td align=center>GRADE</td>";
    }
    ostr << "<td align=center bgcolor=888888>&nbsp;</td>";
    ostr << "<td align=center>OVERALL</td>";
    if (for_instructor && DISPLAY_MOSS_DETAILS) {
      ostr << "<td align=center>OVERALL W/ MOSS PENALTY</td>";
      ostr << "<td align=center>GRADE BEFORE MOSS</td>";
    }
    ostr << "<td align=center bgcolor=888888>&nbsp;</td>";
    for (int i = 0; i < ALL_GRADEABLES.size(); i++) {
      ostr << "<td align=center>" << gradeable_to_string(ALL_GRADEABLES[i]) << " %</td>";
    }
  }

  // -------------------------------------------------------------------------------  
  // GRADE DETAILS
  if (DISPLAY_GRADE_DETAILS) {
    for (int i = 0; i < ALL_GRADEABLES.size(); i++) {
      GRADEABLE_ENUM g = ALL_GRADEABLES[i];
      ostr << "<td align=center bgcolor=888888>&nbsp;</td>"          
           << "<td align=center colspan=" << GRADEABLES[g].getCount() << ">" <<  gradeable_to_string(g)<< "S";
      if (g == GRADEABLE_ENUM::HOMEWORK) {
        ostr << "<br>* = 1 late day used";
      }
      ostr << "</td>";
      if (g == GRADEABLE_ENUM::TEST) {
        if (TEST_IMPROVEMENT_AVERAGING_ADJUSTMENT) {
          ostr << "<td align=center bgcolor=888888>&nbsp;</td>" 
               << "<td align=center colspan=" << GRADEABLES[g].getCount() << ">ADJUSTED TESTS</td>";
        }
      }
    }
  }
   
  if (DISPLAY_ICLICKER) {
    // ICLICKER DETAILS
    if (ICLICKER_QUESTION_NAMES.size() > 0) {
      ostr << "<td align=center bgcolor=888888>&nbsp;</td>";
      ostr << "<td align=center>ICLICKER TOTAL</td>";
      ostr << "<td align=center>ICLICKER RECENT</td>";
      ostr << "<td align=center>ALLOWED LATE DAYS</td>";
        ostr << "<td align=center>USED LATE DAYS</td>";
    }
    if (ICLICKER_QUESTION_NAMES.size() > 0) {
        ostr << "<td align=center bgcolor=888888>&nbsp;</td>" 
             << "<td align=center colspan=" << ICLICKER_QUESTION_NAMES.size() << ">ICLICKER QUESTIONS<br>CORRECT(green)=1.0, INCORRECT(red)=0.5, POLL(yellow)=1.0, NO ANSWER(white)=0.0<br>30.0 iClicker points = 3rd late day, 60.0 iClicker pts = 4th late day, 90.0 iClicker pts = 5th late day<br>&ge;8.0/12.0 most recent=Priority Help Queue (iClicker status highlighted in blue)</td>";
    }
  }
  
  // -------------------------------------------------------------------------------  
  ostr << "</td></tr>\n";    
}