Jpp
JMergeDetector.cc
Go to the documentation of this file.
1 #include <string>
2 #include <iostream>
3 #include <iomanip>
4 
5 #include "JDetector/JDetector.hh"
8 
9 #include "Jeep/JParser.hh"
10 #include "Jeep/JMessage.hh"
11 
12 
13 /**
14  * \file
15  *
16  * Auxiliary program to merge detector files.
17  *
18  * If the option
19  * <pre>
20  * -N [i]
21  * </pre>
22  * is used with a positive number the strings are renumbered starting from <tt>i</tt>.
23  * Each string gets a unique number based on the order of the detector files
24  * and its original index in its own detector file.
25  *
26  * \author mdejong
27  */
28 int main(int argc, char **argv)
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(JModuleLocation(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 }
JMessage.hh
JDETECTOR::load
void load(const JString &file_name, JDetector &detector)
Load detector from input file.
Definition: JDetectorToolkit.hh:476
std::vector
Definition: JSTDTypes.hh:12
JPARSER::JParser
Utility class to parse command line options.
Definition: JParser.hh:1493
JPP
This name space includes all other name spaces (except KM3NETDAQ, KM3NET and ANTARES).
Definition: JAAnetToolkit.hh:37
JDETECTOR::JModuleLocation
Logical location of module.
Definition: JModuleLocation.hh:36
debug
int debug
debug level
Definition: JSirene.cc:59
JParser.hh
JDetectorToolkit.hh
JDETECTOR::store
void store(const JString &file_name, const JDetector &detector)
Store detector to output file.
Definition: JDetectorToolkit.hh:552
JModuleLocation.hh
main
int main(int argc, char **argv)
Definition: JMergeDetector.cc:28
make_field
#define make_field(A,...)
macro to convert parameter to JParserTemplateElement object
Definition: JParser.hh:1954
JDETECTOR::JDetector
Detector data structure.
Definition: JDetector.hh:80
JAANET::detector
Detector file.
Definition: JHead.hh:130
std
Definition: jaanetDictionary.h:36
JDetector.hh
FATAL
#define FATAL(A)
Definition: JMessage.hh:67
outputFile
string outputFile
Definition: JDAQTimesliceSelector.cc:37
JLANG::JException
General exception.
Definition: JException.hh:23