Jpp
 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 
5 #include "evt/Head.hh"
6 
8 #include "JLang/JNullStream.hh"
9 
10 #include "JROOT/JRootDictionary.hh"
11 #include "JROOT/JRootStreamer.hh"
12 
13 #include "JAAnet/JHead.hh"
14 #include "JAAnet/JHeadToolkit.hh"
15 
16 
17 /**
18  * \author mdejong
19  */
20 
21 namespace JAANET {
22 
23  /**
24  * Generators.
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 
33 
34  /**
35  * Copy header from <tt>from</tt> to <tt>to</tt>.
36  *
37  * \param from header
38  * \param to header
39  */
40  void copy(const Head& from, JHead& to)
41  {
42  using namespace std;
43  using namespace JPP;
44 
46  JRootClassReader cls(to);
47 
48  for (Head::const_iterator i = from.begin(); i != from.end(); ++i) {
49 
50  const JRootClassReader& abc = cls.find(getTag(i->first).c_str());
51 
52  if (abc.is_valid()) {
53 
54  JRedirectString redirect(reader, i->second);
55 
56  reader.getObject(abc);
57  }
58 
59  to.insert(*i); // keep track of parsed tags
60  }
61  }
62 
63 
64  /**
65  * Copy header from <tt>from</tt> to <tt>to</tt>.
66  *
67  * \param from header
68  * \param to header
69  */
70  void copy(const JHead& from, Head& to)
71  {
72  using namespace std;
73  using namespace JPP;
74 
75  to.clear();
76 
77  ostringstream os;
78 
79  JRootWriter writer(os, getEquationParameters(), JAAnetDictionary::getInstance());
80  JRootClassWriter cls(from);
81 
82  TIterator* i = cls.getClass()->GetListOfDataMembers()->MakeIterator();
83 
84  for (const TDataMember* p; (p = (const TDataMember*) i->Next()) != NULL; os.str("")) {
85 
86  if (JRootClass::is_class(*p) && strcmp(p->GetName(), end_event::Class_Name()) != 0) {
87 
88  if (from.find(p->GetName()) != from.end()) { // only copy data of parsed tags
89 
90  writer.putObject(cls.get(*p));
91 
92  to.insert(make_pair(p->GetName(), os.str()));
93  }
94  }
95  }
96 
97  // copy pending data
98 
99  for (JHead::const_iterator i = from.begin(); i != from.end(); ++i) {
100  if (to.find(i->first) == to.end()) {
101  to.insert(*i);
102  }
103  }
104  }
105 }
static const std::string GSEAGEN
Definition: JHead.hh:735
static const std::string KM3
Definition: JHead.hh:738
ASCII I/O of objects with ROOT dictionary.
static const std::string MUPAGE
Definition: JHead.hh:736
static const std::string GENIE
Definition: JHead.hh:734
static const std::string JSIRENE
Definition: JHead.hh:737
Monte Carlo run header.
Definition: JHead.hh:727
void copy(const Head &from, JHead &to)
Copy header from from to to.
Definition: JHead.cc:40
static JRootDictionary & getInstance()
Get reference to unique instance of this class object.
static const std::string GENHEN
Generators.
Definition: JHead.hh:733
static JNullStream null
Null I/O stream.
Definition: JNullStream.hh:51
std::string getTag(const std::string &tag)
Get tag without aanet extension &quot;_&lt;counter&gt;&quot; for identical tags.
Definition: JHead.hh:57
const JEquationParameters & getEquationParameters()
Get equation parameters corresponding to Monte Carlo ASCII format, i.e: