Jpp
JHead.cc
Go to the documentation of this file.
1 #include <string>
2 #include <map>
3 #include <sstream>
4 
7 
8 #include "JSystem/JStat.hh"
10 #include "JLang/JStringStream.hh"
11 #include "JLang/JNullStream.hh"
12 #include "JROOT/JRootClass.hh"
13 #include "JROOT/JRootStreamer.hh"
14 #include "JAAnet/JHead.hh"
15 #include "JAAnet/JAAnetDictionary.hh"
16 
17 
18 /**
19  * \author mdejong
20  */
21 namespace JAANET {
22 
23  /**
24  * Applications.
25  */
26  const std::string JHead::GENHEN = "GENHEN";
27  const std::string JHead::GENIE = "GENIE";
28  const std::string JHead::GSEAGEN = "gSeaGen";
29  const std::string JHead::MUPAGE = "HEMAS-DPM";
30  const std::string JHead::JSIRENE = "JSirene";
31  const std::string JHead::KM3 = "KM3";
32  const std::string JHead::KM3SIM = "KM3Sim";
33 
34 
35  /**
36  * Read header from input.
37  *
38  * \param in input stream
39  * \return input stream
40  */
41  std::istream& JHead::read(std::istream& in)
42  {
43  using namespace std;
44  using namespace JPP;
45 
46  JStringStream is(in);
47 
48  if (getFileStatus(is.str().c_str())) {
49  is.load();
50  }
51 
53 
54  JRootReadableClass cls(*this);
55 
56  for (JEquation equation; reader >> equation && equation.getKey() != end_event::Class_Name(); ) {
57 
58  JRedirectString redirect(reader, equation.getValue());
59 
60  const JRootReadableClass abc = cls.find(equation.getKey().c_str());
61 
62  if (abc.is_valid()) {
63  reader.getObject(abc);
64  }
65 
66  (*this)[equation.getKey()] = equation.getValue();
67  }
68 
69  return in;
70  }
71 
72 
73  /**
74  * Write header to output.
75  *
76  * \param out output stream
77  * \return output stream
78  */
79  std::ostream& JHead::write(std::ostream& out) const
80  {
81  using namespace std;
82  using namespace JPP;
83 
84  JRootWriter writer(out, JHead::getEquationParameters(), JAAnetDictionary::getInstance());
85 
86  JRootWritableClass cls(*this);
87 
88  TIterator* i = cls.getClass()->GetListOfDataMembers()->MakeIterator();
89 
90  for (const TDataMember* p; (p = (const TDataMember*) i->Next()) != NULL; ) {
91  if (!JRootClass::is_static(*p)) {
92  if (this->find(p->GetName()) != this->end() ||
93  cls.get(*p) == JRootClass(&JHead::start_run) ||
94  cls.get(*p) == JRootClass(&JHead::end_event)) {
95  writer.put(p->GetName(), cls.get(*p), true);
96  }
97  }
98  }
99 
100  return out << flush;
101  }
102 
103 
104  /**
105  * Print header to output.
106  *
107  * \param out output stream
108  * \return output stream
109  */
110  std::ostream& JHead::print(std::ostream& out) const
111  {
112  using namespace std;
113  using namespace JPP;
114 
116 
117  JRootWriter writer(out, parameters, JAAnetDictionary::getInstance());
118 
119  JRootWritableClass cls(*this);
120 
121  TIterator* i = cls.getClass()->GetListOfDataMembers()->MakeIterator();
122 
124 
125  for (const TDataMember* p; (p = (const TDataMember*) i->Next()) != NULL; ) {
126  if (!JRootClass::is_static(*p)) {
127  if (cls.get(*p) != JRootClass(&JHead::end_event))
128  writer.put(p->GetName(), cls.get(*p), true);
129  else
130  end_event = make_pair(p->GetName(), cls.get(*p));
131  }
132  }
133 
134  for (JHead::const_iterator i = this->begin(); i != this->end(); ++i) {
135  if (!cls.find(i->first.c_str()).is_valid()) {
136  out << i->first << parameters.getDefaultSeparator() << parameters.getDefaultWhiteSpace() << i->second << parameters.getDefaultEndOfLine();
137  }
138  }
139 
140  writer.put(end_event.first, end_event.second, true);
141 
142  return out << flush;
143  }
144 
145 
146  /**
147  * Copy header from <tt>from</tt> to <tt>to</tt>.
148  *
149  * \param from header
150  * \param to header
151  */
152  void copy(const Head& from, JHead& to)
153  {
154  using namespace std;
155  using namespace JPP;
156 
157  JRootReader reader(null, JHead::getEquationParameters(), JAAnetDictionary::getInstance());
158  JRootReadableClass cls(to);
159 
160  for (Head::const_iterator i = from.begin(); i != from.end(); ++i) {
161 
162  const JRootReadableClass& abc = cls.find(getTag(i->first).c_str());
163 
164  if (abc.is_valid()) {
165 
166  JRedirectString redirect(reader, i->second);
167 
168  reader.getObject(abc);
169  }
170 
171  if (i->first == getTag(i->first)) {
172  to.insert(*i); // keep track of parsed tags
173  }
174  }
175  }
176 
177 
178  /**
179  * Copy header from <tt>from</tt> to <tt>to</tt>.
180  *
181  * \param from header
182  * \param to header
183  */
184  void copy(const JHead& from, Head& to)
185  {
186  using namespace std;
187 
188  to = Head();
189 
190  stringstream io;
191 
192  io << from;
193 
194  read(to, io);
195 
196  // copy pending data
197 
198  for (JHead::const_iterator i = from.begin(); i != from.end(); ++i) {
199  if (to.find(i->first) == to.end()) {
200  to.insert(*i);
201  }
202  }
203  }
204 }
Head.hh
JAANET::JHead::end_event
JAANET::end_event end_event
Definition: JHead.hh:1094
JAANET::JHead::GENHEN
static const std::string GENHEN
Generators.
Definition: JHead.hh:845
JHead.hh
JAANET::JHead::read
std::istream & read(std::istream &in)
Read header from input.
Definition: JHead.cc:41
JAANET::JHead::GENIE
static const std::string GENIE
Definition: JHead.hh:846
JLANG::getInstance
T & getInstance(const T &object)
Get static instance from temporary object.
Definition: JObject.hh:75
JNullStream.hh
JAANET::is_valid
bool is_valid(const T &value)
Check validity of given value.
Definition: JHead.hh:823
JRootStreamer.hh
JAANET::JHead::JSIRENE
static const std::string JSIRENE
Definition: JHead.hh:849
JAANET::JHead::print
std::ostream & print(std::ostream &out) const
Print header to output.
Definition: JHead.cc:110
JLANG::JEquationParameters::getDefaultWhiteSpace
const char getDefaultWhiteSpace() const
Get default white space character.
Definition: JEquationParameters.hh:289
JAANET::JHead::start_run
JAANET::start_run start_run
Definition: JHead.hh:1071
JAANET::JHead::write
std::ostream & write(std::ostream &out) const
Write header to output.
Definition: JHead.cc:79
JAANET::JHead::GSEAGEN
static const std::string GSEAGEN
Definition: JHead.hh:847
JAANET::copy
void copy(const Head &from, JHead &to)
Copy header from from to to.
Definition: JHead.cc:152
JAANET::JHead
Monte Carlo run header.
Definition: JHead.hh:839
JPP
This name space includes all other name spaces (except KM3NETDAQ, KM3NET and ANTARES).
Definition: JAAnetToolkit.hh:37
JAANET::JHead::KM3SIM
static const std::string KM3SIM
Definition: JHead.hh:851
Head
The Head class reflects the header of Monte-Carlo event files, which consists of keys (also referred ...
Definition: Head.hh:39
JRedirectString.hh
JLANG::JEquationParameters::getDefaultEndOfLine
const char getDefaultEndOfLine() const
Get default end of line character.
Definition: JEquationParameters.hh:129
JSYSTEM::getFileStatus
static JStat getFileStatus
Function object for file status.
Definition: JStat.hh:173
JStringStream.hh
JStat.hh
std::pair
Definition: JSTDTypes.hh:15
JAANET
Extensions to AAnet data format.
Definition: JAAnetToolkit.hh:36
JLANG::JEquationParameters::getDefaultSeparator
const char getDefaultSeparator() const
Get default separator character.
Definition: JEquationParameters.hh:93
JLANG::JEquationParameters
Simple data structure to support I/O of equations (see class JLANG::JEquation).
Definition: JEquationParameters.hh:20
JAANET::JHead::KM3
static const std::string KM3
Definition: JHead.hh:850
JAANET::getTag
std::string getTag(const std::string &tag)
Get tag without aanet extension "_<counter>" for identical tags.
Definition: JHead.hh:61
std
Definition: jaanetDictionary.h:36
JAANET::JHead::getEquationParameters
static JLANG::JEquationParameters & getEquationParameters()
Get equation parameters corresponding to Monte Carlo ASCII format, i.e:
Definition: JHead.hh:1106
JAANET::JHead::MUPAGE
static const std::string MUPAGE
Definition: JHead.hh:848
JAANET::end_event
End of event record.
Definition: JHead.hh:805
JRootClass.hh
io_ascii.hh