1313// /
1414// / \author Kostas Alexopoulos ([email protected] )1515
16+ #include < fstream>
1617#include < iostream>
1718#include " CommandLineUtilities/Options.h"
1819#include " CommandLineUtilities/Program.h"
@@ -91,6 +92,9 @@ class ProgramConfig : public Program
9192 options.add_options ()(" trigger-window-size" ,
9293 po::value<uint32_t >(&mOptions .triggerWindowSize ),
9394 " Flag to set the size of the trigger window in GBT words" );
95+ options.add_options ()(" gen-cfg-file" ,
96+ po::value<std::string>(&mOptions .genConfigFile ),
97+ " If set generates a configuration file from the command line options. [DOES NOT CONFIGURE]" );
9498 Options::addOptionCardId (options);
9599 }
96100
@@ -134,7 +138,6 @@ class ProgramConfig : public Program
134138 }
135139
136140 if (mOptions .configUri == " " ) {
137- std::cout << " Configuring with command line arguments" << std::endl;
138141 auto params = Parameters::makeParameters (cardId, 2 );
139142 params.setLinkMask (Parameters::linkMaskFromString (mOptions .links ));
140143 params.setAllowRejection (mOptions .allowRejection );
@@ -150,6 +153,40 @@ class ProgramConfig : public Program
150153 params.setOnuAddress (mOptions .onuAddress );
151154 params.setTriggerWindowSize (mOptions .triggerWindowSize );
152155
156+ // Generate a configuration file base on the parameters provided
157+ if (mOptions .genConfigFile != " " ) {
158+ std::cout << " Generating a configuration file at: " << mOptions .genConfigFile << std::endl;
159+ std::ofstream cfgFile;
160+ cfgFile.open (mOptions .genConfigFile );
161+
162+ cfgFile << " [cru]\n " ;
163+ cfgFile << " allowRejection=" << std::boolalpha << mOptions .allowRejection << " \n " ;
164+ cfgFile << " clock=" << mOptions .clock << " \n " ;
165+ cfgFile << " cruId=" << mOptions .cruId << " \n " ;
166+ cfgFile << " datapathMode=" << mOptions .datapathMode << " \n " ;
167+ cfgFile << " loopback=" << std::boolalpha << mOptions .linkLoopbackEnabled << " \n " ;
168+ cfgFile << " gbtMode=" << mOptions .gbtMode << " \n " ;
169+ cfgFile << " downstreamData=" << mOptions .downstreamData << " \n " ;
170+ cfgFile << " ponUpstream=" << std::boolalpha << mOptions .ponUpstreamEnabled << " \n " ;
171+ cfgFile << " onuAddress=" << mOptions .onuAddress << " \n " ;
172+ cfgFile << " dynamicOffset=" << std::boolalpha << mOptions .dynamicOffsetEnabled << " \n " ;
173+ cfgFile << " triggerWindowSize=" << mOptions .triggerWindowSize << " \n " ;
174+
175+ cfgFile << " [links]\n " ;
176+ cfgFile << " enabled=false\n " ;
177+ cfgFile << " gbtMux=TTC\n " ;
178+
179+ for (const auto & link : params.getLinkMaskRequired ()) {
180+ cfgFile << " [link" << link << " ]\n " ;
181+ cfgFile << " enabled=true\n " ;
182+ cfgFile << " gbtMux=" << mOptions .gbtMux << " \n " ;
183+ }
184+
185+ cfgFile.close ();
186+ return ;
187+ }
188+
189+ std::cout << " Configuring with command line arguments" << std::endl;
153190 try {
154191 CardConfigurator (params, mOptions .forceConfig );
155192 } catch (const Exception& e) {
@@ -173,6 +210,7 @@ class ProgramConfig : public Program
173210 std::string downstreamData = " Ctp" ;
174211 std::string gbtMode = " gbt" ;
175212 std::string gbtMux = " ttc" ;
213+ std::string genConfigFile = " " ;
176214 std::string links = " 0" ;
177215 bool allowRejection = false ;
178216 bool bypassFirmwareCheck = false ;
0 commit comments