Jpp  17.1.1
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  * Push all data members to Head.
26  */
27  void JHead::push()
28  {
29  using namespace std;
30  using namespace JPP;
31 
32  JRootReadableClass cls(*this);
33 
34  TIterator* i = cls.getClass()->GetListOfDataMembers()->MakeIterator();
35 
36  for (const TDataMember* p; (p = (const TDataMember*) i->Next()) != NULL; ) {
37  if (!JRootClass::is_static(*p)) {
38  if (this->count(p->GetName()) == 0) {
39  (*this)[p->GetName()] = "";
40  }
41  }
42  }
43  }
44 
45 
46  /**
47  * Read header from input.
48  *
49  * \param in input stream
50  * \return input stream
51  */
52  std::istream& JHead::read(std::istream& in)
53  {
54  using namespace std;
55  using namespace JPP;
56 
57  JStringStream is(in);
58 
59  if (getFileStatus(is.str().c_str())) {
60  is.load();
61  }
62 
64 
65  JRootReadableClass cls(*this);
66 
67  for (JEquation equation; reader >> equation && equation.getKey() != end_event::Class_Name(); ) {
68 
69  JRedirectString redirect(reader, equation.getValue());
70 
71  const JRootReadableClass abc = cls.find(equation.getKey().c_str());
72 
73  if (abc.is_valid()) {
74  reader.getObject(abc);
75  }
76 
77  (*this)[equation.getKey()] = equation.getValue();
78  }
79 
80  return in;
81  }
82 
83 
84  /**
85  * Write header to output.
86  *
87  * \param out output stream
88  * \return output stream
89  */
90  std::ostream& JHead::write(std::ostream& out) const
91  {
92  using namespace std;
93  using namespace JPP;
94 
96 
97  JRootWritableClass cls(*this);
98 
99  TIterator* i = cls.getClass()->GetListOfDataMembers()->MakeIterator();
100 
101  for (const TDataMember* p; (p = (const TDataMember*) i->Next()) != NULL; ) {
102  if (!JRootClass::is_static(*p)) {
103  if (this->find(p->GetName()) != this->end() ||
104  cls.get(*p) == JRootClass(&JHead::start_run) ||
105  cls.get(*p) == JRootClass(&JHead::end_event)) {
106  writer.put(p->GetName(), cls.get(*p), true);
107  }
108  }
109  }
110 
111  return out << flush;
112  }
113 
114 
115  /**
116  * Print header to output.
117  *
118  * \param out output stream
119  * \return output stream
120  */
121  std::ostream& JHead::print(std::ostream& out) const
122  {
123  using namespace std;
124  using namespace JPP;
125 
127 
128  JRootWritableClass cls(*this);
129 
130  TIterator* i = cls.getClass()->GetListOfDataMembers()->MakeIterator();
131 
133 
134  for (const TDataMember* p; (p = (const TDataMember*) i->Next()) != NULL; ) {
135  if (!JRootClass::is_static(*p)) {
136  if (cls.get(*p) != JRootClass(&JHead::end_event))
137  writer.put(p->GetName(), cls.get(*p), true);
138  else
139  end_event = make_pair(p->GetName(), cls.get(*p));
140  }
141  }
142 
143  for (JHead::const_iterator i = this->begin(); i != this->end(); ++i) {
144  if (!cls.find(i->first.c_str()).is_valid()) {
145  writer.put(i->first, i->second);
146  }
147  }
148 
149  writer.put(end_event.first, end_event.second, true);
150 
151  return out << flush;
152  }
153 
154 
155  /**
156  * Copy header from <tt>from</tt> to <tt>to</tt>.
157  *
158  * \param from header
159  * \param to header
160  */
161  void copy(const Head& from, JHead& to)
162  {
163  using namespace std;
164  using namespace JPP;
165 
167 
168  JRootReadableClass cls(to);
169 
170  for (Head::const_iterator i = from.begin(); i != from.end(); ++i) {
171 
172  const JRootReadableClass& abc = cls.find(getTag(i->first).c_str());
173 
174  const string buffer = trim(i->second);
175 
176  if (abc.is_valid() && buffer != "") {
177 
178  JRedirectString redirect(reader, buffer);
179 
180  reader.getObject(abc);
181 
182  if (i->first == getTag(i->first)) {
183  to.insert(*i); // keep track of parsed tags
184  }
185 
186  } else {
187 
188  to.insert(*i); // store data of unknown tags
189  }
190  }
191  }
192 
193 
194  /**
195  * Copy header from <tt>from</tt> to <tt>to</tt>.
196  *
197  * \param from header
198  * \param to header
199  */
200  void copy(const JHead& from, Head& to)
201  {
202  using namespace std;
203  using namespace JPP;
204 
205  to = Head();
206 
208 
209  JRootWritableClass cls(from);
210 
211  TIterator* i = cls.getClass()->GetListOfDataMembers()->MakeIterator();
212 
213  for (const TDataMember* p; (p = (const TDataMember*) i->Next()) != NULL; ) {
214  if (!JRootClass::is_static(*p)) {
215  if (from.find(p->GetName()) != from.end() ||
216  cls.get(*p) == JRootClass(&JHead::start_run) ||
217  cls.get(*p) == JRootClass(&JHead::end_event)) {
218  writer.put(p->GetName(), cls.get(*p), true);
219  }
220  }
221  }
222 
223  // copy pending data
224 
225  for (JHead::const_iterator i = from.begin(); i != from.end(); ++i) {
226  if (to.find(i->first) == to.end()) {
227  to.insert(*i);
228  }
229  }
230  }
231 }
void push()
Push all data members to Head.
Definition: JHead.cc:27
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:1537
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:1566
std::istream & read(std::istream &in)
Read header from input.
Definition: JHead.cc:52
JAANET::start_run start_run
Definition: JHead.hh:1509
std::ostream & print(std::ostream &out) const
Print header to output.
Definition: JHead.cc:121
Monte Carlo run header.
Definition: JHead.hh:1167
The Head class reflects the header of Monte-Carlo event files, which consists of keys (also referred ...
Definition: Head.hh:65
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
std::vector< int > count
Definition: JAlgorithm.hh:180
void copy(const Head &from, JHead &to)
Copy header from from to to.
Definition: JHead.cc:161
End of event record.
Definition: JHead.hh:1146
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:1251
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
std::string getTag(const std::string &tag)
Get tag without aanet extension &quot;_&lt;counter&gt;&quot; for identical tags.
Definition: JHead.hh:94
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:90
File status.