std::shared_ptr<ElfFile> ElfCache::getFile(StringPiece p) { std::lock_guard<std::mutex> lock(mutex_); auto pos = files_.find(p); if (pos != files_.end()) { // Found, move to back (MRU) auto& entry = pos->second; lruList_.erase(lruList_.iterator_to(*entry)); lruList_.push_back(*entry); return filePtr(entry); } auto entry = std::make_shared<Entry>(); entry->path = p.str(); auto& path = entry->path; // No negative caching const char* msg = ""; int r = entry->file.openNoThrow(path.c_str(), true, &msg); if (r != ElfFile::kSuccess) { return nullptr; } if (files_.size() == capacity_) { auto& e = lruList_.front(); lruList_.pop_front(); files_.erase(e.path); } files_.emplace(entry->path, entry); lruList_.push_back(*entry); return filePtr(entry); }
std::shared_ptr<ElfFile> ElfCache::getFile(StringPiece p) { auto path = p.str(); std::lock_guard<std::mutex> lock(mutex_); auto pos = files_.find(path); if (pos != files_.end()) { // Found, move to back (MRU) auto& entry = pos->second; lruList_.erase(lruList_.iterator_to(*entry)); lruList_.push_back(*entry); return filePtr(entry); } auto entry = std::make_shared<Entry>(); // No negative caching if (entry->file.openNoThrow(path.c_str()) == -1) { return nullptr; } if (files_.size() == capacity_) { // Evict LRU lruList_.pop_front(); } files_.emplace(std::move(path), entry); lruList_.push_back(*entry); return filePtr(entry); }
int main(int argc, char *argv[]) { #include "setRootCase.H" #include "createTime.H" #include "createFields.H" label iCheck = 100; for (label i=1; i<=nSamples; i++) { scalar ps = p->sample(); label n = label((ps - xMin)*nIntervals/(xMax - xMin)); samples[n]++; if (writeData) { filePtr() << ps << nl; } if (i % iCheck == 0) { Info<< " processed " << i << " samples" << endl; if (i == 10*iCheck) { iCheck *= 10; } } } scalarField x(nIntervals); forAll(x, i) { x[i] = xMin + i*(xMax - xMin)/(nIntervals - 1); }
bool QMessageContentContainerPrivate::createAttachment(const QString& attachmentPath) { //set the attachment data if (!QFile::exists(attachmentPath)) { return false; } QFile attachmentFile(attachmentPath); if (!attachmentFile.open(QIODevice::ReadOnly)) { return false; } _content = attachmentFile.readAll(); _available = true; _size = attachmentFile.size(); attachmentFile.close(); QFileInfo fi(attachmentPath); _name = fi.fileName().toLatin1(); //set the mime-type QByteArray mimeType; QString type; TBuf8<255> fileBuffer; RApaLsSession session; QString fileString = fi.fileName(); TPtrC16 filePtr(reinterpret_cast<const TUint16*>(fileString.utf16())); TBuf8<20> fileType; TPtrC8 ptr8((TUint8 *)(_content.constData()), _content.length()); if(session.Connect() == KErrNone){ TDataRecognitionResult fileDataType; session.RecognizeData(filePtr, ptr8, fileDataType); fileType.Copy(fileDataType.iDataType.Des8()); mimeType = QByteArray((const char*)fileType.Ptr(), fileType.Length()); session.Close(); } QString extension(fi.suffix()); int index = mimeType.indexOf("/"); if (index != -1) { _type = mimeType.left(index).trimmed(); _subType = mimeType.mid(index + 1).trimmed(); } // set the whole filepath to _filename _filename = fi.filePath().toLatin1(); return true; }
int pmap::read_params(const std::string fname, const int argc, std::vector<std::string> &argv){ //TODO: need locations for input files: numerical input //TODO: need to add an auxilliary variable to accept user variables. Right now everything gets put to standard files paramVec general_opts, time_opts, wf_opts, field_opts, run_opts, plot_opts; boost::shared_ptr<int> ndim_def(new int), charges_def(new int), field_def(new int); defMap dist_map, traj_map, inwf_map, inpot_map, field_map, weight_map, sim_map, int_map; boost::assign::insert(int_map) (1,"Null integrator, does nothing") (3,"Symplectic Integrator") (4,"Adaptive Runge-Kutta") ; boost::assign::insert(sim_map) (0, "None") #ifdef OPENMP_FOUND (1, "OpenMP") #endif #ifdef MPI_FOUND (2, "MPI ") #endif ; boost::assign::insert(dist_map) (1,"Monte-Carlo") (2,"linear") (3,"staged-linear (not implemented)") ; boost::assign::insert(weight_map) (1,"Unit weight") (2,"ADK atomic rate with gaussian weight") ; boost::assign::insert(traj_map) (1,"Check parameters only") (2,"Build ICs only") (3,"run trajectories only") (4,"run binning only") (5,"everything") (6,"everything from 3") (7,"everything from 4") ; boost::assign::insert(inwf_map) (1,"Hydrogen atom like") (2,"Hydrogen molecule like") (3,"GAMESS checkpoint file") (4,"anything on a grid") ; boost::assign::insert(inpot_map) (1,"Hydrogen atom like") (2,"Hydrogen molecule like") (3,"GAMESS checkpoint file") (4,"anything on a grid") (5,"null potential") ; boost::assign::insert(field_map) (1,"constant cosine field") (2,"static field") (3,"gaussian envelope") (4,"sine squard envelope") (5,"numerical form") ; general_opts.push_back(intRunPtr(new intRun("The Number of dimensions to be used in the calculation", "ndim", 4, 100, 1))); general_opts.push_back(intListPtr(new intList("The number of trajectories in each dimension. comma separated list.", "dims", "1,1,1,1",ndim_def))); general_opts.push_back(statePtr(new state_param("The number of trajectories in each dimension. comma separated list.", "dist-type", 1, dist_map))); general_opts.push_back(statePtr(new state_param("Type of run", "run-type", 5, traj_map))); general_opts.push_back(intRunPtr(new intRun("Number of stages for staged-linear distribution(not implemented)", "id-stages", 1, 100, 1))); general_opts.push_back(filePtr( new file_param("Input file, expects serialized results of previous run", "input_file", "in.dat"))); general_opts.push_back(filePtr( new file_param("Output file, either serialized results of current run or results of whole run. If empty, then results will print to stdout for results of whole run.", "output_file", "out.dat"))); time_opts.push_back(doubleRunPtr(new doubleRun("Start time of the simulation, can be negative", "tinitial", 0, 10E10, -10E10))); time_opts.push_back(doubleRunPtr(new doubleRun("Finish time of the simulation, can be negative", "tfinal", 100, 10E10, -10E10))); time_opts.push_back(doubleRunPtr(new doubleRun("Initial time step", "dt", 0.01, 10E10, -10E10))); wf_opts.push_back(statePtr(new state_param("Type of initial wave-function", "wf-type", 1, inwf_map))); wf_opts.push_back(statePtr(new state_param("Type of initial potential", "pot-type", 1, inpot_map))); wf_opts.push_back(statePtr(new state_param("Type of ionization weight function", "weight-func", 2, weight_map))); wf_opts.push_back(doubleListPtr(new doubleList("charge on core(s). list of numbers for each core only needed for H-like and H2-like potential. 1 is for singly ionized etc.", "charges", "1",charges_def))); wf_opts.push_back(doubleRunPtr(new doubleRun("Smoothing parameter to avoid coulomb singularity. Should be small and is only needed when using analytic potentials.", "smoothing", 1E-4, 10E10, -10E10))); wf_opts.push_back(doubleRunPtr(new doubleRun("Internuclear separation in atomic units, only needed for analytic potentials", "rnuc", 0.0, 10E10, -10E10))); wf_opts.push_back(doubleRunPtr(new doubleRun("x-y plane orientation of molecule", "phi-nuc", 0.0, 10E10, -10E10))); wf_opts.push_back(doubleRunPtr(new doubleRun("alignment of molecule wrt the z-axis.", "theta-nuc", 0.0, 10E10, -10E10))); wf_opts.push_back(doubleRunPtr(new doubleRun("ionization potential of target, given in atomic units", "ip", 0.5, 10E10, -10E10))); wf_opts.push_back(doubleRunPtr(new doubleRun("state of atomic or molecular system (not implemented)", "state", 0.01, 10E10, -10E10))); wf_opts.push_back(doubleRunPtr(new doubleRun("escape range: the distance from the origin which an electron can consider being ionized", "escape-range", 1E-5, 10E10, 0))); field_opts.push_back(intRunPtr(new intRun("Number of fields, every option below is given as a comma separated list of options for each field. Currently only 1 field is allowed", "nfield", 1, 100, 1))); field_opts.push_back(statePtr(new state_param("Type of fields", "env", 1,field_map))); field_opts.push_back(doubleListPtr(new doubleList("Field strengths given in atomic units", "ef", "0.01",field_def))); field_opts.push_back(doubleListPtr(new doubleList("frequencies given in atomic units", "omega", "0.057",field_def))); field_opts.push_back(doubleListPtr(new doubleList("FWHM of envelope, ignored for static or constant field.", "fwhm", "0",field_def))); field_opts.push_back(doubleListPtr(new doubleList("initial CE phase of each field given in degrees", "ce", "0",field_def))); field_opts.push_back(intListPtr(new intList("polarization direction, 1 = x, 2 = y, 3 = z,", "pol", "3",field_def))); run_opts.push_back(intRunPtr(new intRun("Number of concurrent trajectories using OpenMP", "nthreads", 1, 100, 1))); run_opts.push_back(intRunPtr(new intRun("Number of nodes using MPI", "mklthreads", 1, 100, 1))); run_opts.push_back(doubleRunPtr(new doubleRun("Absolute error", "abserr", 1.E-9, 10E10, -10E10))); run_opts.push_back(doubleRunPtr(new doubleRun("Relative error", "relerr", 1E-7, 10E10, -10E10))); run_opts.push_back(statePtr(new state_param("Type of parallel run", "parallel", 0, sim_map))); run_opts.push_back(statePtr(new state_param("Type of integrator to use", "int-type", 4, int_map))); plot_opts.push_back(intRunPtr(new intRun("Number of bins in final distrbution", "plot-nums", 256, 10E6, 1))); plot_opts.push_back(doubleRunPtr(new doubleRun("absolute range of saved distribution in atomic units of momentum", "plot-ranges", 6., 10E10, 0))); std::vector<boost::shared_ptr<po::options_description> > opts_desc; opts_desc.push_back(boost::shared_ptr<po::options_description>(new po::options_description("Generic Options"))); opts_desc.push_back(boost::shared_ptr<po::options_description>(new po::options_description("Time Grid"))); opts_desc.push_back(boost::shared_ptr<po::options_description>(new po::options_description("Wave function and potential"))); opts_desc.push_back(boost::shared_ptr<po::options_description>(new po::options_description("Field options"))); opts_desc.push_back(boost::shared_ptr<po::options_description>(new po::options_description("Plotting specific options"))); opts_desc.push_back(boost::shared_ptr<po::options_description>(new po::options_description("Run specific options"))); opts_desc[0]->add_options() ("help", "displays help message"); opts_desc[0]->add_options() ("help-glog", "displays help messages for google glog, the logging interface"); opts_desc[5]->add_options() ("no-build", "builds the initial conditions on the fly, without holding entire set in memory"); opts_desc[5]->add_options() ("no-bin", "do not create distribution while running trajectories, bining of distribution is done in separate step, not valid when doing parallel calculations"); opts_desc[5]->add_options() ("no-store", "do not store trajectories separately just add them to the distribution(mutually exclusive with no-bin, this takes precedence)"); opts_desc[5]->add_options() ("binary", "serialize in binary(OS-dependent), if not set serializes to text(default)"); opts_desc[5]->add_options() ("watch", "turns on observer for RK integrator...lots of output!"); std::vector<paramVec> opts; opts.push_back(general_opts); opts.push_back(time_opts); opts.push_back(wf_opts); opts.push_back(field_opts); opts.push_back(plot_opts); opts.push_back(run_opts); for(std::size_t i=0;i<opts.size();++i){ foreach(paramPtr m, opts[i]){ m->genParam(*(opts_desc[i])); } }
void FileIO::writeInputLog (string log) { ofstream filePtr(TASK_LOG_FILE_NAME, ios::app) ; tm* current = getCurrentTime() ; string time = makePrintableTimeString(asctime(current)) ; filePtr << time << "\t" << log << endl ; }