RowCollection<Group,Hash>::RowCollection(boost::shared_ptr<Query> const& query, const string& name, const Attributes& attributes, size_t chunkSize) : _query(query), _attributes(attributes), _chunkSize(chunkSize), _sizeBuffered(0), _mode(RowCollectionModeAppend) { assert(!attributes.empty()); assert(chunkSize >= 2); // Use (CONFIG_MEM_ARRAY_THRESHOLD / 10) as the #bytes the unflushed items may have. _maxSizeBuffered = Config::getInstance()->getOption<size_t>(CONFIG_MEM_ARRAY_THRESHOLD) * MiB / 10; // Push the empty tag Attributes attributesWithET(attributes); attributesWithET.push_back(AttributeDesc(attributes.size(), DEFAULT_EMPTY_TAG_ATTRIBUTE_NAME, TID_BOOL, AttributeDesc::IS_EMPTY_INDICATOR, 0)); // get the schema Dimensions dims(2); dims[0] = DimensionDesc("Row", 0, MAX_COORDINATE, 1, 0); dims[1] = DimensionDesc("Column", 0, MAX_COORDINATE, _chunkSize, 0); ArrayDesc schema(name, attributesWithET, dims); // create a MemArray _theArray = make_shared<MemArray>(schema,query); // get the array iterators _arrayIterators.reserve(attributes.size()); for (size_t t=0; t<attributes.size(); ++t) { _arrayIterators.push_back(_theArray->getIterator(t)); } }
/** * Function: Show_attributes * * Display both the key and value for an Attributes map. * * Since this is a non-critical message, it is only shown when the debug value * is set high enough. * * Parameter: attributes Defined as std::map<std::string, std::string> pair. * Most commonly found in data as a "name = value" pair. */ void Show_attributes(std::ostream& os, Attributes& attributes) { Monday_out(VERBOSE_LEVEL2, os, "- Num attributes: %d\n", attributes.size()); for(Attributes::iterator i = attributes.begin(); i != attributes.end(); ++i) { Monday_out(VERBOSE_LEVEL2, os, " \"%s\" = \"%s\"\n", i->first.c_str(), i->second.c_str()); } }
void PropertyList::AddAttributes(const Attributes& attributes) { RemoveAll(); for (unsigned int i = 0; i < attributes.size(); i++) { AddRow(new PropertyRow(attributes[i].fName, attributes[i].fValue)); } }
size_t TupleArray::getTupleFootprint(Attributes const& attrs) { size_t res =0, n = attrs.size(); for(size_t i=0; i<n; i++) { size_t attSize = attrs[i].getSize(); if(attSize == 0) { //variable size attSize = Config::getInstance()->getOption<int>(CONFIG_STRING_SIZE_ESTIMATION); } res += Value::getFootprint(attSize); } return res + sizeof(Tuple) + sizeof(shared_ptr<Tuple>); }
GLuint Shader::create(const char *vshSrc, const char *fshSrc, GLuint *vshId, GLuint *fshId, const Attributes &attributes) { *vshId = compile(GL_VERTEX_SHADER, vshSrc); *fshId = compile(GL_FRAGMENT_SHADER, fshSrc); // create shader program GLuint programId = glCreateProgram(); if (programId == 0) { OG_LOGERR("Shader", "could not create shader program"); return 0; } glAttachShader(programId, *vshId); // add the vertex shader to program glAttachShader(programId, *fshId); // add the fragment shader to program // Bind attribute locations // this needs to be done prior to linking for(int i = 0; i < attributes.size(); i++) { glBindAttribLocation(programId, attributes[i].first, attributes[i].second); } glLinkProgram(programId); // link both shaders to a full program // check link status GLint linkStatus; glGetProgramiv(programId, GL_LINK_STATUS, &linkStatus); if (linkStatus != GL_TRUE) { OG_LOGERR("Shader", "could not link shader program. error log:"); GLchar infoLogBuf[1024]; GLsizei infoLogLen; glGetProgramInfoLog(programId, 1024, &infoLogLen, infoLogBuf); cerr << infoLogBuf << endl << endl; glDeleteProgram(programId); return 0; } return programId; }
void DevicesView::AddDeviceAndChildren(device_node_cookie *node, Device* parent) { Attributes attributes; Device* newDevice = NULL; // Copy all its attributes, // necessary because we can only request them once from the device manager char data[256]; struct device_attr_info attr; attr.cookie = 0; attr.node_cookie = *node; attr.value.raw.data = data; attr.value.raw.length = sizeof(data); while (dm_get_next_attr(&attr) == B_OK) { BString attrString; switch (attr.type) { case B_STRING_TYPE: attrString << attr.value.string; break; case B_UINT8_TYPE: attrString << attr.value.ui8; break; case B_UINT16_TYPE: attrString << attr.value.ui16; break; case B_UINT32_TYPE: attrString << attr.value.ui32; break; case B_UINT64_TYPE: attrString << attr.value.ui64; break; default: attrString << "Raw data"; } attributes.push_back(Attribute(attr.name, attrString)); } // Determine what type of device it is and create it for (unsigned int i = 0; i < attributes.size(); i++) { // Devices Root if (attributes[i].fName == B_DEVICE_PRETTY_NAME && attributes[i].fValue == "Devices Root") { newDevice = new Device(parent, BUS_NONE, CAT_COMPUTER, B_TRANSLATE("Computer")); break; } // ACPI Controller if (attributes[i].fName == B_DEVICE_PRETTY_NAME && attributes[i].fValue == "ACPI") { newDevice = new Device(parent, BUS_ACPI, CAT_BUS, B_TRANSLATE("ACPI bus")); break; } // PCI bus if (attributes[i].fName == B_DEVICE_PRETTY_NAME && attributes[i].fValue == "PCI") { newDevice = new Device(parent, BUS_PCI, CAT_BUS, B_TRANSLATE("PCI bus")); break; } // ISA bus if (attributes[i].fName == B_DEVICE_BUS && attributes[i].fValue == "isa") { newDevice = new Device(parent, BUS_ISA, CAT_BUS, B_TRANSLATE("ISA bus")); break; } // PCI device if (attributes[i].fName == B_DEVICE_BUS && attributes[i].fValue == "pci") { newDevice = new DevicePCI(parent); break; } // ACPI device if (attributes[i].fName == B_DEVICE_BUS && attributes[i].fValue == "acpi") { newDevice = new DeviceACPI(parent); break; } // ATA / SCSI / IDE controller if (attributes[i].fName == "controller_name") { newDevice = new Device(parent, BUS_PCI, CAT_MASS, attributes[i].fValue); } // SCSI device node if (attributes[i].fName == B_DEVICE_BUS && attributes[i].fValue == "scsi") { newDevice = new DeviceSCSI(parent); break; } // Last resort, lets look for a pretty name if (attributes[i].fName == B_DEVICE_PRETTY_NAME) { newDevice = new Device(parent, BUS_NONE, CAT_NONE, attributes[i].fValue); break; } } // A completely unknown device if (newDevice == NULL) { newDevice = new Device(parent, BUS_NONE, CAT_NONE, B_TRANSLATE("Unknown device")); } // Add its attributes to the device, initialize it and add to the list. for (unsigned int i = 0; i < attributes.size(); i++) { newDevice->SetAttribute(attributes[i].fName, attributes[i].fValue); } newDevice->InitFromAttributes(); fDevices.push_back(newDevice); // Process children status_t err; device_node_cookie child = *node; if (get_child(&child) != B_OK) return; do { AddDeviceAndChildren(&child, newDevice); } while ((err = get_next_child(&child)) == B_OK); }
int main(int argc, char* argv[]) { namespace js = anu_am::json; char* scalarPath = argv[1]; char* fieldPath = argv[2]; if (argc < 3) { std::cerr << "Usage:" << argv[0] << " SCALARS FIELD [OUTPUT]" << std::endl; return 1; } // Read the data for this process. NCFileInfo const info = readFileInfo(fieldPath); Variable const var = findVolumeVariable(info); std::vector<size_t> dims = readDimensions(info); CubicalComplex complex(dims.at(0), dims.at(1), dims.at(2)); Vertices vertices(dims.at(0), dims.at(1), dims.at(2)); assert(dims == readDimensions(scalarPath)); Scalars::DataPtr scalarData = readVolumeData<Value>(scalarPath); Scalars scalars(complex, scalarData); Field::DataPtr fieldData = readVolumeData<FieldItem>(fieldPath); Field field = Field(dims.at(0), dims.at(1), dims.at(2), fieldData); // Process the data. std::map<Cell, Boundary> chains = chainComplex(complex, field); std::vector<Cell> const sources = criticalCellsSorted(complex, scalars, field); size_t const n = sources.size(); SimpleComplex const simple = simpleChainComplex( complex, scalars, chains, sources); std::vector<Pairing<Cell> > const pairs = persistencePairing(simple); // Generate metadata std::string const parentID = guessDatasetID(fieldPath, info.attributes()); std::string const thisID = derivedID(parentID, "persistence", "PP"); std::string const outfile = argc > 3 ? argv[3] : (stripTimestamp(thisID) + ".txt"); js::Array const predecessors = js::Array (parentID) (guessDatasetID(scalarPath, readFileInfo(scalarPath).attributes())); js::Object const description = js::Object ("id" , thisID) ("process" , "Critical Cell Persistence Pairs") ("sourcefile" , __FILE__) ("revision" , js::Object("id", GIT_REVISION)("date", GIT_TIMESTAMP)) ("parent" , parentID) ("predecessors", predecessors) ("parameters" , js::Object()); // Write data std::stringstream tmp; tmp << "# Persistence pairs for " << scalarPath << std::endl << "# format: <birth> <death> <dimension> <creator xyz> <destructor xyz>" << std::endl; for (size_t i = 0; i < pairs.size(); ++i) { size_t const j = pairs.at(i).partner; if (j > i) { Cell const v = sources.at(i); Cell const w = j >= n ? sources.at(i) : sources.at(j); tmp << std::fixed << std::setprecision(6); tmp << std::setw(12) << cellValue(v, scalars, vertices) << " " << std::setw(12); if (w == v) tmp << "inf"; else tmp << cellValue(w, scalars, vertices); tmp << " " << complex.cellDimension(v) << " " << complex.cellPosition(v) << " "; if (w == v) tmp << " - - - "; else tmp << complex.cellPosition(w); tmp << std::endl; } } std::ofstream ofs(outfile.c_str()); ofs << tmp.str(); // Write metadata ofs << "#" << std::endl << "# Metadata:" << std::endl; Attributes const attr = inheritableAttributes(info.attributes()); for (size_t i = 0; i < attr.size(); ++i) { std::string const key = attr.keyAt(i); ofs << "#" << std::endl << "#+ " << key << std::endl; if (key == "dataset_id") ofs << "#= " << thisID << std::endl; else if (key == "zdim_total") ofs << "#= " << dims.at(2) << std::endl; else if (key == "number_of_files") ofs << "#= 1" << std::endl; else if (key == "zdim_range") ofs << "#= 0, " << dims.at(2)-1 << std::endl; else printWithPrefix(ofs, attr(key).valuesAsString(), "#= "); } ofs << "#" << std::endl << "#+ " << "history_"+thisID << std::endl; ofs << js::toString(description, 2, "#= ") << std::endl; }
int main(int argc, char* argv[]) { char* infile = argv[1]; if (argc < 2) { std::cerr << "Usage:" << argv[0] << " INPUT" << std::endl; return 1; } FileBuffer data(infile); NCFile<FileBuffer> file(data); std::vector<Dimension> const dims = file.dimensions(); std::vector<Variable> const vars = file.variables(); Attributes const attrs = file.attributes(); size_t i; std::cout << "netcdf " << stripname(infile) << " {" << std::endl; std::cout << "dimensions:" << std::endl; for (i = 0; i < dims.size(); ++i) { Dimension d = dims.at(i); std::cout << "\t" << d.name << " = " << d.size << " ;" << std::endl; } std::cout << std::endl; std::cout << "variables:" << std::endl; for (i = 0; i < vars.size(); ++i) { Variable v = vars.at(i); std::cout << "\t" << tname(v.type()) << " " << v.name() << "(" << toString(v.dimensionNames()) << ") ;" << std::endl; Attributes const attrs = v.attributes(); for (size_t j = 0; j < attrs.size(); ++j) { Attribute a = attrs.at(j); std::cout << "\t\t" << v.name() << ":" << attrs.keyAt(j) << " = " << formatString(a.valuesAsString()) << " ;" << std::endl; } } std::cout << std::endl; std::cout << "// global attributes:" << std::endl; for (i = 0; i < attrs.size(); ++i) { Attribute a = attrs.at(i); std::cout << "\t\t:" << attrs.keyAt(i) << " = " << formatString(a.valuesAsString()) << " ;" << std::endl; } std::cout << std::endl; std::cout << "data:" << std::endl; for (i = 0; i < vars.size(); ++i) { Variable v = vars.at(i); std::cout << std::endl << " " << v.name() << " =" << std::endl; std::cout << " " << file.valueAsString(v, 0, 0, 0) << ", " << file.valueAsString(v, 1, 0, 0) << ", " << file.valueAsString(v, 2, 0, 0) << ", " << file.valueAsString(v, 3, 0, 0) << ", " << file.valueAsString(v, 4, 0, 0) << ", ... ;" << std::endl; } std::cout << "}" << std::endl; }