3737
3838using namespace std ;
3939
40+ const auto current_diagnostic = boost::current_exception_diagnostic_information;
41+
4042namespace o2 ::quality_control::core
4143{
4244
@@ -52,13 +54,20 @@ TaskRunner::TaskRunner(const std::string& taskName, const std::string& configura
5254 mMonitorObjectsSpec ({ " mo" }, createTaskDataOrigin(), createTaskDataDescription(taskName), id)
5355{
5456 // setup configuration
55- mConfigFile = ConfigurationFactory::getConfiguration (configurationSource);
56- populateConfig (taskName);
57+ try {
58+ mConfigFile = ConfigurationFactory::getConfiguration (configurationSource);
59+ populateConfig (taskName);
60+ } catch (...) {
61+ // catch the configuration exception and print it to avoid losing it
62+ ILOG (Fatal) << " Unexpected exception during configuration:\n "
63+ << current_diagnostic (true );
64+ throw ;
65+ }
5766}
5867
5968void TaskRunner::init (InitContext& iCtx)
6069{
61- QcInfoLogger::GetInstance ( ) << " initializing TaskRunner" << AliceO2::InfoLogger::InfoLogger::endm ;
70+ ILOG (Info ) << " initializing TaskRunner" << ENDM ;
6271
6372 // registering state machine callbacks
6473 iCtx.services ().get <CallbackService>().set (CallbackService::Id::Start, [this ]() { start (); });
@@ -242,61 +251,55 @@ std::tuple<bool /*data ready*/, bool /*timer ready*/> TaskRunner::validateInputs
242251
243252void TaskRunner::populateConfig (std::string taskName)
244253{
254+ auto tasksConfigList = mConfigFile ->getRecursive (" qc.tasks" );
255+ auto taskConfigTree = tasksConfigList.find (taskName);
256+ if (taskConfigTree == tasksConfigList.not_found ()) {
257+ std::string message = " No configuration found for task \" " + taskName + " \" " ;
258+ BOOST_THROW_EXCEPTION (AliceO2::Common::FatalException () << AliceO2::Common::errinfo_details (message));
259+ }
260+
261+ mTaskConfig .taskName = taskName;
262+ string test = taskConfigTree->second .get <std::string>(" detectorName" , " MISC" );
263+ mTaskConfig .detectorName = validateDetectorName (taskConfigTree->second .get <std::string>(" detectorName" , " MISC" ));
264+ mTaskConfig .moduleName = taskConfigTree->second .get <std::string>(" moduleName" );
265+ mTaskConfig .className = taskConfigTree->second .get <std::string>(" className" );
266+ mTaskConfig .cycleDurationSeconds = taskConfigTree->second .get <int >(" cycleDurationSeconds" , 10 );
267+ mTaskConfig .maxNumberCycles = taskConfigTree->second .get <int >(" maxNumberCycles" , -1 );
268+ mTaskConfig .consulUrl = mConfigFile ->get <std::string>(" qc.config.consul.url" , " http://consul-test.cern.ch:8500" );
269+ mTaskConfig .conditionUrl = mConfigFile ->get <std::string>(" qc.config.conditionDB.url" , " http://ccdb-test.cern.ch:8080" );
245270 try {
246- auto tasksConfigList = mConfigFile ->getRecursive (" qc.tasks" );
247- auto taskConfigTree = tasksConfigList.find (taskName);
248- if (taskConfigTree == tasksConfigList.not_found ()) {
249- throw ;
250- }
271+ mTaskConfig .customParameters = mConfigFile ->getRecursiveMap (" qc.tasks." + taskName + " .taskParameters" );
272+ } catch (...) {
273+ ILOG (Info) << " No custom parameters for " << taskName << ENDM ;
274+ }
251275
252- mTaskConfig .taskName = taskName;
253- string test = taskConfigTree->second .get <std::string>(" detectorName" , " MISC" );
254- mTaskConfig .detectorName = validateDetectorName (taskConfigTree->second .get <std::string>(" detectorName" , " MISC" ));
255- mTaskConfig .moduleName = taskConfigTree->second .get <std::string>(" moduleName" );
256- mTaskConfig .className = taskConfigTree->second .get <std::string>(" className" );
257- mTaskConfig .cycleDurationSeconds = taskConfigTree->second .get <int >(" cycleDurationSeconds" , 10 );
258- mTaskConfig .maxNumberCycles = taskConfigTree->second .get <int >(" maxNumberCycles" , -1 );
259- mTaskConfig .consulUrl = mConfigFile ->get <std::string>(" qc.config.consul.url" , " http://consul-test.cern.ch:8500" );
260- mTaskConfig .conditionUrl = mConfigFile ->get <std::string>(" qc.config.conditionDB.url" , " http://ccdb-test.cern.ch:8080" );
261- try {
262- mTaskConfig .customParameters = mConfigFile ->getRecursiveMap (" qc.tasks." + taskName + " .taskParameters" );
263- } catch (...) {
264- LOG (INFO ) << " No custom parameters for " << taskName;
265- }
276+ auto policiesFilePath = mConfigFile ->get <std::string>(" dataSamplingPolicyFile" , " " );
277+ ConfigurationInterface* config = policiesFilePath.empty () ? mConfigFile .get () : ConfigurationFactory::getConfiguration (policiesFilePath).get ();
278+ auto policiesTree = config->getRecursive (" dataSamplingPolicies" );
279+ auto dataSourceTree = taskConfigTree->second .get_child (" dataSource" );
280+ std::string type = dataSourceTree.get <std::string>(" type" );
281+
282+ if (type == " dataSamplingPolicy" ) {
283+ auto policyName = dataSourceTree.get <std::string>(" name" );
284+ ILOG (Info) << " policyName : " << policyName << ENDM ;
285+ mInputSpecs = DataSampling::InputSpecsForPolicy (config, policyName);
286+ } else if (type == " direct" ) {
287+ auto inputsQuery = dataSourceTree.get <std::string>(" query" );
288+ mInputSpecs = DataDescriptorQueryBuilder::parse (inputsQuery.c_str ());
289+ } else {
290+ std::string message = std::string (" Configuration error : dataSource type unknown : " ) + type;
291+ BOOST_THROW_EXCEPTION (AliceO2::Common::FatalException () << AliceO2::Common::errinfo_details (message));
292+ }
266293
267- auto policiesFilePath = mConfigFile ->get <std::string>(" dataSamplingPolicyFile" , " " );
268- ConfigurationInterface* config = policiesFilePath.empty () ? mConfigFile .get () : ConfigurationFactory::getConfiguration (policiesFilePath).get ();
269- auto policiesTree = config->getRecursive (" dataSamplingPolicies" );
270- auto dataSourceTree = taskConfigTree->second .get_child (" dataSource" );
271- std::string type = dataSourceTree.get <std::string>(" type" );
272-
273- if (type == " dataSamplingPolicy" ) {
274- auto policyName = dataSourceTree.get <std::string>(" name" );
275- LOG (INFO ) << " policyName : " << policyName;
276- mInputSpecs = DataSampling::InputSpecsForPolicy (config, policyName);
277- } else if (type == " direct" ) {
278- auto inputsQuery = dataSourceTree.get <std::string>(" query" );
279- mInputSpecs = DataDescriptorQueryBuilder::parse (inputsQuery.c_str ());
280- } else {
281- std::string message = std::string (" Configuration error : dataSource type unknown : " ) + type; // TODO pass this message to the exception
282- BOOST_THROW_EXCEPTION (AliceO2::Common::FatalException () << AliceO2::Common::errinfo_details (message));
283- }
294+ mInputSpecs .emplace_back (InputSpec{ " timer-cycle" , createTaskDataOrigin (), createTaskDataDescription (" TIMER-" + taskName), 0 , Lifetime::Timer });
295+ mOptions .push_back ({ " period-timer-cycle" , framework::VariantType::Int, static_cast <int >(mTaskConfig .cycleDurationSeconds * 1000000 ), { " timer period" } });
284296
285- mInputSpecs .emplace_back (InputSpec{ " timer-cycle" , createTaskDataOrigin (), createTaskDataDescription (" TIMER-" + taskName), 0 , Lifetime::Timer });
286- mOptions .push_back ({ " period-timer-cycle" , framework::VariantType::Int, static_cast <int >(mTaskConfig .cycleDurationSeconds * 1000000 ), { " timer period" } });
287- } catch (...) { // catch already here the configuration exception and print it
288- // because if we are in a constructor, the exception could be lost
289- std::string diagnostic = boost::current_exception_diagnostic_information ();
290- LOG (ERROR ) << " Unexpected exception, diagnostic information follows:\n "
291- << diagnostic;
292- throw ;
293- }
294- LOG (INFO ) << " Configuration loaded : " ;
295- LOG (INFO ) << " >> Task name : " << mTaskConfig .taskName ;
296- LOG (INFO ) << " >> Module name : " << mTaskConfig .moduleName ;
297- LOG (INFO ) << " >> Detector name : " << mTaskConfig .detectorName ;
298- LOG (INFO ) << " >> Cycle duration seconds : " << mTaskConfig .cycleDurationSeconds ;
299- LOG (INFO ) << " >> Max number cycles : " << mTaskConfig .maxNumberCycles ;
297+ ILOG (Info) << " Configuration loaded : " << ENDM ;
298+ ILOG (Info) << " >> Task name : " << mTaskConfig .taskName << ENDM ;
299+ ILOG (Info) << " >> Module name : " << mTaskConfig .moduleName << ENDM ;
300+ ILOG (Info) << " >> Detector name : " << mTaskConfig .detectorName << ENDM ;
301+ ILOG (Info) << " >> Cycle duration seconds : " << mTaskConfig .cycleDurationSeconds << ENDM ;
302+ ILOG (Info) << " >> Max number cycles : " << mTaskConfig .maxNumberCycles << ENDM ;
300303}
301304
302305std::string TaskRunner::validateDetectorName (std::string name)
@@ -316,9 +319,9 @@ std::string TaskRunner::validateDetectorName(std::string name)
316319 std::string permittedString;
317320 for (auto i : permitted)
318321 permittedString += i + ' ' ;
319- LOG ( ERROR ) << " Invalid detector name : " << name << " \n "
320- << " Placeholder 'MISC' will be used instead\n "
321- << " Note: list of permitted detector names :" << permittedString;
322+ ILOG (Error ) << " Invalid detector name : " << name << " \n "
323+ << " Placeholder 'MISC' will be used instead\n "
324+ << " Note: list of permitted detector names :" << permittedString << ENDM ;
322325 return " MISC" ;
323326 }
324327 return name;
@@ -349,7 +352,7 @@ void TaskRunner::endOfActivity()
349352
350353void TaskRunner::startCycle ()
351354{
352- QcInfoLogger::GetInstance () << " cycle " << mCycleNumber << " in " << mTaskConfig .taskName << AliceO2::InfoLogger::InfoLogger::endm ;
355+ QcInfoLogger::GetInstance () << " cycle " << mCycleNumber << " in " << mTaskConfig .taskName << ENDM ;
353356 mTask ->startOfCycle ();
354357 mNumberMessages = 0 ;
355358 mNumberObjectsPublishedInCycle = 0 ;
@@ -371,8 +374,8 @@ void TaskRunner::finishCycle(DataAllocator& outputs)
371374 mCycleOn = false ;
372375
373376 if (mTaskConfig .maxNumberCycles == mCycleNumber ) {
374- LOG ( INFO ) << " The maximum number of cycles (" << mTaskConfig .maxNumberCycles << " ) has been reached."
375- << " The task will not do anything from now on." ;
377+ ILOG (Info ) << " The maximum number of cycles (" << mTaskConfig .maxNumberCycles << " ) has been reached."
378+ << " The task will not do anything from now on." << ENDM ;
376379 }
377380}
378381
@@ -400,7 +403,7 @@ void TaskRunner::publishCycleStats()
400403
401404int TaskRunner::publish (DataAllocator& outputs)
402405{
403- QcInfoLogger::GetInstance ( ) << " Send data from " << mTaskConfig .taskName << " len: " << mObjectsManager ->getNumberPublishedObjects () << AliceO2::InfoLogger::InfoLogger::endm ;
406+ ILOG (Info ) << " Send data from " << mTaskConfig .taskName << " len: " << mObjectsManager ->getNumberPublishedObjects () << ENDM ;
404407 AliceO2::Common::Timer publicationDurationTimer;
405408
406409 auto concreteOutput = framework::DataSpecUtils::asConcreteDataMatcher (mMonitorObjectsSpec );
0 commit comments