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