4 #include <boost/regex.hpp>
9 #include "travex/utils.h"
17 tvx::ProgramOptions(argc, argv),
22 fStiTChain(new TChain(stiTreeName.c_str(),
"READ"))
25 fOptions.add_options()
26 (
"geom-file", po::value<std::string>(&
fGeomFilePath)->default_value(
"y2014a.root"),
"Full path to a ROOT file with TGeo geometry")
27 (
"volume-pattern,p", po::value<std::string>(&
fVolumePattern)->implicit_value(
"process_all_volumes"),
28 "A regex pattern to match Sti/TGeo volume names. If specified without a value all volumes will be matched")
29 (
"volume-pattern-flist,l", po::value<std::string>(&
fVolumeListFile),
"Full path to a text file with regex patterns to match Sti/TGeo volume names")
33 fVolumeList.insert(
"^.*IDSM_1/PXMO_1/PXLA_[\\d]+/LADR_\\d/PXSI_[\\d]+/PLAC_1.*$");
34 fVolumeList.insert(
"^.*IDSM_1/IBMO_1/IBAM_[\\d]+/IBLM_\\d/IBSS_1.*$");
35 fVolumeList.insert(
"^.*IDSM_1/SFMO_1/SFLM_[\\d]+/SFSW_[\\d]+/SFSL_1/SFSD_1.*$");
52 po::store(po::parse_command_line(fArgc, fArgv, fOptions), fOptionsValues);
53 po::notify(fOptionsValues);
64 TVX_INFO(
"User provided options:");
66 tvx::ProgramOptions::VerifyOptions();
68 if (fOptionsValues.count(
"geom-file"))
70 std::string pathToGeomFile = boost::any_cast<std::string>(fOptionsValues[
"geom-file"].value());
71 std::cout <<
"File with TGeo geometry: " << pathToGeomFile << std::endl;
73 if ( !std::ifstream(pathToGeomFile.c_str()).good() )
74 TVX_FATAL(
"File \"%s\" does not exist", pathToGeomFile.c_str());
76 TVX_FATAL(
"Geometry file not set");
79 if (fOptionsValues.count(
"volume-pattern-flist"))
84 if (!volListFile.good()) {
91 while ( volListFile.good() )
93 volListFile >> pattern;
96 boost::regex re(pattern);
98 catch (boost::regex_error& e) {
99 TVX_FATAL(
"Provided regex \"%s\" is not valid", pattern.c_str());
102 if (volListFile.eof())
break;
107 TVX_INFO(
"User patterns (fVolumeList) are:");
110 TVX_INFO(
"Default patterns (fVolumeList) are:");
115 if (fOptionsValues.count(
"volume-pattern"))
126 catch (boost::regex_error& e) {
127 TVX_FATAL(
"Provided regex \"%s\" is not valid",
fVolumePattern.c_str());
134 TVX_INFO(
"User patterns (fVolumeList) are:");
149 std::set<std::string>::const_iterator iPattern =
fVolumeList.begin();
153 boost::regex r(*iPattern);
155 if ( boost::regex_match(volName, r) )
165 TFile file( fInFilePath.c_str() );
167 if ( file.IsZombie() )
169 TVX_WARNING(
"Input file is not a root file: %s\nWill treat it as a file list", fInFilePath.c_str());
171 std::ifstream treeListFile(fInFilePath.c_str());
173 while ( treeListFile.good() )
175 std::string treeFileName;
176 treeListFile >> treeFileName;
177 if (treeListFile.eof())
break;
183 TVX_INFO(
"Found root file: %s", fInFilePath.c_str());
197 TFile file( stiTreeRootFileName.c_str() );
199 if ( file.IsZombie() )
200 TVX_FATAL(
"Input file is not a valid root file: %s", stiTreeRootFileName.c_str());
202 fStiTChain->AddFile( stiTreeRootFileName.c_str() );
203 TVX_INFO(
"Found valid ROOT file with Sti tree: %s", stiTreeRootFileName.c_str());
Processes and controls user options provided in the command line.
TChain * fStiTChain
A (chained) TTree from the input file.
virtual void AddToInputChains(std::string stiTreeRootFileName)
This private method takes a path to a valid ROOT file as input.
std::string fGeomFilePath
Full path to a ROOT file with TGeo geometry.
std::set< std::string > fVolumeList
A list of volume names to consider.
virtual void VerifyOptions()
bool MatchedVolName(const std::string &volName) const
Note that the function returns true when the internal list of regex'es formed by the user specified o...
void ProcessOptions()
Takes the standard command line arguments and parses them with the boost program_options utility...
std::string fVolumeListFile
Full path to a text file with Sti/TGeo volume names.
std::string fVolumePattern
Regex pattern provided by the user in the command line.