Esempio n. 1
0
void
be_setup(int scope)
{
    *main_code_p = active_code;

    if (scope == SCOPE_BEGIN) {
	if (!begin_code_p)
	    begin_code_p = new_code();
	active_code = *begin_code_p;
    } else {
	if (!end_code_p)
	    end_code_p = new_code();
	active_code = *end_code_p;
    }
}
Esempio n. 2
0
Stock StockManager::addTempCsvStock(
        const string& code,
        const string& day_filename,
        const string& min_filename,
        price_t tick,
        price_t tickValue,
        int precision,
        size_t minTradeNumber,
        size_t maxTradeNumber) {
    string new_code(code);
    boost::to_upper(new_code);
    Stock result("TMP", new_code, day_filename, STOCKTYPE_TMP, true,
            Datetime(199901010000), Null<Datetime>(),
            tick, tickValue, precision, minTradeNumber, maxTradeNumber);

    KDataTempCsvDriver *p = new KDataTempCsvDriver(day_filename, min_filename);
    result.setKDataDriver(KDataDriverPtr(p));
    result.loadKDataToBuffer(KQuery::DAY);
    result.loadKDataToBuffer(KQuery::MIN);

    if (!addStock(result)){
        //加入失败,返回Null<Stock>
        return Null<Stock>();
    }

    return result;
}
Esempio n. 3
0
void
code_init(void)
{
    main_code_p = new_code();

    active_code = *main_code_p;
    code1(_OMAIN);
}
Esempio n. 4
0
/* 遍历子树建立符号编码表 */
static void build_symcode(node *root, symcode *sc)
{
    if (root == NULL)
        return;
    if (root->leaf)
        (*sc)[root->symbol] = new_code(root);
    else {
        build_symcode(root->zero, sc);
        build_symcode(root->one, sc);
    }
}
Esempio n. 5
0
/*
 * build_symbol_encoder builds a SymbolEncoder by walking
 * down to the leaves of the Huffman tree and then,
 * for each leaf, determines its code.
 */
static void
build_symbol_encoder(huffman_node *subtree, SymbolEncoder *pSF)
{
    if(subtree == NULL)
        return;

    if(subtree->isLeaf)
        (*pSF)[subtree->symbol] = new_code(subtree);
    else
    {
        build_symbol_encoder(subtree->zero, pSF);
        build_symbol_encoder(subtree->one, pSF);
    }
}
Esempio n. 6
0
File: latim.c Progetto: tolmalev/SPM
int main (int argc, char *argv[]) {

	struct params par = PAR_DEFAULT;

	int j, js, fd;
	int n_read;
	int spurious_count=0;
	struct timespec very_first, very_last;
	struct event *time_buf, *time_list, *event;
        struct event *big_time_buf=NULL, origin;
	int side, size;
	int *i_differ, *e_delay=NULL, *i_delay;
	int delta_e;
	int status;
	int count=0, first;
	float sigma, quantum;
	FILE * logfile=NULL, * listfile=NULL;
	FILE * plot=NULL;
	char buff[BUFLEN];
	double *tevi=NULL, delta;
	double cf[2];
	double average;
	int total_time;
	int block_size, full_size;
	int bin_size;

	parse_options (argc, argv, &par);

	if (par.p & MRC_PM) {
		bin_size = (par.n + BINS - 1) / BINS;
		if (par.v) printf ("Bin size is: %d\n", bin_size);
	}
	if (!par.e && par.p & LAT_PM) {
		printf ("The latency distribution will not be computed if"
			" the external clock is not specified [-e]\n");
		par.p &= ~LAT_PM;
	}

	quantum = par.g * par.c;     /* usec/channel in time distributions */

	/* start auxiliary services: gnuplot */

	if (par.p) {
		plot = popen("/usr/bin/gnuplot -noraise -persist -geometry "
			     "1024x512", "w");
		if (plot == NULL) {
			printf ("Start of graphical display failed!\n");
			exit (-1);
		} else {
			if (par.v) printf (
				"Time distributions will be plotted\n");
			fprintf (plot, "set grid; set term X11\n");
		}
	}

	/* open time device and log files */

	if (par.i == NULL) par.i = "/dev/latim";
	if (strcmp(par.i, "-") == 0) {         /* data from standard input */
		fd = 0;
	} else {
		fd = open (par.i, O_RDONLY);
		if (fd == -1) {
			printf ("Failed while opening time device '%s'\n",
				par.i);
			perror ("");
			exit (-1);
		}
	}

	if (!par.f) par.f = new_code();
	logfile = fopen(par.f, "w");
	if (!logfile) {
		perror ("Failed while opening log file");
		exit (-1);
	}
	printf ("Log to file %s\n", par.f);

	if (par.L) {
		strcpy (par.f+strlen(par.f)-3, "lst");
		listfile = fopen (par.f, "w");
		if (!listfile) {
			perror ("Failed while opening list file");
			exit (-1);
		}
		printf ("Time list to file %s\n", par.f);
	}

	/* save the full command line to log file */

	fprintf (logfile, "# ");
	for ( j=0 ; j<argc ; j++) {
		fprintf (logfile, "%s ", *(argv+j));
		if (par.v) printf ("%s ", *(argv+j));
	}
	fprintf (logfile, "\n\n");
	if (par.v) printf ("\n");
	    
	/* get memory for buffers */

	block_size = par.n * SLOT;
	full_size = (par.U ? par.N : 1) * block_size;

	big_time_buf = malloc (full_size+SLOT);
	time_buf = big_time_buf;
	if (!time_buf) {
		perror ("malloc failed with time_buf");
		exit (-1);
	}

	if (par.v) printf ("Allocated time buffer %d bytes wide at %p\n",
			   (int) (full_size+SLOT), big_time_buf);

	time_list = time_buf + 1;

	tevi = malloc (par.n * sizeof(double));
	if (!tevi) {
		perror ("malloc failed with tevi");
		goto bad_exit;
	}
	if (par.v) printf ("Allocated count buffer %d bytes wide at %p\n",
			   (int) (par.n * sizeof(*tevi)), tevi);

	side = par.m/par.c + 1.0;
	size = 2*side + 1;

	e_delay = calloc (3*size, sizeof(int));
	if (!e_delay) {
		perror ("malloc failed with e_delay");
		goto bad_exit;
	}
	if (par.v) printf ("Allocated distribution buffer %d bytes wide "
			   "at %p\n", (int) (3*size*sizeof(int)), e_delay);
	i_differ = e_delay + size;
	i_delay = i_differ + size;

	/*
	 *   enter the main loop
	 */

	n_read = read (fd, (void *) time_buf, SLOT);
	if (n_read != SLOT) {
		printf ("reading of time origin failed with %d\n", n_read);
		goto bad_exit;
	}

	origin = *time_buf;
	count = 0;
	while (!par.N || count < par.N) {

		n_read = 0;
		while (n_read < block_size) {
			status = read (fd, (void *) time_list +
				       n_read, block_size - n_read);
			if (status == 0) break;
			if (status < 0) {
				perror ("read operation failed");
				goto bad_exit;
			}
			n_read += status;
		}
		if (status == 0) {
			printf ("Undue EOF after %d bytes\n", n_read);
			goto bad_exit;
		}

		if (n_read != block_size) {
			printf("read operation failed with return %d\n",
			       n_read);
			perror ("reason");
			goto bad_exit;
		}
    
		first = count * par.n;

		/*
		 *    issue a complete list of all events:
                 *    -l  list to console
                 *    -L  list to file
		 */

                list_events (&par, listfile, time_list, first, &origin);

		/*     Analyze buffer for spurious events.
		 *     An event is spurious when the measured latency exceeds
		 *     the given threshold (-m).
		 */

                if (check_events (&par, time_list, logfile, count,
                                  &spurious_count, first, &origin) == -1)
                  goto bad_exit;
                
		printf ("events/err.: %9d / %d", first+par.n, spurious_count);

		/*
		 *    histograms:
		 *
		 *    i_differ: distribution of internal clock differences
		 *    e_delay:  distribution of external counter delays
		 *    i_delay:  distribution of internal clock delays
		 *
		 */

		/* build i_differ and e_delay time distributions */

		for ( j=0 ; j<par.n ; j++ ) {
			event = time_list+j;
			delta = (us_diff(&event->timic, &(event-1)->timic) -
                                 par.t) / quantum;
			if (delta < -side) delta = -side;
			else if (delta > side) delta = side;
			i_differ[(int) (delta + side)] += 1;
//			tevi[j] = us_diff(&event->timic, &origin.timic);
			tevi[j] = us_diff(&event->timic, &time_list->timic);
			if (par.e) {
				delta_e = diff_e(event) / par.g;
				if (delta_e > size) delta_e = size;
				e_delay[delta_e] += 1;
			}
		}

		/* compute clock rate and build 'i_delay' histogram */

		fit1 (tevi, par.n, cf);
		printf ("      clock rate: %9.3f  %8.3f\n", cf[0], cf[1]+200);

		for ( j=0 ; j<par.n ; j++ ) {
			tevi[j] -= (cf[0]*(j+1) + cf[1]);
			if (tevi[j] < -par.m) tevi[j] = -par.m;
			if (tevi[j] >= par.m) tevi[j] = par.m;
			delta = tevi[j] / (par.g * par.c);
			i_delay[(int) (delta+side)] += 1;
		}

		/* plots */

                plot_histograms
                  (&par, plot, i_differ, i_delay, e_delay, tevi, time_list);

                /*
                 * close the main loop
                 */

		if (!count) very_first = time_buf->timic;
		very_last = (time_buf + par.n)->timic;
		if (par.U) {
			time_buf += par.n;
			time_list = time_buf + 1;
		} else {
			*time_buf = *(time_buf + par.n);
		}
		count++;
	}

	/* print final logs */

	if ((par.L || par.l) && par.U) {
		for ( j=0 ; j<par.n*par.N ; j++ ) {
			event = big_time_buf+j+1;
			delta = us_diff (&event->timic, &(event-1)->timic);
			sprintf (buff, "%8d  %12ld.%09ld  %10d  %8.2f %6.2f",
                                 j, event->timic.tv_sec, event->timic.tv_nsec,
				 tm_diff(&event->timic, &origin.timic),
				 delta, delta - par.t);
			if (par.e) {
				delta_e = diff_e(event);
				sprintf (buff+strlen(buff), "    %4d  %4d",
					 event->timec, delta_e);
			}
			sprintf (buff+strlen(buff), "\n");
			if (par.l) printf (buff);
			if (par.L) fprintf (listfile, buff);
		}
	}

	/* print final time distributions */

	if (par.S) {                                        /* i_differ */
		printf ("\nTime distribution from internal clock\n");
		print_distrib (i_differ, size, logfile, side, quantum);

		if (par.e) {                                 /* e_delay */
			printf ("\nTime distribution from external clock\n");
			fprintf (logfile, "\n\n");
			print_distrib (e_delay, size, logfile, 0, quantum);
		}

		printf ("\nTime distribution of delays from internal clock\n");
		fprintf (logfile, "\n\n");                       /* delay */
		print_distrib (i_delay, size, logfile, side, quantum);
	}

	/* time distribution average and width */

	if (par.s || par.S) {

		sigma = 0.;
		average = 0.;

		for ( js=-side ; js<=side ; js++ )
                  average += i_differ[js+side] * js;

		average /= (par.n * par.N)/quantum;

		for ( js=-side ; js<=side ; js++ )
                  sigma += i_differ[js+side] * (js-average) * (js-average);

		sprintf (buff, "par.t: %d   <T>: %f   Sigma: %f\n", par.t,
			 average, quantum*sqrt(sigma/(par.n * par.N - 1)));

		printf ("\n%s", buff);
		fprintf (logfile, "\n# %s", buff); 
	}

	total_time = tm_diff(&very_last, &very_first);
	sprintf (buff, "Total time: %d   skew: %d\n",
		 total_time, total_time -
		 par.n * par.N * par.t);
	printf (buff);
	fprintf (logfile, "# %s", buff);

	if (listfile) fclose (listfile);
	if (logfile) fclose (logfile);

	if (par.v) printf ("Cleaning buffers at %p %p %p\n",
			   big_time_buf, tevi, e_delay);
	free (big_time_buf);
	free (tevi);
	free (e_delay);

	return 0;

 bad_exit:
	if (logfile) fclose (logfile);
	if (listfile) fclose (listfile);
	free (big_time_buf);
	free (tevi);
	free (e_delay);
	return -1;
}
Esempio n. 7
0
void c_typecheck_baset::typecheck_decl(codet &code)
{
  // this comes with 1 operand, which is a declaration
  if(code.operands().size()!=1)
  {
    err_location(code);
    error() << "decl expected to have 1 operand" << eom;
    throw 0;
  }

  // op0 must be declaration
  if(code.op0().id()!=ID_declaration)
  {
    err_location(code);
    error() << "decl statement expected to have declaration as operand"
            << eom;
    throw 0;
  }

  ansi_c_declarationt declaration;
  declaration.swap(code.op0());

  if(declaration.get_is_static_assert())
  {
    assert(declaration.operands().size()==2);
    codet new_code(ID_static_assert);
    new_code.add_source_location()=code.source_location();
    new_code.operands().swap(declaration.operands());
    code.swap(new_code);
    typecheck_code(code);
    return; // done
  }

  typecheck_declaration(declaration);

  std::list<codet> new_code;

  // iterate over declarators

  for(ansi_c_declarationt::declaratorst::const_iterator
      d_it=declaration.declarators().begin();
      d_it!=declaration.declarators().end();
      d_it++)
  {
    irep_idt identifier=d_it->get_name();

    // look it up
    symbol_tablet::symbolst::iterator s_it=
      symbol_table.symbols.find(identifier);

    if(s_it==symbol_table.symbols.end())
    {
      err_location(code);
      error() << "failed to find decl symbol `" << identifier
              << "' in symbol table" << eom;
      throw 0;
    }

    symbolt &symbol=s_it->second;

    // This must not be an incomplete type, unless it's 'extern'
    // or a typedef.
    if(!symbol.is_type &&
       !symbol.is_extern &&
       !is_complete_type(symbol.type))
    {
      error().source_location=symbol.location;
      error() << "incomplete type not permitted here" << eom;
      throw 0;
    }

    // see if it's a typedef
    // or a function
    // or static
    if(symbol.is_type ||
       symbol.type.id()==ID_code ||
       symbol.is_static_lifetime)
    {
      // we ignore
    }
    else
    {
      code_declt code;
      code.add_source_location()=symbol.location;
      code.symbol()=symbol.symbol_expr();
      code.symbol().add_source_location()=symbol.location;

      // add initializer, if any
      if(symbol.value.is_not_nil())
      {
        code.operands().resize(2);
        code.op1()=symbol.value;
      }

      new_code.push_back(code);
    }
  }

  // stash away any side-effects in the declaration
  new_code.splice(new_code.begin(), clean_code);

  if(new_code.empty())
  {
    source_locationt source_location=code.source_location();
    code=code_skipt();
    code.add_source_location()=source_location;
  }
  else if(new_code.size()==1)
  {
    code.swap(new_code.front());
  }
  else
  {
    // build a decl-block
    code_blockt code_block(new_code);
    code_block.set_statement(ID_decl_block);
    code.swap(code_block);
  }
}
Esempio n. 8
0
void cpp_typecheckt::convert_anonymous_union(
  cpp_declarationt &declaration,
  codet &code)
{
  codet new_code(ID_decl_block);
  new_code.reserve_operands(declaration.declarators().size());

  // unnamed object
  std::string identifier="#anon_union"+i2string(anon_counter++);

  irept name(ID_name);
  name.set(ID_identifier, identifier);
  name.set(ID_C_source_location, declaration.source_location());

  cpp_namet cpp_name;
  cpp_name.move_to_sub(name);
  cpp_declaratort declarator;
  declarator.name()=cpp_name;

  cpp_declarator_convertert cpp_declarator_converter(*this);

  const symbolt &symbol=
    cpp_declarator_converter.convert(declaration, declarator);

  if(!cpp_is_pod(declaration.type()))
  {
   error().source_location=follow(declaration.type()).source_location();
   error() << "anonymous union is not POD" << eom;
   throw 0;
  }

  codet decl_statement(ID_decl);
  decl_statement.reserve_operands(2);
  decl_statement.copy_to_operands(cpp_symbol_expr(symbol));

  new_code.move_to_operands(decl_statement);

  // do scoping
  symbolt union_symbol=symbol_table.symbols[follow(symbol.type).get(ID_name)];
  const irept::subt &components=union_symbol.type.add(ID_components).get_sub();

  forall_irep(it, components)
  {
    if(it->find(ID_type).id()==ID_code)
    {
      error().source_location=union_symbol.type.source_location();
      error() << "anonymous union `" << union_symbol.base_name
              << "' shall not have function members" << eom;
      throw 0;
    }

    const irep_idt &base_name=it->get(ID_base_name);

    if(cpp_scopes.current_scope().contains(base_name))
    {
      error().source_location=union_symbol.type.source_location();
      error() << "identifier `" << base_name << "' already in scope"
              << eom;
      throw 0;
    }

    cpp_idt &id=cpp_scopes.current_scope().insert(base_name);
    id.id_class = cpp_idt::SYMBOL;
    id.identifier=it->get(ID_name);
    id.class_identifier=union_symbol.name;
    id.is_member=true;
  }

  symbol_table.symbols[union_symbol.name].type.set(
    "#unnamed_object", symbol.base_name);

  code.swap(new_code);
}
Esempio n. 9
0
codet cpp_typecheckt::cpp_constructor(
  const source_locationt &source_location,
  const exprt &object,
  const exprt::operandst &operands)
{
  exprt object_tc=object;

  typecheck_expr(object_tc);

  elaborate_class_template(object_tc.type());

  typet tmp_type(object_tc.type());
  follow_symbol(tmp_type);

  assert(!is_reference(tmp_type));

  if(tmp_type.id()==ID_array)
  {
    // We allow only one operand and it must be tagged with '#array_ini'.
    // Note that the operand is an array that is used for copy-initialization.
    // In the general case, a program is not allow to use this form of
    // construct. This way of initializing an array is used internaly only.
    // The purpose of the tag #arra_ini is to rule out ill-formed
    // programs.

    if(!operands.empty() && !operands.front().get_bool("#array_ini"))
    {
      error().source_location=source_location;
      error() << "bad array initializer" << eom;
      throw 0;
    }

    assert(operands.empty() || operands.size()==1);

    if(operands.empty() && cpp_is_pod(tmp_type))
    {
      codet nil;
      nil.make_nil();
      return nil;
    }

    const exprt &size_expr=
      to_array_type(tmp_type).size();

    if(size_expr.id()=="infinity")
    {
      // don't initialize
      codet nil;
      nil.make_nil();
      return nil;
    }

    exprt tmp_size=size_expr;
    make_constant_index(tmp_size);

    mp_integer s;
    if(to_integer(tmp_size, s))
    {
      error().source_location=source_location;
      error() << "array size `" << to_string(size_expr)
              << "' is not a constant" << eom;
      throw 0;
    }

    /*if(cpp_is_pod(tmp_type))
    {
      code_expressiont new_code;
      exprt op_tc=operands.front();
      typecheck_expr(op_tc);
       // Override constantness
      object_tc.type().set("#constant", false);
      object_tc.set("#lvalue", true);
      side_effect_exprt assign("assign");
      assign.add_source_location()=source_location;
      assign.copy_to_operands(object_tc, op_tc);
      typecheck_side_effect_assignment(assign);
      new_code.expression()=assign;
      return new_code;
    }
    else*/
    {
      codet new_code(ID_block);

      // for each element of the array, call the default constructor
      for(mp_integer i=0; i < s; ++i)
      {
        exprt::operandst tmp_operands;

        exprt constant=from_integer(i, index_type());
        constant.add_source_location()=source_location;

        exprt index(ID_index);
        index.copy_to_operands(object);
        index.copy_to_operands(constant);
        index.add_source_location()=source_location;

        if(!operands.empty())
        {
          exprt operand(ID_index);
          operand.copy_to_operands(operands.front());
          operand.copy_to_operands(constant);
          operand.add_source_location()=source_location;
          tmp_operands.push_back(operand);
        }

        exprt i_code =
          cpp_constructor(source_location, index, tmp_operands);

        if(i_code.is_nil())
        {
          new_code.is_nil();
          break;
        }

        new_code.move_to_operands(i_code);
      }
      return new_code;
    }
  }
  else if(cpp_is_pod(tmp_type))
  {
    code_expressiont new_code;
    exprt::operandst operands_tc=operands;

    for(exprt::operandst::iterator
      it=operands_tc.begin();
      it!=operands_tc.end();
      it++)
    {
      typecheck_expr(*it);
      add_implicit_dereference(*it);
    }

    if(operands_tc.empty())
    {
      // a POD is NOT initialized
      new_code.make_nil();
    }
    else if(operands_tc.size()==1)
    {
      // Override constantness
      object_tc.type().set(ID_C_constant, false);
      object_tc.set(ID_C_lvalue, true);
      side_effect_exprt assign(ID_assign);
      assign.add_source_location()=source_location;
      assign.copy_to_operands(object_tc, operands_tc.front());
      typecheck_side_effect_assignment(assign);
      new_code.expression()=assign;
    }
    else
    {
      error().source_location=source_location;
      error() << "initialization of POD requires one argument, "
                 "but got " << operands.size() << eom;
      throw 0;
    }

    return new_code;
  }
  else if(tmp_type.id()==ID_union)
  {
    assert(0); // Todo: union
  }
  else if(tmp_type.id()==ID_struct)
  {
    exprt::operandst operands_tc=operands;

    for(exprt::operandst::iterator
      it=operands_tc.begin();
      it!=operands_tc.end();
      it++)
    {
      typecheck_expr(*it);
      add_implicit_dereference(*it);
    }

    const struct_typet &struct_type=
      to_struct_type(tmp_type);

    // set most-derived bits
    codet block(ID_block);
    for(std::size_t i=0; i < struct_type.components().size(); i++)
    {
      const irept &component=struct_type.components()[i];
      if(component.get(ID_base_name)!="@most_derived")
        continue;

      exprt member(ID_member, bool_typet());
      member.set(ID_component_name, component.get(ID_name));
      member.copy_to_operands(object_tc);
      member.add_source_location()=source_location;
      member.set(ID_C_lvalue, object_tc.get_bool(ID_C_lvalue));

      exprt val=false_exprt();

      if(!component.get_bool("from_base"))
        val=true_exprt();

      side_effect_exprt assign(ID_assign);
      assign.add_source_location()=source_location;
      assign.move_to_operands(member, val);
      typecheck_side_effect_assignment(assign);
      code_expressiont code_exp;
      code_exp.expression()=assign;
      block.move_to_operands(code_exp);
    }

    // enter struct scope
    cpp_save_scopet save_scope(cpp_scopes);
    cpp_scopes.set_scope(struct_type.get(ID_name));

    // find name of constructor
    const struct_typet::componentst &components=
      struct_type.components();

    irep_idt constructor_name;

    for(struct_typet::componentst::const_iterator
        it=components.begin();
        it!=components.end();
        it++)
    {
      const typet &type=it->type();

      if(!it->get_bool(ID_from_base) &&
         type.id()==ID_code &&
         type.find(ID_return_type).id()==ID_constructor)
      {
        constructor_name=it->get(ID_base_name);
        break;
      }
    }

    // there is always a constructor for non-PODs
    assert(constructor_name!="");

    irept cpp_name(ID_cpp_name);
    cpp_name.get_sub().push_back(irept(ID_name));
    cpp_name.get_sub().back().set(ID_identifier, constructor_name);
    cpp_name.get_sub().back().set(ID_C_source_location, source_location);

    side_effect_expr_function_callt function_call;
    function_call.add_source_location()=source_location;
    function_call.function().swap(static_cast<exprt&>(cpp_name));
    function_call.arguments().reserve(operands_tc.size());

    for(exprt::operandst::iterator
        it=operands_tc.begin();
        it!=operands_tc.end();
        it++)
      function_call.op1().copy_to_operands(*it);

    typecheck_side_effect_function_call(function_call);
    assert(function_call.get(ID_statement)==ID_temporary_object);

    exprt &initializer =
      static_cast<exprt &>(function_call.add(ID_initializer));

    assert(initializer.id()==ID_code &&
           initializer.get(ID_statement)==ID_expression);

    side_effect_expr_function_callt &func_ini=
      to_side_effect_expr_function_call(initializer.op0());

    exprt &tmp_this=func_ini.arguments().front();
    assert(tmp_this.id()==ID_address_of
           && tmp_this.op0().id()=="new_object");

    exprt address_of(ID_address_of, typet(ID_pointer));
    address_of.type().subtype()=object_tc.type();
    address_of.copy_to_operands(object_tc);
    tmp_this.swap(address_of);

    if(block.operands().empty())
      return to_code(initializer);
    else
    {
      block.move_to_operands(initializer);
      return block;
    }
  }
  else
    assert(false);

  codet nil;
  nil.make_nil();
  return nil;
}
Esempio n. 10
0
static double aRate(double X, int everage,int Fast, float ** wPrc)
{
  double Sum=0.;
  int i,l1,l2;
  int nPrc=0;
  char* pname[5];
  gridStr grid,grid1;
  double MassCutOut=MassCut+M*log(100.)/X;
  double Msmall,Mlarge;

  int nPrcTot=0;

  if(MassCutOut<M*(2+10/X)) MassCutOut=M*(2+10/X); 

  xf_=X;
  exi=everage;

  if(wPrc) *wPrc=NULL;

  for(l1=0;l1<NC;l1++)
  { int k1=sort[l1]; if(M+inMass[k1]>MassCut) break;
  for(l2=0;l2<NC;l2++)
  {
    double Sumkk=0.;
    double x[2],f[2];
    double factor;
    int k2=sort[l2];
    CalcHEP_interface * CI;

    if(inMass[k1]+inMass[k2] > MassCut) break;

    if(inC[k1*NC+k2]<=0) continue;
    if(code22[k1*NC+k2]==NULL) new_code(k1,k2);
    if(inC[k1*NC+k2]<=0) continue;


    if(!code22[k1*NC+k2]->init)
    { numout * cd=code22[k1*NC+k2];
      CalcHEP_interface *cdi=cd->interface;
      for(i=1;i<=cdi->nvar;i++) if(cd->link[i]) cdi->va[i]=*(cd->link[i]);
      
      if( cdi->calcFunc()>0 ) {FError=1; return -1;}
      cd->init=1;
    }

    if(wPrc)
    {  nPrcTot+=code22[k1*NC+k2]->interface->nprc;
       *wPrc=(float*)realloc(*wPrc,sizeof(float)*(nPrcTot));
    }

    sqme=code22[k1*NC+k2]->interface->sqme;
    DeltaXf=(inDelta[k1]+inDelta[k2])*X;
    inBuff=0;

    M1=inMass[k1];
    M2=inMass[k2];

    Msmall=M1>M2? M1-M*(1-sWidth): M2-M*(1-sWidth);
    Mlarge=M1>M2? M2+M*(1-sWidth): M1+M*(1-sWidth);

    u_max=m2u(MassCutOut);
    if(Fast)
    { 
      if(Fast==1)
      {  double c[4];

         for(Npow=0;Npow<4;Npow++) c[Npow]=simpson(s_pow_integrand, 0. ,1. ,1.E-4);
         gaussC2(c,x,f);
         for(i=0;i<2;i++){ x[i]=sqrt(x[i]); f[i]*=2*x[i]/M;}
      }else 
      {
         double c[2];
         for(Npow=0;Npow<2;Npow++) c[Npow]=simpson(s_pow_integrand, 0. ,1. ,1.E-4);
         x[0]= sqrt(c[1]/c[0]);
         f[0]= c[0]*2*x[0]/M;
      }
    }
    factor=inC[k1*NC+k2]*inG[k1]*inG[k2]*exp(-DeltaXf);
    CI=code22[k1*NC+k2]->interface;
    for(nsub=1; nsub<= CI->nprc;nsub++,nPrc++)
    { double u_min=0.;
      double a=0;

      if(wPrc) (*wPrc)[nPrc]=0;

      for(i=0;i<4;i++)  pname[i]=CI->pinf(nsub,i+1,pmass+i,NULL);
      if(pmass[2]+pmass[3]>MassCutOut) continue;

      if( (pmass[2]>Mlarge && pmass[3]<Msmall)
        ||(pmass[3]>Mlarge && pmass[2]<Msmall))
           { *(CI->twidth)=1; *(CI->gtwidth)=1;}
      else { *(CI->twidth)=0; *(CI->gtwidth)=0;}
      *(CI->gswidth)=0;
                             
      if(pmass[2]+pmass[3] > pmass[0]+pmass[1])
      { double smin=pmass[2]+pmass[3];
        if((pmass[0]!=M1 || pmass[1]!=M2)&&(pmass[0]!=M2 || pmass[1]!=M1))
        { double ms=pmass[0]+pmass[1];
          double md=pmass[0]-pmass[1];
          double Pcm=sqrt((smin-ms)*(smin+ms)*(smin-md)*(smin+md))/(2*smin);
          smin=sqrt(M1*M1+Pcm*Pcm)+sqrt(M2*M2+Pcm*Pcm);
        }
        u_min=m2u(smin); 
      }else  u_min=0;
      
repeat:
      neg_cs_flag=0;
      if(!Fast) a=simpson(s_integrand,u_min,1.,eps); 
      else if(Fast!=1) a=f[0]*sigma(x[0]); else
      {
          int isPole=0;
          char * s;
          int m,w,n;
          double mass,width;

          for(n=1;(s=code22[k1*NC+k2]->interface->den_info(nsub,n,&m,&w));n++)
          if(m && w && strcmp(s,"\1\2")==0 )
          { mass=code22[k1*NC+k2]->interface->va[m];
            width=code22[k1*NC+k2]->interface->va[w];
            if(mass<MassCutOut && mass+8*width > pmass[0]+pmass[1]
                            && mass+8*width > pmass[2]+pmass[3])
            { if((pmass[0]!=M1 || pmass[1]!=M2)&&(pmass[0]!=M2 || pmass[1]!=M1))
              { double ms=pmass[0]+pmass[1];
                double md=pmass[0]-pmass[1];
                double Pcm=sqrt((mass-ms)*(mass+ms)*(mass-md)*(mass+md))/(2*mass);
                mass=sqrt(M1*M1+Pcm*Pcm)+sqrt(M2*M2+Pcm*Pcm);
              }
              grid1=makeGrid(mass,width);
              if(isPole) grid=crossGrids(&grid,&grid1); else grid=grid1;
              isPole++;
            }
          }
          if(isPole==0)
          {  grid.n=1;
             grid.ul[0]=u_min;
             grid.ur[0]=u_max;
             grid.pow[0]=3;
          }

          if(grid.n==1 && pmass[0]+pmass[1]> 1.1*(pmass[2]+pmass[3]))
                a=f[0]*sigma(x[0])+f[1]*sigma(x[1]);
          else for(i=0;i<grid.n;i++)if(u_min<=grid.ur[i])
          {  
             double ul= u_min<grid.ul[i]? grid.ul[i]:u_min;
             double da=gauss(s_integrand,ul,grid.ur[i],grid.pow[i]);
             a+=da;             
          }
      }
      if(neg_cs_flag && *(CI->gswidth)==0)
      { *(CI->gswidth)=1;
         goto  repeat;
      }   
/* 
printf("X=%.2E (%d) %.3E %s %s %s %s\n",X,everage, a, pname[0],pname[1],pname[2],pname[3]);
*/
      Sumkk+=a;
      if(wPrc) (*wPrc)[nPrc] = a*factor;
    }
    Sum+=factor*Sumkk;
/*
printf("Sum=%E\n",Sum);
*/
  }
  }
  if(wPrc) for(i=0; i<nPrc;i++)  (*wPrc)[i]/=Sum;
  if(!everage) { double gf=geff(X);  Sum/=gf*gf;}
/*
exit(1);
*/
  return Sum;
}
Esempio n. 11
0
static int testSubprocesses(void)
{
 static int first=1;
 int err,k1,k2,i,j;
 double *Q;

 if(first)
 {
    first=0;
    
    for(i=0,NC=0;i<Nodd;i++,NC++) 
        if(strcmp(OddPrtcls[i].name,OddPrtcls[i].aname))NC++;
        
    inP=(char**)malloc(NC*sizeof(char*));
    inAP=(int*)malloc(NC*sizeof(int));
    inG=(int*)malloc(NC*sizeof(int));
    inDelta=(double*)malloc(NC*sizeof(double)); 
    inG_=(double*)malloc(NC*sizeof(double));
    inMassAddress=(double**)malloc(NC*sizeof(double*));
    inMass=(double*)malloc(NC*sizeof(double));
    inNum= (int*)malloc(NC*sizeof(int));
    sort=(int*)malloc(NC*sizeof(int));

    code22=(numout**)malloc(NC*NC*sizeof(numout*));
    inC=(int*)malloc(NC*NC*sizeof(int)); 

      
    for(i=0,j=0;i<Nodd;i++)
    {  
       inP[j]=OddPrtcls[i].name;
       inNum[j]=OddPrtcls[i].NPDG;
       inG[j]=(OddPrtcls[i].spin2+1)*OddPrtcls[i].cdim;
       if(strcmp(OddPrtcls[i].name,OddPrtcls[i].aname))
       {
         inAP[j]=j+1;
         j++;
         inP[j]=OddPrtcls[i].aname;
         inG[j]=inG[j-1];
         inAP[j]=j-1;
         inNum[j]=-OddPrtcls[i].NPDG;
       } else inAP[j]=j;
       j++;
    }

    for(i=0;i<NC;i++) sort[i]=i;
    for(k1=0;k1<NC;k1++) for(k2=0;k2<NC;k2++) inC[k1*NC+k2]=-1;
    for(k1=0;k1<NC;k1++) for(k2=0;k2<NC;k2++) if(inC[k1*NC+k2]==-1)
    {  int kk1=inAP[k1];
       int kk2=inAP[k2];
       inC[k1*NC+k2]=1;
       if(inC[k2*NC+k1]==-1)   {inC[k2*NC+k1]=0;   inC[k1*NC+k2]++;}
       if(inC[kk1*NC+kk2]==-1) {inC[kk1*NC+kk2]=0; inC[k1*NC+k2]++;}
       if(inC[kk2*NC+kk1]==-1) {inC[kk2*NC+kk1]=0; inC[k1*NC+k2]++;}
    }

    for(k1=0;k1<NC;k1++) for(k2=0;k2<NC;k2++) code22[k1*NC+k2]=NULL;
    mainChan=NULL;
    if(strcmp(OddPrtcls[0].name,OddPrtcls[0].aname)==0)
         { new_code(0,0); mainChan=code22[0*NC+0];} 
    else { new_code(0,1); mainChan=code22[0*NC+1];}

    if(!mainChan){printf("Can not compile generate and load code for "
      "annihilation  channel %s %s->2*x\n Program stops.\n", 
         OddPrtcls[0].name,OddPrtcls[0].aname); exit(44);}
        
    for(i=0,j=0;i<Nodd;i++)
    {
       inMassAddress[j]=paramAddress(OddPrtcls[i].mass);
       if(!inMassAddress[j]) 
       { printf(" Can not find mass  %s among parameetrs\n",OddPrtcls[i].mass);
         exit(5);
       }

       if(strcmp(OddPrtcls[i].name,OddPrtcls[i].aname))
       {
         j++;
         inMassAddress[j]=inMassAddress[j-1];
       }
       j++;
    }
  }
  Q=NULL;
  for(i=1;i<=mainChan->interface->nvar;i++) 
 {  if(mainChan->link[i]) 
    mainChan->interface->va[i]=*(mainChan->link[i]);
    if(strcmp(mainChan->interface->varName[i],"Q")==0) Q=mainChan->interface->va+i;
 }
 if(Q) *Q=100;
 
 err=mainChan->interface->calcFunc();
 if(err>0) return err;

 M=fabs(*(inMassAddress[0]));
 for(i=0;i<NC;i++) 
 { inMass[i]=fabs(*(inMassAddress[i]));
   if(M>inMass[i]) M=inMass[i];
 }

 if(Q) 
 { *Q=2*M;
    assignVal("Q",2*M);
    err=mainChan->interface->calcFunc();
    if(err>0) return err;
 }
            
 for(i=0; i<NC-1;)
 { int i1=i+1;
   if(inMass[sort[i]] > inMass[sort[i1]])
   { int c=sort[i]; sort[i]=sort[i1]; sort[i1]=c;
     if(i) i--; else i++;
   } else i++;
 }

 LSP=sort[0];
 M=inMass[LSP];

 for(i=0;i<NC;i++)
 { inDelta[i]= (inMass[i]-M)/M;
   inG_[i]=inG[i]*pow(1+inDelta[i],1.5);
 }

  for(k1=0;k1<NC;k1++)  for(k2=0;k2<NC;k2++) if(code22[k1*NC+k2]) code22[k1*NC+k2]->init=0;
return 0;
}