21 #include "isoSpec++.h"
23 #define ISOSPEC_INIT_TABLE_SIZE 1024
47 if( _masses !=
nullptr ) free(_masses);
48 if( _lprobs !=
nullptr ) free(_lprobs);
49 if( _probs !=
nullptr ) free(_probs);
50 if( _confs !=
nullptr ) free(_confs);
53 inline size_t confs_no()
const {
return _confs_no; };
54 inline int getAllDim()
const {
return allDim; };
56 inline const double* lprobs() {
return _lprobs; };
57 inline const double* masses() {
return _masses; };
58 inline const double* probs() {
return _probs; };
59 inline const int* confs() {
return _confs; };
61 inline double* release_lprobs() {
double* ret = _lprobs; _lprobs =
nullptr;
return ret; };
62 inline double* release_masses() {
double* ret = _masses; _masses =
nullptr;
return ret; };
63 inline double* release_probs() {
double* ret = _probs; _probs =
nullptr;
return ret; };
64 inline int* release_confs() {
int* ret = _confs; _confs =
nullptr;
return ret; };
67 inline double mass(
size_t i) {
return _masses[i]; };
68 inline double lprob(
size_t i) {
return _lprobs[i]; };
69 inline double prob(
size_t i) {
return _probs[i]; };
70 inline const int* conf(
size_t i) {
return _confs + i*allDim; };
80 template<
typename T,
bool tgetlProbs,
bool tgetMasses,
bool tgetProbs,
bool tgetConfs> ISOSPEC_FORCE_INLINE
void store_conf(T& generator)
82 constexpr_if(tgetlProbs) { *tlprobs = generator.lprob(); tlprobs++; };
83 constexpr_if(tgetMasses) { *tmasses = generator.mass(); tmasses++; };
84 constexpr_if(tgetProbs) { *tprobs = generator.prob(); tprobs++; };
85 constexpr_if(tgetConfs) { generator.get_conf_signature(tconfs); tconfs += allDim; };
88 template<
bool tgetlProbs,
bool tgetMasses,
bool tgetProbs,
bool tgetConfs>
void reallocate_memory(
size_t new_size);
91 template<
typename T>
void call_init(T* tabulator,
Iso&& iso,
bool tgetlProbs,
bool tgetMasses,
bool tgetProbs,
bool tgetConfs);
95 const double threshold;
98 ThresholdFixedEnvelope(
Iso&& iso,
double _threshold,
bool _absolute,
bool tgetConfs =
false,
bool tgetlProbs =
false,
bool tgetMasses =
true,
bool tgetProbs =
true) :
100 threshold(_threshold),
103 call_init<ThresholdFixedEnvelope>(
this, std::move(iso), tgetlProbs, tgetMasses, tgetProbs, tgetConfs);
106 inline ThresholdFixedEnvelope(
const Iso& iso,
double _threshold,
bool _absolute,
bool tgetConfs =
false,
bool tgetlProbs =
false,
bool tgetMasses =
true,
bool tgetProbs =
true) :
112 template<
bool tgetlProbs,
bool tgetMasses,
bool tgetProbs,
bool tgetConfs>
void init(
Iso&& iso);
114 template<
typename T>
friend void call_init(T* tabulator,
Iso&& iso,
bool tgetlProbs,
bool tgetMasses,
bool tgetProbs,
bool tgetConfs);
121 double target_total_prob;
125 TotalProbFixedEnvelope(
Iso&& iso,
double _target_total_prob,
bool _optimize,
bool tgetConfs =
false,
bool tgetlProbs =
false,
bool tgetMasses =
true,
bool tgetProbs =
true) :
128 target_total_prob(_target_total_prob >= 1.0 ? std::numeric_limits<double>::infinity() : _target_total_prob),
129 current_size(ISOSPEC_INIT_TABLE_SIZE)
131 if(_target_total_prob <= 0.0)
134 call_init(
this, std::move(iso), tgetlProbs, tgetMasses, tgetProbs || _optimize, tgetConfs);
136 if(!tgetProbs && optimize)
143 inline TotalProbFixedEnvelope(
const Iso& iso,
double _target_total_prob,
bool _optimize,
bool tgetConfs =
false,
bool tgetlProbs =
false,
bool tgetMasses =
true,
bool tgetProbs =
true) :
150 template<
bool tgetlProbs,
bool tgetMasses,
bool tgetProbs,
bool tgetConfs>
void init(
Iso&& iso);
152 template<
bool tgetlProbs,
bool tgetMasses,
bool tgetProbs,
bool tgetConfs>
void swap([[maybe_unused]]
size_t idx1, [[maybe_unused]]
size_t idx2, [[maybe_unused]]
int* conf_swapspace)
154 constexpr_if(tgetlProbs) std::swap<double>(this->_lprobs[idx1], this->_lprobs[idx2]);
155 constexpr_if(tgetProbs) std::swap<double>(this->_probs[idx1], this->_probs[idx2]);
156 constexpr_if(tgetMasses) std::swap<double>(this->_masses[idx1], this->_masses[idx2]);
157 constexpr_if(tgetConfs)
159 int* c1 = this->_confs + (idx1*this->allDim);
160 int* c2 = this->_confs + (idx2*this->allDim);
161 memcpy(conf_swapspace, c1, this->allDimSizeofInt);
162 memcpy(c1, c2, this->allDimSizeofInt);
163 memcpy(c2, conf_swapspace, this->allDimSizeofInt);
168 template<
bool tgetlProbs,
bool tgetMasses,
bool tgetProbs,
bool tgetConfs>
void addConf(
IsoLayeredGenerator& generator)
170 if(this->_confs_no == this->current_size)
172 this->current_size *= 2;
173 this->
template reallocate_memory<tgetlProbs, tgetMasses, tgetProbs, tgetConfs>(this->current_size);
176 this->
template store_conf<IsoLayeredGenerator, tgetlProbs, tgetMasses, tgetProbs, tgetConfs>(generator);
180 template<
typename T>
friend void call_init(T* tabulator,
Iso&& iso,
bool tgetlProbs,
bool tgetMasses,
bool tgetProbs,
bool tgetConfs);