72 m_tasks_semaphose{num_slots, num_slots},
73 m_product_queue{queue_depth == 0 ? num_slots : queue_depth}
79 m_tasks_semaphose.Wait();
84 m_tasks_semaphose.Post();
85 m_product_queue.push_back(std::move(token));
87 size_t current = m_running.fetch_sub(1);
90 m_product_queue.push_back({});
95 return m_product_queue.pop_front();
99 std::atomic<size_t> m_running = 0;
112 void Init()
override;
116 void Setup(
const CArgs& args);
117 void x_AliasLogFile();
120 void xValidateThread(
const string& filename,
bool save_output);
125 void ValidateOneDirectory(
string dir_name,
bool recurse);
130 size_t m_NumFiles = 0;
149 std::promise<CThreadExitData> prom;
150 prom.set_value(std::move(
result));
151 auto fut = prom.get_future();
153 m_queue.release(std::move(fut));
158 static const string str_sev[] = {
159 "NOTE",
"WARNING",
"ERROR",
"REJECT",
"FATAL",
"MAX"
164 if (sev == 0 && is_xml) {
189 if (args[
"logfile"]) {
190 if (
NStr::Equal(args[
"L"].AsString(), args[
"logfile"].AsString())) {
208 arg_desc->AddOptionalKey
209 (
"indir",
"Directory",
"Path to ASN.1 Files",
212 arg_desc->AddOptionalKey
213 (
"i",
"InFile",
"Single Input File",
215 arg_desc->AddOptionalKey(
216 "o",
"OutFile",
"Single Output File",
218 arg_desc->AddOptionalKey(
219 "f",
"Filter",
"Substring Filter",
221 arg_desc->AddDefaultKey
223 arg_desc->AddFlag(
"u",
"Recurse");
224 arg_desc->AddDefaultKey(
225 "R",
"SevCount",
"Severity for Error in Return Code\n\
233 arg_desc->AddDefaultKey(
234 "Q",
"SevLevel",
"Lowest Severity for Error to Show\n\
242 arg_desc->AddDefaultKey(
243 "P",
"SevLevel",
"Highest Severity for Error to Show\n\
252 arg_desc->SetConstraint(
"Q", constraint);
253 arg_desc->SetConstraint(
"P", constraint);
254 arg_desc->SetConstraint(
"R", constraint);
255 arg_desc->AddOptionalKey(
256 "E",
"String",
"Only Error Code to Show",
259 arg_desc->AddDefaultKey(
"a",
"a",
272 arg_desc->AddFlag(
"b",
"Input is in binary format; obsolete",
274 arg_desc->AddFlag(
"c",
"Batch File is Compressed; obsolete",
277 arg_desc->AddFlag(
"quiet",
"Do not log progress");
280 arg_desc->AddFlag(
"annot",
"Verify Seq-annots only");
282 arg_desc->AddOptionalKey(
283 "L",
"OutFile",
"Log File",
286 arg_desc->AddDefaultKey(
"v",
"Verbosity",
288 "\t1 Standard Report\n"
289 "\t2 Accession / Severity / Code(space delimited)\n"
290 "\t3 Accession / Severity / Code(tab delimited)\n"
294 arg_desc->SetConstraint(
"v", v_constraint);
296 arg_desc->AddFlag(
"cleanup",
"Perform BasicCleanup before validating (to match C Toolkit)");
297 arg_desc->AddFlag(
"batch",
"Process NCBI release file (Seq-submit or Bioseq-set only)");
298 arg_desc->AddFlag(
"huge",
"Execute in huge-file mode");
299 arg_desc->AddFlag(
"disable-huge",
"Explicitly disable huge-files mode");
300 arg_desc->SetDependency(
"disable-huge",
304 arg_desc->AddOptionalKey(
305 "D",
"String",
"Path to lat_lon country data files",
313 arg_desc->SetUsageContext(
"",
"ASN Validator");
316 SetupArgDescriptions(arg_desc.release());
332 suffix = args[
"x"].AsString();
339 string fname = ii->GetName();
341 (!args[
"f"] ||
NStr::Find(fname, args[
"f"].AsString()) !=
NPOS)) {
344 bool separate_outputs = !args[
"o"];
348 std::thread([
this, fpath, separate_outputs]()
349 { xValidateThread(fpath, separate_outputs); })
356 string subdir = ii->GetName();
359 ValidateOneDirectory(
subname, recurse);
372 std::list<CConstRef<CValidError>> eval;
378 auto fut = m_queue.GetNext();
382 auto exit_data = fut.get();
386 combined_exit_data.
mReported += exit_data.mReported;
388 combined_exit_data.
mNumRecords += exit_data.mNumRecords;
389 if (exit_data.mLongest > combined_exit_data.
mLongest) {
390 combined_exit_data.
mLongest = exit_data.mLongest;
391 combined_exit_data.
mLongestId = exit_data.mLongestId;
394 if (combined_file && !exit_data.mEval.empty()) {
395 combined_exit_data.
mReported +=
out.Write(exit_data.mEval);
399 return combined_exit_data;
407 mRemoteUpdater.reset(
new edit::CRemoteUpdater(
nullptr));
409 CTime expires = GetFullVersion().GetBuildInfo().GetBuildTime();
415 NcbiCerr <<
"This copy of " << GetProgramDisplayName()
416 <<
" is more than 1 year old. Please download the current version if it is newer." << endl;
422 std::ostream* ValidErrorStream =
nullptr;
424 ValidErrorStream = &args[
"o"].AsOutputFile();
428 string lat_lon_path = args[
"D"].AsString();
429 if (! lat_lon_path.empty()) {
430 SetEnvironment(
"NCBI_LAT_LON_DATA_PATH", lat_lon_path );
435 cerr <<
"Warning: -b is deprecated; do not use" << endl;
439 bool exception_caught =
false;
443 auto writer_task = std::async([
this, ValidErrorStream] {
return xCombinedWriterTask(ValidErrorStream); });
445 ValidateOneDirectory(args[
"indir"].AsString(), args[
"u"]);
447 exit_data = writer_task.get();
450 string in_filename = (args[
"i"]) ? args[
"i"].AsString() :
"";
451 exit_data = xValidate(in_filename, ValidErrorStream==
nullptr);
453 if (ValidErrorStream) {
460 exception_caught =
true;
462 if (m_NumFiles == 0) {
463 ERR_POST(
"No matching files found");
466 time_t stop_time = time(
NULL);
467 if (! mAppConfig->mQuiet ) {
473 if (exit_data.
mReported > 0 || exception_caught) {
489 mAppConfig.reset(
new CAppConfig(args, GetConfig()));
500 m_Output.PutString(
" <message severity=\"");
503 m_Output.PutString(
"\" seq-id=\"");
508 m_Output.PutString(
"\" feat-id=\"");
513 m_Output.PutString(
"\" interval=\"");
516 loc =
"[" + loc.substr(1, loc.length() - 2) +
"]";
521 m_Output.PutString(
"\" code=\"");
523 m_Output.PutString(
"_");
525 m_Output.PutString(
"\">");
529 m_Output.PutString(
"</message>");
537 int main(
int argc,
const char* argv[])
541 list<string> split_args;
542 vector<const char*> new_argv;
544 if (argc==2 && argv && argv[1] && strchr(argv[1],
' '))
548 auto it = split_args.begin();
549 while (it != split_args.end())
552 if (
next != split_args.end() &&
553 ((it->front() ==
'"' && it->back() !=
'"') ||
554 (it->front() ==
'\'' && it->back() !=
'\'')))
556 it->append(
" "); it->append(*
next);
560 for (
auto& rec: split_args)
562 if (rec.front()==
'\'' && rec.back()==
'\'')
563 rec=rec.substr(1, rec.length()-2);
565 argc = 1 + split_args.size();
566 new_argv.reserve(argc);
567 new_argv.push_back(argv[0]);
568 for (
const string& s : split_args)
570 new_argv.push_back(s.c_str());
571 std::cerr << s.c_str() <<
" ";
576 argv = new_argv.data();
string s_GetSeverityLabel(EDiagSev sev, bool is_xml)
int main(int argc, const char *argv[])
int Run() override
Run the application.
void xValidateThread(const string &filename, bool save_output)
void Setup(const CArgs &args)
CThreadExitData xValidate(const string &filename, bool save_output)
void ValidateOneDirectory(string dir_name, bool recurse)
CThreadExitData xCombinedWriterTask(std::ostream *ofile)
unique_ptr< edit::CRemoteUpdater > mRemoteUpdater
void Init() override
Initialize the application.
unique_ptr< CAppConfig > mAppConfig
CThreadExitData ValidateOneFile(const std::string &filename)
static void SetupObjectManager(const CArgs &args, objects::CObjectManager &obj_mgr, TLoaders loaders=fDefault)
Set up the standard object manager data loaders according to the arguments provided above.
static void AddArgumentDescriptions(CArgDescriptions &arg_desc, TLoaders loaders=fDefault)
Add a standard set of arguments used to configure the object manager.
void Print(const CValidErrItem &item)
const string GetErrGroup(void) const
EDiagSev GetSeverity(void) const
const string GetErrCode(void) const
static void SetupArgDescriptions(CArgDescriptions *arg_desc)
Setup core splign argument descriptions for the application.
void release(token_type &&token)
CSemaphore m_tasks_semaphose
TThreadPoolLimited(unsigned num_slots, unsigned queue_depth=0)
std::future< CThreadExitData > token_type
std::future< void > m_consumer
Include a standard set of the NCBI C++ Toolkit most basic headers.
static DLIST_TYPE *DLIST_NAME() next(DLIST_LIST_TYPE *list, DLIST_TYPE *item)
std::ofstream out("events_result.xml")
main entry point for tests
int AppMain(int argc, const char *const *argv, const char *const *envp=0, EAppDiagStream diag=eDS_Default, const char *conf=NcbiEmptyCStr, const string &name=NcbiEmptyString)
Main function (entry point) for the NCBI application.
@ fHidden
Hide it in Usage.
@ eExcludes
One argument excludes another.
@ eInputFile
Name of file (must exist and be readable)
@ eString
An arbitrary string.
@ eOutputFile
Name of file (must be writable)
@ eInteger
Convertible into an integer number (int or Int8)
bool SetLogFile(const string &file_name, EDiagFileType file_type=eDiagFile_All, bool quick_flush=true)
Set log files.
#define ERR_POST(message)
Error posting with file, line number information but without error codes.
EDiagSev
Severity level for the posted diagnostics.
#define LOG_POST_XX(error_name, err_subcode, message)
@ eDiagSevMin
Verbosity level for min. severity.
@ eDiagSevMax
Verbosity level for max. severity.
void Error(CExceptionArgs_Base &args)
#define NCBI_THROW(exception_class, err_code, message)
Generic macro to throw an exception, given the exception class, error code and message string.
TEntries GetEntries(const string &mask=kEmptyStr, TGetEntriesFlags flags=0) const
Get directory entries based on the specified "mask".
static string MakePath(const string &dir=kEmptyStr, const string &base=kEmptyStr, const string &ext=kEmptyStr)
Assemble a path from basic components.
@ eStringTypeVisible
VisibleString (in ASN.1 sense)
static CRef< CObjectManager > GetInstance(void)
Return the existing object manager or create one.
static list< string > & Split(const CTempString str, const CTempString delim, list< string > &arr, TSplitFlags flags=0, vector< SIZE_TYPE > *token_pos=NULL)
Split a string using specified delimiters.
static bool EndsWith(const CTempString str, const CTempString end, ECase use_case=eCase)
Check if a string ends with a specified suffix value.
static SIZE_TYPE Find(const CTempString str, const CTempString pattern, ECase use_case=eCase, EDirection direction=eForwardSearch, SIZE_TYPE occurrence=0)
Find the pattern in the string.
static bool StartsWith(const CTempString str, const CTempString start, ECase use_case=eCase)
Check if a string starts with a specified prefix value.
static bool Equal(const CTempString s1, SIZE_TYPE pos, SIZE_TYPE n, const char *s2, ECase use_case=eCase)
Test for equality of a substring with another string.
void Run(void)
Enter the main loop.
@ eCurrent
Use current time. See also CCurrentTime.
bool IsSetFeatureId(void) const
Check if a value has been assigned to FeatureId data member.
const TAccnver & GetAccnver(void) const
Get the Accnver member data.
bool IsSetLocation(void) const
Check if a value has been assigned to Location data member.
bool IsSetAccnver(void) const
Check if a value has been assigned to Accnver data member.
const TLocation & GetLocation(void) const
Get the Location member data.
const TMsg & GetMsg(void) const
Get the Msg member data.
const TFeatureId & GetFeatureId(void) const
Get the FeatureId member data.
const struct ncbi::grid::netcache::search::fields::EXPIRES expires
Magic spell ;-) needed for some weird compilers... very empiric.
#define NCBI_SC_VERSION_PROXY
#define NCBI_TEAMCITY_BUILD_NUMBER_PROXY
Defines the CNcbiApplication and CAppException classes for creating NCBI applications.
#define GetArgs
Avoid preprocessor name clash with the NCBI C Toolkit.
Defines command line argument related classes.
NCBI C++ stream class wrappers for triggering between "new" and "old" C++ stream libraries.
static const char * suffix[]
std::list< CConstRef< CValidError > > mEval