TSchemaRule.cxx

Go to the documentation of this file.
00001 // @(#)root/core:$Id: TSchemaRule.cxx 34885 2010-08-20 13:33:08Z pcanal $
00002 // author: Lukasz Janyst <ljanyst@cern.ch>
00003 
00004 #include "TSchemaRule.h"
00005 #include "TSchemaRuleProcessor.h"
00006 #include "TObjArray.h"
00007 #include "TObjString.h"
00008 #include "TNamed.h"
00009 #include <utility>
00010 #include <iostream>
00011 #include <vector>
00012 #include <list>
00013 #include <string>
00014 #include <cstdlib>
00015 #include "TROOT.h"
00016 #include "Riostream.h"
00017 
00018 #include "RConversionRuleParser.h"
00019 
00020 ClassImp(TSchemaRule)
00021 
00022 using namespace ROOT;
00023 
00024 //------------------------------------------------------------------------------
00025 TSchemaRule::TSchemaRule(): fVersionVect( 0 ), fChecksumVect( 0 ),
00026                             fTargetVect( 0 ), fSourceVect( 0 ),
00027                             fIncludeVect( 0 ), fEmbed( kTRUE ), 
00028                             fReadFuncPtr( 0 ), fReadRawFuncPtr( 0 ),
00029                             fRuleType( kNone )
00030 {
00031    // Default Constructor.
00032    
00033 }
00034 
00035 //------------------------------------------------------------------------------
00036 TSchemaRule::~TSchemaRule()
00037 {
00038    // Destructor.
00039    
00040    delete fVersionVect;
00041    delete fChecksumVect;
00042    delete fTargetVect;
00043    delete fSourceVect;
00044    delete fIncludeVect;
00045 }
00046 
00047 //------------------------------------------------------------------------------
00048 TSchemaRule::TSchemaRule( const TSchemaRule& rhs ): TObject( rhs ),
00049                             fVersionVect( 0 ), fChecksumVect( 0 ),
00050                             fTargetVect( 0 ), fSourceVect( 0 ),
00051                             fIncludeVect( 0 ), fEmbed( kTRUE ), 
00052                             fReadFuncPtr( 0 ), fReadRawFuncPtr( 0 ),
00053                             fRuleType( kNone )
00054 {
00055    // Copy Constructor.
00056    *this = rhs;
00057 }
00058 
00059 //------------------------------------------------------------------------------
00060 TSchemaRule& TSchemaRule::operator = ( const TSchemaRule& rhs )
00061 {
00062    // Copy operator.
00063    
00064    if( this != &rhs ) {
00065       fVersion        = rhs.fVersion;
00066       fChecksum       = rhs.fChecksum;
00067       fSourceClass    = rhs.fSourceClass;
00068       fTarget         = rhs.fTarget;
00069       fSource         = rhs.fSource;
00070       fInclude        = rhs.fInclude;
00071       fCode           = rhs.fCode;
00072       fEmbed          = rhs.fEmbed;
00073       fReadFuncPtr    = rhs.fReadFuncPtr;
00074       fReadRawFuncPtr = rhs.fReadRawFuncPtr;
00075       fRuleType       = rhs.fRuleType;
00076       fAttributes     = rhs.fAttributes;
00077    }
00078    return *this;
00079 }
00080 
00081 //------------------------------------------------------------------------------
00082 Bool_t TSchemaRule::operator == ( const TSchemaRule& rhs )
00083 {
00084    // Return true if the rule have the same effects.
00085    
00086    if( this != &rhs ) {
00087       Bool_t result = ( fVersion == rhs.fVersion 
00088                        && fChecksum == rhs.fChecksum
00089                        && fSourceClass == rhs.fSourceClass
00090                        && fTargetClass == rhs.fTargetClass
00091                        && fSource == rhs.fSource
00092                        && fTarget == rhs.fTarget
00093                        && fInclude == rhs.fInclude
00094                        && fCode == rhs.fCode
00095                        && fEmbed == rhs.fEmbed
00096                        && fRuleType == rhs.fRuleType
00097                        && fAttributes == rhs.fAttributes );
00098       if (result && 
00099           ( (fReadRawFuncPtr != rhs.fReadRawFuncPtr && fReadRawFuncPtr != 0 && rhs.fReadRawFuncPtr != 0)
00100            ||  (fReadFuncPtr != rhs.fReadFuncPtr && fReadFuncPtr != 0 && rhs.fReadFuncPtr != 0) ) )
00101       {
00102          result = kFALSE;
00103       }
00104 
00105       return result;
00106    }
00107    return kTRUE;
00108 }
00109 
00110 //------------------------------------------------------------------------------
00111 void TSchemaRule::ls(Option_t *targetname) const
00112 {
00113    // The ls function lists the contents of a class on stdout. Ls output
00114    // is typically much less verbose then Dump().
00115    
00116    TROOT::IndentLevel();
00117    cout << "Schema Evolution Rule: ";
00118    if (fRuleType==kReadRule) cout <<  "read ";
00119    else if (fRuleType==kReadRawRule) cout << "readraw ";
00120    cout << "\n";
00121    TROOT::IncreaseDirLevel();
00122    TROOT::IndentLevel();
00123    cout << "sourceClass=\"" << fSourceClass << "\" ";
00124    if (fVersion.Length())  cout << "version=\"" << fVersion << "\" ";
00125    if (fChecksum.Length()) cout << "checksum=\"" << fChecksum << "\" ";
00126    if (targetname && targetname[0]) cout << "targetClass=\"" << targetname << "\" ";
00127    else cout << "targetClass\"" << fTargetClass << "\" ";
00128    cout << "\n";
00129    TROOT::IndentLevel();
00130    cout << "source=\"" << fSource << "\" ";
00131    cout << "target=\"" << fTarget << "\" ";
00132    cout << "\n";
00133    if (fInclude.Length()) {
00134       TROOT::IndentLevel();
00135       cout << "include=\"" << fInclude << "\" " << "\n";
00136    }
00137    if (fAttributes.Length()) {
00138       TROOT::IndentLevel();
00139       cout << "attributes=\"" << fAttributes << "\"" << "\n";
00140    }
00141    if (fCode.Length()) {
00142       TROOT::IndentLevel();
00143       cout << "code=\"{" << fCode << "}\" "
00144       << "\n";
00145    }
00146    TROOT::DecreaseDirLevel();
00147 }
00148 
00149 //------------------------------------------------------------------------------
00150 void TSchemaRule::AsString(TString &out, const char *options) const
00151 {
00152    // Add to the string 'out' the string representation of the rule.
00153    // if options contains:
00154    //  's' : add the short form of the rule is possible
00155    //  'x' : add the xml form of the rule
00156    
00157    TString opt(options);
00158    opt.ToLower();
00159    Bool_t shortform = opt.Contains('s');
00160    Bool_t xmlform = opt.Contains('x');
00161    
00162    TString end;
00163    if (xmlform) {  
00164       /* 
00165        <read sourceClass="ClassA" version="[2]" targetClass="ClassA" source="int m_unit;" target="m_unit" >
00166        <![CDATA[ { m_unit = 10*onfile.m_unit; } ]]>
00167        </read>
00168        */
00169       shortform = kFALSE;
00170       out += "<";
00171       if (fRuleType==kReadRule) { out += "read "; end = "</read>"; }
00172       else if (fRuleType==kReadRawRule) { out += "readraw "; end = "</readraw>"; }
00173       else { out += "-- "; end = "-->"; }
00174       
00175    } else {
00176       if (!shortform || fRuleType!=kReadRule) {
00177          out += "type=";
00178          if (fRuleType==kReadRule) out += "read ";
00179          else if (fRuleType==kReadRawRule) out += "readraw ";
00180          else out += " ";
00181       }
00182    }
00183    if (!shortform || (fSourceClass != fTargetClass) ) {
00184       out += "sourceClass=\"" + fSourceClass + "\" ";
00185       out += "targetClass=\"" + fTargetClass + "\" ";
00186    } else {
00187       out += fSourceClass + " ";
00188    }
00189    if (shortform && fTarget == fSource) {
00190       out += fSource + " ";
00191    }
00192    if (!shortform || (fVersion != "[1-]")) {
00193       if (fVersion.Length())  out += "version=\""     + fVersion + "\" ";
00194    }
00195    if (fChecksum.Length()) out += "checksum=\""    + fChecksum + "\" ";
00196    if (!shortform || fTarget != fSource) {
00197       out += "source=\""      + fSource + "\" ";
00198       out += "target=\""      + fTarget + "\" ";
00199    }
00200    if (fInclude.Length())  out += "include=\""     + fInclude + "\" ";
00201    if (fAttributes.Length()) out += "attributes=\"" + fAttributes + "\" ";
00202    if (xmlform) {
00203       out += "> ";
00204    }
00205    if (xmlform) {
00206       if (fCode.Length()) {
00207          out += "\n<![CDATA[ { " + fCode + " ]]>\n ";
00208       } else if (fReadFuncPtr) {
00209          // Can we guess?
00210          // out += "code=\" + nameof(fReadFuncPtr) + "\" ";
00211       } else if (fReadRawFuncPtr) {
00212          // Can we guess?
00213          // out += "code=\" + nameof(fReadRawFuncPtr) + "\" ";      
00214       }
00215    } else {
00216       if (fCode.Length()) {
00217          out += "code=\"{" + fCode + "}\" ";
00218       } else if (fReadFuncPtr) {
00219          // Can we guess?
00220          // out += "code=\" + nameof(fReadFuncPtr) + "\" ";
00221       } else if (fReadRawFuncPtr) {
00222          // Can we guess?
00223          // out += "code=\" + nameof(fReadRawFuncPtr) + "\" ";      
00224       }
00225    }
00226    if (xmlform) {
00227       out += end;
00228    }
00229 }
00230 
00231 //------------------------------------------------------------------------------
00232 void TSchemaRule::Clear( const char * /* option */)
00233 {
00234    // Zero out this rule object.
00235    
00236    fVersion.Clear();
00237    fChecksum.Clear();
00238    fSourceClass.Clear();
00239    fTarget.Clear();
00240    fSource.Clear();
00241    fInclude.Clear();
00242    fCode.Clear();
00243    fAttributes.Clear();
00244    fReadRawFuncPtr = 0;
00245    fReadFuncPtr = 0;
00246    fRuleType = kNone;
00247    delete fVersionVect;   fVersionVect = 0;
00248    delete fChecksumVect;  fChecksumVect = 0;
00249    delete fTargetVect;    fTargetVect = 0;
00250    delete fSourceVect;    fSourceVect = 0;
00251    delete fIncludeVect;   fIncludeVect = 0;
00252 } 
00253 
00254 //------------------------------------------------------------------------------
00255 Bool_t TSchemaRule::SetFromRule( const char *rule )
00256 {
00257    // Set the content fot this object from the rule
00258    // See TClass::AddRule for details on the syntax.
00259    
00260    //-----------------------------------------------------------------------
00261    // Parse the rule and check it's validity
00262    //-----------------------------------------------------------------------
00263    ROOT::MembersMap_t rule_values;
00264    
00265    std::string error_string;
00266    if( !ParseRule( rule, rule_values, error_string) ) {
00267       Error("SetFromRule","The rule (%s) is invalid: %s",rule,error_string.c_str());
00268       return kFALSE;
00269    }
00270    ROOT::MembersMap_t ::const_iterator it1;
00271    
00272    it1 = rule_values.find( "type" );
00273    if( it1 != rule_values.end() ) {
00274       if (it1->second == "read" || it1->second == "Read") {
00275          SetRuleType( TSchemaRule::kReadRule );
00276       } else if (it1->second == "readraw" || it1->second == "ReadRaw") {
00277          SetRuleType( TSchemaRule::kReadRawRule );
00278       } else {
00279          SetRuleType( TSchemaRule::kNone );
00280       }         
00281    } else {
00282       // Default to read.
00283       SetRuleType( TSchemaRule::kReadRule );
00284    }
00285    it1 = rule_values.find( "targetClass" );
00286    if( it1 != rule_values.end() ) SetTargetClass( it1->second );
00287    it1 = rule_values.find( "sourceClass" );
00288    if( it1 != rule_values.end() ) SetSourceClass( it1->second );
00289    it1 = rule_values.find( "target" );
00290    if( it1 != rule_values.end() ) SetTarget( it1->second );
00291    it1 = rule_values.find( "source" );
00292    if( it1 != rule_values.end() ) SetSource( it1->second );
00293    it1 = rule_values.find( "version" );
00294    if( it1 != rule_values.end() ) SetVersion( it1->second );
00295    it1 = rule_values.find( "checksum" );
00296    if( it1 != rule_values.end() ) SetChecksum( it1->second );
00297    it1 = rule_values.find( "embed" );
00298    if( it1 != rule_values.end() ) SetEmbed( it1->second == "false" ? false : true );
00299    it1 = rule_values.find( "include" );
00300    if( it1 != rule_values.end() ) SetInclude( it1->second );
00301    it1 = rule_values.find( "attributes" );
00302    if( it1 != rule_values.end() ) SetAttributes( it1->second );
00303    it1 = rule_values.find( "code" );
00304    if( it1 != rule_values.end() ) SetCode( it1->second );
00305    // if (code is functioname) {
00306    // switch (ruleobj->GetRuleType() ) {
00307    // case kRead: SetReadFunctionPointer(  )
00308    // case kReadRewa: SetReadRawFunctionPointer( )
00309    // }
00310 
00311    return kTRUE;
00312 } 
00313 
00314 //------------------------------------------------------------------------------
00315 Bool_t TSchemaRule::SetVersion( const TString& version )
00316 {
00317    // Set the version string - returns kFALSE if the format is incorrect
00318 
00319    fVersion = "";
00320    Bool_t ret = ProcessVersion( version );
00321    if( ret )
00322       fVersion = version;
00323    return ret;
00324 }
00325 
00326 //------------------------------------------------------------------------------
00327 const char *TSchemaRule::GetVersion() const
00328 {
00329    // Get the version string.
00330    
00331    return fVersion;
00332 }
00333 
00334 
00335 //------------------------------------------------------------------------------
00336 Bool_t TSchemaRule::TestVersion( Int_t version ) const
00337 {
00338    // Check if given version number is defined in this rule
00339 
00340    if( fVersion == "" )
00341       return kFALSE;
00342 
00343    if( !fVersionVect )
00344       ProcessVersion( fVersion ); // At this point the version string should always be correct
00345 
00346    std::vector<std::pair<Int_t, Int_t> >::iterator it;
00347    for( it = fVersionVect->begin(); it != fVersionVect->end(); ++it ) {
00348       if( version >= it->first && version <= it->second )
00349          return kTRUE;
00350    }
00351    return kFALSE;
00352 }
00353 
00354 //------------------------------------------------------------------------------
00355 Bool_t TSchemaRule::SetChecksum( const TString& checksum )
00356 {
00357    // Set the checksum string - returns kFALSE if the format is incorrect
00358    fChecksum = "";
00359    Bool_t ret = ProcessChecksum( checksum );
00360    if( ret )
00361       fChecksum = checksum;
00362    return ret;
00363 }
00364 
00365 //------------------------------------------------------------------------------
00366 Bool_t TSchemaRule::TestChecksum( UInt_t checksum ) const
00367 {
00368    // Check if given checksum is defined in this rule
00369 
00370    if( fChecksum == "" )
00371       return kFALSE;
00372 
00373    if( !fChecksumVect )
00374       ProcessChecksum( fChecksum ); // At this point the checksum string should always be correct
00375 
00376    std::vector<UInt_t>::iterator it;
00377    for( it = fChecksumVect->begin(); it != fChecksumVect->end(); ++it ) {
00378       if( checksum == *it )
00379          return kTRUE;
00380    }
00381    return kFALSE;
00382 }
00383 
00384 //------------------------------------------------------------------------------
00385 void TSchemaRule::SetSourceClass( const TString& classname )
00386 {
00387    // Set the source class of this rule (i.e. the onfile class).
00388    
00389    fSourceClass = classname;
00390 }
00391 
00392 //------------------------------------------------------------------------------
00393 const char *TSchemaRule::GetSourceClass() const
00394 {
00395    // Get the source class of this rule (i.e. the onfile class).
00396    
00397    return fSourceClass;
00398 }
00399 
00400 //------------------------------------------------------------------------------
00401 void TSchemaRule::SetTargetClass( const TString& classname )
00402 {
00403    // Set the target class of this rule (i.e. the in memory class).
00404    
00405    fTargetClass = classname;
00406 }
00407 
00408 //------------------------------------------------------------------------------
00409 const char *TSchemaRule::GetTargetClass() const
00410 {
00411    // Get the targte class of this rule (i.e. the in memory class).
00412    
00413    return fTargetClass;
00414 }
00415 
00416 //------------------------------------------------------------------------------
00417 void TSchemaRule::SetTarget( const TString& target )
00418 {
00419    // Set the target member of this rule (i.e. the in memory data member).
00420 
00421    fTarget = target;
00422 
00423    if( target == "" ) {
00424       delete fTargetVect;
00425       fTargetVect = 0;
00426       return;
00427    }
00428 
00429    if( !fTargetVect ) {
00430       fTargetVect = new TObjArray();
00431       fTargetVect->SetOwner();
00432    }
00433    ProcessList( fTargetVect, target );
00434 }
00435 
00436 //------------------------------------------------------------------------------
00437 const char *TSchemaRule::GetTargetString() const
00438 {
00439    // Get the target data members of this rule as a simple string (i.e. the in memory data member).
00440    
00441    return fTarget;
00442 }
00443 
00444 //------------------------------------------------------------------------------
00445 const TObjArray*  TSchemaRule::GetTarget() const
00446 {
00447    // Get the target data members of this rule (i.e. the in memory data member).
00448 
00449    if( fTarget == "" )
00450       return 0;
00451 
00452    if( !fTargetVect ) {
00453       fTargetVect = new TObjArray();
00454       fTargetVect->SetOwner();
00455       ProcessList( fTargetVect, fTarget );
00456    }
00457 
00458    return fTargetVect;
00459 }
00460 
00461 //------------------------------------------------------------------------------
00462 void TSchemaRule::SetSource( const TString& source )
00463 {
00464    // Set the list of source members.  This should be in the form of a declaration:
00465    //     Int_t fOldMember; TNamed fName;
00466    
00467    fSource = source;
00468 
00469    if( source == "" ) {
00470       delete fSourceVect;
00471       fSourceVect = 0;
00472       return;
00473    }
00474 
00475    if( !fSourceVect ) {
00476       fSourceVect = new TObjArray();
00477       fSourceVect->SetOwner();
00478    }
00479 
00480    ProcessDeclaration( fSourceVect, source );
00481 }
00482 
00483 //------------------------------------------------------------------------------
00484 const TObjArray* TSchemaRule::GetSource() const
00485 {
00486    // Get the list of source members as a TObjArray of TNamed object,
00487    // with the name being the member name and the title being its type.
00488    
00489    if( fSource == "" )
00490       return 0;
00491 
00492    if( !fSourceVect ) {
00493       fSourceVect = new TObjArray();
00494       fSourceVect->SetOwner();
00495       ProcessDeclaration( fSourceVect, fSource );
00496    }
00497    return fSourceVect;
00498 }
00499 
00500 //------------------------------------------------------------------------------
00501 void TSchemaRule::SetInclude( const TString& incl )
00502 {
00503    // Set the comma separated list of header files to include to be able
00504    // to compile this rule.
00505    
00506    fInclude = incl;
00507 
00508    if( incl == "" ) {
00509       delete fIncludeVect;
00510       fIncludeVect = 0;
00511       return;
00512    }
00513 
00514    if( !fIncludeVect ) {
00515       fIncludeVect = new TObjArray();
00516       fIncludeVect->SetOwner();
00517    }
00518 
00519    ProcessList( fIncludeVect, incl );
00520 }
00521 
00522 //------------------------------------------------------------------------------
00523 const TObjArray* TSchemaRule::GetInclude() const
00524 {
00525    // Return the list of header files to include to be able to
00526    // compile this rule as a TObjArray of TObjString
00527    
00528    if( fInclude == "" )
00529       return 0;
00530 
00531    if( !fIncludeVect ) {
00532       fIncludeVect = new TObjArray();
00533       fIncludeVect->SetOwner();
00534       ProcessList( fIncludeVect, fInclude );
00535    }
00536 
00537    return fIncludeVect;
00538 }
00539 
00540 //------------------------------------------------------------------------------
00541 void TSchemaRule::SetEmbed( Bool_t embed )
00542 {
00543    // Set whether this rule should be save in the ROOT file (if true)
00544    
00545    fEmbed = embed;
00546 }
00547 
00548 //------------------------------------------------------------------------------
00549 Bool_t TSchemaRule::GetEmbed() const
00550 {
00551    // Return true if this rule should be saved in the ROOT File.
00552    
00553    return fEmbed;
00554 }
00555 
00556 //------------------------------------------------------------------------------
00557 Bool_t TSchemaRule::IsValid() const
00558 {
00559    // Return kTRUE if this rule is valid.
00560    
00561    return (fVersionVect || fChecksumVect) && (fSourceClass.Length() != 0); 
00562 }
00563 
00564 //------------------------------------------------------------------------------
00565 void TSchemaRule::SetCode( const TString& code )
00566 {
00567    // Set the source code of this rule.
00568    
00569    fCode = code;
00570 }
00571 
00572 //------------------------------------------------------------------------------
00573 const char *TSchemaRule::GetCode() const
00574 {
00575    // Get the source code of this rule.
00576    
00577    return fCode;
00578 }
00579 
00580 //------------------------------------------------------------------------------
00581 void TSchemaRule::SetAttributes( const TString& attributes )
00582 {
00583    // Set the attributes code of this rule.
00584    
00585    fAttributes = attributes;
00586 }
00587 
00588 //------------------------------------------------------------------------------
00589 const char *TSchemaRule::GetAttributes() const
00590 {
00591    // Get the attributes code of this rule.
00592    
00593    return fAttributes;
00594 }
00595 
00596 //------------------------------------------------------------------------------
00597 Bool_t TSchemaRule::HasTarget( const TString& target ) const
00598 {
00599    // Return true if one of the rule's data member target  is 'target'.
00600    
00601    if( !fTargetVect )
00602       return kFALSE;
00603 
00604    TObject*      obj;
00605    TObjArrayIter it( fTargetVect );
00606    while( (obj = it.Next()) ) {
00607       TObjString* str = (TObjString*)obj;
00608       if( str->GetString() == target )
00609          return kTRUE;
00610    }
00611    return kFALSE;
00612 }
00613 
00614 //------------------------------------------------------------------------------
00615 Bool_t TSchemaRule::HasSource( const TString& source ) const
00616 {
00617    // Return true if one of the rule's data member source is 'source'
00618    if( !fSourceVect )
00619       return kFALSE;
00620 
00621    TObject*      obj;
00622    TObjArrayIter it( fSourceVect );
00623    while( (obj = it.Next()) ) {
00624       TSources* var = (TSources*)obj;
00625       if( var->GetName() == source )
00626          return kTRUE;
00627    }
00628    return kFALSE;
00629 }
00630 
00631 //------------------------------------------------------------------------------
00632 void TSchemaRule::SetReadFunctionPointer( TSchemaRule::ReadFuncPtr_t ptr )
00633 {
00634    // Set the pointer to the function to be run for the rule (if it is a read rule).
00635    
00636    fReadFuncPtr = ptr;
00637 }
00638 
00639 //------------------------------------------------------------------------------
00640 TSchemaRule::ReadFuncPtr_t TSchemaRule::GetReadFunctionPointer() const
00641 {
00642    // Get the pointer to the function to be run for the rule (if it is a read rule).
00643 
00644    return fReadFuncPtr;
00645 }
00646 
00647 //------------------------------------------------------------------------------
00648 void TSchemaRule::SetReadRawFunctionPointer( TSchemaRule::ReadRawFuncPtr_t ptr )
00649 {
00650    // Set the pointer to the function to be run for the rule (if it is a raw read rule).
00651 
00652    fReadRawFuncPtr = ptr;
00653 }
00654 
00655 //------------------------------------------------------------------------------
00656 TSchemaRule::ReadRawFuncPtr_t TSchemaRule::GetReadRawFunctionPointer() const
00657 {
00658    // Get the pointer to the function to be run for the rule (if it is a raw read rule).
00659 
00660    return fReadRawFuncPtr;
00661 }
00662 
00663 //------------------------------------------------------------------------------
00664 void TSchemaRule::SetRuleType( TSchemaRule::RuleType_t type )
00665 {
00666    // Set the type of the rule.
00667    
00668    fRuleType = type;
00669 }
00670 
00671 //------------------------------------------------------------------------------
00672 Bool_t TSchemaRule::IsAliasRule() const
00673 {
00674    // Return kTRUE if the rule is a strict renaming of one of the data member of the class.
00675 
00676    return fSourceClass != "" && (fVersion != "" || fChecksum != "") && fTarget == "" && fSource == "" && fInclude == "" && fCode == "" && fAttributes == "";
00677 }
00678 
00679 //------------------------------------------------------------------------------
00680 Bool_t TSchemaRule::IsRenameRule() const
00681 {
00682    // Return kTRUE if the rule is a strict renaming of the class to a new name.
00683 
00684    return fSourceClass != "" && (fVersion != "" || fChecksum != "") && fTarget != "" && fSource != "" && fInclude == "" && fCode == "" && fAttributes == "";
00685 }
00686 
00687 //------------------------------------------------------------------------------
00688 TSchemaRule::RuleType_t TSchemaRule::GetRuleType() const
00689 {
00690    // Return the type of the rule.
00691    
00692    return fRuleType;
00693 }
00694 
00695 //------------------------------------------------------------------------------
00696 Bool_t TSchemaRule::Conflicts( const TSchemaRule* rule ) const
00697 {
00698    // Check if this rule conflicts with the given one.
00699 
00700    //---------------------------------------------------------------------------
00701    // If the rules have different sources then the don't conflict
00702    //---------------------------------------------------------------------------
00703    if( fSourceClass != rule->fSourceClass )
00704       return kFALSE;
00705 
00706    //---------------------------------------------------------------------------
00707    // Check if the rules have common target
00708    //---------------------------------------------------------------------------
00709    if( !rule->GetTarget() )
00710       return kFALSE;
00711 
00712    Bool_t         haveCommonTargets = kFALSE;
00713    TObjArrayIter  titer( rule->GetTarget() );
00714    TObjString    *str;
00715    TObject       *obj;
00716 
00717    while( (obj = titer.Next() ) ) {
00718       str = (TObjString*)obj;
00719       if( HasTarget( str->String() ) )
00720          haveCommonTargets = kTRUE;
00721    }
00722 
00723    if( !haveCommonTargets )
00724       return kFALSE;
00725 
00726    //---------------------------------------------------------------------------
00727    // Check if there are conflicting checksums
00728    //---------------------------------------------------------------------------
00729    if( fChecksumVect ) {
00730       std::vector<UInt_t>::iterator it;
00731       for( it = fChecksumVect->begin(); it != fChecksumVect->end(); ++it )
00732          if( rule->TestChecksum( *it ) )
00733             return kTRUE;
00734    }
00735 
00736    //---------------------------------------------------------------------------
00737    // Check if there are conflicting versions
00738    //---------------------------------------------------------------------------
00739    if( fVersionVect && rule->fVersionVect )
00740    {
00741       std::vector<std::pair<Int_t, Int_t> >::iterator it1;
00742       std::vector<std::pair<Int_t, Int_t> >::iterator it2;
00743       for( it1 = fVersionVect->begin(); it1 != fVersionVect->end(); ++it1 ) {
00744          for( it2 = rule->fVersionVect->begin();
00745               it2 != rule->fVersionVect->end(); ++it2 ) {
00746             //------------------------------------------------------------------
00747             // the rules conflict it their version ranges intersect
00748             //------------------------------------------------------------------
00749             if( it1->first >= it2->first && it1->first <= it2->second )
00750                return kTRUE;
00751 
00752             if( it1->first < it2->first && it1->second >= it2->first )
00753                return kTRUE;
00754          }
00755       }
00756    }
00757    return kFALSE;
00758 }
00759 
00760 //------------------------------------------------------------------------------
00761 Bool_t TSchemaRule::ProcessVersion( const TString& version ) const
00762 {
00763    // Check if specified version string is correct and build version vector.
00764 
00765    //---------------------------------------------------------------------------
00766    // Check if we have valid list
00767    //---------------------------------------------------------------------------
00768    if( version[0] != '[' || version[version.Length()-1] != ']' )
00769       return kFALSE;
00770    std::string ver = version.Data();
00771 
00772    std::list<std::string> versions;
00773    ROOT::TSchemaRuleProcessor::SplitList( ver.substr( 1, ver.size()-2), versions );
00774 
00775    if( versions.empty() )
00776    {
00777       delete fVersionVect;
00778       fVersionVect = 0;
00779       return kFALSE;
00780    }
00781 
00782    if( !fVersionVect )
00783       fVersionVect = new std::vector<std::pair<Int_t, Int_t> >;
00784    fVersionVect->clear();
00785 
00786    //---------------------------------------------------------------------------
00787    // Check the validity of each list element
00788    //---------------------------------------------------------------------------
00789    std::list<std::string>::iterator it;
00790    for( it = versions.begin(); it != versions.end(); ++it ) {
00791       std::pair<Int_t, Int_t> verpair;
00792       if( !ROOT::TSchemaRuleProcessor::ProcessVersion( *it, verpair ) )
00793       {
00794          delete fVersionVect;
00795          fVersionVect = 0;
00796          return kFALSE;
00797       }
00798       fVersionVect->push_back( verpair );
00799    }
00800    return kTRUE;
00801 }
00802 
00803 //------------------------------------------------------------------------------
00804 Bool_t TSchemaRule::ProcessChecksum( const TString& checksum ) const
00805 {
00806    // Check if specified checksum string is correct and build checksum vector.
00807    
00808    //---------------------------------------------------------------------------
00809    // Check if we have valid list
00810    //---------------------------------------------------------------------------
00811    if (!checksum[0])
00812       return kFALSE;
00813    std::string chk = (const char*)checksum;
00814    if( chk[0] != '[' || chk[chk.size()-1] != ']' )
00815       return kFALSE;
00816 
00817    std::list<std::string> checksums;
00818    ROOT::TSchemaRuleProcessor::SplitList( chk.substr( 1, chk.size()-2), checksums );
00819 
00820    if( checksums.empty() ) {
00821       delete fChecksumVect;
00822       fChecksumVect = 0;
00823       return kFALSE; 
00824    }
00825 
00826    if( !fChecksumVect )
00827       fChecksumVect = new std::vector<UInt_t>;
00828    fChecksumVect->clear();
00829 
00830    //---------------------------------------------------------------------------
00831    // Check the validity of each list element
00832    //---------------------------------------------------------------------------
00833    std::list<std::string>::iterator it;
00834    for( it = checksums.begin(); it != checksums.end(); ++it ) {
00835       if( !ROOT::TSchemaRuleProcessor::IsANumber( *it ) ) {
00836          delete fChecksumVect;
00837          fChecksumVect = 0;
00838          return kFALSE;
00839       }
00840       fChecksumVect->push_back( atoi( it->c_str() ) );
00841    }
00842    return kTRUE;
00843 }
00844 
00845 //------------------------------------------------------------------------------
00846 void TSchemaRule::ProcessList( TObjArray* array, const TString& list )
00847 {
00848    // Split the list as a comma separated list into a TObjArray of TObjString.
00849 
00850    std::list<std::string>           elems;
00851    std::list<std::string>::iterator it;
00852    ROOT::TSchemaRuleProcessor::SplitList( (const char*)list, elems );
00853 
00854    array->Clear();
00855 
00856    if( elems.empty() )
00857       return;
00858 
00859    for( it = elems.begin(); it != elems.end(); ++it ) {
00860       TObjString *str = new TObjString;
00861       *str = it->c_str();
00862       array->Add( str );
00863    }
00864 }
00865 
00866 //------------------------------------------------------------------------------
00867 void TSchemaRule::ProcessDeclaration( TObjArray* array, const TString& list )
00868 {
00869    // Split the list as a declaration into as a TObjArray of TNamed(name,type).
00870 
00871    std::list<std::pair<ROOT::TSchemaType,std::string> >           elems;
00872    std::list<std::pair<ROOT::TSchemaType,std::string> >::iterator it;
00873    ROOT::TSchemaRuleProcessor::SplitDeclaration( (const char*)list, elems );
00874 
00875    array->Clear();
00876 
00877    if( elems.empty() )
00878       return;
00879 
00880    for( it = elems.begin(); it != elems.end(); ++it ) {
00881       TSources *type = new TSources( it->second.c_str(), it->first.fType.c_str(), it->first.fDimensions.c_str() ) ;
00882       array->Add( type );
00883    }
00884 }
00885 
00886 #if 0
00887 //------------------------------------------------------------------------------
00888 Bool_t TSchemaRule::GenerateFor( TStreamerInfo *info )
00889 {
00890    // Generate the actual function for the rule.
00891 
00892    String funcname = fSourceClass + "_to_" + fTargetClass;
00893    if (info) funcname += "_v" + info->GetClassVersion();
00894    TString names = fSource + "_" + fTarget; 
00895    name.ReplaceAll(',','_');
00896    name.ReplaceAll(':','_');
00897    funcname += "_" + name;
00898 
00899    String filename = funcname + ".C";
00900    if (!false) {
00901       filename += '+';
00902    }
00903 
00904    std::ofstream fileout(filename);
00905 
00906 
00907       ROOT::WriteReadRawRuleFunc( *rIt, 0, mappedname, nameTypeMap, fileout );
00908       ROOT::WriteReadRuleFunc( *rIt, 0, mappedname, nameTypeMap, fileout );
00909 
00910    gROOT->LoadMacro(filename);
00911 }
00912 
00913 #endif

Generated on Tue Jul 5 14:11:55 2011 for ROOT_528-00b_version by  doxygen 1.5.1