Beispiel #1
0
TDateWnd::TDateWnd(const TTm& StartTm, const TTm& EndTm, const int& _WndSize, 
        const TTmUnit& _TmUnit, const bool& _NormalizeP): InitP(true),
            WndSize(_WndSize), TmUnit(_TmUnit), NormalizeP(_NormalizeP) {

    EAssert(WndSize > 0);
    // use borders to construct time boundaries
    Update(StartTm);
    Update(EndTm);
    // initialize feature vector weight
    InitWgt();
}
Beispiel #2
0
int main(int argc, char* argv[]) {
  Env = TEnv(argc, argv, TNotify::StdNotify);
  Env.PrepArgs(TStr::Fmt("Motifs. build: %s, %s. Time: %s", __TIME__, __DATE__, TExeTm::GetCurTm()));
  TExeTm ExeTm;
  Try
  
  const TStr InFNm = Env.GetIfArgPrefixStr("-i:", "../as20graph.txt", "Input directed graph file (single directed edge per line)");
  const int MotifSz = Env.GetIfArgPrefixInt("-m:", 3, "Motif size (has to be 3 or 4)");
  const bool DrawMotifs = Env.GetIfArgPrefixBool("-d:", true, "Draw motif shapes (requires GraphViz)");
  TStr OutFNm = Env.GetIfArgPrefixStr("-o:", "", "Output file prefix");
  if (OutFNm.Empty()) { OutFNm = InFNm.GetFMid(); }
  EAssert(MotifSz==3 || MotifSz==4);

  // load graph
  PNGraph G;
  if (InFNm.GetFExt().GetLc()==".ungraph") {
    TFIn FIn(InFNm);  G=TSnap::ConvertGraph<PNGraph>(TUNGraph::Load(FIn), true); }
  else if (InFNm.GetFExt().GetLc()==".ngraph") {
    TFIn FIn(InFNm);  G=TNGraph::Load(FIn); }
  else {
    G = TSnap::LoadEdgeList<PNGraph>(InFNm, 0, 1); }
  bool IsOk = true;
  for (int nid = 0; nid < G->GetNodes(); nid++) {
    if (! G->IsNode(nid)) { IsOk=false; break; } }
  if (! IsOk) {
    printf("Nodes of the input graph have to be numbered 0...N-1\nRenumbering nodes...\n"); 
    PNGraph OG = G; G = TNGraph::New();
    TGraphEnumUtils::GetNormalizedGraph(OG, G);
  }
  // G = TSnap::GenRndGnm<PNGraph>(100, Kilo(1));
  
  // count frequency of connected subgraphs in G that have MotifSz nodes
  TD34GraphCounter GraphCounter(MotifSz);
  TSubGraphEnum<TD34GraphCounter> GraphEnum;
  GraphEnum.GetSubGraphs(G, MotifSz, GraphCounter);
  FILE *F = fopen(TStr::Fmt("%s-counts.tab", OutFNm.CStr()).CStr(), "wt");
  fprintf(F, "MotifId\tNodes\tEdges\tCount\n");
  for (int i = 0; i < GraphCounter.Len(); i++) {
    const int gid = GraphCounter.GetId(i);
    PNGraph SG = GraphCounter.GetGraph(gid);
    if (DrawMotifs) {
      TGraphViz::Plot(SG, gvlNeato, TStr::Fmt("%s-motif%03d.gif", OutFNm.CStr(), i), 
        TStr::Fmt("GId:%d  Count: %llu", gid, GraphCounter.GetCnt(gid)));
    }
    fprintf(F, "%d\t%d\t%d\t%llu\n", gid, SG->GetNodes(), SG->GetEdges(), GraphCounter.GetCnt(gid));
  }
  printf("done.");
  fclose(F); 
  
  Catch
  printf("\nrun time: %s (%s)\n", ExeTm.GetTmStr(), TSecTm::GetCurTm().GetTmStr().CStr());
  return 0;
}
void TThread::Start() {
    // create new thread
	int code = pthread_create(
			&ThreadHandle,	// Handle
			NULL,			// Attributes
			EntryPoint,		// Thread func
			this			// Arg
	);
	EAssert(code == 0);


}
Beispiel #4
0
TBlobPt TGBlobBs::PutBlob(const PSIn& SIn){
  EAssert((Access==faCreate)||(Access==faUpdate)||(Access==faRestore));
  int BfL=SIn->Len();
  int MxBfL; int FFreeBlobPtN;
  GetAllocInfo(BfL, BlockLenV, MxBfL, FFreeBlobPtN);
  TBlobPt BlobPt; TCs Cs;
  if (FFreeBlobPtV[FFreeBlobPtN].Empty()){
    int FLen=FBlobBs->GetFLen();
    if (FLen<=MxSegLen){
      EAssert(FLen<=MxBlobFLen);
      BlobPt=TBlobPt(FLen);
      FBlobBs->SetFPos(BlobPt.GetAddr());
      PutBlobTag(FBlobBs, btBegin);
      FBlobBs->PutInt(MxBfL);
      PutBlobState(FBlobBs, bsActive);
      FBlobBs->PutInt(BfL);
      FBlobBs->PutSIn(SIn, Cs);
      FBlobBs->PutCh(TCh::NullCh, MxBfL-BfL);
      FBlobBs->PutCs(Cs);
      PutBlobTag(FBlobBs, btEnd);
    }
  } else {
    BlobPt=FFreeBlobPtV[FFreeBlobPtN];
    FBlobBs->SetFPos(BlobPt.GetAddr());
    AssertBlobTag(FBlobBs, btBegin);
    int MxBfL=FBlobBs->GetInt();
    int FPos=FBlobBs->GetFPos();
    AssertBlobState(FBlobBs, bsFree);
    FFreeBlobPtV[FFreeBlobPtN]=TBlobPt::LoadAddr(FBlobBs);
    FBlobBs->SetFPos(FPos);
    PutBlobState(FBlobBs, bsActive);
    FBlobBs->PutInt(BfL);
    FBlobBs->PutSIn(SIn, Cs);
    FBlobBs->PutCh(TCh::NullCh, MxBfL-BfL);
    FBlobBs->PutCs(Cs);
    AssertBlobTag(FBlobBs, btEnd);
  }
  FBlobBs->Flush();
  return BlobPt;
}
Beispiel #5
0
void TThread::Start() {
    // create new thread
    ThreadHandle = CreateThread(
        NULL,                   // default security attributes
        0,                      // use default stack size
        EntryPoint,             // thread function
        this,                   // argument to thread function
        0,                      // use default creation flags
        &ThreadId);             // returns the thread identifier

    // make sure all ok so far...
    EAssert(ThreadHandle != NULL);
}
Beispiel #6
0
void TSASFunRedirect::Exec(const TStrKdV& FldNmValPrV, const PSAppSrvRqEnv& RqEnv) {
    PUrl Url = RqEnv->GetHttpRq()->GetUrl();
    TStr FunNm = (Url->GetPathSegs() > 1) ? Url->GetPathSeg(1) : "";
	EAssert(MapH.IsKey(FunNm));
	const TRedirect& Redirect =  MapH.GetDat(FunNm);
	TStrKdV _FldNmValPrV = Redirect.FldNmValPrV;
	for (int FldN = 0; FldN < FldNmValPrV.Len(); FldN++) {
		TStr OrgFldNm = FldNmValPrV[FldN].Key;
		if (Redirect.FldNmMapH.IsKey(OrgFldNm)) {
			_FldNmValPrV.Add(TStrKd(Redirect.FldNmMapH.GetDat(OrgFldNm), FldNmValPrV[FldN].Dat));
		}
	}
	RqEnv->ExecFun(Redirect.FunNm, _FldNmValPrV);
}
Beispiel #7
0
void TBlobBs::GenBlockLenV(TIntV& BlockLenV){
  BlockLenV.Clr();
  for (int P2Exp=0; P2Exp<TB4Def::MxP2Exp; P2Exp++){
    BlockLenV.Add(TInt(TB4Def::GetP2(P2Exp)));}
  EAssert(int(BlockLenV.Last())<2000000000);

  {for (int Len=10; Len<100; Len+=10){BlockLenV.Add(Len);}}
  {for (int Len=100; Len<10000; Len+=100){BlockLenV.Add(Len);}}
  {for (int Len=10000; Len<100000; Len+=1000){BlockLenV.Add(Len);}}
  {for (int Len=100000; Len<1000000; Len+=25000){BlockLenV.Add(Len);}}
  {for (int Len=1000000; Len<10000000; Len+=1000000){BlockLenV.Add(Len);}}
  {for (int Len=10000000; Len<100000000; Len+=10000000){BlockLenV.Add(Len);}}

  BlockLenV.Sort();
}
Beispiel #8
0
uint TYL40Adc::Read(const int& InputN) {
	TLock Lock(CriticalSection);

	EAssert(FileDesc >= 0);

	Notify->OnNotifyFmt(TNotifyType::ntInfo, "Reading YL-40 input %d ...", InputN);
	SetInput(InputN);

	uchar Val;
	int Read;
	for (int ReadN = 0; ReadN < 2; ReadN++) {
		Read = read(FileDesc, &Val, 1);
		EAssertR(Read == 1, "Failed to read YL-40!");
		usleep(PROCESSING_DELAY);
	}

	return (uint) Val;
}
Beispiel #9
0
/// Create new page and return pointers to it
void TPgBlob::CreateNewPage(TPgBlobPgPt& Pt, char** Bf) {
    // determine if last file is empty
    if (Files.Len() > 0) {
        // try to add to last file
        long Pg = Files.Last()->CreateNewPage();
        if (Pg >= 0) {
            Pt.Set(Files.Len() - 1, (uint32)Pg);
            *Bf = LoadPage(Pt, false);
            InitPageP(*Bf);
            return;
        }
    }
    TStr NewFNm = FNm + ".bin" + TStr::GetNrNumFExt(Files.Len());
    Files.Add(TPgBlobFile::New(NewFNm, TFAccess::faCreate, MxBlobFLen));
    long Pg = Files.Last()->CreateNewPage();
    EAssert(Pg >= 0);
    Pt.Set(Files.Len() - 1, (uint32)Pg);
    *Bf = LoadPage(Pt, false);
    InitPageP(*Bf);
}
Beispiel #10
0
/// Add given buffer to page, return item-index
uint16 TPgBlob::AddItem(char* Pg, const char* Bf, const int BfL) {
    TPgHeader* Header = (TPgHeader*)Pg;
    EAssert(Header->CanStoreBf(BfL));

    uint16 res = Header->ItemCount;
    TPgBlobPageItem* NewItem = GetItemRec(Pg, Header->ItemCount);
    NewItem->Len = BfL;
    NewItem->Offset = Header->OffsetFreeEnd - BfL;

    if (Bf != NULL) { // only copy when there is some data
        memcpy(Pg + NewItem->Offset, Bf, BfL);
    }

    Header->ItemCount++;
    Header->OffsetFreeEnd -= BfL;
    Header->OffsetFreeStart += sizeof(TPgBlobPageItem);

    Header->SetDirty(true);

    return res;
}
Beispiel #11
0
void TThread::Start() {
    TLock Lck(CriticalSection);

    if (IsAlive()) {
        printf("Tried to start a thread that is already alive! Ignoring ...\n");
        return;
    }
    if (IsCancelled()) {
        return;
    }

    Status = STATUS_STARTED;

    // create new thread
    int code = pthread_create(
                   &ThreadHandle,	// Handle
                   NULL,			// Attributes
                   EntryPoint,		// Thread func
                   this			// Arg
               );
    EAssert(code == 0);
}
Beispiel #12
0
TBlobPt TGBlobBs::PutBlob(const TBlobPt& BlobPt, const PSIn& SIn){
  EAssert((Access==faCreate)||(Access==faUpdate)||(Access==faRestore));
  int BfL=SIn->Len();

  FBlobBs->SetFPos(BlobPt.GetAddr());
  AssertBlobTag(FBlobBs, btBegin);
  int MxBfL=FBlobBs->GetInt();
  AssertBlobState(FBlobBs, bsActive);
  if (BfL>MxBfL){
    DelBlob(BlobPt);
    return PutBlob(SIn);
  } else {
    TCs Cs;
    FBlobBs->PutInt(BfL);
    FBlobBs->PutSIn(SIn, Cs);
    FBlobBs->PutCh(TCh::NullCh, MxBfL-BfL);
    FBlobBs->PutCs(Cs);
    PutBlobTag(FBlobBs, btEnd);
    FBlobBs->Flush();
    return BlobPt;
  }
}
Beispiel #13
0
		// parse from json configuration file
		TJsParam(const TStr& RootFNm, const PJsonVal& JsVal) { 
			EAssertR(JsVal->IsObj(), "Unsupported type: " + TJsonVal::GetStrFromVal(JsVal));
			// we must have at least the script name
			EAssert(JsVal->IsObjKey("file"));
			// get script name				
			FNm = JsVal->GetObjStr("file");
			// get namespace (get from script name if not available)
			Nm = JsVal->IsObjKey("name") ? JsVal->GetObjStr("name") : FNm.GetFMid();
			// get initialization parameters (if available)
			InitVal = JsVal->IsObjKey("init") ? JsVal->GetObjKey("init") : TJsonVal::NewObj();
			// get library include folders
			if (JsVal->IsObjKey("include")) { 
				PJsonVal IncludesVal = JsVal->GetObjKey("include");
				EAssertR(IncludesVal->IsArr(), "Expected array of strings, not: " + TJsonVal::GetStrFromVal(IncludesVal));
				for (int IncludeN = 0; IncludeN < IncludesVal->GetArrVals(); IncludeN++) {
					PJsonVal IncludeVal = IncludesVal->GetArrVal(IncludeN);
					EAssertR(IncludeVal->IsStr(), "Expected string, not: " + TJsonVal::GetStrFromVal(IncludeVal));						
					IncludeFPathV.Add(IncludeVal->GetStr());
				}
			}
			// handle default includes
			AddLocalLibFPath();
			AddQMinerLibFPath();
			// get folders with access permissions
			if (JsVal->IsObjKey("dirs")) { 
				PJsonVal DirsVal = JsVal->GetObjKey("dirs");
				EAssertR(DirsVal->IsArr(), "Expected array of strings, not: " + TJsonVal::GetStrFromVal(DirsVal));
				for (int DirN = 0; DirN < DirsVal->GetArrVals(); DirN++) {
					PJsonVal DirVal = DirsVal->GetArrVal(DirN);
					EAssertR(DirVal->IsStr(), "Expected string, not: " + TJsonVal::GetStrFromVal(DirVal));
					AccessFPathV.Add(DirVal->GetStr());
				}
			}
			// add sandbox access
			AddSandboxAccessFPath(RootFNm);
		}
Beispiel #14
0
int TFtrGenBs::AddFtrGen(const PFtrGen& FtrGen) { 
	EAssert(State == fgsInit);
	return FtrGenV.Add(FtrGen);
}
Beispiel #15
0
//////////////////////////////////////
// Simple-App-Server-Request-Environment
void TSAppSrvRqEnv::ExecFun(const TStr& FunNm, const TStrKdV& FldNmValPrV) { 
	EAssert(FunNmToFunH.IsKey(FunNm));
	FunNmToFunH.GetDat(FunNm)->Exec(FldNmValPrV, this); 
}
Beispiel #16
0
void TJsonVal::GetObjStrV(const char *Key, TStrV& StrV) const {
    EAssert(IsObj());
    EAssert(IsObjKey(Key));
    GetObjKey(Key)->GetArrStrV(StrV);
}
Beispiel #17
0
TStr TJsonVal::GetObjStr(const char *Key, const TStr& DefStr) const { 
  EAssert(IsObj());
  return (IsObjKey(Key)) ? KeyValH.GetDat(Key)->GetStr() : DefStr;
}
Beispiel #18
0
void TJsonVal::GetObjIntV(const TStr& Key, TIntV& IntV) const {
    EAssert(IsObj());
    EAssert(IsObjKey(Key));
    GetObjKey(Key)->GetArrIntV(IntV);
}
Beispiel #19
0
int TJsonVal::GetObjInt(const char *Key, const int& DefInt) const { 
  EAssert(IsObj());
  return (IsObjKey(Key)) ? KeyValH.GetDat(Key)->GetInt() : DefInt;
}
Beispiel #20
0
double TJsonVal::GetObjNum(const char *Key, const double& DefNum) const { 
  EAssert(IsObj());
  return (IsObjKey(Key)) ? KeyValH.GetDat(Key)->GetNum() : DefNum;
}
Beispiel #21
0
bool TJsonVal::GetObjBool(const char *Key, const bool& DefBool) const { 
  EAssert(IsObj());
  return (IsObjKey(Key)) ? KeyValH.GetDat(Key)->GetBool() : DefBool;
}
Beispiel #22
0
PJsonVal TJsonVal::GetObjKey(const char *Key) const {
  EAssert(IsObj());
  EAssertR(IsObjKey(Key), TStr::Fmt("Unknown key '%s'", Key)); 
  return KeyValH.GetDat(Key);
}
Beispiel #23
0
void TJsonVal::GetObjFltV(const TStr& Key, TFltV& FltV) const {
    EAssert(IsObj());
    EAssert(IsObjKey(Key));
    GetObjKey(Key)->GetArrNumV(FltV);
}
Beispiel #24
0
void TJsonVal::AddToObj(const TStr& KeyNm, const PJsonVal& Val) {
  EAssert(JsonValType == jvtObj);
  EAssert(KeyNm != "");
  KeyValH.AddDat(KeyNm, Val);
}
Beispiel #25
0
	void* operator new( size_t nSize, void* ptr )
	{
		EAssert(((ref_ptr)ptr % 16) == 0, "new object error");
		return ptr;
	}
Beispiel #26
0
void TSockSys::AddSockEvent(const PSockEvent& SockEvent) {
	// make sure we don't add empty stuff
	EAssert(!SockEvent.Empty());
	IdToSockEventH.AddDat(SockEvent->GetSockEventId(), SockEvent);
}
Beispiel #27
0
uint64 TZipIn::GetFLen(const TStr& ZipFNm) {
  #ifdef GLib_WIN
  HANDLE ZipStdoutRd, ZipStdoutWr;
  // create pipes
  SECURITY_ATTRIBUTES saAttr;
  saAttr.nLength = sizeof(SECURITY_ATTRIBUTES);
  saAttr.bInheritHandle = TRUE;
  saAttr.lpSecurityDescriptor = NULL;
    // Create a pipe for the child process's STDOUT.
  const int PipeBufferSz = 32*1024;
  EAssertR(CreatePipe(&ZipStdoutRd, &ZipStdoutWr, &saAttr, PipeBufferSz), "Stdout pipe creation failed");
  // Ensure the read handle to the pipe for STDOUT is not inherited.
  SetHandleInformation(ZipStdoutRd, HANDLE_FLAG_INHERIT, 0);
  //CreateZipProcess(GetCmd(FNm), FNm);
  { const TStr CmdLine = TStr::Fmt("7z.exe l \"%s\"", ZipFNm.CStr());
  PROCESS_INFORMATION piProcInfo;
  STARTUPINFO siStartInfo;
  ZeroMemory( &piProcInfo, sizeof(PROCESS_INFORMATION));
  ZeroMemory( &siStartInfo, sizeof(STARTUPINFO));
  siStartInfo.cb = sizeof(STARTUPINFO);
  siStartInfo.hStdOutput = ZipStdoutWr;
  siStartInfo.dwFlags |= STARTF_USESTDHANDLES;
  // Create the child process.
  const BOOL FuncRetn = CreateProcess(NULL, (LPSTR) CmdLine.CStr(),
    NULL, NULL, TRUE, 0, NULL, NULL, &siStartInfo, &piProcInfo);
  EAssertR(FuncRetn!=0, TStr::Fmt("Can not execute '%s'", CmdLine.CStr()).CStr());
  CloseHandle(piProcInfo.hProcess);
  CloseHandle(piProcInfo.hThread); }
  #else
  const TStr CmdLine = TStr::Fmt("7za l %s", ZipFNm.CStr());
  FILE* ZipStdoutRd = popen(CmdLine.CStr(), "r");
  if (ZipStdoutRd == NULL) { // try using SevenZipPath
    ZipStdoutRd = popen((TZipIn::SevenZipPath+"/"+CmdLine).CStr(), "r");
  }
  EAssertR(ZipStdoutRd != NULL, TStr::Fmt("Can not execute '%s'", CmdLine.CStr()).CStr());
  #endif
  // Read output from the child process
  const int BfSz = 32*1024;
  char* Bf = new char [BfSz];
  int BfC=0, BfL=0;
  memset(Bf, 0, BfSz);
  #ifdef GLib_WIN
  DWORD BytesRead;
  EAssert(ReadFile(ZipStdoutRd, Bf, MxBfL, &BytesRead, NULL) != 0);
  #else
  size_t BytesRead = fread(Bf, 1, MxBfL, ZipStdoutRd);
  EAssert(BytesRead != 0);
  EAssert(pclose(ZipStdoutRd) != -1);
  #endif
  BfL = (int) BytesRead;  IAssert((BfC!=0)||(BfL!=0));
  BfC = 0; Bf[BfL] = 0;
  // find file lenght
  TStr Str(Bf);  delete [] Bf;
  TStrV StrV; Str.SplitOnWs(StrV);
  int n = StrV.Len()-1;
  while (n > 0 && ! StrV[n].StartsWith("-----")) { n--; }
  if (n-7 <= 0) {
    WrNotify(TStr::Fmt("Corrupt file %s: MESSAGE:\n", ZipFNm.CStr()).CStr(), Str.CStr());
    SaveToErrLog(TStr::Fmt("Corrupt file %s. Message:\n:%s\n", ZipFNm.CStr(), Str.CStr()).CStr());
    return 0;
  }
  return StrV[n-7].GetInt64();
}
Beispiel #28
0
void TFtrGenBs::PutClsFtrGen(const PFtrGen& FtrGen) {
	EAssert(State == fgsInit); 
	ClsFtrGen = FtrGen; 
}
Beispiel #29
0
void TRpiUtil::SetPinMode(const int& Pin, const int& Mode) {
	EAssert(IsValidMode(Pin, Mode));
	pinMode(Pin, Mode);
}
Beispiel #30
0
PJsonVal TJsonVal::GetObjKey(const TStr& Key) const {
  EAssert(IsObj());
  EAssertR(IsObjKey(Key), "Unknown key '" + Key + "'"); 
  return KeyValH.GetDat(Key);
}