Example #1
0
void PhotoPionProduction::setPhotonField(PhotonField field) {
	photonField = field;
	if (haveRedshiftDependence) {
		std::cout << "PhotoPionProduction: tabulated redshift dependence not needed for CMB, switching off" << std::endl;
		haveRedshiftDependence = false;
	}
	std::string fname = photonFieldName(field);
	setDescription("PhotoPionProduction: " + fname);
	if (haveRedshiftDependence)
		initRate(getDataPath("PhotoPionProduction/rate_" + fname.replace(0, 3, "IRBz") + ".txt"));
	else
		initRate(getDataPath("PhotoPionProduction/rate_" + fname + ".txt"));
}
void ElectronPairProduction::setPhotonField(PhotonField photonField) {
    this->photonField = photonField;
    std::string fname = photonFieldName(photonField);
    setDescription("ElectronPairProduction: " + fname);
    initRate(getDataPath("ElectronPairProduction/lossrate_" + fname + ".txt"));
    initSpectrum(getDataPath("ElectronPairProduction/spectrum_" + fname.substr(0,3) + ".txt"));
}
void EMInverseComptonScattering::setPhotonField(PhotonField photonField) {
	this->photonField = photonField;
	switch (photonField) {
	case CMB:
		setDescription("EMInverseComptonScattering: CMB");
		initRate(getDataPath("EMInverseComptonScattering_CMB.txt"));
		initCumulativeRate(getDataPath("EMInverseComptonScattering_CDF_CMB.txt"));
		break;
	case IRB:  // default: Kneiske '04 IRB model
	case IRB_Kneiske04:
		setDescription("EMInverseComptonScattering: IRB (Kneiske 2004)");
		initRate(getDataPath("EMInverseComptonScattering_IRB_Kneiske04.txt"));
		initCumulativeRate(getDataPath("EMInverseComptonScattering_CDF_IRB_Kneiske04.txt"));
		break;
	case IRB_Stecker05:
		setDescription("EMInverseComptonScattering: IRB (Stecker 2005)");
		initRate(getDataPath("EMInverseComptonScattering_IRB_Stecker05.txt"));
		initCumulativeRate(getDataPath("EMInverseComptonScattering_CDF_IRB_Stecker05.txt"));
		break;
	case IRB_Franceschini08:
		setDescription("EMInverseComptonScattering: IRB (Franceschini 2008)");
		initRate(getDataPath("EMInverseComptonScattering_IRB_Franceschini08.txt"));
		initCumulativeRate(getDataPath("EMInverseComptonScattering_CDF_IRB_Franceschini08.txt"));
		break;
	case IRB_Finke10:
		setDescription("EMInverseComptonScattering: IRB (Finke 2010)");
		initRate(getDataPath("EMInverseComptonScattering_IRB_Finke10.txt"));
		initCumulativeRate(getDataPath("EMInverseComptonScattering_CDF_IRB_Finke10.txt"));
		break;
	case IRB_Dominguez11:
		setDescription("EMInverseComptonScattering: IRB (Dominguez 2011)");
		initRate(getDataPath("EMInverseComptonScattering_IRB_Dominguez11.txt"));
		initCumulativeRate(getDataPath("EMInverseComptonScattering_CDF_IRB_Dominguez11.txt"));
		break;
	case IRB_Gilmore12:
		setDescription("EMInverseComptonScattering: IRB (Gilmore 2012)");
		initRate(getDataPath("EMInverseComptonScattering_IRB_Gilmore12.txt"));
		initCumulativeRate(getDataPath("EMInverseComptonScattering_CDF_IRB_Gilmore12.txt"));
		break;
	case URB_Protheroe96:
		setDescription("EMInverseComptonScattering: URB (Protheroe 1996)");
		initRate(getDataPath("EMInverseComptonScattering_URB_Protheroe96.txt"));
		initCumulativeRate(getDataPath("EMInverseComptonScattering_CDF_URB_Protheroe96.txt"));
		break;
	default:
		throw std::runtime_error(
				"EMInverseComptonScattering: unknown photon background");
	}
}
static void* runThread(void *arg)
{
	rate_t loopRate;
	int ret = 0;
	
	rtSimulationThread_t *simulationThread = (rtSimulationThread_t*) arg;
	//allegro has to be initialized int thread
	//allegro creates thread -> shall inherit from this one
	ret = initAllegroComponents(simulationThread);
	if(ret != 0)
		exit(0);
		
	PRINT_INFO("SimulationThread started.\n");	
	simulationThread->running = 1;
	simulationThread->exitCode = initRate(&loopRate, SIMULATION_RATE);
	if(simulationThread->exitCode != 0) {
		PRINT_ERR("Failed to init rate (%d).\n", simulationThread->exitCode);
		simulationThread->keepRunning = 0;
	}
	
	while(simulationThread->keepRunning) {
		//EXEC RESTART_TIME_TAKING(simulationExecutionTime);
		RESTART_TIME_TAKING(simulationReactionTime);
		if(simulationThread->simulate) {
			// simulate the crash simulation for one timestep
			ret = stepSimulationThreadSafe(simulationThread);
			if(ret != 0)
				stopSimulation(simulationThread);
		}
		drawSimulationThreadSafe(simulationThread, ret);
		//EXEC STOP_TIME_TAKING(simulationExecutionTime);
		STOP_TIME_TAKING(simulationReactionTime);
		
		simulationThread->exitCode = sleepRate(&loopRate);
		if(simulationThread->exitCode != 0) {
			PRINT_ERR("Failed to sleep (%d).\n", simulationThread->exitCode);
			simulationThread->keepRunning = 0;
		}
	}
	
	destroyAllegroComponents(simulationThread);
	simulationThread->running = 0;
	PRINT_INFO("SimulationThread terminated.\n");
	pthread_exit(&simulationThread->exitCode);
}
Example #5
0
int main(int argc, char *argv[], char *envp[])
{
  register char    *pl, *pr, *p, x;
#ifdef AK
  auto     FILE    *f = fopen("/www/log/isdn.log", "r");
#else
  auto     FILE    *f = fopen("/var/log/isdn.log", "r");
#endif
  auto     char     s[BUFSIZ], sx[BUFSIZ];
  auto     int      i, l, col, day, lday = UNKNOWN, month, lmonth = UNKNOWN;
  auto     double   dur;
  auto     char    *version;
  auto     char    *myname = basename(argv[0]);
  auto     int      opt, go, s0, indent;
  auto	   time_t   now;
  auto 	   struct   tm *tm;


  if (f != (FILE *)NULL) {

    while ((opt = getopt(argc, argv, options)) != EOF)
      switch (opt) {
        case 'n' : onlynumbers++;
                   break;

        case 'v' : verbose = atoi(optarg);
                   break;

        case 'V' : print_version(myname);
                   exit(0);

        case 'i' : showincoming++;
                   break;

        case 'o' : showoutgoing++;
                   break;

        case 'e' : showerrors++;
                   break;

        case 'a' : showincoming = showoutgoing = showerrors = 1;
                   break;

        case 'N' : strcpy(onlythis, optarg);
                   break;

        case 'm' : netto++;
             	   break;

        case 'f' : force++;
             	   break;

        case 't' : onlytoday++;
             	   break;

        case 'I' : onlyInternal++;
             	   break;

        case 'E' : onlyExternal++;
             	   break;

        case '?' : printf(usage, argv[0], argv[0], options);
                   return(1);
      } /* switch */

    if (!showincoming && !showoutgoing && !showerrors) {
      printf("This makes no sense! You must specify -i, -o or -e\n");
      printf("\t-a    -> alle Verbindungen anzeigen i.e. \"-ioe\"\n");
      printf("\t      -> show all connections\n");
      printf("\t-e    -> nichtzustandegekommene Verbindungen anzeigen\n");
      printf("\t      -> show incomplete calls\n");
      printf("\t-f    -> Verbindungsentgeld _immer_ neu berechnen\n");
      printf("\t      -> recalculate costs _always_\n");
      printf("\t-i    -> reinkommende Verbindungen anzeigen\n");
      printf("\t      -> show incoming calls\n");
      printf("\t-m    -> ohne MwSt anzeigen\n");
      printf("\t      -> prices without VAT\n");
      printf("\t-n    -> _nicht_ anstelle Rufnummern Alias-Bezeichnungen anzeigen\n");
      printf("\t      -> do _not_ replace numbers with aliases\n");
      printf("\t-o    -> rausgehende Verbindungen anzeigen\n");
      printf("\t      -> show outgoing calls\n");
      printf("\t-t    -> nur die heutigen Verbindungen anzeigen\n");
      printf("\t      -> show only current connections\n");
      printf("\t-vn   -> Verbose Level\n");
      printf("\t-Nnnn -> nur Verbindungen mit _dieser_ Rufnummer anzeigen\n");
      printf("\t      -> show only calls with the specified number\n");
      printf("\t-I    -> nur Verbindungen am Internen S0-Bus anzeigen\n");
      printf("\t      -> show only calls on the internal S0 bus\n");
      printf("\t-E    -> nur Verbindungen am Externen S0-Bus anzeigen\n");
      printf("\t      -> show only calls on the external S0 bus\n");
      printf("\t-V    -> Version anzeigen\n");
      printf("\t      -> show version\n");

      return(1);
    } /* if */

    *home = 0;

    interns0 = 3;

    set_print_fct_for_tools(print_in_modules);

    if (!readconfig(myname)) {

      initHoliday(holifile, &version);

      if (verbose)
        fprintf(stderr, "%s\n", version);

      initDest(destfile, &version);

      if (verbose)
        fprintf(stderr, "%s\n", version);

      initRate(rateconf, ratefile, zonefile, &version);

      if (verbose)
        fprintf(stderr, "%s\n", version);

      memset(&msnsum, 0, sizeof(msnsum));
      memset(&provsum, 0, sizeof(provsum));
      memset(&zonesum, 0, sizeof(zonesum));

      partner[0] = (PARTNER *)calloc(knowns, sizeof(PARTNER));
      partner[1] = (PARTNER *)calloc(knowns, sizeof(PARTNER));

      time(&now);
      tm = localtime(&now);
      tm->tm_sec = tm->tm_min = tm->tm_hour = 0;
      now = mktime(tm);

      while (fgets(s, BUFSIZ, f)) {
        pl = s;
        col = 0;

        memset(&c, 0, sizeof(c));

        while ((pr = strchr(pl, '|'))) {
          memcpy(sx, pl, (l = (pr - pl)));
          sx[l] = 0;
          pl = pr + 1;

          switch (col++) {
            case  0 :                               break;

            case  1 : deb(sx);
                      strcpy(c.num[CALLING], sx);
                      break;

            case  2 : deb(sx);
                      strcpy(c.num[CALLED], sx);
                      break;

            case  3 : dur = atoi(sx);               break;

            case  4 : c.duration = atol(sx) / 100;
                      break;

            case  5 : c.connect = atol(sx);         break;
            case  6 : c.units = atoi(sx);           break;
            case  7 : c.dialout = *sx == 'O';       break;
            case  8 : c.cause = atoi(sx);           break;
            case  9 : c.ibytes = atoi(sx);          break;
            case 10 : c.obytes = atoi(sx);          break;
            case 11 : strcpy(c.version, sx);        break;
            case 12 : c.si1 = atoi(sx);             break;
            case 13 : c.si2 = atoi(sx);             break;
            case 14 : c.currency_factor = atof(sx); break;
            case 15 : strcpy(c.currency, sx);       break;
            case 16 : c.pay = atof(sx);             break;
            case 17 : c.provider = atoi(sx);        break;
            case 18 :                               break;
          } /* switch */

        } /* while */


        /* Repair wrong entries from older (or current?) isdnlog-versions ... */

        if (abs((int)dur - (int)c.duration) > 1) {
          if (verbose)
            fprintf(stderr, "REPAIR: Duration %f -> %f\n", c.duration, dur);

          c.duration = dur;
        } /* if */

        if (!memcmp(c.num[CALLED], "+4910", 5)) {
          p = c.num[CALLED] + 7;
          x = *p;
          *p = 0;

          c.provider = atoi(c.num[CALLED] + 5);

          *p = x;

          if (strlen(c.num[CALLED]) > 7)
            memmove(c.num[CALLED] + 3, c.num[CALLED] + 8, strlen(c.num[CALLED]) - 7);

          if (verbose)
            fprintf(stderr, "REPAIR: Provider=%d\n", c.provider);
        } /* if */

        if (!c.provider || (c.provider == UNKNOWN)) {
          if (verbose)
            fprintf(stderr, "REPAIR: Provider %d -> %d\n", c.provider, preselect);

          c.provider = preselect;
        } /* if */

        if (c.dialout && (strlen(c.num[CALLED]) > 3) && !getSpecial(c.num[CALLED])) {
          sprintf(s, "0%s", c.num[CALLED] + 3);

          if (getSpecial(s)) {
            if (verbose)
              fprintf(stderr, "REPAIR: Callee %s -> %s\n", c.num[CALLED], s);

            strcpy(c.num[CALLED], s);
          } /* if */
        } /* if */

        if (!c.dialout && (strlen(c.num[CALLING]) > 3) && !getSpecial(c.num[CALLING])) {
          sprintf(s, "0%s", c.num[CALLING] + 3);

          if (getSpecial(s)) {
            if (verbose)
              fprintf(stderr, "REPAIR: Caller %s -> %s\n", c.num[CALLING], s);

            strcpy(c.num[CALLING], s);
          } /* if */
        } /* if */


        go = 0;

        if (showoutgoing && c.dialout && c.duration)
          go++;

        if (showincoming && !c.dialout && c.duration)
          go++;

        if (showerrors && !c.duration)
          go++;

        if (*onlythis && strstr(c.num[CALLING], onlythis) == NULL &&
           	      	 strstr(c.num[CALLED], onlythis) == NULL)
          go = 0;

        if (onlytoday && c.connect < now)
          go = 0;

        s0 = 0; /* Externer S0 */

        if (c.dialout && (strlen(c.num[CALLING]) < interns0))
          s0 = 1; /* Interner S0-Bus */

        if (!c.dialout && (strlen(c.num[CALLED]) < interns0))
          s0 = 1; /* Interner S0-Bus */

        if (onlyInternal && !s0)
          go = 0;

        if (onlyExternal && s0)
          go = 0;


        if (go) {
          when(s, &day, &month);

          if (lmonth == UNKNOWN)
            lmonth = month;
          else if (month != lmonth) {
            total(SUBTOTAL);
            lmonth = month;
          } /* if */

          if (lday == UNKNOWN)
            lday = day;
          else if (day != lday) {
            printf("\n");
            lday = day;
          } /* else */

          printf("%s%s ", s, timestr(c.duration));

	  if (*c.num[CALLING])
            normalizeNumber(c.num[CALLING], &number[CALLING], TN_ALL);
          else {
	    memset(&number[CALLING], 0, sizeof(TELNUM));
            strcpy(number[CALLING].msn, "UNKNOWN");
          } /* else */

	  if (*c.num[CALLED])
            normalizeNumber(c.num[CALLED], &number[CALLED], TN_ALL);
          else {
	    memset(&number[CALLED], 0, sizeof(TELNUM));
            strcpy(number[CALLED].msn, "UNKNOWN");
          } /* else */

          findme();

          indent = 11 + strlen(c.currency);

          if (c.dialout) {

            findrate();

            msnsum[SUBTOTAL][c.si1][c.ihome].ncalls++;

            justify(number[CALLING].msn, c.num[CALLED], number[CALLED]);

            provsum[SUBTOTAL][c.provider].ncalls++;

            strcpy(s, getProvider(pnum2prefix(c.provider, c.connect)));
            s[PROVLEN] = 0;

            if (c.provider < 100)
              sprintf(c.sprovider, "  010%02d:%-*s", c.provider, PROVLEN, s);
            else if (c.provider < 200)
              sprintf(c.sprovider, "0100%03d:%-*s", c.provider - 100, PROVLEN, s);
            else
              sprintf(c.sprovider, "01900%02d:%-*s", c.provider - 200, PROVLEN, s);


            if (c.duration) {

#if 0 // Berechnung, um wieviel es mit AktivPlus der DTAG billiger waere -- stimmt irgendwie eh nicht mehr ...

              if ((preselect == DTAG) && ((c.zone == 1) || (c.zone == 2))) {
                auto struct tm *tm = localtime(&c.connect);
                auto int        takte;
                auto double     price;


                takte = (c.duration + 59) / 60;

                if ((tm->tm_wday > 0) && (tm->tm_wday < 5)) {   /* Wochentag */
                  if ((tm->tm_hour > 8) && (tm->tm_hour < 18))  /* Hauptzeit */
                    price = 0.06;
                  else
                    price = 0.03;
                }
                else                                            /* Wochenende */
                  price = 0.03;

                c.aktiv = takte * price;

                msnsum[SUBTOTAL][c.si1][c.ihome].aktiv += c.aktiv;
                provsum[SUBTOTAL][c.provider].aktiv += c.aktiv;
                zonesum[SUBTOTAL][c.zone].aktiv += c.aktiv;
              } /* if */
#endif

              if (c.pay < 0.0) { /* impossible! */
                c.pay = c.compute;
                c.computed++;
              } /* if */

              if (force || fabs(c.pay - c.compute) > 1.00) {
                c.pay = c.compute;
                c.computed++;
              } /* if */

              if (netto)
                c.pay = c.pay * 100.0 / 116.0;

              if (c.pay)
                printf("%12s%s ", printRate(c.pay), c.computed ? "*" : " ");
              else
                printf("%*s", indent, "");

              printf("%s%s%s", c.country, c.sprovider, c.error);

#if 0
              if (c.aktiv)
                printf(" AktivPlus - %13s", printRate(c.pay - c.aktiv));
#endif

              msnsum[SUBTOTAL][c.si1][c.ihome].pay += c.pay;
              msnsum[SUBTOTAL][c.si1][c.ihome].duration += c.duration;
              msnsum[SUBTOTAL][c.si1][c.ihome].compute += c.compute;
              msnsum[SUBTOTAL][c.si1][c.ihome].ibytes += c.ibytes;
              msnsum[SUBTOTAL][c.si1][c.ihome].obytes += c.obytes;

              provsum[SUBTOTAL][c.provider].pay += c.pay;
              provsum[SUBTOTAL][c.provider].duration += c.duration;
              provsum[SUBTOTAL][c.provider].compute += c.compute;
              provsum[SUBTOTAL][c.provider].ibytes += c.ibytes;
              provsum[SUBTOTAL][c.provider].obytes += c.obytes;

              zonesum[SUBTOTAL][c.zone].pay += c.pay;
              zonesum[SUBTOTAL][c.zone].duration += c.duration;
              zonesum[SUBTOTAL][c.zone].compute += c.compute;
              zonesum[SUBTOTAL][c.zone].ibytes += c.ibytes;
              zonesum[SUBTOTAL][c.zone].obytes += c.obytes;
            }
            else {
              printf("%*s%s%s", indent, "", c.country, c.sprovider);

              if ((c.cause != 0x1f) && /* Normal, unspecified */
                  (c.cause != 0x10))   /* Normal call clearing */
                printf(" %s", qmsg(TYPE_CAUSE, VERSION_EDSS1, c.cause));

              if ((c.cause == 0x22) || /* No circuit/channel available */
                  (c.cause == 0x2a) || /* Switching equipment congestion */
                  (c.cause == 0x2f))   /* Resource unavailable, unspecified */
                provsum[SUBTOTAL][c.provider].failed++;
            } /* else */
          }
          else { /* Dialin: */
            justify(number[CALLED].msn, c.num[CALLING], number[CALLING]);
            printf("%*s%s%s", indent, "", c.country, c.sprovider);
          } /* else */


          if (c.known[OTHER] == UNKNOWN) {
            l = UNKNOWN;

            for (i = 0; i < nunknown[c.dialout]; i++) {
              if (!strcmp(unknown[c.dialout][i].num, c.num[OTHER])) {
                l = i;
                break;
              } /* if */
            } /* for */

            if (l == UNKNOWN) {
              l = nunknown[c.dialout];

              nunknown[c.dialout]++;

              if (!l)
                unknown[c.dialout] = (PARTNER *)malloc(sizeof(PARTNER));
              else
                unknown[c.dialout] = (PARTNER *)realloc(unknown[c.dialout], sizeof(PARTNER) * nunknown[c.dialout]);

              memset(&unknown[c.dialout][l], 0, sizeof(PARTNER));
            } /* if */

            strcpy(unknown[c.dialout][l].num, c.num[OTHER]);

            unknown[c.dialout][l].ihome = c.ihome;
            unknown[c.dialout][l].ncalls++;
            unknown[c.dialout][l].pay += c.pay;
            unknown[c.dialout][l].duration += c.duration;
            unknown[c.dialout][l].compute += c.compute;
            unknown[c.dialout][l].ibytes += c.ibytes;
            unknown[c.dialout][l].obytes += c.obytes;
          }
          else {
            strcpy(partner[c.dialout][c.known[OTHER]].num, c.num[OTHER]);
            partner[c.dialout][c.known[OTHER]].ncalls++;
            partner[c.dialout][c.known[OTHER]].pay += c.pay;
            partner[c.dialout][c.known[OTHER]].duration += c.duration;
            partner[c.dialout][c.known[OTHER]].compute += c.compute;
            partner[c.dialout][c.known[OTHER]].ibytes += c.ibytes;
            partner[c.dialout][c.known[OTHER]].obytes += c.obytes;
          } /* else */

          printf("\n");

        } /* if */
      } /* while */

      fclose(f);
      total(SUBTOTAL);

      if (!onlytoday)
        total(TOTAL);

      showpartner();

    }
    else
      fprintf(stderr, "%s: Can't read configuration file(s)\n", myname);
  }
  else
    fprintf(stderr, "%s: Can't open \"isdn.log\" file\n", myname);

  return(0);
} /* isdnbill */
Example #6
0
public:
	void calculate() { amount += amount * interestRate; }	
	static double rate() { return interestRate; }
	static void rate(double);

private:
	std::string owner;
	double amount;
	static double interestRate;
	static double initRate();
};

void Accout::rate(double rate)
{
	interestRate = rate;
}

double Accout::initRate()
{
	return 2.3;
}

double Accout::interestRate = initRate();

int main() 
{
	std::cout << Accout::rate() << std::endl;
	Accout::rate(3.2);
	std::cout << Accout::rate() << std::endl;
}