15 #include "boost/program_options/options_description.hpp" 16 #include "boost/program_options/variables_map.hpp" 17 #include "boost/program_options/parsers.hpp" 18 #include "boost/algorithm/string/predicate.hpp" 36 namespace po = boost::program_options;
75 TChain chain(config.fTreeName.c_str());
77 if (boost::ends_with(input,
".list")) {
78 std::ifstream list_file(input.c_str());
79 if (!list_file.is_open()) {
80 std::cout <<
"Could not open " << input <<
std::endl;
85 while (list_file>>ifname)
86 chain.Add(ifname.c_str());
90 else if (boost::ends_with(input,
".root")) {
91 chain.Add(input.c_str());
94 chain.SetMakeClass(1);
99 std::vector<float> fPMap_fPEX;
100 std::vector<float> fPMap_fPEY;
101 std::vector<float> fPMap_fPEZ;
103 chain.SetBranchAddress(
"fInt", &fInt);
104 chain.SetBranchAddress(
"fPMap.fNWire", &fPMap_fNWire);
105 chain.SetBranchAddress(
"fPMap.fNTdc", &fPMap_fNTdc);
106 chain.SetBranchAddress(
"fPMap.fPEX", &fPMap_fPEX);
107 chain.SetBranchAddress(
"fPMap.fPEY", &fPMap_fPEY);
108 chain.SetBranchAddress(
"fPMap.fPEZ", &fPMap_fPEZ);
122 int fTopologyType = -1;
123 int fTopologyTypeAlt = -1;
125 chain.SetBranchAddress(
"fNuEnergy", &fNuEnergy);
126 chain.SetBranchAddress(
"fLepEnergy", &fLepEnergy);
127 chain.SetBranchAddress(
"fRecoNueEnergy", &fRecoNueEnergy);
128 chain.SetBranchAddress(
"fRecoNumuEnergy", &fRecoNumuEnergy);
129 chain.SetBranchAddress(
"fEventWeight", &fEventWeight);
131 chain.SetBranchAddress(
"fNuPDG", &fNuPDG);
132 chain.SetBranchAddress(
"fNProton", &fNProton);
133 chain.SetBranchAddress(
"fNPion", &fNPion);
134 chain.SetBranchAddress(
"fNPizero", &fNPizero);
135 chain.SetBranchAddress(
"fNNeutron", &fNNeutron);
137 chain.SetBranchAddress(
"fTopologyType", &fTopologyType);
138 chain.SetBranchAddress(
"fTopologyTypeAlt", &fTopologyTypeAlt);
140 unsigned int entries = chain.GetEntries();
141 if(config.fNEvents < entries){
142 entries = config.fNEvents;
145 std::cout <<
"Error: Input tree has no entries." <<
std::endl;
149 std::cout <<
"- Will process " << entries <<
" from the input tree." <<
std::endl;
151 std::srand (
unsigned ( std::time(0) ) );
152 std::vector<unsigned int> shuffled;
153 for (
unsigned int i = 0; i < entries; ++i)
155 shuffled.push_back(i);
158 if(entries > chain.GetEntries()){
159 entries = chain.GetEntries();
162 std::string image_path = config.fOutputDir +
"/images/";
163 std::string info_path = config.fOutputDir +
"/info/";
166 if (
mkdir(image_path.data(), S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH) == -1)
168 if(
errno == EEXIST ) {
172 std::cout <<
"cannot create folder error:" << strerror(
errno) <<
std::endl;
177 if (
mkdir(info_path.data(), S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH) == -1)
179 if(
errno == EEXIST ) {
183 std::cout <<
"cannot create folder error:" << strerror(
errno) <<
std::endl;
188 for(
unsigned int iEntry = 0; iEntry < entries; ++iEntry)
190 unsigned int entry = shuffled[iEntry];
191 chain.GetEntry(entry);
193 unsigned int nViews = 3;
201 std::vector<unsigned char> pixelArray(nViews * config.fPlaneLimit * config.fTDCLimit,0);
212 std::cout <<
"[DEBUG] entry " << entry+1 <<
" out of " << entries <<
std::endl;
213 std::cout <<
"[DEBUG] file: " << chain.GetCurrentFile()->GetName() <<
std::endl;
219 std::cout <<
"[DEBUG] label: " << fInt <<
std::endl;
220 unsigned long srcLen = nViews * config.fPlaneLimit * config.fTDCLimit;
221 unsigned long destLen = compressBound(srcLen);
222 char* ostream = (
char *) malloc(destLen);
224 int res = compress((Bytef *) ostream, &destLen, (Bytef *) &pixelArray[0], srcLen);
232 if(res == Z_BUF_ERROR){
233 std::cout <<
"[DEBUG] Buffer was too small!" <<
std::endl;
238 else if(res == Z_MEM_ERROR){
239 std::cout <<
"[DEBUG] Not enough memory for compression!" <<
std::endl;
245 std::cout <<
"[DEBUG] Compression successful" <<
std::endl;
254 std::ofstream image_file (image_file_name, std::ofstream::binary);
255 std::ofstream info_file (info_file_name);
257 if(image_file.is_open() && info_file.is_open()){
261 image_file.write(ostream, destLen);
275 info_file << fRecoNueEnergy <<
std::endl;
276 info_file << fRecoNumuEnergy <<
std::endl;
288 info_file << fTopologyTypeAlt;
292 std::cout <<
"[DEBUG] Done" <<
std::endl;
298 if(image_file.is_open()){
302 std::cout <<
"[DEBUG] Unable to open file: " << image_file_name <<
std::endl;
305 if(info_file.is_open()){
309 std::cout <<
"[DEBUG] Unable to open file: " << info_file_name <<
std::endl;
327 po::options_description
desc(
"Allowed options");
329 (
"help",
"produce help message")
330 (
"config,c", po::value<std::string>(&config)->required(),
331 "configuration file")
332 (
"input,i", po::value<std::string>(&input)->required(),
333 "Input data in ROOT file.");
334 po::variables_map vm;
338 po::store(po::parse_command_line(argc, argv, desc), vm);
344 std::cout <<
"ERROR: " << e.what() <<
std::endl;
349 if (vm.count(
"help")) {
350 std::cout << desc <<
"\n";
368 std::string configPath, inputPath, outputPath, logPath;
369 po::variables_map vm =
getOptions(argc, argv, configPath, inputPath);
374 fill(config, inputPath);
void fill(const Config &config, std::string input)
Config(const fhicl::ParameterSet &pset)
def mkdir(path, mode=0o777)
static ParameterSet make(intermediate_table const &tbl)
void ConvertChargeVectorsToPixelArray(std::vector< float > &v0pe, std::vector< float > &v1pe, std::vector< float > &v2pe, std::vector< unsigned char > &pix)
void SetViewReversal(bool reverseX, bool reverseY, bool reverseZ)
Function to set any views that need reversing.
void SetLogScale(bool setLog)
Set the log scale for charge.
int errno
Contains the last error code.
typename config_impl< T >::type Config
Utilities for producing images for the CVN.
int fTDCLimit
Limit the number of TDCs in the output image.
Class containing some utility functions for all things CVN.
unsigned int fNEvents
Limit the number of entries in the tree to consider.
std::vector< bool > fReverseViews
Views to reverse.
int fPlaneLimit
Limit the number of wires in the output image.
std::string fTrainingBranchObjectName
int main(int argc, char *argv[])
intermediate_table parse_document(std::string const &filename, cet::filepath_maker &maker)
fhicl::ParameterSet getPSet(std::string configPath)
po::variables_map getOptions(int argc, char *argv[], std::string &config, std::string &input)
auto const & get(AssnsNode< L, R, D > const &r)
std::string to_string(ModuleType const mt)
QTextStream & endl(QTextStream &s)
void SetPixelMapSize(unsigned int nWires, unsigned int nTDCs)
Set the input pixel map size.