// ############################################################ } END_PIE BEGIN_PIE(TPCC_PAYMENT, // txn TPCC_PAYMENT_4, // piece 4, R & W customer DF_REAL) { // ############################################################ verify(input_size == 6); Log::debug("TPCC_PAYMENT, piece: %d", TPCC_PAYMENT_4); i32 output_index = 0; // ############################################################ mdb::Row *r = NULL; std::vector<Value> buf; mdb::MultiBlob mb(3); //cell_locator_t cl(TPCC_TB_CUSTOMER, 3); mb[0] = input[0].get_blob(); mb[1] = input[2].get_blob(); mb[2] = input[1].get_blob(); // R customer if (!(IS_MODE_RCC || IS_MODE_RO6) || ((IS_MODE_RCC || IS_MODE_RO6) && IN_PHASE_1)) { // non-rcc || rcc start request r = dtxn->query(dtxn->get_table(TPCC_TB_CUSTOMER), mb, output_size, header.pid).next(); } ALock::type_t lock_20_type = ALock::RLOCK; if (input[0].get_i32() % 10 == 0) lock_20_type = ALock::WLOCK; // ############################################################ TPL_KISS( mdb::column_lock_t(r, 3, ALock::RLOCK), mdb::column_lock_t(r, 4, ALock::RLOCK), mdb::column_lock_t(r, 5, ALock::RLOCK), mdb::column_lock_t(r, 6, ALock::RLOCK), mdb::column_lock_t(r, 7, ALock::RLOCK), mdb::column_lock_t(r, 8, ALock::RLOCK), mdb::column_lock_t(r, 9, ALock::RLOCK), mdb::column_lock_t(r, 10, ALock::RLOCK), mdb::column_lock_t(r, 11, ALock::RLOCK), mdb::column_lock_t(r, 12, ALock::RLOCK), mdb::column_lock_t(r, 13, ALock::RLOCK), mdb::column_lock_t(r, 14, ALock::RLOCK), mdb::column_lock_t(r, 15, ALock::RLOCK), mdb::column_lock_t(r, 16, ALock::WLOCK), mdb::column_lock_t(r, 17, ALock::WLOCK), mdb::column_lock_t(r, 20, lock_20_type) ) // ############################################################ RCC_KISS(r, 16, false); RCC_KISS(r, 17, false); RCC_KISS(r, 20, false); RCC_SAVE_ROW(r, TPCC_PAYMENT_4); RCC_PHASE1_RET; RCC_LOAD_ROW(r, TPCC_PAYMENT_4); if (!dtxn->read_columns(r, std::vector<mdb::column_id_t>({ 3, // c_first buf[0] 4, // c_middle buf[1] 5, // c_last buf[2] 6, // c_street_1 buf[3] 7, // c_street_2 buf[4] 8, // c_city buf[5] 9, // c_state buf[6] 10, // c_zip buf[7] 11, // c_phone buf[8] 12, // c_since buf[9] 13, // c_credit buf[10] 14, // c_credit_lim buf[11] 15, // c_discount buf[12] 16, // c_balance buf[13] 17, // c_ytd_payment buf[14] 20 // c_data buf[15] }), &buf)) { *res = REJECT; *output_size = output_index; return; } // if c_credit == "BC" (bad) 10% // here we use c_id to pick up 10% instead of c_credit if (input[0].get_i32() % 10 == 0) { Value c_data(( to_string(input[0]) + to_string(input[2]) + to_string(input[1]) + to_string(input[5]) + to_string(input[4]) + to_string(input[3]) + buf[15].get_str() ).substr(0, 500)); std::vector<mdb::column_id_t> col_ids({ 16, // c_balance 17, // c_ytd_payment 20 // c_data }); std::vector<Value> col_data({ Value(buf[13].get_double() - input[3].get_double()), Value(buf[14].get_double() + input[3].get_double()), c_data }); dtxn->write_columns(r, col_ids, col_data); } else { std::vector<mdb::column_id_t> col_ids({ 16, // c_balance 17 // c_ytd_payment }); std::vector<Value> col_data({ Value(buf[13].get_double() - input[3].get_double()), Value(buf[14].get_double() + input[3].get_double()) }); dtxn->write_columns(r, col_ids, col_data); } output[output_index++] = input[0]; // output[0] => c_id output[output_index++] = buf[0]; // output[1] => c_first output[output_index++] = buf[1]; // output[2] => c_middle output[output_index++] = buf[2]; // output[3] => c_last output[output_index++] = buf[3]; // output[4] => c_street_1 output[output_index++] = buf[4]; // output[5] => c_street_2 output[output_index++] = buf[5]; // output[6] => c_city output[output_index++] = buf[6]; // output[7] => c_state output[output_index++] = buf[7]; // output[8] => c_zip output[output_index++] = buf[8]; // output[9] => c_phone output[output_index++] = buf[9]; // output[10] => c_since output[output_index++] = buf[10]; // output[11] => c_credit output[output_index++] = buf[11]; // output[12] => c_credit_lim output[output_index++] = buf[12]; // output[13] => c_discount output[output_index++] = Value(buf[13].get_double() - input[3].get_double()); // output[14] => c_balance // ############################################################ verify(*output_size >= output_index); *res = SUCCESS; Log::debug("TPCC_PAYMENT, piece: %d end", TPCC_PAYMENT_4); // ############################################################ *output_size = output_index; } END_PIE
/***********************************************************************//** * @brief Write Pulse Height Analyzer spectrum * * @param[in] fits FITS file. * * Writes the Pulse Height Analyzer spectrum into `SPECTRUM` and `EBOUNDS` * extensions of the FITS file. Extensions with these names will be removed * from the FITS file before writing. * * The columns `CHANNEL`, `COUNTS`, `STAT_ERR`, `SYS_ERR`, `QUALITY`, * `GROUPING`, `AREASCAL`, and `BACKSCAL` will be written into the `SPECTRUM` * extension, but only the `CHANNEL` and `COUNTS` columns will be filled with * values. Note that the channels start from 1 in the Pulse Height Analyzer * spectrum. * * See * https://heasarc.gsfc.nasa.gov/docs/heasarc/ofwg/docs/spectra/ogip_92_007/node5.html * for details about the PHA file format. ***************************************************************************/ void GPha::write(GFits& fits) const { // Remove extensions if they exist already if (fits.contains("EBOUNDS")) { fits.remove("EBOUNDS"); } if (fits.contains("SPECTRUM")) { fits.remove("SPECTRUM"); } // Set column length int length = size(); // Continue only if there are bins if (length > 0) { // Create new binary table GFitsBinTable hdu; // Allocate floating point vector columns GFitsTableShortCol col_chan("CHANNEL", length); GFitsTableFloatCol col_data("COUNTS", length); GFitsTableFloatCol col_stat("STAT_ERR", length); GFitsTableFloatCol col_syst("SYS_ERR", length); GFitsTableShortCol col_qual("QUALITY", length); GFitsTableShortCol col_grpg("GROUPING", length); GFitsTableFloatCol col_area("AREASCAL", length); GFitsTableFloatCol col_back("BACKSCAL", length); // Fill columns for (int i = 0; i < length; ++i) { col_chan(i) = i+1; // Channels start at 1 col_data(i) = float(m_counts[i]); } // Set table attributes hdu.extname("SPECTRUM"); // Append columns to table hdu.append(col_chan); hdu.append(col_data); hdu.append(col_stat); hdu.append(col_syst); hdu.append(col_qual); hdu.append(col_grpg); hdu.append(col_area); hdu.append(col_back); // Write keywords hdu.card("EXPOSURE", m_exposure, "[s] Deadtime corrected exposure time"); // Append HDU to FITS file fits.append(hdu); // Optionally append energy boundaries if (m_ebounds.size() > 0) { m_ebounds.write(fits); } } // endif: there were data to write // Return return; }