Jpp master_rocky-44-g75b7c4f75
the software that should make you happy
Loading...
Searching...
No Matches
JSeparateCuts.cc File Reference

Program for extracting disjoint output files without overlapping cuts
from a list of Monte-Carlo files with overlapping cuts. More...

#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <set>
#include <stdio.h>
#include "km3net-dataformat/offline/Head.hh"
#include "km3net-dataformat/offline/Evt.hh"
#include "km3net-dataformat/definitions/trkmembers.hh"
#include "Jeep/JPrint.hh"
#include "Jeep/JParser.hh"
#include "Jeep/JMessage.hh"
#include "Jeep/JeepToolkit.hh"
#include "JLang/JException.hh"
#include "JTools/JRange.hh"
#include "JSupport/JMeta.hh"
#include "JSupport/JSupport.hh"
#include "JSupport/JFileRecorder.hh"
#include "JSupport/JMultipleFileScanner.hh"
#include "JSupport/JEvtWeightFileScanner.hh"
#include "JSupport/JEvtWeightFileScannerSet.hh"
#include "JAAnet/JHead.hh"

Go to the source code of this file.

Functions

int main (int argc, char **argv)
 

Detailed Description

Program for extracting disjoint output files without overlapping cuts
from a list of Monte-Carlo files with overlapping cuts.

Note: Already existing disjoint output files which have been extracted previously will be overwritten.

Author
bjung

Definition in file JSeparateCuts.cc.

Function Documentation

◆ main()

int main ( int argc,
char ** argv )

Definition at line 360 of file JSeparateCuts.cc.

361{
362 using namespace std;
363 using namespace JPP;
364
365 JMultipleFileScanner_t inputFiles;
366 string outputFile;
367 char wildcard;
368 bool replace;
369
370 int debug;
371
372 try {
373
374 JParser<> zap;
375
376 zap['f'] = make_field(inputFiles);
377 zap['o'] = make_field(outputFile) = "%.root";
378 zap['w'] = make_field(wildcard) = '%';
379 zap['r'] = make_field(replace);
380 zap['d'] = make_field(debug) = 1;
381
382 zap(argc, argv);
383 }
384 catch(const exception& error) {
385 FATAL(error.what() << endl);
386 }
387
388 const size_t pos = outputFile.find(wildcard);
389
390 if (pos == string::npos) {
391 FATAL("Valid wildcard must be specified (<" << outputFile << "> does not contain \'" << wildcard << "\').");
392 }
393
394
395 // Create set of files ordered based on header-info
396
397 JEvtWeightFileScannerSet<> scanners(inputFiles);
398
399 // Split files with overlapping cuts into separate files with disjoint cuts.
400
401 set<string> buffer;
402 JSeparateCuts separator(outputFile, wildcard, JMeta(argc, argv));
403
404 for (JEvtWeightFileScannerSet<>::iterator scanner1 = next(scanners.begin()); scanner1 != scanners.end(); ++scanner1) {
405
406 JEvtWeightFileScannerSet<>::iterator scanner0 = prev(scanner1);
407
408 if (scanner0->hasNext() && scanner1->hasNext()) {
409
410 const string identifier = scanners.getUniqueIdentifier(scanner0) + MAKE_STRING(".cut" << wildcard);
411 const string name = string(outputFile).replace(pos, 1, identifier.c_str());
412
413 separator.setFilenameTemplate(name);
414
415 const size_t N = (separator.separate(*scanner0, *scanner1, &JHead::cut_primary) +
416 separator.separate(*scanner0, *scanner1, &JHead::cut_seamuon) +
417 separator.separate(*scanner0, *scanner1, &JHead::cut_in) +
418 separator.separate(*scanner0, *scanner1, &JHead::cut_nu));
419
420 STATUS("\rExtracted " << N << " output files with" <<
421 " disjoint cuts for " << getFilename(scanner0->getFilename()) <<
422 " and " << getFilename(scanner1->getFilename())); DEBUG(endl);
423
424 if (N > 0) {
425
426 buffer.insert(scanner0->getFilename());
427 buffer.insert(scanner1->getFilename());
428 }
429 }
430 }
431
432 for (set<string>::const_iterator i = buffer.begin(); replace && i != buffer.end(); ++i) {
433
434 if (remove(i->c_str()) != 0) {
435 FATAL(endl << "Error removing file " << *i);
436 } else {
437 NOTICE(endl << "Removing file " << *i);
438 }
439 }
440
441 return 0;
442}
string outputFile
#define DEBUG(A)
Message macros.
Definition JMessage.hh:62
#define STATUS(A)
Definition JMessage.hh:63
#define NOTICE(A)
Definition JMessage.hh:64
#define FATAL(A)
Definition JMessage.hh:67
int debug
debug level
Definition JSirene.cc:69
#define make_field(A,...)
macro to convert parameter to JParserTemplateElement object
Definition JParser.hh:2142
#define MAKE_STRING(A)
Make string.
Definition JPrint.hh:63
JAANET::cut_in cut_in
Definition JHead.hh:1595
JAANET::cut_nu cut_nu
Definition JHead.hh:1596
JAANET::cut_seamuon cut_seamuon
Definition JHead.hh:1594
JAANET::cut_primary cut_primary
Definition JHead.hh:1593
Utility class to parse command line options.
Definition JParser.hh:1698
std::string getFilename(const std::string &file_name)
Get file name part, i.e. part after last JEEP::PATHNAME_SEPARATOR if any.
std::ostream & separator(std::ostream &out)
Print separator.
std::string replace(const std::string &input, const std::string &target, const std::string &replacement)
Replace tokens in string.
This name space includes all other name spaces (except KM3NETDAQ, KM3NET and ANTARES).
Auxiliary class for organising Monte Carlo file scanners associated with event weighters.
std::vector< filescanner_type >::iterator iterator
Auxiliary class for ROOT I/O of application specific meta data.
Definition JMeta.hh:72
Auxiliary base class for list of file names.