@@ -67,7 +67,8 @@ PoissonLogLikelihoodWithLinearModelForMean<TargetT>::post_processing()
6767{
6868 if (base_type::post_processing () == true )
6969 return true ;
70-
70+ // call set, which will do some checks
71+ this ->set_subsensitivity_filenames (this ->subsensitivity_filenames );
7172 return false ;
7273}
7374
@@ -85,6 +86,19 @@ PoissonLogLikelihoodWithLinearModelForMean<TargetT>::get_subsensitivity_filename
8586 return this ->subsensitivity_filenames ;
8687}
8788
89+ template <typename TargetT>
90+ std::string
91+ PoissonLogLikelihoodWithLinearModelForMean<TargetT>::get_subsensitivity_filename(const int subset_num) const
92+ {
93+ if (this ->subsensitivity_filenames .empty ())
94+ return this ->subsensitivity_filenames ;
95+
96+ if (this ->subsensitivity_filenames .find (" %" ) != std::string::npos)
97+ return boost::str (boost::format (this ->subsensitivity_filenames ) % subset_num);
98+ else
99+ return runtime_format (this ->subsensitivity_filenames , subset_num);
100+ }
101+
88102template <typename TargetT>
89103void
90104PoissonLogLikelihoodWithLinearModelForMean<TargetT>::set_sensitivity_filename(const std::string& filename)
@@ -101,20 +115,17 @@ PoissonLogLikelihoodWithLinearModelForMean<TargetT>::set_subsensitivity_filename
101115 this ->subsensitivity_filenames = filenames;
102116 try
103117 {
104- if (this ->subsensitivity_filenames .find (" %" ))
118+ if (this ->subsensitivity_filenames .find (" %" ) != std::string::npos )
105119 {
106- warning (" The subsensitivity_filenames pattern is using the boost::format convention ('\ %d')."
120+ warning (" The subsensitivity_filenames pattern is using the boost::format convention ('% %d')."
107121 " It is recommended to use fmt::format/std::format style formatting ('{}')." );
108- const std::string test_sensitivity_filename = boost::str (boost::format (this ->subsensitivity_filenames ) % 0 );
109- }
110- else
111- {
112- const std::string test_sensitivity_filename = runtime_format (this ->subsensitivity_filenames .c_str (), 0 );
113122 }
123+ const std::string test_sensitivity_filename = this ->get_subsensitivity_filename (0 );
114124 }
115125 catch (std::exception& e)
116126 {
117- error (format (" argument {} to set_subsensitivity_filenames is invalid (see fmt::format documentation)\n . Error message: {}" ,
127+ error (format (" argument {} to set_subsensitivity_filenames is invalid (see fmt::format or boost::format documentation)\n . "
128+ " Error message: {}" ,
118129 filenames.c_str (),
119130 e.what ()));
120131 }
@@ -224,35 +235,25 @@ PoissonLogLikelihoodWithLinearModelForMean<TargetT>::set_up(shared_ptr<TargetT>
224235 // read subsensitivies
225236 for (int subset = 0 ; subset < this ->get_num_subsets (); ++subset)
226237 {
227- std::string current_sensitivity_filename;
228- try
238+ const std::string current_sensitivity_filename = this ->get_subsensitivity_filename (subset);
239+
240+ if (subset > 0 )
229241 {
230- if (this ->subsensitivity_filenames .find (" %" ))
231- {
232- warning (" The subsensitivity_filenames pattern is using the boost::format convention ('\%d')."
233- " It is recommended to use fmt::format/std::format style formatting ('{}')." );
234- current_sensitivity_filename = boost::str (boost::format (this ->subsensitivity_filenames ) % subset);
235- }
236- else
242+ if (current_sensitivity_filename == this ->get_subsensitivity_filename (0 ))
237243 {
238- current_sensitivity_filename = runtime_format (this ->subsensitivity_filenames .c_str (), subset);
244+ error (format (
245+ " subset sensitivity filename pattern should lead to a different filename for every subset,"
246+ " but seems to always give '{}'" ,
247+ current_sensitivity_filename));
239248 }
240249 }
241- catch (std::exception& e)
242- {
243- error (format (" Error using 'subset sensitivity filenames' pattern (which is set to '{}'). "
244- " Check syntax for fmt::format. Error is:\n {}" ,
245- this ->subsensitivity_filenames ,
246- e.what ()));
247- return Succeeded::no;
248- }
249250 info (format (" Reading sensitivity from '{}'" , current_sensitivity_filename));
250251
251252 this ->subsensitivity_sptrs [subset] = read_from_file<TargetT>(current_sensitivity_filename);
252253 string explanation;
253254 if (!target_sptr->has_same_characteristics (*this ->subsensitivity_sptrs [subset], explanation))
254255 {
255- error (" sensitivity and target should have the same characteristics.\n %s " , explanation. c_str () );
256+ error (" sensitivity and target should have the same characteristics.\n " + explanation);
256257 return Succeeded::no;
257258 }
258259 }
@@ -321,8 +322,7 @@ PoissonLogLikelihoodWithLinearModelForMean<TargetT>::set_up(shared_ptr<TargetT>
321322 {
322323 for (int subset = 0 ; subset < this ->get_num_subsets (); ++subset)
323324 {
324- const std::string current_sensitivity_filename
325- = runtime_format (this ->subsensitivity_filenames .c_str (), subset);
325+ const std::string current_sensitivity_filename = this ->get_subsensitivity_filename (subset);
326326 info (format (" Writing sensitivity to '{}'" , current_sensitivity_filename));
327327 write_to_file (current_sensitivity_filename, this ->get_subset_sensitivity (subset));
328328 }
0 commit comments