Skip to content

Commit

Permalink
Merge pull request #65 from antoniogioiosa/antonio
Browse files Browse the repository at this point in the history
Antonio
  • Loading branch information
eflumerf committed Nov 11, 2022
2 parents 269f49a + 25da5f9 commit 7d8ef2c
Show file tree
Hide file tree
Showing 7 changed files with 120 additions and 22 deletions.
12 changes: 6 additions & 6 deletions otsdaq/ConfigurationInterface/ConfigurationManager.cc
Original file line number Diff line number Diff line change
Expand Up @@ -854,17 +854,17 @@ void ConfigurationManager::recursiveTreeToFhicl(ConfigurationTree node,
//==============================================================================
// dumpActiveConfiguration
// if filePath == "", then output to cout
void ConfigurationManager::dumpActiveConfiguration(const std::string& filePath,
const std::string& dumpType,
const std::string& logEntry,
const std::string& activeUsers)
void ConfigurationManager::dumpActiveConfiguration(const std::string& filePath,
const std::string& dumpType, const std::string& logEntry,
const std::string& activeUsers, std::ostream& altOut /* = std::cout */)
{
time_t rawtime = time(0);
__GEN_COUT__ << "filePath = " << filePath << __E__;
__GEN_COUT__ << "dumpType = " << dumpType << __E__;

std::ofstream fs;
fs.open(filePath, std::fstream::out | std::fstream::trunc);
if(filePath != "")
fs.open(filePath, std::fstream::out | std::fstream::trunc);

std::ostream* out;

Expand All @@ -879,7 +879,7 @@ void ConfigurationManager::dumpActiveConfiguration(const std::string& filePath,
__GEN_COUT_ERR__ << ss.str();
__SS_THROW__;
}
out = &(std::cout);
out = &(altOut);
}

(*out) << "#################################" << __E__;
Expand Down
2 changes: 1 addition & 1 deletion otsdaq/ConfigurationInterface/ConfigurationManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ const TableBase* srcPtr = getTableByName(tableName);
const T* retPtr = dynamic_cast<const T*>(srcPtr); if(retPtr == nullptr) { __SS__ << "Illegal cast of '" << tableName << "' to type " << StringMacros::getTypeName<T>() << " (s=" << static_cast<const void*>(srcPtr) <<", t=" << typeid(srcPtr).name() << ")"<< __E__; __SS_THROW__ } return retPtr;}
const TableBase* getTableByName (const std::string& configurationName) const;

void dumpActiveConfiguration (const std::string& filePath, const std::string& dumpType, const std::string& logEntry, const std::string& activeUsers);
void dumpActiveConfiguration (const std::string& filePath, const std::string& dumpType, const std::string& logEntry, const std::string& activeUsers, std::ostream& altOut = std::cout);
void dumpMacroMakerModeFhicl (void);

std::map<std::string /*groupAlias*/,
Expand Down
8 changes: 4 additions & 4 deletions otsdaq/FiniteStateMachine/RunInfoVInterface.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ class RunInfoVInterface // : public Configurable
HALT,
STOP,
ERROR,
PAUSE
PAUSE,
RESUME
};

// NOTE: Memory access violations were happening when we tried to pass const ConfigurationTree& theXDAQContextConfigTree
Expand All @@ -34,9 +35,8 @@ class RunInfoVInterface // : public Configurable
}
virtual ~RunInfoVInterface(void) { ; }

virtual unsigned int claimNextRunNumber(void) = 0;
virtual void updateRunInfo(unsigned int runNumber, RunInfoVInterface::RunStopType runStopType) = 0;

virtual unsigned int claimNextRunNumber (const std::string& runInfoConditions = "") = 0;
virtual void updateRunInfo (unsigned int runNumber, RunInfoVInterface::RunStopType runStopType) = 0;
private:
const std::string mfSubject_;
// ConfigurationTree theXDAQContextConfigTree_;
Expand Down
85 changes: 75 additions & 10 deletions otsdaq/GatewaySupervisor/GatewaySupervisor.cc
Original file line number Diff line number Diff line change
Expand Up @@ -844,7 +844,7 @@ std::string GatewaySupervisor::attemptStateMachineTransition(HttpXmlDocument*

std::string configurationAlias = parameters.getValue("ConfigurationAlias");
__COUT__ << "Configure --> Name: ConfigurationAlias Value: " << configurationAlias << __E__;

lastConfigurationAlias_ = configurationAlias;
// save last used config alias by user
std::string fn =
ConfigurationManager::LAST_TABLE_GROUP_SAVE_PATH + "/" + FSM_LAST_GROUP_ALIAS_FILE_START + username + "." + FSM_USERS_PREFERENCES_FILETYPE;
Expand Down Expand Up @@ -888,7 +888,8 @@ std::string GatewaySupervisor::attemptStateMachineTransition(HttpXmlDocument*
if(commandParameters.size() == 0)
{
runNumber = getNextRunNumber();
// Check if run number should come from db, if so create run info record into database
std::stringstream dumpSs;
//Check if run number should come from db, if so create run info record into database
try
{
ConfigurationTree configLinkNode =
Expand All @@ -904,10 +905,23 @@ std::string GatewaySupervisor::attemptStateMachineTransition(HttpXmlDocument*
RunInfoVInterface* runInfoInterface = nullptr;
try
{
runInfoInterface = makeRunInfo(runInfoPluginType, activeStateMachineName_);
// ,
// CorePropertySupervisorBase::theConfigurationManager_->getSupervisorTableNode(supervisorContextUID_, supervisorApplicationUID_),
// CorePropertySupervisorBase::getSupervisorConfigurationPath());
std::string dumpFormat = fsmLinkNode.getNode("ConfigurationDumpOnRunFormat").getValue<std::string>();

// dump configuration
CorePropertySupervisorBase::theConfigurationManager_->dumpActiveConfiguration(
"", dumpFormat,
"Configuration Alias: " + lastConfigurationAlias_ +
"\n\n" +
"Run note: " + StringMacros::decodeURIComponent(logEntry),
theWebUsers_.getActiveUsersString(),dumpSs);

runInfoInterface = makeRunInfo(
runInfoPluginType,
activeStateMachineName_
);
// ,
// CorePropertySupervisorBase::theConfigurationManager_->getSupervisorTableNode(supervisorContextUID_, supervisorApplicationUID_),
// CorePropertySupervisorBase::getSupervisorConfigurationPath());
}
catch(...)
{
Expand All @@ -919,10 +933,10 @@ std::string GatewaySupervisor::attemptStateMachineTransition(HttpXmlDocument*
__SS_THROW__;
}

runNumber = runInfoInterface->claimNextRunNumber();
} // end Run Info Plugin handling

// test Require user log info
runNumber = runInfoInterface->claimNextRunNumber(dumpSs.str());
} //end Run Info Plugin handling
//test Require user log info
try
{
bool requireUserLogInput = fsmLinkNode.getNode("RequireUserLogInputOnRunTransition").getValue<bool>();
Expand Down Expand Up @@ -1104,6 +1118,57 @@ void GatewaySupervisor::stateRunning(toolbox::fsm::FiniteStateMachine& /*fsm*/)
{
__COUT__ << "Fsm current state: " << theStateMachine_.getCurrentStateName() << __E__;

if(theStateMachine_.getProvenanceStateName() == RunControlStateMachine::PAUSED_STATE_NAME)
{
__COUT__ << "Fsm current state: " << theStateMachine_.getCurrentStateName() << " coming from resume" << __E__;

try
{
ConfigurationTree configLinkNode =
CorePropertySupervisorBase::theConfigurationManager_->getSupervisorTableNode(supervisorContextUID_, supervisorApplicationUID_);
if(!configLinkNode.isDisconnected())
{
ConfigurationTree fsmLinkNode = configLinkNode.getNode("LinkToStateMachineTable").getNode(activeStateMachineName_);
std::string runInfoPluginType = fsmLinkNode.getNode("RunInfoPluginType").getValue<std::string>();
__COUTV__(runInfoPluginType);
if(runInfoPluginType != TableViewColumnInfo::DATATYPE_STRING_DEFAULT && runInfoPluginType != "No Run Info Plugin")
{
RunInfoVInterface* runInfoInterface = nullptr;
try
{
runInfoInterface = makeRunInfo(runInfoPluginType, activeStateMachineName_);
}
catch(...)
{
}

if(runInfoInterface == nullptr)
{
__SS__ << "Run Info interface plugin construction failed of type " << runInfoPluginType << __E__;
__SS_THROW__;
}

runInfoInterface->updateRunInfo(
getNextRunNumber(activeStateMachineName_) - 1,
RunInfoVInterface::RunStopType::RESUME);
}
}
}
catch(const std::runtime_error& e)
{
//ERROR
__SS__ << "RUN INFO RESUME TIME UPDATE INTO DATABASE FAILED!!! "
<< e.what() << __E__;
__SS_THROW__;
}
catch(...)
{
//ERROR
__SS__ << "RUN INFO RESUME TIME UPDATE INTO DATABASE FAILED!!! "
<< __E__;
__SS_THROW__;
} // End update pause time into run info db
} //end update Run Info handling
} // end stateRunning()

//==============================================================================
Expand Down
2 changes: 1 addition & 1 deletion otsdaq/GatewaySupervisor/GatewaySupervisor.h
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,7 @@ class WorkLoopManager;
std::mutex stateMachineAccessMutex_; // for sharing state machine access with
// iterator thread
std::string stateMachineLastCommandInput_;

std::string lastConfigurationAlias_;
enum
{
VERBOSE_MUTEX = 0
Expand Down
14 changes: 14 additions & 0 deletions otsdaq/PluginMakers/MakeRunInfo.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#include "otsdaq/PluginMakers/MakeRunInfo.h"
#include <cetlib/BasicPluginFactory.h>

#include "otsdaq/FiniteStateMachine/RunInfoVInterface.h"

ots::RunInfoVInterface* ots::makeRunInfo(const std::string& runInfoPluginName,
const std::string& runInfoUID)
{
static cet::BasicPluginFactory basicPluginInterfaceFactory("runinfo", "make");

return basicPluginInterfaceFactory
.makePlugin<ots::RunInfoVInterface*, const std::string&, const std::string&>(
runInfoPluginName, runInfoPluginName, runInfoUID);
}
19 changes: 19 additions & 0 deletions otsdaq/PluginMakers/MakeRunInfo.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#ifndef _ots_MakeRunInfo_h_
#define _ots_MakeRunInfo_h_
// Using LibraryManager, find the correct library and return an instance of the specified
// Run Info Interface.

#include <string>

namespace ots
{
class RunInfoVInterface;
class ConfigurationTree;

RunInfoVInterface* makeRunInfo(
const std::string& runInfoPluginName,
const std::string& runInfoUID);

} // namespace ots

#endif /* _ots_MakeRunInfo_h_ */

0 comments on commit 7d8ef2c

Please sign in to comment.