Jpp  18.0.1-rc.1
the software that should make you happy
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Functions
JMoveDetector.cc File Reference

Auxiliary program to modify detector calibration. More...

#include <iostream>
#include <fstream>
#include <string>
#include <vector>
#include "JDetector/JDetector.hh"
#include "JDetector/JDetectorToolkit.hh"
#include "JGeometry3D/JVector3D.hh"
#include "JIO/JByteArrayIO.hh"
#include "Jeep/JeepToolkit.hh"
#include "Jeep/JPrint.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 modify detector calibration.

Syntax:

    -M     "<module identifier>     (setx|addx|subx|sety|addy|suby|setz|addz|subz) value"
    -(S|s) "<string number>         (setx|addx|subx|sety|addy|suby|setz|addz|subz) value"

Options -M and -S refer to a module and a string, respectively.
The values provided for a string modification coherently apply to the modules of the specified string number.
The option -s is equivalent to option -S except that the action applies only to the optical modules in the string and not the base module.

If the module identifier or string number is -1, the action is applied to all modules or strings in the detector, respectively.

For options (set|add|sub)(x|y|z), the value corresponds to last character of the the quoted action.

The units of all positions are m.

Multiple options -M, -S or -s will be processed in order of appearance.

Author
mdejong

Definition in file JMoveDetector.cc.

Function Documentation

int main ( int  argc,
char **  argv 
)

Definition at line 209 of file JMoveDetector.cc.

210 {
211  using namespace std;
212  using namespace JPP;
213 
215 
216  string detectorFile;
217  vector<pair_type> mod;
218  vector<pair_type> str;
219  vector<pair_type> dos;
220  size_t size;
221  int debug;
222 
223  try {
224 
225  JParser<> zap("Auxiliary program to modify detector.");
226 
227  zap['a'] = make_field(detectorFile, "detector file I/O");
228  zap['M'] = make_field(mod, "module modification") = JPARSER::initialised();
229  zap['S'] = make_field(str, "string modification (optical modules and base module") = JPARSER::initialised();
230  zap['s'] = make_field(dos, "string modification (optical modules only)") = JPARSER::initialised();
231  zap['N'] = make_field(size, "internal buffer size") = 500000;
232  zap['d'] = make_field(debug, "debug level") = 2;
233 
234  zap(argc, argv);
235  }
236  catch(const exception &error) {
237  FATAL(error.what() << endl);
238  }
239 
240 
241  if (getFilenameExtension(detectorFile) != BINARY_DETECTOR_FILE_FORMAT[1]) {
242  FATAL("Wrong file name extension - should be " << BINARY_DETECTOR_FILE_FORMAT[1] << endl);
243  }
244 
246 
247  JByteArrayWriter buffer;
248 
249  buffer.resize(size);
250 
251  fstream io;
252 
253  io.open(detectorFile.c_str(), ios::binary | ios_base::in | ios_base::out);
254 
255  if (!io) {
256  FATAL("Error opening file " << detectorFile << endl);
257  }
258 
259  size_t len = 0;
260 
261  for ( ; ; ) {
262 
263  io.read(buffer.data() + len, buffer.size() - len);
264 
265  len += io.gcount();
266 
267  if (io.eof())
268  break;
269  else
270  buffer.resize(2 * buffer.size());
271  }
272 
273  buffer.resize(len);
274 
275  JByteArrayReader in(buffer.data(), buffer.size());
276 
277  detector.read(in);
278 
279  detector.comment.clear();
280  detector.comment.add(argv[0]);
281 
282  for (vector<pair_type>::const_iterator i = mod.begin(); i != mod.end(); ++i) {
283 
284  for (JDetector::iterator module = detector.begin(); module != detector.end(); ++module) {
285 
286  if (module->getID() == i->first || i->first == WILDCARD ){
287 
288  if (debug >= debug_t) {
289  print(cout, *module, i->second);
290  }
291 
292  if (!i->second.apply(*module)) {
293  ERROR("No valid action: " << i->first << ' ' << i->second << endl);
294  }
295  }
296  }
297  }
298 
299 
300  for (vector<pair_type>::const_iterator i = str.begin(); i != str.end(); ++i) {
301 
302  for (JDetector::iterator module = detector.begin(); module != detector.end(); ++module) {
303 
304  if (module->getString() == i->first || i->first == WILDCARD) {
305 
306  if (debug >= debug_t) {
307  print(cout, *module, i->second);
308  }
309 
310  if (!i->second.apply(*module)) {
311  ERROR("No valid action: " << i->first << ' ' << i->second << endl);
312  }
313  }
314  }
315  }
316 
317 
318  for (vector<pair_type>::const_iterator i = dos.begin(); i != dos.end(); ++i) {
319 
320  for (JDetector::iterator module = detector.begin(); module != detector.end(); ++module) {
321 
322  if (module->getFloor() != 0) {
323 
324  if (module->getString() == i->first || i->first == WILDCARD) {
325 
326  if (debug >= debug_t) {
327  print(cout, *module, i->second);
328  }
329 
330  if (!i->second.apply(*module)) {
331  ERROR("No valid action: " << i->first << ' ' << i->second << endl);
332  }
333  }
334  }
335  }
336  }
337 
338  buffer.clear();
339 
340  detector.write(buffer);
341 
342  io.clear();
343  io.seekp(0, ios_base::beg);
344 
345  io.write(buffer.data(), buffer.size());
346 
347  io.close();
348 }
Utility class to parse command line options.
Definition: JParser.hh:1514
JCombinatorics::pair_type pair_type
debug
Definition: JMessage.hh:29
Detector data structure.
Definition: JDetector.hh:89
Empty structure for specification of parser element that is initialised (i.e. does not require input)...
Definition: JParser.hh:83
static const char *const BINARY_DETECTOR_FILE_FORMAT[]
JIO binary file format.
Detector file.
Definition: JHead.hh:226
#define make_field(A,...)
macro to convert parameter to JParserTemplateElement object
Definition: JParser.hh:1989
Byte array binary input.
Definition: JByteArrayIO.hh:25
#define ERROR(A)
Definition: JMessage.hh:66
print
Definition: JConvertDusj.sh:44
#define FATAL(A)
Definition: JMessage.hh:67
std::string getFilenameExtension(const std::string &file_name)
Get file name extension, i.e. part after last JEEP::FILENAME_SEPARATOR if any.
Definition: JeepToolkit.hh:109
Byte array binary output.
do set_variable DETECTOR_TXT $WORKDIR detector
then fatal Wrong number of arguments fi set_variable DETECTOR $argv[1] set_variable INPUT_FILE $argv[2] eval JPrintDetector a $DETECTOR O IDENTIFIER eval JPrintDetector a $DETECTOR O SUMMARY JAcoustics sh $DETECTOR_ID source JAcousticsToolkit sh CHECK_EXIT_CODE typeset A EMITTERS get_tripods $WORKDIR tripod txt EMITTERS get_transmitters $WORKDIR transmitter txt EMITTERS for EMITTER in
Definition: JCanberra.sh:46
int debug
debug level