parseFCLMetadata.cxx
Go to the documentation of this file.
1 ////////////////////////////////////////////////////////////////////////
2 /// \brief Class for parsing *.fcl files for their metadata information
3 /// \author Adam Aurisano - aurisaam@uc.edu
4 ////////////////////////////////////////////////////////////////////////
5 
6 #include <algorithm>
7 #include <cstdlib>
8 #include <fstream>
9 #include <iostream>
10 #include <iomanip>
11 #include <iterator>
12 #include <map>
13 #include <string>
14 #include <vector>
15 
16 #include "cetlib/filepath_maker.h"
19 #include "fhiclcpp/ParameterSet.h"
20 
21 #include "MetadataManager.h"
22 
23 namespace meta {
24 
25  class MetadataParse {
26 
27  public:
29 
30  void PrintMetadata();
31 
32  };
33 }
34 
35 namespace meta {
36 
37  //.................................................................
39  {
41 
42  char const* fhiclEnv = getenv("FHICL_FILE_PATH");
43  std::string searchPath;
44  if(*fhiclEnv == '\0'){
45  std::cerr << "FHICL_FILE_PATH is empty\n";
46  abort();
47  }
48  else searchPath = std::string(fhiclEnv) + ":";
49 
51  // parse a configuration file; obtain intermediate form
53  fhicl::parse_document(infile, policy, tbl);
54 
55  // convert to ParameterSet
57  fhicl::make_ParameterSet(tbl, pset);
58 
59  //fetch the appropriate sub-pset and pass to the manager
60  fhicl::ParameterSet metaPSet;
61  bool foundPSet = pset.get_if_present<fhicl::ParameterSet>("physics.analyzers.metadata.params", metaPSet);
62  if(foundPSet) fManager.DoParsing(metaPSet);
63  }
64 
65  //..................................................................
67  {
69 
70  std::map<std::string, std::string> metamap = fManager.GetMetadata();
71 
72  std::cout << "{" << std::endl;
73  std::cout << " \"file_type\": \"mc_config\" " << std::endl;
74  std::cout << ",\"file_format\": \"fcl\" " << std::endl;
75 
76  for(auto& it: metamap){
77  std::string key = it.first;
78  std::string value = it.second;
79 
80  // Exclude base_release type entries from fcl metadata
81  size_t found = key.find("base_release");
82  if(found != std::string::npos) continue;
83 
84  std::cout << ",\"" << key
85  << "\":" << " "
86  << "\"" << value
87  << "\"" << std::endl;
88  }
89  std::cout << "}" << std::endl;
90  }
91 
92 } // end namespace meta
93 
94 //...................................................................
95 int main(int argc, char *argv[])
96 {
97  if(argc != 2) return 1;
98 
99  std::string infile = argv[1];
100  meta::MetadataParse parser(infile);
101  parser.PrintMetadata();
102 
103  return 0;
104 }
105 ///////////////////////////////////////////////////////////////////
int main(int argc, char *argv[])
static MetadataManager & getInstance()
set< int >::iterator it
OStream cerr
Definition: OStream.cxx:7
std::map< std::string, std::string > & GetMetadata()
void make_ParameterSet(intermediate_table const &tbl, ParameterSet &ps)
string infile
const XML_Char int const XML_Char * value
Definition: expat.h:331
std::string getenv(std::string const &name)
Class for parsing *.fcl files for their metadata information.
bool get_if_present(std::string const &key, T &value) const
Definition: ParameterSet.h:208
OStream cout
Definition: OStream.cxx:6
MetadataParse(std::string infile)
void DoParsing(fhicl::ParameterSet const &pset)
void parse_document(std::string const &filename, cet::filepath_maker &maker, intermediate_table &result)
enum BeamMode string