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 
24 
25  TypeSet&
27  return missingTypes_;
28  }
29 
30  bool
32  TClass *cl = TClass::GetClass(type.typeInfo(), true);
33  if(cl == nullptr) {
34  // Assume not a class
35  return true;
36  }
37  if(!cl->HasDictionary()) {
38  missingTypes().insert(type);
39  return false;
40  }
41  return true;
42  }
43 
44  void
45  checkTypeDictionaries(TypeID const& type, bool recursive) {
46  TClass *cl = TClass::GetClass(type.typeInfo(), true);
47  if(cl == nullptr) {
48  // Assume not a class
49  return;
50  }
51  THashTable result;
52  cl->GetMissingDictionaries(result, recursive);
53  for(auto const& item : result) {
54  TClass const* cl = static_cast<TClass const*>(item);
55  missingTypes().insert(TypeID(cl->GetTypeInfo()));
56  }
57  }
58 
59  bool
61  TClass *cl = TClass::GetClass(type.typeInfo(), true);
62  if(cl == nullptr) {
64  << "No TClass for class: '" << type.className() << "'" << std::endl;
65  }
66  if(!cl->HasDictionary()) {
67  missingTypes().insert(type);
68  return false;
69  }
70  return true;
71  }
72 
73  void
74  checkClassDictionaries(TypeID const& type, bool recursive) {
75  TClass *cl = TClass::GetClass(type.typeInfo(), true);
76  if(cl == nullptr) {
78  << "No TClass for class: '" << type.className() << "'" << std::endl;
79  }
80  THashTable result;
81  cl->GetMissingDictionaries(result, recursive);
82  for(auto const& item : result) {
83  TClass const* cl = static_cast<TClass const*>(item);
84  missingTypes().insert(TypeID(cl->GetTypeInfo()));
85  }
86  }
87 
88  void
90  if (!missingTypes().empty()) {
91  std::ostringstream ostr;
92  for(auto const& item : missingTypes()) {
93  ostr << item << "\n\n";
94  }
96  << "No data dictionary found for the following classes:\n\n"
97  << ostr.str()
98  << "Most likely each dictionary was never generated,\n"
99  << "but it may be that it was generated in the wrong package.\n"
100  << "Please add (or move) the specification\n"
101  << "<class name=\"whatever\"/>\n"
102  << "to the appropriate classes_def.xml file.\n"
103  << "If the class is a template instance, you may need\n"
104  << "to define a dummy variable of this type in classes.h.\n"
105  << "Also, if this class has any transient members,\n"
106  << "you need to specify them in classes_def.xml.";
107  }
108  }
109 
110  void
112  while (!missingTypes().empty()) {
114  for(auto const& item : missing) {
115  try {
116  TClass::GetClass(item.typeInfo(), kTRUE);
117  }
118  // We don't want to fail if we can't load a plug-in.
119  catch (...) {}
120  }
121  missingTypes().clear();
122  for(auto const& item : missing) {
123  checkTypeDictionaries(item, true);
124  }
125  if (missingTypes() == missing) {
126  break;
127  }
128  }
129  if (missingTypes().empty()) {
130  return;
131  }
133  }
134 
135  void
137  std::vector<TypeWithDict>& baseTypes) {
138  if (!typeID.isClass()) {
139  return;
140  }
141  TypeWithDict type(typeID.typeInfo());
142  TypeBases bases(type);
143  for (auto const& basex : bases) {
144  BaseWithDict base(basex);
145  if (!base.isPublic()) {
146  continue;
147  }
148  TypeWithDict baseRflxType = base.typeOf();
149  if (!bool(baseRflxType)) {
150  continue;
151  }
152  TypeWithDict baseType(baseRflxType.typeInfo());
153  // Check to make sure this base appears only once in the
154  // inheritance hierarchy.
155  if (!search_all(baseTypes, baseType)) {
156  // Save the type and recursive look for its base types
157  baseTypes.push_back(baseType);
158  public_base_classes(baseType, baseTypes);
159  }
160  // For now just ignore it if the class appears twice,
161  // After some more testing we may decide to uncomment the following
162  // exception.
163  //
164  //else {
165  // throw Exception(errors::UnimplementedFeature)
166  // << "DataFormats/Common/src/DictionaryTools.cc in function public_base_classes.\n"
167  // << "Encountered class that has a public base class that appears\n"
168  // << "multiple times in its inheritance heirarchy.\n"
169  // << "Please contact the EDM Framework group with details about\n"
170  // << "this exception. It was our hope that this complicated situation\n"
171  // << "would not occur. There are three possible solutions. 1. Change\n"
172  // << "the class design so the public base class does not appear multiple\n"
173  // << "times in the inheritance heirarchy. In many cases, this is a\n"
174  // << "sign of bad design. 2. Modify the code that supports Views to\n"
175  // << "ignore these base classes, but not supply support for creating a\n"
176  // << "View of this base class. 3. Improve the View infrastructure to\n"
177  // << "deal with this case. Class name of base class: " << baseType.Name() << "\n\n";
178  //}
179  }
180  }
181 
182 } // 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_
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)