CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
DictionaryTools.cc
Go to the documentation of this file.
2 
9 
10 #include "TClass.h"
11 #include "TInterpreter.h"
12 #include "THashTable.h"
13 
14 #include "boost/algorithm/string.hpp"
15 #include "boost/thread/tss.hpp"
16 
17 #include <algorithm>
18 #include <sstream>
19 #include <string>
20 
21 namespace edm {
22 
23  std::string const&
25  static std::string const prefix("LCGReflex/");
26  return prefix;
27  }
28 
30 
31  TypeSet&
33  return missingTypes_;
34  }
35 
36  bool
38  TClass *cl = TClass::GetClass(type.typeInfo(), true);
39  if(cl == nullptr) {
40  // Assume not a class
41  return true;
42  }
43  if(!cl->HasDictionary()) {
44  missingTypes().insert(type);
45  return false;
46  }
47  return true;
48  }
49 
50  void
51  checkTypeDictionaries(TypeID const& type, bool recursive) {
52  TClass *cl = TClass::GetClass(type.typeInfo(), true);
53  if(cl == nullptr) {
54  // Assume not a class
55  return;
56  }
57  THashTable result;
58  cl->GetMissingDictionaries(result, recursive);
59  for(auto const& item : result) {
60  TClass const* cl = static_cast<TClass const*>(item);
61  missingTypes().insert(TypeID(cl->GetTypeInfo()));
62  }
63  }
64 
65  bool
67  TClass *cl = TClass::GetClass(type.typeInfo(), true);
68  if(cl == nullptr) {
70  << "No TClass for class: '" << type.className() << "'" << std::endl;
71  }
72  if(!cl->HasDictionary()) {
73  missingTypes().insert(type);
74  return false;
75  }
76  return true;
77  }
78 
79  void
80  checkClassDictionaries(TypeID const& type, bool recursive) {
81  TClass *cl = TClass::GetClass(type.typeInfo(), true);
82  if(cl == nullptr) {
84  << "No TClass for class: '" << type.className() << "'" << std::endl;
85  }
86  THashTable result;
87  cl->GetMissingDictionaries(result, recursive);
88  for(auto const& item : result) {
89  TClass const* cl = static_cast<TClass const*>(item);
90  missingTypes().insert(TypeID(cl->GetTypeInfo()));
91  }
92  }
93 
94  void
96  if (!missingTypes().empty()) {
97  std::ostringstream ostr;
98  for(auto const& item : missingTypes()) {
99  ostr << item << "\n\n";
100  }
102  << "No data dictionary found for the following classes:\n\n"
103  << ostr.str()
104  << "Most likely each dictionary was never generated,\n"
105  << "but it may be that it was generated in the wrong package.\n"
106  << "Please add (or move) the specification\n"
107  << "<class name=\"whatever\"/>\n"
108  << "to the appropriate classes_def.xml file.\n"
109  << "If the class is a template instance, you may need\n"
110  << "to define a dummy variable of this type in classes.h.\n"
111  << "Also, if this class has any transient members,\n"
112  << "you need to specify them in classes_def.xml.";
113  }
114  }
115 
116  void
118  while (!missingTypes().empty()) {
120  for(auto const& item : missing) {
121  try {
122  TClass::GetClass(item.typeInfo(), kTRUE);
123  }
124  // We don't want to fail if we can't load a plug-in.
125  catch (...) {}
126  }
127  missingTypes().clear();
128  for(auto const& item : missing) {
129  checkTypeDictionaries(item, true);
130  }
131  if (missingTypes() == missing) {
132  break;
133  }
134  }
135  if (missingTypes().empty()) {
136  return;
137  }
139  }
140 
141  void
143  std::vector<TypeWithDict>& baseTypes) {
144  if (!typeID.isClass()) {
145  return;
146  }
147  TypeWithDict type(typeID.typeInfo());
148  TypeBases bases(type);
149  for (auto const& basex : bases) {
150  BaseWithDict base(basex);
151  if (!base.isPublic()) {
152  continue;
153  }
154  TypeWithDict baseRflxType = base.typeOf();
155  if (!bool(baseRflxType)) {
156  continue;
157  }
158  TypeWithDict baseType(baseRflxType.typeInfo());
159  // Check to make sure this base appears only once in the
160  // inheritance hierarchy.
161  if (!search_all(baseTypes, baseType)) {
162  // Save the type and recursive look for its base types
163  baseTypes.push_back(baseType);
164  public_base_classes(baseType, baseTypes);
165  }
166  // For now just ignore it if the class appears twice,
167  // After some more testing we may decide to uncomment the following
168  // exception.
169  //
170  //else {
171  // throw Exception(errors::UnimplementedFeature)
172  // << "DataFormats/Common/src/DictionaryTools.cc in function public_base_classes.\n"
173  // << "Encountered class that has a public base class that appears\n"
174  // << "multiple times in its inheritance heirarchy.\n"
175  // << "Please contact the EDM Framework group with details about\n"
176  // << "this exception. It was our hope that this complicated situation\n"
177  // << "would not occur. There are three possible solutions. 1. Change\n"
178  // << "the class design so the public base class does not appear multiple\n"
179  // << "times in the inheritance heirarchy. In many cases, this is a\n"
180  // << "sign of bad design. 2. Modify the code that supports Views to\n"
181  // << "ignore these base classes, but not supply support for creating a\n"
182  // << "View of this base class. 3. Improve the View infrastructure to\n"
183  // << "deal with this case. Class name of base class: " << baseType.Name() << "\n\n";
184  //}
185  }
186  }
187 
188 } // namespace edm
tuple base
Main Program
Definition: newFWLiteAna.py:92
type
Definition: HCALResponse.h:21
dictionary missing
Definition: combine.py:4
bool checkTypeDictionary(TypeID const &type)
void checkTypeDictionaries(TypeID const &type, bool recursive=true)
void checkClassDictionaries(TypeID const &type, bool recursive=true)
static TypeSet missingTypes_
std::string const & dictionaryPlugInPrefix()
const std::type_info & typeInfo() const
Definition: TypeIDBase.h:58
void public_base_classes(TypeWithDict const &type, std::vector< TypeWithDict > &baseTypes)
std::set< TypeID > TypeSet
tuple result
Definition: query.py:137
bool isClass() const
std::type_info const & typeInfo() const
TypeWithDict typeOf() const
Definition: BaseWithDict.cc:26
void throwMissingDictionariesException()
bool search_all(ForwardSequence const &s, Datum const &d)
Definition: Algorithms.h:46
string const
Definition: compareJSON.py:14
void loadMissingDictionaries()
TypeSet & missingTypes()
std::string const & className() const
Definition: TypeID.cc:46
bool isPublic() const
Definition: BaseWithDict.cc:16
bool checkClassDictionary(TypeID const &type)