atable_ptr_t TableGenerator::create_empty_table_modifiable(size_t rows, size_t cols, std::vector<std::string> names) { std::vector<std::vector<AbstractTable::SharedDictionaryPtr> *> dicts; std::vector<std::vector<const ColumnMetadata *> *> md; for (size_t col = 0; col < cols; ++col) { std::vector<const ColumnMetadata *> *m = new std::vector<const ColumnMetadata *>; std::string colname(col < names.size() ? names.at(col) : "attr" + std::to_string(col)); m->push_back(new ColumnMetadata(colname, IntegerType)); md.push_back(m); auto d = new std::vector<AbstractTable::SharedDictionaryPtr>; auto new_dict = makeDictionary<OrderIndifferentDictionary>(IntegerType); d->push_back(new_dict); dicts.push_back(d); } auto new_table = std::make_shared<MutableVerticalTable>(md, &dicts, rows, false); for (const auto & d : dicts) delete d; for (const auto & m : md) { for (const auto & f: *m) delete f; delete m; } new_table->resize(rows); return new_table; }
Json::Value ResponseTask::generateResponseJson() { Json::Value response; epoch_t responseStart = _recordPerformanceData ? get_epoch_nanoseconds() : 0; PapiTracer pt; pt.addEvent("PAPI_TOT_CYC"); if (_recordPerformanceData) pt.start(); auto predecessor = getResultTask(); const auto& result = predecessor->getResultTable(); if (getState() != OpFail) { if (!_isAutoCommit) { response["session_context"] = std::to_string(_txContext.tid).append(" ").append(std::to_string(_txContext.lastCid)); } if (result) { // Make header Json::Value json_header(Json::arrayValue); for (unsigned col = 0; col < result->columnCount(); ++col) { Json::Value colname(result->nameOfColumn(col)); json_header.append(colname); } // Copy the complete result response["real_size"] = result->size(); response["rows"] = generateRowsJson(result, _transmitLimit, _transmitOffset); response["header"] = json_header; } //////////////////////////////////////////////////////////////////////////////////////// // Copy Performance Data if (_recordPerformanceData) { Json::Value json_perf(Json::arrayValue); for (const auto& attr : performance_data) { Json::Value element; element["papi_event"] = Json::Value(attr->papiEvent); element["duration"] = Json::Value((Json::UInt64)attr->duration); element["data"] = Json::Value((Json::UInt64)attr->data); element["name"] = Json::Value(attr->name); element["id"] = Json::Value(attr->operatorId); element["startTime"] = Json::Value((double)(attr->startTime - queryStart) / 1000000); element["endTime"] = Json::Value((double)(attr->endTime - queryStart) / 1000000); element["executingThread"] = Json::Value(attr->executingThread); element["lastCore"] = Json::Value(attr->core); element["lastNode"] = Json::Value(attr->node); // Put null for in/outRows if -1 was set element["inRows"] = attr->in_rows ? Json::Value(*(attr->in_rows)) : Json::Value(); element["outRows"] = attr->out_rows ? Json::Value(*(attr->out_rows)) : Json::Value(); if (_getSubQueryPerformanceData) { element["subQueryPerformanceData"] = _scriptOperation->getSubQueryPerformanceData(); } json_perf.append(element); } pt.stop(); Json::Value responseElement; responseElement["duration"] = Json::Value((Json::UInt64)pt.value("PAPI_TOT_CYC")); responseElement["name"] = Json::Value("ResponseTask"); responseElement["id"] = Json::Value("respond"); responseElement["startTime"] = Json::Value((double)(responseStart - queryStart) / 1000000); responseElement["endTime"] = Json::Value((double)(get_epoch_nanoseconds() - queryStart) / 1000000); std::string threadId = boost::lexical_cast<std::string>(std::this_thread::get_id()); responseElement["executingThread"] = Json::Value(threadId); responseElement["lastCore"] = Json::Value(getCurrentCore()); responseElement["lastNode"] = Json::Value(getCurrentNode()); std::optional<size_t> result_size; if (result) { result_size = result->size(); } responseElement["inRows"] = result_size ? Json::Value(*result_size) : Json::Value(); responseElement["outRows"] = Json::Value(); json_perf.append(responseElement); response["performanceData"] = json_perf; } Json::Value jsonKeys(Json::arrayValue); for (const auto& x : _generatedKeyRefs) { for (const auto& key : *x) { Json::Value element(key); jsonKeys.append(element); } } response["generatedKeys"] = jsonKeys; response["affectedRows"] = Json::Value(_affectedRows); if (_getSubQueryPerformanceData) { response["subQueryDataflow"] = _scriptOperation->getSubQueryDataflow(); } } LOG4CXX_DEBUG(_logger, "Table Use Count: " << result.use_count()); return response; }
void ResponseTask::operator()() { epoch_t responseStart = get_epoch_nanoseconds(); Json::Value response; if (getDependencyCount() > 0) { PapiTracer pt; pt.addEvent("PAPI_TOT_CYC"); pt.start(); auto predecessor = getResultTask(); const auto& result = predecessor->getResultTable(); if (predecessor->getState() != OpFail) { if (result) { // Make header Json::Value json_header(Json::arrayValue); for (unsigned col = 0; col < result->columnCount(); ++col) { Json::Value colname(result->nameOfColumn(col)); json_header.append(colname); } // Copy the complete result response["real_size"] = result->size(); response["rows"] = generateRowsJson(result, _transmitLimit); response["header"] = json_header; } // Copy Performance Data Json::Value json_perf(Json::arrayValue); for (const auto & attr: performance_data) { Json::Value element; element["papi_event"] = Json::Value(attr->papiEvent); element["duration"] = Json::Value((Json::UInt64) attr->duration); element["data"] = Json::Value((Json::UInt64) attr->data); element["name"] = Json::Value(attr->name); element["id"] = Json::Value(attr->operatorId); element["startTime"] = Json::Value((double)(attr->startTime - queryStart) / 1000000); element["endTime"] = Json::Value((double)(attr->endTime - queryStart) / 1000000); element["executingThread"] = Json::Value(attr->executingThread); json_perf.append(element); } pt.stop(); Json::Value responseElement; responseElement["duration"] = Json::Value((Json::UInt64) pt.value("PAPI_TOT_CYC")); responseElement["name"] = Json::Value("ResponseTask"); responseElement["id"] = Json::Value("respond"); responseElement["startTime"] = Json::Value((double)(responseStart - queryStart) / 1000000); responseElement["endTime"] = Json::Value((double)(get_epoch_nanoseconds() - queryStart) / 1000000); std::string threadId = boost::lexical_cast<std::string>(std::this_thread::get_id()); responseElement["executingThread"] = Json::Value(threadId); json_perf.append(responseElement); response["performanceData"] = json_perf; } else { LOG4CXX_ERROR(_logger, "Error during plan execution: " << predecessor->getErrorMessage()); response["error"] = predecessor->getErrorMessage(); } LOG4CXX_DEBUG(_logger, "Table Use Count: " << result.use_count()); } else { response["error"] = "Query parsing failed, see server error log"; } connection->respond(response.toStyledString()); }
/***********************************************************************//** * @brief Read Auxiliary Response File * * @param[in] table ARF FITS table. * * Reads the Auxiliary Response File from a FITS table. The true energy * boundaries are expected in the `ENERG_LO` and `ENERG_HI` columns, the * response information is expected in the `SPECRESP` column. * * The method will analyze the unit of the `SPECRESP` column, and if either * `m^2` or `m2` are encountered, multiply the values of the column by * \f$10^4\f$ to convert the response into units of \f$cm^2\f$. Units of the * `ENERG_LO` and `ENERG_HI` columns are also interpreted for conversion. * * See * http://heasarc.gsfc.nasa.gov/docs/heasarc/caldb/docs/memos/cal_gen_92_002/cal_gen_92_002.html#tth_sEc4 * for details about the Auxiliary Response File format. ***************************************************************************/ void GArf::read(const GFitsTable& table) { // Clear members clear(); // Get pointer to data columns const GFitsTableCol* energy_lo = table["ENERG_LO"]; const GFitsTableCol* energy_hi = table["ENERG_HI"]; const GFitsTableCol* specresp = table["SPECRESP"]; // Determine effective area conversion factor. Internal // units are cm^2 std::string u_specresp = gammalib::tolower(gammalib::strip_whitespace(specresp->unit())); double c_specresp = 1.0; if (u_specresp == "m^2" || u_specresp == "m2") { c_specresp = 10000.0; } // Extract number of energy bins int num = energy_lo->length(); // Set energy bins for (int i = 0; i < num; ++i) { // Append energy bin GEnergy emin(energy_lo->real(i), energy_lo->unit()); GEnergy emax(energy_hi->real(i), energy_hi->unit()); m_ebounds.append(emin, emax); // Append effective area value double aeff = specresp->real(i) * c_specresp; m_specresp.push_back(aeff); } // endfor: looped over energy bins // Read any additional columns for (int icol = 0; icol < table.ncols(); ++icol) { // Fall through if the column is a standard column std::string colname(table[icol]->name()); if ((colname == "ENERG_LO") || (colname == "ENERG_HI") || (colname == "SPECRESP")) { continue; } // Get pointer to column const GFitsTableCol* column = table[icol]; // Set column vector std::vector<double> coldata; for (int i = 0; i < num; ++i) { coldata.push_back(column->real(i)); } // Append column append(colname, coldata); } // endfor: looped over all additional columns // Return return; }