void ViewTspCircuit(TSP_Data &tsp)
{
  ListGraph h;
  ListGraph::NodeMap<string> h_vname(h);  // node names
  ListGraph::NodeMap<Node> h_g2h(tsp.g);  // maps a node of g to a node of h
  ListGraph::NodeMap<double> h_posx(h);
  ListGraph::NodeMap<double> h_posy(h);
  ListGraph::NodeMap<int> vcolor(h);   // color of the vertices
  ListGraph::EdgeMap<int> acolor(h);  // color of edges
  ListGraph::EdgeMap<string> aname(h);  // name of edges
  for (ListGraph::NodeIt v(tsp.g); v!=INVALID; ++v) {
    Node hv;
    hv = h.addNode();
    h_g2h[v] = hv;
    h_posx[hv] = tsp.posx[v];
    h_posy[hv] = tsp.posy[v];
    h_vname[hv] = tsp.vname[v];
    vcolor[hv] = BLUE;
  }
  for (int i=0;i<tsp.NNodes;i++) {
    ListGraph::Node u,v;
    ListGraph::Edge a;
    u = tsp.BestCircuit[i]; 
    v = tsp.BestCircuit[(i+1) % tsp.NNodes]; 
    a = h.addEdge(h_g2h[u] , h_g2h[v]);
    aname[a] = "";
    acolor[a] = BLUE;
  }
  ViewListGraph(h,h_vname,aname,h_posx,h_posy,vcolor,acolor,"TSP Circuit with cost "+DoubleToString(tsp.BestCircuitValue));
}
Ejemplo n.º 2
0
// PDBfile::pdb_Atom()
Atom PDBfile::pdb_Atom() {
  // Atom number (6-11)
  // Atom name (12-16)
  char savechar = linebuffer_[16];
  linebuffer_[16] = '\0';
  NameType aname(linebuffer_+12);
  // Replace asterisks with single quotes
  aname.ReplaceAsterisk();
  linebuffer_[16] = savechar;
  return Atom(aname);
}
// ****************************************************************************
//  Method:  avtAxisRestrictionToolInterface::ResetNumberOfAxes
//
//  Purpose:
//    Sets the number of available axes.
//
//  Arguments:
//    n          the number of axes
//
//  Programmer:  Jeremy Meredith
//  Creation:    February  1, 2008
//
//  Modifications:
//    Jeremy Meredith, Fri Feb 15 13:21:20 EST 2008
//    Added axis names to the axis restriction attributes.
//
// ****************************************************************************
void
avtAxisRestrictionToolInterface::ResetNumberOfAxes(int n)
{
    AxisRestrictionAttributes *a = (AxisRestrictionAttributes *)atts;
    stringVector aname(n, "");
    doubleVector amin(n, -1e+37);
    doubleVector amax(n, +1e+37);
    a->SetNames(aname);
    a->SetMinima(amin);
    a->SetMaxima(amax);
}
Ejemplo n.º 4
0
void LogonConsole::CreateAccount(char* str)
{
	char name[ 512 ];
	char password[ 512 ];
	char email[ 512 ];

	int count = sscanf(str, "%s %s %s", name, password, email);
	if(count != 3)
	{
		std::cout << "Usage: createaccount <name> <password> <email>" << std::endl;
		std::cout << "Example: createaccount username password [email protected]" << std::endl;
		std::cout << "--or--" << std::endl;
		std::cout << "Usage: account <name> <password> <email>" << std::endl;
		std::cout << "Example: account username password [email protected]" << std::endl;
		return;
	}

	{
		// need to pass uppercase names to check if account exists
		std::string aname(name);

		for(std::string::iterator itr = aname.begin(); itr != aname.end(); ++itr)
			*itr = toupper(*itr);

		if(AccountMgr::getSingleton().GetAccount(aname) != NULL)
		{
			std::cout << "There's already an account with name " << name << std::endl;
			return;
		}
	}

	std::string pass;
	pass.assign(name);
	pass.push_back(':');
	pass.append(password);

	std::stringstream query;
	query << "INSERT INTO `accounts`( `login`,`password`,`encrypted_password`,`gm`,`banned`,`email`,`flags`,`banreason`) VALUES ( '";
	query << name << "','',";
	query << "SHA( UPPER( '" << pass << "' ) ),'0','0','";
	query << email << "','";
	query << 24 << "','' );";

	if(!sLogonSQL->WaitExecuteNA(query.str().c_str()))
	{
		std::cout << "Couldn't save new account to database. Aborting." << std::endl;
		return;
	}

	AccountMgr::getSingleton().ReloadAccounts(true);

	std::cout << "Account created." << std::endl;
}
Ejemplo n.º 5
0
  /** This should be moved to branch engine */
  bool EstimatorManager::put(MCWalkerConfiguration& W, QMCHamiltonian& H, xmlNodePtr cur) 
  {
    vector<string> extra;
    cur = cur->children;
    while(cur != NULL) 
    {
      string cname((const char*)(cur->name));
      if(cname == "estimator") 
      {
        xmlChar* att=xmlGetProp(cur,(const xmlChar*)"name");
        if(att) 
        {
          string aname((const char*)att);
          if(aname == "LocalEnergy") 
            add(new LocalEnergyEstimator(H),MainEstimatorName);
          else 
            extra.push_back(aname);
        }
      } 
      cur = cur->next;
    }

    if(Estimators.empty()) 
    {
      app_log() << "  Using a default LocalEnergyOnlyEstimator for the MainEstimator " << endl;
      add(new LocalEnergyOnlyEstimator(),MainEstimatorName);
    } 

    string SkName("sk");
    string GofRName("gofr");
    for(int i=0; i< extra.size(); i++)
    {
      if(extra[i] == SkName && W.Lattice.SuperCellEnum)
      {
        if(CompEstimators == 0) CompEstimators = new CompositeEstimatorSet;
        if(CompEstimators->missing(SkName))
        {
          app_log() << "  EstimatorManager::add " << SkName << endl;
          CompEstimators->add(new SkEstimator(W),SkName);
        }
      } else if(extra[i] == GofRName)
      {
        if(CompEstimators == 0) CompEstimators = new CompositeEstimatorSet;
        if(CompEstimators->missing(GofRName))
        {
          app_log() << "  EstimatorManager::add " << GofRName << endl;
          CompEstimators->add(new GofREstimator(W),GofRName);
        }
      }
    }
    //add extra
    return true;
  }
Ejemplo n.º 6
0
bool ADIOS1CommonRead::IsVarLocalValue(ADIOS_VARINFO *vi)
{
    bool isLocalValue = false;
    std::string aname(m_fh->var_namelist[vi->varid]);
    aname = aname + "/ReadAsArray";
    for (int i = 0; i < vi->nattrs; ++i)
    {
        if (!strcmp(m_fh->attr_namelist[vi->attr_ids[i]], aname.c_str()))
        {
            isLocalValue = true;
            break;
        }
    }
    return isLocalValue;
}
Ejemplo n.º 7
0
	static void xml_start(void *data, const char *el, const char **attr) {
	xml_parser *p = (xml_parser *)data;

		p->m_current->name.assign(el);

		for (size_t i = 0; attr[i]; i += 2) {
			std::string aname(attr[i]);
			std::string aval(attr[i+1]);

			auto it = p->m_current->attrs.find(aname);
			if (it == p->m_current->attrs.end()) {
				p->m_current->attrs[aname] = std::vector<std::string>({aval});
			} else {
				it->second.emplace_back(aval);
			}
		}

		p->on_start(*p->m_current);
	}
Ejemplo n.º 8
0
STDMETHODIMP CElement::Call(BSTR name, SAFEARRAY * params, /*[out,retval]*/ VARIANT *rv)
{
  HRESULT hr; 
  long lbound = 0, ubound = -1;
  bool r = false;

	hr = SafeArrayGetLBound(params, 0, &lbound); 
  hr = SafeArrayGetUBound(params, 0, &ubound); 
  
  aux::w2a aname(name);
  XCALL_PARAMS prm(aname);

  if( lbound <= ubound )
  {
    json::value *argv = new json::value[ubound - lbound + 1];
    int argc = 0;
    for(long n = lbound; n <= ubound; ++n)
    {
      CComVariant var;
      hr = SafeArrayGetElement(params,&n, &var); 
      if(FAILED(hr))
        break;
      argv[argc++] = cvt_VARIANT_to_json_value(var);
    }
    prm.argv = argv;
    prm.argc = argc;
    r = self.call_behavior_method(&prm);
    *rv = cvt_json_value_to_VARIANT(prm.retval);
    delete [] argv;
  }  
  else
  {
    prm.argv = 0;
    prm.argc = 0;
    r = self.call_behavior_method(&prm);
    *rv = cvt_json_value_to_VARIANT(prm.retval);
  }
  return r? S_OK : S_FALSE;
}
Ejemplo n.º 9
0
Archivo: UnLua.cpp Proyecto: hce/unlua
static int
luaCallFunction(lua_State *L)
{
	int numparams = lua_gettop(L);
	lua_getglobal(L, "__unlua");
	AActor* unlua = (AActor*) lua_topointer(L, -1);
	lua_remove(L, -1);

	AActor* actor = (AActor*) lua_topointer(L, lua_upvalueindex(1));
	UFunction* func = (UFunction*) lua_topointer(L, lua_upvalueindex(2));
	const char* funcName_s = lua_tostring(L, lua_upvalueindex(3));
	

	if (func->NumParms == 0) {
		actor->ProcessEvent(func, NULL, NULL);
		return 0;
	}

	TFieldIterator<UProperty> It (func);
	char params[1024];
	memset(params, 0, sizeof(params));
	char* parptr = params;
	TArray<FString*> allocatedStrings;
	for (int i = 0; i < func->NumParms; ++i) {
		if (i >= numparams) {
			if (It->PropertyFlags & CPF_OptionalParm) {
				break;
			} else {
				lua_pushfstring(L, "Too few parameters for call to %s", funcName_s);
				lua_error(L);
			}
		}
		if (It->IsA(UIntProperty::StaticClass())) {
			int anint = lua_tointeger(L, i + 1);
			memcpy(parptr, &anint, It->ElementSize);
		} else if (It->IsA(UStrProperty::StaticClass())) {
			FString* astr = new FString(lua_tostring(L, i + 1));
			allocatedStrings.AddItem(astr);
			memcpy(parptr, astr, It->ElementSize);
		} else if (It->IsA(UNameProperty::StaticClass())) {
			FString astr(lua_tostring(L, i + 1));
			FName aname(*astr, FNAME_Add);
			memcpy(parptr, &aname, It->ElementSize);
		} else if (It->IsA(UByteProperty::StaticClass())) {
			*parptr = (char) lua_tointeger(L, i + 1);
		} else if (It->IsA(UBoolProperty::StaticClass())) {
			int bval = lua_toboolean(L, i + 1);
			memcpy(parptr, &bval, It->ElementSize);
		} else if (It->IsA(UFloatProperty::StaticClass())) {
			float fval = (float)lua_tonumber(L, i + 1);
			memcpy(parptr, &fval, It->ElementSize);
		} else if (It->IsA(UObjectProperty::StaticClass())) {
			UObjectProperty *uop = (UObjectProperty*) *It;
			struct UnLuaActor* ula  = (struct UnLuaActor*)
				luaL_testudata(L, i + 1, "UnrealActor");
			struct UnrealClass* ulc = (struct UnrealClass*)
				luaL_testudata(L, i + 1, "UnrealClass");
			UObject** uobj = (UObject**) parptr;
			if ((ula == NULL) && (ulc == NULL))
				*uobj = NULL;
			else {
				if (uop->PropertyClass == UClass::StaticClass()) {
					if (ulc == NULL) {
						lua_pushfstring(L, "Invalid type for parameter %d", i+1);
						lua_error(L);
					}
					*uobj = ulc->uclass;
				} else {
					if (ula->actor->IsA(uop->PropertyClass)) {
						//memcpy(parptr, ula->actor, It->ElementSize);
						*uobj = ula->actor;
					} else {
						lua_pushfstring(L, "Invalid type for parameter %d", i+1);
						lua_error(L);
					}
				}
			}
		} else {
			lua_pushfstring(L, "luaCallFunction: Unreal function %s requires "
				"parameter type not yet supported by UnLua", funcName_s);
			lua_error(L);
		}
		parptr += It->ElementSize;
		++It;
	}
	actor->ProcessEvent(func, params, NULL);
	free(params);
	while(allocatedStrings.Num())
		delete allocatedStrings.Pop();

	return 0;
}
Ejemplo n.º 10
0
void sort_ions(int nsa, int nw, int repl[], atom_id index[],
               t_atoms *atoms, rvec x[],
               const char *p_name, const char *n_name)
{
    int    i, j, k, r, np, nn, starta, startr, npi, nni;
    rvec  *xt;
    char **pptr = NULL, **nptr = NULL, **paptr = NULL, **naptr = NULL;

    snew(xt, atoms->nr);

    /* Put all the solvent in front and count the added ions */
    np = 0;
    nn = 0;
    j  = index[0];
    for (i = 0; i < nw; i++)
    {
        r = repl[i];
        if (r == 0)
        {
            for (k = 0; k < nsa; k++)
            {
                copy_rvec(x[index[nsa*i+k]], xt[j++]);
            }
        }
        else if (r > 0)
        {
            np++;
        }
        else if (r < 0)
        {
            nn++;
        }
    }

    if (np+nn > 0)
    {
        /* Put the positive and negative ions at the end */
        starta = index[nsa*(nw - np - nn)];
        startr = atoms->atom[starta].resind;

        if (np)
        {
            snew(pptr, 1);
            pptr[0] = gmx_strdup(p_name);
            snew(paptr, 1);
            paptr[0] = aname(p_name);
        }
        if (nn)
        {
            snew(nptr, 1);
            nptr[0] = gmx_strdup(n_name);
            snew(naptr, 1);
            naptr[0] = aname(n_name);
        }
        npi = 0;
        nni = 0;
        for (i = 0; i < nw; i++)
        {
            r = repl[i];
            if (r > 0)
            {
                j = starta+npi;
                k = startr+npi;
                copy_rvec(x[index[nsa*i]], xt[j]);
                atoms->atomname[j]     = paptr;
                atoms->atom[j].resind  = k;
                atoms->resinfo[k].name = pptr;
                npi++;
            }
            else if (r < 0)
            {
                j = starta+np+nni;
                k = startr+np+nni;
                copy_rvec(x[index[nsa*i]], xt[j]);
                atoms->atomname[j]     = naptr;
                atoms->atom[j].resind  = k;
                atoms->resinfo[k].name = nptr;
                nni++;
            }
        }
        for (i = index[nsa*nw-1]+1; i < atoms->nr; i++)
        {
            j                  = i-(nsa-1)*(np+nn);
            atoms->atomname[j] = atoms->atomname[i];
            atoms->atom[j]     = atoms->atom[i];
            copy_rvec(x[i], xt[j]);
        }
        atoms->nr -= (nsa-1)*(np+nn);

        /* Copy the new positions back */
        for (i = index[0]; i < atoms->nr; i++)
        {
            copy_rvec(xt[i], x[i]);
        }
        sfree(xt);
    }
}
Ejemplo n.º 11
0
GridMolecularOrbitals::BasisSetType*
GridMolecularOrbitals::addBasisSet(xmlNodePtr cur)
{
  if(!BasisSet)
    BasisSet = new BasisSetType(IonSys.getSpeciesSet().getTotalNum());
  QuantumNumberType nlms;
  string rnl;
  //current number of centers
  int ncenters = CenterID.size();
  int activeCenter;
  int gridmode = -1;
  bool addsignforM = false;
  string  sph("default"), Morder("gaussian");
  //go thru the tree
  cur = cur->xmlChildrenNode;
  map<string,RGFBuilderBase*> rbuilderlist;
  while(cur!=NULL)
  {
    string cname((const char*)(cur->name));
    if(cname == basis_tag || cname == "atomicBasisSet")
    {
      int expandlm = GAUSSIAN_EXPAND;
      string abasis("invalid"), btype("Numerical");
      //Register valid attributes attributes
      OhmmsAttributeSet aAttrib;
      aAttrib.add(abasis,"elementType");
      aAttrib.add(abasis,"species");
      aAttrib.add(btype,"type");
      aAttrib.add(sph,"angular");
      aAttrib.add(addsignforM,"expM");
      aAttrib.add(Morder,"expandYlm");
      aAttrib.put(cur);
      if(abasis == "invalid")
        continue;
      if(sph == "spherical")
        addsignforM=1; //include (-1)^m
      if(Morder == "gaussian")
      {
        expandlm = GAUSSIAN_EXPAND;
      }
      else
        if(Morder == "natural")
        {
          expandlm = NATURAL_EXPAND;
        }
        else
          if(Morder == "no")
          {
            expandlm = DONOT_EXPAND;
          }
      if(addsignforM)
        LOGMSG("Spherical Harmonics contain (-1)^m factor")
            else
              LOGMSG("Spherical Harmonics  DO NOT contain (-1)^m factor")
              //search the species name
              map<string,int>::iterator it = CenterID.find(abasis);
      if(it == CenterID.end())
        //add the name to the map CenterID
      {
        if(btype == "Numerical" || btype == "NG" || btype == "HFNG")
        {
          rbuilder = new NumericalRGFBuilder(cur);
        }
        else
        {
          rbuilder = new Any2GridBuilder(cur);
        }
        //CenterID[abasis] = activeCenter = ncenters++;
        CenterID[abasis]=activeCenter=IonSys.getSpeciesSet().findSpecies(abasis);
        int Lmax(0); //maxmimum angular momentum of this center
        int num(0);//the number of localized basis functions of this center
        //process the basic property: maximun angular momentum, the number of basis functions to be added
        vector<xmlNodePtr> radGroup;
        xmlNodePtr cur1 = cur->xmlChildrenNode;
        xmlNodePtr gptr=0;
        while(cur1 != NULL)
        {
          string cname1((const char*)(cur1->name));
          if(cname1 == basisfunc_tag || cname1 == "basisGroup")
          {
            radGroup.push_back(cur1);
            int l=atoi((const char*)(xmlGetProp(cur1, (const xmlChar *)"l")));
            Lmax = max(Lmax,l);
            //expect that only Rnl is given
            if(expandlm)
              num += 2*l+1;
            else
              num++;
          }
          else
            if(cname1 == "grid")
            {
              gptr = cur1;
            }
          cur1 = cur1->next;
        }
        XMLReport("Adding a center " << abasis << " centerid "<< CenterID[abasis])
        XMLReport("Maximum angular momentum    = " << Lmax)
        XMLReport("Number of centered orbitals = " << num)
        //create a new set of atomic orbitals sharing a center with (Lmax, num)
        //if(addsignforM) the basis function has (-1)^m sqrt(2)Re(Ylm)
        CenteredOrbitalType* aos = new CenteredOrbitalType(Lmax,addsignforM);
        aos->LM.resize(num);
        aos->NL.resize(num);
        //Now, add distinct Radial Orbitals and (l,m) channels
        num=0;
        rbuilder->setOrbitalSet(aos,abasis); //assign radial orbitals for the new center
        rbuilder->addGrid(gptr); //assign a radial grid for the new center
        vector<xmlNodePtr>::iterator it(radGroup.begin());
        vector<xmlNodePtr>::iterator it_end(radGroup.end());
        while(it != it_end)
        {
          cur1 = (*it);
          xmlAttrPtr att = cur1->properties;
          while(att != NULL)
          {
            string aname((const char*)(att->name));
            if(aname == "rid" || aname == "id")
              //accept id/rid
            {
              rnl = (const char*)(att->children->content);
            }
            else
            {
              map<string,int>::iterator iit = nlms_id.find(aname);
              if(iit != nlms_id.end())
                //valid for n,l,m,s
              {
                nlms[(*iit).second] = atoi((const char*)(att->children->content));
              }
            }
            att = att->next;
          }
          XMLReport("\n(n,l,m,s) " << nlms[0] << " " << nlms[1] << " " << nlms[2] << " " << nlms[3])
          //add Ylm channels
          num = expandYlm(rnl,nlms,num,aos,cur1,expandlm);
          ++it;
        }
        //add the new atomic basis to the basis set
        BasisSet->add(aos,activeCenter);
#if !defined(HAVE_MPI)
        rbuilder->print(abasis,1);
#endif
        if(rbuilder)
        {
          delete rbuilder;
          rbuilder=0;
        }
      }
      else
      {
        WARNMSG("Species " << abasis << " is already initialized. Ignore the input.")
      }
    }
    cur = cur->next;
  }
Ejemplo n.º 12
0
  GTOMolecularOrbitals::BasisSetType* 
  GTOMolecularOrbitals::addBasisSet(xmlNodePtr cur) {

    if(!BasisSet) 
      BasisSet = new BasisSetType(IonSys.getSpeciesSet().getTotalNum());

    QuantumNumberType nlms;
    string rnl;

    //current number of centers
    int ncenters = CenterID.size();
    int activeCenter;
    int gridmode = -1;
    bool addsignforM = true;
    string  sph("spherical"), Morder("gaussian");

    //go thru the tree
    cur = cur->xmlChildrenNode;
    while(cur!=NULL) {
      string cname((const char*)(cur->name));
      if(cname == basis_tag || cname == "atomicBasisSet") {
        int expandlm = GAUSSIAN_EXPAND;
        string abasis("invalid"), norm("no");

        //Register valid attributes attributes
        OhmmsAttributeSet aAttrib;
        aAttrib.add(abasis,"elementType"); aAttrib.add(abasis,"species");
        aAttrib.add(sph,"angular"); aAttrib.add(addsignforM,"expM"); 
        aAttrib.add(Morder,"expandYlm"); 
        aAttrib.add(norm,"normalized"); 
        aAttrib.put(cur);

        if(norm == "yes") Normalized=true;
        else Normalized=false;

        if(abasis == "invalid") continue;
        if(sph == "spherical") addsignforM=true; //include (-1)^m
        if(sph == "cartesian") addsignforM=false;

        if(Morder == "gaussian") {
          expandlm = GAUSSIAN_EXPAND;
        } else if(Morder == "natural"){
          expandlm = NATURAL_EXPAND;
        } else if(Morder == "no") {
          expandlm = DONOT_EXPAND;
        }

        if(addsignforM) 
          LOGMSG("Spherical Harmonics contain (-1)^m factor")
        else
          LOGMSG("Spherical Harmonics  DO NOT contain (-1)^m factor")

	map<string,int>::iterator it = CenterID.find(abasis); //search the species name
	if(it == CenterID.end()) {//add the name to the map CenterID

	  //CenterID[abasis] = activeCenter = ncenters++;
          CenterID[abasis]=activeCenter=IonSys.getSpeciesSet().findSpecies(abasis);
	  int Lmax(0); //maxmimum angular momentum of this center
          int num(0);//the number of localized basis functions of this center

	  //process the basic property: maximun angular momentum, the number of basis functions to be added
          vector<xmlNodePtr> radGroup;
	  xmlNodePtr cur1 = cur->xmlChildrenNode;
          xmlNodePtr gptr=0;
	  while(cur1 != NULL) {
	    string cname1((const char*)(cur1->name));
	    if(cname1 == basisfunc_tag || cname1 == "basisGroup") {
              radGroup.push_back(cur1);
    	      int l=atoi((const char*)(xmlGetProp(cur1, (const xmlChar *)"l")));
	      Lmax = max(Lmax,l);
	      if(expandlm) 
                num += 2*l+1;
	      else
                num++;
	    } 
	    cur1 = cur1->next;
	  }
	  LOGMSG("Adding a center " << abasis << " centerid "<< CenterID[abasis])
          LOGMSG("Maximum angular momentum    = " << Lmax)
          LOGMSG("Number of centered orbitals = " << num)

	  //create a new set of atomic orbitals sharing a center with (Lmax, num)
          //if(addsignforM) the basis function has (-1)^m sqrt(2)Re(Ylm)
	  CenteredOrbitalType* aos = new CenteredOrbitalType(Lmax,addsignforM);
	  aos->LM.resize(num);
	  aos->NL.resize(num);

          //Now, add distinct Radial Orbitals and (l,m) channels
	  num=0;
          vector<xmlNodePtr>::iterator it(radGroup.begin());
          vector<xmlNodePtr>::iterator it_end(radGroup.end());
          while(it != it_end) {
            cur1 = (*it);
	    xmlAttrPtr att = cur1->properties;
	    while(att != NULL) {
	      string aname((const char*)(att->name));
	      if(aname == "rid" || aname == "id") { //accept id/rid
	        rnl = (const char*)(att->children->content);
	      } else { 
	        map<string,int>::iterator iit = nlms_id.find(aname);
	        if(iit != nlms_id.end()) { //valid for n,l,m,s
	          nlms[(*iit).second] = atoi((const char*)(att->children->content));
	        } 
	      }
	      att = att->next;
	    }
	    LOGMSG("\n(n,l,m,s) " << nlms[0] << " " << nlms[1] << " " << nlms[2] << " " << nlms[3])

            //add Ylm channels
            num = expandYlm(rnl,nlms,num,aos,cur1,expandlm);
            ++it;
          }

          LOGMSG("Checking the order of angular momentum ")
          std::copy(aos->LM.begin(), aos->LM.end(), ostream_iterator<int>(app_log()," "));
          app_log() << endl;

	  //add the new atomic basis to the basis set
	  BasisSet->add(aos,activeCenter);
	}else {
	  WARNMSG("Species " << abasis << " is already initialized. Ignore the input.")
	}
      }
      cur = cur->next;
    }
Ejemplo n.º 13
0
void generateMap(string id) {
    srand(1);

    int n, l, m, s;
    READ(cin, n);
    READ(cin, l);
    READ(cin, m);
    READ(cin, s);

    vector<string> aname(n * l);
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < l; j++) {
            READ_FRAG(cin, j, aname[i * l + j]);
        }
        READ_DONE();
    }

    int newL, newM, newS, tagNumber;
    READ(cin, newL);
    READ(cin, newM);
    READ(cin, newS);
    READ(cin, tagNumber);

    vector<string> nodeNameList;
    vector<string> nodeTagList;
    for (int j = 0; j < newM; j++) {
        string nodeName;
        READ_FRAG(cin, 0, nodeName);
        nodeNameList.push_back(nodeName);
        for (int i = 0; i < tagNumber; i++) {
            string nodeTag;
            READ_FRAG(cin, i+1, nodeTag);
            nodeTagList.push_back(nodeTag);
        }
        READ_DONE();
    }

    fixOldData(n, l, m, s, aname);
    fixNewData(n, newL, newM, newS, tagNumber, nodeNameList, nodeTagList);

    if (!validate(n, l, m, s)) {
        DIAG("ERROR: existing mapping failed validation" << endl);
        throw "Validation failure";
    }

    if (!validate(n, newL, newM, newS) || !validate(newM, nodeNameList, tagNumber, nodeTagList)) {
        DIAG("ERROR: new mapping failed validation" << endl);
        throw "Validation failure";
    }

    if (!IsInRow(nodeNameList, _NULL_NODE_NAME)) {
        nodeNameList.insert(nodeNameList.begin(), _NULL_NODE_NAME);
        for (int i = 0; i < tagNumber; i++) {
            nodeTagList.insert(nodeTagList.begin(), "");
        }
    }

    Mapping map0(n, l, m, s);
    map0.InitMapping(aname);

    vector<int> TagPrice(tagNumber,0);
    for (int i = 0; i < tagNumber; i++) {
        TagPrice[i] = 10;  // default to 10 for now
    }

    stack<int> addedNode;
    for (int j = 1; j <= newM; ++j ) {
        if (!IsInRow(map0.nodeNameList, nodeNameList[j])) {
            addedNode.push(j);
        }
    }
    // Deleted nodes map to zero, used for computing lower bound
    vector<int> oldNode2NewZero(map0.M + 1, 0);
    // Deleted nodes map to added nodes if possible
    // Used for initialize a search for RI
    vector<int> oldNode2NewMatch(map0.M + 1, 0);
    string currentNode;
    bool nodeFound;
    for (int i = 1; i <= map0.M; i++) {
        currentNode = map0.nodeNameList[i];
        nodeFound = 0;
        for (int j = 0; j <= newM; ++j ) {
            if (!currentNode.compare(nodeNameList[j])) {
                nodeFound = 1;
                oldNode2NewMatch[i] = j;
                oldNode2NewZero[i] = j;
                break;
            }
        }
        if (!nodeFound) {
            if (!addedNode.empty() ) {
                oldNode2NewMatch[i] = addedNode.top();
                addedNode.pop();
            }
        }
    }

    Mapping map1(map0.N, newL, newM, newS);
    map1.nodeNameList.swap(nodeNameList);
    map1.nodeTagList.swap(nodeTagList);
    map1.Rebalance(map0, oldNode2NewMatch, TagPrice);
    map1.nodeTagNumber = tagNumber;
    int LowerBound = map1.RebalanceLowerBound(map0, oldNode2NewZero, TagPrice);

    if (map1.imbalance)
        DIAG("WARNING : Output mapping has imbalance of " << map1.imbalance << "\n\n");

    DIAG("\nRebalance completed.\nNode number : " << map0.M << " ---> " << map1.M);
    DIAG("\nMove count (index/non-index) : " << map1.MoveCount(map0, 1) << " / ");
    DIAG(map1.MoveCount(map0, 0) << "\tLower bound : " << LowerBound);
    DIAG("\n\nSame tags replication :\nPrice : \t");

    vector<int> sameTagCount;
    map1.CheckTags(sameTagCount);
    for (int i = 0; i < map1.nodeTagNumber; i++) {
        DIAG(TagPrice[i] << '\t');
    }
    DIAG("\nCount : \t");
    for (int i = 0; i < map1.nodeTagNumber; i++) {
        DIAG(sameTagCount[i] << '\t');
    }
    DIAG(endl);

    ostringstream mapout;
    map1.PrintAname(mapout);
    WRITE(cout, mapout.str() << endl);
}
Ejemplo n.º 14
0
// -----------------------------------------------------------------------------
//
TCanvas* createPlot( TString path, 
		     TString canvas_name, 
		     TString name, 
		     TString dirmame, 
		     int rebin, 
		     bool norm, 
		     bool log,
		     TDirectory* file )
{

  // SetSomeStyles();

  float lumi = 250.0;// 15.04;//10.9;//6.8;
 
  // Create legend
  TLegend* legend = new TLegend(0.75, 0.6, 0.99, 0.99, "", "brNDC" );
  legend->SetFillColor(0);
  legend->SetLineColor(0); 
  legend->SetShadowColor(0);
  TLatex* prelim = new TLatex(0.6,0.54,"#scale[0.8]{CMS preliminary 2010}");
  prelim->SetNDC();
  TLatex* alumi = new TLatex(0.6,.45,"#scale[0.8]{#int L dt = 35 pb^{-1}, #sqrt{s} = 7 TeV}");
  alumi->SetNDC();

  // Create canvas 
  TCanvas* aCanvas = createCanvas( canvas_name, file, log );

  // Create histogram
  TString aname("nAll");
  // TH1D* data1    = getHisto( path+"S14datacleaned/Edward_Data_Skim/",name,"data.root",aname,rebin);
  // TH1D* data    = getHisto( path+"S14datacleaned/Edward_Data_Skim/",name,"data.root",dirmame,rebin);
 
  TH1D* data    = getHisto( path+"", name, "tt.root", dirmame, rebin );
  TH1D* qcd     = getHisto( path+"", name, "lm1.root", dirmame, rebin );
  TH1D* w_jets  = getHisto( path+"", name, "w.root", dirmame, rebin );
  TH1D* tt_jets = getHisto( path+"", name, "tt.root", dirmame, rebin );
  TH1D* z_jets  = getHisto( path+"", name, "z.root", dirmame, rebin );
  TH1D* lm3     = getHisto( path+"", name, "lm3.root", dirmame, rebin );
  TH1D* lm1     = getHisto( path+"", name, "lm1.root", dirmame, rebin );
  TH1D* lm6     = getHisto( path+"", name, "data.root", dirmame, rebin );
  TH1D* wm     = getHisto( path+"", name, "w.root", dirmame, rebin );
  data->Scale(lumi/100.);
  qcd->Scale(lumi/100.);
  tt_jets->Scale(lumi/100);
  w_jets->Scale(lumi/100);
  //  w_jets->Scale(10);
  //  z_inv->Scale(lumi/100);
  //  lm6->Scale(lumi/100);
  lm1->Scale(lumi/100);
  lm3->Scale(lumi/100);
  z_jets->Scale(lumi/100);
  wm->Scale(lumi/100);
  // Combine Z+jets and Z->inv
  // TH1D* z_all = z_inv->Clone(); 
  //  z_all->Add(z_jets,1);
  //z_jets->Add(z_inv,1);
  TH1D* total = tt_jets->Clone();
  total->Add(w_jets);
  total->Add(z_jets);

  // total->
 
  Int_t binMax =   total->GetNbinsX();
  Double_t& err = new Double_t(0.);
  total->IntegralAndError(10,binMax ,err);
  Double_t& errW = new Double_t(0.);
  w_jets->IntegralAndError(10,binMax ,errW);
  Double_t& errtt = new Double_t(0.);
  tt_jets->IntegralAndError(10,binMax ,errtt);
  Double_t& errZ = new Double_t(0.);
  z_jets->IntegralAndError(10,binMax ,errZ);
  Double_t& errQCD = new Double_t(0.);
  qcd->IntegralAndError(10,binMax ,errQCD );


  cout  <<endl;
  //  cout << "MC:" <<  total->IntegralAndError(11,binMax ,err) <<" && " <<  w_jets->Integral(11,binMax)<<" && "<<tt_jets->Integral(11,binMax) << "&&  "<<z_jets->Integral(11,binMax)<<" && "<< "\/\ /\hline"<<endl;
  //  cout << total->IntegralAndError(0,binMax ,err) <<" & " << lm1->Integral(0,binMax) <<" & " << lm3->Integral(0,binMax)<<" & " << lm6->Integral(0,binMax)   <<"\\\\ \\hline"<<endl;
  //  cout <<"270: " <<  total->IntegralAndError(27,binMax ,err) <<" & " << lm1->Integral(27,binMax) <<" & " << lm3->Integral(27,binMax)<<" & " << lm6->Integral(27,binMax)   <<"\\\\ \\hline"<<endl;


  cout <<"250& " <<  total->IntegralAndError(6,binMax ,err) <<" & " << lm1->Integral(6,binMax) <<" & " << lm3->Integral(6,binMax)<<" & " << lm6->Integral(6,binMax)   <<"\\\\ \\hline"<<endl;
 
  // cout << "300: " <<  total->IntegralAndError(7,binMax ,err) <<" & " << lm1->Integral(7,binMax) <<" & " << lm3->Integral(7,binMax)<<" &" << lm6->Integral(7,binMax)   <<"\\\\ \\hline"<<endl;

  cout <<"350& " <<  total->IntegralAndError(8,binMax ,err) <<" & " << lm1->Integral(8,binMax) <<" & " << lm3->Integral(8,binMax)<<" & " << lm6->Integral(8,binMax)    <<"\\\\ \\hline"<<endl;

  //   cout << "400: " <<  total->IntegralAndError(9,binMax ,err) <<" & " << lm1->Integral(9,binMax) <<" & " << lm3->Integral(9,binMax)<<" & " << lm6->Integral(9,binMax)    <<"\\\\ \\hline"<<endl;

cout << "450& " <<  total->IntegralAndError(10,binMax ,err) <<" & " << lm1->Integral(10,binMax) <<" & " << lm3->Integral(10,binMax)<<" & " << lm6->Integral(10,binMax)    <<"\\\\ \\hline"<<endl;

//cout << "500: " <<   total->IntegralAndError(11,binMax ,err) <<" & " << lm1->Integral(11,binMax) <<" & " << lm3->Integral(11,binMax)<<" & " << lm6->Integral(11,binMax)    <<"\\\\ \\hline"<<endl;

  cout <<"550& " <<  total->IntegralAndError(12,binMax ,err) <<" & " << lm1->Integral(12,binMax) <<" & " << lm3->Integral(12,binMax)<<" & " << lm6->Integral(12,binMax)    <<"\\\\ \\hline"<<endl;
  /*
 cout << "MC:" <<  total->IntegralAndError(7,binMax ,err) <<" && " << lm1->Integral(7,binMax) <<" && " << lm3->Integral(7,binMax)<<" && " << lm6->Integral(6,binMax)   <<"/\/\ /\hline"<<endl;
  cout << "MC:" <<  total->IntegralAndError(8,binMax ,err) <<" && " << lm1->Integral(8,binMax) <<" && " << lm3->Integral(8,binMax)<<" && " << lm6->Integral(7,binMax)   <<"/\/\ /\hline"<<endl;
  cout << "MC:" <<  total->IntegralAndError(10,binMax ,err) <<" && " << lm1->Integral(10,binMax) <<" && " << lm3->Integral(10,binMax)<<" && " << lm6->Integral(10,binMax)   <<"/\/\ /\hline"<<endl;
 cout << "MC:" <<  total->IntegralAndError(11,binMax ,err) <<" && " << lm1->Integral(11,binMax) <<" && " << lm3->Integral(11,binMax)<<" && " << lm6->Integral(11,binMax)   <<"/\/\ /\hline"<<endl;
 cout << "MC:" <<  total->IntegralAndError(12,binMax ,err) <<" && " << lm1->Integral(12,binMax) <<" && " << lm3->Integral(12,binMax)<<" && " << lm6->Integral(12,binMax)   <<"/\/\ /\hline"<<endl;
  // cout << "MC:" << err  <<", W: " << errW<<", tt: "<<errtt << ", Z: "<<errZ<<", QCD: "<<  errQCD<< endl;
  */

  //  cout << "data:" << data->Integral() << endl;


  TH1D* hcen = total->Clone();
  TH1D* herr = total->Clone();
  
  herr->SetLineColor(kTeal+3);
  herr->SetMarkerColor(kAzure+6);
  herr->SetFillColor(kAzure+6);
  herr->SetLineWidth(3);
  
  total->SetLineWidth(3);
  total->SetFillColor(kAzure+2);
  total->SetLineColor(kAzure+2);
  total->SetFillStyle(3245);
 
  hcen->SetFillStyle(0);
  hcen->SetMarkerColor(kTeal+3);
  hcen->SetLineColor(kTeal+3);
  hcen->SetLineWidth(3);

  // Merge Z+jets and Z->inv
  bool combine = false;
  
  // Line colour and fill
  qcd->SetLineColor(kPink+4);
  qcd->SetLineWidth(3);
  tt_jets->SetLineColor(kBlue+1);
  tt_jets->SetLineWidth(3);
  
  w_jets->SetLineColor(kPink+7);
  w_jets->SetLineWidth(3);

  z_jets->SetLineWidth(3);
  z_jets->SetLineColor(kTeal-7);
  
  if ( combine ) {
    z_all->SetLineColor(kBlack);
    z_all->SetLineStyle(3);
    z_all->SetLineWidth(1);
  } else {
    data->SetLineColor(1);
    data->SetLineStyle(1);
    data->SetLineWidth(3);
    data->SetMarkerStyle(20);
    data->SetFillColor(0);
  }
  //  lm0->SetLineColor(kRed);
  //  lm0->SetLineWidth(3);
  // lm1->SetLineColor(kRed+3);
  // lm1->SetLineWidth(3);

  // Populate legend
  // legend->AddEntry( data, "tt fully leptonic/", "LP" );
   legend->AddEntry( herr, "full SM", "LP" );
    legend->AddEntry( z_jets, " Z+jets ", "LP" );
    legend->AddEntry( w_jets, " W+jets", "LP" );
    legend->AddEntry( tt_jets, " t#bar{t}", "LP" );
    //  legend->AddEntry( lm3, " SUSY LM3", "LP" );
    //   legend->AddEntry( lm1, " SUSY LM1", "LP" );
    legend->AddEntry( lm6, " data", "LP" );
    // legend->AddEntry(wm,"W Mad","lp");
    
  // Calc maximum number of entries
  double aMax = 0.;
  if( data->GetMaximum()     > aMax ) { aMax = data->GetMaximum()+data->GetBinError(data->GetMaximumBin()); }
  if ( qcd->GetMaximum()     > aMax ) { aMax = qcd->GetMaximum(); }
  //  if ( lm0->GetMaximum()     > aMax ) { aMax = lm0->GetMaximum(); }
  //  if ( lm1->GetMaximum()     > aMax ) { aMax = lm1->GetMaximum(); }
  if ( tt_jets->GetMaximum() > aMax ) { aMax = tt_jets->GetMaximum(); }  
  if ( w_jets->GetMaximum()  > aMax ) { aMax = w_jets->GetMaximum(); }  
  if ( combine ) {
    if ( z_all->GetMaximum()  > aMax ) { aMax = z_all->GetMaximum(); }  
  } else {
    //   if ( data->GetMaximum()   > aMax ) { aMax = z_inv->GetMaximum(); }  
    if ( z_jets->GetMaximum()  > aMax ) { aMax = z_jets->GetMaximum(); }  
  }

  // Calc minimum number of entries
  double aMin = 1.e12;
  if ( qcd->GetMinimum(1.e-12)     < aMin ) { aMin = qcd->GetMinimum(1.e-12); }
  //  if ( lm0->GetMinimum(1.e-12)     < aMin ) { aMin = lm0->GetMinimum(1.e-12); }
  //  if ( lm1->GetMinimum(1.e-12)     < aMin ) { aMin = lm1->GetMinimum(1.e-12); }
  if ( tt_jets->GetMinimum(1.e-12) < aMin ) { aMin = tt_jets->GetMinimum(1.e-12); }  
  if ( w_jets->GetMinimum(1.e-12)  < aMin ) { aMin = w_jets->GetMinimum(1.e-12); }  
  if ( combine ) {
    if ( z_all->GetMinimum(1.e-12)   < aMin ) { aMin = z_all->GetMinimum(1.e-12); }  
  } else {
    // if ( data->GetMinimum(1.e-12)   < aMin ) { aMin = z_inv->GetMinimum(1.e-12); }  
    if ( z_jets->GetMinimum(1.e-12)  < aMin ) { aMin = z_jets->GetMinimum(1.e-12); }  
  }

  if ( qcd ) qcd->GetYaxis()->SetTitleOffset(1.43);
  if ( qcd ) qcd->GetYaxis()->SetTitleSize(0.06);
  if ( qcd ) qcd->GetXaxis()->SetTitleSize(0.06);
  if ( qcd ) qcd->GetXaxis()->SetTitleOffset(0.9);

 
  if ( log ) {
    if ( qcd ) herr->SetMaximum( aMax * 10. );
    //   if ( qcd ) herr->SetMinimum( aMin * 0.1 );
    if ( qcd ) herr->SetMinimum( 0.005);
  } else {
    if ( qcd ) herr->SetMaximum( aMax * 1.1 );
    //   if ( qcd ) herr->SetMinimum( aMin * 0.9 );
  if ( qcd ) herr->SetMinimum( 0.005);

  }

  /*  TPad* mainPad = new TPad("","",0.01,0.25,0.99,0.99);
  mainPad->SetNumber(1);
  mainPad->SetFillColor(0);
  // mainPad->Range(-288.2483,-2.138147,1344.235,6.918939);
  mainPad->SetFillColor(0);
  mainPad->SetBorderMode(0);
  mainPad->SetBorderSize(2);
  if ( log == true)mainPad->SetLogy();
   mainPad->SetLeftMargin(0.1765705);
  mainPad->SetRightMargin(0.05772496);
  mainPad->SetTopMargin(0.04778761);
  mainPad->SetBottomMargin(0.1256637);
  mainPad->SetFrameFillStyle(0);
  mainPad->SetFrameLineWidth(2);
  mainPad->SetFrameBorderMode(0);
  mainPad->SetFrameFillStyle(0);
  mainPad->SetFrameLineWidth(2);
  mainPad->SetFrameBorderMode(0);
  if ( log == true)mainPad->SetLogy();
  mainPad->Draw();
  TPad*  ratioPad = new TPad("","",0.01,0.01,0.99,0.25);
  ratioPad->SetNumber(2);
  ratioPad->SetFillColor(0);
  ratioPad->SetFillColor(0);
  ratioPad->SetBorderMode(0);
  ratioPad->SetBorderSize(2);
  // if ( log == true)ratioPad->SetLogy();
   ratioPad->SetLeftMargin(0.1765705);
  ratioPad->SetRightMargin(0.05772496);
  ratioPad->SetTopMargin(0.04778761);
  ratioPad->SetBottomMargin(0.1256637);
  ratioPad->SetFrameFillStyle(0);
  ratioPad->SetFrameLineWidth(2);
  ratioPad->SetFrameBorderMode(0);
  ratioPad->SetFrameFillStyle(0);
  ratioPad->SetFrameLineWidth(2);
  ratioPad->SetFrameBorderMode(0);
  //  if ( log == true)ratioPad->SetLogy();
  ratioPad->Draw();
 

  aCanvas->cd(1);
  */

  herr->GetYaxis()->SetTitle("events");


  if ( norm ) {
    if ( qcd ) qcd->DrawNormalized("Ehist");
    // if ( lm0->GetEntries() > 0. )     { lm0->DrawNormalized("hsame"); }
    if ( lm1->GetEntries() > 0. )     { lm1->DrawNormalized("hsame"); }
    if ( tt_jets->GetEntries() > 0. ) { tt_jets->DrawNormalized("hsame"); }
    if ( w_jets->GetEntries() > 0. )  { w_jets->DrawNormalized("hsame"); }
    if ( combine ) {
      if ( z_all->GetEntries() > 0. )   { z_all->DrawNormalized("hsame"); }
    } else {
      if ( data->GetEntries() > 0. )   { z_inv->DrawNormalized("hsame"); }
      if ( z_jets->GetEntries() > 0. )  { z_jets->DrawNormalized("hsame"); }
    }
  } else {
     herr->Draw("hist");
   
   
     // qcd->SetFillStyle(3240);
     // qcd->SetFillColor(kPink+4);
    // qcd->Draw("hist");
    w_jets->Draw("hSameh");
    z_jets->Draw("9Sameh");
    w_jets->Draw("9Sameh");
    tt_jets->Draw("9SAMEh");
    //data1->Draw("9SAMEh");
     //lm0->Draw("9SAMEh");
     lm1->SetLineColor(12);
     lm1->SetLineStyle(2);
     lm1->SetLineWidth(2);
     //     lm1->Draw("9SAMEh");
     lm3->SetLineColor(14);
     lm3->SetLineStyle(2);
     lm3->SetLineWidth(2);
     //  lm3->Draw("9SAMEh");
     lm6->Draw("9SAMEh");
     wm->SetLineStyle(2);
     wm->SetLineColor(kPink+7);
     // wm->Draw("9Sameh");

     // total->DrawNormalized("9E2same");
     //      data->Draw("SAMEh");
    //  tt_jets->Divide(data);
    //  tt_jets->Draw("h");
  //  data->SetLineColor(kRed);
  //  data->Draw("sameh");
     //     data1->SetLineColor(kRed);
     //  data1->Draw("9SAMEP");
  }
  
    legend->Draw();
  // prelim->Draw();
  // alumi->Draw();



  /*  TH1D* ratioBottom = total->Clone();
  TH1D* ratioTop = data->Clone();
  ratioTop->GetYaxis()->SetTitle("data / sim");
  ratioTop->Divide(ratioBottom);
  
  aCanvas->cd(1)->Update();
 
  aCanvas->cd(2);

  ratioTop->SetTitleSize(0.1, "XYZ");
  ratioTop->SetTitleOffset(0.55, "X");
  ratioTop->SetTitleOffset(0.3, "Y");
  ratioTop->SetLabelSize(0.06,"XY");
    
  // ratioTop->GetXaxis().SetRangeUser(MinX,MaxX);
  ratioTop->GetYaxis()->SetRangeUser(0.,2.0);
  ratioTop->Draw();*/
  /* TBox* unity = TBox(ratioTop->GetXaxis()->GetBinLowEdge(ratioTop->GetXaxis()->GetFirst()), 0.89,ratioTop->GetXaxis()->GetBinLowEdge(ratioTop->GetXaxis()->GetLast()), 1.11);
  unity->SetLineWidth(2);
   
  unity->SetLineColor(2);
  unity->SetFillColor(2);
  unity->SetFillStyle(3002);
  unity->Draw();

  */
  file->cd();
 
  aCanvas->SaveAs( std::string(canvas_name+".pdf").c_str() );
  aCanvas->Write();



  //   aCanvas->Print(".png");
 return aCanvas;

}