CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
MappingDatabase.cc
Go to the documentation of this file.
2 #include "MappingDatabase.h"
3 #include "IDatabaseSchema.h"
4 #include "MappingTree.h"
5 #include "MappingRules.h"
6 //
7 #include <sstream>
8 // externals
9 #include "Reflex/Type.h"
10 
11 std::string
13  std::string className = dictionary.Name(Reflex::SCOPED);
14  Reflex::PropertyList classProps = dictionary.Properties();
15  std::string classVersion = MappingRules::defaultClassVersion(className);
16  if(classProps.HasProperty(MappingRules::classVersionPropertyNameInDictionary())){
17  classVersion = classProps.PropertyAsString(MappingRules::classVersionPropertyNameInDictionary());
18  }
19  return classVersion;
20 }
21 
23  const std::string& scopeName,
24  std::map<std::string, std::vector<MappingRawElement> >& innerElements ){
25  std::map<std::string,std::vector<MappingRawElement> >::iterator iScope = innerElements.find(scopeName);
26  if(iScope != innerElements.end()){
27  for( std::vector<MappingRawElement>::const_iterator iM = iScope->second.begin();
28  iM != iScope->second.end(); ++iM ){
29  MappingElement& element = parentElement.appendSubElement( iM->elementType,
30  iM->variableName,
31  iM->variableType,
32  iM->tableName );
33  element.setColumnNames(iM->columns);
34  std::string nextScope(scopeName);
35  nextScope.append("::").append(iM->variableName);
36  buildElement( element, nextScope, innerElements );
37  }
38  }
39  innerElements.erase(scopeName);
40 }
41 
43  int newElemId = m_mappingSequence.getNextId();
44  MappingRawElement& elem = destination.addElement( newElemId );
46  elem.scopeName = element.scopeName();
47  if(elem.scopeName.empty()) elem.scopeName = MappingRawElement::emptyScope();
48  elem.variableName = element.variableName();
49  elem.variableType = element.variableType();
50  elem.tableName = element.tableName();
51  elem.columns = element.columnNames();
52  for ( MappingElement::const_iterator iSubEl = element.begin();
53  iSubEl != element.end(); ++iSubEl) {
54  unfoldElement( iSubEl->second, destination );
55  }
56 }
57 
59  m_schema( schema ),
60  m_mappingSequence( MappingRules::sequenceNameForMapping(), schema ),
61  m_versions(),
62  m_isLoaded( false ){
63 }
64 
65 
67 }
68 
69 std::string
70 ora::MappingDatabase::newMappingVersionForContainer( const std::string& containerName ){
71  if(!m_isLoaded){
72  m_schema.mappingSchema().getVersionList( m_versions );
73  m_isLoaded = true;
74  }
75 
76  std::string newMappingVersion = "";
77  for ( int iteration = 0;; ++iteration ) {
78  newMappingVersion = MappingRules::newMappingVersionForContainer( containerName, iteration );
79  bool found = false;
80  for ( std::set<std::string>::reverse_iterator iVersion = m_versions.rbegin();
81  iVersion != m_versions.rend(); ++iVersion ) {
82  if ( *iVersion == newMappingVersion ) {
83  found = true;
84  break;
85  }
86  }
87  if ( ! found ){
88  m_versions.insert( newMappingVersion );
89  break;
90  }
91 
92  }
93  return newMappingVersion;
94 }
95 
96 std::string
97 ora::MappingDatabase::newMappingVersionForDependentClass( const std::string& containerName, const std::string& className ){
98  if(!m_isLoaded){
99  m_schema.mappingSchema().getVersionList( m_versions );
100  m_isLoaded = true;
101  }
102 
103  std::string newMappingVersion = "";
104  for ( int iteration = 0;; ++iteration ) {
105  newMappingVersion = MappingRules::newMappingVersionForDependentClass( containerName, className, iteration );
106  bool found = false;
107  for ( std::set<std::string>::reverse_iterator iVersion = m_versions.rbegin();
108  iVersion != m_versions.rend(); ++iVersion ) {
109  if ( *iVersion == newMappingVersion ) {
110  found = true;
111  break;
112  }
113  }
114  if ( ! found ){
115  m_versions.insert( newMappingVersion );
116  break;
117  }
118 
119  }
120  return newMappingVersion;
121 }
122 
123 bool ora::MappingDatabase::getMappingByVersion( const std::string& version, MappingTree& destination ){
124  bool ret = false;
125  MappingRawData mapData;
126  if(m_schema.mappingSchema().getMapping( version, mapData )){
127  ret = true;
128  MappingRawElement topLevelElement;
129  bool topLevelFound = false;
130  bool dependency = false;
131  std::map<std::string, std::vector<MappingRawElement> > innerElements;
132  for( std::map< int, MappingRawElement>::iterator iElem = mapData.elements.begin();
133  iElem != mapData.elements.end(); iElem++ ){
134  // first loading the top level elements
135  if( iElem->second.scopeName == MappingRawElement::emptyScope() ){
136  if( iElem->second.elementType == MappingElement::classMappingElementType() ||
137  iElem->second.elementType == MappingElement::dependencyMappingElementType() ){
138  if( topLevelFound ){
139  throwException("Mapping inconsistent.More then one top level element found.",
140  "MappingDatabase::getMappingByVersion");
141  }
142  topLevelElement = iElem->second;
143  if( topLevelElement.elementType == MappingElement::dependencyMappingElementType() ) dependency = true;
144  topLevelFound = true;
145  }
146  } else {
147  std::map<std::string, std::vector<MappingRawElement> >::iterator iN = innerElements.find( iElem->second.scopeName );
148  if(iN==innerElements.end()){
149  innerElements.insert( std::make_pair( iElem->second.scopeName, std::vector<MappingRawElement>(1,iElem->second) ) );
150  } else {
151  iN->second.push_back( iElem->second );
152  }
153  }
154  }
155  if( !topLevelFound ){
156  throwException( "Could not find top element for mapping version \""+version+"\".",
157  "MappingDatabase::getMappingByVersion" );
158  }
159  MappingElement& topElement = destination.setTopElement( topLevelElement.variableName,
160  topLevelElement.tableName,
161  dependency );
162  topElement.setColumnNames( topLevelElement.columns);
163  buildElement( topElement, topLevelElement.variableName, innerElements );
164  destination.setVersion( version );
165  }
166  return ret;
167 }
168 
169 void ora::MappingDatabase::removeMapping( const std::string& version ){
170  m_schema.mappingSchema().removeMapping( version );
171 }
172 
173 bool
175  int containerId,
176  MappingTree& destination ){
177 
178  bool ret = false;
179  // The class parameters
180  std::string className = containerClass.Name(Reflex::SCOPED);
181  std::string classVersion = versionOfClass( containerClass );
182  std::string classId = MappingRules::classId( className, classVersion );
183 
184  std::string version("");
185  bool found = m_schema.mappingSchema().selectMappingVersion( classId, containerId, version );
186 
187  if( found ){
188  ret = getMappingByVersion( version, destination );
189  if( !ret ){
190  throwException("Mapping version \""+version+"\" not found.",
191  "MappingDatabase::getMappingForContainer");
192  }
193  if( destination.className() != className ){
194  throwException("Mapping inconsistency detected for version=\""+version+"\"",
195  "MappingDatabase::getMappingForContainer");
196  }
197  }
198  return ret;
199 }
200 
202  int containerId,
203  MappingTree& destination ){
204  bool ret = false;
205  std::string classId = MappingRules::baseIdForClass( className );
206  std::string mappingVersion("");
207  bool found = m_schema.mappingSchema().selectMappingVersion( classId, containerId, mappingVersion );
208 
209  if( found ){
210  ret = getMappingByVersion( mappingVersion, destination );
211  if( !ret ){
212  throwException("Mapping version \""+mappingVersion+"\" not found.",
213  "MappingDatabase::getBaseMappingForContainer");
214  }
215  if( destination.className() != className ){
216  throwException("Mapping inconsistency detected for version=\""+mappingVersion+"\"",
217  "MappingDatabase::getBaseMappingForContainer");
218  }
219  }
220  return ret;
221 }
222 
224  std::vector<MappingElement>& destination ){
225  bool ret = false;
226  std::set<std::string> versions;
227  if( m_schema.mappingSchema().getMappingVersionListForContainer( containerId, versions, true ) ){
228  ret = true;
229  for( std::set<std::string>::iterator iM = versions.begin();
230  iM != versions.end(); ++iM ){
231  MappingTree mapping;
232  if( ! getMappingByVersion( *iM, mapping )){
233  throwException("Mapping version \""+*iM+"\" not found.",
234  "MappingDatabase::getDependentMappingsForContainer");
235 
236  }
237  destination.push_back( mapping.topElement() );
238  }
239  }
240  return ret;
241 }
242 
243 bool ora::MappingDatabase::getClassVersionListForMappingVersion( const std::string& mappingVersion,
244  std::set<std::string>& destination ){
245  return m_schema.mappingSchema().getClassVersionListForMappingVersion( mappingVersion, destination );
246 }
247 
249  const std::string& classVersion,
250  int dependencyIndex,
251  int containerId,
252  const std::string& mappingVersion,
253  bool asBase ){
254  std::string classId = MappingRules::classId( className, classVersion );
255  m_schema.mappingSchema().insertClassVersion( className, classVersion, classId, dependencyIndex, containerId, mappingVersion );
256  if( asBase ){
257  m_schema.mappingSchema().insertClassVersion( className, MappingRules::baseClassVersion(), MappingRules::baseIdForClass( className ), dependencyIndex, containerId, mappingVersion );
258  }
259 }
260 
262  std::map<std::string,std::string>& versionMap ){
263 
264  return m_schema.mappingSchema().getClassVersionListForContainer( containerId, versionMap );
265 }
266 
268  int depIndex,
269  int containerId,
270  const std::string& mappingVersion,
271  bool asBase ){
272  std::string className = dictionaryEntry.Name( Reflex::SCOPED );
273  std::string classVersion = versionOfClass( dictionaryEntry );
274  insertClassVersion( className, classVersion, depIndex, containerId, mappingVersion, asBase );
275 }
276 
278  int containerId,
279  const std::string& mappingVersion,
280  bool dependency ){
281  std::string className = dictionaryEntry.Name( Reflex::SCOPED );
282  std::string classVersion = versionOfClass( dictionaryEntry );
283  std::string classId = MappingRules::classId( className, classVersion );
284  std::string mv("");
285  bool found = m_schema.mappingSchema().selectMappingVersion( classId, containerId, mv );
286  if( !found ){
287  int depIndex = 0;
288  if( dependency ) depIndex = 1;
289  m_schema.mappingSchema().insertClassVersion( className, classVersion, classId, depIndex, containerId, mappingVersion );
290  } else {
291  m_schema.mappingSchema().setMappingVersion( classId, containerId, mappingVersion );
292  }
293 }
294 
296  MappingRawData rowMapping( mapping.version() );
297  unfoldElement( mapping.topElement(), rowMapping );
298  m_mappingSequence.sinchronize();
299  m_schema.mappingSchema().storeMapping( rowMapping );
300 }
301 
302 bool ora::MappingDatabase::getMappingVersionsForContainer( int containerId, std::set<std::string>& versionList ){
303  return m_schema.mappingSchema().getMappingVersionListForContainer( containerId, versionList );
304 }
305 
306 const std::set<std::string>& ora::MappingDatabase::versions(){
307  if(!m_isLoaded){
308  m_schema.mappingSchema().getVersionList( m_versions );
309  m_isLoaded = true;
310  }
311  return m_versions;
312 }
313 
315  std::set<std::string>& list ){
316  return m_schema.mappingSchema().getDependentClassesInContainerMapping( containerId, list );
317 }
318 
320  m_versions.clear();
321  m_isLoaded = false;
322 }
323 
MappingDatabase(IDatabaseSchema &schema)
Constructor.
MappingRawElement & addElement(int elementId)
bool getDependentMappingsForContainer(int containerId, std::vector< MappingElement > &destination)
bool getBaseMappingForContainer(const std::string &className, int containerId, MappingTree &destination)
const std::string & className() const
Definition: MappingTree.h:134
std::vector< std::string > columns
static std::string newMappingVersionForContainer(const std::string &containerName, int iteration)
mapping versions
const std::string & variableName() const
static std::string dependencyMappingElementType()
Returns the name of the dependent class mapping element type.
bool getClassVersionListForMappingVersion(const std::string &mappingVersion, std::set< std::string > &destination)
void setMappingVersionForClass(const Reflex::Type &dictionaryEntry, int containerId, const std::string &mappingVersion, bool dependency=false)
const std::string & version() const
Definition: MappingTree.h:124
void buildElement(MappingElement &parentElement, const std::string &scopeName, std::map< std::string, std::vector< MappingRawElement > > &innerElements)
static std::string baseIdForClass(const std::string &className)
Definition: MappingRules.cc:61
std::map< int, MappingRawElement > elements
void insertClassVersion(const Reflex::Type &dictionaryEntry, int dependencyIndex, int containerId, const std::string &mappingVersion, bool asBase=false)
ElementType elementType() const
void unfoldElement(const MappingElement &element, MappingRawData &destination)
MappingElement & setTopElement(const std::string &className, const std::string &tableName, bool isDependent=false)
Definition: MappingTree.cc:40
std::string newMappingVersionForDependentClass(const std::string &containerName, const std::string &className)
MappingElement & appendSubElement(const std::string &elementType, const std::string &variableName, const std::string &variableType, const std::string &tableName)
bool getMappingVersionsForContainer(int containerId, std::set< std::string > &versionList)
void storeMapping(const MappingTree &mappingStructure)
bool getMappingForContainer(const Reflex::Type &containerClass, int containerId, MappingTree &destination)
iterator begin()
Returns an iterator in the beginning of the sequence.
tuple iteration
Definition: align_cfg.py:5
static std::string elementTypeAsString(ElementType elementType)
Converts the enumeration type to a string.
static std::string defaultClassVersion(const std::string &className)
Definition: MappingRules.cc:83
static std::string emptyScope()
const MappingElement & topElement() const
Definition: MappingTree.h:139
~MappingDatabase()
Destructor.
const std::vector< std::string > & columnNames() const
bool getClassVersionListForContainer(int containerId, std::map< std::string, std::string > &versionMap)
static std::string versionOfClass(const Reflex::Type &dictionary)
std::string newMappingVersionForContainer(const std::string &className)
bool getDependentClassesForContainer(int containerId, std::set< std::string > &list)
bool getMappingByVersion(const std::string &version, MappingTree &destination)
const std::set< std::string > & versions()
const std::string & variableType() const
std::map< std::string, MappingElement >::const_iterator const_iterator
iterator end()
Returns an iterator in the end of the sequence.
static std::string baseClassVersion()
Definition: MappingRules.cc:66
void setVersion(const std::string &version)
Definition: MappingTree.h:129
static std::string classId(const std::string &className, const std::string &classVersion)
Definition: MappingRules.cc:46
const std::string & tableName() const
void throwException(const std::string &message, const std::string &methodName)
Definition: Exception.cc:10
static std::string newMappingVersionForDependentClass(const std::string &containerName, const std::string &className, int iteration)
static std::string classVersionPropertyNameInDictionary()
Definition: MappingRules.cc:91
static std::string classMappingElementType()
Returns the name of the class mapping element type.
void removeMapping(const std::string &version)
const std::string & scopeName() const
std::string className(const T &t)
Definition: ClassName.h:30
void setColumnNames(const std::vector< std::string > &columns)
How EventSelector::AcceptEvent() decides whether to accept an event for output otherwise it is excluding the probing of A single or multiple positive and the trigger will pass if any such matching triggers are PASS or EXCEPTION[A criterion thatmatches no triggers at all is detected and causes a throw.] A single negative with an expectation of appropriate bit checking in the decision and the trigger will pass if any such matching triggers are FAIL or EXCEPTION A wildcarded negative criterion that matches more than one trigger in the trigger list("!*","!HLTx*"if it matches 2 triggers or more) will accept the event if all the matching triggers are FAIL.It will reject the event if any of the triggers are PASS or EXCEPTION(this matches the behavior of"!*"before the partial wildcard feature was incorporated).Triggers which are in the READY state are completely ignored.(READY should never be returned since the trigger paths have been run