Jpp  18.2.1-ARCA-DF-PATCH
the software that should make you happy
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Functions
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

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 }
Auxiliary class for ROOT I/O of application specific meta data.
Definition: JMeta.hh:70
Utility class to parse command line options.
Definition: JParser.hh:1514
TString replace(const TString &target, const TRegexp &regexp, const T &replacement)
Replace regular expression in input by given replacement.
Definition: JPrintResult.cc:63
#define STATUS(A)
Definition: JMessage.hh:63
then echo Enter input within $TIMEOUT_S seconds echo n User name
Definition: JCookie.sh:42
string outputFile
#define MAKE_STRING(A)
Make string.
Definition: JPrint.hh:127
std::ostream & separator(std::ostream &out)
Print separator.
#define make_field(A,...)
macro to convert parameter to JParserTemplateElement object
Definition: JParser.hh:1989
#define NOTICE(A)
Definition: JMessage.hh:64
then awk string
#define FATAL(A)
Definition: JMessage.hh:67
Auxiliary base class for list of file names.
then usage $script< input file >[option[primary[working directory]]] nWhere option can be N
Definition: JMuonPostfit.sh:40
std::vector< filescanner_type >::iterator iterator
std::string getFilename(const std::string &file_name)
Get file name part, i.e. part after last JEEP::PATHNAME_SEPARATOR if any.
Definition: JeepToolkit.hh:128
Auxiliary class for organising Monte Carlo file scanners associated with event weighters.
int debug
debug level
#define DEBUG(A)
Message macros.
Definition: JMessage.hh:62