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()) {
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();
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;
199 imageUtils.SetPixelMapSize(fPMap_fNWire,fPMap_fNTdc);
201 std::vector<unsigned char> pixelArray(nViews *
config.fPlaneLimit *
config.fTDCLimit,0);
203 imageUtils.SetLogScale(
config.fSetLog);
204 imageUtils.SetViewReversal(
config.fReverseViews);
205 imageUtils.ConvertChargeVectorsToPixelArray(fPMap_fPEX, fPMap_fPEY, fPMap_fPEZ, pixelArray);
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;
def mkdir(path, mode=0o777)
int errno
Contains the last error code.
Class containing some utility functions for all things CVN.
std::string to_string(ModuleType const mt)
QTextStream & endl(QTextStream &s)