Eclipse Debug-Code ausblenden



  • Hi,

    ich habe das Problem, dass manche meiner algorithmischen Methoden viel Code enthalten, den man über einen Flag zuschalten kann, um sich zwecks Debugging Werte von Variablen ausgeben zu lassen. Also z. B.

    double rec_prob(Rev_Base_Nd* nd)
    {
    	const BOOL OUTPUT_DEBUG = 0;
    
    	...
    
    	if (OUTPUT_DEBUG) {
    		cout << "p_L: " << p_L << endl;
    		cout << "p_R: " << p_R << endl;
    		cout << "P: " << P << endl;
    		cout << "PP: " << PP << endl;
    		cout << "----------------" << endl;
    	}
    
    	// sum the probability of a observable recombination event happening over all possible numbers of BPs
    	double ret = 0;
    	for (unsigned k = 1; k <= K; ++k) {
    		// -- probability to have a BP in A
    		double p_A = 1 - gsl_sf_pow_int((double)P / R, k);
    		// -- probability to have a configuration of BPs which lead to an observable recombination event given that no BP is in A
    		double p_P = 0;
    
    		if (OUTPUT_DEBUG) {
    			cout << "k: " << k << endl;
    			cout << "p_A: " << p_A << endl;
    		}
    
    		// calculate p_P
    		if (p_A < 1) {
    			if (k % 2 == 1)
    				p_P = 1;   // when the number of BPs in P are odd, it always leads to an observable recombination event
    			else {
    				double p[num_PP];   // the probability that a BP is in a segment of P given that it is in P
    				for (unsigned i = 0; i < num_PP; ++i)
    					p[i] = (double)PP[i] / P;
    
    				if (OUTPUT_DEBUG) {
    					cout << "p: ";
    					for (unsigned i = 0; i < num_PP; ++i)
    						cout << p[i] << " ";
    					cout << endl;
    				}
    
    				double q = 0;   // the probability of all placements of BPs in P which will not lead to an observable recombination event
    				set<VECTOR(unsigned)> reals = gen_math::reals_multinomial(num_PP, k / 2);
    				FOREACH (VECTOR(unsigned) v, reals) {
    					unsigned n[num_PP];
    					for (unsigned i = 0; i < num_PP; ++i)
    						n[i] = v[i] * 2;
    					double r = gsl_ran_multinomial_pdf (num_PP, p, n);
    					q += r;
    					if (OUTPUT_DEBUG) {
    						cout << "n: ";
    						for (unsigned i = 0; i < num_PP; ++i)
    							cout << n[i] << " ";
    						cout << " r: " << r << endl;
    					}
    				}
    
    				p_P = 1 - q;
    			}
    		}
    
    		if (OUTPUT_DEBUG) {
    			cout << "p_P: " << p_P << endl;
    			cout << "----------------" << endl;
    		}
    
    		ret += p_R[k - 1] * (p_A + (1 - p_A) * p_P);
    	}
    
    	return ret;
    }
    

    Da dieser Ausgabecode die Lesbarkeit verringert, frage ich mich, ob man ihn bei Eclipse irgendwie ausblenden lassen kann oder ob es anderartige Lösungen für das Problem gibt.



  • Teile die Funktion in kleinere Funktionen auf, die du überblicken kannst. Teste die kleinen Funktionen einzeln und vor allem automatisiert. GTest ist dabei zum Beispiel hilfreich. Dann brauchst du kein cout zum "Debugging".


Anmelden zum Antworten