示例#1
0
int main()
{
	std::ifstream in("data/data.json");
	sqlite3* db;

//	std::remove("data.sqlite3");

	sqlite3_config(SQLITE_CONFIG_SINGLETHREAD);

	int rc;
	rc = sqlite3_open("data.sqlite3", &db);
	assert(rc == SQLITE_OK);

	rc = sqlite3_exec(db, schema, NULL, NULL, NULL);
	assert(rc == SQLITE_OK);

	sqlite3_stmt* insert;
	rc = sqlite3_prepare_v2(db, insert_stmt, -1, &insert, NULL);
	while (!in.eof())
	{
		Json::Value root;
		char comment[512000];
		in.getline(comment, 512000);
		size_t clen = std::strlen(comment);
		//comment[clen++] = '}';
		//comment[clen] = 0;
		char* cstart = comment;
		while (cstart != comment + clen && *cstart != '{') ++cstart;
		if (cstart == comment + clen) continue;
		//std::cout << cstart << std::endl;
		std::stringstream cstream(cstart);
		cstream >> root;
		assert(root.type() == Json::ValueType::objectValue);
		bind_text(insert, 1, root, "name", Json::nullValue);
		bind_text(insert, 2, root, "link_id");
		bind_text(insert, 3, root, "created_utc");
		sqlite3_bind_int64(insert, 4, root.get("ups", 0).asInt64());
		sqlite3_bind_int64(insert, 5, root.get("downs", 0).asInt64());
		sqlite3_bind_int64(insert, 6, root.get("gilded", 0).asInt64());
		bind_text(insert, 7, root, "author");
		sqlite3_bind_int64(insert, 8, root.get("score", 0).asInt64());
		bind_text(insert, 9, root, "subreddit");
		bind_text(insert, 10, root, "subreddit_id");
		bind_text(insert, 11, root, "parent_id", Json::nullValue);
		bind_text(insert, 12, root, "author_flair_text", Json::nullValue);
		bind_text(insert, 13, root, "body");
		rc = sqlite3_step(insert);
		assert(rc == SQLITE_DONE);
		sqlite3_reset(insert);
	}

	sqlite3_finalize(insert);

	sqlite3_close(db);
}
示例#2
0
/*get limits from < >*/
void PredicateBuilder::getConditions(string& conditions, string& first_cond, string& second_cond) {
	stringstream cstream(conditions);
	getline(cstream, first_cond, '<');
	getline(cstream, second_cond);
}
示例#3
0
std::vector<ModelObj::Mesh>::iterator meshCommandRead(std::vector<ModelObj::Model>::iterator modelIter, std::vector<ModelObj::Mesh>::iterator meshIter, const std::string command, const std::string content, const int currentLine)
{
    //count elements in content
    const int count = countElements(content);
    //check what type the face has
    ModelObj::PrimitiveType foundType = primitiveType(command, content, currentLine);
    //compare to type of current mesh
    if (foundType != meshIter->primitiveType || foundType == ModelObj::LINE_STRIP || foundType == ModelObj::POLYGON) {
        //the mesh already has a mesh type, but it isn't the same, switch to next mesh
        //if it is LINE_STRIP or POLYGON we need to switch to a new mesh anyway, 
        //because otherwise the line strips or polygons would be connected...
        meshIter++;
    }
    //read data from command
    //create stream object from string
    std::istringstream cstream(content);
    while (!cstream.eof()) {
        //retrieve first element
        std::string element;
        cstream >> element;
        //count how many parts (vertex/texcoord/normal) this has. all following elements have to have the same
        //no '/'   --> only vertex index
        //one '/'  --> vertex and texture index
        //one "//" --> vertex and normal index
        //two '/'  --> vertex, texture and normal index
        bool hasNormals = false;
        bool hasTextures = false;
        if (element.find("//") != std::string::npos) {
            hasNormals = true;
        }
        else if (element.find("/") != std::string::npos) {
            hasTextures = true;
            if (element.find("/") != element.rfind("/")) {
                hasNormals = true;
            }
        }
        //now we can allocate the index array as now we know which elements actually exist
        bool wasAllocation = false;
        if (NULL == meshIter->vertexIndices) {
            meshIter->vertexIndices = new int[meshIter->nrOfIndices];
            wasAllocation = true;
        }
        if (hasNormals) {
            if (NULL == meshIter->normalIndices) {
                meshIter->normalIndices = new int[meshIter->nrOfIndices];
                wasAllocation = true;
            }
        }
        if (hasTextures) {
            if (NULL == meshIter->textureIndices) {
                meshIter->textureIndices = new int[meshIter->nrOfIndices];
                wasAllocation = true;
            }
        }
        if (wasAllocation) {
            //this is the first element of the mesh, clear counters
            meshIter->nrOfIndices = 0;
            meshIter->nrOfPrimitives = 0;
        }
        //now get elements from stream
        cstream.clear();
        cstream.seekg(0, std::ios::beg);
        while (!cstream.eof()) {
            int value = 0;
            cstream >> element;
            std::istringstream estream(element);
            //get vertex index
            estream >> value;
            meshIter->vertexIndices[meshIter->nrOfIndices] = value - 1;
            //if this has a texture coordinate read it
            if (hasTextures) {
                //discard '/'
                estream.ignore(1, '/');
                //read texture coord
                estream >> value;
                meshIter->textureIndices[meshIter->nrOfIndices] = value - 1;
                if (hasNormals) {
                    //discard '/'
                    estream.ignore(1, '/');
                    //read normal
                    estream >> value;
                    meshIter->normalIndices[meshIter->nrOfIndices] = value - 1;
                }
            }
            else {
                if (hasNormals) {
                    //discard '//'
                    estream.ignore(1, '/');
                    estream.ignore(1, '/');
                    //read normal
                    estream >> value;
                    meshIter->normalIndices[meshIter->nrOfIndices] = value - 1;
                }
            }
            meshIter->nrOfIndices++;
        }
    }
示例#4
0
void FitSignals(TTree * treeB, TCut cut, Int_t max){
  AliSignalProcesor proc;
  TF1 * f1 = proc.GetAsymGauss();
  TTreeSRedirector cstream("FitSignal.root");
  TFile *f = cstream.GetFile();

  char lname[100];
  sprintf(lname,"Fit%s", cut.GetTitle());
  TEventList *list = new TEventList(lname,lname);
  sprintf(lname,">>Fit%s", cut.GetTitle());
  treeB->Draw(lname,cut);
  treeB->SetEventList(list);
  Int_t nFits=0;
  for (Int_t ievent=0; ievent<list->GetN(); ievent++){
    if (nFits>max) break;
    if (nFits%50==0) printf("%d\n",nFits);
    char ename[100];
    sprintf(ename,"Fit%d", ievent);
    Double_t nsample = treeB->Draw("Graph.fY-Mean09:Graph.fX","","",1,ievent);
    Double_t * signal  = treeB->GetV1();
    Double_t * time  = treeB->GetV2();
    Double_t maxpos =0;
    Double_t max = 0;
    for (Int_t ipos = 0; ipos<nsample; ipos++){
      if (signal[ipos]>max){
	max    = signal[ipos];
	maxpos = ipos;
      }
    }

    Int_t first = TMath::Max(maxpos-10,0.);
    Int_t last  = TMath::Min(maxpos+60, nsample);
    //
    f->cd();
    TH1F his(ename,ename,last-first,first,last);
    for (Int_t ipos=0; ipos<last-first; ipos++){
      his.SetBinContent(ipos+1,signal[ipos+first]);
    }
    treeB->Draw("Sector:Row:Pad","","",1,ievent);
    Double_t sector = treeB->GetV1()[0];
    Double_t row    = treeB->GetV2()[0];
    Double_t pad    = treeB->GetV3()[0];
    //    TGraph  graph(last-first,&time[first],&signal[first]);
    f1->SetParameters(0.75*max,maxpos,1.1,0.8,0.25,0.2);
    //    TH1F * his = (TH1F*)graph.GetHistogram();
    his.Fit(f1,"q");
    his.Write(ename);
    gPad->Clear();
    his.Draw();
    gPad->Update();
    Double_t params[6];
    for (Int_t ipar=0; ipar<6; ipar++) params[ipar] = f1->GetParameters()[ipar];
    Double_t chi2 = TFitter::GetFitter()->Chisquare(6,params);
    TMatrixD cov(6,6);
    cov.SetMatrixArray(TFitter::GetFitter()->GetCovarianceMatrix());
    //
    // tail cancellation
    //
    Double_t x0[1000];
    Double_t x1[1000];
    Double_t x2[1000];
    for (Int_t ipos=0; ipos<last-first; ipos++){
      x0[ipos] = signal[ipos+first];
    }
    proc.TailCancelationALTRO1(x0,x1,0.85*0.339,0.09,last-first);
    proc.TailCancelationALTRO1(x1,x2,0.85,0.789,last-first);
    //
    sprintf(ename,"Cancel1_%d", ievent);
    TH1F his1(ename,ename,last-first,first,last);
    for (Int_t ipos=0; ipos<last-first; ipos++){
      his1.SetBinContent(ipos+1,x1[ipos]);
    }
    his1.Write(ename);
    sprintf(ename,"Cancel2_%d", ievent);
    TH1F his2(ename,ename,last-first,first,last);
    for (Int_t ipos=0; ipos<last-first; ipos++){
      his2.SetBinContent(ipos+1,x1[ipos]);
    }
    f1->SetParameters(0.75*max,maxpos,1.1,0.8,0.25,0.2);
    his2.Fit(f1,"q");
    his2.Write(ename);
    Double_t params2[6];
    for (Int_t ipar=0; ipar<6; ipar++) params2[ipar] = f1->GetParameters()[ipar];
    Double_t chi22 = TFitter::GetFitter()->Chisquare(6,params2);    
    TMatrixD cov2(6,6);
    cov2.SetMatrixArray(TFitter::GetFitter()->GetCovarianceMatrix());

    TGraph gr0(last-first, &time[first],x0);
    TGraph gr1(last-first, &time[first],x1);
    TGraph gr2(last-first, &time[first],x2);
    //
    cstream<<"Fit"<<
      "Sector="<<sector<<
      "Row="<<row<<
      "Pad="<<pad<<
      "First="<<first<<
      "Max="<<max<<
      "MaxPos="<<maxpos<<
      "chi2="<<chi2<<
      "chi22="<<chi22<<
      "Cov="<<&cov<<
      "Cov2="<<&cov2<<
      "gr0.="<<&gr0<<
      "gr1.="<<&gr1<<
      "gr2.="<<&gr2<<
      "p0="<<params[0]<<
      "p1="<<params[1]<<
      "p2="<<params[2]<<
      "p3="<<params[3]<<
      "p4="<<params[4]<<
      "p5="<<params[5]<<
      "p02="<<params2[0]<<
      "p12="<<params2[1]<<
      "p22="<<params2[2]<<
      "p32="<<params2[3]<<
      "p42="<<params2[4]<<
      "p52="<<params2[5]<<
      "\n";
    //    delete his;
    nFits++;
  }

}