<commit_before>#include <iostream>
#include <iomanip>
#include <limits>
#include <stdexcept>
#include <fstream>
#include <bitset>
#include <string>
#include <sstream>
#include <vector>
#include <cmath>

#include "pcaconst.hpp"

using namespace pca;
using namespace std;

template <typename T>
void dump_element (const pca::matrixpcaconst<T> & in, std::ostream & out)
{
  out.precision(6);
  for (unsigned int i = 0; i<in.n_rows(); ++i)
  {
    for (unsigned int j = 0; j<in.n_cols(); ++j)
      out << std::scientific << in(i, j) << " ";
    out << std::endl;
  }
}

bool check_val(double val, int width, bool sign = true) 
{
  if (sign)
  {
    if (abs(val) > pow(2, width-1))
      std::cerr << "value: " << (long long int) val << " width: " << width << std::endl;

    return (abs(val) > pow(2, width-1));
  }

  if (abs(val) > pow(2, width))
    std::cerr << "value: " << (long long int) val << " width: " << width << std::endl;

  return (abs(val) > pow(2, width));
}

bool read_integer_const_filename (const std::string & in, 
    std::vector<pca::matrixpcaconst<long long int> > & pcacontvct_integer)
{
  std::cout << "Reading " << in << std::endl;
  if (!pca::read_pcaconst_from_file (pcacontvct_integer, in.c_str()))
  {
    std::cerr << "Error while reading constant from " << in << " read only " <<                   
      pcacontvct_integer.size() << std::endl;
    return false;
  }
        
  std::vector<pca::matrixpcaconst<long long int> >::const_iterator it = 
    pcacontvct_integer.begin();
  for (; it != pcacontvct_integer.end(); ++it)            
  {
    if (it->get_ttype() != pca::INTEGPT)
    {        
      std::cerr << "Wrong PCAconst type for " << it->get_towerid() <<      
        " input file " <<  in << std::endl;      
      return false;                                        
    }                    
  }
            
  std::cout << "Done" << std::endl;

  return true;
}


int main (int argc, char *argv[]) 
{
  if (argc != 2)
  {
    std::cerr << "usage: " << argv[0] << " pca_const_file.txt " << std::endl;
    return EXIT_FAILURE;
  }

  std::string in_fname = argv[1];
  std::vector<pca::matrixpcaconst<long long int> > pcacontvct_integer;
  
  if (read_integer_const_filename (in_fname, pcacontvct_integer))
  {
    pca::matrixpcaconst<long long int> cmtx_rz(0, 0);
    pca::matrixpcaconst<long long int> qvec_rz(0, 0); 
    pca::matrixpcaconst<long long int> amtx_rz(0, 0); 
    pca::matrixpcaconst<long long int> kvec_rz(0, 0); 
    pca::matrixpcaconst<long long int> cmtx_rphi(0, 0); 
    pca::matrixpcaconst<long long int> qvec_rphi(0, 0); 
    pca::matrixpcaconst<long long int> amtx_rphi(0, 0); 
    pca::matrixpcaconst<long long int> kvec_rphi(0, 0); 

    double eta_est, pt_est, charge;
    int tow;

    pca::matrixpcaconst<long long int> zrv(1, 12), phirv(1, 12);
    std::string layersid, pslayersid;

    bool rz5oof6, rphi5oof6;

    /* TEST FW 
    |---------+----------------|
    | value   | scaling factor |
    |---------+----------------|
    | r       |           1024 | OK
    | phi     |          65536 | OK
    | z       |            256 | OK
    | pt      |            256 | ==> ?
    | eta     |           1024 | ==> ?
    | results |       1e5*1024 | OK
    |---------+----------------|

    ----------------- Track #1 --------------------

    |----------+------+-----|
    | Pattern# |   pt | eta |
    |----------+------+-----|
    | 0x05C5A2 | 1172 | 171 |
    |----------+------+-----|
    */

    eta_est = 0.1669921875;
    pt_est = 4.578125;
    charge = +1;

    tow = 25;
 
    /*
    |--------+--------+-------+------|
    | Layer# |      r |   phi |    z |
    |--------+--------+-------+------|
    |      1 |  34971 | 43112 | -534 | missing layer is 5
    |      2 |  51069 | 44438 |  141 |
    |      8 |  69286 | 45914 |  751 |
    |      9 |  91956 | 47752 | 2038 |
    |     10 | 108987 | 49128 | 3267 |
    |--------+--------+-------+------|
    */

    rz5oof6 = true;
    rphi5oof6 = true;

    layersid = "6:7:8:9:10"; 
    pslayersid = "6:7";

    zrv(0, 0) = -534; zrv(0, 1) = 34971;
    zrv(0, 2) =  141; zrv(0, 3) = 51069;
    //zrv(0, 4) = 733; zrv(0, 5) = 53194;
    
    phirv(0, 0) = 43112; phirv(0, 1) =  34971;
    phirv(0, 2) = 44438; phirv(0, 3) =  51069;
    phirv(0, 4) = 45914; phirv(0, 5) =  69286;
    phirv(0, 6) = 47752; phirv(0, 7) =  91956;
    phirv(0, 8) = 49128; phirv(0, 9) = 108987;
    //phirv(0, 10) = 35082; phirv(0, 11) = 111634;

    double sec_phi = (tow%8) * M_PI / 4.0 - 0.4;

    if (pca::import_pca_const (pcacontvct_integer, 
                          cmtx_rz, 
                          qvec_rz, 
                          amtx_rz, 
                          kvec_rz, 
                          cmtx_rphi, 
                          qvec_rphi, 
                          amtx_rphi, 
                          kvec_rphi, 
                          eta_est, 
                          pt_est, 
                          charge,
                          layersid, 
                          pslayersid, 
                          tow, 
                          pca::INTEGPT))
    {
      std::cout << "CMTX RZ: " << std::endl;
      dump_element(cmtx_rz, std::cout);
      
      std::cout << "QVEC RZ: " << std::endl;
      dump_element(qvec_rz, std::cout);
      
      std::cout << "CMTX RPHI: " << std::endl;
      dump_element(cmtx_rphi, std::cout);
      
      std::cout << "QVEC RPHI: " << std::endl;
      dump_element(qvec_rphi, std::cout);

      long long int cottheta = 0;
      long long int z0 = 0;
      
      cottheta = qvec_rz(0,0);
      z0 = qvec_rz(0,1);<commit_msg>dump also amtx and kvec<commit_after>#include <iostream>
#include <iomanip>
#include <limits>
#include <stdexcept>
#include <fstream>
#include <bitset>
#include <string>
#include <sstream>
#include <vector>
#include <cmath>

#include "pcaconst.hpp"

using namespace pca;
using namespace std;

template <typename T>
void dump_element (const pca::matrixpcaconst<T> & in, std::ostream & out)
{
  out.precision(6);
  for (unsigned int i = 0; i<in.n_rows(); ++i)
  {
    for (unsigned int j = 0; j<in.n_cols(); ++j)
      out << std::scientific << in(i, j) << " ";
    out << std::endl;
  }
}

bool check_val(double val, int width, bool sign = true) 
{
  if (sign)
  {
    if (abs(val) > pow(2, width-1))
      std::cerr << "value: " << (long long int) val << " width: " << width << std::endl;

    return (abs(val) > pow(2, width-1));
  }

  if (abs(val) > pow(2, width))
    std::cerr << "value: " << (long long int) val << " width: " << width << std::endl;

  return (abs(val) > pow(2, width));
}

bool read_integer_const_filename (const std::string & in, 
    std::vector<pca::matrixpcaconst<long long int> > & pcacontvct_integer)
{
  std::cout << "Reading " << in << std::endl;
  if (!pca::read_pcaconst_from_file (pcacontvct_integer, in.c_str()))
  {
    std::cerr << "Error while reading constant from " << in << " read only " <<                   
      pcacontvct_integer.size() << std::endl;
    return false;
  }
        
  std::vector<pca::matrixpcaconst<long long int> >::const_iterator it = 
    pcacontvct_integer.begin();
  for (; it != pcacontvct_integer.end(); ++it)            
  {
    if (it->get_ttype() != pca::INTEGPT)
    {        
      std::cerr << "Wrong PCAconst type for " << it->get_towerid() <<      
        " input file " <<  in << std::endl;      
      return false;                                        
    }                    
  }
            
  std::cout << "Done" << std::endl;

  return true;
}


int main (int argc, char *argv[]) 
{
  if (argc != 2)
  {
    std::cerr << "usage: " << argv[0] << " pca_const_file.txt " << std::endl;
    return EXIT_FAILURE;
  }

  std::string in_fname = argv[1];
  std::vector<pca::matrixpcaconst<long long int> > pcacontvct_integer;
  
  if (read_integer_const_filename (in_fname, pcacontvct_integer))
  {
    pca::matrixpcaconst<long long int> cmtx_rz(0, 0);
    pca::matrixpcaconst<long long int> qvec_rz(0, 0); 
    pca::matrixpcaconst<long long int> amtx_rz(0, 0); 
    pca::matrixpcaconst<long long int> kvec_rz(0, 0); 
    pca::matrixpcaconst<long long int> cmtx_rphi(0, 0); 
    pca::matrixpcaconst<long long int> qvec_rphi(0, 0); 
    pca::matrixpcaconst<long long int> amtx_rphi(0, 0); 
    pca::matrixpcaconst<long long int> kvec_rphi(0, 0); 

    double eta_est, pt_est, charge;
    int tow;

    pca::matrixpcaconst<long long int> zrv(1, 12), phirv(1, 12);
    std::string layersid, pslayersid;

    bool rz5oof6, rphi5oof6;

    /* TEST FW 
    |---------+----------------|
    | value   | scaling factor |
    |---------+----------------|
    | r       |           1024 | OK
    | phi     |          65536 | OK
    | z       |            256 | OK
    | pt      |            256 | ==> ?
    | eta     |           1024 | ==> ?
    | results |       1e5*1024 | OK
    |---------+----------------|

    ----------------- Track #1 --------------------

    |----------+------+-----|
    | Pattern# |   pt | eta |
    |----------+------+-----|
    | 0x05C5A2 | 1172 | 171 |
    |----------+------+-----|
    */

    eta_est = 0.1669921875;
    pt_est = 4.578125;
    charge = +1;

    tow = 25;
 
    /*
    |--------+--------+-------+------|
    | Layer# |      r |   phi |    z |
    |--------+--------+-------+------|
    |      1 |  34971 | 43112 | -534 | missing layer is 5
    |      2 |  51069 | 44438 |  141 |
    |      8 |  69286 | 45914 |  751 |
    |      9 |  91956 | 47752 | 2038 |
    |     10 | 108987 | 49128 | 3267 |
    |--------+--------+-------+------|
    */

    rz5oof6 = true;
    rphi5oof6 = true;

    layersid = "6:7:8:9:10"; 
    pslayersid = "6:7";

    zrv(0, 0) = -534; zrv(0, 1) = 34971;
    zrv(0, 2) =  141; zrv(0, 3) = 51069;
    //zrv(0, 4) = 733; zrv(0, 5) = 53194;
    
    phirv(0, 0) = 43112; phirv(0, 1) =  34971;
    phirv(0, 2) = 44438; phirv(0, 3) =  51069;
    phirv(0, 4) = 45914; phirv(0, 5) =  69286;
    phirv(0, 6) = 47752; phirv(0, 7) =  91956;
    phirv(0, 8) = 49128; phirv(0, 9) = 108987;
    //phirv(0, 10) = 35082; phirv(0, 11) = 111634;

    double sec_phi = (tow%8) * M_PI / 4.0 - 0.4;

    if (pca::import_pca_const (pcacontvct_integer, 
                          cmtx_rz, 
                          qvec_rz, 
                          amtx_rz, 
                          kvec_rz, 
                          cmtx_rphi, 
                          qvec_rphi, 
                          amtx_rphi, 
                          kvec_rphi, 
                          eta_est, 
                          pt_est, 
                          charge,
                          layersid, 
                          pslayersid, 
                          tow, 
                          pca::INTEGPT))
    {
      std::cout << "CMTX RZ: " << std::endl;
      dump_element(cmtx_rz, std::cout);
      
      std::cout << "QVEC RZ: " << std::endl;
      dump_element(qvec_rz, std::cout);
      
      std::cout << "CMTX RPHI: " << std::endl;
      dump_element(cmtx_rphi, std::cout);
      
      std::cout << "QVEC RPHI: " << std::endl;
      dump_element(qvec_rphi, std::cout);

      std::cout << "AMTX RPHI: " << std::endl;
      dump_element(amtx_rphi, std::cout);
      
      std::cout << "KVEC RPHI: " << std::endl;
      dump_element(kvec_rphi, std::cout);

      std::cout << "AMTX RZ: " << std::endl;
      dump_element(amtx_rz, std::cout);
      
      std::cout << "KVEC RZ: " << std::endl;
      dump_element(kvec_rz, std::cout);

      long long int cottheta = 0;
      long long int z0 = 0;
      
      cottheta = qvec_rz(0,0);
      z0 = qvec_rz(0,1);
{'fraction_non_alphanumeric': 0.19545376270018944, 'fraction_numerical': 0.055278112622696746, 'mean_word_length': 1.6308040770101926, 'pattern_counts': {'":': 0, '<': 241, '<?xml version=': 0, '>': 73, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5198457', 'n_tokens_mistral': 4831, 'n_tokens_neox': 4294, 'n_words': 903}