int main(int argc, char **argv) { progname = argv[0]; if (argc != 3) { usage(); return 1; } char *frameworkConfigPath = argv[1]; char *pipelineConfigPath = argv[2]; fprintf(stderr, "Validating %s\n", pipelineConfigPath); // open the log temp file Log log; Poco::TemporaryFile filename; log.open(filename.path().c_str()); TskServices::Instance().setLog(log); std::string progDirPath = TskUtilities::getProgDir(); // Initialize properties based on the config file. Do this to shutdown noise in validation. TskSystemPropertiesImpl systemProperties; systemProperties.initialize(frameworkConfigPath); TskServices::Instance().setSystemProperties(systemProperties); SetSystemProperty(TskSystemProperties::PROG_DIR, progDirPath); ValidatePipeline vp; bool valid = vp.isValid(pipelineConfigPath); fprintf(stdout, "%s is %s\n", pipelineConfigPath, (valid ? "valid." : "invalid.")); // close the log file and dump content to stdout log.close(); #define MAX_BUF 1024 char buf[MAX_BUF]; std::ifstream fin(filename.path().c_str()); fprintf(stdout, "\nLog messages created during validation: \n"); while (fin.getline(buf, MAX_BUF)) { fprintf(stdout, "%s\n", buf); } fin.close(); if (valid) return 0; else return 1; }
void FilesystemBinding::CreateTempDirectory(const ValueList& args, KValueRef result) { try { Poco::TemporaryFile tempDir; tempDir.keepUntilExit(); tempDir.createDirectory(); ti::File* jsFile = new ti::File(tempDir.path()); result->SetObject(jsFile); } catch (Poco::Exception& exc) { throw ValueException::FromString(exc.displayText()); } }
static std::string& BlankURLToFilePath() { static std::string path; if (path.empty()) { Poco::TemporaryFile temp; temp.keepUntilExit(); path = temp.path(); std::string contents("<html><body></body></html>"); Poco::FileStream stream; stream.open(path, std::ios::out); stream.write(contents.c_str(), contents.size()); stream.close(); } return path; }
/** Download a url and fetch it inside the local path given. @param urlFile: Define a valid URL for the file to be downloaded. Eventually, it may give any valid https path. For example: url_file = "http://www.google.com" url_file = "https://mantidweb/repository/README.md" The result is to connect to the http server, and request the path given. The answer, will be inserted at the local_file_path. @param localFilePath : Provide the destination of the file downloaded at the url_file. @exception Mantid::Kernel::Exception::InternetError : For any unexpected behaviour. */ int InternetHelper::downloadFile(const std::string &urlFile, const std::string &localFilePath) { int retStatus = 0; g_log.debug() << "DownloadFile : " << urlFile << " to file: " << localFilePath << std::endl; Poco::TemporaryFile tempFile; Poco::FileStream tempFileStream(tempFile.path()); retStatus = sendRequest(urlFile, tempFileStream); tempFileStream.close(); // if there have been no errors move it to the final location, and turn off // automatic deletion. // clear the way if the target file path is already in use Poco::File file(localFilePath); if (file.exists()) { file.remove(); } tempFile.moveTo(localFilePath); tempFile.keep(); return retStatus; }
// instrument creation Geometry::Instrument_sptr LoadBBY::createInstrument(ANSTO::Tar::File &tarFile, InstrumentInfo &instrumentInfo) { const double toMeters = 1.0 / 1000; instrumentInfo.bm_counts = 0; instrumentInfo.att_pos = 0; instrumentInfo.period_master = 0.0; instrumentInfo.period_slave = 0.0; instrumentInfo.phase_slave = 0.0; instrumentInfo.L1_chopper_value = 18.47258984375; instrumentInfo.L2_det_value = 33.15616015625; instrumentInfo.L2_curtainl_value = 23.28446093750; instrumentInfo.L2_curtainr_value = 23.28201953125; instrumentInfo.L2_curtainu_value = 24.28616015625; instrumentInfo.L2_curtaind_value = 24.28235937500; instrumentInfo.D_det_value = (8.4 + 2.0) / (2 * 1000); instrumentInfo.D_curtainl_value = 0.3816; instrumentInfo.D_curtainr_value = 0.4024; instrumentInfo.D_curtainu_value = 0.3947; instrumentInfo.D_curtaind_value = 0.3978; // extract log and hdf file const std::vector<std::string> &files = tarFile.files(); int64_t fileSize = 0; for (auto itr = files.begin(); itr != files.end(); ++itr) if (itr->rfind(".hdf") == itr->length() - 4) { tarFile.select(itr->c_str()); fileSize = tarFile.selected_size(); break; } if (fileSize != 0) { // extract hdf file into tmp file Poco::TemporaryFile hdfFile; boost::shared_ptr<FILE> handle(fopen(hdfFile.path().c_str(), "wb"), fclose); if (handle) { // copy content char buffer[4096]; size_t bytesRead; while (0 != (bytesRead = tarFile.read(buffer, sizeof(buffer)))) fwrite(buffer, bytesRead, 1, handle.get()); handle.reset(); NeXus::NXRoot root(hdfFile.path()); NeXus::NXEntry entry = root.openFirstEntry(); float tmp_float; int32_t tmp_int32 = 0; if (loadNXDataSet(entry, "monitor/bm1_counts", tmp_int32)) instrumentInfo.bm_counts = tmp_int32; if (loadNXDataSet(entry, "instrument/att_pos", tmp_float)) instrumentInfo.att_pos = boost::math::iround(tmp_float); // [1.0, 2.0, ..., 5.0] if (loadNXDataSet(entry, "instrument/master_chopper_freq", tmp_float)) instrumentInfo.period_master = 1.0 / tmp_float * 1.0e6; if (loadNXDataSet(entry, "instrument/t0_chopper_freq", tmp_float)) instrumentInfo.period_slave = 1.0 / tmp_float * 1.0e6; if (loadNXDataSet(entry, "instrument/t0_chopper_phase", tmp_float)) instrumentInfo.phase_slave = tmp_float < 999.0 ? tmp_float : 0.0; if (loadNXDataSet(entry, "instrument/L2_det", tmp_float)) instrumentInfo.L2_det_value = tmp_float * toMeters; if (loadNXDataSet(entry, "instrument/Ltof_det", tmp_float)) instrumentInfo.L1_chopper_value = tmp_float * toMeters - instrumentInfo.L2_det_value; // if (loadNXDataSet(entry, "instrument/L1", tmp_float)) // instrumentInfo.L1_source_value = tmp_float * toMeters; if (loadNXDataSet(entry, "instrument/L2_curtainl", tmp_float)) instrumentInfo.L2_curtainl_value = tmp_float * toMeters; if (loadNXDataSet(entry, "instrument/L2_curtainr", tmp_float)) instrumentInfo.L2_curtainr_value = tmp_float * toMeters; if (loadNXDataSet(entry, "instrument/L2_curtainu", tmp_float)) instrumentInfo.L2_curtainu_value = tmp_float * toMeters; if (loadNXDataSet(entry, "instrument/L2_curtaind", tmp_float)) instrumentInfo.L2_curtaind_value = tmp_float * toMeters; if (loadNXDataSet(entry, "instrument/detector/curtainl", tmp_float)) instrumentInfo.D_curtainl_value = tmp_float * toMeters; if (loadNXDataSet(entry, "instrument/detector/curtainr", tmp_float)) instrumentInfo.D_curtainr_value = tmp_float * toMeters; if (loadNXDataSet(entry, "instrument/detector/curtainu", tmp_float)) instrumentInfo.D_curtainu_value = tmp_float * toMeters; if (loadNXDataSet(entry, "instrument/detector/curtaind", tmp_float)) instrumentInfo.D_curtaind_value = tmp_float * toMeters; } } // patching std::string logContent; for (auto itr = files.begin(); itr != files.end(); ++itr) if (itr->compare("History.log") == 0) { tarFile.select(itr->c_str()); logContent.resize(tarFile.selected_size()); tarFile.read(&logContent[0], logContent.size()); break; } if (logContent.size() > 0) { std::istringstream data(logContent); Poco::AutoPtr<Poco::Util::PropertyFileConfiguration> conf( new Poco::Util::PropertyFileConfiguration(data)); if (conf->hasProperty("bm1_counts")) instrumentInfo.bm_counts = conf->getInt("bm1_counts"); if (conf->hasProperty("att_pos")) instrumentInfo.att_pos = boost::math::iround(conf->getDouble("att_pos")); if (conf->hasProperty("master_chopper_freq")) instrumentInfo.period_master = 1.0 / conf->getDouble("master_chopper_freq") * 1.0e6; if (conf->hasProperty("t0_chopper_freq")) instrumentInfo.period_slave = 1.0 / conf->getDouble("t0_chopper_freq") * 1.0e6; if (conf->hasProperty("t0_chopper_phase")) instrumentInfo.phase_slave = conf->getDouble("t0_chopper_phase"); if (conf->hasProperty("L2_det")) instrumentInfo.L2_det_value = conf->getDouble("L2_det") * toMeters; if (conf->hasProperty("Ltof_det")) instrumentInfo.L1_chopper_value = conf->getDouble("Ltof_det") * toMeters - instrumentInfo.L2_det_value; // if (conf->hasProperty("L1")) // instrumentInfo.L1_source_value = conf->getDouble("L1") * toMeters; if (conf->hasProperty("L2_curtainl")) instrumentInfo.L2_curtainl_value = conf->getDouble("L2_curtainl") * toMeters; if (conf->hasProperty("L2_curtainr")) instrumentInfo.L2_curtainr_value = conf->getDouble("L2_curtainr") * toMeters; if (conf->hasProperty("L2_curtainu")) instrumentInfo.L2_curtainu_value = conf->getDouble("L2_curtainu") * toMeters; if (conf->hasProperty("L2_curtaind")) instrumentInfo.L2_curtaind_value = conf->getDouble("L2_curtaind") * toMeters; if (conf->hasProperty("curtainl")) instrumentInfo.D_curtainl_value = conf->getDouble("curtainl") * toMeters; if (conf->hasProperty("curtainr")) instrumentInfo.D_curtainr_value = conf->getDouble("curtainr") * toMeters; if (conf->hasProperty("curtainu")) instrumentInfo.D_curtainu_value = conf->getDouble("curtainu") * toMeters; if (conf->hasProperty("curtaind")) instrumentInfo.D_curtaind_value = conf->getDouble("curtaind") * toMeters; } return Geometry::Instrument_sptr(); /* // instrument Geometry::Instrument_sptr instrument = boost::make_shared<Geometry::Instrument>("BILBY"); instrument->setDefaultViewAxis("Z-"); // source Geometry::ObjComponent *source = new Geometry::ObjComponent("Source", instrument.get()); instrument->add(source); instrument->markAsSource(source); // sample Geometry::ObjComponent *samplePos = new Geometry::ObjComponent("Sample", instrument.get()); instrument->add(samplePos); instrument->markAsSamplePos(samplePos); source->setPos(0.0, 0.0, -instrumentInfo.L1_chopper_value); samplePos->setPos(0.0, 0.0, 0.0); // dimensions of the detector (height is in y direction, width is in x // direction) double width = 336.0 / 1000; // meters double height = 640.0 / 1000; // meters double angle = 10.0; // degree // raw data format size_t xPixelCount = HISTO_BINS_X / 6; size_t yPixelCount = HISTO_BINS_Y; // we assumed that individual pixels have the same size and shape of a cuboid: double pixel_width = width / static_cast<double>(xPixelCount); double pixel_height = height / static_cast<double>(yPixelCount); // final number of pixels size_t pixelCount = xPixelCount * yPixelCount; // Create size strings for shape creation std::string pixel_width_str = boost::lexical_cast<std::string>(pixel_width / 2); std::string pixel_height_str = boost::lexical_cast<std::string>(pixel_height / 2); std::string pixel_depth_str = "0.00001"; // Set the depth of a pixel to a very small number // Define shape of a pixel as an XML string. See // http://www.mantidproject.org/HowToDefineGeometricShape for details on // shapes in Mantid. std::string detXML = "<cuboid id=\"pixel\">" "<left-front-bottom-point x=\"+"+pixel_width_str+"\" y=\"-"+pixel_height_str+"\" z=\"0\" />" "<left-front-top-point x=\"+"+pixel_width_str+"\" y=\"-"+pixel_height_str+"\" z=\""+pixel_depth_str+"\" />" "<left-back-bottom-point x=\"-"+pixel_width_str+"\" y=\"-"+pixel_height_str+"\" z=\"0\" />" "<right-front-bottom-point x=\"+"+pixel_width_str+"\" y=\"+"+pixel_height_str+"\" z=\"0\" />" "</cuboid>"; // Create a shape object which will be shared by all pixels. Geometry::Object_sptr pixelShape = Geometry::ShapeFactory().createShape(detXML); // create detector banks BbyDetectorBankFactory factory( instrument, pixelShape, xPixelCount, yPixelCount, pixel_width, pixel_height, Kernel::V3D(0, (height - pixel_height) / 2, 0)); // curtain l factory.createAndAssign(0 * pixelCount, Kernel::V3D(+instrumentInfo.D_curtainl_value, 0, instrumentInfo.L2_curtainl_value), Kernel::Quat(0, Kernel::V3D(0, 0, 1)) * Kernel::Quat(angle, Kernel::V3D(0, 1, 0))); // curtain r factory.createAndAssign(1 * pixelCount, Kernel::V3D(-instrumentInfo.D_curtainr_value, 0, instrumentInfo.L2_curtainr_value), Kernel::Quat(180, Kernel::V3D(0, 0, 1)) * Kernel::Quat(angle, Kernel::V3D(0, 1, 0))); // curtain u factory.createAndAssign(2 * pixelCount, Kernel::V3D(0, +instrumentInfo.D_curtainu_value, instrumentInfo.L2_curtainu_value), Kernel::Quat(90, Kernel::V3D(0, 0, 1)) * Kernel::Quat(angle, Kernel::V3D(0, 1, 0))); // curtain d factory.createAndAssign(3 * pixelCount, Kernel::V3D(0, -instrumentInfo.D_curtaind_value, instrumentInfo.L2_curtaind_value), Kernel::Quat(-90, Kernel::V3D(0, 0, 1)) * Kernel::Quat(angle, Kernel::V3D(0, 1, 0))); // back 1 (left) factory.createAndAssign(4 * pixelCount, Kernel::V3D(+instrumentInfo.D_det_value, 0, instrumentInfo.L2_det_value), Kernel::Quat(0, Kernel::V3D(0, 0, 1))); // back 2 (right) factory.createAndAssign(5 * pixelCount, Kernel::V3D(-instrumentInfo.D_det_value, 0, instrumentInfo.L2_det_value), Kernel::Quat(180, Kernel::V3D(0, 0, 1))); return instrument; */ }
bool File::load(string path) { //load the blend file into the stream if(file.is_open()) file.close(); file.open(ofToDataPath(path, true).c_str(), ios::binary); //info should contain blender now, if not it is compressed string info = readString(7); //check if the file is gzipped if(info != "BLENDER") { seek(0); //unzip the blend file to a temp file and reload Poco::InflatingInputStream inflater(file, Poco::InflatingStreamBuf::STREAM_GZIP); Poco::TemporaryFile tempFile; tempFile.keepUntilExit(); std::ofstream out(tempFile.path().c_str(), ios::binary); Poco::StreamCopier::copyStream( inflater, out); out.close(); file.close(); file.open(tempFile.path().c_str(), ios::binary); info = readString(7); if(info != "BLENDER") { ofLogWarning(OFX_BLENDER) << "Could not read blend file " << path; } else { ofLogVerbose(OFX_BLENDER) << "Blend file is gzipped, temporarily decompressed contents to " << tempFile.path(); } } //now extract the rest of the header data string tempString = readString(1); if(tempString == "-") pointerSize = 8; else if(tempString == "_") pointerSize = 4; //ofLogVerbose(OFX_BLENDER) << "Pointer Size is " << pointerSize; if(pointerSize == 4) { readPointer = std::bind(&File::read<unsigned int>, this); } else { readPointer = std::bind(&File::read<unsigned long>, this); } bool littleEndianness; char structPre = ' '; tempString = readString(1); if(tempString == "v") { littleEndianness = true; structPre = '<'; } else if(tempString == "V") { littleEndianness = false; structPre = '>'; } //ofLogVerbose(OFX_BLENDER) << "Struct pre is " << structPre; //ofLogVerbose(OFX_BLENDER) << "Little Endianness is " << littleEndianness; //version version = readString(3); //now go through all them blocks blocks.push_back(Block(this)); //read the first block readHeader(blocks.back()); while(blocks.back().code != "DNA1" && blocks.back().code != "SDNA") { //skip the block data file.seekg(file.tellg() + streamoff(blocks.back().size)); //read a new block blocks.push_back(Block(this)); readHeader(blocks.back()); } //advance readString(4); readString(4); //NAMES unsigned int numNames = read<unsigned int>(); for(unsigned int i=0; i<numNames; i++) { catalog.names.push_back(DNAName(readString(0))); } align(file); //TYPES readString(4); unsigned int numTypes = read<unsigned int>(); //cout << "FOUND TYPES " << numTypes << endl; for(unsigned int i=0; i<numTypes; i++) { catalog.types.push_back(DNAType(readString(0), i)); } align(file); //TYPE LENGTHS readString(4);; for(unsigned int i=0; i<numTypes; i++) { catalog.types[i].size = read<unsigned short>(); if(catalog.types[i].size == 0) //assume it is a pointer catalog.types[i].size = pointerSize; } align(file); //STRUCTURES readString(4); unsigned int numStructs = read<unsigned int>(); //cout << "FOUND STRUCTURES " << numStructs << endl; for(unsigned int i=0; i<numStructs; i++) { //get the type unsigned int index = read<unsigned short>(); DNAType* type = &catalog.types[index]; catalog.structures.push_back(DNAStructure(type)); DNAStructure& structure = catalog.structures.back(); //get the fields for the structure unsigned short numFields = read<unsigned short>(); unsigned int curOffset = 0; for(unsigned int j=0; j<numFields; j++) { unsigned short typeIndex = read<unsigned short>(); unsigned short nameIndex = read<unsigned short>(); DNAType* type = &catalog.types[typeIndex]; DNAName* name = &catalog.names[nameIndex]; structure.fields.push_back(DNAField(type, name, curOffset)); //if the field is a pointer, then only add the pointer size to offset bool offsetSet = false; if(structure.fields.back().isPointer) { int amount = 0; if(structure.fields.back().isArray) { amount = structure.fields.back().arraySizes[0]; } if(amount == 0) amount = 1; curOffset += (pointerSize * amount); offsetSet = true; } else if(structure.fields.back().isArray) { //arrays add n times the size to offset float multi = 0; for(int s: structure.fields.back().arraySizes) { if(s!=-1) { if(multi == 0) multi += s; else multi *= s; } } if(multi != 0) offsetSet = true; curOffset += type->size * multi; } if(!offsetSet) { curOffset += type->size; } } } align(file); //now link all structures with the File Blocks vector<Block>::iterator it = blocks.begin(); while(it != blocks.end()) { (*it).structure = &catalog.structures[(*it).SDNAIndex]; it++; } ofLogVerbose(OFX_BLENDER) << "Loaded \"" << path << "\" - Blender version is " << version; return true; }