////////////////////////////////////////////////////////////////////////////////////////// // UNIT TESTS bool utest_BTShapeStream(UnitTestExecutionContext const *context) { Ogre::String intro = "test_BTShapeStream(): "; BTShapeManager shapeMan; Ogre::String streamId = "utests/shapes/A - sequence"; File rootFile("/media/a0/cpp/1210/usmb/data/raw_resources/BT/utests/shapes/A - sequence"); BTShapeStream *stream = nullptr; if(!rootFile.exists()) { Debug::warning(intro)(rootFile)(" not found. ").endl(); return false; } if(!shapeMan.buildShapeStream(streamId, rootFile, stream)) { Debug::error(intro)("Could not create shape stream, see above for details.").endl(); return false; } BTShapeToken groundTruth_data[] = { {BTShapeTokenType::BTSequenceToken, 0, 7, BTFileNode(rootFile).descriptor()}, //A {BTShapeTokenType::BTSequenceToken, 1, 4, BTFileNode(rootFile.subfile("B - sequence")).descriptor()}, //+-B {BTShapeTokenType::BTFinderToken, 2, 3, BTFileNode(rootFile.subfile("B - sequence").subfile("C - finder")).descriptor()}, //| +-C {BTShapeTokenType::BTNavigatorToken, 3, 4, BTFileNode(rootFile.subfile("B - sequence").subfile("D - navigator")).descriptor()}, //| |-D {BTShapeTokenType::BTSequenceToken, 4, 7, BTFileNode(rootFile.subfile("E - sequence")).descriptor()}, //+-E {BTShapeTokenType::BTFinderToken, 5, 6, BTFileNode(rootFile.subfile("E - sequence").subfile("F - finder")).descriptor()}, // +-F {BTShapeTokenType::BTNavigatorToken, 6, 7, BTFileNode(rootFile.subfile("E - sequence").subfile("G - navigator")).descriptor()}, // |-G }; BTShapeStream groundTruth; groundTruth.mName = streamId; groundTruth.mData = BTShapeStreamData(groundTruth_data, groundTruth_data + sizeof(groundTruth_data) / sizeof(BTShapeToken)); // BTShapeStream groundTruth; // groundTruth.push_back({BTSequenceToken,0,7}); std::pair<BTShapeStreamData::iterator, BTShapeStreamData::iterator> mismatch; // using default comparison mismatch = std::mismatch(stream->mData.begin(), stream->mData.end(), groundTruth.mData.begin()); if(mismatch.first != stream->mData.end()) { Debug::error(intro)("BTShapeStream mismatch with groundTruth:").endl(); Debug::error("streamId: ")(streamId).endl(); Debug::error("rootFile: ")(rootFile).endl(); Debug::error("stream built: ")(stream).endl(); Debug::error("groundTruth: ")(&groundTruth).endl(); Debug::error("first mismatch: ").endl().indent(); Debug::error("stream: ")(*mismatch.first).endl(); Debug::error("groundTruth: ")(*mismatch.second).unIndent().endl(); return false; } shapeMan.clearCachedStreams(); return true; }
void Reminder::createDb() { // Create the $HOME/.kde4/... /translatoid.db : database for users if (!QFile::exists(KStandardDirs::locateLocal("data", "translatoid/translatoid.db"))) { QFile rootFile(KStandardDirs::locate("data", "translatoid/translatoid.db")); rootFile.copy (KStandardDirs::locateLocal("data", "translatoid/translatoid.db")); } }
bool MainWindow::getCVSRootEntry(const QString& path) { // Add the CVS path QString rootPath = path+"/CVS/Root"; QFile rootFile(rootPath); if (!rootFile.open(QIODevice::ReadOnly | QIODevice::Text)) return false; QTextStream in(&rootFile); if (!in.atEnd()) { rootEntry = in.readLine(); return true; } else return false; }
bool BTModelManager::fromSingleJson(Json::Value const&root, ModelId &id, bool updateModel/* = false*/) { Json::Value value; if(root.isNull()) { Debug::error(STEEL_METH_INTRO, "Empty root. Aborting.").endl(); return false; } value = root[BTModel::SHAPE_NAME_ATTRIBUTE]; if(value.isNull()) { Debug::error(STEEL_METH_INTRO, "unknown BTModel attribute").quotes(BTModel::SHAPE_NAME_ATTRIBUTE)(" with value ").quotes(value)(". Aborting.").endl(); return false; } Ogre::String rootPath = value.asString(); File rootFile(mBasePath.subfile(rootPath)); if(!rootFile.exists()) { Debug::error(STEEL_METH_INTRO, "rootFile ", rootFile, " not found. Aborting.").endl(); return false; } if(!buildFromFile(rootFile, id, updateModel)) return false; if(!mModels[id].fromJson(root)) return false; // agentTags if(!mModels[id].deserializeTags(root)) { Debug::error(STEEL_METH_INTRO, "could not deserialize tags. Aborting.").endl(); return false; } return true; }
bool MainWindow::replaceRootEntry(QString path, QString rootEntry) { QString rootPath = path+"/CVS/Root"; QFile rootFile(rootPath); if (!rootFile.open(QIODevice::ReadOnly | QIODevice::Text)) return false; // Remove previous root file rootFile.remove(); // Create new file QFile ofile(rootPath); ofile.open(QIODevice::ReadWrite | QIODevice::Text); QTextStream out(&ofile); out << rootEntry; ofile.close(); QString message = "Updated Root Entry in: "+ path; ui->infoWindow->appendPlainText(message); qApp->processEvents(); return true; }
bool Repository::setWorkingCopy(const QString& dirName) { const QFileInfo fi(dirName); const QString path = fi.absoluteFilePath(); // is this really a cvs-controlled directory? const QFileInfo cvsDirInfo(path + "/CVS"); if( !cvsDirInfo.exists() || !cvsDirInfo.isDir() || !QFile::exists( cvsDirInfo.filePath() + "/Entries" ) || !QFile::exists( cvsDirInfo.filePath() + "/Repository" ) || !QFile::exists( cvsDirInfo.filePath() + "/Root" ) ) return false; d->workingCopy = path; d->location.clear(); // determine path to the repository QFile rootFile(path + "/CVS/Root"); if( rootFile.open(QIODevice::ReadOnly) ) { QTextStream stream(&rootFile); d->location = stream.readLine(); } rootFile.close(); // add identities (ssh-add) to ssh-agent // TODO CL make sure this is called only once if( d->location.contains(":ext:", Qt::CaseInsensitive) ) { SshAgent ssh; ssh.addSshIdentities(); } QDir::setCurrent(path); d->readConfig(); return true; }
///////////////////////////////////////////////////////////////////////////////////////////////////////////// // UNIT TESTS bool utest_BTrees(UnitTestExecutionContext const *context) { Engine *engine = context->engine; BTModelManager *btModelMan = new BTModelManager(engine->level(), "/media/a0/cpp/1210/usmb/install_dir/data/raw_resources/BT"); // load BTree serialization File rootFile("/media/a0/cpp/1210/usmb/data/resources/BTree models/patrol.model"); if(!rootFile.exists()) { Debug::warning(STEEL_METH_INTRO, rootFile, "not found. Aborting unit test.").endl(); return false; } Ogre::String content = rootFile.read(); Json::Reader reader; Json::Value root; bool parsingOk = reader.parse(content, root, false); if(!parsingOk) { Debug::error(STEEL_METH_INTRO, "could not parse this:").endl()(content).endl()(reader.getFormattedErrorMessages()).endl(); return false; } // instanciate it ModelId mid = INVALID_ID; if(!btModelMan->fromSingleJson(root, mid) || mid == INVALID_ID) { Debug::error(STEEL_METH_INTRO, "Model id is invalid. See above for details.").endl(); return false; } Debug::log("test_BTrees(): passed").endl(); return true; }
// /r06/lc/sg568/HCAL_Optimisation_Studies/EnergyResolutionResults/Detector_Model_103/Reco_Stage_38/Photon // EnergyResolution_PandoraSettingsDefault_DetectorModel_103_ReconstructionVariant_38_Photon.root void DrawNumLayers() { const int recoVar(71); const int energy(100); std::vector<int> detectorModels; detectorModels.push_back(96); detectorModels.push_back(97); detectorModels.push_back(98); detectorModels.push_back(99); std::map<int, int> detModelToLayerNumber; detModelToLayerNumber[96] = 30; detModelToLayerNumber[97] = 26; detModelToLayerNumber[98] = 20; detModelToLayerNumber[99] = 16; TCanvas *pTCanvas = new TCanvas(); TGraphErrors *pTGraphErrors = new TGraphErrors("EResVsLayer","EResVsLayer"); for (std::vector<int>::iterator it = detectorModels.begin(); it != detectorModels.end(); it++) { const int detModel(*it); const int layerNumber(detModelToLayerNumber.find(detModel)->second); std::string rootFile("/r06/lc/sg568/HCAL_Optimisation_Studies/EnergyResolutionResults/Detector_Model_" + NumberToString(detModel) + "/Reco_Stage_" + NumberToString(recoVar) + "/Photon/EnergyResolution_PandoraSettingsDefault_DetectorModel_" + NumberToString(detModel) + "_ReconstructionVariant_" + NumberToString(recoVar) + "_Photon.root"); std::cout << rootFile << std::endl; TFile *pTFile = new TFile(rootFile.c_str()); std::string histogramName("Resolution_DetectorModel_" + NumberToString(detModel) + "_ReconstructionVariant_" + NumberToString(recoVar) + "/PFOEnergyHistogram_DetectorModel_" + NumberToString(detModel) + "_ReconstructionVariant_" + NumberToString(recoVar) + ";4"); std::cout << histogramName << std::endl; TH1F *pTH1F = (TH1F*)pTFile->Get(histogramName.c_str()); std::string fitTitle = "PFOEnergyHistogramGaussianFit_DetectorModel_" + NumberToString(detModel) + "_ReconstructionVariant_" + NumberToString(recoVar) + "_Energy" + NumberToString(energy) + "GeV"; TF1 *pGaussianFit = new TF1(fitTitle.c_str(),"gaus",0,1000); pTH1F->Fit(fitTitle.c_str()); const float fitAmplitude(pGaussianFit->GetParameter(0)); const float fitMean(pGaussianFit->GetParameter(1)); const float fitStdDev(pGaussianFit->GetParameter(2)); const float energyResolution(fitStdDev/fitMean); const float meanError(pGaussianFit->GetParError(1)); const float meanFracError(meanError / fitMean); const float stdDevError(pGaussianFit->GetParError(2)); const float stdDevFracError(stdDevError / fitStdDev); const float energyResolutionError = energyResolution * std::pow( (meanFracError*meanFracError) + (stdDevFracError*stdDevFracError) ,0.5); pTGraphErrors->SetPoint(pTGraphErrors->GetN(),layerNumber,energyResolution*100.f); pTGraphErrors->SetPointError(pTGraphErrors->GetN()-1,0,energyResolutionError*100.f); std::cout << "For energy : " << energy << std::endl; std::cout << "Amplitude : " << fitAmplitude << std::endl; std::cout << "Mean : " << fitMean << std::endl; std::cout << "Standard Deviation : " << fitStdDev << std::endl; std::cout << "Det model " << detModel << std::endl; std::cout << "Energy Resolution : " << energyResolution*100 << std::endl; } TH2F *pAxes = new TH2F("axesEj","",100,14,32,1000,2.5,3.5); pAxes->SetTitle("100 GeV Photon Energy Resolution vs Number of Layers in ECal (Si)"); pAxes->GetYaxis()->SetTitle("#sigma_{Reco} / E_{Reco}"); pAxes->GetXaxis()->SetTitle("Number of ECal Layers"); pAxes->Draw(); pTGraphErrors->Draw("same PL"); }