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 cfgMgr->loadConfigurationGroup(
00368 groupPair.first.first,
00369 groupPair.first.second,
00370 true,&memberMap,0,&accumulateErrors);
00371 }
00372 catch(std::runtime_error& e)
00373 {
00374
00375 std::cout << __COUT_HDR_FL__ << "Error was caught loading members for " <<
00376 groupPair.first.first <<
00377 "(" << groupPair.first.second << ")" <<
00378 std::endl;
00379 std::cout << __COUT_HDR_FL__ << e.what() << std::endl;
00380 errDetected = true;
00381 }
00382 catch(...)
00383 {
00384 std::cout << __COUT_HDR_FL__ << "Error was caught loading members for " <<
00385 groupPair.first.first <<
00386 "(" << groupPair.first.second << ")" <<
00387 std::endl;
00388 errDetected = true;
00389 }
00390
00391
00392
00393
00394
00395
00396
00397 std::cout << __COUT_HDR_FL__ << "Moving current directory: \t" << currentDir << std::endl;
00398 std::cout << __COUT_HDR_FL__ << "\t... to: \t\t" << moveToDir << std::endl;
00399 if(rename(currentDir.c_str(),moveToDir.c_str()) < 0)
00400 {
00401 __SS__ << "Problem!" << std::endl;
00402 throw std::runtime_error(ss.str());
00403 }
00404
00405 if(pathToSwapIn != "")
00406 {
00407 std::cout << __COUT_HDR_FL__ << "Swapping in directory: \t" << pathToSwapIn << std::endl;
00408 std::cout << __COUT_HDR_FL__ << "\t.. to: \t\t" << currentDir << std::endl;
00409 if(rename(pathToSwapIn.c_str(),currentDir.c_str()) < 0)
00410 {
00411 __SS__ << "Problem!" << std::endl;
00412 throw std::runtime_error(ss.str());
00413 }
00414 }
00415 else if(count)
00416 {
00417 std::cout << __COUT_HDR_FL__ << "Moving temporary directory: \t" << (moveToDir+"_tmp") << std::endl;
00418 std::cout << __COUT_HDR_FL__ << "\t.. to current directory: \t\t" << currentDir << std::endl;
00419 if(rename((moveToDir+"_tmp").c_str(),currentDir.c_str()) < 0)
00420 {
00421 __SS__ << "Problem!" << std::endl;
00422 throw std::runtime_error(ss.str());
00423 }
00424 }
00425
00426
00427
00428 if(errDetected)
00429 {
00430
00431
00432
00433
00434
00435 groupErrors.insert(std::pair<
00436 std::pair<std::string,ConfigurationGroupKey>,
00437 std::string> (
00438 std::pair<std::string,ConfigurationGroupKey>(
00439 groupPair.first.first,
00440 groupPair.first.second),
00441 "Error caught loading the group."));
00442 continue;
00443 }
00444
00445
00446
00447
00448
00449
00450 try
00451 {
00452
00453 for(auto &memberPair:memberMap)
00454 {
00455 std::cout << __COUT_HDR_FL__ << memberPair.first << ":v" << memberPair.second << std::endl;
00456
00457
00458
00459 if(modifiedTables.find(std::pair<std::string,ConfigurationVersion>(
00460 memberPair.first,
00461 memberPair.second
00462 )) != modifiedTables.end())
00463 {
00464
00465 std::cout << __COUT_HDR_FL__ << "Table was already modified!" << std::endl;
00466 memberPair.second = modifiedTables[std::pair<std::string,ConfigurationVersion>(
00467 memberPair.first,
00468 memberPair.second
00469 )];
00470 std::cout << __COUT_HDR_FL__ << "\t to...\t" <<
00471 memberPair.first << ":v" << memberPair.second << std::endl;
00472 continue;
00473 }
00474
00475
00476 config = cfgMgr->getConfigurationByName(memberPair.first);
00477 cfgView = config->getViewP();
00478 cfgView->setVersion(ConfigurationVersion(flatVersion));
00479 theInterface_->saveActiveVersion(config);
00480
00481
00482 cfgView->setVersion(memberPair.second);
00483
00484 memberPair.second = flatVersion;
00485
00486 std::cout << __COUT_HDR_FL__ << "\t to...\t" <<
00487 memberPair.first << ":v" << memberPair.second << std::endl;
00488
00489
00490 modifiedTables.insert(std::pair<
00491 std::pair<std::string,ConfigurationVersion>,
00492 ConfigurationVersion> (
00493 std::pair<std::string,ConfigurationVersion>(
00494 memberPair.first,
00495 memberPair.second),
00496 ConfigurationVersion(flatVersion))
00497 );
00498 }
00499
00500
00501 theInterface_->saveConfigurationGroup(memberMap,
00502 ConfigurationGroupKey::getFullGroupString(
00503 groupPair.first.first,
00504 ConfigurationGroupKey(flatVersion)));
00505
00506
00507 groupPair.second = ConfigurationGroupKey(flatVersion);
00508
00509
00510 if(activeGroupKeys.find(groupPair.first.first) != activeGroupKeys.end() &&
00511 activeGroupKeys[groupPair.first.first].first == groupPair.first.second)
00512 activeGroupKeys[groupPair.first.first].second =
00513 ConfigurationGroupKey(flatVersion);
00514 }
00515 catch(std::runtime_error& e)
00516 {
00517 std::cout << __COUT_HDR_FL__ << "Error was caught saving group " <<
00518 groupPair.first.first <<
00519 " (" << groupPair.first.second << ") " <<
00520 std::endl;
00521 std::cout << __COUT_HDR_FL__ << e.what() << 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 catch(...)
00532 {
00533 std::cout << __COUT_HDR_FL__ << "Error was caught saving group " <<
00534 groupPair.first.first <<
00535 " (" << groupPair.first.second << ") " <<
00536 std::endl;
00537
00538 groupErrors.insert(std::pair<
00539 std::pair<std::string,ConfigurationGroupKey>,
00540 std::string> (
00541 std::pair<std::string,ConfigurationGroupKey>(
00542 groupPair.first.first,
00543 groupPair.first.second),
00544 "Error caught saving the group."));
00545 }
00546
00547
00548
00549
00550 ++flatVersion;
00551 ++count;
00552 }
00553
00554
00555 {
00556 FILE *fp = fopen((moveToDir + "/README_otsdaq_flatten.txt").c_str(),"a");
00557 if(!fp)
00558 std::cout << __COUT_HDR_FL__ << "\tError opening README file!" << std::endl;
00559 else
00560 {
00561 time_t rawtime;
00562 struct tm * timeinfo;
00563 char buffer [200];
00564
00565 time (&rawtime);
00566 timeinfo = localtime (&rawtime);
00567 strftime (buffer,200,"%b %d, %Y %I:%M%p %Z",timeinfo);
00568
00569 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",
00570 currentDir.c_str(),moveToDir.c_str(),time(0),buffer);
00571
00572 fclose(fp);
00573 }
00574 }
00575
00576
00577
00578 {
00579 FILE *fp = fopen((currentDir + "/README_otsdaq_flatten.txt").c_str(),"a");
00580
00581 if(!fp)
00582 std::cout << __COUT_HDR_FL__ << "\tError opening README file!" << std::endl;
00583 else
00584 {
00585 time_t rawtime;
00586 struct tm * timeinfo;
00587 char buffer [200];
00588
00589 time (&rawtime);
00590 timeinfo = localtime (&rawtime);
00591 strftime (buffer,200,"%b %d, %Y %I:%M:%S%p %Z",timeinfo);
00592
00593 fprintf(fp,"This database was moved from...\t %s \t to...\t %s at this time \t %lu \t %s\n\n",
00594 pathToSwapIn.c_str(),currentDir.c_str(),time(0),buffer);
00595 fclose(fp);
00596 }
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 if(activeBackboneGroupName == "")
00628 {
00629 std::cout << __COUT_HDR_FL__ << "No active Backbone table identified." << std::endl;
00630 goto CLEAN_UP;
00631 }
00632
00633 std::cout << "\n\n" << __COUT_HDR_FL__ <<
00634 "Modifying the active Backbone table to reflect new table versions and group keys." <<
00635 std::endl;
00636
00637 {
00638 cfgMgr->loadConfigurationGroup(
00639 activeBackboneGroupName,
00640 activeGroupKeys[activeBackboneGroupName].second,
00641 true,&memberMap,0,&accumulateErrors);
00642
00643
00644
00645
00646 const std::string groupAliasesName = "GroupAliasesConfiguration";
00647 const std::string versionAliasesName = "VersionAliasesConfiguration";
00648
00649
00650 std::map<std::string, ConfigurationVersion> activeMap = cfgMgr->getActiveVersions();
00651
00652
00653 if(activeMap.find(groupAliasesName) != activeMap.end())
00654 {
00655 std::cout << __COUT_HDR_FL__ << "\n\nModifying " << groupAliasesName << std::endl;
00656 config = cfgMgr->getConfigurationByName(groupAliasesName);
00657 cfgView = config->getViewP();
00658
00659 unsigned int col1 = cfgView->findCol("GroupName");
00660 unsigned int col2 = cfgView->findCol("GroupKey");
00661
00662
00663
00664
00665 bool found;
00666 for(unsigned int row = 0; row<cfgView->getNumberOfRows(); ++row )
00667 {
00668 found = false;
00669 for(const auto &group: groupSet)
00670 if(group.second.isInvalid()) continue;
00671 else if(cfgView->getDataView()[row][col1] == group.first.first &&
00672 cfgView->getDataView()[row][col2] == group.first.second.toString())
00673 {
00674
00675 std::cout << __COUT_HDR_FL__ <<
00676 "Changing row " << row << " for " <<
00677 cfgView->getDataView()[row][col1] << " key=" <<
00678 cfgView->getDataView()[row][col2] << " to NEW key=" <<
00679 group.second << std::endl;
00680 cfgView->setValue(
00681 group.second.toString(),
00682 row,col2);
00683 found = true;
00684 break;
00685 }
00686
00687 if(!found)
00688 cfgView->deleteRow(row--);
00689 }
00690
00691 }
00692
00693
00694 if(activeMap.find(versionAliasesName) != activeMap.end())
00695 {
00696 std::cout << __COUT_HDR_FL__ << "\n\nModifying " << versionAliasesName << std::endl;
00697 config = cfgMgr->getConfigurationByName(versionAliasesName);
00698 cfgView = config->getViewP();
00699 unsigned int col1 = cfgView->findCol("ConfigurationName");
00700 unsigned int col2 = cfgView->findCol("Version");
00701
00702
00703 bool found;
00704 for(unsigned int row = 0; row<cfgView->getNumberOfRows(); ++row )
00705 {
00706 found = false;
00707 for(const auto &table:modifiedTables)
00708 if(cfgView->getDataView()[row][col1] == table.first.first &&
00709 cfgView->getDataView()[row][col2] == table.first.second.toString())
00710 {
00711
00712 std::cout << __COUT_HDR_FL__ << "Changing row " << row << " for " <<
00713 cfgView->getDataView()[row][col1] << " version=" <<
00714 cfgView->getDataView()[row][col2] << " to NEW version=" <<
00715 table.second << std::endl;
00716 cfgView->setValue(table.second.toString(),row,col2);
00717 found = true;
00718 break;
00719 }
00720
00721 if(!found)
00722 cfgView->deleteRow(row--);
00723 }
00724 }
00725
00726
00727
00728
00729
00730 std::cout << __COUT_HDR_FL__ << groupAliasesName << ":v" <<
00731 memberMap[groupAliasesName] << std::endl;
00732
00733 config = cfgMgr->getConfigurationByName(groupAliasesName);
00734 cfgView = config->getViewP();
00735 cfgView->setVersion(ConfigurationVersion(flatVersion));
00736 theInterface_->saveActiveVersion(config);
00737
00738 memberMap[groupAliasesName] = flatVersion;
00739
00740 std::cout << __COUT_HDR_FL__ << "\t to...\t" <<
00741 groupAliasesName << ":v" << memberMap[groupAliasesName] << std::endl;
00742
00743
00744
00745 std::cout << __COUT_HDR_FL__ << versionAliasesName << ":v" <<
00746 memberMap[versionAliasesName] << std::endl;
00747
00748 config = cfgMgr->getConfigurationByName(versionAliasesName);
00749 cfgView = config->getViewP();
00750 cfgView->setVersion(ConfigurationVersion(flatVersion));
00751 theInterface_->saveActiveVersion(config);
00752
00753 memberMap[versionAliasesName] = flatVersion;
00754
00755 std::cout << __COUT_HDR_FL__ << "\t to...\t" <<
00756 versionAliasesName << ":v" << memberMap[versionAliasesName] << std::endl;
00757
00758
00759 theInterface_->saveConfigurationGroup(memberMap,
00760 ConfigurationGroupKey::getFullGroupString(
00761 activeBackboneGroupName,
00762 ConfigurationGroupKey(flatVersion)));
00763
00764 activeGroupKeys[activeBackboneGroupName].second =
00765 ConfigurationGroupKey(flatVersion);
00766
00767 std::cout << __COUT_HDR_FL__ << "New to-be-active backbone group " << activeBackboneGroupName <<
00768 ":v" << activeGroupKeys[activeBackboneGroupName].second << std::endl;
00769 }
00770
00771
00772
00773
00774
00775
00776
00777 {
00778 std::cout << "\n\n" << __COUT_HDR_FL__ << "Manipulating the Active Groups file..." << std::endl;
00779
00780
00781 FILE *fp = fopen(ConfigurationManager::ACTIVE_GROUP_FILENAME.c_str(),"r");
00782 if(!fp)
00783 {
00784 __SS__ << "Original active groups file '" << ConfigurationManager::ACTIVE_GROUP_FILENAME
00785 << "' not found." << std::endl;
00786 goto CLEAN_UP;
00787 }
00788
00789 std::cout << __COUT_HDR_FL__ << "Backing up file: " << ConfigurationManager::ACTIVE_GROUP_FILENAME
00790 << std::endl;
00791
00792 fclose(fp);
00793
00794 std::string renameFile = ConfigurationManager::ACTIVE_GROUP_FILENAME + "." + nowTime;
00795 rename(ConfigurationManager::ACTIVE_GROUP_FILENAME.c_str(),
00796 renameFile.c_str());
00797
00798 std::cout << __COUT_HDR_FL__ << "Backup file name: " << renameFile
00799 << std::endl;
00800
00801 ConfigurationGroupKey *theConfigurationGroupKey_, *theContextGroupKey_, *theBackboneGroupKey_, *theIterateGroupKey_;
00802 std::string theConfigurationGroup_, theContextGroup_, theBackboneGroup_, theIterateGroup_;
00803
00804 theConfigurationGroup_ = activeConfigGroupName;
00805 theConfigurationGroupKey_ = &(activeGroupKeys[activeConfigGroupName].second);
00806
00807 theContextGroup_ = activeContextGroupName;
00808 theContextGroupKey_ = &(activeGroupKeys[activeContextGroupName].second);
00809
00810 theBackboneGroup_ = activeBackboneGroupName;
00811 theBackboneGroupKey_ = &(activeGroupKeys[activeBackboneGroupName].second);
00812
00813 theIterateGroup_ = activeIterateGroupName;
00814 theIterateGroupKey_ = &(activeGroupKeys[activeIterateGroupName].second);
00815
00816
00817
00818 {
00819 std::cout << __COUT_HDR_FL__ << "Updating persistent active groups to " <<
00820 ConfigurationManager::ACTIVE_GROUP_FILENAME << " ..." << std::endl;
00821
00822 std::string fn = ConfigurationManager::ACTIVE_GROUP_FILENAME;
00823 FILE *fp = fopen(fn.c_str(),"w");
00824 if(!fp) return;
00825
00826 fprintf(fp,"%s\n",theContextGroup_.c_str());
00827 fprintf(fp,"%s\n",theContextGroupKey_?theContextGroupKey_->toString().c_str():"-1");
00828 fprintf(fp,"%s\n",theBackboneGroup_.c_str());
00829 fprintf(fp,"%s\n",theBackboneGroupKey_?theBackboneGroupKey_->toString().c_str():"-1");
00830 fprintf(fp,"%s\n",theConfigurationGroup_.c_str());
00831 fprintf(fp,"%s\n",theConfigurationGroupKey_?theConfigurationGroupKey_->toString().c_str():"-1");
00832 fprintf(fp,"%s\n",theIterateGroup_.c_str());
00833 fprintf(fp,"%s\n",theIterateGroupKey_?theIterateGroupKey_->toString().c_str():"-1");
00834 fclose(fp);
00835 }
00836 }
00837
00838
00839
00840 std::cout << "\n\n" << __COUT_HDR_FL__ << "Resulting Groups:" << std::endl;
00841 for(const auto &group: groupSet)
00842 std::cout << __COUT_HDR_FL__ << "\t" << group.first.first << ": " <<
00843 group.first.second << " => " << group.second << std::endl;
00844 std::cout << "\n\n" << __COUT_HDR_FL__ << "Resulting Groups end." << std::endl;
00845
00846
00847
00848
00849 std::cout << "\n\n" << __COUT_HDR_FL__ << "Resulting Active Groups:" << std::endl;
00850 for(const auto &activeGroup: activeGroupKeys)
00851 std::cout << __COUT_HDR_FL__ << "\t" << activeGroup.first << ": " <<
00852 activeGroup.second.first << " => " << activeGroup.second.second << std::endl;
00853
00854 std::cout << __COUT_HDR_FL__ << activeBackboneGroupName << " is the " <<
00855 ConfigurationManager::ACTIVE_GROUP_NAME_BACKBONE << "." << std::endl;
00856 std::cout << "\n\n" << __COUT_HDR_FL__ << "Resulting Active Groups end." << std::endl;
00857
00858
00859 CLEAN_UP:
00860
00861 std::cout << "\n\n" << __COUT_HDR_FL__ << "End of Flattening Active Configuration Groups!\n\n\n" << std::endl;
00862
00863
00864
00865 std::cout << __COUT_HDR_FL__ << "****************************" << std::endl;
00866 std::cout << __COUT_HDR_FL__ << "There were " << groupSet.size() <<
00867 " groups considered, and there were errors handling " << groupErrors.size() <<
00868 " of those groups." << std::endl;
00869 std::cout << __COUT_HDR_FL__ << "The following errors were found handling the groups:" << std::endl;
00870 for(auto& groupErr:groupErrors)
00871 std::cout << __COUT_HDR_FL__ << "\t" << groupErr.first.first << " " << groupErr.first.second <<
00872 ": \t" << groupErr.second << std::endl;
00873 std::cout << __COUT_HDR_FL__ << "End of errors.\n\n" << std::endl;
00874
00875
00876 std::cout << __COUT_HDR_FL__ << "Run the following to return to your previous database structure:" <<
00877 std::endl;
00878 std::cout << __COUT_HDR_FL__ << "\t otsdaq_flatten_system_aliases -1 " << moveToDir <<
00879 "\n\n" << std::endl;
00880
00881
00882 return;
00883 }
00884
00885 int main(int argc, char* argv[])
00886 {
00887 FlattenActiveSystemAliasConfigurationGroups(argc,argv);
00888 return 0;
00889 }
00890
00891
00892