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>
47 #define ROOT_BROWSER_PATH __ENV__("ROOT_BROWSER_PATH")
48 #define ROOT_DISPLAY_CONFIG_PATH __ENV__("ROOT_DISPLAY_CONFIG_PATH")
50 #define LIVEDQM_DIR std::string("LIVE_DQM")
51 #define PRE_MADE_ROOT_CFG_DIR std::string("Pre-made Views")
53 #define PRE_MADE_ROOT_CFG_FILE_EXT std::string(".rcfg")
55 #define PREFERENCES_PATH std::string(__ENV__("SERVICE_DATA_PATH")) + "/VisualizerData/"
56 #define PREFERENCES_FILE_EXT ".pref"
58 #define ROOT_VIEWER_PERMISSIONS_THRESHOLD 100
63 #define __MF_SUBJECT__ "Visualizer"
68 #define STDLINE(X, Y) __COUT__ << X
71 VisualSupervisor::VisualSupervisor(xdaq::ApplicationStub* stub)
72 : CoreSupervisorBase(stub), theDataManager_(nullptr), loadedRunNumber_(-1)
74 __SUP_COUT__ <<
"Constructor." << __E__;
75 INIT_MF(
"VisualSupervisor");
77 mkdir(((std::string)PREFERENCES_PATH).c_str(), 0755);
78 ROOT::EnableThreadSafety();
80 __SUP_COUT__ <<
"Constructed." << __E__;
84 VisualSupervisor::~VisualSupervisor(
void)
86 __SUP_COUT__ <<
"Destructor." << __E__;
88 __SUP_COUT__ <<
"Destructed." << __E__;
92 void VisualSupervisor::destroy(
void)
94 __SUP_COUT__ <<
"Destroying..." << __E__;
96 DataManagerSingleton::deleteInstance(CorePropertySupervisorBase::getSupervisorUID());
97 if(theStateMachineImplementation_.size() > 1)
99 __SS__ <<
"Not expecting more than one visual data manager!" << __E__;
102 if(theStateMachineImplementation_.size())
103 theStateMachineImplementation_.pop_back();
105 __COUT_WARN__ <<
"No visual data manager was pushed." << __E__;
112 __SUP_COUT__ <<
"Configuring..." << __E__;
116 if(RunControlStateMachine::getIterationIndex() == 0 &&
117 RunControlStateMachine::getSubIterationIndex() == 0)
119 std::pair<std::string , TableGroupKey> theGroup(
120 SOAPUtilities::translate(theStateMachine_.getCurrentMessage())
122 .getValue(
"ConfigurationTableGroupName"),
124 SOAPUtilities::translate(theStateMachine_.getCurrentMessage())
126 .getValue(
"ConfigurationTableGroupKey")));
128 __SUP_COUT__ <<
"Configuration table group name: " << theGroup.first
129 <<
" key: " << theGroup.second << __E__;
132 theConfigurationManager_->loadTableGroup(
145 ConfigurationManager::LoadGroupType::ALL_TYPES,
152 ConfigurationTree testAppLink = theConfigurationManager_->getNode(
154 theConfigurationManager_->__GET_CONFIG__(XDAQContextTable)->getTableName() +
155 CorePropertySupervisorBase::getSupervisorConfigurationPath());
157 catch(
const std::runtime_error& e)
159 __SS__ <<
"The link to the Visual Supervisor configuration seems to be broken. "
160 "Please check this path: "
162 theConfigurationManager_->__GET_CONFIG__(XDAQContextTable)
164 CorePropertySupervisorBase::getSupervisorConfigurationPath()
165 << __E__ << __E__ << e.what() << __E__;
169 ConfigurationTree appLink = theConfigurationManager_->getNode(
170 "/" + theConfigurationManager_->__GET_CONFIG__(XDAQContextTable)->getTableName() +
171 CorePropertySupervisorBase::getSupervisorConfigurationPath());
173 __COUTV__(appLink.getValueAsString());
175 if(!appLink.isDisconnected())
177 theDataManager_ = DataManagerSingleton::getInstance<VisualDataManager>(
178 theConfigurationManager_->getNode(
179 theConfigurationManager_->__GET_CONFIG__(XDAQContextTable)
181 CorePropertySupervisorBase::getSupervisorConfigurationPath(),
182 CorePropertySupervisorBase::getSupervisorUID());
184 CoreSupervisorBase::theStateMachineImplementation_.push_back(theDataManager_);
186 __SUP_COUT__ <<
"Done instantiating Visual data manager." << __E__;
189 __SUP_COUT__ <<
"No Visual Supervisor configuration link, so skipping Visual "
190 "data manager instantiation."
194 CoreSupervisorBase::transitionConfiguringFSMs();
196 __SUP_COUT__ <<
"Configured." << __E__;
198 catch(
const std::runtime_error& e)
200 __SS__ <<
"Error with VisualSupervisor::transitionConfiguring(): " << e.what()
202 __COUT_ERR__ << ss.str();
206 theStateMachine_.setErrorMessage(ss.str());
207 throw toolbox::fsm::exception::Exception(
210 "VisualSupervisor::transitionConfiguring" ,
217 void VisualSupervisor::transitionHalting(toolbox::Event::Reference e)
219 __SUP_COUT__ <<
"Halting..." << __E__;
221 CoreSupervisorBase::transitionHalting(e);
224 __SUP_COUT__ <<
"Halted." << __E__;
233 CorePropertySupervisorBase::setSupervisorProperty(
234 CorePropertySupervisorBase::SUPERVISOR_PROPERTIES.AllowNoLoginRequestTypes,
235 "setUserPreferences | getUserPreferences | getDirectoryContents | getRoot | "
238 CorePropertySupervisorBase::setSupervisorProperty(
239 CorePropertySupervisorBase::SUPERVISOR_PROPERTIES.UserPermissionsThreshold,
240 "*=1 | rootAdminControls=100");
248 CorePropertySupervisorBase::setSupervisorProperty(
249 CorePropertySupervisorBase::SUPERVISOR_PROPERTIES.AutomatedRequestTypes,
250 "getRoot | getEvents");
251 CorePropertySupervisorBase::setSupervisorProperty(
252 CorePropertySupervisorBase::SUPERVISOR_PROPERTIES.NoXmlWhiteSpaceRequestTypes,
253 "getRoot | getEvents");
260 HttpXmlDocument& xmlOut,
261 const WebUsers::RequestUserInfo& userInfo)
288 __SUP_COUT__ <<
"Request type: " << requestType << __E__;
292 __SUP_COUT__ << __E__;
297 if(theDataManager_ ==
nullptr)
299 __SS__ <<
"No data manager instantiated." << __E__;
302 __SUP_COUT__ <<
"Getting Raw data and converting to binary string" << __E__;
305 __SUP_COUT__ << __E__;
306 __SUP_SS__ <<
"Raw data visualizion is deprecated!" << __E__;
309 catch(std::exception
const& e)
312 <<
"ERROR! Exception while getting raw data. Incoming exception data..."
314 __SUP_COUT__ << e.what() << __E__;
315 __SUP_COUT__ <<
"End Exception Data" << __E__;
319 __SUP_COUT__ <<
"ERROR! Something went wrong trying to get raw data."
325 catch(
const std::exception& e)
327 __SUP_COUT_ERR__ <<
"Exception message: " << e.what();
332 __SUP_COUT_INFO__ <<
"ERROR! Something went wrong trying to get raw data."
337 requestType ==
"setUserPreferences" &&
338 userInfo.username_ !=
341 __SUP_COUT__ <<
"userInfo.username_: " << userInfo.username_ << __E__;
342 std::string fullPath =
343 (std::string)PREFERENCES_PATH + userInfo.username_ + PREFERENCES_FILE_EXT;
344 __SUP_COUT__ <<
"fullPath: " << fullPath << __E__;
346 std::string radioSelect = CgiDataUtilities::getData(cgiIn,
"radioSelect");
347 std::string autoRefresh = CgiDataUtilities::getData(cgiIn,
"autoRefresh");
348 std::string autoHide = CgiDataUtilities::getData(cgiIn,
"autoHide");
349 std::string hardRefresh = CgiDataUtilities::getData(cgiIn,
"hardRefresh");
350 std::string autoRefreshPeriod =
351 CgiDataUtilities::getData(cgiIn,
"autoRefreshPeriod");
353 __SUP_COUT__ <<
"radioSelect: " << radioSelect << __E__;
354 __SUP_COUT__ <<
"autoRefresh: " << autoRefresh << __E__;
355 __SUP_COUT__ <<
"autoHide: " << autoHide << __E__;
356 __SUP_COUT__ <<
"hardRefresh: " << hardRefresh << __E__;
357 __SUP_COUT__ <<
"autoRefreshPeriod: " << autoRefreshPeriod << __E__;
360 FILE* fp = fopen(fullPath.c_str(),
"r");
366 fgets(line, 100, fp);
367 sscanf(line,
"%*s %s", val);
368 if(radioSelect ==
"")
371 fgets(line, 100, fp);
372 sscanf(line,
"%*s %s", val);
373 if(autoRefresh ==
"")
376 fgets(line, 100, fp);
377 sscanf(line,
"%*s %s", val);
381 fgets(line, 100, fp);
382 sscanf(line,
"%*s %s", val);
383 if(hardRefresh ==
"")
386 fgets(line, 100, fp);
387 sscanf(line,
"%*s %s", val);
388 if(autoRefreshPeriod ==
"")
389 autoRefreshPeriod = val;
395 fp = fopen(fullPath.c_str(),
"w");
398 fprintf(fp,
"radioSelect %s\n", radioSelect.c_str());
399 fprintf(fp,
"autoRefresh %s\n", autoRefresh.c_str());
400 fprintf(fp,
"autoHide %s\n", autoHide.c_str());
401 fprintf(fp,
"hardRefresh %s\n", hardRefresh.c_str());
402 fprintf(fp,
"autoRefreshPeriod %s\n", autoRefreshPeriod.c_str());
406 __SUP_COUT_ERR__ <<
"Failure writing preferences to file: " << fullPath
411 "getUserPreferences")
413 __SUP_COUT__ <<
"Next is userinfo" << __E__;
414 __SUP_COUT__ <<
"userInfo.username_: " << userInfo.username_ << __E__;
415 std::string fullPath =
416 (std::string)PREFERENCES_PATH + userInfo.username_ + PREFERENCES_FILE_EXT;
417 __SUP_COUT__ <<
"fullPath: " << fullPath << __E__;
419 FILE* fp = fopen(fullPath.c_str(),
"r");
426 fgets(line, 100, fp);
427 sscanf(line,
"%*s %d", &val);
428 if(val < 0 || val > 3)
430 xmlOut.addTextElementToData(
"radioSelect", std::to_string(val));
431 fgets(line, 100, fp);
432 sscanf(line,
"%*s %d", &val);
433 xmlOut.addTextElementToData(
"autoRefresh", std::to_string(val));
434 fgets(line, 100, fp);
435 sscanf(line,
"%*s %d", &val);
436 xmlOut.addTextElementToData(
"autoHide", std::to_string(val));
437 fgets(line, 100, fp);
438 sscanf(line,
"%*s %d", &val);
439 xmlOut.addTextElementToData(
"hardRefresh", std::to_string(val));
440 fgets(line, 100, fp);
441 sscanf(line,
"%*s %d", &val);
442 xmlOut.addTextElementToData(
"autoRefreshPeriod", std::to_string(val));
448 xmlOut.addTextElementToData(
"radioSelect",
"");
449 xmlOut.addTextElementToData(
"autoRefresh",
"");
450 xmlOut.addTextElementToData(
"autoHide",
"");
451 xmlOut.addTextElementToData(
"hardRefresh",
"");
452 xmlOut.addTextElementToData(
"autoRefreshPeriod",
"");
454 __SUP_COUT__ <<
"Done with preferences!" << __E__;
458 "getDirectoryContents")
461 std::string rootpath =
462 std::string(ROOT_BROWSER_PATH) +
464 std::string path = CgiDataUtilities::postData(cgiIn,
"Path");
465 boost::regex re(
"%2F");
466 path = boost::regex_replace(path, re,
"/");
476 userInfo.permissionLevel_ >=
477 CoreSupervisorBase::getSupervisorPropertyUserPermissionsThreshold(
478 "rootAdminControls"));
479 xmlOut.addTextElementToData(
"permissions", permStr);
483 std::string dirpath = rootpath + path;
485 if(path ==
"/" + PRE_MADE_ROOT_CFG_DIR +
"/")
486 dirpath = ROOT_DISPLAY_CONFIG_PATH;
488 if(path.find(
"/" + PRE_MADE_ROOT_CFG_DIR +
"/") ==
490 dirpath = std::string(ROOT_DISPLAY_CONFIG_PATH) +
"/" +
491 path.substr(PRE_MADE_ROOT_CFG_DIR.length() + 2);
494 __SUP_COUT__ <<
"rootpath:-" << rootpath <<
"-path:-" << path <<
"-dirpath:-"
495 << dirpath <<
"-" << __E__;
498 struct dirent* entry;
501 if((pDIR = opendir(dirpath.c_str())))
503 xmlOut.addTextElementToData(
"path", path);
504 xmlOut.addTextElementToData(
"headOfSearch",
"located");
509 if(theDataManager_ !=
nullptr)
510 __COUT__ <<
"path-" << path <<
"-DM: " << theDataManager_
511 <<
" Live: " << theDataManager_->getLiveDQMHistos() << std::endl;
515 if(theDataManager_ !=
nullptr &&
516 theDataManager_->getLiveDQMHistos() ==
true)
517 xmlOut.addTextElementToData(
"dir",
518 LIVEDQM_DIR +
".root");
521 DIR* pRtDIR = opendir(ROOT_DISPLAY_CONFIG_PATH);
522 bool recheck =
false;
526 if(mkdir(ROOT_DISPLAY_CONFIG_PATH,
527 S_IRWXU | (S_IRGRP | S_IXGRP) |
528 (S_IROTH | S_IXOTH)))
529 __SUP_COUT__ <<
"Failed to make directory for pre made views: "
530 << ROOT_DISPLAY_CONFIG_PATH << __E__;
535 if(!recheck || (pRtDIR = opendir(ROOT_DISPLAY_CONFIG_PATH)))
539 xmlOut.addTextElementToData(
"dir",
540 PRE_MADE_ROOT_CFG_DIR);
546 while((entry = readdir(pDIR)))
550 if(entry->d_name[0] !=
'.' &&
553 entry->d_type == 4 ||
559 std::string(entry->d_name).find(
".rcfg") == std::string::npos;
562 if(entry->d_type == 0)
566 DIR* pTmpDIR = opendir((dirpath + entry->d_name).c_str());
576 if((entry->d_type == 8 ||
577 (!isDir && entry->d_type == 0))
578 && std::string(entry->d_name).find(
".root") == std::string::npos &&
581 else if(entry->d_type == 4)
584 xmlOut.addTextElementToData(
585 isDir ?
"dir" : (isNotRtCfg ?
"dir" :
"file"), entry->d_name);
591 __SUP_COUT__ <<
"Failed to access directory contents!" << __E__;
600 std::string path = CgiDataUtilities::postData(cgiIn,
"RootPath");
603 unsigned splitter = path.find(
".root") + 5;
604 std::string rootFileName =
605 std::string(__ENV__(
"ROOT_BROWSER_PATH")) + path.substr(0, splitter);
606 __SUP_COUTV__(rootFileName);
608 std::string rootDirectoryName = path.substr(splitter, path.length() - splitter);
609 __SUP_COUTV__(rootDirectoryName);
614 bool isLiveDQM = (path.find(
"/" + LIVEDQM_DIR +
".root/") == 0) ?
true :
false;
615 __SUP_COUTV__(isLiveDQM);
617 TFile* rootFile =
nullptr;
618 TObject* tObject =
nullptr;
619 TDirectory* tDirectory =
nullptr;
623 rootFile = TFile::Open(rootFileName.c_str());
625 if(rootFile ==
nullptr || !rootFile->IsOpen())
627 __SUP_SS__ <<
"Failed to access ROOT file: " << rootFileName << __E__;
632 if((tObject = rootFile->Get(rootDirectoryName.c_str())) !=
nullptr)
634 if(tObject->IsA() == TCanvas::Class())
636 static_cast<TCanvas*
>(tObject)->Modified();
637 static_cast<TCanvas*
>(tObject)->Update();
639 TString json = TBufferJSON::ConvertToJSON(tObject);
640 TBufferFile tBuffer(TBuffer::kWrite);
641 tObject->Streamer(tBuffer);
642 std::string hexString = BinaryStringMacros::binaryStringToHexString(
643 tBuffer.Buffer(), tBuffer.Length());
645 __SUP_COUT__ <<
"Returning object from file '" << tObject->GetName()
646 <<
"' of class '" << tObject->ClassName() << __E__;
648 xmlOut.addTextElementToData(
"path", path);
649 xmlOut.addTextElementToData(
"rootType", tObject->ClassName());
650 xmlOut.addTextElementToData(
"rootData", hexString);
651 xmlOut.addTextElementToData(
"rootJSON", json.Data());
653 else if((tDirectory = rootFile->GetDirectory(rootDirectoryName.c_str())) !=
657 TIter next(tDirectory->GetListOfKeys());
658 xmlOut.addTextElementToData(
"path", path);
659 while((key = (TKey*)next()))
661 TString s = key->GetName();
662 TRegexp re(
"*", kTRUE);
663 if(s.Index(re) == kNPOS)
665 __SUP_COUT__ <<
"Class Name: " << key->GetClassName() << __E__;
666 xmlOut.addTextElementToData(
667 (std::string(key->GetClassName()).find(
"Directory") !=
669 std::string(key->GetClassName()) ==
"TTree" ||
670 std::string(key->GetClassName()).find(
"TBranch") !=
679 __SUP_COUT_ERR__ <<
"Failed to find object " << rootDirectoryName
680 <<
" in " << rootFileName << __E__;
684 else if(theDataManager_ !=
nullptr && theDataManager_->isReady())
686 if(theDataManager_ !=
nullptr)
687 theDataManager_->setDoNotStop(
true);
690 __SUP_COUT__ <<
"Attempting to get LIVE ROOT object." << __E__;
692 std::vector<DQMHistosBase*> dqmConsumers = theDataManager_->getLiveDQMs();
694 for(
auto const& consumer : dqmConsumers)
696 rootFile = consumer->getFile();
697 __SUP_COUT__ <<
"LIVE file name: " << rootFile->GetName() << __E__;
698 if(rootFile ==
nullptr || !rootFile->IsOpen())
700 __SUP_SS__ <<
"Failed to access LIVE ROOT file: " << rootFileName
702 theDataManager_->setDoNotStop(
false);
706 if((tObject = rootFile->Get(rootDirectoryName.c_str())) !=
nullptr)
708 __SUP_COUT__ <<
"Object class name: " << tObject->ClassName()
710 std::string tmpClassName = tObject->ClassName();
712 TBufferFile tBuffer(TBuffer::kWrite);
713 if(tObject->IsA() == TCanvas::Class())
715 static_cast<TCanvas*
>(tObject)->Modified();
716 static_cast<TCanvas*
>(tObject)->Update();
719 std::unique_lock<std::mutex> lock(
720 static_cast<DQMHistosConsumerBase*
>(consumer)
721 ->getFillHistoMutex());
722 json = TBufferJSON::ConvertToJSON(tObject);
723 tObject->Streamer(tBuffer);
725 std::string hexString = BinaryStringMacros::binaryStringToHexString(
726 tBuffer.Buffer(), tBuffer.Length());
728 __SUP_COUT__ <<
"Returning object '" << tObject->GetName()
729 <<
"' of class '" << tObject->ClassName() << __E__;
732 xmlOut.addTextElementToData(
"path", path);
733 xmlOut.addTextElementToData(
"rootType", tObject->ClassName());
734 xmlOut.addTextElementToData(
"rootData", hexString);
735 xmlOut.addTextElementToData(
"rootJSON", json.Data());
737 theDataManager_->setDoNotStop(
false);
742 std::map<std::string, std::string> dirList;
744 for(
auto const& consumer : dqmConsumers)
746 __SUP_COUT__ <<
"Attempting to get LIVE ROOT directory." << __E__;
747 rootFile = consumer->getFile();
748 __SUP_COUT__ <<
"LIVE file name: " << rootFile->GetName() << __E__;
749 if(rootFile ==
nullptr || !rootFile->IsOpen())
751 __SUP_SS__ <<
"Failed to access LIVE ROOT file: " << rootFileName
753 xmlOut.addTextElementToData(
"Warning", ss.str());
754 theDataManager_->setDoNotStop(
false);
757 if((tDirectory = rootFile->GetDirectory(rootDirectoryName.c_str())) !=
760 xmlOut.addTextElementToData(
"path", path);
761 __SUP_COUT__ <<
"Directory found getting the content!" << __E__;
762 TRegexp re(
"*", kTRUE);
764 TIter nextobj(tDirectory->GetList());
765 while((obj = (TObject*)nextobj()))
767 TString s = obj->GetName();
768 if(s.Index(re) == kNPOS)
770 __SUP_COUT__ <<
"Class Name: " << obj->IsA()->GetName() << __E__;
771 dirList[obj->GetName()] =
772 (std::string(obj->IsA()->GetName()).find(
"Directory") !=
774 std::string(obj->IsA()->GetName()) ==
"TTree" ||
775 std::string(obj->IsA()->GetName()).find(
"TBranch") !=
782 for(
auto const& dir : dirList)
784 xmlOut.addTextElementToData(dir.second, dir.first);
785 __SUP_COUT__ <<
"Class Name: " << dir.second <<
" Object: " << dir.first
1193 if(theDataManager_ ==
nullptr)
1195 __SS__ <<
"No Data Manager instantiated." << __E__;
1199 int Run = atoi(cgiIn(
"run").c_str());
1201 __SUP_COUT__ <<
"getEvents for run " << Run << __E__;
1203 if(Run != (
int)loadedRunNumber_ || loadedRunNumber_ == (
unsigned int)-1)
1205 theDataManager_->load(
"Run1684.root",
"Monicelli");
1206 loadedRunNumber_ = Run;
1209 xmlOut.addTextElementToData(
"events",
"");
1252 __SUP_COUT__ <<
"Done hits xml" << __E__;
1258 __SUP_COUT__ <<
"getGeometry" << __E__;
1260 if(theDataManager_ ==
nullptr)
1262 __SS__ <<
"No Data Manager instantiated." << __E__;
1267 theDataManager_->load(
"Run1684.geo",
"Geometry");
1269 __SUP_COUT__ <<
"getGeometry" << __E__;
1271 xmlOut.addTextElementToData(
"geometry",
"");
1306 std::string path = CgiDataUtilities::postData(cgiIn,
"RootConfigPath");
1307 __SUP_COUT__ <<
"path " << path << __E__;
1309 if(path.find(
"/" + PRE_MADE_ROOT_CFG_DIR +
"/") ==
1312 path = std::string(ROOT_DISPLAY_CONFIG_PATH) +
"/" +
1313 path.substr(PRE_MADE_ROOT_CFG_DIR.length() + 2);
1314 __SUP_COUT__ <<
"mod path " << path << __E__;
1317 HttpXmlDocument cfgXml;
1318 if(cfgXml.loadXmlDocument(path))
1320 xmlOut.addTextElementToData(
"status",
"1");
1321 xmlOut.copyDataChildren(cfgXml);
1322 cfgXml.saveXmlDocument(path);
1325 xmlOut.addTextElementToData(
"status",
1326 "Failed. File to properly load config file.");
1330 "rootAdminControls")
1342 std::string cmd = cgiIn(
"cmd");
1347 std::string path = CgiDataUtilities::postData(cgiIn,
"path");
1348 std::string name = CgiDataUtilities::postData(cgiIn,
"name");
1349 __SUP_COUT__ <<
"cmd " << cmd << __E__;
1350 __SUP_COUT__ <<
"path " << path << __E__;
1351 __SUP_COUT__ <<
"name " << name << __E__;
1353 if(path.find(
"/" + PRE_MADE_ROOT_CFG_DIR +
"/") ==
1356 path = std::string(ROOT_DISPLAY_CONFIG_PATH) +
"/" +
1357 path.substr(PRE_MADE_ROOT_CFG_DIR.length() + 2) + name;
1358 __SUP_COUT__ <<
"mod path " << path << __E__;
1362 if(mkdir(path.c_str(),
1363 S_IRWXU | (S_IRGRP | S_IXGRP) |
1364 (S_IROTH | S_IXOTH)))
1365 xmlOut.addTextElementToData(
"status",
1366 "Failed. Directory create rejected.");
1368 xmlOut.addTextElementToData(
"status",
"1");
1370 else if(cmd ==
"save")
1372 path += PRE_MADE_ROOT_CFG_FILE_EXT;
1374 bool useRunWildCard =
1375 atoi(CgiDataUtilities::postData(cgiIn,
"useRunWildCard")
1377 std::string config = CgiDataUtilities::postData(cgiIn,
"config");
1378 __SUP_COUT__ <<
"config " << config << __E__;
1379 __SUP_COUT__ <<
"useRunWildCard " << useRunWildCard << __E__;
1382 FILE* fp = fopen(path.c_str(),
"r");
1386 xmlOut.addTextElementToData(
"status",
"Failed. File already exists.");
1387 __SUP_COUT__ <<
" Failed. File already exists." << __E__;
1396 fp = fopen(path.c_str(),
"w");
1397 fputs(config.c_str(), fp);
1401 HttpXmlDocument cfgXml;
1402 if(cfgXml.loadXmlDocument(path))
1405 cfgXml.saveXmlDocument(path);
1406 xmlOut.addTextElementToData(
"status",
"1");
1410 xmlOut.addTextElementToData(
1411 "status",
"Failed. Fatal. Improper file format.");
1412 if(remove(path.c_str()) != 0)
1413 __SUP_COUT__ <<
"Failed. Could not remove poorly formed Root "
1419 else if(cmd ==
"delete")
1422 if(rmdir(path.c_str()) == 0 ||
1423 remove((path + PRE_MADE_ROOT_CFG_FILE_EXT).c_str()) == 0)
1424 xmlOut.addTextElementToData(
"status",
"1");
1426 xmlOut.addTextElementToData(
"status",
1427 "Failed. Target could not be deleted.");
1430 xmlOut.addTextElementToData(
"status",
"Failed. Unrecognized command.");
1433 xmlOut.addTextElementToData(
"status",
"Failed. Invalid path.");
1441 xmlOut.setDarioStyle(
true);
1442 std::string fSystemPath = std::string(ROOT_BROWSER_PATH) +
"/";
1443 std::string fRootPath = CgiDataUtilities::postData(cgiIn,
"Path");
1444 boost::regex re(
"%2F");
1445 fRootPath = boost::regex_replace(fRootPath, re,
"/");
1446 std::string fullPath = fSystemPath + fRootPath;
1448 STDLINE(std::string(
"Begin: fSystemPath = ") + fSystemPath, ACWhite);
1449 STDLINE(std::string(
"Begin: fRootPath = ") + fRootPath, ACWhite);
1450 STDLINE(std::string(
"Begin: fullPath = ") + fullPath, ACWhite);
1453 xmlOut.setRootPath(fRootPath);
1454 xmlOut.makeDirectoryBinaryTree(fSystemPath, fRootPath, 0, NULL);
1455 std::ostringstream* out =
new std::ostringstream();
1456 xmlOut.outputXmlDocument((std::ostringstream*)out,
true);
1462 xmlOut.setDarioStyle(
true);
1463 std::string fSystemPath = std::string(ROOT_BROWSER_PATH) +
"/";
1464 std::string fRootPath = CgiDataUtilities::postData(cgiIn,
"fRootPath");
1465 std::string fFoldersPath = CgiDataUtilities::postData(cgiIn,
"fFoldersPath");
1466 std::string fHistName = CgiDataUtilities::postData(cgiIn,
"fHistName");
1467 std::string fRFoldersPath = CgiDataUtilities::postData(cgiIn,
"fRFoldersPath");
1468 std::string fFileName = CgiDataUtilities::postData(cgiIn,
"fFileName");
1469 boost::regex re(
"%2F");
1470 fRootPath = boost::regex_replace(fRootPath, re,
"/");
1471 fFoldersPath = boost::regex_replace(fFoldersPath, re,
"/");
1478 RootFileExplorer* theExplorer =
new RootFileExplorer(
1479 fSystemPath, fRootPath, fFoldersPath, fHistName, fRFoldersPath, fFileName);
1480 xmlOut.setDocument(theExplorer->initialize(
false));
1546 "saveConfiguration")
1548 std::string configPayload = CgiDataUtilities::postData(cgiIn,
"configPayload");
1549 STDLINE(
"configPayload: ", ACRed);
1550 STDLINE(configPayload, ACYellow);
1553 outFile.open(
"/tmp/configPayload.json", ios::out | ios::app);
1554 outFile << configPayload << endl;
1561 std::string configPayload = CgiDataUtilities::postData(cgiIn,
"configPayload");
1562 std::string JSONPayLoad =
"";
1563 std::string line =
"";
1565 ifstream JSONFile(
"/tmp/configPayload.json");
1567 if(JSONFile.is_open())
1569 while(getline(JSONFile, line))
1571 JSONPayLoad += line;
1576 xmlOut.addTextElementToData(
"JSONPayLoad", JSONPayLoad);
1580 if(theDataManager_ !=
nullptr)
1581 theDataManager_->setDoNotStop(
false);
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