void IBRTree::CreateLeafInverted() { map<int, vector<int> *>::iterator iter = leaves.begin(); for(;iter != leaves.end(); ++iter) { int leafID = iter->first; vector<int> *p = iter->second; map<int, vector<int> *> inverted; //------------------------------------------------------------------------ //vector<vector<int> *> objectTexts; // remove duplicated words!! one word may occur multiple times at a location vector<set<int> *> objectTexts; //------------------------------------------------------------------------ string leafDoc = subdocFolder + MyTool::IntToString(leafID); ifstream docF(leafDoc.c_str()); string line; while(!docF.eof()) { getline(docF, line); if(line == "") continue; int oid, wid; char c; istringstream iss(line); iss>>oid; set<int> *p = new set<int>(); while(iss>>c>>wid) { p->insert(wid); } objectTexts.push_back(p); } docF.close(); //------------------------------------------------------------------------ vector<int> temp(*p); sort(temp.begin(), temp.end()); //Nodes id read from Rtree is not ordered, but in subdoc they are ordered! map<int, int> mapping; for(unsigned int i=0;i<temp.size(); i++) { mapping[temp[i]] = i; } //------------------------------------------------------------------------ for(unsigned int i=0;i<p->size();i++) //for each object in this leaf node { int nid = (*p)[i]; int idx = mapping[nid]; //get this object's position in the ordered list set<int> *words = objectTexts[idx]; set<int>::iterator wi = words->begin(); for(; wi!=words->end();++wi) //for each word contained in this object { int wordID = *wi; map<int, vector<int> *>::iterator ti = inverted.find(wordID); if(ti != inverted.end()) //------------------------------------------------------------------------ inverted[wordID]->push_back(i); //push_back the original position in the unordered list in R-tree!! //------------------------------------------------------------------------ else { vector<int> *p = new vector<int>(); p->push_back(i); inverted[wordID] = p; } } } ofstream outF( (invertedFolder + MyTool::IntToString(leafID)).c_str()); //write the object's index, instead of its ID£¡ map<int, vector<int> *>::iterator fi; for(fi = inverted.begin(); fi != inverted.end(); ++fi) { outF<<fi->first<<"\t"; vector<int> *p = fi->second; vector<int>::iterator iter = p->begin(); for(; iter != p->end() ; ++iter) outF<<*iter<<","; outF<<endl; } outF.close(); vector<set<int> *>::iterator iter1; for(iter1 = objectTexts.begin(); iter1 != objectTexts.end(); ++iter1) delete *iter1; map<int, vector<int> *>::iterator iter2; for(iter2 = inverted.begin(); iter2 != inverted.end(); ++iter2) delete iter2->second; } }
void computeTimeOT(int nToys, std::string inFile) { srand (time (NULL)); TFile *_file0 = TFile::Open(inFile.c_str(), "read"); TProfile** wf_promed = new TProfile*[5]; wf_promed[0] = (TProfile*)_file0->Get("wf_promed_4"); wf_promed[1] = (TProfile*)_file0->Get("wf_promed_5"); wf_promed[2] = (TProfile*)_file0->Get("wf_promed_6"); wf_promed[3] = (TProfile*)_file0->Get("wf_promed_7"); wf_promed[4] = (TProfile*)_file0->Get("wf_promed_9"); wf_promed[0]->SetDirectory(0); wf_promed[1]->SetDirectory(0); wf_promed[2]->SetDirectory(0); wf_promed[3]->SetDirectory(0); wf_promed[4]->SetDirectory(0); _file0->Delete(); // TH2F** correlation_TvA = new TH2F*[5]; // TH2F** correlation_AvT = new TH2F*[5]; TProfile** correlationTvA = new TProfile*[5]; TProfile** correlationAvT = new TProfile*[5]; for(int iCh=0; iCh<5; ++iCh) { // correlation_TvA[iCh] = new TH2F(Form("correlation_TvA_%d",iCh), "", 10000, 0., 10000., 10000., 0., 1000.); // correlation_AvT[iCh] = new TH2F(Form("correlation_AvT_%d",iCh), "", 10000, 0., 1000., 10000., 0., 10000.); correlationTvA[iCh] = new TProfile(Form("correlationTvA_%d",iCh), "", 10000, 0., 10000.); correlationAvT[iCh] = new TProfile(Form("correlationAvT_%d",iCh), "", 10000, 0., 1000.); } std::vector<float> digiCh[5]; float ampMax[5]; float sampleMax[5]; // std::cout << " >>> nToys = " << nToys << std::endl; for(int iToy=0.; iToy<nToys; ++iToy){ //for(int iToy=0; iToy<1; ++iToy){ if(iToy % 100 == 0) std::cout << " >>> iToy = " << iToy << std::endl; for(int iCh=0; iCh<5; ++iCh){ digiCh[iCh].clear(); ampMax[iCh] = 0.; sampleMax[iCh] = 0.; float randN = int( 10000. * rand() / RAND_MAX); //std::cout << " randN = " << randN << std::endl; for(int iSample=0; iSample<wf_promed[0]->GetNbinsX(); ++iSample){ float value = wf_promed[iCh]->GetBinContent(iSample+1); // std::cout << " wf_promed[iCh]->GetBinContent(iSample+1) = " << wf_promed[iCh]->GetBinContent(iSample+1) << std::endl; digiCh[iCh].push_back(value*randN); if(value < ampMax[iCh]) ampMax[iCh] = value; } float tOT = TimeOverThreshold(20, 800, &(digiCh[iCh]), -1000.); // float tOT = 1; // correlation_TvA[iCh]->Fill(-1. * ampMax[iCh] * randN, tOT); // correlation_AvT[iCh]->Fill(tOT, -1. * ampMax[iCh] * randN); correlationTvA[iCh]->Fill(-1. * ampMax[iCh] * randN, tOT); correlationAvT[iCh]->Fill(tOT, -1. * ampMax[iCh] * randN); } } //// TF1 pippo("pippo", "15 - exp(1 - 0.0005 * (x-2000))", 0, 10000); // TF1* trend = new TF1("trend", "[0] - exp([1] - [2] * (x-[3]))", 2000, 10000); //// TF1* trend = new TF1("trend", "log(x-[0])", 1000, 10000); //// trend->SetParameters(15, 1, 0.0005, 2000); //trend->SetParameters(20, 0.1, 0.005, 2000); /* TCanvas* c1 = new TCanvas(); c1->cd(); correlation[0]->Draw("colz"); correlation[0]->Fit("trend", "R"); */ TFile outF("correlation_timeOT_ampM.root", "recreate"); outF.cd(); for(int iCh=0; iCh<5; ++iCh) { // correlation_TvA[iCh]->Write(); // correlation_AvT[iCh]->Write(); correlationTvA[iCh]->Write(); correlationAvT[iCh]->Write(); } outF.Close(); // return; }
void LogThread::run() { this->running = true; file->open( QIODevice::WriteOnly ); QTextStream outF( this->file ); //outF << ""; while(true) { if(toWrite.empty()) { if(!this->running) break; Radiant::Sleep::sleepMs(1); continue; } std::string write = toWrite.front(); toWrite.pop(); outF << write.c_str(); outF.flush(); } #if 0 this->msleep(7); mutex.lock(); FingerData fd = fingerdata; mutex.unlock(); if(fd.empty()) continue; out << YAML::BeginSeq; out << YAML::BeginMap; out << YAML::Key << "time"; out << YAML::Value << QTime().currentTime().toString("hh:mm:ss:zzz").toStdString(); out << YAML::Key << "fingers"; out << YAML::Value << YAML::BeginSeq; for(FingerData::iterator it = fd.begin(); it != fd.end(); ++it) { out << YAML::BeginMap; out << YAML::Key << "id"; qDebug() << "id" << it->first; out << YAML::Value << it->first; out << YAML::Key << "x"; out << YAML::Value << it->second.x; out << YAML::Key << "y"; out << YAML::Value << it->second.y; qDebug() << it->second.y; out << YAML::EndMap; } out << YAML::EndSeq; out << YAML::EndMap; out << YAML::EndSeq; outF << out.c_str(); outF.flush(); }
void TimeData<T>::print(const std::string& filename) const { std::ofstream outF(filename); if (outF.is_open()) outF << *this; }