1 #include "otsdaq-utilities/Visualization/VisualSupervisor.h"
2 #include "otsdaq/DataManager/DataManagerSingleton.h"
3 #include "otsdaq/Macros/BinaryStringMacros.h"
4 #include "otsdaq/RootUtilities/VisualDataManager.h"
5 #include "otsdaq/XmlUtilities/XmlDocument.h"
7 #include <boost/regex.hpp>
8 #include "otsdaq/DataManager/DQMHistosConsumerBase.h"
9 #include "otsdaq/Macros/MessageTools.h"
10 #include "otsdaq/RootUtilities/RootFileExplorer.h"
15 #include <TBranchElement.h>
17 #include <TBufferJSON.h>
20 #include <TDirectory.h>
24 #include <TIterator.h>
31 #include "TBufferFile.h"
37 #include <xdaq/NamespaceURI.h>
46 #include "otsdaq/DataManager/DataConsumer.h"
47 #include "otsdaq/DataManager/DataProducerBase.h"
51 #define ROOT_BROWSER_PATH __ENV__("ROOT_BROWSER_PATH")
52 #define ROOT_DISPLAY_CONFIG_PATH __ENV__("ROOT_DISPLAY_CONFIG_PATH")
54 #define LIVEDQM_DIR std::string("LIVE_DQM")
58 #define LIVE_TOP_DIR std::string("Mu2eHistos")
59 #define PRE_MADE_ROOT_CFG_DIR std::string("Pre-made Views")
60 #define HISTORY_DIR std::string("History")
62 #define PRE_MADE_ROOT_CFG_FILE_EXT std::string(".rcfg")
64 #define PREFERENCES_PATH std::string(__ENV__("SERVICE_DATA_PATH")) + "/VisualizerData/"
65 #define PREFERENCES_FILE_EXT ".pref"
67 #define ROOT_VIEWER_PERMISSIONS_THRESHOLD 100
72 #define __MF_SUBJECT__ "Visualizer"
77 #define STDLINE(X, Y) __COUT__ << X
80 VisualSupervisor::VisualSupervisor(xdaq::ApplicationStub* stub)
83 __SUP_COUT__ <<
"Constructor." << __E__;
86 mkdir(((std::string)PREFERENCES_PATH).c_str(), 0755);
87 ROOT::EnableThreadSafety();
89 __SUP_COUT__ <<
"Constructed." << __E__;
93 VisualSupervisor::~VisualSupervisor(
void)
95 __SUP_COUT__ <<
"Destructor." << __E__;
97 __SUP_COUT__ <<
"Destructed." << __E__;
101 void VisualSupervisor::destroy(
void)
103 __SUP_COUT__ <<
"Destroying..." << __E__;
106 if(theStateMachineImplementation_.size() > 1)
108 __SS__ <<
"Not expecting more than one visual data manager!" << __E__;
111 if(theStateMachineImplementation_.size())
112 theStateMachineImplementation_.pop_back();
114 __COUT_WARN__ <<
"No visual data manager was pushed." << __E__;
121 __SUP_COUT__ <<
"Configuring..." << __E__;
123 CoreSupervisorBase::configureInit();
129 theConfigurationManager_->__GET_CONFIG__(
XDAQContextTable)->getTableName() +
130 CorePropertySupervisorBase::getSupervisorConfigurationPath());
132 catch(
const std::runtime_error& e)
134 __SS__ <<
"The link to the Visual Supervisor configuration seems to be broken. "
135 "Please check this path: "
139 CorePropertySupervisorBase::getSupervisorConfigurationPath()
140 << __E__ << __E__ << e.what() << __E__;
145 "/" + theConfigurationManager_->__GET_CONFIG__(
XDAQContextTable)->getTableName() +
146 CorePropertySupervisorBase::getSupervisorConfigurationPath());
152 theDataManager_ = DataManagerSingleton::getInstance<VisualDataManager>(
153 theConfigurationManager_->getNode(
156 CorePropertySupervisorBase::getSupervisorConfigurationPath(),
157 CorePropertySupervisorBase::getSupervisorUID());
159 CoreSupervisorBase::theStateMachineImplementation_.push_back(theDataManager_);
161 __SUP_COUT__ <<
"Done instantiating Visual data manager." << __E__;
164 __SUP_COUT__ <<
"No Visual Supervisor configuration link, so skipping Visual "
165 "data manager instantiation."
169 CoreSupervisorBase::transitionConfiguringFSMs();
171 __SUP_COUT__ <<
"Configured." << __E__;
173 catch(
const std::runtime_error& e)
175 __SS__ <<
"Error with VisualSupervisor::transitionConfiguring(): " << e.what()
177 __COUT_ERR__ << ss.str();
181 theStateMachine_.setErrorMessage(ss.str());
182 throw toolbox::fsm::exception::Exception(
185 "VisualSupervisor::transitionConfiguring" ,
192 void VisualSupervisor::transitionHalting(toolbox::Event::Reference e)
194 __SUP_COUT__ <<
"Halting..." << __E__;
199 __SUP_COUT__ <<
"Halted." << __E__;
208 CorePropertySupervisorBase::setSupervisorProperty(
209 CorePropertySupervisorBase::SUPERVISOR_PROPERTIES.AllowNoLoginRequestTypes,
210 "setUserPreferences | getUserPreferences | getDirectoryContents | getRoot | "
211 "getEvents | getDataStatus");
213 CorePropertySupervisorBase::setSupervisorProperty(
214 CorePropertySupervisorBase::SUPERVISOR_PROPERTIES.UserPermissionsThreshold,
215 "*=1 | rootAdminControls=100");
223 CorePropertySupervisorBase::setSupervisorProperty(
224 CorePropertySupervisorBase::SUPERVISOR_PROPERTIES.AutomatedRequestTypes,
225 "getRoot | getEvents | getDataStatus");
226 CorePropertySupervisorBase::setSupervisorProperty(
227 CorePropertySupervisorBase::SUPERVISOR_PROPERTIES.NoXmlWhiteSpaceRequestTypes,
228 "getRoot | getEvents | getDataStatus");
236 const WebUsers::RequestUserInfo& userInfo)
263 __SUP_COUT__ <<
"Request type: " << requestType << __E__;
267 __SUP_COUT__ << __E__;
272 if(theDataManager_ ==
nullptr)
274 __SS__ <<
"No data manager instantiated." << __E__;
277 __SUP_COUT__ <<
"Getting Raw data and converting to binary string" << __E__;
280 __SUP_COUT__ << __E__;
281 __SUP_SS__ <<
"Raw data visualizion is deprecated!" << __E__;
284 catch(std::exception
const& e)
287 <<
"ERROR! Exception while getting raw data. Incoming exception data..."
289 __SUP_COUT__ << e.what() << __E__;
290 __SUP_COUT__ <<
"End Exception Data" << __E__;
294 __SUP_COUT__ <<
"ERROR! Something went wrong trying to get raw data."
300 catch(
const std::exception& e)
302 __SUP_COUT_ERR__ <<
"Exception message: " << e.what();
307 __SUP_COUT_INFO__ <<
"ERROR! Something went wrong trying to get raw data."
324 xmlOut.addTextElementToData(
326 std::to_string(std::chrono::duration_cast<std::chrono::milliseconds>(
327 std::chrono::system_clock::now().time_since_epoch())
329 xmlOut.addTextElementToData(
331 theDataManager_ !=
nullptr && theDataManager_->isReady() ?
"1" :
"0");
333 if(theDataManager_ !=
nullptr)
335 auto addProcessor = [&xmlOut](
const std::string& role,
336 const std::string& bufferName,
339 unsigned int capacity) {
340 xercesc::DOMElement* el = xmlOut.addTextElementToData(
"processor",
"");
345 "packets", std::to_string(processor->getStatPackets()), el);
347 "bytes", std::to_string(processor->getStatBytes()), el);
349 "errors", std::to_string(processor->getStatErrors()), el);
351 "busyNanos", std::to_string(processor->getStatBusyNanos()), el);
354 for(
auto const& extra : processor->getExtraStatus())
358 for(
auto const& bufferPair : theDataManager_->getBuffers())
360 const auto& buffer = bufferPair.second;
361 for(
auto const* producer : buffer.producers_)
363 unsigned int queued = 0, capacity = 0;
364 if(buffer.buffer_ !=
nullptr)
368 capacity = buffer.buffer_->getProducerBufferSize(
369 producer->getProcessorID());
370 queued = buffer.buffer_->getProducerWrittenBuffers(
371 producer->getProcessorID());
378 "producer", bufferPair.first, producer, queued, capacity);
380 for(
auto const* consumer : buffer.consumers_)
381 addProcessor(
"consumer", bufferPair.first, consumer, 0, 0);
386 requestType ==
"setUserPreferences" &&
387 userInfo.username_ !=
390 __SUP_COUT__ <<
"userInfo.username_: " << userInfo.username_ << __E__;
391 std::string fullPath =
392 (std::string)PREFERENCES_PATH + userInfo.username_ + PREFERENCES_FILE_EXT;
393 __SUP_COUT__ <<
"fullPath: " << fullPath << __E__;
399 std::string autoRefreshPeriod =
402 __SUP_COUT__ <<
"radioSelect: " << radioSelect << __E__;
403 __SUP_COUT__ <<
"autoRefresh: " << autoRefresh << __E__;
404 __SUP_COUT__ <<
"autoHide: " << autoHide << __E__;
405 __SUP_COUT__ <<
"hardRefresh: " << hardRefresh << __E__;
406 __SUP_COUT__ <<
"autoRefreshPeriod: " << autoRefreshPeriod << __E__;
409 FILE* fp = fopen(fullPath.c_str(),
"r");
415 fgets(line, 100, fp);
416 sscanf(line,
"%*s %s", val);
417 if(radioSelect ==
"")
420 fgets(line, 100, fp);
421 sscanf(line,
"%*s %s", val);
422 if(autoRefresh ==
"")
425 fgets(line, 100, fp);
426 sscanf(line,
"%*s %s", val);
430 fgets(line, 100, fp);
431 sscanf(line,
"%*s %s", val);
432 if(hardRefresh ==
"")
435 fgets(line, 100, fp);
436 sscanf(line,
"%*s %s", val);
437 if(autoRefreshPeriod ==
"")
438 autoRefreshPeriod = val;
444 fp = fopen(fullPath.c_str(),
"w");
447 fprintf(fp,
"radioSelect %s\n", radioSelect.c_str());
448 fprintf(fp,
"autoRefresh %s\n", autoRefresh.c_str());
449 fprintf(fp,
"autoHide %s\n", autoHide.c_str());
450 fprintf(fp,
"hardRefresh %s\n", hardRefresh.c_str());
451 fprintf(fp,
"autoRefreshPeriod %s\n", autoRefreshPeriod.c_str());
455 __SUP_COUT_ERR__ <<
"Failure writing preferences to file: " << fullPath
460 "getUserPreferences")
462 __SUP_COUT__ <<
"Next is userinfo" << __E__;
463 __SUP_COUT__ <<
"userInfo.username_: " << userInfo.username_ << __E__;
464 std::string fullPath =
465 (std::string)PREFERENCES_PATH + userInfo.username_ + PREFERENCES_FILE_EXT;
466 __SUP_COUT__ <<
"fullPath: " << fullPath << __E__;
468 FILE* fp = fopen(fullPath.c_str(),
"r");
475 fgets(line, 100, fp);
476 sscanf(line,
"%*s %d", &val);
477 if(val < 0 || val > 3)
479 xmlOut.addTextElementToData(
"radioSelect", std::to_string(val));
480 fgets(line, 100, fp);
481 sscanf(line,
"%*s %d", &val);
482 xmlOut.addTextElementToData(
"autoRefresh", std::to_string(val));
483 fgets(line, 100, fp);
484 sscanf(line,
"%*s %d", &val);
485 xmlOut.addTextElementToData(
"autoHide", std::to_string(val));
486 fgets(line, 100, fp);
487 sscanf(line,
"%*s %d", &val);
488 xmlOut.addTextElementToData(
"hardRefresh", std::to_string(val));
489 fgets(line, 100, fp);
490 sscanf(line,
"%*s %d", &val);
491 xmlOut.addTextElementToData(
"autoRefreshPeriod", std::to_string(val));
497 xmlOut.addTextElementToData(
"radioSelect",
"");
498 xmlOut.addTextElementToData(
"autoRefresh",
"");
499 xmlOut.addTextElementToData(
"autoHide",
"");
500 xmlOut.addTextElementToData(
"hardRefresh",
"");
501 xmlOut.addTextElementToData(
"autoRefreshPeriod",
"");
503 __SUP_COUT__ <<
"Done with preferences!" << __E__;
507 "getDirectoryContents")
510 std::string rootpath =
511 std::string(ROOT_BROWSER_PATH) +
514 boost::regex re(
"%2F");
515 path = boost::regex_replace(path, re,
"/");
525 userInfo.permissionLevel_ >=
527 "rootAdminControls"));
528 xmlOut.addTextElementToData(
"permissions", permStr);
532 std::string dirpath = rootpath + path;
534 if(path ==
"/" + PRE_MADE_ROOT_CFG_DIR +
"/")
535 dirpath = ROOT_DISPLAY_CONFIG_PATH;
537 if(path.find(
"/" + PRE_MADE_ROOT_CFG_DIR +
"/") ==
539 dirpath = std::string(ROOT_DISPLAY_CONFIG_PATH) +
"/" +
540 path.substr(PRE_MADE_ROOT_CFG_DIR.length() + 2);
543 if(path ==
"/" + HISTORY_DIR +
"/")
544 dirpath = std::string(ROOT_BROWSER_PATH) +
"/";
545 else if(path.find(
"/" + HISTORY_DIR +
"/") == 0)
546 dirpath = std::string(ROOT_BROWSER_PATH) +
"/" +
547 path.substr(HISTORY_DIR.length() + 2);
550 __SUP_COUT__ <<
"rootpath:-" << rootpath <<
"-path:-" << path <<
"-dirpath:-"
551 << dirpath <<
"-" << __E__;
554 struct dirent* entry;
557 if((pDIR = opendir(dirpath.c_str())))
559 xmlOut.addTextElementToData(
"path", path);
560 xmlOut.addTextElementToData(
"headOfSearch",
"located");
565 if(theDataManager_ !=
nullptr)
566 __COUT__ <<
"path-" << path <<
"-DM: " << theDataManager_
567 <<
" Live: " << theDataManager_->getLiveDQMHistos() << std::endl;
573 if(theDataManager_ !=
nullptr && theDataManager_->isReady())
574 xmlOut.addTextElementToData(
"dir",
575 LIVEDQM_DIR +
".root");
578 DIR* pRtDIR = opendir(ROOT_DISPLAY_CONFIG_PATH);
579 bool recheck =
false;
583 if(mkdir(ROOT_DISPLAY_CONFIG_PATH,
584 S_IRWXU | (S_IRGRP | S_IXGRP) |
585 (S_IROTH | S_IXOTH)))
586 __SUP_COUT__ <<
"Failed to make directory for pre made views: "
587 << ROOT_DISPLAY_CONFIG_PATH << __E__;
592 if(!recheck || (pRtDIR = opendir(ROOT_DISPLAY_CONFIG_PATH)))
596 xmlOut.addTextElementToData(
"dir",
597 PRE_MADE_ROOT_CFG_DIR);
602 xmlOut.addTextElementToData(
"dir", HISTORY_DIR);
606 while((entry = readdir(pDIR)))
610 if(entry->d_name[0] !=
'.' &&
613 entry->d_type == 4 ||
619 std::string(entry->d_name).find(
".rcfg") == std::string::npos;
622 if(entry->d_type == 0)
626 DIR* pTmpDIR = opendir((dirpath + entry->d_name).c_str());
636 if((entry->d_type == 8 ||
637 (!isDir && entry->d_type == 0))
638 && std::string(entry->d_name).find(
".root") ==
642 else if(entry->d_type == 4)
645 xmlOut.addTextElementToData(
646 isDir ?
"dir" : (isNotRtCfg ?
"dir" :
"file"), entry->d_name);
652 __SUP_COUT__ <<
"Failed to access directory contents!" << __E__;
665 std::string filePath = path;
666 if(filePath.find(
"/" + HISTORY_DIR +
"/") == 0)
667 filePath = filePath.substr(HISTORY_DIR.length() + 1);
670 filePath.find(
".root") + 5;
671 std::string rootFileName =
672 std::string(__ENV__(
"ROOT_BROWSER_PATH")) + filePath.substr(0, splitter);
673 __SUP_COUTV__(rootFileName);
675 std::string rootDirectoryName =
676 filePath.substr(splitter, filePath.length() - splitter);
677 __SUP_COUTV__(rootDirectoryName);
682 bool isLiveDQM = (path.find(
"/" + LIVEDQM_DIR +
".root/") == 0) ?
true :
false;
683 __SUP_COUTV__(isLiveDQM);
689 const std::string top =
"/" + LIVE_TOP_DIR;
690 if(rootDirectoryName.empty() || rootDirectoryName ==
"/")
691 rootDirectoryName = top;
692 else if(rootDirectoryName != top &&
693 rootDirectoryName.rfind(top +
"/", 0) != 0)
694 rootDirectoryName = top + rootDirectoryName;
695 __SUP_COUTV__(rootDirectoryName);
698 TFile* rootFile =
nullptr;
699 TObject* tObject =
nullptr;
700 TDirectory* tDirectory =
nullptr;
704 rootFile = TFile::Open(rootFileName.c_str());
706 if(rootFile ==
nullptr || !rootFile->IsOpen())
708 __SUP_SS__ <<
"Failed to access ROOT file: " << rootFileName << __E__;
714 std::unique_ptr<TFile> rootFileGuard(rootFile);
717 if((tObject = rootFile->Get(rootDirectoryName.c_str())) !=
719 (rootDirectoryName.size() &&
720 rootDirectoryName[0] ==
'/' &&
721 (tObject = rootFile->Get(rootDirectoryName.substr(1).c_str())) !=
724 if(tObject->IsA() == TCanvas::Class())
726 static_cast<TCanvas*
>(tObject)->Modified();
727 static_cast<TCanvas*
>(tObject)->Update();
729 TString json = TBufferJSON::ConvertToJSON(tObject);
730 TBufferFile tBuffer(TBuffer::kWrite);
731 tObject->Streamer(tBuffer);
733 tBuffer.Buffer(), tBuffer.Length());
735 __SUP_COUT__ <<
"Returning object from file '" << tObject->GetName()
736 <<
"' of class '" << tObject->ClassName() << __E__;
738 xmlOut.addTextElementToData(
"path", path);
739 xmlOut.addTextElementToData(
"rootType", tObject->ClassName());
740 xmlOut.addTextElementToData(
"rootData", hexString);
741 xmlOut.addTextElementToData(
"rootJSON", json.Data());
743 else if((tDirectory = rootFile->GetDirectory(rootDirectoryName.c_str())) !=
747 TIter next(tDirectory->GetListOfKeys());
748 xmlOut.addTextElementToData(
"path", path);
749 while((key = (TKey*)next()))
751 TString s = key->GetName();
752 TRegexp re(
"*", kTRUE);
753 if(s.Index(re) == kNPOS)
755 __SUP_COUT__ <<
"Class Name: " << key->GetClassName() << __E__;
756 xmlOut.addTextElementToData(
757 (std::string(key->GetClassName()).find(
"Directory") !=
759 std::string(key->GetClassName()) ==
"TTree" ||
760 std::string(key->GetClassName()).find(
"TBranch") !=
769 tObject = key->ReadObj();
770 __SUP_COUT__ <<
"JSON : " << key->GetClassName() << __E__;
772 TString json = TBufferJSON::ConvertToJSON(tObject);
773 TBufferFile tBuffer(TBuffer::kWrite);
774 tObject->Streamer(tBuffer);
775 std::string hexString =
779 __SUP_COUT__ <<
"Returning directory object from file '"
780 << tObject->GetName() <<
"' of class '"
781 << tObject->ClassName() << __E__;
783 __SUP_COUTV__(json.Data());
788 __SUP_COUT_ERR__ <<
"Failed to find object " << rootDirectoryName
789 <<
" in " << rootFileName << __E__;
793 else if(theDataManager_ !=
nullptr && theDataManager_->isReady())
795 if(theDataManager_ !=
nullptr)
796 theDataManager_->setDoNotStop(
true);
799 __SUP_COUT__ <<
"Attempting to get LIVE ROOT object." << __E__;
801 std::vector<DQMHistosBase*> dqmConsumers = theDataManager_->
getLiveDQMs();
803 for(
auto const& consumer : dqmConsumers)
805 rootFile = consumer->getFile();
806 __SUP_COUT__ <<
"LIVE file name: " << rootFile->GetName() << __E__;
807 if(rootFile ==
nullptr || !rootFile->IsOpen())
809 __SUP_SS__ <<
"Failed to access LIVE ROOT file: " << rootFileName
811 theDataManager_->setDoNotStop(
false);
815 if((tObject = rootFile->Get(rootDirectoryName.c_str())) !=
nullptr)
817 __SUP_COUT__ <<
"Object class name: " << tObject->ClassName()
819 std::string tmpClassName = tObject->ClassName();
821 TBufferFile tBuffer(TBuffer::kWrite);
822 if(tObject->IsA() == TCanvas::Class())
824 static_cast<TCanvas*
>(tObject)->Modified();
825 static_cast<TCanvas*
>(tObject)->Update();
828 std::unique_lock<std::mutex> lock(
830 ->getFillHistoMutex());
831 json = TBufferJSON::ConvertToJSON(tObject);
832 tObject->Streamer(tBuffer);
835 tBuffer.Buffer(), tBuffer.Length());
837 __SUP_COUT__ <<
"Returning object '" << tObject->GetName()
838 <<
"' of class '" << tObject->ClassName() << __E__;
841 xmlOut.addTextElementToData(
"path", path);
842 xmlOut.addTextElementToData(
"rootType", tObject->ClassName());
843 xmlOut.addTextElementToData(
"rootData", hexString);
844 xmlOut.addTextElementToData(
"rootJSON", json.Data());
846 theDataManager_->setDoNotStop(
false);
851 std::map<std::string, std::string> dirList;
853 for(
auto const& consumer : dqmConsumers)
855 __SUP_COUT__ <<
"Attempting to get LIVE ROOT directory." << __E__;
856 rootFile = consumer->getFile();
857 __SUP_COUT__ <<
"LIVE file name: " << rootFile->GetName() << __E__;
858 if(rootFile ==
nullptr || !rootFile->IsOpen())
860 __SUP_SS__ <<
"Failed to access LIVE ROOT file: " << rootFileName
862 xmlOut.addTextElementToData(
"Warning", ss.str());
863 theDataManager_->setDoNotStop(
false);
866 if((tDirectory = rootFile->GetDirectory(rootDirectoryName.c_str())) !=
869 xmlOut.addTextElementToData(
"path", path);
870 __SUP_COUT__ <<
"Directory found getting the content!" << __E__;
871 TRegexp re(
"*", kTRUE);
873 TIter nextobj(tDirectory->GetList());
874 while((obj = (TObject*)nextobj()))
876 TString s = obj->GetName();
877 if(s.Index(re) == kNPOS)
879 __SUP_COUT__ <<
"Class Name: " << obj->IsA()->GetName() << __E__;
880 dirList[obj->GetName()] =
881 (std::string(obj->IsA()->GetName()).find(
"Directory") !=
883 std::string(obj->IsA()->GetName()) ==
"TTree" ||
884 std::string(obj->IsA()->GetName()).find(
"TBranch") !=
891 for(
auto const& dir : dirList)
893 xmlOut.addTextElementToData(dir.second, dir.first);
894 __SUP_COUT__ <<
"Class Name: " << dir.second <<
" Object: " << dir.first
1302 if(theDataManager_ ==
nullptr)
1304 __SS__ <<
"No Data Manager instantiated." << __E__;
1308 int Run = atoi(cgiIn(
"run").c_str());
1310 __SUP_COUT__ <<
"getEvents for run " << Run << __E__;
1312 if(Run != (
int)loadedRunNumber_ || loadedRunNumber_ == (
unsigned int)-1)
1314 theDataManager_->load(
"Run1684.root",
"Monicelli");
1315 loadedRunNumber_ = Run;
1318 xmlOut.addTextElementToData(
"events",
"");
1361 __SUP_COUT__ <<
"Done hits xml" << __E__;
1367 __SUP_COUT__ <<
"getGeometry" << __E__;
1369 if(theDataManager_ ==
nullptr)
1371 __SS__ <<
"No Data Manager instantiated." << __E__;
1376 theDataManager_->load(
"Run1684.geo",
"Geometry");
1378 __SUP_COUT__ <<
"getGeometry" << __E__;
1380 xmlOut.addTextElementToData(
"geometry",
"");
1416 __SUP_COUT__ <<
"path " << path << __E__;
1418 if(path.find(
"/" + PRE_MADE_ROOT_CFG_DIR +
"/") ==
1421 path = std::string(ROOT_DISPLAY_CONFIG_PATH) +
"/" +
1422 path.substr(PRE_MADE_ROOT_CFG_DIR.length() + 2);
1423 __SUP_COUT__ <<
"mod path " << path << __E__;
1429 xmlOut.addTextElementToData(
"status",
"1");
1434 xmlOut.addTextElementToData(
"status",
1435 "Failed. File to properly load config file.");
1439 "rootAdminControls")
1451 std::string cmd = cgiIn(
"cmd");
1458 __SUP_COUT__ <<
"cmd " << cmd << __E__;
1459 __SUP_COUT__ <<
"path " << path << __E__;
1460 __SUP_COUT__ <<
"name " << name << __E__;
1462 if(path.find(
"/" + PRE_MADE_ROOT_CFG_DIR +
"/") ==
1465 path = std::string(ROOT_DISPLAY_CONFIG_PATH) +
"/" +
1466 path.substr(PRE_MADE_ROOT_CFG_DIR.length() + 2) + name;
1467 __SUP_COUT__ <<
"mod path " << path << __E__;
1471 if(mkdir(path.c_str(),
1472 S_IRWXU | (S_IRGRP | S_IXGRP) |
1473 (S_IROTH | S_IXOTH)))
1474 xmlOut.addTextElementToData(
"status",
1475 "Failed. Directory create rejected.");
1477 xmlOut.addTextElementToData(
"status",
"1");
1479 else if(cmd ==
"save")
1481 path += PRE_MADE_ROOT_CFG_FILE_EXT;
1483 bool useRunWildCard =
1487 __SUP_COUT__ <<
"config " << config << __E__;
1488 __SUP_COUT__ <<
"useRunWildCard " << useRunWildCard << __E__;
1491 FILE* fp = fopen(path.c_str(),
"r");
1495 xmlOut.addTextElementToData(
"status",
"Failed. File already exists.");
1496 __SUP_COUT__ <<
" Failed. File already exists." << __E__;
1505 fp = fopen(path.c_str(),
"w");
1506 fputs(config.c_str(), fp);
1515 xmlOut.addTextElementToData(
"status",
"1");
1519 xmlOut.addTextElementToData(
1520 "status",
"Failed. Fatal. Improper file format.");
1521 if(remove(path.c_str()) != 0)
1522 __SUP_COUT__ <<
"Failed. Could not remove poorly formed Root "
1528 else if(cmd ==
"delete")
1531 if(rmdir(path.c_str()) == 0 ||
1532 remove((path + PRE_MADE_ROOT_CFG_FILE_EXT).c_str()) == 0)
1533 xmlOut.addTextElementToData(
"status",
"1");
1535 xmlOut.addTextElementToData(
"status",
1536 "Failed. Target could not be deleted.");
1539 xmlOut.addTextElementToData(
"status",
"Failed. Unrecognized command.");
1542 xmlOut.addTextElementToData(
"status",
"Failed. Invalid path.");
1551 std::string fSystemPath = std::string(ROOT_BROWSER_PATH) +
"/";
1553 boost::regex re(
"%2F");
1554 fRootPath = boost::regex_replace(fRootPath, re,
"/");
1555 std::string fullPath = fSystemPath + fRootPath;
1557 STDLINE(std::string(
"Begin: fSystemPath = ") + fSystemPath, ACWhite);
1558 STDLINE(std::string(
"Begin: fRootPath = ") + fRootPath, ACWhite);
1559 STDLINE(std::string(
"Begin: fullPath = ") + fullPath, ACWhite);
1562 xmlOut.setRootPath(fRootPath);
1563 xmlOut.makeDirectoryBinaryTree(fSystemPath, fRootPath, 0, NULL);
1564 std::ostringstream* out =
new std::ostringstream();
1572 std::string fSystemPath = std::string(ROOT_BROWSER_PATH) +
"/";
1578 boost::regex re(
"%2F");
1579 fRootPath = boost::regex_replace(fRootPath, re,
"/");
1580 fFoldersPath = boost::regex_replace(fFoldersPath, re,
"/");
1588 fSystemPath, fRootPath, fFoldersPath, fHistName, fRFoldersPath, fFileName);
1589 xmlOut.setDocument(theExplorer->initialize(
false));
1655 "saveConfiguration")
1658 STDLINE(
"configPayload: ", ACRed);
1659 STDLINE(configPayload, ACYellow);
1662 outFile.open(
"/tmp/configPayload.json", ios::out | ios::app);
1663 outFile << configPayload << endl;
1671 std::string JSONPayLoad =
"";
1672 std::string line =
"";
1674 ifstream JSONFile(
"/tmp/configPayload.json");
1676 if(JSONFile.is_open())
1678 while(getline(JSONFile, line))
1680 JSONPayLoad += line;
1685 xmlOut.addTextElementToData(
"JSONPayLoad", JSONPayLoad);
1693 std::string fsmName = theStateMachine_.getCurrentStateName();
1694 bool in_transition = theStateMachine_.isInTransition();
1696 xmlOut.addTextElementToData(
"current_state", fsmName);
1697 xmlOut.addTextElementToData(
"in_transition", in_transition ?
"1" :
"0");
1701 __SUP_SS__ <<
"requestType Request, " << requestType
1702 <<
", not recognized by the Visual Supervisor (was it intended for "
1703 "another Supervisor?)."
1708 if(theDataManager_ !=
nullptr)
1709 theDataManager_->setDoNotStop(
false);
static std::string postData(cgicc::Cgicc &cgi, const std::string &needle)
static std::string getData(cgicc::Cgicc &cgi, const std::string &needle)
bool isDisconnected(void) const
ConfigurationTree getNode(const std::string &nodeName, bool doNotThrowOnBrokenUIDLinks=false) const
const std::string & getValueAsString(bool returnLinkTableValue=false) const
WebUsers::permissionLevel_t getSupervisorPropertyUserPermissionsThreshold(const std::string &requestType)
virtual void transitionHalting(toolbox::Event::Reference event)
static void deleteInstance(std::string instanceUID)
void copyDataChildren(HttpXmlDocument &document)
bool loadXmlDocument(const std::string &filePath)
void outputXmlDocument(std::ostringstream *out, bool dispStdOut=false, bool allowWhiteSpace=false, bool printErrors=false)
const std::vector< DQMHistosBase * > & getLiveDQMs(void)
virtual void setSupervisorPropertyDefaults(void) override
virtual void forceSupervisorPropertyValues(void) override
virtual void transitionConfiguring(toolbox::Event::Reference e) override
virtual void request(const std::string &requestType, cgicc::Cgicc &cgiIn, HttpXmlDocument &xmlOut, const WebUsers::RequestUserInfo &userInfo) override
xercesc::DOMElement * addTextElementToParent(const std::string &childName, const std::string &childText, xercesc::DOMElement *parent)
void setDarioStyle(bool darioStyle)
void saveXmlDocument(const std::string &filePath)
void INIT_MF(const char *name)
static std::string binaryStringToHexString(const void *binaryBuffer, unsigned int numberOfBytes, const std::string &resultPreamble="", const std::string &resultDelimiter="")