FclFileFloatArray_tool.cc
Go to the documentation of this file.
1 // FclFileFloatArray_tool.cc
2 
3 #include "FclFileFloatArray.h"
7 #include <iostream>
8 #include "TSystem.h"
9 
10 using std::cout;
11 using std::endl;
12 
13 //**********************************************************************
14 
16 : m_LogLevel(ps.get<Index>("LogLevel")),
17  m_FileNames(ps.get<NameVector>("FileNames")),
18  m_DefaultValue(ps.get<float>("DefaultValue")) {
19  const Name myname = "FclFileFloatArray::ctor: ";
20  if ( m_LogLevel ) {
21  cout << "Configuration:" << endl;
22  cout << " LogLevel: " << m_LogLevel << endl;
23  cout << " FileNames: ";
24  if ( m_FileNames.size() == 0 ) {
25  cout << "<empty>";
26  }
27  for ( Name fname : m_FileNames ) {
28  cout << "\n " << fname;
29  }
30  cout << endl;
31  cout << " DefaultValue: " << m_DefaultValue << endl;
32  }
33  init();
34 }
35 
36 //**********************************************************************
37 
39  const Name myname = "FclFileFloatArray::init: ";
40  bool first = true;
41  Name fclPath = gSystem->Getenv("FHICL_FILE_PATH");
42  for ( Name fname : m_FileNames ) {
43  TString ts(fname.c_str());
44  gSystem->FindFile(fclPath.c_str(), ts);
45  Name pfname = ts.Data();
46  if ( pfname.size() == 0 ) {
47  cout << myname << "WARNING: Unable to find file " << fname << endl;
48  continue;
49  }
50  cet::filepath_maker policy;
51  auto ps = fhicl::ParameterSet::make(fhicl::parse_document(pfname, policy));
52  auto pfat = art::make_tool<FloatArrayTool>(ps);
53  if ( m_LogLevel >= 2 ) cout << myname << "Reading tool " << pfat->label() << endl;
54  if ( first ) {
55  m_unit = pfat->unit();
56  first = false;
57  } else {
58  if ( pfat->unit() != unit() ) {
59  cout << myname << "WARNING: Inconsistent units: " << pfat->unit() << " != " << m_unit << endl;
60  cout << myname << "Skipping tool at " << fname << endl;
61  continue;
62  }
63  }
64  pfat->fill(m_vals, defaultValue());
65  }
66 }
67 
68 //**********************************************************************
69 
#define DEFINE_ART_CLASS_TOOL(tool)
Definition: ToolMacros.h:42
Name unit() const override
static ParameterSet make(intermediate_table const &tbl)
Definition: ParameterSet.cc:68
int fill() const
Definition: qtextstream.h:253
static constexpr double ps
Definition: Units.h:99
FclFileFloatArray(fhicl::ParameterSet const &ps)
intermediate_table parse_document(std::string const &filename, cet::filepath_maker &maker)
Definition: parse.cc:720
float defaultValue() const override
auto const & get(AssnsNode< L, R, D > const &r)
Definition: AssnsNode.h:115
std::vector< Name > NameVector
unsigned int Index
QTextStream & endl(QTextStream &s)