/* * Return 1 if the expression tree rooted at root evaluates to true * for the event record (entry, buf), or to 0 otherwise. tmplAtts is * the array of pointers into the populated template for any non-standard * attributes referenced by the query. */ static int evaluateTree(const pnode_t *root, evlattribute_t *tmplAtts[], const struct posix_log_entry *entry, const void *buf) { const pnode_t *left; const pnode_t *right; int op; int attIndex; long sval; unsigned long uval; if (root->node_type == nt_attname) { /* True if this record has this attribute. */ if (root->attr_flag == POSIX_LOG_ENTRY_DATA) { return (entry->log_size > 0); } return 1; } if (root->node_type == nt_nsaname) { /* True if this record has this non-standard attribute. */ evlattribute_t *att; if (!tmplAtts) { return 0; } att = tmplAtts[root->attr_nsa->nsaAtt]; return (att && attExists(att)); } assert(root->node_type == nt_op); left = pnLeft(root); right = pnRight(root); op = root->attr_flag; if (op == AND) { return (evaluateTree(left, tmplAtts, entry, buf) && evaluateTree(right, tmplAtts, entry, buf)); } if (op == OR) { return (evaluateTree(left, tmplAtts, entry, buf) || evaluateTree(right, tmplAtts, entry, buf)); } if (op == '!') { return (! evaluateTree(left, tmplAtts, entry, buf)); } if (left->node_type == nt_nsaname) { return evaluateNonStdComparison(root, tmplAtts); } attIndex = left->attr_flag; if (right->node_type == nt_string || right->node_type == nt_regex) { /* * Get the string equivalent of the attribute value, for * comparison either via strstr or via regexec. */ const char *leftStr; char memStr[POSIX_LOG_MEMSTR_MAXLEN]; int status; if (attIndex == POSIX_LOG_ENTRY_DATA) { if (entry->log_format != POSIX_LOG_STRING) { /* Can compare only string data. */ return 0; } leftStr = (const char*) buf; } else { if (attIndex == EVL_ENTRY_HOST) { leftStr = _evlGetHostNameEx(entry->log_processor>>16); } else { status = posix_log_memtostr(attIndex, entry, memStr, POSIX_LOG_MEMSTR_MAXLEN); assert(status == 0); leftStr = (const char*) memStr; } }
/* construct sphere-tree for the model */ bool constructTree(const boost::filesystem::path& input_file, bool toYAML) { boost::filesystem::path output_file = input_file.parent_path () / boost::filesystem::basename (input_file); if (toYAML) output_file += "-spawn.yml"; else output_file += "-spawn.sph"; printf("Input file: %s\n", input_file.c_str ()); printf("Output file: %s\n\n", output_file.c_str ()); /* load the surface model */ Surface sur; bool loaded = false; std::string extension = boost::algorithm::to_lower_copy (input_file.extension ().string ()); if (extension == ".obj") loaded = loadOBJ(&sur, input_file.c_str ()); else loaded = sur.loadSurface(input_file.c_str ()); if (!loaded){ printf("ERROR : Unable to load input file (%s)\n\n", input_file.c_str ()); return false; } /* scale box */ // FIXME: Disable scaling for now (wrong result if a transformation is applied after) //float boxScale = sur.fitIntoBox(1000); float boxScale = 1.; /* make medial tester */ MedialTester mt; mt.setSurface(sur); mt.useLargeCover = true; /* setup evaluator */ SEConvex convEval; convEval.setTester(mt); SEBase *eval = &convEval; Array<Point3D> sphPts; SESphPt sphEval; if (testerLevels > 0){ // <= 0 will use convex tester SSIsohedron::generateSamples(&sphPts, testerLevels-1); sphEval.setup(mt, sphPts); eval = &sphEval; printf("Using concave tester (%d)\n\n", sphPts.getSize()); } /* verify model */ if (verify){ bool ok = verifyModel(sur); if (!ok){ printf("ERROR : model is not usable\n\n"); return false; } } /* setup for the set of cover points */ Array<Surface::Point> coverPts; MSGrid::generateSamples(&coverPts, numCoverPts, sur, TRUE, minCoverPts); printf("%d cover points\n", coverPts.getSize()); /* setup SPAWN algorithm */ SRSpawn spawn; spawn.setup(mt); spawn.useIterativeSelect = false; spawn.eval = eval; /* setup SphereTree constructor - using dynamic construction */ STGGeneric treegen; treegen.eval = eval; treegen.useRefit = true; treegen.setSamples(coverPts); treegen.reducer = &spawn; /* make sphere-tree */ SphereTree tree; tree.setupTree(branch, depth+1); waitForKey(); treegen.constructTree(&tree); /* save sphere-tree */ if (tree.saveSphereTree(output_file, 1.0f/boxScale)){ Array<LevelEval> evals; if (eval){ evaluateTree(&evals, tree, eval); writeEvaluation(stdout, evals); } if (!yaml) { FILE *f = fopen(output_file.c_str (), "a"); if (f){ fprintf(f, "\n\n"); fprintf(f, "Options : \n"); writeParam(stdout, intParams); writeParam(stdout, boolParams); fprintf(f, "\n\n"); writeEvaluation(f, evals); fclose(f); } } return true; } else{ return false; } }