예제 #1
0
void fileCopy(std::string sourePath, std::string destPath)
{
    std::ifstream source(sourePath, std::ios::binary);
    std::ofstream dest(destPath, std::ios::binary);

    std::istreambuf_iterator<char> begin_source(source);
    std::istreambuf_iterator<char> end_source;
    std::ostreambuf_iterator<char> begin_dest(dest);
    std::copy(begin_source, end_source, begin_dest);

    source.close();
    dest.close();
}
예제 #2
0
   void writeOutputFile(const char* uniname)
   {
       OutputFiles& outputFiles = *this;

       Int_t ngood = outputFiles.nevents;

       //
       // combine output files
       //

       cout<<endl<< ngood << " good events" <<endl;

       cout<< "look at the output file" <<endl;

       for (int ilayer=0; ilayer<4; ilayer++) {
           outputFiles.tfile[ilayer]->seekg(0, outputFiles.tfile[ilayer]->beg);
           outputFiles.vfile[ilayer]->seekg(0, outputFiles.vfile[ilayer]->beg);
           outputFiles.ufile[ilayer]->seekg(0, outputFiles.ufile[ilayer]->beg);
       }
       outputFiles.wfile->seekg(0, outputFiles.wfile->beg);

       // output file
       std::ofstream unifile(uniname, std::ios::binary);

       char magicNumber[4];
       magicNumber[0] = 'P';
       magicNumber[1] = 'C';
       magicNumber[2] = 'T';
       magicNumber[3] = 'D';
       unifile.write(magicNumber, 4);

       Int_t versionNumberIdentifier = 0;
       unifile.write((const char*) &versionNumberIdentifier, sizeof(Int_t));

       Int_t numberEvents = ngood;
       unifile.write((const char*) &numberEvents, sizeof(Int_t));

       Float_t projectionAngle = outputFiles.angle;                      // take angle from outputFiles
       unifile.write((const char*) &projectionAngle, sizeof(Float_t));

       Float_t beamEnergy = 200;
       unifile.write((const char*) &beamEnergy, sizeof(Float_t));

       //-- Int_t acquisitionDate = start_time;              //--TODO
       Int_t acquisitionDate = 0;
       unifile.write((const char*) &acquisitionDate, sizeof(Int_t));

       time_t timer = std::time(NULL);
       Int_t preprocessingDate = timer;
       unifile.write((const char*) &preprocessingDate, sizeof(Int_t));

       Int_t variableStringSize = 0;       // will be used for each of the variable length string

       std::string phantomName = "Very nice phantom";
       variableStringSize = phantomName.size() + 1;
       unifile.write((const char*) &variableStringSize, sizeof(Int_t));
       unifile.write(phantomName.c_str(), variableStringSize);

       std::string dataSource = "Data Source";
       variableStringSize = dataSource.size() + 1;
       unifile.write((const char*) &variableStringSize, sizeof(Int_t));
       unifile.write(dataSource.c_str(), variableStringSize);

       std::string preparedBy = "Tia";
       variableStringSize = preparedBy.size() + 1;
       unifile.write((const char*) &variableStringSize, sizeof(Int_t));
       unifile.write(preparedBy.c_str(), variableStringSize);

       cout<< "combine the data files" <<endl;

       // write T first
       for (int ilayer=0; ilayer<4; ++ilayer) {
           std::istreambuf_iterator<char> begin_source(*outputFiles.tfile[ilayer]);
           std::istreambuf_iterator<char> end_source;
           std::ostreambuf_iterator<char> begin_dest(unifile);
           std::copy(begin_source, end_source, begin_dest);
       }

       // then V
       for (int ilayer=0; ilayer<4; ++ilayer) {
           std::istreambuf_iterator<char> begin_source(*outputFiles.vfile[ilayer]);
           std::istreambuf_iterator<char> end_source;
           std::ostreambuf_iterator<char> begin_dest(unifile);
           std::copy(begin_source, end_source, begin_dest);
       }

       // followed by U
       for (int ilayer=0; ilayer<4; ++ilayer) {
           std::istreambuf_iterator<char> begin_source(*outputFiles.ufile[ilayer]);
           std::istreambuf_iterator<char> end_source;
           std::ostreambuf_iterator<char> begin_dest(unifile);
           std::copy(begin_source, end_source, begin_dest);
       }
       // and WEPL
       std::istreambuf_iterator<char> begin_source(*outputFiles.wfile);
       std::istreambuf_iterator<char> end_source;
       std::ostreambuf_iterator<char> begin_dest(unifile);
       std::copy(std::istreambuf_iterator<char>(*outputFiles.wfile), std::istreambuf_iterator<char>(), std::ostreambuf_iterator<char>(unifile));

       //cout<< "OutputFiles: Wrote " << ngood << " events into output binary file " << uniname <<endl;
       outputFiles.close();
   }