Jpp  17.0.0
the software that should make you happy
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
getUUID.cc
Go to the documentation of this file.
1 #include <string>
2 #include <iostream>
3 #include <fstream>
4 #include <iomanip>
5 
6 #include "TFile.h"
7 #include "TError.h"
8 
9 #include "JLang/JUUID.hh"
10 #include "Jeep/JComment.hh"
11 #include "JIO/JFileStreamIO.hh"
14 
15 #include "Jeep/JParser.hh"
16 #include "Jeep/JMessage.hh"
17 
18 /**
19  * \file
20  * Auxiliary program to print UUID.
21  * \author mdejong
22  */
23 int main(int argc, char **argv)
24 {
25  using namespace std;
26  using namespace JPP;
27 
28  string inputFile;
29  int debug;
30 
31  try {
32 
33  JParser<> zap("Auxiliary program to print UUID.");
34 
35  zap['f'] = make_field(inputFile) = "";
36  zap['d'] = make_field(debug) = 1;
37 
38  zap(argc, argv);
39  }
40  catch(const exception &error) {
41  FATAL(error.what() << endl);
42  }
43 
44  if (inputFile != "") {
45 
46  if (getFilenameExtension(inputFile) == ROOT_FILE_FORMAT) {
47 
48  gErrorIgnoreLevel = kError;
49 
50  TFile* file = TFile::Open(inputFile.c_str(), "EXISTS");
51 
52  if (file != NULL) {
53  file->GetUUID().Print();
54  file->Close();
55  } else
56  return 1;
57 
58  } else if (getFilenameExtension(inputFile) == ASCII_FILE_FORMAT ||
60 
61  ifstream in(inputFile.c_str());
62 
63  JComment comment;
64 
65  if (in >> comment && comment.hasUUID())
66  cout << comment.getUUID() << endl;
67  else
68  return 1;
69 
70  in.close();
71 
72  } else if (getFilenameExtension(inputFile) == BINARY_DETECTOR_FILE_FORMAT[0] ||
74 
75  JFileStreamReader in(inputFile.c_str());
76 
77  JComment comment;
78 
79  char c;
80 
81  for (string buffer; in >> c && c == JComment::START_COMMENT; ) {
82 
83  in >> buffer;
84 
85  comment.add(buffer);
86  }
87 
88  if (comment.hasUUID())
89  cout << comment.getUUID() << endl;
90  else
91  return 1;
92 
93  in.close();
94  }
95 
96  } else {
97 
98  cout << JUUID::rndm() << endl;
99  }
100 
101  return 0;
102 }
Utility class to parse command line options.
Definition: JParser.hh:1500
int main(int argc, char *argv[])
Definition: Main.cc:15
static const char *const BINARY_DETECTOR_FILE_FORMAT[]
JIO binary file format.
static const char *const ASCII_FILE_FORMAT
file name extension ASCII format
#define make_field(A,...)
macro to convert parameter to JParserTemplateElement object
Definition: JParser.hh:1961
int debug
debug level
Definition: JSirene.cc:66
General purpose messaging.
JUUID getUUID() const
Get UUID.
Definition: JComment.hh:140
#define FATAL(A)
Definition: JMessage.hh:67
static const char *const KM3NET_DETECTOR_FILE_FORMAT
KM3NeT standard ASCII format
Auxiliary class for comment.
Definition: JComment.hh:41
Utility class to parse command line options.
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
$WORKDIR ev_configure_domsimulator txt echo process $DOM_SIMULATOR $i $SOURCE_HOST[$index] csh c(setenv ROOTSYS $ROOTSYS &&source $JPP_DIR/setenv.csh $JPP_DIR &&($DOM_SIMULATOR\-u\$NAME\$\-H\$SERVER\$\-M\$LOGGER\$\-d $DEBUG</dev/null > &/dev/null &))'
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
static const char *const ROOT_FILE_FORMAT
file name extension ROOT format
Specifications of file name extensions.
Binary buffered file input.