00001 #include <string>
00002 #include <iostream>
00003 #include <memory>
00004 #include <cassert>
00005 #include <dirent.h>
00006 #include "otsdaq-core/ConfigurationInterface/ConfigurationManagerRW.h"
00007 #include "otsdaq-core/ConfigurationInterface/ConfigurationInterface.h"
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017 using namespace ots;
00018
00019
00020 void FlattenActiveSystemAliasConfigurationGroups(int argc, char* argv[])
00021 {
00022 std::cout << "=================================================\n";
00023 std::cout << "=================================================\n";
00024 std::cout << "=================================================\n";
00025 std::cout << __COUT_HDR_FL__ << "\nFlattening Active System Aliases!" << std::endl;
00026
00027 std::cout << "\n\nusage: Two arguments:\n\t pathToSwapIn <baseFlatVersion> <pathToSwapIn (optional)> \n\n" <<
00028 "\t Default values: baseFlatVersion = 0, pathToSwapIn = \"\" \n\n" <<
00029 std::endl;
00030
00031 std::cout << "\n\nNote: you can optionally just swap databases (and not modify their contents at all)" <<
00032 " by providing an invalid baseFlatVersion of -1.\n\n" <<
00033 std::endl;
00034
00035 std::cout << "\n\nNote: This assumes artdaq db file type interface. " <<
00036 "The current database/ will be moved to database_<linuxtime>/ " <<
00037 "and if a pathToSwapIn is specified it will be copied to database/ " <<
00038 "before saving the currently active groups.\n\n" <<
00039 std::endl;
00040
00041 std::cout << "argc = " << argc << std::endl;
00042 for(int i = 0; i < argc; i++)
00043 std::cout << "argv[" << i << "] = " << argv[i] << std::endl;
00044
00045 if(argc < 2)
00046 {
00047 std::cout << "Must provide at least one parameter.";
00048 return;
00049 }
00050
00051
00052 std::string flatVersionStr = argv[1];
00053 if(flatVersionStr.find('h') != std::string::npos)
00054 {
00055 std::cout << "Recognized parameter 1. as a 'help' option. Usage was printed. Exiting." << std::endl;
00056 return;
00057 }
00058
00059 int flatVersion = 0;
00060 std::string pathToSwapIn = "";
00061 if(argc >= 2)
00062 sscanf(argv[1],"%d",&flatVersion);
00063 if(argc >= 3)
00064 pathToSwapIn = argv[2];
00065
00066 std::cout << __COUT_HDR_FL__ << "flatVersion = " << flatVersion << std::endl;
00067 std::cout << __COUT_HDR_FL__ << "pathToSwapIn = " << pathToSwapIn << std::endl;
00068
00069
00070
00071
00072
00073
00074
00075 setenv("CONFIGURATION_TYPE","File",1);
00076 setenv("CONFIGURATION_DATA_PATH",(std::string(getenv("USER_DATA")) + "/ConfigurationDataExamples").c_str(),1);
00077 setenv("CONFIGURATION_INFO_PATH",(std::string(getenv("USER_DATA")) + "/ConfigurationInfo").c_str(),1);
00079
00080
00081 setenv("SERVICE_DATA_PATH",(std::string(getenv("USER_DATA")) + "/ServiceData").c_str(),1);
00082
00083
00084
00085 setenv("OTSDAQ_LIB",(std::string(getenv("USER_DATA")) + "/").c_str(),1);
00086 setenv("OTSDAQ_UTILITIES_LIB",(std::string(getenv("USER_DATA")) + "/").c_str(),1);
00087
00088
00089 setenv("OTS_MAIN_PORT","2015",1);
00090
00091
00092 setenv("XDAQ_CONFIGURATION_DATA_PATH",(std::string(getenv("USER_DATA")) + "/XDAQConfigurations").c_str(),1);
00093 setenv("XDAQ_CONFIGURATION_XML","otsConfigurationNoRU_CMake",1);
00095
00096
00097
00098
00099
00100 std::cout << "\n\n\n" << __COUT_HDR_FL__ << "Loading active Aliases..." << std::endl;
00101 ConfigurationManagerRW cfgMgrInst("flatten_admin");
00102 ConfigurationManagerRW *cfgMgr = &cfgMgrInst;
00103
00104
00105
00106
00107
00108
00109
00110
00111
00112
00113
00114
00115
00116
00117
00118
00119
00120
00121
00122
00123
00124
00125
00126
00127
00128
00129 std::map<std::pair<std::string,ConfigurationGroupKey>,
00130 ConfigurationGroupKey> groupSet;
00131
00132 std::map<std::pair<std::string,ConfigurationVersion>,
00133 ConfigurationVersion> modifiedTables;
00134 std::map<std::string, std::pair<ConfigurationGroupKey,
00135 ConfigurationGroupKey>> activeGroupKeys;
00136 std::map<std::pair<std::string,ConfigurationGroupKey>,
00137 std::string> groupErrors;
00138
00139 std::string activeBackboneTableName = "";
00140 std::string activeContextTableName = "";
00141 std::string activeConfigTableName = "";
00142
00143 std::string nowTime = std::to_string(time(0));
00144
00145 std::string thenTime = "";
00146 if(pathToSwapIn != "")
00147 {
00148 thenTime = pathToSwapIn.substr(pathToSwapIn.rfind('_')+1);
00149 std::cout << __COUT_HDR_FL__<< "thenTime = " << thenTime << std::endl;
00150
00151 }
00152
00153
00154 std::map<std::string, std::pair<std::string, ConfigurationGroupKey>> activeGroupsMap =
00155 cfgMgr->getActiveConfigurationGroups();
00156
00157 for(const auto &activeGroup: activeGroupsMap)
00158 {
00159 groupSet.insert(std::pair<
00160 std::pair<std::string,ConfigurationGroupKey>,
00161 ConfigurationGroupKey> (
00162 std::pair<std::string,ConfigurationGroupKey>(
00163 activeGroup.second.first,
00164 activeGroup.second.second),
00165 ConfigurationGroupKey())
00166 );
00167 activeGroupKeys.insert(std::pair<
00168 std::string,
00169 std::pair<ConfigurationGroupKey,ConfigurationGroupKey>> (
00170 activeGroup.second.first,
00171 std::pair<ConfigurationGroupKey,ConfigurationGroupKey>(
00172 activeGroup.second.second,
00173 ConfigurationGroupKey()))
00174 );
00175
00176 if(activeGroup.first == ConfigurationManager::ACTIVE_GROUP_NAME_BACKBONE)
00177 {
00178 activeBackboneTableName = activeGroup.second.first;
00179 std::cout << __COUT_HDR_FL__<< "found activeBackboneTableName = " <<
00180 activeBackboneTableName << std::endl;
00181 }
00182 else if(activeGroup.first == ConfigurationManager::ACTIVE_GROUP_NAME_CONTEXT)
00183 {
00184 activeContextTableName = activeGroup.second.first;
00185 std::cout << __COUT_HDR_FL__<< "found activeContextTableName = " <<
00186 activeContextTableName << std::endl;
00187 }
00188 else if(activeGroup.first == ConfigurationManager::ACTIVE_GROUP_NAME_CONFIGURATION)
00189 {
00190 activeConfigTableName = activeGroup.second.first;
00191 std::cout << __COUT_HDR_FL__<< "found activeConfigTableName = " <<
00192 activeConfigTableName << std::endl;
00193 }
00194 }
00195
00196
00197 const std::string groupAliasesTableName = "GroupAliasesConfiguration";
00198 std::map<std::string, ConfigurationVersion> activeVersions = cfgMgr->getActiveVersions();
00199 if(activeVersions.find(groupAliasesTableName) == activeVersions.end())
00200 {
00201 __SS__ << "\nActive version of GroupAliasesConfiguration missing! " <<
00202 "GroupAliasesConfiguration is a required member of the Backbone configuration group." <<
00203 "\n\nLikely you need to activate a valid Backbone group." <<
00204 std::endl;
00205 throw std::runtime_error(ss.str());
00206 }
00207
00208
00209 std::vector<std::pair<std::string,ConfigurationTree> > aliasNodePairs =
00210 cfgMgr->getNode(groupAliasesTableName).getChildren();
00211 for(auto& groupPair:aliasNodePairs)
00212 groupSet.insert(std::pair<
00213 std::pair<std::string,ConfigurationGroupKey>,
00214 ConfigurationGroupKey> (
00215 std::pair<std::string,ConfigurationGroupKey>(
00216 groupPair.second.getNode("GroupName").getValueAsString(),
00217 ConfigurationGroupKey(groupPair.second.getNode("GroupKey").getValueAsString())),
00218 ConfigurationGroupKey())
00219 );
00220
00221 std::cout << __COUT_HDR_FL__<< "Identfied groups:" << std::endl;
00222 for(auto& group:groupSet)
00223 std::cout << __COUT_HDR_FL__<< group.first.first << " " << group.first.second << std::endl;
00224 std::cout << __COUT_HDR_FL__<< std::endl;
00225 std::cout << __COUT_HDR_FL__<< std::endl;
00226
00227
00228
00229
00230 std::string currentDir = getenv("ARTDAQ_DATABASE_URI");
00231
00232 if(currentDir.find("filesystemdb://") != 0)
00233 throw std::runtime_error("filesystemdb:// was not found in $ARTDAQ_DATABASE_URI!");
00234
00235 currentDir = currentDir.substr(std::string("filesystemdb://").length());
00236 while(currentDir.length() && currentDir[currentDir.length()-1] == '/')
00237 currentDir = currentDir.substr(0,currentDir.length()-1);
00238 std::string moveToDir = currentDir + "_" + nowTime;
00239 if(argc < 2)
00240 throw std::runtime_error("Aborting move! Must at least give version argument to flatten to!");
00241
00242 if(pathToSwapIn != "")
00243 {
00244 DIR *dp;
00245 if((dp = opendir(pathToSwapIn.c_str())) == 0)
00246 {
00247 std::cout << __COUT_HDR_FL__<< "ERROR:(" << errno << "). Can't open directory: " << pathToSwapIn << std::endl;
00248 exit(0);
00249 }
00250 closedir(dp);
00251 }
00252
00253
00254 std::cout << __COUT_HDR_FL__ << "Moving current directory: \t" << currentDir << std::endl;
00255 std::cout << __COUT_HDR_FL__ << "\t... to: \t\t" << moveToDir << std::endl;
00256
00257 rename(currentDir.c_str(),moveToDir.c_str());
00258
00259 if(pathToSwapIn != "")
00260 {
00261 std::cout << __COUT_HDR_FL__ << "Swapping in directory: \t" << pathToSwapIn << std::endl;
00262 std::cout << __COUT_HDR_FL__ << "\t.. to: \t\t" << currentDir << std::endl;
00263 rename(pathToSwapIn.c_str(),currentDir.c_str());
00264
00265
00266
00267 std::string activeGroupsFile = ConfigurationManager::ACTIVE_GROUP_FILENAME + "." + thenTime;
00268 FILE *fp = fopen(activeGroupsFile.c_str(),"r");
00269 if(fp)
00270 {
00271 std::cout << __COUT_HDR_FL__ << "Swapping active groups file: \t" <<
00272 activeGroupsFile << std::endl;
00273 std::cout << __COUT_HDR_FL__ << "\t.. to: \t\t" <<
00274 ConfigurationManager::ACTIVE_GROUP_FILENAME << std::endl;
00275 rename(activeGroupsFile.c_str(),
00276 ConfigurationManager::ACTIVE_GROUP_FILENAME.c_str());
00277 }
00278 }
00279
00280
00281
00282
00283
00284 ConfigurationInterface* theInterface_ = ConfigurationInterface::getInstance(false);
00285 ConfigurationView* cfgView;
00286 ConfigurationBase* config;
00287
00288 bool errDetected;
00289 std::string accumulateErrors = "";
00290 std::map<std::string, ConfigurationVersion> memberMap;
00291 int count = 0;
00292
00293
00294 if(ConfigurationVersion(flatVersion).isInvalid() ||
00295 ConfigurationVersion(flatVersion).isTemporaryVersion())
00296 {
00297 std::cout << __COUT_HDR_FL__ << "\n\nflatVersion " << ConfigurationVersion(flatVersion) <<
00298 " is an invalid or temporary version. Skipping to end!" << std::endl;
00299 goto CLEAN_UP;
00300 }
00301
00302
00303 for(auto& groupPair:groupSet)
00304 {
00305 errDetected = false;
00306
00307 std::cout << __COUT_HDR_FL__ << "****************************" << std::endl;
00308 std::cout << __COUT_HDR_FL__ << "Loading members for " <<
00309 groupPair.first.first <<
00310 "(" << groupPair.first.second << ")" <<
00311 std::endl;
00312 std::cout << __COUT_HDR_FL__ << "flatVersion = " << flatVersion << std::endl;
00313
00314
00315 if(pathToSwapIn != "")
00316 {
00317 std::cout << __COUT_HDR_FL__ << "REVERT by Swapping back directory: \t" << currentDir << std::endl;
00318 std::cout << __COUT_HDR_FL__ << "\t.. to: \t\t" << pathToSwapIn << std::endl;
00319 if(rename(currentDir.c_str(),pathToSwapIn.c_str()) < 0)
00320 {
00321 __SS__ << "Problem!" << std::endl;
00322 throw std::runtime_error(ss.str());
00323 }
00324
00325 }
00326 else if(count)
00327 {
00328 std::cout << __COUT_HDR_FL__ << "REVERT by Moving directory: \t" << currentDir << std::endl;
00329 std::cout << __COUT_HDR_FL__ << "\t.. to temporary directory: \t\t" << (moveToDir+"_tmp") << std::endl;
00330 if(rename(currentDir.c_str(),(moveToDir+"_tmp").c_str()) < 0)
00331 {
00332 __SS__ << "Problem!" << std::endl;
00333 throw std::runtime_error(ss.str());
00334 }
00335 }
00336
00337
00338 std::cout << __COUT_HDR_FL__ << "REVERT by Moving directory: \t" << moveToDir << std::endl;
00339 std::cout << __COUT_HDR_FL__ << "\t... to: \t\t" << currentDir << std::endl;
00340 if(rename(moveToDir.c_str(),currentDir.c_str()) < 0)
00341 {
00342 __SS__ << "Problem!" << std::endl;
00343 throw std::runtime_error(ss.str());
00344 }
00345
00346
00347
00348
00349 try
00350 {
00351 memberMap =
00352 cfgMgr->loadConfigurationGroup(
00353 groupPair.first.first,
00354 groupPair.first.second,
00355 true,0,&accumulateErrors);
00356 }
00357 catch(std::runtime_error& e)
00358 {
00359
00360 std::cout << __COUT_HDR_FL__ << "Error was caught loading members for " <<
00361 groupPair.first.first <<
00362 "(" << groupPair.first.second << ")" <<
00363 std::endl;
00364 std::cout << __COUT_HDR_FL__ << e.what() << std::endl;
00365 errDetected = true;
00366 }
00367 catch(...)
00368 {
00369 std::cout << __COUT_HDR_FL__ << "Error was caught loading members for " <<
00370 groupPair.first.first <<
00371 "(" << groupPair.first.second << ")" <<
00372 std::endl;
00373 errDetected = true;
00374 }
00375
00376
00377
00378
00379
00380
00381
00382 std::cout << __COUT_HDR_FL__ << "Moving current directory: \t" << currentDir << std::endl;
00383 std::cout << __COUT_HDR_FL__ << "\t... to: \t\t" << moveToDir << std::endl;
00384 if(rename(currentDir.c_str(),moveToDir.c_str()) < 0)
00385 {
00386 __SS__ << "Problem!" << std::endl;
00387 throw std::runtime_error(ss.str());
00388 }
00389
00390 if(pathToSwapIn != "")
00391 {
00392 std::cout << __COUT_HDR_FL__ << "Swapping in directory: \t" << pathToSwapIn << std::endl;
00393 std::cout << __COUT_HDR_FL__ << "\t.. to: \t\t" << currentDir << std::endl;
00394 if(rename(pathToSwapIn.c_str(),currentDir.c_str()) < 0)
00395 {
00396 __SS__ << "Problem!" << std::endl;
00397 throw std::runtime_error(ss.str());
00398 }
00399 }
00400 else if(count)
00401 {
00402 std::cout << __COUT_HDR_FL__ << "Moving temporary directory: \t" << (moveToDir+"_tmp") << std::endl;
00403 std::cout << __COUT_HDR_FL__ << "\t.. to current directory: \t\t" << currentDir << std::endl;
00404 if(rename((moveToDir+"_tmp").c_str(),currentDir.c_str()) < 0)
00405 {
00406 __SS__ << "Problem!" << std::endl;
00407 throw std::runtime_error(ss.str());
00408 }
00409 }
00410
00411
00412
00413 if(errDetected)
00414 {
00415
00416
00417
00418
00419
00420 groupErrors.insert(std::pair<
00421 std::pair<std::string,ConfigurationGroupKey>,
00422 std::string> (
00423 std::pair<std::string,ConfigurationGroupKey>(
00424 groupPair.first.first,
00425 groupPair.first.second),
00426 "Error caught loading the group."));
00427 continue;
00428 }
00429
00430
00431
00432
00433
00434
00435 try
00436 {
00437
00438 for(auto &memberPair:memberMap)
00439 {
00440 std::cout << __COUT_HDR_FL__ << memberPair.first << ":v" << memberPair.second << std::endl;
00441
00442
00443
00444 if(modifiedTables.find(std::pair<std::string,ConfigurationVersion>(
00445 memberPair.first,
00446 memberPair.second
00447 )) != modifiedTables.end())
00448 {
00449
00450 std::cout << __COUT_HDR_FL__ << "Table was already modified!" << std::endl;
00451 memberPair.second = modifiedTables[std::pair<std::string,ConfigurationVersion>(
00452 memberPair.first,
00453 memberPair.second
00454 )];
00455 std::cout << __COUT_HDR_FL__ << "\t to...\t" <<
00456 memberPair.first << ":v" << memberPair.second << std::endl;
00457 continue;
00458 }
00459
00460
00461 config = cfgMgr->getConfigurationByName(memberPair.first);
00462 cfgView = config->getViewP();
00463 cfgView->setVersion(ConfigurationVersion(flatVersion));
00464 theInterface_->saveActiveVersion(config);
00465
00466
00467 cfgView->setVersion(memberPair.second);
00468
00469 memberPair.second = flatVersion;
00470
00471 std::cout << __COUT_HDR_FL__ << "\t to...\t" <<
00472 memberPair.first << ":v" << memberPair.second << std::endl;
00473
00474
00475 modifiedTables.insert(std::pair<
00476 std::pair<std::string,ConfigurationVersion>,
00477 ConfigurationVersion> (
00478 std::pair<std::string,ConfigurationVersion>(
00479 memberPair.first,
00480 memberPair.second),
00481 ConfigurationVersion(flatVersion))
00482 );
00483 }
00484
00485
00486 theInterface_->saveConfigurationGroup(memberMap,
00487 ConfigurationGroupKey::getFullGroupString(
00488 groupPair.first.first,
00489 ConfigurationGroupKey(flatVersion)));
00490
00491
00492 groupPair.second = ConfigurationGroupKey(flatVersion);
00493
00494
00495 if(activeGroupKeys.find(groupPair.first.first) != activeGroupKeys.end() &&
00496 activeGroupKeys[groupPair.first.first].first == groupPair.first.second)
00497 activeGroupKeys[groupPair.first.first].second =
00498 ConfigurationGroupKey(flatVersion);
00499 }
00500 catch(std::runtime_error& e)
00501 {
00502 std::cout << __COUT_HDR_FL__ << "Error was caught saving group " <<
00503 groupPair.first.first <<
00504 " (" << groupPair.first.second << ") " <<
00505 std::endl;
00506 std::cout << __COUT_HDR_FL__ << e.what() << std::endl;
00507
00508 groupErrors.insert(std::pair<
00509 std::pair<std::string,ConfigurationGroupKey>,
00510 std::string> (
00511 std::pair<std::string,ConfigurationGroupKey>(
00512 groupPair.first.first,
00513 groupPair.first.second),
00514 "Error caught saving the group."));
00515 }
00516 catch(...)
00517 {
00518 std::cout << __COUT_HDR_FL__ << "Error was caught saving group " <<
00519 groupPair.first.first <<
00520 " (" << groupPair.first.second << ") " <<
00521 std::endl;
00522
00523 groupErrors.insert(std::pair<
00524 std::pair<std::string,ConfigurationGroupKey>,
00525 std::string> (
00526 std::pair<std::string,ConfigurationGroupKey>(
00527 groupPair.first.first,
00528 groupPair.first.second),
00529 "Error caught saving the group."));
00530 }
00531
00532
00533
00534
00535 ++flatVersion;
00536 ++count;
00537 }
00538
00539
00540 {
00541 FILE *fp = fopen((moveToDir + "/README_otsdaq_flatten.txt").c_str(),"a");
00542 if(!fp)
00543 std::cout << __COUT_HDR_FL__ << "\tError opening README file!" << std::endl;
00544 else
00545 {
00546 time_t rawtime;
00547 struct tm * timeinfo;
00548 char buffer [200];
00549
00550 time (&rawtime);
00551 timeinfo = localtime (&rawtime);
00552 strftime (buffer,200,"%b %d, %Y %I:%M%p %Z",timeinfo);
00553
00554 fprintf(fp,"This database was moved from...\n\t %s \nto...\n\t %s \nat this time \n\t %lu \t %s\n\n\n",
00555 currentDir.c_str(),moveToDir.c_str(),time(0),buffer);
00556
00557 fclose(fp);
00558 }
00559 }
00560
00561
00562
00563 {
00564 FILE *fp = fopen((currentDir + "/README_otsdaq_flatten.txt").c_str(),"a");
00565
00566 if(!fp)
00567 std::cout << __COUT_HDR_FL__ << "\tError opening README file!" << std::endl;
00568 else
00569 {
00570 time_t rawtime;
00571 struct tm * timeinfo;
00572 char buffer [200];
00573
00574 time (&rawtime);
00575 timeinfo = localtime (&rawtime);
00576 strftime (buffer,200,"%b %d, %Y %I:%M:%S%p %Z",timeinfo);
00577
00578 fprintf(fp,"This database was moved from...\t %s \t to...\t %s at this time \t %lu \t %s\n\n",
00579 pathToSwapIn.c_str(),currentDir.c_str(),time(0),buffer);
00580 fclose(fp);
00581 }
00582 }
00583
00584
00585
00586
00587
00588
00589
00590
00591
00592
00593
00594
00595
00596
00597
00598
00599
00600
00601
00602
00603
00604
00605
00606
00607
00608
00609
00610
00611
00612 if(activeBackboneTableName == "")
00613 {
00614 std::cout << __COUT_HDR_FL__ << "No active Backbone table identified." << std::endl;
00615 goto CLEAN_UP;
00616 }
00617
00618 std::cout << "\n\n" << __COUT_HDR_FL__ <<
00619 "Modifying the active Backbone table to reflect new table versions and group keys." <<
00620 std::endl;
00621
00622 {
00623 memberMap =
00624 cfgMgr->loadConfigurationGroup(
00625 activeBackboneTableName,
00626 activeGroupKeys[activeBackboneTableName].second,
00627 true,0,&accumulateErrors);
00628
00629
00630
00631
00632 const std::string groupAliasesName = "GroupAliasesConfiguration";
00633 const std::string versionAliasesName = "VersionAliasesConfiguration";
00634
00635
00636 std::map<std::string, ConfigurationVersion> activeMap = cfgMgr->getActiveVersions();
00637
00638
00639 if(activeMap.find(groupAliasesName) != activeMap.end())
00640 {
00641 std::cout << __COUT_HDR_FL__ << "\n\nModifying " << groupAliasesName << std::endl;
00642 config = cfgMgr->getConfigurationByName(groupAliasesName);
00643 cfgView = config->getViewP();
00644
00645 unsigned int col1 = cfgView->findCol("GroupName");
00646 unsigned int col2 = cfgView->findCol("GroupKey");
00647
00648
00649
00650
00651 bool found;
00652 for(unsigned int row = 0; row<cfgView->getNumberOfRows(); ++row )
00653 {
00654 found = false;
00655 for(const auto &group: groupSet)
00656 if(group.second.isInvalid()) continue;
00657 else if(cfgView->getDataView()[row][col1] == group.first.first &&
00658 cfgView->getDataView()[row][col2] == group.first.second.toString())
00659 {
00660
00661 std::cout << __COUT_HDR_FL__ <<
00662 "Changing row " << row << " for " <<
00663 cfgView->getDataView()[row][col1] << " key=" <<
00664 cfgView->getDataView()[row][col2] << " to NEW key=" <<
00665 group.second << std::endl;
00666 cfgView->setValue(
00667 group.second.toString(),
00668 row,col2);
00669 found = true;
00670 break;
00671 }
00672
00673 if(!found)
00674 cfgView->deleteRow(row--);
00675 }
00676
00677 }
00678
00679
00680 if(activeMap.find(versionAliasesName) != activeMap.end())
00681 {
00682 std::cout << __COUT_HDR_FL__ << "\n\nModifying " << versionAliasesName << std::endl;
00683 config = cfgMgr->getConfigurationByName(versionAliasesName);
00684 cfgView = config->getViewP();
00685 unsigned int col1 = cfgView->findCol("ConfigurationName");
00686 unsigned int col2 = cfgView->findCol("Version");
00687
00688
00689 bool found;
00690 for(unsigned int row = 0; row<cfgView->getNumberOfRows(); ++row )
00691 {
00692 found = false;
00693 for(const auto &table:modifiedTables)
00694 if(cfgView->getDataView()[row][col1] == table.first.first &&
00695 cfgView->getDataView()[row][col2] == table.first.second.toString())
00696 {
00697
00698 std::cout << __COUT_HDR_FL__ << "Changing row " << row << " for " <<
00699 cfgView->getDataView()[row][col1] << " version=" <<
00700 cfgView->getDataView()[row][col2] << " to NEW version=" <<
00701 table.second << std::endl;
00702 cfgView->setValue(table.second.toString(),row,col2);
00703 found = true;
00704 break;
00705 }
00706
00707 if(!found)
00708 cfgView->deleteRow(row--);
00709 }
00710 }
00711
00712
00713
00714
00715
00716 std::cout << __COUT_HDR_FL__ << groupAliasesName << ":v" <<
00717 memberMap[groupAliasesName] << std::endl;
00718
00719 config = cfgMgr->getConfigurationByName(groupAliasesName);
00720 cfgView = config->getViewP();
00721 cfgView->setVersion(ConfigurationVersion(flatVersion));
00722 theInterface_->saveActiveVersion(config);
00723
00724 memberMap[groupAliasesName] = flatVersion;
00725
00726 std::cout << __COUT_HDR_FL__ << "\t to...\t" <<
00727 groupAliasesName << ":v" << memberMap[groupAliasesName] << std::endl;
00728
00729
00730
00731 std::cout << __COUT_HDR_FL__ << versionAliasesName << ":v" <<
00732 memberMap[versionAliasesName] << std::endl;
00733
00734 config = cfgMgr->getConfigurationByName(versionAliasesName);
00735 cfgView = config->getViewP();
00736 cfgView->setVersion(ConfigurationVersion(flatVersion));
00737 theInterface_->saveActiveVersion(config);
00738
00739 memberMap[versionAliasesName] = flatVersion;
00740
00741 std::cout << __COUT_HDR_FL__ << "\t to...\t" <<
00742 versionAliasesName << ":v" << memberMap[versionAliasesName] << std::endl;
00743
00744
00745 theInterface_->saveConfigurationGroup(memberMap,
00746 ConfigurationGroupKey::getFullGroupString(
00747 activeBackboneTableName,
00748 ConfigurationGroupKey(flatVersion)));
00749
00750 activeGroupKeys[activeBackboneTableName].second =
00751 ConfigurationGroupKey(flatVersion);
00752
00753 std::cout << __COUT_HDR_FL__ << "New to-be-active backbone group " << activeBackboneTableName <<
00754 ":v" << activeGroupKeys[activeBackboneTableName].second << std::endl;
00755 }
00756
00757
00758
00759
00760
00761
00762
00763 {
00764 std::cout << "\n\n" << __COUT_HDR_FL__ << "Manipulating the Active Groups file..." << std::endl;
00765
00766
00767 FILE *fp = fopen(ConfigurationManager::ACTIVE_GROUP_FILENAME.c_str(),"r");
00768 if(!fp)
00769 {
00770 __SS__ << "Original active groups file '" << ConfigurationManager::ACTIVE_GROUP_FILENAME
00771 << "' not found." << std::endl;
00772 goto CLEAN_UP;
00773 }
00774
00775 std::cout << __COUT_HDR_FL__ << "Backing up file: " << ConfigurationManager::ACTIVE_GROUP_FILENAME
00776 << std::endl;
00777
00778 fclose(fp);
00779
00780 std::string renameFile = ConfigurationManager::ACTIVE_GROUP_FILENAME + "." + nowTime;
00781 rename(ConfigurationManager::ACTIVE_GROUP_FILENAME.c_str(),
00782 renameFile.c_str());
00783
00784 std::cout << __COUT_HDR_FL__ << "Backup file name: " << renameFile
00785 << std::endl;
00786
00787 ConfigurationGroupKey *theConfigurationGroupKey_, *theContextGroupKey_, *theBackboneGroupKey_;
00788 std::string theConfigurationGroup_, theContextGroup_, theBackboneGroup_;
00789
00790 theConfigurationGroup_ = activeConfigTableName;
00791 theConfigurationGroupKey_ = &(activeGroupKeys[activeConfigTableName].second);
00792
00793 theContextGroup_ = activeContextTableName;
00794 theContextGroupKey_ = &(activeGroupKeys[activeContextTableName].second);
00795
00796 theBackboneGroup_ = activeBackboneTableName;
00797 theBackboneGroupKey_ = &(activeGroupKeys[activeBackboneTableName].second);
00798
00799
00800
00801 {
00802 std::cout << __COUT_HDR_FL__ << "Updating persistent active groups to " <<
00803 ConfigurationManager::ACTIVE_GROUP_FILENAME << " ..." << std::endl;
00804
00805 std::string fn = ConfigurationManager::ACTIVE_GROUP_FILENAME;
00806 FILE *fp = fopen(fn.c_str(),"w");
00807 if(!fp) return;
00808
00809 fprintf(fp,"%s\n",theContextGroup_.c_str());
00810 fprintf(fp,"%s\n",theContextGroupKey_?theContextGroupKey_->toString().c_str():"-1");
00811 fprintf(fp,"%s\n",theBackboneGroup_.c_str());
00812 fprintf(fp,"%s\n",theBackboneGroupKey_?theBackboneGroupKey_->toString().c_str():"-1");
00813 fprintf(fp,"%s\n",theConfigurationGroup_.c_str());
00814 fprintf(fp,"%s\n",theConfigurationGroupKey_?theConfigurationGroupKey_->toString().c_str():"-1");
00815 fclose(fp);
00816 }
00817 }
00818
00819
00820
00821 std::cout << "\n\n" << __COUT_HDR_FL__ << "Resulting Groups:" << std::endl;
00822 for(const auto &group: groupSet)
00823 std::cout << __COUT_HDR_FL__ << "\t" << group.first.first << ": " <<
00824 group.first.second << " => " << group.second << std::endl;
00825 std::cout << "\n\n" << __COUT_HDR_FL__ << "Resulting Groups end." << std::endl;
00826
00827
00828
00829
00830 std::cout << "\n\n" << __COUT_HDR_FL__ << "Resulting Active Groups:" << std::endl;
00831 for(const auto &activeGroup: activeGroupKeys)
00832 std::cout << __COUT_HDR_FL__ << "\t" << activeGroup.first << ": " <<
00833 activeGroup.second.first << " => " << activeGroup.second.second << std::endl;
00834
00835 std::cout << __COUT_HDR_FL__ << activeBackboneTableName << " is the " <<
00836 ConfigurationManager::ACTIVE_GROUP_NAME_BACKBONE << "." << std::endl;
00837 std::cout << "\n\n" << __COUT_HDR_FL__ << "Resulting Active Groups end." << std::endl;
00838
00839
00840 CLEAN_UP:
00841
00842 std::cout << "\n\n" << __COUT_HDR_FL__ << "End of Flattening Active Configuration Groups!\n\n\n" << std::endl;
00843
00844
00845
00846 std::cout << __COUT_HDR_FL__ << "****************************" << std::endl;
00847 std::cout << __COUT_HDR_FL__ << "There were " << groupSet.size() <<
00848 " groups considered, and there were errors handling " << groupErrors.size() <<
00849 " of those groups." << std::endl;
00850 std::cout << __COUT_HDR_FL__ << "The following errors were found handling the groups:" << std::endl;
00851 for(auto& groupErr:groupErrors)
00852 std::cout << __COUT_HDR_FL__ << "\t" << groupErr.first.first << " " << groupErr.first.second <<
00853 ": \t" << groupErr.second << std::endl;
00854 std::cout << __COUT_HDR_FL__ << "End of errors.\n\n" << std::endl;
00855
00856
00857 std::cout << __COUT_HDR_FL__ << "Run the following to return to your previous database structure:" <<
00858 std::endl;
00859 std::cout << __COUT_HDR_FL__ << "\t otsdaq_flatten_system_aliases -1 " << moveToDir <<
00860 "\n\n" << std::endl;
00861
00862
00863 return;
00864 }
00865
00866 int main(int argc, char* argv[])
00867 {
00868 FlattenActiveSystemAliasConfigurationGroups(argc,argv);
00869 return 0;
00870 }
00871
00872
00873