Jpp
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Functions
JMergeDetector.cc File Reference

Auxiliary program to merge detector files. More...

#include <string>
#include <iostream>
#include <iomanip>
#include "JDetector/JDetector.hh"
#include "JDetector/JDetectorToolkit.hh"
#include "JDetector/JLocation.hh"
#include "Jeep/JParser.hh"
#include "Jeep/JMessage.hh"

Go to the source code of this file.

Functions

int main (int argc, char **argv)
 

Detailed Description

Auxiliary program to merge detector files.

If the option

    -N [i] 

is used with a positive number the strings are renumbered starting from i. Each string gets a unique number based on the order of the detector files and its original index in its own detector file.

Author
mdejong

Definition in file JMergeDetector.cc.

Function Documentation

int main ( int  argc,
char **  argv 
)

Definition at line 28 of file JMergeDetector.cc.

29 {
30  using namespace std;
31  using namespace JPP;
32 
33  vector<string> detectorFile;
34  string outputFile;
35  string variant;
36  int debug;
37  int firstStringNr;
38 
39  try {
40 
41  JParser<> zap("Auxiliary program to merge detector files.");
42 
43  zap['a'] = make_field(detectorFile);
44  zap['o'] = make_field(outputFile);
45  zap['V'] = make_field(variant) = "", getDetectorVersions<string>();
46  zap['d'] = make_field(debug) = 1;
47  zap['N'] = make_field(firstStringNr) = -1;
48 
49  zap(argc, argv);
50  }
51  catch(const exception &error) {
52  FATAL(error.what() << endl);
53  }
54 
55 
57 
58  for (vector<string>::const_iterator i = detectorFile.begin(); i != detectorFile.end(); ++i) {
59 
60  JDetector buffer;
61 
62  int highestStringNr = 0;
63 
64  try {
65  load(*i, buffer);
66  }
67  catch(const JException& error) {
68  FATAL(error);
69  }
70 
71  for (JDetector::const_iterator module = buffer.begin(); module != buffer.end(); ++module) {
72 
73  detector.push_back(*module);
74 
75  // optionally change string number
76  if (firstStringNr > 0) {
77 
78  if( module->getLocation().getString() > highestStringNr ) {
79  highestStringNr = module->getLocation().getString();
80  }
81 
82  const int newStringNr = firstStringNr + module->getLocation().getString() - 1;
83 
84  detector.back().setLocation(JLocation(newStringNr, module->getLocation().getFloor()));
85  }
86  }
87 
88  // increase firstStringNr to ensure all new string numbers are unique
89  if (firstStringNr > 0) {
90  firstStringNr += highestStringNr;
91  }
92 
93  } // end of loop over detector files
94 
95  if (variant != "") {
96  detector.setVersion(variant);
97  }
98 
99  try {
101  }
102  catch(const JException& error) {
103  FATAL(error);
104  }
105 }
Utility class to parse command line options.
Definition: JParser.hh:1493
General exception.
Definition: JException.hh:23
Detector data structure.
Definition: JDetector.hh:80
string outputFile
Detector file.
Definition: JHead.hh:130
Logical location of module.
Definition: JLocation.hh:37
#define make_field(A,...)
macro to convert parameter to JParserTemplateElement object
Definition: JParser.hh:1954
void load(const JString &file_name, JDetector &detector)
Load detector from input file.
int debug
debug level
Definition: JSirene.cc:61
#define FATAL(A)
Definition: JMessage.hh:67
void store(const JString &file_name, const JDetector &detector)
Store detector to output file.