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