$treeview $search $mathjax $extrastylesheet
otsdaq_utilities
v2_03_00
$projectbrief
|
$projectbrief
|
$searchbox |
00001 #include "otsdaq-utilities/Visualization/VisualSupervisor.h" 00002 //#include "otsdaq-core/RootUtilities/DQMHistos.h" 00003 #include "otsdaq-core/DataManager/DataManagerSingleton.h" 00004 #include "otsdaq-core/Macros/BinaryStringMacros.h" 00005 00006 // ROOT documentation 00007 // http://root.cern.ch/root/html/index.html 00008 00009 #include <TBuffer.h> 00010 #include <TBufferJSON.h> 00011 #include <TCanvas.h> 00012 #include <TClass.h> 00013 #include <TDirectory.h> 00014 #include <TFile.h> 00015 #include <TH1.h> 00016 #include <TH2.h> 00017 #include <TIterator.h> 00018 #include <TKey.h> 00019 #include <TProfile.h> 00020 #include <TROOT.h> 00021 #include <TRegexp.h> 00022 #include <TString.h> 00023 #include "TBufferFile.h" 00024 #include "TObject.h" 00025 00026 #include <dirent.h> /*DIR and dirent*/ 00027 #include <sys/stat.h> /*mkdir*/ 00028 00029 #include <xdaq/NamespaceURI.h> 00030 00031 #include <iostream> 00032 00033 #define ROOT_BROWSER_PATH getenv("ROOT_BROWSER_PATH") 00034 #define ROOT_DISPLAY_CONFIG_PATH getenv("ROOT_DISPLAY_CONFIG_PATH") 00035 00036 #define LIVEDQM_DIR std::string("LIVE_DQM") 00037 #define PRE_MADE_ROOT_CFG_DIR std::string("Pre-made Views") 00038 00039 #define PRE_MADE_ROOT_CFG_FILE_EXT std::string(".rcfg") 00040 00041 #define PREFERENCES_PATH std::string(getenv("SERVICE_DATA_PATH")) + "/VisualizerData/" 00042 #define PREFERENCES_FILE_EXT ".pref" 00043 00044 #define ROOT_VIEWER_PERMISSIONS_THRESHOLD 100 00045 00046 using namespace ots; 00047 00048 #undef __MF_SUBJECT__ 00049 #define __MF_SUBJECT__ "Visualizer" 00050 00051 XDAQ_INSTANTIATOR_IMPL(VisualSupervisor) 00052 00053 //======================================================================================================================== 00054 VisualSupervisor::VisualSupervisor(xdaq::ApplicationStub* stub) 00055 : CoreSupervisorBase(stub), theDataManager_(0), loadedRunNumber_(-1) 00056 { 00057 __SUP_COUT__ << "Constructor." << __E__; 00058 INIT_MF("VisualSupervisor"); 00059 00060 theDataManager_ = DataManagerSingleton::getInstance<VisualDataManager>( 00061 theConfigurationManager_->getNode( 00062 theConfigurationManager_->__GET_CONFIG__(XDAQContextTable)->getTableName()), 00063 CorePropertySupervisorBase::getSupervisorConfigurationPath(), 00064 CorePropertySupervisorBase::getSupervisorUID()); 00065 00066 CoreSupervisorBase::theStateMachineImplementation_.push_back(theDataManager_); 00067 00068 __SUP_COUT__ << "Done instantiating Visual data manager." << __E__; 00069 00070 // xgi::bind(this, &VisualSupervisor::safariDefaultPage, "safari" ); 00071 00072 // make preferences directory in case they don't exist 00073 mkdir(((std::string)PREFERENCES_PATH).c_str(), 0755); 00074 00075 __SUP_COUT__ << "Constructed." << __E__; 00076 } //end constructor 00077 00078 //======================================================================================================================== 00079 VisualSupervisor::~VisualSupervisor(void) 00080 { 00081 __SUP_COUT__ << "Destructor." << __E__; 00082 destroy(); 00083 __SUP_COUT__ << "Destructed." << __E__; 00084 } // end destructor() 00085 00086 //======================================================================================================================== 00087 void VisualSupervisor::destroy(void) 00088 { 00089 __SUP_COUT__ << "Destroying..." << __E__; 00090 00091 // called by destructor 00092 // delete theConfigurationManager_; 00093 00094 DataManagerSingleton::deleteInstance( 00095 CorePropertySupervisorBase::getSupervisorUID()); 00096 theStateMachineImplementation_.pop_back(); 00097 } //end destroy() 00098 // 00100 // void VisualSupervisor::defaultPage(xgi::Input * in, xgi::Output * out ) 00101 //{ 00102 // //__SUP_COUT__ << this->getApplicationContext()->getURL() << __E__; 00103 // 00104 // *out << "<!DOCTYPE HTML><html lang='en'><frameset col='100%' row='100%'><frame 00105 // src='/WebPath/html/Visualization.html?urn=" << 00106 // this->getApplicationDescriptor()->getLocalId() <<"'></frameset></html>"; 00107 // 00108 //} 00109 // 00111 // void VisualSupervisor::safariDefaultPage(xgi::Input * in, xgi::Output * out ) 00112 //{ 00113 // *out << "<!DOCTYPE HTML><html lang='en'><iframe 00114 // style='width:100%;height:100%;position:absolute;left:0;top:0;border:0;padding:0;margin:0;' 00115 // src='/WebPath/html/Visualization.html?urn=" << 00116 // this->getApplicationDescriptor()->getLocalId() <<"'></iframe></html>"; 00117 //} 00118 00119 //======================================================================================================================== 00120 // setSupervisorPropertyDefaults 00121 // override to set defaults for supervisor property values (before user settings 00122 // override) 00123 void VisualSupervisor::setSupervisorPropertyDefaults() 00124 { 00125 CorePropertySupervisorBase::setSupervisorProperty( 00126 CorePropertySupervisorBase::SUPERVISOR_PROPERTIES.AllowNoLoginRequestTypes, 00127 "setUserPreferences | getUserPreferences | getDirectoryContents | getRoot | " 00128 "getEvents"); 00129 00130 CorePropertySupervisorBase::setSupervisorProperty( 00131 CorePropertySupervisorBase::SUPERVISOR_PROPERTIES.UserPermissionsThreshold, 00132 "*=1 | rootAdminControls=100"); 00133 } 00134 00135 //======================================================================================================================== 00136 // forceSupervisorPropertyValues 00137 // override to force supervisor property values (and ignore user settings) 00138 void VisualSupervisor::forceSupervisorPropertyValues() 00139 { 00140 CorePropertySupervisorBase::setSupervisorProperty( 00141 CorePropertySupervisorBase::SUPERVISOR_PROPERTIES.AutomatedRequestTypes, 00142 "getRoot | getEvents"); 00143 CorePropertySupervisorBase::setSupervisorProperty( 00144 CorePropertySupervisorBase::SUPERVISOR_PROPERTIES.NoXmlWhiteSpaceRequestTypes, 00145 "getRoot | getEvents"); // json data in ROOTJS library expects no funny 00146 // characters 00147 // CorePropertySupervisorBase::setSupervisorProperty(CorePropertySupervisorBase::SUPERVISOR_PROPERTIES.NeedUsernameRequestTypes, 00148 // "setUserPreferences | getUserPreferences"); 00149 } 00150 00151 //======================================================================================================================== 00152 void VisualSupervisor::request(const std::string& requestType, 00153 cgicc::Cgicc& cgiIn, 00154 HttpXmlDocument& xmlOut, 00155 const WebUsers::RequestUserInfo& userInfo) 00156 { 00157 // Commands 00158 // getRawData 00159 // getGeometry 00160 // getEvents 00161 // getRoot 00162 // getDirectoryContents 00163 // setUserPreferences 00164 // getUserPreference 00165 00166 // if (requestType == "getHisto" && theDataManager_->getLiveDQMHistos() != 0) 00167 // { 00168 // // TH1I* histo = 00169 // (TH1I*)theDataManager_->getLiveDQMHistos()->get("Planes/Plane_0_Occupancy"); 00170 // 00171 // // theDataManager_->load("Run185_Histo.root","Histograms"); 00172 // //TH1F* histo1d = theDataManager_->getFileDQMHistos().getHisto1D(); 00173 // //TCanvas* canvas = theDataManager_->getFileDQMHistos().getCanvas (); 00174 // //TH2F* histo2d = theDataManager_->getFileDQMHistos().getHisto2D(); 00175 // //TProfile* profile = theDataManager_->getFileDQMHistos().getProfile(); 00176 // 00177 // } 00178 if(requestType == "getRawData") 00179 { 00180 __SUP_COUT__ << __E__; 00181 try 00182 { 00183 // TODO -- add timestamp, so we know if data is new 00184 __SUP_COUT__ << "Getting Raw data and converting to binary string" << __E__; 00185 xmlOut.addBinaryStringToData("rawData", theDataManager_->getRawData()); 00186 __SUP_COUT__ << __E__; 00187 } 00188 catch(std::exception const& e) 00189 { 00190 __SUP_COUT__ 00191 << "ERROR! Exception while getting raw data. Incoming exception data..." 00192 << __E__; 00193 __SUP_COUT__ << e.what() << __E__; 00194 __SUP_COUT__ << "End Exception Data" << __E__; 00195 } 00196 catch(...) 00197 { 00198 __SUP_COUT__ << "ERROR! Something went wrong trying to get raw data." 00199 << __E__; 00200 __SUP_COUT_INFO__ << "ERROR! Something went wrong trying to get raw data." 00201 << __E__; 00202 } 00203 } 00204 else if(requestType == "setUserPreferences" && 00205 userInfo.username_ != "" /*from allow no user*/) 00206 { 00207 __SUP_COUT__ << "userInfo.username_: " << userInfo.username_ << __E__; 00208 std::string fullPath = 00209 (std::string)PREFERENCES_PATH + userInfo.username_ + PREFERENCES_FILE_EXT; 00210 __SUP_COUT__ << "fullPath: " << fullPath << __E__; 00211 00212 std::string radioSelect = CgiDataUtilities::getData(cgiIn, "radioSelect"); 00213 std::string autoRefresh = CgiDataUtilities::getData(cgiIn, "autoRefresh"); 00214 std::string autoHide = CgiDataUtilities::getData(cgiIn, "autoHide"); 00215 std::string hardRefresh = CgiDataUtilities::getData(cgiIn, "hardRefresh"); 00216 std::string autoRefreshPeriod = 00217 CgiDataUtilities::getData(cgiIn, "autoRefreshPeriod"); 00218 00219 __SUP_COUT__ << "radioSelect: " << radioSelect << __E__; 00220 __SUP_COUT__ << "autoRefresh: " << autoRefresh << __E__; 00221 __SUP_COUT__ << "autoHide: " << autoHide << __E__; 00222 __SUP_COUT__ << "hardRefresh: " << hardRefresh << __E__; 00223 __SUP_COUT__ << "autoRefreshPeriod: " << autoRefreshPeriod << __E__; 00224 00225 // read existing 00226 FILE* fp = fopen(fullPath.c_str(), "r"); 00227 if(fp) 00228 { 00229 char line[100]; 00230 char val[100]; 00231 00232 fgets(line, 100, fp); 00233 sscanf(line, "%*s %s", val); 00234 if(radioSelect == "") 00235 radioSelect = val; 00236 00237 fgets(line, 100, fp); 00238 sscanf(line, "%*s %s", val); 00239 if(autoRefresh == "") 00240 autoRefresh = val; 00241 00242 fgets(line, 100, fp); 00243 sscanf(line, "%*s %s", val); 00244 if(autoHide == "") 00245 autoHide = val; 00246 00247 fgets(line, 100, fp); 00248 sscanf(line, "%*s %s", val); 00249 if(hardRefresh == "") 00250 hardRefresh = val; 00251 00252 fgets(line, 100, fp); 00253 sscanf(line, "%*s %s", val); 00254 if(autoRefreshPeriod == "") 00255 autoRefreshPeriod = val; 00256 00257 fclose(fp); 00258 } 00259 00260 // write new 00261 fp = fopen(fullPath.c_str(), "w"); 00262 if(fp) 00263 { 00264 fprintf(fp, "radioSelect %s\n", radioSelect.c_str()); 00265 fprintf(fp, "autoRefresh %s\n", autoRefresh.c_str()); 00266 fprintf(fp, "autoHide %s\n", autoHide.c_str()); 00267 fprintf(fp, "hardRefresh %s\n", hardRefresh.c_str()); 00268 fprintf(fp, "autoRefreshPeriod %s\n", autoRefreshPeriod.c_str()); 00269 fclose(fp); 00270 } 00271 else 00272 __SUP_COUT_ERR__ << "Failure writing preferences to file: " << fullPath 00273 << __E__; 00274 } 00275 else if(requestType == "getUserPreferences") 00276 { 00277 __SUP_COUT__ << "userInfo.username_: " << userInfo.username_ << __E__; 00278 std::string fullPath = 00279 (std::string)PREFERENCES_PATH + userInfo.username_ + PREFERENCES_FILE_EXT; 00280 __SUP_COUT__ << "fullPath: " << fullPath << __E__; 00281 00282 FILE* fp = fopen(fullPath.c_str(), "r"); 00283 if(fp) 00284 { 00285 char line[100]; 00286 // char val[100]; 00287 int val; 00288 00289 fgets(line, 100, fp); 00290 sscanf(line, "%*s %d", &val); 00291 if(val < 0 || val > 3) 00292 val = 0; // FIXME.. value can get corrupt... 00293 xmlOut.addTextElementToData("radioSelect", std::to_string(val)); 00294 fgets(line, 100, fp); 00295 sscanf(line, "%*s %d", &val); 00296 xmlOut.addTextElementToData("autoRefresh", std::to_string(val)); 00297 fgets(line, 100, fp); 00298 sscanf(line, "%*s %d", &val); 00299 xmlOut.addTextElementToData("autoHide", std::to_string(val)); 00300 fgets(line, 100, fp); 00301 sscanf(line, "%*s %d", &val); 00302 xmlOut.addTextElementToData("hardRefresh", std::to_string(val)); 00303 fgets(line, 100, fp); 00304 sscanf(line, "%*s %d", &val); 00305 xmlOut.addTextElementToData("autoRefreshPeriod", std::to_string(val)); 00306 fclose(fp); 00307 } 00308 else 00309 { 00310 // else assume user has no preferences yet 00311 xmlOut.addTextElementToData("radioSelect", ""); 00312 xmlOut.addTextElementToData("autoRefresh", ""); 00313 xmlOut.addTextElementToData("autoHide", ""); 00314 xmlOut.addTextElementToData("hardRefresh", ""); 00315 xmlOut.addTextElementToData("autoRefreshPeriod", ""); 00316 } 00317 } 00318 else if(requestType == "getDirectoryContents") 00319 { 00320 // return directory structure for requested path, types are "dir" and "file" 00321 00322 std::string rootpath = std::string(ROOT_BROWSER_PATH) + "/"; 00323 std::string path = CgiDataUtilities::postData(cgiIn, "Path"); 00324 __SUP_COUT__ << path << __E__; 00325 00326 // return 1 if user has access to admin controls, else 0 00327 char permStr[10]; 00328 sprintf(permStr, 00329 "%d", 00330 userInfo.permissionLevel_ >= 00331 CoreSupervisorBase::getSupervisorPropertyUserPermissionsThreshold( 00332 "rootAdminControls")); 00333 xmlOut.addTextElementToData("permissions", permStr); // add permissions 00334 00335 std::string dirpath = rootpath + path; 00336 if(path == "/" + PRE_MADE_ROOT_CFG_DIR + "/") 00337 dirpath = ROOT_DISPLAY_CONFIG_PATH; 00338 00339 if(path.find("/" + PRE_MADE_ROOT_CFG_DIR + "/") == 00340 0) // ROOT config path must start the path 00341 dirpath = std::string(ROOT_DISPLAY_CONFIG_PATH) + "/" + 00342 path.substr(PRE_MADE_ROOT_CFG_DIR.length() + 2); 00343 00344 __SUP_COUT__ << "full path: " << dirpath << __E__; 00345 00346 DIR* pDIR; 00347 struct dirent* entry; 00348 bool isNotRtCfg; 00349 bool isDir; 00350 if((pDIR = opendir(dirpath.c_str()))) 00351 { 00352 xmlOut.addTextElementToData("path", path); 00353 00354 // add LIVE if path is / and DQM is active 00355 // add Pre-made Views if path is / and ROOT_DISPLAY_CONFIG_PATH isnt already 00356 // there 00357 if(path == "/") 00358 { 00359 if(theDataManager_->getLiveDQMHistos() != 0) 00360 xmlOut.addTextElementToData("dir", 00361 LIVEDQM_DIR + ".root"); // add to xml 00362 00363 // check for ROOT_DISPLAY_CONFIG_PATH 00364 DIR* pRtDIR = opendir(ROOT_DISPLAY_CONFIG_PATH); 00365 bool recheck = false; 00366 if(!pRtDIR) // if doesn't exist, make it 00367 { 00368 recheck = true; 00369 if(mkdir(ROOT_DISPLAY_CONFIG_PATH, 00370 S_IRWXU | (S_IRGRP | S_IXGRP) | 00371 (S_IROTH | S_IXOTH))) // mode = drwx r-x r-x 00372 __SUP_COUT__ << "Failed to make directory for pre made views: " 00373 << ROOT_DISPLAY_CONFIG_PATH << __E__; 00374 } 00375 else 00376 closedir(pRtDIR); // else close and display 00377 00378 if(!recheck || (pRtDIR = opendir(ROOT_DISPLAY_CONFIG_PATH))) 00379 { 00380 xmlOut.addTextElementToData("dir", 00381 PRE_MADE_ROOT_CFG_DIR); // add to xml 00382 if(recheck) 00383 closedir(pRtDIR); 00384 } 00385 } 00386 00387 while((entry = readdir(pDIR))) 00388 { 00389 //__SUP_COUT__ << int(entry->d_type) << " " << entry->d_name << "\n" << 00390 // __E__; 00391 if(entry->d_name[0] != '.' && 00392 (entry->d_type == 00393 0 || // 0 == UNKNOWN (which can happen - seen in SL7 VM) 00394 entry->d_type == 4 || 00395 entry->d_type == 8)) 00396 { 00397 //__SUP_COUT__ << int(entry->d_type) << " " << entry->d_name << "\n" 00398 //<< __E__; 00399 isNotRtCfg = 00400 std::string(entry->d_name).find(".rcfg") == std::string::npos; 00401 isDir = false; 00402 00403 if(entry->d_type == 0) 00404 { 00405 // unknown type .. determine if directory 00406 DIR* pTmpDIR = opendir((dirpath + entry->d_name).c_str()); 00407 if(pTmpDIR) 00408 { 00409 isDir = true; 00410 closedir(pTmpDIR); 00411 } 00412 // else //assume file 00413 } 00414 00415 if((entry->d_type == 8 || 00416 (!isDir && entry->d_type == 0)) // file type 00417 && std::string(entry->d_name).find(".root") == std::string::npos && 00418 isNotRtCfg) 00419 continue; // skip if not a root file or a config file 00420 else if(entry->d_type == 4) 00421 isDir = true; // flag directory types 00422 00423 xmlOut.addTextElementToData( 00424 isDir ? "dir" : (isNotRtCfg ? "dir" : "file"), entry->d_name); 00425 } 00426 } 00427 closedir(pDIR); 00428 } 00429 else 00430 __SUP_COUT__ << "Failed to access directory contents!" << __E__; 00431 } 00432 else if(requestType == "getRoot") 00433 { 00434 // return directory structure for requested ROOT path, types are "dir" and "file" 00435 00436 std::string path = CgiDataUtilities::postData(cgiIn, "RootPath"); 00437 std::string fullPath = std::string(getenv("ROOT_BROWSER_PATH")) + path; 00438 00439 //__SUP_COUT__ << "Full path:-" << fullPath << "-" << __E__; 00440 00441 std::string rootFileName = fullPath.substr(0, fullPath.find(".root") + 5); 00442 std::string rootDirectoryName = 00443 rootFileName + ":" + 00444 fullPath.substr(fullPath.find(".root") + 5, 00445 fullPath.size() - fullPath.find(".root") + 5 + 1); 00446 00447 std::string::size_type LDQM_pos = path.find("/" + LIVEDQM_DIR + ".root/"); 00448 TFile* rootFile; 00449 00450 if(theDataManager_->getLiveDQMHistos() != nullptr && LDQM_pos == 0) 00451 { 00452 //__SUP_COUT__ << "Attempting to get LIVE file." << __E__; 00453 rootFile = theDataManager_->getLiveDQMHistos()->getFile(); 00454 if(!rootFile) 00455 __SUP_COUT__ << "File was closed." << __E__; 00456 else 00457 { 00458 //__SUP_COUT__ << "LIVE file name: " << rootFile->GetName() << __E__; 00459 rootDirectoryName = path.substr(("/" + LIVEDQM_DIR + ".root").length()); 00460 } 00461 } 00462 else 00463 rootFile = TFile::Open(rootFileName.c_str()); 00464 00465 //__SUP_COUT__ << "FileName : " << rootFileName << " Object: " << 00466 // rootDirectoryName << __E__; 00467 00468 if(!rootFile || !rootFile->IsOpen()) 00469 { 00470 __SUP_COUT__ << "Failed to access root file: " << rootFileName << __E__; 00471 } 00472 else 00473 { 00474 xmlOut.addTextElementToData("path", path); 00475 00476 TDirectory* directory; 00477 if((directory = rootFile->GetDirectory(rootDirectoryName.c_str())) == 0) 00478 { 00479 //__SUP_COUT__ << "This is not a directory!" << __E__; 00480 directory = rootFile; 00481 00482 // failed directory so assume it's file 00483 //__SUP_COUT__ << "Getting object name: " << rootDirectoryName << 00484 // __E__; 00485 TObject* histoClone = nullptr; 00486 TObject* histo = (TObject*)rootFile->Get(rootDirectoryName.c_str()); 00487 00488 if(histo != nullptr) // turns out was a root object path 00489 { 00490 // Clone histo to avoid conflict when it is filled by other threads 00491 histoClone = histo->Clone(); 00492 TString json = TBufferJSON::ConvertToJSON(histoClone); 00493 TBufferFile tBuffer(TBuffer::kWrite); 00494 histoClone->Streamer(tBuffer); 00495 00496 //__SUP_COUT__ << "histo length " << tbuff.Length() << __E__; 00497 00498 std::string destination = BinaryStringMacros::binaryToHexString( 00499 tBuffer.Buffer(), tBuffer.Length()); 00500 00501 xmlOut.addTextElementToData("rootType", histoClone->ClassName()); 00502 xmlOut.addTextElementToData("rootData", destination); 00503 xmlOut.addTextElementToData("rootJSON", json.Data()); 00504 delete histoClone; 00505 } 00506 else 00507 __SUP_COUT_ERR__ << "Failed to access:-" << rootDirectoryName << "-" 00508 << __E__; 00509 } 00510 else 00511 { 00512 __SUP_COUT__ << "directory found getting the content!" << __E__; 00513 TRegexp re("*", kTRUE); 00514 if(LDQM_pos == 0) 00515 { 00516 TObject* obj; 00517 TIter nextobj(directory->GetList()); 00518 while((obj = (TObject*)nextobj())) 00519 { 00520 TString s = obj->GetName(); 00521 if(s.Index(re) == kNPOS) 00522 continue; 00523 __SUP_COUT__ << "Class Name: " << obj->IsA()->GetName() 00524 << __E__; 00525 xmlOut.addTextElementToData( 00526 (std::string(obj->IsA()->GetName()).find("Directory") != 00527 std::string::npos) 00528 ? "dir" 00529 : "file", 00530 obj->GetName()); 00531 } 00532 } 00533 else 00534 { 00535 TKey* key; 00536 TIter next(directory->GetListOfKeys()); 00537 while((key = (TKey*)next())) 00538 { 00539 TString s = key->GetName(); 00540 if(s.Index(re) == kNPOS) 00541 continue; 00542 __SUP_COUT__ << "Class Name: " << key->GetClassName() 00543 << __E__; 00544 xmlOut.addTextElementToData( 00545 (std::string(key->GetClassName()).find("Directory") != 00546 std::string::npos) 00547 ? "dir" 00548 : "file", 00549 key->GetName()); 00550 } 00551 } 00552 } 00553 if(LDQM_pos == std::string::npos) 00554 rootFile->Close(); 00555 } 00556 } 00557 else if(requestType == "getEvents") 00558 { 00559 int Run = atoi(cgiIn("run").c_str()); 00560 00561 __SUP_COUT__ << "getEvents for run " << Run << __E__; 00562 00563 if(Run != (int)loadedRunNumber_ || loadedRunNumber_ == (unsigned int)-1) 00564 { 00565 theDataManager_->load("Run1684.root", "Monicelli"); 00566 loadedRunNumber_ = Run; 00567 } 00568 00569 DOMElement* eventsParent = xmlOut.addTextElementToData("events", ""); 00570 DOMElement* eventParent; 00571 char str[40]; 00572 00573 // const Visual3DEvents& events = theDataManager_->getVisual3DEvents(); 00574 // __SUP_COUT__ << "Preparing hits xml" << __E__; 00575 // int numberOfEvents = 0; 00576 // for(Visual3DEvents::const_iterator it=events.begin(); it!=events.end() && 00577 // numberOfEvents < 10000; it++, numberOfEvents++) 00578 // { 00579 // //__SUP_COUT__ << "Event: " << numberOfEvents << __E__; 00580 // eventParent = xmlOut.addTextElementToParent("event", str, 00581 // eventsParent); const VisualHits& hits = it->getHits(); 00582 // for(VisualHits::const_iterator itHits=hits.begin(); 00583 // itHits!=hits.end(); itHits++) 00584 // { 00585 // sprintf(str,"%f",itHits->x); 00586 // xmlOut.addTextElementToParent("xyz_point", str, eventParent); 00587 // sprintf(str,"%f",itHits->y); 00588 // xmlOut.addTextElementToParent("xyz_point", str, eventParent); 00589 // sprintf(str,"%f",itHits->z); 00590 // xmlOut.addTextElementToParent("xyz_point", str, eventParent); 00591 // //__SUP_COUT__ << "X: " << itHits->x << " Y: " << itHits->y << " 00592 // Z: 00593 //" 00594 //<< itHits->z << __E__; 00595 // } 00596 // const VisualTracks& tracks = it->getTracks(); 00597 // for(VisualTracks::const_iterator itTrks=tracks.begin(); 00598 // itTrks!=tracks.end(); itTrks++) 00599 // { 00600 // sprintf(str,"%f",itTrks->slopeX); 00601 // xmlOut.addTextElementToParent("slope", str, eventParent); 00602 // sprintf(str,"%f",itTrks->slopeY); 00603 // xmlOut.addTextElementToParent("slope", str, eventParent); 00604 // sprintf(str,"%f",itTrks->interceptX); 00605 // xmlOut.addTextElementToParent("intcpt", str, eventParent); 00606 // sprintf(str,"%f",itTrks->interceptY); 00607 // xmlOut.addTextElementToParent("intcpt", str, eventParent); 00608 // 00609 // } 00610 // 00611 // } 00612 __SUP_COUT__ << "Done hits xml" << __E__; 00613 } 00614 else if(requestType == "getGeometry") 00615 { 00616 __SUP_COUT__ << "getGeometry" << __E__; 00617 00618 // FIXME -- this crashes when the file doesn't exist! 00619 theDataManager_->load("Run1684.geo", "Geometry"); 00620 00621 __SUP_COUT__ << "getGeometry" << __E__; 00622 00623 DOMElement* geometryParent = xmlOut.addTextElementToData("geometry", ""); 00624 // const Visual3DShapes& shapes = 00625 // theDataManager_->getVisual3DGeometry().getShapes(); 00626 // 00627 // __SUP_COUT__ << "getGeometry" << __E__; 00628 // 00629 // 00630 // DOMElement* objectParent; 00631 // char str[40]; 00632 // for(Visual3DShapes::const_iterator itShapes=shapes.begin(); 00633 // itShapes!=shapes.end(); itShapes++) 00634 // { 00635 // objectParent = xmlOut.addTextElementToParent("object", str, 00636 // geometryParent); 00637 // xmlOut.addTextElementToParent("object_type", "LINE_LOOP", 00638 // objectParent); sprintf(str,"%d",itShapes->numberOfRows); 00639 // xmlOut.addTextElementToParent("object_rows", str, objectParent); 00640 // sprintf(str,"%d",itShapes->numberOfColumns); 00641 // xmlOut.addTextElementToParent("object_columns", str, objectParent); 00642 // for(Points::const_iterator itCorners=itShapes->corners.begin(); 00643 // itCorners!=itShapes->corners.end(); itCorners++) 00644 // { 00645 // sprintf(str,"%f",itCorners->x); 00646 // xmlOut.addTextElementToParent("xyz_point", str, objectParent); 00647 // sprintf(str,"%f",itCorners->y); 00648 // xmlOut.addTextElementToParent("xyz_point", str, objectParent); 00649 // sprintf(str,"%f",itCorners->z); 00650 // xmlOut.addTextElementToParent("xyz_point", str, objectParent); 00651 // } 00652 // } 00653 } 00654 else if(requestType == "getRootConfig") 00655 { 00656 std::string path = CgiDataUtilities::postData(cgiIn, "RootConfigPath"); 00657 __SUP_COUT__ << "path " << path << __E__; 00658 00659 if(path.find("/" + PRE_MADE_ROOT_CFG_DIR + "/") == 00660 0) // ROOT config path must start the path 00661 { 00662 path = std::string(ROOT_DISPLAY_CONFIG_PATH) + "/" + 00663 path.substr(PRE_MADE_ROOT_CFG_DIR.length() + 2); 00664 __SUP_COUT__ << "mod path " << path << __E__; 00665 } 00666 00667 HttpXmlDocument cfgXml; 00668 if(cfgXml.loadXmlDocument(path)) 00669 { 00670 xmlOut.addTextElementToData("status", "1"); 00671 xmlOut.copyDataChildren(cfgXml); // copy file to output xml 00672 cfgXml.saveXmlDocument(path); 00673 } 00674 else 00675 xmlOut.addTextElementToData("status", 00676 "Failed. File to properly load config file."); 00677 } 00678 else if(requestType == "rootAdminControls") 00679 { 00680 // if(userPermissions < ROOT_VIEWER_PERMISSIONS_THRESHOLD) 00681 // { 00682 // __SUP_COUT__ << "Insufficient permissions for Root Viewer Admin 00683 // Controls: " << userPermissions << " < " << ROOT_VIEWER_PERMISSIONS_THRESHOLD << 00684 // __E__; 00685 // xmlOut.addTextElementToData("status", "Failed. Insufficient user 00686 // permissions."); 00687 // } 00688 // else 00689 // { 00690 std::string cmd = cgiIn("cmd"); // possible commands are 00691 // mkdir 00692 // save 00693 // delete 00694 00695 std::string path = CgiDataUtilities::postData(cgiIn, "path"); 00696 std::string name = CgiDataUtilities::postData(cgiIn, "name"); 00697 __SUP_COUT__ << "cmd " << cmd << __E__; 00698 __SUP_COUT__ << "path " << path << __E__; 00699 __SUP_COUT__ << "name " << name << __E__; 00700 00701 if(path.find("/" + PRE_MADE_ROOT_CFG_DIR + "/") == 00702 0) // ROOT config path must start the path 00703 { 00704 path = std::string(ROOT_DISPLAY_CONFIG_PATH) + "/" + 00705 path.substr(PRE_MADE_ROOT_CFG_DIR.length() + 2) + name; 00706 __SUP_COUT__ << "mod path " << path << __E__; 00707 00708 if(cmd == "mkdir") 00709 { 00710 if(mkdir(path.c_str(), 00711 S_IRWXU | (S_IRGRP | S_IXGRP) | 00712 (S_IROTH | S_IXOTH))) // mode = drwx r-x r-x 00713 xmlOut.addTextElementToData("status", 00714 "Failed. Directory create rejected."); 00715 else 00716 xmlOut.addTextElementToData("status", "1"); // success 00717 } 00718 else if(cmd == "save") 00719 { 00720 path += PRE_MADE_ROOT_CFG_FILE_EXT; // add file extension 00721 00722 bool useRunWildCard = 00723 atoi(CgiDataUtilities::postData(cgiIn, "useRunWildCard") 00724 .c_str()); // 0 or 1 00725 std::string config = CgiDataUtilities::postData(cgiIn, "config"); 00726 __SUP_COUT__ << "config " << config << __E__; 00727 __SUP_COUT__ << "useRunWildCard " << useRunWildCard << __E__; 00728 00729 // check if file already exists 00730 FILE* fp = fopen(path.c_str(), "r"); 00731 if(fp) 00732 { 00733 fclose(fp); 00734 xmlOut.addTextElementToData("status", "Failed. File already exists."); 00735 __SUP_COUT__ << " Failed. File already exists." << __E__; 00736 } 00737 else 00738 { 00739 // dump to file 00740 // verify proper format through read back 00741 // if successfully loaded, re-save for formatting 00742 00743 // dump to file 00744 fp = fopen(path.c_str(), "w"); 00745 fputs(config.c_str(), fp); 00746 fclose(fp); 00747 00748 // verify proper format through read back 00749 HttpXmlDocument cfgXml; 00750 if(cfgXml.loadXmlDocument(path)) 00751 { 00752 // successfully loaded, re-save for formatting 00753 cfgXml.saveXmlDocument(path); 00754 xmlOut.addTextElementToData("status", "1"); // success 00755 } 00756 else // failed to load properly 00757 { 00758 xmlOut.addTextElementToData( 00759 "status", "Failed. Fatal. Improper file format."); 00760 if(remove(path.c_str()) != 0) 00761 __SUP_COUT__ << "Failed. Could not remove poorly formed Root " 00762 "config file!" 00763 << __E__; 00764 } 00765 } 00766 } 00767 else if(cmd == "delete") 00768 { 00769 // guess first directory and then file 00770 if(rmdir(path.c_str()) == 0 || 00771 remove((path + PRE_MADE_ROOT_CFG_FILE_EXT).c_str()) == 0) 00772 xmlOut.addTextElementToData("status", "1"); // success 00773 else 00774 xmlOut.addTextElementToData("status", 00775 "Failed. Target could not be deleted."); 00776 } 00777 else 00778 xmlOut.addTextElementToData("status", "Failed. Unrecognized command."); 00779 } 00780 else 00781 xmlOut.addTextElementToData("status", "Failed. Invalid path."); 00782 00783 //} 00784 } 00785 else 00786 __SUP_COUT__ << "requestType request, " << requestType << ", not recognized." 00787 << __E__; 00788 // return xml doc holding server response 00789 // xmlOut.outputXmlDocument((std::ostringstream*) out, false); 00790 }