NLM_EXTERN EIO_Status VecScreenWaitForReply ( CONN conn ) { time_t currtime, starttime; time_t max = 0; EIO_Status status; STimeout timeout; #ifdef OS_MAC EventRecord currEvent; #endif if (conn == NULL) return eIO_Unknown; #ifdef OS_MAC timeout.sec = 0; timeout.usec = 0; #else timeout.sec = 100; timeout.usec = 0; #endif starttime = GetSecs (); while ((status = CONN_Wait (conn, eIO_Read, &timeout)) == eIO_Timeout && max < 300) { currtime = GetSecs (); max = currtime - starttime; #ifdef OS_MAC WaitNextEvent (0, &currEvent, 0, NULL); #endif } return status; }
NLM_EXTERN Int4 VecScreenCheckQueue ( VQUEUE* queue ) { CONN conn; Nlm_Int4 count = 0; VQueuePtr curr; time_t currtime; VQueuePtr next; VQueuePtr PNTR qptr; Char str [128]; qptr = (VQueuePtr PNTR) queue; if (qptr == NULL || *qptr == NULL) return 0; curr = *qptr; while (curr != NULL) { next = curr->next; /* check for return of rID, WAITING, of SUCCESS message */ QUERY_CheckQueue (&(curr->connqueue)); if (curr->done) { VecScreen_RemoveFromQueue (queue, curr); } else { if (curr->connqueue == NULL) { currtime = GetSecs (); if (currtime - curr->postedTime < curr->secondsToWait) { } else if (! StringHasNoText (curr->rid)) { /* estimated wait time has expired, so queue another check */ if (curr->secondsToWait < 300) { curr->secondsToWait *= 2; if (curr->secondsToWait > 300) { curr->secondsToWait = 300; } } curr->postedTime = GetSecs (); sprintf (str, "req=%s", curr->rid); conn = VecScreenOpenConnection (str); QUERY_SendQuery (conn); QUERY_AddToQueue (&(curr->connqueue), conn, SecondVecScreenCallback, (Pointer) curr, TRUE); } } count++; } curr = next; } return count; }
NLM_EXTERN Int4 PrintVecScreenQueue ( VQUEUE* queue, FILE *fp ) { Nlm_Int4 count = 0; VQueuePtr curr; time_t currtime; VQueuePtr next; VQueuePtr PNTR qptr; qptr = (VQueuePtr PNTR) queue; if (qptr == NULL || *qptr == NULL || fp == NULL) return 0; currtime = GetSecs (); curr = *qptr; while (curr != NULL) { next = curr->next; if (! curr->done) { fprintf (fp, "%s\t%s\t%d\t%d\n", curr->rid, curr->seqid, (int) (currtime - curr->initialTime), (int) curr->estTime); count++; } curr = next; } return count; }
static void VecScreen_AddToQueue ( VQUEUE * queue, VecScreenResultProc resultproc, VecScreenAnnounceProc announceproc, Nlm_VoidPtr userdata, CONN conn, BioseqPtr bsp ) { VQueuePtr cqp; VQueuePtr PNTR qptr; VQueuePtr tmp; if (queue == NULL || resultproc == NULL || conn == NULL || bsp == NULL) return; /* allocate queue element */ cqp = (VQueuePtr) MemNew (sizeof (VecScreenQueue)); if (cqp == NULL) return; cqp->rid [0] = '\0'; SeqIdWrite (bsp->id, cqp->seqid, PRINTID_FASTA_LONG, 40); cqp->estTime = 0; cqp->initialTime = GetSecs (); cqp->postedTime = cqp->initialTime; cqp->secondsToWait = 15; cqp->resultproc = resultproc; cqp->announceproc = announceproc; cqp->userdata = userdata; cqp->connqueue = NULL; cqp->done = FALSE; /* add to polling queue */ qptr = (VQueuePtr PNTR) queue; if (qptr != NULL) { if (*qptr != NULL) { tmp = *qptr; if (tmp != NULL) { while (tmp->next != NULL) { tmp = tmp->next; } tmp->next = cqp; } } else { *qptr = cqp; } } /* queue the request for a rID */ QUERY_AddToQueue (&(cqp->connqueue), conn, FirstVecScreenCallback, (Pointer) cqp, TRUE); }
Boolean QSRV_Time(CharPtr string, Int4 len, time_t seconds) { if(string == NULL || len < 25) return FALSE; if(!seconds) { seconds = GetSecs(); } #if defined(OS_UNIX_IRIX) || defined(OS_UNIX_LINUX) || defined(OS_UNIX_OSF1) || defined(OS_UNIX_FREEBSD) ctime_r(&seconds, string); #elif defined(OS_UNIX_DARWIN) /* no ctime_r :-/ */ strncpy(string, ctime(&seconds), len - 1); string[len - 1] = '\0'; #else ctime_r(&seconds, string, len); #endif string[24] = NULLB; return TRUE; }
static void ProcessMultipleRecord ( CharPtr filename, CSpeedFlagPtr cfp ) { AsnIoPtr aip; AsnTypePtr atp; BioseqPtr bsp; Char buf [41]; Uint2 entityID; FILE *fp; SeqEntryPtr fsep; Char longest [41]; Int4 numrecords, x; SeqEntryPtr sep; time_t starttime, stoptime, worsttime; #ifdef OS_UNIX Char cmmd [256]; CharPtr gzcatprog; int ret; Boolean usedPopen = FALSE; #endif if (cfp == NULL) return; if (StringHasNoText (filename)) return; #ifndef OS_UNIX if (cfp->compressed) { Message (MSG_POSTERR, "Can only decompress on-the-fly on UNIX machines"); return; } #endif #ifdef OS_UNIX if (cfp->compressed) { gzcatprog = getenv ("NCBI_UNCOMPRESS_BINARY"); if (gzcatprog != NULL) { sprintf (cmmd, "%s %s", gzcatprog, filename); } else { ret = system ("gzcat -h >/dev/null 2>&1"); if (ret == 0) { sprintf (cmmd, "gzcat %s", filename); } else if (ret == -1) { Message (MSG_POSTERR, "Unable to fork or exec gzcat in ScanBioseqSetRelease"); return; } else { ret = system ("zcat -h >/dev/null 2>&1"); if (ret == 0) { sprintf (cmmd, "zcat %s", filename); } else if (ret == -1) { Message (MSG_POSTERR, "Unable to fork or exec zcat in ScanBioseqSetRelease"); return; } else { Message (MSG_POSTERR, "Unable to find zcat or gzcat in ScanBioseqSetRelease - please edit your PATH environment variable"); return; } } } fp = popen (cmmd, /* cfp->binary? "rb" : */ "r"); usedPopen = TRUE; } else { fp = FileOpen (filename, cfp->binary? "rb" : "r"); } #else fp = FileOpen (filename, cfp->binary? "rb" : "r"); #endif if (fp == NULL) { Message (MSG_POSTERR, "FileOpen failed for input file '%s'", filename); return; } aip = AsnIoNew (cfp->binary? ASNIO_BIN_IN : ASNIO_TEXT_IN, fp, NULL, NULL, NULL); if (aip == NULL) { Message (MSG_ERROR, "AsnIoNew failed for input file '%s'", filename); return; } if (cfp->logfp != NULL) { fprintf (cfp->logfp, "%s\n\n", filename); fflush (cfp->logfp); } longest [0] = '\0'; worsttime = 0; numrecords = 0; atp = cfp->atp_bss; while ((atp = AsnReadId (aip, cfp->amp, atp)) != NULL) { if (atp == cfp->atp_se) { sep = SeqEntryAsnRead (aip, atp); if (sep != NULL) { entityID = ObjMgrGetEntityIDForChoice (sep); fsep = FindNthBioseq (sep, 1); if (fsep != NULL && fsep->choice == 1) { bsp = (BioseqPtr) fsep->data.ptrvalue; if (bsp != NULL) { SeqIdWrite (bsp->id, buf, PRINTID_FASTA_LONG, sizeof (buf)); if (cfp->logfp != NULL) { fprintf (cfp->logfp, "%s\n", buf); fflush (cfp->logfp); } } } starttime = GetSecs (); for (x = 0; x < cfp->maxcount; x++) { DoProcess (sep, entityID, cfp); } stoptime = GetSecs (); if (stoptime - starttime > worsttime) { worsttime = stoptime - starttime; StringCpy (longest, buf); } numrecords++; ObjMgrFreeByEntityID (entityID); } } else { AsnReadVal (aip, atp, NULL); } } AsnIoFree (aip, FALSE); #ifdef OS_UNIX if (usedPopen) { pclose (fp); } else { FileClose (fp); } #else FileClose (fp); #endif if (cfp->logfp != NULL && (! StringHasNoText (longest))) { fprintf (cfp->logfp, "Longest processing time %ld seconds on %s\n", (long) worsttime, longest); fprintf (cfp->logfp, "Total number of records %ld\n", (long) numrecords); fflush (cfp->logfp); } }
static void ProcessSingleRecord ( CharPtr filename, CSpeedFlagPtr cfp ) { AsnIoPtr aip; BioseqPtr bsp; ValNodePtr bsplist = NULL; BioseqSetPtr bssp; Pointer dataptr = NULL; Uint2 datatype, entityID = 0; FileCache fc; FILE *fp; Int1 iotype; Char line [512]; Int4 maxio = 1; SeqEntryPtr sep; time_t starttime, stoptime, worsttime; CharPtr str; Int4 x; if (cfp == NULL) return; if (StringHasNoText (filename)) return; if (StringChr (cfp->io, 'r') != NULL) { maxio = cfp->maxcount; } starttime = GetSecs (); for (x = 0; x < maxio; x++) { if (entityID != 0) { ObjMgrFreeByEntityID (entityID); entityID = 0; dataptr = NULL; } if (cfp->type == 1) { fp = FileOpen (filename, "r"); if (fp == NULL) { Message (MSG_POSTERR, "Failed to open '%s'", filename); return; } dataptr = ReadAsnFastaOrFlatFile (fp, &datatype, NULL, FALSE, FALSE, FALSE, FALSE); FileClose (fp); entityID = ObjMgrRegister (datatype, dataptr); } else if (cfp->type >= 2 && cfp->type <= 5) { aip = AsnIoOpen (filename, cfp->binary? "rb" : "r"); if (aip == NULL) { Message (MSG_POSTERR, "AsnIoOpen failed for input file '%s'", filename); return; } switch (cfp->type) { case 2 : dataptr = (Pointer) SeqEntryAsnRead (aip, NULL); datatype = OBJ_SEQENTRY; break; case 3 : dataptr = (Pointer) BioseqAsnRead (aip, NULL); datatype = OBJ_BIOSEQ; break; case 4 : dataptr = (Pointer) BioseqSetAsnRead (aip, NULL); datatype = OBJ_BIOSEQSET; break; case 5 : dataptr = (Pointer) SeqSubmitAsnRead (aip, NULL); datatype = OBJ_SEQSUB; break; default : break; } AsnIoClose (aip); entityID = ObjMgrRegister (datatype, dataptr); } else if (cfp->type == 6) { fp = FileOpen (filename, "r"); if (fp == NULL) { Message (MSG_POSTERR, "Failed to open '%s'", filename); return; } dataptr = ReadAsnFastaOrFlatFile (fp, &datatype, NULL, FALSE, FALSE, FALSE, FALSE); FileClose (fp); entityID = ObjMgrRegister (datatype, dataptr); } else if (cfp->type == 7) { fp = FileOpen (filename, "r"); if (fp == NULL) { Message (MSG_POSTERR, "Failed to open '%s'", filename); return; } FileCacheSetup (&fc, fp); str = FileCacheReadLine (&fc, line, sizeof (line), NULL); while (str != NULL) { str = FileCacheReadLine (&fc, line, sizeof (line), NULL); } FileClose (fp); return; } else { Message (MSG_POSTERR, "Input format type '%d' unrecognized", (int) cfp->type); return; } } if (entityID < 1 || dataptr == NULL) { Message (MSG_POSTERR, "Data read failed for input file '%s'", filename); return; } if (datatype == OBJ_SEQSUB || datatype == OBJ_SEQENTRY || datatype == OBJ_BIOSEQ || datatype == OBJ_BIOSEQSET) { stoptime = GetSecs (); worsttime = stoptime - starttime; if (cfp->logfp != NULL) { fprintf (cfp->logfp, "ASN reading time %ld seconds\n", (long) worsttime); fflush (cfp->logfp); } sep = GetTopSeqEntryForEntityID (entityID); if (sep == NULL) { sep = SeqEntryNew (); if (sep != NULL) { if (datatype == OBJ_BIOSEQ) { bsp = (BioseqPtr) dataptr; sep->choice = 1; sep->data.ptrvalue = bsp; SeqMgrSeqEntry (SM_BIOSEQ, (Pointer) bsp, sep); } else if (datatype == OBJ_BIOSEQSET) { bssp = (BioseqSetPtr) dataptr; sep->choice = 2; sep->data.ptrvalue = bssp; SeqMgrSeqEntry (SM_BIOSEQSET, (Pointer) bssp, sep); } else { sep = SeqEntryFree (sep); } } sep = GetTopSeqEntryForEntityID (entityID); } if (sep != NULL) { if (cfp->lock) { starttime = GetSecs (); bsplist = LockFarComponents (sep); stoptime = GetSecs (); worsttime = stoptime - starttime; if (cfp->logfp != NULL) { fprintf (cfp->logfp, "Far component locking time %ld seconds\n", (long) worsttime); fflush (cfp->logfp); } } if (StringChr (cfp->io, 'w') != NULL) { starttime = GetSecs (); iotype = ASNIO_TEXT_OUT; if (StringChr (cfp->io, 'b') != NULL) { iotype = ASNIO_BIN_OUT; } for (x = 0; x < cfp->maxcount; x++) { aip = AsnIoNew (iotype, cfp->ofp, NULL, NULL, NULL); if (aip != NULL) { SeqEntryAsnWrite (sep, aip, NULL); AsnIoFree (aip, FALSE); } } stoptime = GetSecs (); worsttime = stoptime - starttime; if (cfp->logfp != NULL) { fprintf (cfp->logfp, "ASN writing time %ld seconds\n", (long) worsttime); fflush (cfp->logfp); } } starttime = GetSecs (); for (x = 0; x < cfp->maxcount; x++) { DoProcess (sep, entityID, cfp); } stoptime = GetSecs (); worsttime = stoptime - starttime; if (cfp->logfp != NULL) { fprintf (cfp->logfp, "Internal processing time %ld seconds\n", (long) worsttime); fflush (cfp->logfp); } ObjMgrFreeByEntityID (entityID); bsplist = UnlockFarComponents (bsplist); } } else { Message (MSG_POSTERR, "Datatype %d not recognized", (int) datatype); } }
Int2 Main (void) { Char app [64], type; CSpeedFlagData cfd; CharPtr directory, filter, infile, logfile, outfile, str, suffix; Boolean remote; time_t runtime, starttime, stoptime; /* standard setup */ ErrSetFatalLevel (SEV_MAX); ErrClearOptFlags (EO_SHOW_USERSTR); UseLocalAsnloadDataAndErrMsg (); ErrPathReset (); /* finish resolving internal connections in ASN.1 parse tables */ if (! AllObjLoad ()) { Message (MSG_FATAL, "AllObjLoad failed"); return 1; } if (! SubmitAsnLoad ()) { Message (MSG_FATAL, "SubmitAsnLoad failed"); return 1; } if (! FeatDefSetLoad ()) { Message (MSG_FATAL, "FeatDefSetLoad failed"); return 1; } if (! SeqCodeSetLoad ()) { Message (MSG_FATAL, "SeqCodeSetLoad failed"); return 1; } if (! GeneticCodeTableLoad ()) { Message (MSG_FATAL, "GeneticCodeTableLoad failed"); return 1; } /* process command line arguments */ sprintf (app, "cspeedtest %s", CSPEEDTEST_APPLICATION); if (! GetArgs (app, sizeof (myargs) / sizeof (Args), myargs)) { return 0; } MemSet ((Pointer) &cfd, 0, sizeof (CSpeedFlagData)); directory = (CharPtr) myargs [p_argInputPath].strvalue; infile = (CharPtr) myargs [i_argInputFile].strvalue; outfile = (CharPtr) myargs [o_argOutputFile].strvalue; filter = (CharPtr) myargs [f_argFilter].strvalue; suffix = (CharPtr) myargs [x_argSuffix].strvalue; cfd.batch = FALSE; cfd.binary = (Boolean) myargs [b_argBinary].intvalue; cfd.compressed = (Boolean) myargs [c_argCompressed].intvalue; cfd.lock = (Boolean) myargs [l_argLockFar].intvalue; cfd.type = 1; str = myargs [a_argType].strvalue; TrimSpacesAroundString (str); if (StringDoesHaveText (str)) { type = str [0]; } else { type = 'a'; } type = TO_LOWER (type); switch (type) { case 'a' : cfd.type = 1; break; case 'e' : cfd.type = 2; break; case 'b' : cfd.type = 3; break; case 's' : cfd.type = 4; break; case 'm' : cfd.type = 5; break; case 't' : cfd.type = 1; cfd.batch = TRUE; break; case 'f' : cfd.type = 6; break; case 'l' : cfd.type = 7; break; default : cfd.type = 1; break; } remote = (Boolean) myargs [R_argRemote].intvalue; cfd.maxcount = myargs [X_argMaxCount].intvalue; if (cfd.maxcount < 1) { cfd.maxcount = 1; } cfd.io = myargs [O_argInOut].strvalue; cfd.clean = myargs [K_argClean].strvalue; cfd.skip = myargs [P_argSkip].strvalue; cfd.index = myargs [I_argIndex].strvalue; cfd.seq = myargs [S_argSeq].strvalue; cfd.feat = myargs [F_argFeat].strvalue; cfd.desc = myargs [D_argDesc].strvalue; cfd.verify = myargs [V_argVerify].strvalue; cfd.amp = AsnAllModPtr (); cfd.atp_bss = AsnFind ("Bioseq-set"); cfd.atp_bsss = AsnFind ("Bioseq-set.seq-set"); cfd.atp_se = AsnFind ("Bioseq-set.seq-set.E"); cfd.atp_bsc = AsnFind ("Bioseq-set.class"); cfd.bssp_atp = AsnLinkType (NULL, cfd.atp_bss); logfile = (CharPtr) myargs [L_argLogFile].strvalue; if (StringDoesHaveText (logfile)) { cfd.logfp = FileOpen (logfile, "w"); } if (remote) { PubSeqFetchEnable (); } if (StringDoesHaveText (outfile)) { cfd.ofp = FileOpen (outfile, "w"); } starttime = GetSecs (); if (StringDoesHaveText (directory)) { DirExplore (directory, NULL, suffix, FALSE, ProcessOneRecord, (Pointer) &cfd); } else if (StringDoesHaveText (infile)) { ProcessOneRecord (infile, (Pointer) &cfd); } if (cfd.ofp != NULL) { FileClose (cfd.ofp); } stoptime = GetSecs (); runtime = stoptime - starttime; if (cfd.logfp != NULL) { fprintf (cfd.logfp, "Finished in %ld seconds\n", (long) runtime); FileClose (cfd.logfp); } printf ("Finished in %ld seconds\n", (long) runtime); if (remote) { PubSeqFetchDisable (); } return 0; }