FclRunDataTool_tool.cc
Go to the documentation of this file.
1 // FclRunDataTool_tool.cc
2 
3 #include "FclRunDataTool.h"
7 #include "TString.h"
8 #include "TSystem.h"
9 #include <iostream>
10 
11 using std::cout;
12 using std::endl;
13 using std::string;
14 
15 //**********************************************************************
16 
17 namespace {
18 
20 using Index = RunData::Index;
22 
23 int parseFcl(string path, string fclname, RunData& rdat) {
24  TString ts(fclname.c_str());
25  gSystem->FindFile(path.c_str(), ts);
26  string pfname = ts.Data();
27  if ( pfname.size() == 0 ) return 1;
28  cet::filepath_maker policy;
29  auto ps = fhicl::ParameterSet::make(fhicl::parse_document(pfname, policy));
30  ps.get_if_present<Index>("run", rdat.accessRun());
31  ps.get_if_present<string>("cryostat", rdat.accessCryostat());
32  ps.get_if_present<IndexVector>("apas", rdat.accessApas());
33  ps.get_if_present<float>("gain", rdat.accessGain());
34  ps.get_if_present<float>("shaping", rdat.accessShaping());
35  ps.get_if_present<float>("baseline", rdat.accessBaseline());
36  ps.get_if_present<float>("leakage", rdat.accessLeakage());
37  ps.get_if_present<float>("hvfrac", rdat.accessHvfrac());
38  ps.get_if_present<Index>("pulserAmplitude", rdat.accessPulserAmplitude());
39  ps.get_if_present<Index>("pulserSource", rdat.accessPulserSource());
40  ps.get_if_present<Index>("pulserPeriod", rdat.accessPulserPeriod());
41  ps.get_if_present<Name>("phaseGroup", rdat.accessPhaseGroup());
42  ps.get_if_present<IndexVector>("phases", rdat.accessPhases());
43  return 0;
44 }
45 
46 } // end unnamed namespace
47 
48 //**********************************************************************
49 
51 : m_LogLevel(ps.get<Index>("LogLevel")),
52  m_FileNames(ps.get<NameVector>("FileNames")) {
53  const Name myname = "FclRunDataTool::ctor: ";
54  m_fclPath = gSystem->Getenv("FHICL_FILE_PATH");
55  if ( m_LogLevel ) {
56  cout << myname << "Configuration:" << endl;
57  cout << myname << " LogLevel: " << m_LogLevel << endl;
58  cout << myname << " FileNames: ";
59  if ( m_FileNames.size() == 0 ) {
60  cout << "<empty>";
61  }
62  for ( Name fname : m_FileNames ) {
63  cout << "\n" << myname << " " << fname;
64  }
65  cout << endl;
66  }
67 }
68 
69 //**********************************************************************
70 
72  const Name myname = "FclRunDataTool::runData: ";
73  RunData rdat;
74  bool useSubRun = subRun;
75  if ( m_LogLevel >= 2 ) {
76  cout << myname << "Fetching tool for run " << run;
77  if ( useSubRun ) cout << ", subrun " << subRun;
78  cout << endl;
79  }
80  for ( Name fname : m_FileNames ) {
81  StringManipulator sman(fname, false);
82  sman.replaceFixedWidth("%RUN%", run, 6);
83  sman.replaceFixedWidth("%SUBRUN%", subRun, 6);
84  if ( parseFcl(m_fclPath, fname, rdat) ) {
85  if ( m_LogLevel >= 3 ) cout << myname << "Unable to find/read " << fname << endl;
86  } else {
87  if ( m_LogLevel >= 3 ) cout << myname << " Read " << fname << endl;
88  }
89  }
90  return rdat;
91 }
92 
93 //**********************************************************************
94 
std::vector< Index > IndexVector
RunData runData(Index run, Index subRun) const override
#define DEFINE_ART_CLASS_TOOL(tool)
Definition: ToolMacros.h:42
std::string string
Definition: nybbler.cc:12
static ParameterSet make(intermediate_table const &tbl)
Definition: ParameterSet.cc:68
float & accessGain()
Definition: RunData.h:158
ChannelGroupService::Name Name
float & accessBaseline()
Definition: RunData.h:160
float & accessLeakage()
Definition: RunData.h:161
NameVector m_FileNames
unsigned int Index
FclRunDataTool(fhicl::ParameterSet const &ps)
IndexVector & accessPhases()
Definition: RunData.h:167
IndexVector & accessApas()
Definition: RunData.h:157
Name & accessPhaseGroup()
Definition: RunData.h:166
Name & accessCryostat()
Definition: RunData.h:156
std::vector< Name > NameVector
std::vector< Index > IndexVector
Definition: RunData.h:27
unsigned int Index
Definition: RunDataTool.h:14
static constexpr double ps
Definition: Units.h:99
Index & accessPulserAmplitude()
Definition: RunData.h:163
Index & accessPulserSource()
Definition: RunData.h:164
float & accessHvfrac()
Definition: RunData.h:162
intermediate_table parse_document(std::string const &filename, cet::filepath_maker &maker)
Definition: parse.cc:720
int replaceFixedWidth(std::string substr, const T &xsub, Index width)
float & accessShaping()
Definition: RunData.h:159
Index & accessPulserPeriod()
Definition: RunData.h:165
std::string Name
auto const & get(AssnsNode< L, R, D > const &r)
Definition: AssnsNode.h:115
unsigned int Index
Definition: RunData.h:26
QTextStream & endl(QTextStream &s)
Index & accessRun()
Definition: RunData.h:155