void Logger::log(const stringstream& text) { filestream << text.str() << std::endl; }
/// Read one value, whether it is numeric, string or text string CIFReadValue(stringstream &in,char &lastc) { bool vv=false;//very verbose ? string value(""); while(!isgraph(in.peek())) in.get(lastc); while(in.peek()=='#') {//discard these comments for now string tmp; getline(in,tmp); lastc='\r'; while(!isgraph(in.peek())) in.get(lastc); } if(in.peek()=='_') { stringstream errorMsg; errorMsg << "Warning: Trying to read a value but found a new CIF tag !"; obErrorLog.ThrowError(__FUNCTION__, errorMsg.str() , obError); return value; } if(in.peek()==';') {//SemiColonTextField bool warning=!iseol(lastc); if(warning){ stringstream errorMsg; errorMsg << "Warning: Trying to read a SemiColonTextField but last char is not an end-of-line char !"; obErrorLog.ThrowError(__FUNCTION__, errorMsg.str() , obError); } value=""; in.get(lastc); while(in.peek()!=';') { if (in.peek() == '_') { stringstream errorMsg; errorMsg << "Warning: Trying to read a value but found a new CIF tag !"; obErrorLog.ThrowError(__FUNCTION__, errorMsg.str() , obError); warning = true; break; } string tmp; getline(in,tmp); value+=tmp+" "; } if (!warning) in.get(lastc); if(vv) cout<<"SemiColonTextField:"<<value<<endl; if(warning && !vv) cout<<"SemiColonTextField:"<<value<<endl; return value; } if((in.peek()=='\'') || (in.peek()=='\"')) {//QuotedString char delim; in.get(delim); value=""; while(!((lastc==delim)&&(!isgraph(in.peek()))) ) { in.get(lastc); value+=lastc; } if(vv) cout<<"QuotedString:"<<value<<endl; return value.substr(0,value.size()-1); } // If we got here, we have an ordinary value, numeric or unquoted string in>>value; if(vv) cout<<"NormalValue:"<<value<<endl; return value; }
TPad *pad3 = new TPad("pad3","pad3",0.01,0.20,0.99,0.99); TPad *pad4 = new TPad("pad4","pad4",0.01,0.01,0.99,0.20); pad3->Draw(); pad4->Draw(); pad3->cd(); pad3->SetLeftMargin(0.15); pad3->SetFillColor(0); deFrame->GetXaxis()->SetTitleSize(0.05); deFrame->GetXaxis()->SetTitleOffset(0.85); deFrame->GetXaxis()->SetLabelSize(0.04); deFrame->GetYaxis()->SetTitleOffset(1.6); deFrame->Draw(); stringstream out1; TPaveText *pt = new TPaveText(0.6,0.75,0.98,0.9,"brNDC"); pt->SetFillColor(0); pt->SetTextAlign(12); out1.str(""); out1 << "#chi^{2}/n.d.f = " << deFrame->chiSquare(); pt->AddText(out1.str().c_str()); out1.str(""); if(!type) out1 << "S: " << (int)(nsig+0.5) << " #pm " << (int)(nsig_err_total+0.5); else out1 << "S: " << (int)(nsigEl+0.5) << " #pm " << (int)(nsig_errEl_total+0.5); pt->AddText(out1.str().c_str()); out1.str(""); if(!type) out1 << "Purity: " << std::fixed << std::setprecision(2) << purity*100. << " #pm " << purity_err*100; else out1 << "Purity: " << std::fixed << std::setprecision(2) << purityEl*100. << " #pm " << purity_errEl*100; pt->AddText(out1.str().c_str()); pt->Draw();
bool handleRESTQuery( const std::string& ns, const std::string& action, BSONObj & params, int & responseCode, stringstream & out ) { Timer t; int html = _getOption( params["html"] , 0 ); int skip = _getOption( params["skip"] , 0 ); int num = _getOption( params["limit"] , _getOption( params["count" ] , 1000 ) ); // count is old, limit is new int one = 0; if ( params["one"].type() == String && tolower( params["one"].valuestr()[0] ) == 't' ) { num = 1; one = 1; } BSONObjBuilder queryBuilder; BSONObjIterator i(params); while ( i.more() ) { BSONElement e = i.next(); string name = e.fieldName(); if ( name.find( "filter_" ) != 0 ) continue; string field = name.substr(7); const char * val = e.valuestr(); char * temp; // TODO: this is how i guess if something is a number. pretty lame right now double number = strtod( val , &temp ); if ( temp != val ) queryBuilder.append( field , number ); else queryBuilder.append( field , val ); } BSONObj query = queryBuilder.obj(); auto_ptr<DBClientCursor> cursor = db.query( ns.c_str() , query, num , skip ); uassert( 13085 , "query failed for dbwebserver" , cursor.get() ); if ( one ) { if ( cursor->more() ) { BSONObj obj = cursor->next(); out << obj.jsonString(Strict,html?1:0) << '\n'; } else { responseCode = 404; } return html != 0; } if( html ) { string title = string("query ") + ns; out << start(title) << p(title) << "<pre>"; } else { out << "{\n"; out << " \"offset\" : " << skip << ",\n"; out << " \"rows\": [\n"; } int howMany = 0; while ( cursor->more() ) { if ( howMany++ && html == 0 ) out << " ,\n"; BSONObj obj = cursor->next(); if( html ) { if( out.tellp() > 4 * 1024 * 1024 ) { out << "Stopping output: more than 4MB returned and in html mode\n"; break; } out << obj.jsonString(Strict, html?1:0) << "\n\n"; } else { if( out.tellp() > 50 * 1024 * 1024 ) // 50MB limit - we are using ram break; out << " " << obj.jsonString(); } } if( html ) { out << "</pre>\n"; if( howMany == 0 ) out << p("Collection is empty"); out << _end(); } else { out << "\n ],\n\n"; out << " \"total_rows\" : " << howMany << " ,\n"; out << " \"query\" : " << query.jsonString() << " ,\n"; out << " \"millis\" : " << t.millis() << '\n'; out << "}\n"; } return html != 0; }
void ReplSetImpl::_summarizeAsHtml(stringstream& s) const { s << table(0, false); s << tr("Set name:", _name); s << tr("Majority up:", elect.aMajoritySeemsToBeUp()?"yes":"no" ); // lag const Member *primary = box.getPrimary(); if (primary != 0 && primary != _self && !iAmArbiterOnly() && !lastOpTimeWritten.isNull()) { int lag = primary->hbinfo().opTime.getSecs() - lastOpTimeWritten.getSecs(); s << tr("Lag: ", str::stream() << lag << " secs"); } s << _table(); const char *h[] = {"Member", "<a title=\"member id in the replset config\">id</a>", "Up", "<a title=\"length of time we have been continuously connected to the other member with no reconnects (for self, shows uptime)\">cctime</a>", "<a title=\"when this server last received a heartbeat response - includes error code responses\">Last heartbeat</a>", "Votes", "Priority", "State", "Messages", "<a title=\"how up to date this server is. this value polled every few seconds so actually lag is typically much lower than value shown here.\">optime</a>", "<a title=\"Not replication lag. Clock skew in seconds relative to this server. Informational; server clock variances will make the diagnostics hard to read, but otherwise are benign.\">clock skew</a>", 0 }; s << table(h); /* this is to sort the member rows by their ordinal _id, so they show up in the same order on all the different web ui's; that is less confusing for the operator. */ map<int,string> mp; string myMinValid; try { readlocktry lk(/*"local.replset.minvalid", */300); if( lk.got() ) { BSONObj mv; if( Helpers::getSingleton("local.replset.minvalid", mv) ) { myMinValid = "minvalid:" + mv["ts"]._opTime().toString(); } } else myMinValid = "."; } catch(...) { myMinValid = "exception fetching minvalid"; } const Member *_self = this->_self; verify(_self); { stringstream s; /* self row */ s << tr() << td(_self->fullName() + " (me)") << td(_self->id()) << td("1") << //up td(ago(serverGlobalParams.started)) << td("") << // last heartbeat td(ToString(_self->config().votes)) << td(ToString(_self->config().priority)) << td( stateAsHtml(box.getState()) + (_self->config().hidden?" (hidden)":"") ); s << td( _hbmsg ); stringstream q; q << "/_replSetOplog?_id=" << _self->id(); s << td( a(q.str(), myMinValid, theReplSet->lastOpTimeWritten.toString()) ); s << td(""); // skew s << _tr(); mp[_self->hbinfo().id()] = s.str(); } Member *m = head(); while( m ) { stringstream s; m->summarizeMember(s); mp[m->hbinfo().id()] = s.str(); m = m->next(); } for( map<int,string>::const_iterator i = mp.begin(); i != mp.end(); i++ ) s << i->second; s << _table(); }
void PrintHelper::padString(stringstream& ss, int len) { while (ss.str().length() < len) { ss << " "; } }
void ReplSetImpl::_getOplogDiagsAsHtml(unsigned server_id, stringstream& ss) const { const Member *m = findById(server_id); if( m == 0 ) { ss << "Error : can't find a member with id: " << server_id << '\n'; return; } ss << p("Server : " + m->fullName() + "<br>ns : " + rsoplog ); //const bo fields = BSON( "o" << false << "o2" << false ); const bo fields; /** todo fix we might want an so timeout here */ OplogReader reader; if (reader.connect(m->fullName()) == false) { ss << "couldn't connect to " << m->fullName(); return; } reader.query(rsoplog, Query().sort("$natural",1), 20, 0, &fields); if ( !reader.haveCursor() ) { ss << "couldn't query " << rsoplog; return; } static const char *h[] = {"ts","optime","h","op","ns","rest",0}; ss << "<style type=\"text/css\" media=\"screen\">" "table { font-size:75% }\n" // "th { background-color:#bbb; color:#000 }\n" // "td,th { padding:.25em }\n" "</style>\n"; ss << table(h, true); //ss << "<pre>\n"; int n = 0; OpTime otFirst; OpTime otLast; OpTime otEnd; while( reader.more() ) { bo o = reader.next(); otLast = o["ts"]._opTime(); if( otFirst.isNull() ) otFirst = otLast; say(ss, o); n++; } if( n == 0 ) { ss << rsoplog << " is empty\n"; } else { reader.query(rsoplog, Query().sort("$natural",-1), 20, 0, &fields); if( !reader.haveCursor() ) { ss << "couldn't query [2] " << rsoplog; return; } string x; bo o = reader.next(); otEnd = o["ts"]._opTime(); while( 1 ) { stringstream z; if( o["ts"]._opTime() == otLast ) break; say(z, o); x = z.str() + x; if( !reader.more() ) break; o = reader.next(); } if( !x.empty() ) { ss << "<tr><td>...</td><td>...</td><td>...</td><td>...</td><td>...</td></tr>\n" << x; //ss << "\n...\n\n" << x; } } ss << _table(); ss << p(time_t_to_String_short(time(0)) + " current time"); if( !otEnd.isNull() ) { ss << "<p>Log length in time: "; unsigned d = otEnd.getSecs() - otFirst.getSecs(); double h = d / 3600.0; ss.precision(3); if( h < 72 ) ss << h << " hours"; else ss << h / 24.0 << " days"; ss << "</p>\n"; } }
int main(int argc, char *argv[]) { ss << "#include \"SgGraphTemplate.h\"\n"; ss << "#include \"graphProcessing.h\"\n"; ss << "#include \"staticCFG.h\"\n"; ss << "using namespace std;\n"; ss << "using namespace boost;\n"; //ss << "set<vector<string> > sssv;\n"; //ss << "vector<string> sss;\n"; ss << "typedef myGraph CFGforT;\n"; SgProject* proj = frontend(argc,argv); ROSE_ASSERT (proj != NULL); SgFunctionDeclaration* mainDefDecl = SageInterface::findMain(proj); SgFunctionDefinition* mainDef = mainDefDecl->get_definition(); visitorTraversal* vis = new visitorTraversal(); StaticCFG::CFG cfg(mainDef); // stringstream ss; string fileName= StringUtility::stripPathFromFileName(mainDef->get_file_info()->get_filenameString()); string Cfilename = fileName+"."+ mainDef->get_declaration()->get_name() +"test.C"; // cfgToDot(mainDef,dotFileName1); //cfg->buildFullCFG(); SgIncidenceDirectedGraph* g = new SgIncidenceDirectedGraph(); g = cfg.getGraph(); myGraph* mg = new myGraph(); mg = instantiateGraph(g, cfg); //vis->constructPathAnalyzer(mg, true, 0, 0, true); // std::cout << "took: " << timeDifference(t2, t1) << std::endl; //cfg.clearNodesAndEdges(); //std::cout << "finished" << std::endl; // std::cout << "tltnodes: " << vis->tltnodes << " paths: " << vis->paths << std::endl; // delete vis; //} ss << "class visitorTraversal : public SgGraphTraversal<CFGforT>\n"; ss << " {\n"; ss << " public:\n"; ss << " vector<string> sss;\n"; ss << " set<vector<string> > sssv;\n"; //vis->constructPathAnalyzer(mg, true, 0, 0, true); ss << " void analyzePath(std::vector<VertexID>& pth);\n"; ss << " SgIncidenceDirectedGraph* g;\n"; ss << " myGraph* orig;\n"; ss << " StaticCFG::CFG* cfg;\n"; ss << " std::vector<std::vector<string> > paths;\n"; ss << " };\n"; ss << "void visitorTraversal::analyzePath(std::vector<VertexID>& pathR) {\n"; ss << " std::vector<string> path;\n"; ss << " for (unsigned int j = 0; j < pathR.size(); j++) {\n"; ss << " SgGraphNode* R = getGraphNode[pathR[j]];\n"; ss << " CFGNode cf = cfg->toCFGNode(R);\n"; ss << " string str = cf.toString();"; ss << "str.erase(std::remove(str.begin(), str.end(), '\\n'), str.end());\n"; ss << " path.push_back(str);\n"; ss << " }\n"; ss << " paths.push_back(path);\n"; ss << " // ROSE_ASSERT(sssv.find(path) != sssv.end());\n"; ss << "}\n"; //ss << "set<vector<string> > sssv;\n"; ss << "int main(int argc, char *argv[]) {\n"; ss << "SgProject* proj = frontend(argc,argv);\n"; ss << "ROSE_ASSERT (proj != NULL);\n"; ss << "SgFunctionDeclaration* mainDefDecl = SageInterface::findMain(proj);\n"; ss << "SgFunctionDefinition* mainDef = mainDefDecl->get_definition();\n"; ss << "visitorTraversal* vis = new visitorTraversal();\n"; ss << "StaticCFG::CFG cfg(mainDef);\n"; ss << "stringstream ss;\n"; ss << "string fileName= StringUtility::stripPathFromFileName(mainDef->get_file_info()->get_filenameString());\n"; ss << "string dotFileName1=fileName+\".\"+ mainDef->get_declaration()->get_name() +\".dot\";\n"; ss << "cfgToDot(mainDef,dotFileName1);\n"; ss << "SgIncidenceDirectedGraph* g = new SgIncidenceDirectedGraph();\n"; ss << "g = cfg.getGraph();\n"; ss << "myGraph* mg = new myGraph();\n"; ss << "mg = instantiateGraph(g, cfg);\n"; //ss << "vis->tltnodes = 0;\n"; //ss << "vis->paths = 0;\n"; ss << "std::set<std::vector<string> > sssv;\n"; ss << "std::vector<string> sss;\n"; vis->constructPathAnalyzer(mg, true, 0, 0, true); ss << "vis->sssv = sssv;\n"; ss << "vis->constructPathAnalyzer(mg, true, 0, 0, true);\n"; ss << "ROSE_ASSERT(vis->sssv.size() == vis->paths.size());\n"; ss << "std::cout << \"finished\" << std::endl;\n"; ss << "std::cout << \" paths: \" << vis->paths.size() << std::endl;\n"; ss << "delete vis;\n"; ss << "}\n"; string sst = ss.str(); ofstream myfile; myfile.open(Cfilename.c_str()); myfile << sst; myfile.close(); delete vis; return 0; }
s >> hex >> u.i; ios::iostate state = s.rdstate(); if ((state & ios::failbit) || (state & ios::badbit)) { throw (int)-1; } v_out = u.f; } catch (...) { string message = "Cannot convert HEX value [" + str + "] to a double"; throw Isis::iException::Message(Isis::iException::Parse,message, _FILEINFO_); } } // Convert a decimal value else { try { stringstream s; s << str; // Put the string into a stream s.seekg(0, ios::beg); // Move the input pointer to the beginning s >> v_out; // read/get "type T" out of the stream ios::iostate state = s.rdstate(); if ((state & ios::failbit) || (state & ios::badbit) || (!(state & ios::eofbit))) { // Make sure the stream is empty throw (int)-1; } } catch (...) { string message = "Cannot convert [" + str + "] to a double"; throw Isis::iException::Message(Isis::iException::Parse,message, _FILEINFO_); } } return(v_out);
int check_for_message(int sock) { static char * data=0; int message_length, sender; if(!data) data = new char[MAXMSGSIZE+1]; MessageType type = get_message(sock, &data, message_length, &sender); if(type==NO_MESSAGE) return 0; //printf("organism recvd %i from %i\n", type, sender); if(type == SOUND) { char * msg = getStringFromData(data, message_length); //printf("%i) I hear sound %s length %i\n", myPort, msg, message_length); delete [] msg; if(sender!=myPort) { /*ignore sounds from myself*/ myNet.feedInput(data, message_length, "ear"); usleep(200); myNet.addClick(); usleep(200); myGenome.transcribeGene("//encourage_auditory", 2, genome_file, portstr.str().c_str()); } } else if(type == VISION) { //printf("start vision\n"); if(message_length<=0) { organism_of_focus=worldPort; if(success(30)) { char data[2]={60,0}; send_message(myPort, worldPort, TURN, 1, data); usleep(1600); } } else { memcpy(&organism_of_focus, data, sizeof(int)); myNet.feedInput(data, message_length, "eye"); char * dx_str = &data[sizeof(int)]; float dx; memcpy(&dx, dx_str, sizeof(float)); /*if(myPort==49153) { printf("%i at %g\n", organism_of_focus, dx); }*/ if(dx<2.0) { if(std::find(children.begin(), children.end(), organism_of_focus) == children.end()) { stringstream destination_str; destination_str<<organism_of_focus; myGenome.transcribeGene("//eat", 2, portstr.str().c_str(), destination_str.str().c_str()); } } //printf("%i focus on %i dx %g\n", myPort, organism_of_focus, dx); } //printf("end vision\n"); } else if(type == EAT) { int victim; memcpy(&victim, data, sizeof(int)); if(victim==myPort) { /*printf("I'm being eaten\n");*/ } else { myNet.reward("eat", 0.5); } } else if(type == KILL) { //printf("%i received kill message\n", myPort); exit(0); } else if(type == MATE) { if(sender == worldPort) { /*mate directive*/ if(organism_of_focus==worldPort) { /*I can't see anybody, mate with self*/ stringstream child_file; child_file<<genome_file<<n_children; myGenome.transcribeGene("//asexual_reproduction", 4, portstr.str().c_str(), genome_file, child_file.str().c_str(), worldportstr.str().c_str()) ; } else { /*transmit request to potential mate*/ printf("%i) send mate request to %i\n", myPort, organism_of_focus); send_message(myPort, organism_of_focus, MATE, strlen(genome_file), genome_file); } } else { /*the message came from a potential mate*/ char * mate_genome = getStringFromData(data, message_length); printf("%i) received mate request from %i (%s)\n", myPort, sender, mate_genome); stringstream child_file; child_file<<genome_file<<n_children; myGenome.transcribeGene("//sexual_reproduction", 5, portstr.str().c_str(), genome_file, mate_genome, child_file.str().c_str(), worldportstr.str().c_str()) ; } } else if(type == NEW_ORGANISM) { int child_id; memcpy(&child_id, data, sizeof(int)); children.push_back(child_id); n_children++; } else if(type == DISPLAY) { myNet.printStats(1); } else if(type == SAVE) { char * filename = getStringFromData(data, message_length); stringstream cmd; cmd<<"cp "<<genome_file<<" "<<filename; system(cmd.str().c_str()); } return 1; }
int main (int argc, char * argv[]) { worldportstr << worldPort; if(argc<2) return 1; genome_file = argv[1]; if(!genome_file) return 1; myGenome.attachFile(genome_file); if(argc>2) myPort=atoi(argv[2]); portstr << myPort; int sock = UDP_bind(myPort); //printf("my file is %s waiting on port %i\n", genome_file, myPort); myGenome.transcribeGene("//green_appearance", 1, portstr.str().c_str()); srandom(100); stringstream net_file; net_file<<genome_file<<"."<<myPort<<".net"; myNet.name = net_file.str(); myNet.saveToFile(net_file.str().c_str()); myGenome.transcribeGene("//add_eye", 2, genome_file, portstr.str().c_str()); myGenome.transcribeGene("//add_eye", 2, genome_file, portstr.str().c_str()); myGenome.transcribeGene("//add_auditory", 2, genome_file, portstr.str().c_str()); myGenome.transcribeGene("//add_reproduction", 2, genome_file, portstr.str().c_str()); myGenome.transcribeGene("//add_movement", 2, genome_file, portstr.str().c_str()); myGenome.transcribeGene("//add_turn", 2, genome_file, portstr.str().c_str()); myGenome.transcribeGene("//connect_subnets", 2, genome_file, portstr.str().c_str()); myNet.loadFromFile(net_file.str().c_str()); myNet.printStats(); //printf("body\n"); stringstream child_file; child_file<<genome_file<<n_children; //myGenome.transcribeGene("//asexual_reproduction", 4, portstr.str().c_str(), genome_file, child_file.str().c_str(), worldportstr.str().c_str()); int n=4; while(1) { try { int status; while (waitpid(-1, &status, WNOHANG)>0); int nMessages=0; do { nMessages = check_for_message(sock); } while (nMessages>0); myNet.addClick(); map<string,int>output_length; map<string,unsigned char*>output_data; myNet.getOutput(output_length, output_data); myGenome.transcribeGeneIfSubnetFires(output_length, output_data, "talk", 0.25, "//say", 1, portstr.str().c_str()) ; myGenome.transcribeGeneIfSubnetFires(output_length, output_data, "move", 0.2, "//move", 1, portstr.str().c_str()) ; myGenome.transcribeGeneIfSubnetFires(output_length, output_data, "turn", 0.1, "//turn", 1, portstr.str().c_str()) ; myGenome.transcribeGeneIfSubnetFires(output_length, output_data, "attack", 0.1, "//attack", 1, portstr.str().c_str()) ; myGenome.transcribeGeneIfSubnetFires(output_length, output_data, "eat", 0.2, "//eat", 1, portstr.str().c_str()) ; stringstream child_file; child_file<<genome_file<<n_children; myGenome.transcribeGeneIfSubnetFires(output_length, output_data, "reproduction", 0.33, "//asexual_reproduction", 4, portstr.str().c_str(), genome_file, child_file.str().c_str(), worldportstr.str().c_str()) ; usleep(1000); //sleep(2); } catch (...) { printf("organism %i error\n", myPort); } } close (sock); return 1; }