4 #include <boost/lexical_cast.hpp>
6 #include <fwk/CentralConfig.h>
7 #include <fwk/RunController.h>
8 #include <utl/ErrorLogger.h>
9 #include <fwk/VModule.h>
10 #include <utl/Reader.h>
11 #include <evt/Event.h>
12 #include <utl/AugerException.h>
13 #include <utl/TabularStream.h>
14 #include <utl/StringCompare.h>
22 RunController::RunController() :
23 fCurEvent(new evt::Event)
25 ErrorLogger::GetInstance();
39 emsg <<
"No module creator found for module with name '" << moduleName <<
"'. "
40 "Most likely reasons:\n"
41 "1) You misspelled the module name, or the module doesn't exist.\n"
42 "2) You declared a default constructor for your module\n"
43 " but did not provide an implementation.\n"
44 "3) You linked with static libraries (currently not supported)\n"
45 "4) Your application was not linked to AugerModules (check with ldd and your compiler options).";
74 ostringstream modules;
78 modules << it->first <<
" (version: "
105 msg <<
"Failure configuring the framework. "
106 "A exception of type " << ex.GetExceptionName() <<
" was thrown. "
108 "Cannot recover. Terminating";
118 emsg <<
"Error in RunController. "
119 "Unable to find the module sequencing information! "
120 "Is the ModuleSequence configLink correctly defined in the bootstrap file?";
140 cerr <<
"--> Running Init() of module '" << mn <<
"'\n";
142 const auto flag =
mod.Init();
144 cerr <<
"--> Finished Init() of module '" << mn <<
"', "
158 if (currentB.
GetName() ==
"module") {
159 const string modName = currentB.
Get<
string>();
198 double moduleUTimeSum = 0;
199 double moduleSTimeSum = 0;
201 ostringstream failureMessage;
212 auto& stopwatch =
mod.GetStopwatch();
213 const double moduleUTime = stopwatch.GetCPUTime(Stopwatch::eUser) /
second;
214 const double moduleSTime = stopwatch.GetCPUTime(Stopwatch::eSystem) /
second;
215 moduleUTimeSum += moduleUTime;
216 moduleSTimeSum += moduleSTime;
217 const double frac = round(1000*(moduleUTime + moduleSTime) / totalTime) / 10;
219 tab << mn <<
endc << moduleUTime <<
endc << moduleSTime <<
endc << frac <<
endr;
221 cerr <<
"--> Running Finish() of module '" << mn <<
"'\n";
223 const auto flag =
mod.Finish();
225 cerr <<
"--> Finished Finish() of module '" << mn <<
"', "
229 failureMessage << (failureMessage.str().empty() ?
"" :
"\n")
230 <<
"Received failure message from Finish() of module: " << mn;
233 const auto failureStr = failureMessage.str();
234 if (!failureStr.empty())
239 tab <<
"Item" <<
endc <<
"Count" <<
endr
244 INFO(
"Performance counters:\n" + tab.
Str());
247 const double frac = round(1000*(moduleUTimeSum + moduleSTimeSum) / totalTime) / 10;
249 <<
"All modules" <<
endc << moduleUTimeSum <<
endc
250 << moduleSTimeSum <<
endc << frac <<
endr
251 <<
"Total" <<
endc << totalUTime <<
endc << totalSTime <<
endc << 100;
253 info <<
"\n\nCPU user and system time in Module::Run()\n"
256 info <<
"Total real time of the run: " << time/
second <<
" s";
259 if (!failureStr.empty())
269 case eBreak:
return "eBreak";
271 default:
return "Unknown";
284 INFO(
"No <moduleControl> tag was found in the module sequencing file. No sequencing will be done.");
292 err <<
"Module sequence cannot handle the " <<
GetBreakStatusByName(status) <<
" return value. "
293 "Please, fix your module sequence.";
309 if (currentB.
GetName() ==
"loop" ||
312 bool unboundedLoopFlag =
false;
315 const auto attEnd = attMap.end();
317 const auto numTimesIt = attMap.find(
"numTimes");
318 if (numTimesIt != attEnd) {
320 unboundedLoopFlag =
true;
322 loopInt = boost::lexical_cast<
int>(numTimesIt->second);
326 const auto pushEventToStackIt = attMap.find(
"pushEventToStack");
327 const auto saveIt = attMap.find(
"save");
329 bool saveFlag =
false;
331 if (saveIt != attEnd) {
334 warn <<
"The 'save' loop attribute is deprecated (people find it unclear). "
335 "Please use 'pushEventToStack' instead.";
339 if (pushEventToStackIt != attEnd) {
341 err <<
"You can have either a 'save' or 'pushEventToStack' attribute"
342 "in the loop tag, but not both.";
352 if (pushEventToStackIt != attEnd &&
358 for (
int iLoop = 0; unboundedLoopFlag || iLoop < loopInt; ++iLoop) {
360 if (iLoop && savedEvent)
366 if (outerBreakStatus ==
eBreak) {
367 innerBreakStatus =
eBreak;
369 }
else if (outerBreakStatus ==
eContinue)
373 if (innerBreakStatus ==
eBreak)
381 }
else if (currentB.
GetName() ==
"module") {
386 cerr <<
"--> Running Run() of module '" << modName <<
"'\n";
394 cerr <<
"--> Finished running module '" << modName <<
"' "
398 cerr <<
" +--> Calling Finish() methods of all modules\n";
412 err <<
"Encountered a Branch in XML file with name <" << currentB.
GetName() <<
">. "
413 "RunController can only process Branches called <loop> or <module>.";
427 ErrorLogger::GetInstance().WriteErrorMessagesToStream();
bool HasModule(const std::string &moduleName) const
std::set< std::string > fUsedModuleNames
std::string GetRegisteredModuleNames() const
Get list of all module builder names and module versions in the registry.
Base class for all exceptions used in the auger offline code.
Skip remaining modules in the current loop and continue with next iteration of the loop...
#define INFO(message)
Macro for logging informational messages.
Exception to use in case of module sequencing failures.
Branch GetChild(const std::string &childName) const
Get child of this Branch by child name.
static Iterator Begin()
Begin iterator over the internal map (read only)
void RunBranch(utl::Branch ¤tB)
bool StringEquivalent(const std::string &a, const std::string &b, Predicate p)
Utility to compare strings for equivalence. It takes a predicate to determine the equivalence of indi...
AttributeMap GetAttributes() const
Get a map<string, string> containing all the attributes of this Branch.
Branch GetNextSibling() const
Get next sibling of this branch.
ResultFlag RunWithTiming(evt::Event &event)
static std::string GetBreakStatusByName(const BreakStatus status)
Class representing a document branch.
Break current loop. It works for nested loops too!
static std::string GetResultFlagByName(const ResultFlag flag)
class to format data in tabular form
static Iterator End()
End iterator over the internal map (read only)
#define WARNING(message)
Macro for logging warning messages.
static unsigned int GetNumberOfCreators()
Get number of object types know to this factory.
void GetData(bool &b) const
Overloads of the GetData member template function.
std::string GetName() const
function to get the Branch name
int GetNumberOfRegisteredModules() const
Return number of registered modules.
void DoRunSequence(utl::Branch ¤tB)
void GetNextModuleName(utl::Branch ¤tB)
std::string fCurrentModule
static CentralConfig * GetInstance()
Use this the first time you get an instance of central configuration.
Report failure to RunController, causing RunController to terminate execution.
Main configuration utility.
void FinishBranch(utl::Branch ¤tB)
utl::RealTimeStopwatch fRealTimeStopwatch
Branch GetFirstChild() const
Get first child of this Branch.
double Stop()
returns time since last call to Start()
void InitBranch(utl::Branch ¤tB)
double GetCPUTime(const CPUTime kind=eTotal)
double mod(const double d, const double periode)
NamedCounters & GetNamedCounters()
#define ERROR(message)
Macro for logging error messages.
utl::Stopwatch fStopwatch
const std::string & GetMessage() const
Retrieve the message from the exception.
utl::Branch GetTopBranch(const std::string &id)
Get top branch for moduleConfigLink with given id (XML files)
std::set< std::string > fUniqueModuleNames
static ObjectPtrType Create(const IdentifierType &id)
Create an object (0-argument constructor)
VModule & GetModule(const std::string &moduleName) const
Get module by name.
BreakStatus DoNextInSequence(utl::Branch ¤tB)