Jpp  pmt_effective_area_update_2
the software that should make you happy
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
JHead.cc
Go to the documentation of this file.
1 #include <string>
2 #include <map>
3 #include <sstream>
4 
6 
7 #include "JSystem/JStat.hh"
9 #include "JLang/JStringStream.hh"
10 #include "JLang/JNullStream.hh"
11 #include "JLang/JLangToolkit.hh"
12 #include "JROOT/JRootClass.hh"
13 #include "JROOT/JRootStreamer.hh"
14 #include "JAAnet/JHead.hh"
15 #include "JAAnet/JAAnetDictionary.hh"
16 #include "JAAnet/JHeadWriter.hh"
17 
18 
19 /**
20  * \author mdejong
21  */
22 namespace JAANET {
23 
24  /**
25  * Read header from input.
26  *
27  * \param in input stream
28  * \return input stream
29  */
30  std::istream& JHead::read(std::istream& in)
31  {
32  using namespace std;
33  using namespace JPP;
34 
35  JStringStream is(in);
36 
37  if (getFileStatus(is.str().c_str())) {
38  is.load();
39  }
40 
42 
43  JRootReadableClass cls(*this);
44 
45  for (JEquation equation; reader >> equation && equation.getKey() != end_event::Class_Name(); ) {
46 
47  JRedirectString redirect(reader, equation.getValue());
48 
49  const JRootReadableClass abc = cls.find(equation.getKey().c_str());
50 
51  if (abc.is_valid()) {
52  reader.getObject(abc);
53  }
54 
55  (*this)[equation.getKey()] = equation.getValue();
56  }
57 
58  return in;
59  }
60 
61 
62  /**
63  * Write header to output.
64  *
65  * \param out output stream
66  * \return output stream
67  */
68  std::ostream& JHead::write(std::ostream& out) const
69  {
70  using namespace std;
71  using namespace JPP;
72 
74 
75  JRootWritableClass cls(*this);
76 
77  TIterator* i = cls.getClass()->GetListOfDataMembers()->MakeIterator();
78 
79  for (const TDataMember* p; (p = (const TDataMember*) i->Next()) != NULL; ) {
80  if (!JRootClass::is_static(*p)) {
81  if (this->find(p->GetName()) != this->end() ||
82  cls.get(*p) == JRootClass(&JHead::start_run) ||
83  cls.get(*p) == JRootClass(&JHead::end_event)) {
84  writer.put(p->GetName(), cls.get(*p), true);
85  }
86  }
87  }
88 
89  return out << flush;
90  }
91 
92 
93  /**
94  * Print header to output.
95  *
96  * \param out output stream
97  * \return output stream
98  */
99  std::ostream& JHead::print(std::ostream& out) const
100  {
101  using namespace std;
102  using namespace JPP;
103 
105 
106  JRootWritableClass cls(*this);
107 
108  TIterator* i = cls.getClass()->GetListOfDataMembers()->MakeIterator();
109 
111 
112  for (const TDataMember* p; (p = (const TDataMember*) i->Next()) != NULL; ) {
113  if (!JRootClass::is_static(*p)) {
114  if (cls.get(*p) != JRootClass(&JHead::end_event))
115  writer.put(p->GetName(), cls.get(*p), true);
116  else
117  end_event = make_pair(p->GetName(), cls.get(*p));
118  }
119  }
120 
121  for (JHead::const_iterator i = this->begin(); i != this->end(); ++i) {
122  if (!cls.find(i->first.c_str()).is_valid()) {
123  writer.put(i->first, i->second);
124  }
125  }
126 
127  writer.put(end_event.first, end_event.second, true);
128 
129  return out << flush;
130  }
131 
132 
133  /**
134  * Copy header from <tt>from</tt> to <tt>to</tt>.
135  *
136  * \param from header
137  * \param to header
138  */
139  void copy(const Head& from, JHead& to)
140  {
141  using namespace std;
142  using namespace JPP;
143 
145 
146  JRootReadableClass cls(to);
147 
148  for (Head::const_iterator i = from.begin(); i != from.end(); ++i) {
149 
150  const JRootReadableClass& abc = cls.find(getTag(i->first).c_str());
151 
152  const string buffer = trim(i->second);
153 
154  if (abc.is_valid() && buffer != "") {
155 
156  JRedirectString redirect(reader, buffer);
157 
158  reader.getObject(abc);
159 
160  if (i->first == getTag(i->first)) {
161  to.insert(*i); // keep track of parsed tags
162  }
163 
164  } else {
165 
166  to.insert(*i); // store data of unknown tags
167  }
168  }
169  }
170 
171 
172  /**
173  * Copy header from <tt>from</tt> to <tt>to</tt>.
174  *
175  * \param from header
176  * \param to header
177  */
178  void copy(const JHead& from, Head& to)
179  {
180  using namespace std;
181  using namespace JPP;
182 
183  to = Head();
184 
186 
187  JRootWritableClass cls(from);
188 
189  TIterator* i = cls.getClass()->GetListOfDataMembers()->MakeIterator();
190 
191  for (const TDataMember* p; (p = (const TDataMember*) i->Next()) != NULL; ) {
192  if (!JRootClass::is_static(*p)) {
193  if (from.find(p->GetName()) != from.end() ||
194  cls.get(*p) == JRootClass(&JHead::start_run) ||
195  cls.get(*p) == JRootClass(&JHead::end_event)) {
196  writer.put(p->GetName(), cls.get(*p), true);
197  }
198  }
199  }
200 
201  // copy pending data
202 
203  for (JHead::const_iterator i = from.begin(); i != from.end(); ++i) {
204  if (to.find(i->first) == to.end()) {
205  to.insert(*i);
206  }
207  }
208  }
209 }
const std::string & getKey() const
Get key.
Definition: JEquation.hh:163
Implementation for ASCII output of objects with ROOT dictionary.
is
Definition: JDAQCHSM.chsm:167
std::string trim(const std::string &buffer)
Trim string.
Definition: JLangToolkit.hh:79
JAANET::end_event end_event
Definition: JHead.hh:1420
General purpose equation class.
Definition: JEquation.hh:47
ASCII I/O of objects with ROOT dictionary.
T & getInstance(const T &object)
Get static instance from temporary object.
Definition: JObject.hh:75
static JLANG::JEquationParameters & getEquationParameters()
Get equation parameters corresponding to Monte Carlo ASCII format, i.e:
Definition: JHead.hh:1432
std::istream & read(std::istream &in)
Read header from input.
Definition: JHead.cc:30
JAANET::start_run start_run
Definition: JHead.hh:1393
std::ostream & print(std::ostream &out) const
Print header to output.
Definition: JHead.cc:99
Monte Carlo run header.
Definition: JHead.hh:1113
The Head class reflects the header of Monte-Carlo event files, which consists of keys (also referred ...
Definition: Head.hh:67
static JStat getFileStatus
Function object for file status.
Definition: JStat.hh:173
virtual JRootWriter & put(const JEquation &equation) override
Write equation.
Definition: JHeadWriter.hh:54
void copy(const Head &from, JHead &to)
Copy header from from to to.
Definition: JHead.cc:139
End of event record.
Definition: JHead.hh:1092
JRootWriter & put(const T &object)
Write object according equation format.
Implementation for Head output of JHead objects with ROOT dictionary.
Definition: JHeadWriter.hh:28
bool is_valid(T JHead::*pd) const
Check validity of given data member in JHead.
Definition: JHead.hh:1183
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 source JAcoustics sh $DETECTOR_ID CHECK_EXIT_CODE typeset A TRIPODS get_tripods $WORKDIR tripod txt TRIPODS for EMITTER in
Definition: JCanberra.sh:40
std::string getTag(const std::string &tag)
Get tag without aanet extension &quot;_&lt;counter&gt;&quot; for identical tags.
Definition: JHead.hh:64
esac $JPP_BIN JLogger sh $LOGGER until pgrep JGetMessage</dev/null > dev null
std::ostream & write(std::ostream &out) const
Write header to output.
Definition: JHead.cc:68
File status.