Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
TSchemaRule.cxx
Go to the documentation of this file.
1// @(#)root/core:$Id$
2// author: Lukasz Janyst <ljanyst@cern.ch>
3
4#include "TSchemaRule.h"
5
7#include "TClassEdit.h"
9#include "TSchemaType.h"
10#include "TObjArray.h"
11#include "TObjString.h"
12#include "TROOT.h"
13#include "TSchemaHelper.h"
14
15#include <utility>
16#include <iostream>
17#include <vector>
18#include <list>
19#include <string>
20#include <cstdlib>
21#include <sstream>
22
24
25using namespace ROOT;
26
27namespace {
28 static Bool_t IsIrrelevantCharacter(char c)
29 {
30 return (c == ' ' || c == '\n' || c == '\t');
31 }
32
33 static void AdvanceOverIrrelevantCharacter(const char*& str)
34 {
35 while (IsIrrelevantCharacter(*str)) {
36 ++str;
37 }
38 }
39
40 // check if lhs matches rhs if we ignore irelevant white space differences
41
42 static Bool_t IsCodeEquivalent(const TString& lhs, const TString& rhs)
43 {
45
46 if (lhs != rhs) {
47 const char null = '\0';
48 const char* left = lhs.Data();
49 const char* right = rhs.Data();
50 Bool_t literal = false;
51 // skip initial white space
54
55 while (*left != null || *right != null) {
56 // If both chars are white space, skip consecutive white space
57 if (!literal && IsIrrelevantCharacter(*left) && IsIrrelevantCharacter(*right)) {
60 continue;
61 }
62 // Check if one string has trailing white space, and the other doesn't.
63 if (*left == null || *right == null) {
66 result = (*left == null && *right == null);
67 break;
68 }
69
70 if (*left != *right) {
71 result = kFALSE;
72 break;
73 }
74
75 if (*left == '"') {
77 }
78 ++left;
79 ++right;
80 }
81 }
82 return result;
83 }
84
85}
86
87////////////////////////////////////////////////////////////////////////////////
88/// Default Constructor.
89
90TSchemaRule::TSchemaRule(): fVersionVect( nullptr ), fChecksumVect( nullptr ),
91 fTargetVect( nullptr ), fSourceVect( nullptr ),
92 fIncludeVect( nullptr ), fEmbed( kTRUE ),
93 fReadFuncPtr( nullptr ), fReadRawFuncPtr( nullptr ),
94 fRuleType( kNone )
95{
96}
97
98////////////////////////////////////////////////////////////////////////////////
99/// Constructor.
102 : fVersionVect(nullptr),
103 fChecksumVect(nullptr),
104 fTargetVect(nullptr),
105 fSourceVect(nullptr),
106 fIncludeVect(nullptr),
107 fEmbed(kTRUE),
108 fReadFuncPtr(nullptr),
109 fReadRawFuncPtr(nullptr),
110 fRuleType(type)
111{
112 SetTarget(helper.fTarget);
114 SetSourceClass(helper.fSourceClass);
115 SetSource(helper.fSource);
116 SetCode(helper.fCode);
117 SetVersion(helper.fVersion);
118 SetChecksum(helper.fChecksum);
119 SetEmbed(helper.fEmbed);
120 SetInclude(helper.fInclude);
121 SetAttributes(helper.fAttributes);
122
125 } else {
127 }
128}
129
130////////////////////////////////////////////////////////////////////////////////
131/// Destructor.
132
134{
135 delete fVersionVect;
136 delete fChecksumVect;
137 delete fTargetVect;
138 delete fSourceVect;
139 delete fIncludeVect;
140}
141
142////////////////////////////////////////////////////////////////////////////////
143/// Copy Constructor.
144
146 fVersionVect( nullptr ), fChecksumVect( nullptr ),
147 fTargetVect( nullptr ), fSourceVect( nullptr ),
148 fIncludeVect( nullptr ), fEmbed( kTRUE ),
149 fReadFuncPtr( nullptr ), fReadRawFuncPtr( nullptr ),
150 fRuleType( kNone )
151{
152 *this = rhs;
153}
154
155////////////////////////////////////////////////////////////////////////////////
156/// Copy operator.
157
159{
160 if( this != &rhs ) {
161 fVersion = rhs.fVersion;
162 fChecksum = rhs.fChecksum;
163 fSourceClass = rhs.fSourceClass;
164 fTarget = rhs.fTarget;
165 fSource = rhs.fSource;
166 fInclude = rhs.fInclude;
167 fCode = rhs.fCode;
168 fEmbed = rhs.fEmbed;
169 fReadFuncPtr = rhs.fReadFuncPtr;
170 fReadRawFuncPtr = rhs.fReadRawFuncPtr;
171 fRuleType = rhs.fRuleType;
172 fAttributes = rhs.fAttributes;
173 }
174 return *this;
175}
176
177////////////////////////////////////////////////////////////////////////////////
178/// Return true if the rule have the same effects.
179
181{
182 if( this != &rhs ) {
183 Bool_t result = ( fVersion == rhs.fVersion
184 && fChecksum == rhs.fChecksum
185 && fSourceClass == rhs.fSourceClass
186 && fTargetClass == rhs.fTargetClass
187 && fSource == rhs.fSource
188 && fTarget == rhs.fTarget
189 && fInclude == rhs.fInclude
190 && IsCodeEquivalent(fCode, rhs.fCode)
191 && fEmbed == rhs.fEmbed
192 && fRuleType == rhs.fRuleType
193 && fAttributes == rhs.fAttributes );
194 if (result &&
195 ( (fReadRawFuncPtr != rhs.fReadRawFuncPtr && fReadRawFuncPtr != nullptr && rhs.fReadRawFuncPtr != nullptr)
196 || (fReadFuncPtr != rhs.fReadFuncPtr && fReadFuncPtr != nullptr && rhs.fReadFuncPtr != nullptr) ) )
197 {
198 result = kFALSE;
199 }
200
201 return result;
202 }
203 return kTRUE;
204}
205
206////////////////////////////////////////////////////////////////////////////////
207/// The ls function lists the contents of a class on stdout. Ls output
208/// is typically much less verbose then Dump().
209
211{
213 std::cout << "Schema Evolution Rule: ";
214 if (fRuleType==kReadRule) std::cout << "read ";
215 else if (fRuleType==kReadRawRule) std::cout << "readraw ";
216 std::cout << "\n";
219 std::cout << "sourceClass=\"" << fSourceClass << "\" ";
220 if (fVersion.Length()) std::cout << "version=\"" << fVersion << "\" ";
221 if (fChecksum.Length()) std::cout << "checksum=\"" << fChecksum << "\" ";
222 if (targetname && targetname[0]) std::cout << "targetClass=\"" << targetname << "\" ";
223 else std::cout << "targetClass\"" << fTargetClass << "\" ";
224 std::cout << "\n";
226 std::cout << "source=\"" << fSource << "\" ";
227 std::cout << "target=\"" << fTarget << "\" ";
228 std::cout << "\n";
229 if (fInclude.Length()) {
231 std::cout << "include=\"" << fInclude << "\" " << "\n";
232 }
233 if (fAttributes.Length()) {
235 std::cout << "attributes=\"" << fAttributes << "\"" << "\n";
236 }
237 if (fCode.Length()) {
239 std::cout << "code=\"{" << fCode << "}\" "
240 << "\n";
241 }
243}
244
245////////////////////////////////////////////////////////////////////////////////
246/// Add to the string 'out' the string representation of the rule.
247/// if options contains:
248/// 's' : add the short form of the rule is possible
249/// 'x' : add the xml form of the rule
250
251void TSchemaRule::AsString(TString &out, const char *options) const
252{
253 TString opt(options);
254 opt.ToLower();
255 Bool_t shortform = opt.Contains('s');
256 Bool_t xmlform = opt.Contains('x');
257
258 TString end;
259 if (xmlform) {
260 /*
261 <read sourceClass="ClassA" version="[2]" targetClass="ClassA" source="int m_unit;" target="m_unit" >
262 <![CDATA[ { m_unit = 10*onfile.m_unit; } ]]>
263 </read>
264 */
266 out += "<";
267 if (fRuleType==kReadRule) { out += "read "; end = "</read>"; }
268 else if (fRuleType==kReadRawRule) { out += "readraw "; end = "</readraw>"; }
269 else { out += "-- "; end = "-->"; }
270
271 } else {
272 if (!shortform || fRuleType!=kReadRule) {
273 out += "type=";
274 if (fRuleType==kReadRule) out += "read ";
275 else if (fRuleType==kReadRawRule) out += "readraw ";
276 else out += " ";
277 }
278 }
279 if (!shortform || (fSourceClass != fTargetClass) ) {
280 out += "sourceClass=\"" + fSourceClass + "\" ";
281 out += "targetClass=\"" + fTargetClass + "\" ";
282 } else {
283 out += fSourceClass + " ";
284 }
285 if (shortform && fTarget == fSource) {
286 out += fSource + " ";
287 }
288 if (!shortform || (fVersion != "[1-]")) {
289 if (fVersion.Length()) out += "version=\"" + fVersion + "\" ";
290 }
291 if (fChecksum.Length()) out += "checksum=\"" + fChecksum + "\" ";
292 if (!shortform || fTarget != fSource) {
293 out += "source=\"" + fSource + "\" ";
294 out += "target=\"" + fTarget + "\" ";
295 }
296 if (fInclude.Length()) out += "include=\"" + fInclude + "\" ";
297 if (fAttributes.Length()) out += "attributes=\"" + fAttributes + "\" ";
298 if (xmlform) {
299 out += "> ";
300 }
301 if (xmlform) {
302 if (fCode.Length()) {
303 out += "\n<![CDATA[ { " + fCode + " ]]>\n ";
304 } else if (fReadFuncPtr) {
305 // Can we guess?
306 // out += "code=\" + nameof(fReadFuncPtr) + "\" ";
307 } else if (fReadRawFuncPtr) {
308 // Can we guess?
309 // out += "code=\" + nameof(fReadRawFuncPtr) + "\" ";
310 }
311 } else {
312 if (fCode.Length()) {
313 out += "code=\"{" + fCode + "}\" ";
314 } else if (fReadFuncPtr) {
315 // Can we guess?
316 // out += "code=\" + nameof(fReadFuncPtr) + "\" ";
317 } else if (fReadRawFuncPtr) {
318 // Can we guess?
319 // out += "code=\" + nameof(fReadRawFuncPtr) + "\" ";
320 }
321 }
322 if (xmlform) {
323 out += end;
324 }
325}
326
327////////////////////////////////////////////////////////////////////////////////
328/// Zero out this rule object.
329
330void TSchemaRule::Clear( const char * /* option */)
331{
332 fVersion.Clear();
335 fTarget.Clear();
336 fSource.Clear();
337 fInclude.Clear();
338 fCode.Clear();
340 fReadRawFuncPtr = nullptr;
341 fReadFuncPtr = nullptr;
343 delete fVersionVect; fVersionVect = nullptr;
344 delete fChecksumVect; fChecksumVect = nullptr;
345 delete fTargetVect; fTargetVect = nullptr;
346 delete fSourceVect; fSourceVect = nullptr;
347 delete fIncludeVect; fIncludeVect = nullptr;
348}
349
350////////////////////////////////////////////////////////////////////////////////
351/// Set the content fot this object from the rule
352/// See TClass::AddRule for details on the syntax.
353
355{
356 //-----------------------------------------------------------------------
357 // Parse the rule and check it's validity
358 /////////////////////////////////////////////////////////////////////////////
359
361
362 std::string error_string;
364 Error("SetFromRule","The rule (%s) is invalid: %s",rule,error_string.c_str());
365 return kFALSE;
366 }
367 ROOT::Internal::MembersMap_t::const_iterator it1;
368
369 it1 = rule_values.find( "type" );
370 if( it1 != rule_values.end() ) {
371 if (it1->second == "read" || it1->second == "Read") {
373 } else if (it1->second == "readraw" || it1->second == "ReadRaw") {
375 } else {
377 }
378 } else {
379 // Default to read.
381 }
382 it1 = rule_values.find( "targetClass" );
383 if( it1 != rule_values.end() ) SetTargetClass( it1->second );
384 it1 = rule_values.find( "sourceClass" );
385 if( it1 != rule_values.end() ) SetSourceClass( it1->second );
386 it1 = rule_values.find( "target" );
387 if( it1 != rule_values.end() ) SetTarget( it1->second );
388 it1 = rule_values.find( "source" );
389 if( it1 != rule_values.end() ) SetSource( it1->second );
390 it1 = rule_values.find( "version" );
391 if( it1 != rule_values.end() ) SetVersion( it1->second );
392 it1 = rule_values.find( "checksum" );
393 if( it1 != rule_values.end() ) SetChecksum( it1->second );
394 it1 = rule_values.find( "embed" );
395 if( it1 != rule_values.end() ) SetEmbed( it1->second == "false" ? false : true );
396 it1 = rule_values.find( "include" );
397 if( it1 != rule_values.end() ) SetInclude( it1->second );
398 it1 = rule_values.find( "attributes" );
399 if( it1 != rule_values.end() ) SetAttributes( it1->second );
400 it1 = rule_values.find( "code" );
401 if( it1 != rule_values.end() ) SetCode( it1->second );
402 // if (code is functioname) {
403 // switch (ruleobj->GetRuleType() ) {
404 // case kRead: SetReadFunctionPointer( )
405 // case kReadRewa: SetReadRawFunctionPointer( )
406 // }
407
408 return kTRUE;
409}
410
411////////////////////////////////////////////////////////////////////////////////
412/// Set the version string - returns kFALSE if the format is incorrect
413
415{
416 fVersion = "";
418 if( ret )
420 return ret;
421}
422
423////////////////////////////////////////////////////////////////////////////////
424/// Get the version string.
425
426const char *TSchemaRule::GetVersion() const
427{
428 return fVersion;
429}
430
431
432////////////////////////////////////////////////////////////////////////////////
433/// Check if given version number is defined in this rule
434
436{
437 if( fVersion.IsNull() )
438 return kFALSE;
439
440 if( !fVersionVect )
441 ProcessVersion( fVersion ); // At this point the version string should always be correct
442
443 if (version == -1) {
444 version = 1;
445 }
446
447 if (fVersionVect)
448 for (auto &it : *fVersionVect)
449 if( version >= it.first && version <= it.second )
450 return kTRUE;
451
452 return kFALSE;
453}
454
455////////////////////////////////////////////////////////////////////////////////
456/// Set the checksum string - returns kFALSE if the format is incorrect
457
459{
460 fChecksum = "";
462 if( ret )
464 return ret;
465}
466
467////////////////////////////////////////////////////////////////////////////////
468/// Check if given checksum is defined in this rule
469
471{
472 if( fChecksum.IsNull() )
473 return kFALSE;
474
475 if( !fChecksumVect )
476 ProcessChecksum( fChecksum ); // At this point the checksum string should always be correct
477
478 if (fChecksumVect)
479 for (auto &it : *fChecksumVect)
480 if( checksum == it )
481 return kTRUE;
482
483 return kFALSE;
484}
485
486////////////////////////////////////////////////////////////////////////////////
487/// Set the source class of this rule (i.e. the onfile class).
488
489void TSchemaRule::SetSourceClass( const TString& classname )
490{
491 std::string normalizedName;
494}
495
496////////////////////////////////////////////////////////////////////////////////
497/// Get the source class of this rule (i.e. the onfile class).
498
500{
501 return fSourceClass;
502}
503
504////////////////////////////////////////////////////////////////////////////////
505/// Set the target class of this rule (i.e. the in memory class).
506
507void TSchemaRule::SetTargetClass( const TString& classname )
508{
509 std::string normalizedName;
512}
513
514////////////////////////////////////////////////////////////////////////////////
515/// Get the targte class of this rule (i.e. the in memory class).
516
518{
519 return fTargetClass;
520}
521
522////////////////////////////////////////////////////////////////////////////////
523/// Set the target member of this rule (i.e. the in memory data member).
524
526{
527 fTarget = target;
528
529 if( target == "" ) {
530 delete fTargetVect;
531 fTargetVect = nullptr;
532 return;
533 }
534
535 if( !fTargetVect ) {
536 fTargetVect = new TObjArray();
538 }
540}
541
542////////////////////////////////////////////////////////////////////////////////
543/// Get the target data members of this rule as a simple string (i.e. the in memory data member).
544
546{
547 return fTarget;
548}
549
550////////////////////////////////////////////////////////////////////////////////
551/// Get the target data members of this rule (i.e. the in memory data member).
552
554{
555 if( fTarget == "" )
556 return nullptr;
557
558 if( !fTargetVect ) {
559 fTargetVect = new TObjArray();
562 }
563
564 return fTargetVect;
565}
566
567////////////////////////////////////////////////////////////////////////////////
568/// Set the list of source members. This should be in the form of a declaration:
569/// Int_t fOldMember; TNamed fName;
570
572{
573 fSource = source;
574
575 if( source == "" ) {
576 delete fSourceVect;
577 fSourceVect = nullptr;
578 return;
579 }
580
581 if( !fSourceVect ) {
582 fSourceVect = new TObjArray();
584 }
585
587}
588
589////////////////////////////////////////////////////////////////////////////////
590/// Get the list of source members as a TObjArray of TNamed object,
591/// with the name being the member name and the title being its type.
592
594{
595 if( fSource == "" )
596 return nullptr;
597
598 if( !fSourceVect ) {
599 fSourceVect = new TObjArray();
602 }
603 return fSourceVect;
604}
605
606////////////////////////////////////////////////////////////////////////////////
607/// Set the comma separated list of header files to include to be able
608/// to compile this rule.
609
611{
612 fInclude = incl;
613
614 if( incl == "" ) {
615 delete fIncludeVect;
616 fIncludeVect = nullptr;
617 return;
618 }
619
620 if( !fIncludeVect ) {
621 fIncludeVect = new TObjArray();
623 }
624
626}
627
628////////////////////////////////////////////////////////////////////////////////
629/// Return the list of header files to include to be able to
630/// compile this rule as a TObjArray of TObjString
631
633{
634 if( fInclude == "" )
635 return nullptr;
636
637 if( !fIncludeVect ) {
638 fIncludeVect = new TObjArray();
641 }
642
643 return fIncludeVect;
644}
645
646////////////////////////////////////////////////////////////////////////////////
647/// Set whether this rule should be save in the ROOT file (if true)
648
653
654////////////////////////////////////////////////////////////////////////////////
655/// Return true if this rule should be saved in the ROOT File.
656
658{
659 return fEmbed;
660}
661
662////////////////////////////////////////////////////////////////////////////////
663/// Return kTRUE if this rule is valid.
664
666{
667 return (fVersionVect || fChecksumVect) && (fSourceClass.Length() != 0);
668}
669
670////////////////////////////////////////////////////////////////////////////////
671/// Set the source code of this rule.
672
673void TSchemaRule::SetCode( const TString& code )
674{
675 fCode = code;
676}
677
678////////////////////////////////////////////////////////////////////////////////
679/// Get the source code of this rule.
680
681const char *TSchemaRule::GetCode() const
682{
683 return fCode;
684}
685
686////////////////////////////////////////////////////////////////////////////////
687/// Set the attributes code of this rule.
688
689void TSchemaRule::SetAttributes( const TString& attributes )
690{
691 fAttributes = attributes;
692}
693
694////////////////////////////////////////////////////////////////////////////////
695/// Get the attributes code of this rule.
696
697const char *TSchemaRule::GetAttributes() const
698{
699 return fAttributes;
700}
701
702////////////////////////////////////////////////////////////////////////////////
703/// Return true if one of the rule's data member target is 'target'.
704
706{
707 if( !fTargetVect )
708 return kFALSE;
709
710 TObject* obj;
712 while( (obj = it.Next()) ) {
713 TObjString* str = (TObjString*)obj;
714 if( str->GetString() == target )
715 return kTRUE;
716 }
717 return kFALSE;
718}
719
720////////////////////////////////////////////////////////////////////////////////
721/// Return true if one of the rule's data member source is 'source'
722
724{
725 if( !fSourceVect )
726 return kFALSE;
727
728 TObject* obj;
730 while( (obj = it.Next()) ) {
731 TSources* var = (TSources*)obj;
732 if( var->GetName() == source )
733 return kTRUE;
734 }
735 return kFALSE;
736}
737
738////////////////////////////////////////////////////////////////////////////////
739/// Set the pointer to the function to be run for the rule (if it is a read rule).
740
745
746////////////////////////////////////////////////////////////////////////////////
747/// Get the pointer to the function to be run for the rule (if it is a read rule).
748
753
754////////////////////////////////////////////////////////////////////////////////
755/// Set the pointer to the function to be run for the rule (if it is a raw read rule).
756
761
762////////////////////////////////////////////////////////////////////////////////
763/// Get the pointer to the function to be run for the rule (if it is a raw read rule).
764
769
770////////////////////////////////////////////////////////////////////////////////
771/// Set the type of the rule.
772
777
778////////////////////////////////////////////////////////////////////////////////
779/// Return kTRUE if the rule is a strict renaming of one of the data member of the class.
780
782{
783 return fSourceClass != "" && (fVersion != "" || fChecksum != "") && fTarget == "" && fSource == "" && fInclude == "" && fCode == "" && fAttributes == "";
784}
785
786////////////////////////////////////////////////////////////////////////////////
787/// Return kTRUE if the rule is a strict renaming of the class to a new name.
788
790{
791 return fSourceClass != "" && (fVersion != "" || fChecksum != "") && fTarget != "" && fSource != "" && fInclude == "" && fCode == "" && fAttributes == "";
792}
793
794////////////////////////////////////////////////////////////////////////////////
795/// Return the type of the rule.
796
801
802////////////////////////////////////////////////////////////////////////////////
803/// Check if this rule conflicts with the given one.
804
806{
807 //---------------------------------------------------------------------------
808 // If the rules have different sources then the don't conflict
809 /////////////////////////////////////////////////////////////////////////////
810
811 if( fSourceClass != rule->fSourceClass )
812 return kFALSE;
813
814 //---------------------------------------------------------------------------
815 // Check if the rules have common target
816 /////////////////////////////////////////////////////////////////////////////
817
818 if( !rule->GetTarget() )
819 return kFALSE;
820
822 TObjArrayIter titer( rule->GetTarget() );
823 TObjString *str;
824 TObject *obj;
825
826 while( (obj = titer.Next() ) ) {
827 str = (TObjString*)obj;
828 if( HasTarget( str->String() ) )
830 }
831
832 if( !haveCommonTargets )
833 return kFALSE;
834
835 //---------------------------------------------------------------------------
836 // Check if there are conflicting checksums
837 /////////////////////////////////////////////////////////////////////////////
838
839 if( fChecksumVect ) {
840 std::vector<UInt_t>::iterator it;
841 for( it = fChecksumVect->begin(); it != fChecksumVect->end(); ++it )
842 if( rule->TestChecksum( *it ) )
843 return kTRUE;
844 }
845
846 //---------------------------------------------------------------------------
847 // Check if there are conflicting versions
848 /////////////////////////////////////////////////////////////////////////////
849
850 if( fVersionVect && rule->fVersionVect )
851 {
852 std::vector<std::pair<Int_t, Int_t> >::iterator it1;
853 std::vector<std::pair<Int_t, Int_t> >::iterator it2;
854 for( it1 = fVersionVect->begin(); it1 != fVersionVect->end(); ++it1 ) {
855 for( it2 = rule->fVersionVect->begin();
856 it2 != rule->fVersionVect->end(); ++it2 ) {
857 //------------------------------------------------------------------
858 // the rules conflict it their version ranges intersect
859 ////////////////////////////////////////////////////////////////////
860
861 if( it1->first >= it2->first && it1->first <= it2->second )
862 return kTRUE;
863
864 if( it1->first < it2->first && it1->second >= it2->first )
865 return kTRUE;
866 }
867 }
868 }
869 return kFALSE;
870}
871
872////////////////////////////////////////////////////////////////////////////////
873/// Check if specified version string is correct and build version vector.
874
876{
877 //---------------------------------------------------------------------------
878 // Check if we have valid list
879 /////////////////////////////////////////////////////////////////////////////
880
881 if( version[0] != '[' || version[version.Length()-1] != ']' )
882 return kFALSE;
883 std::string ver = version.Data();
884
885 std::list<std::string> versions;
887
888 if( versions.empty() )
889 {
890 delete fVersionVect;
891 fVersionVect = nullptr;
892 return kFALSE;
893 }
894
895 if( !fVersionVect )
896 fVersionVect = new std::vector<std::pair<Int_t, Int_t> >;
897 fVersionVect->clear();
898
899 //---------------------------------------------------------------------------
900 // Check the validity of each list element
901 /////////////////////////////////////////////////////////////////////////////
902
903 std::list<std::string>::iterator it;
904 for( it = versions.begin(); it != versions.end(); ++it ) {
905 std::pair<Int_t, Int_t> verpair;
907 {
908 delete fVersionVect;
909 fVersionVect = nullptr;
910 return kFALSE;
911 }
912 fVersionVect->push_back( verpair );
913 }
914 return kTRUE;
915}
916
917////////////////////////////////////////////////////////////////////////////////
918/// Check if specified checksum string is correct and build checksum vector.
919
921{
922 //---------------------------------------------------------------------------
923 // Check if we have valid list
924 /////////////////////////////////////////////////////////////////////////////
925
926 if (!checksum[0])
927 return kFALSE;
928 std::string chk = (const char*)checksum;
929 if( chk[0] != '[' || chk[chk.size()-1] != ']' )
930 return kFALSE;
931
932 std::list<std::string> checksums;
934
935 if( checksums.empty() ) {
936 delete fChecksumVect;
937 fChecksumVect = nullptr;
938 return kFALSE;
939 }
940
941 if( !fChecksumVect )
942 fChecksumVect = new std::vector<UInt_t>;
943 fChecksumVect->clear();
944
945 //---------------------------------------------------------------------------
946 // Check the validity of each list element
947 /////////////////////////////////////////////////////////////////////////////
948
949 for( const auto& checksumStr : checksums ) {
950 auto chksum = ParseChecksum( checksumStr.c_str() );
951 if (chksum == 0u) {
952 delete fChecksumVect;
953 fChecksumVect = nullptr;
954 return kFALSE;
955 }
956
957 fChecksumVect->push_back( chksum );
958 }
959 return kTRUE;
960}
961
962////////////////////////////////////////////////////////////////////////////////
963/// Parse the checksum in the given string. Returns either the checksum or zero
964/// if the string is not a hex or decimal number.
965
967 std::istringstream converter(checksum);
969 converter >> std::hex >> chksum;
970 if (converter.fail()) {
971 converter.clear();
972 converter.seekg(0);
973 converter >> std::dec >> chksum;
974 }
975
976 if( converter.fail() ) {
977 return 0u;
978 }
979
980 return chksum;
981}
982
983////////////////////////////////////////////////////////////////////////////////
984/// Split the list as a comma separated list into a TObjArray of TObjString.
985
986void TSchemaRule::ProcessList( TObjArray* array, const TString& list )
987{
988 std::list<std::string> elems;
989 std::list<std::string>::iterator it;
990 Internal::TSchemaRuleProcessor::SplitList( (const char*)list, elems );
991
992 array->Clear();
993
994 if( elems.empty() )
995 return;
996
997 for( it = elems.begin(); it != elems.end(); ++it ) {
998 TObjString *str = new TObjString;
999 *str = it->c_str();
1000 array->Add( str );
1001 }
1002}
1003
1004////////////////////////////////////////////////////////////////////////////////
1005/// Split the list as a declaration into as a TObjArray of TNamed(name,type).
1006
1008{
1009 std::list<std::pair<ROOT::Internal::TSchemaType,std::string> > elems;
1010 std::list<std::pair<ROOT::Internal::TSchemaType,std::string> >::iterator it;
1011 Internal::TSchemaRuleProcessor::SplitDeclaration( (const char*)list, elems );
1012
1013 array->Clear();
1014
1015 if( elems.empty() )
1016 return;
1017
1018 for( it = elems.begin(); it != elems.end(); ++it ) {
1019 TSources *type = new TSources( it->second.c_str(), it->first.fType.c_str(), it->first.fDimensions.c_str() ) ;
1020 array->Add( type );
1021 }
1022}
1023
1024#if 0
1025////////////////////////////////////////////////////////////////////////////////
1026/// Generate the actual function for the rule.
1027
1028Bool_t TSchemaRule::GenerateFor( TStreamerInfo *info )
1029{
1030 String funcname = fSourceClass + "_to_" + fTargetClass;
1031 if (info) funcname += "_v" + info->GetClassVersion();
1032 TString names = fSource + "_" + fTarget;
1033 name.ReplaceAll(',','_');
1034 name.ReplaceAll(':','_');
1035 funcname += "_" + name;
1036
1037 String filename = funcname + ".C";
1038 if (!false) {
1039 filename += '+';
1040 }
1041
1042 std::ofstream fileout(filename);
1043
1044
1047
1048 gROOT->LoadMacro(filename);
1049}
1050
1051#endif
const Handle_t kNone
Definition GuiTypes.h:88
#define c(i)
Definition RSha256.hxx:101
bool Bool_t
Definition RtypesCore.h:63
constexpr Bool_t kFALSE
Definition RtypesCore.h:94
constexpr Bool_t kTRUE
Definition RtypesCore.h:93
const char Option_t
Definition RtypesCore.h:66
#define ClassImp(name)
Definition Rtypes.h:374
ROOT::Detail::TRangeCast< T, true > TRangeDynCast
TRangeDynCast is an adapter class that allows the typed iteration through a TCollection.
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t Int_t Int_t Window_t TString Int_t GCValues_t GetPrimarySelectionOwner GetDisplay GetScreen GetColormap GetNativeEvent const char const char dpyName wid window const char font_name cursor keysym reg const char only_if_exist regb h Point_t winding char text const char depth char const char Int_t count const char ColorStruct_t color const char filename
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t Int_t Int_t Window_t TString Int_t GCValues_t GetPrimarySelectionOwner GetDisplay GetScreen GetColormap GetNativeEvent const char const char dpyName wid window const char font_name cursor keysym reg const char only_if_exist regb h Point_t winding char text const char depth char const char Int_t count const char ColorStruct_t color const char Pixmap_t Pixmap_t PictureAttributes_t attr const char char ret_data h unsigned char height h Atom_t Int_t ULong_t ULong_t unsigned char prop_list Atom_t Atom_t target
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t result
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t Int_t Int_t Window_t TString Int_t GCValues_t GetPrimarySelectionOwner GetDisplay GetScreen GetColormap GetNativeEvent const char const char dpyName wid window const char font_name cursor keysym reg const char only_if_exist regb h Point_t winding char text const char depth char const char Int_t count const char ColorStruct_t color const char Pixmap_t Pixmap_t PictureAttributes_t attr const char char ret_data h unsigned char height h Atom_t Int_t ULong_t ULong_t unsigned char prop_list Atom_t Atom_t Atom_t Time_t type
char name[80]
Definition TGX11.cxx:110
#define gROOT
Definition TROOT.h:406
static void SplitDeclaration(const std::string &source, std::list< std::pair< ROOT::Internal::TSchemaType, std::string > > &result)
static bool ProcessVersion(const std::string &source, std::pair< Int_t, Int_t > &result)
static void SplitList(const std::string &source, std::list< std::string > &result, char delimiter=',')
const_iterator begin() const
const_iterator end() const
void SetRuleType(RuleType_t type)
Set the type of the rule.
TObjArray * fSourceVect
void SetCode(const TString &code)
Set the source code of this rule.
TString fCode
Includes vector.
void SetTarget(const TString &target)
Set the target member of this rule (i.e. the in memory data member).
ReadFuncPtr_t fReadFuncPtr
TObjArray * fIncludeVect
void SetReadRawFunctionPointer(ReadRawFuncPtr_t ptr)
Set the pointer to the function to be run for the rule (if it is a raw read rule).
void SetInclude(const TString &include)
Set the comma separated list of header files to include to be able to compile this rule.
void AsString(TString &out, const char *options="") const
Add to the string 'out' the string representation of the rule.
const TObjArray * GetSource() const
Get the list of source members as a TObjArray of TNamed object, with the name being the member name a...
void SetReadFunctionPointer(ReadFuncPtr_t ptr)
Set the pointer to the function to be run for the rule (if it is a read rule).
void ls(Option_t *option="") const override
The ls function lists the contents of a class on stdout.
std::vector< UInt_t > * fChecksumVect
UInt_t ParseChecksum(const char *checksum) const
Parse the checksum in the given string.
static void ProcessList(TObjArray *array, const TString &list)
Split the list as a comma separated list into a TObjArray of TObjString.
Bool_t operator==(const TSchemaRule &rhs) const
Return true if the rule have the same effects.
Bool_t SetFromRule(const char *rule)
Set the content fot this object from the rule See TClass::AddRule for details on the syntax.
void Clear(Option_t *="") override
Zero out this rule object.
Bool_t TestVersion(Int_t version) const
Check if given version number is defined in this rule.
TString fSource
Target data member vector (for searching purposes)
Bool_t HasSource(const TString &source) const
Return true if one of the rule's data member source is 'source'.
ReadRawFuncPtr_t GetReadRawFunctionPointer() const
Get the pointer to the function to be run for the rule (if it is a raw read rule).
const TObjArray * GetTarget() const
Get the target data members of this rule (i.e. the in memory data member).
Bool_t ProcessChecksum(const TString &checksum) const
Check if specified checksum string is correct and build checksum vector.
void(* ReadFuncPtr_t)(char *, TVirtualObject *)
Definition TSchemaRule.h:77
void SetEmbed(Bool_t embed)
Set whether this rule should be save in the ROOT file (if true)
RuleType_t GetRuleType() const
Return the type of the rule.
Bool_t Conflicts(const TSchemaRule *rule) const
Check if this rule conflicts with the given one.
TSchemaRule & operator=(const TSchemaRule &rhs)
Copy operator.
void SetTargetClass(const TString &classname)
Set the target class of this rule (i.e. the in memory class).
void(* ReadRawFuncPtr_t)(char *, TBuffer &)
Definition TSchemaRule.h:78
const char * GetSourceClass() const
Get the source class of this rule (i.e. the onfile class).
virtual ~TSchemaRule()
Destructor.
Bool_t TestChecksum(UInt_t checksum) const
Check if given checksum is defined in this rule.
Bool_t SetVersion(const TString &version)
Set the version string - returns kFALSE if the format is incorrect.
TString fInclude
Source data member vector (for searching purposes)
TObjArray * fTargetVect
TString fChecksum
Source version vector (for searching purposes)
void SetSource(const TString &source)
Set the list of source members.
Bool_t IsRenameRule() const
Return kTRUE if the rule is a strict renaming of the class to a new name.
void SetAttributes(const TString &attributes)
Set the attributes code of this rule.
TString fSourceClass
Source checksum vector (for searching purposes)
Bool_t HasTarget(const TString &target) const
Return true if one of the rule's data member target is 'target'.
const char * GetTargetString() const
Get the target data members of this rule as a simple string (i.e. the in memory data member).
std::vector< std::pair< Int_t, Int_t > > * fVersionVect
ReadRawFuncPtr_t fReadRawFuncPtr
Conversion function pointer for read rule.
RuleType_t fRuleType
Conversion function pointer for readraw rule.
Bool_t IsValid() const
Return kTRUE if this rule is valid.
ReadFuncPtr_t GetReadFunctionPointer() const
Get the pointer to the function to be run for the rule (if it is a read rule).
const char * GetVersion() const
Get the version string.
const char * GetAttributes() const
Get the attributes code of this rule.
Bool_t GetEmbed() const
Return true if this rule should be saved in the ROOT File.
const char * GetCode() const
Get the source code of this rule.
void SetSourceClass(const TString &classname)
Set the source class of this rule (i.e. the onfile class).
TSchemaRule()
Default Constructor.
Bool_t SetChecksum(const TString &checksum)
Set the checksum string - returns kFALSE if the format is incorrect.
const TObjArray * GetInclude() const
Return the list of header files to include to be able to compile this rule as a TObjArray of TObjStri...
Bool_t IsAliasRule() const
Return kTRUE if the rule is a strict renaming of one of the data member of the class.
const char * GetTargetClass() const
Get the targte class of this rule (i.e. the in memory class).
static void ProcessDeclaration(TObjArray *array, const TString &list)
Split the list as a declaration into as a TObjArray of TNamed(name,type).
Bool_t ProcessVersion(const TString &version) const
Check if specified version string is correct and build version vector.
virtual void SetOwner(Bool_t enable=kTRUE)
Set whether this collection is the owner (enable==true) of its content.
const char * GetName() const override
Returns name of object.
Definition TNamed.h:47
Iterator of object array.
Definition TObjArray.h:117
TObject * Next() override
Return next object in array. Returns 0 when no more objects in array.
An array of TObjects.
Definition TObjArray.h:31
void Clear(Option_t *option="") override
Remove all objects from the array.
void Add(TObject *obj) override
Definition TObjArray.h:68
Collectable string class.
Definition TObjString.h:28
Mother of all ROOT objects.
Definition TObject.h:41
virtual void Error(const char *method, const char *msgfmt,...) const
Issue error message.
Definition TObject.cxx:1005
static Int_t IncreaseDirLevel()
Increase the indentation level for ls().
Definition TROOT.cxx:2887
static void IndentLevel()
Functions used by ls() to indent an object hierarchy.
Definition TROOT.cxx:2895
static Int_t DecreaseDirLevel()
Decrease the indentation level for ls().
Definition TROOT.cxx:2746
Describes a persistent version of a class.
Basic string class.
Definition TString.h:139
Ssiz_t Length() const
Definition TString.h:417
void ToLower()
Change string to lower-case.
Definition TString.cxx:1182
void Clear()
Clear string without changing its capacity.
Definition TString.cxx:1235
Bool_t IsNull() const
Definition TString.h:414
Bool_t Contains(const char *pat, ECaseCompare cmp=kExact) const
Definition TString.h:632
std::map< std::string, std::string > MembersMap_t
Definition TSchemaType.h:20
tbb::task_arena is an alias of tbb::interface7::task_arena, which doesn't allow to forward declare tb...
void WriteReadRuleFunc(SchemaRuleMap_t &rule, int index, std::string &mappedName, MembersTypeMap_t &members, std::ostream &output)
Write the conversion function for Read rule, the function name is being written to rule["funcname"].
void WriteReadRawRuleFunc(SchemaRuleMap_t &rule, int index, std::string &mappedName, MembersTypeMap_t &members, std::ostream &output)
Write the conversion function for ReadRaw rule, the function name is being written to rule["funcname"...
bool ParseRule(std::string rule, ROOT::Internal::MembersMap_t &result, std::string &error_string)
Parse the schema rule as specified in the LinkDef file.
void GetNormalizedName(std::string &norm_name, std::string_view name)
Return the normalized name.
null_t< F > null()