Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:05:18

0001 #ifndef DataFormats_TestObjects_SchemaEvolutionTestObjects_h
0002 #define DataFormats_TestObjects_SchemaEvolutionTestObjects_h
0003 
0004 #include <vector>
0005 
0006 // Don't delete the following comment line.
0007 // This #define is required when generating data files
0008 // using the old formats. These data files are saved and used
0009 // as input in unit tests to verify that ROOT can use schema
0010 // evolution to read the old formats with a release that has
0011 // modified formats. When reading this #define should be commented
0012 // out and it should be commented out in the code repository.
0013 // Note that the data files are generated manually and this
0014 // line and classes_def.xml must be manually modified and built
0015 // when generating new data files. The data files are saved
0016 // in this repository: https://github.com/cms-data/IOPool-Input.
0017 //#define DataFormats_TestObjects_USE_OLD
0018 #if defined DataFormats_TestObjects_USE_OLD
0019 
0020 #include <map>
0021 
0022 #else
0023 
0024 #include <array>
0025 #include <list>
0026 #include <memory>
0027 #include <unordered_map>
0028 
0029 #endif
0030 
0031 namespace edmtest {
0032 
0033   class SchemaEvolutionChangeOrder {
0034   public:
0035 #if defined DataFormats_TestObjects_USE_OLD
0036     SchemaEvolutionChangeOrder() : a_(0), b_(0) {}
0037     SchemaEvolutionChangeOrder(int a, int b) : a_(a), b_(b) {}
0038     int a_;
0039     int b_;
0040 #else
0041     SchemaEvolutionChangeOrder() : b_(0), a_(0) {}
0042     SchemaEvolutionChangeOrder(int a, int b) : b_(b), a_(a) {}
0043     int b_;
0044     int a_;
0045 #endif
0046   };
0047 
0048   class SchemaEvolutionAddMember {
0049   public:
0050 #if defined DataFormats_TestObjects_USE_OLD
0051     SchemaEvolutionAddMember() : a_(0), b_(0) {}
0052     SchemaEvolutionAddMember(int a, int b, int) : a_(a), b_(b) {}
0053     int a_;
0054     int b_;
0055 #else
0056     SchemaEvolutionAddMember() : a_(0), b_(0), c_(0) {}
0057     SchemaEvolutionAddMember(int a, int b, int c) : a_(a), b_(b), c_(c) {}
0058     int a_;
0059     int b_;
0060     int c_;
0061 #endif
0062   };
0063 
0064   class SchemaEvolutionRemoveMember {
0065   public:
0066 #if defined DataFormats_TestObjects_USE_OLD
0067     SchemaEvolutionRemoveMember() : a_(0), b_(0) {}
0068     SchemaEvolutionRemoveMember(int a, int b) : a_(a), b_(b) {}
0069     int a_;
0070     int b_;
0071 #else
0072     SchemaEvolutionRemoveMember() : a_(0) {}
0073     SchemaEvolutionRemoveMember(int a, int) : a_(a) {}
0074     int a_;
0075 #endif
0076   };
0077 
0078 #if defined DataFormats_TestObjects_USE_OLD
0079   class SchemaEvolutionBase {
0080   public:
0081     SchemaEvolutionBase() : d_(0) {}
0082     SchemaEvolutionBase(int d) : d_(d) {}
0083     int d_;
0084   };
0085 
0086   class SchemaEvolutionMoveToBase : public SchemaEvolutionBase {
0087   public:
0088     SchemaEvolutionMoveToBase() : a_(0), b_(0), c_(0) {}
0089     SchemaEvolutionMoveToBase(int a, int b, int c, int d) : SchemaEvolutionBase(d), a_(a), b_(b), c_(c) {}
0090     int a_;
0091     int b_;
0092     int c_;
0093   };
0094 #else
0095   class SchemaEvolutionBase {
0096   public:
0097     SchemaEvolutionBase() : c_(0), d_(0) {}
0098     SchemaEvolutionBase(int c, int d) : c_(c), d_(d) {}
0099     int c_;
0100     int d_;
0101   };
0102 
0103   class SchemaEvolutionMoveToBase : public SchemaEvolutionBase {
0104   public:
0105     SchemaEvolutionMoveToBase() : a_(0), b_(0) {}
0106     SchemaEvolutionMoveToBase(int a, int b, int c, int d) : SchemaEvolutionBase(c, d), a_(a), b_(b) {}
0107     int a_;
0108     int b_;
0109   };
0110 #endif
0111 
0112   class SchemaEvolutionChangeType {
0113   public:
0114 #if defined DataFormats_TestObjects_USE_OLD
0115     SchemaEvolutionChangeType() : a_(0), b_(0) {}
0116     SchemaEvolutionChangeType(int a, int b) : a_(a), b_(b) {}
0117     int a_;
0118     int b_;
0119 #else
0120     SchemaEvolutionChangeType() : a_(0.0), b_(0LL) {}
0121     SchemaEvolutionChangeType(int a, int b) : a_(a), b_(b) {}
0122     double a_;
0123     long long b_;
0124 #endif
0125   };
0126 
0127   class SchemaEvolutionBaseA {
0128   public:
0129     SchemaEvolutionBaseA() : c_(0) {}
0130     SchemaEvolutionBaseA(int c) : c_(c) {}
0131     int c_;
0132   };
0133 
0134 #if defined DataFormats_TestObjects_USE_OLD
0135   class SchemaEvolutionAddBase {
0136   public:
0137     SchemaEvolutionAddBase() : a_(0), b_(0) {}
0138     SchemaEvolutionAddBase(int a, int b, int) : a_(a), b_(b) {}
0139 #else
0140   class SchemaEvolutionAddBase : public SchemaEvolutionBaseA {
0141   public:
0142     SchemaEvolutionAddBase() : a_(0), b_(0) {}
0143     SchemaEvolutionAddBase(int a, int b, int c) : SchemaEvolutionBaseA(c), a_(a), b_(b) {}
0144 #endif
0145     int a_;
0146     int b_;
0147   };
0148 
0149   class SchemaEvolutionContained {
0150   public:
0151     SchemaEvolutionContained() : c_(0) {}
0152     SchemaEvolutionContained(int c) : c_(c) {}
0153     int c_;
0154   };
0155 
0156   class SchemaEvolutionPointerToMember {
0157   public:
0158 #if defined DataFormats_TestObjects_USE_OLD
0159     SchemaEvolutionPointerToMember() : a_(0), b_(0), contained_(nullptr) {}
0160     SchemaEvolutionPointerToMember(SchemaEvolutionPointerToMember const& other)
0161         : a_(other.a_), b_(other.b_), contained_(new SchemaEvolutionContained(other.contained_->c_)) {}
0162     SchemaEvolutionPointerToMember(SchemaEvolutionPointerToMember&&) = delete;
0163     SchemaEvolutionPointerToMember& operator=(SchemaEvolutionPointerToMember const&) = delete;
0164     SchemaEvolutionPointerToMember& operator=(SchemaEvolutionPointerToMember&&) = delete;
0165 
0166     SchemaEvolutionPointerToMember(int a, int b, int c) : a_(a), b_(b), contained_(new SchemaEvolutionContained(c)) {}
0167     ~SchemaEvolutionPointerToMember() { delete contained_; }
0168     int c() const { return contained_->c_; }
0169     int a_;
0170     int b_;
0171     SchemaEvolutionContained* contained_;
0172 #else
0173     SchemaEvolutionPointerToMember() : a_(0), b_(0) {}
0174     SchemaEvolutionPointerToMember(int a, int b, int c) : a_(a), b_(b), contained_(c) {}
0175     int c() const { return contained_.c_; }
0176     int a_;
0177     int b_;
0178     SchemaEvolutionContained contained_;
0179 #endif
0180   };
0181 
0182   class SchemaEvolutionPointerToUniquePtr {
0183   public:
0184     SchemaEvolutionPointerToUniquePtr(SchemaEvolutionPointerToUniquePtr&&) = delete;
0185     SchemaEvolutionPointerToUniquePtr& operator=(SchemaEvolutionPointerToUniquePtr const&) = delete;
0186     SchemaEvolutionPointerToUniquePtr& operator=(SchemaEvolutionPointerToUniquePtr&&) = delete;
0187 
0188 #if defined DataFormats_TestObjects_USE_OLD
0189     SchemaEvolutionPointerToUniquePtr() : a_(0), b_(0), contained_(nullptr) {}
0190     SchemaEvolutionPointerToUniquePtr(SchemaEvolutionPointerToUniquePtr const& other)
0191         : a_(other.a_), b_(other.b_), contained_(new SchemaEvolutionContained(other.contained_->c_)) {}
0192 
0193     SchemaEvolutionPointerToUniquePtr(int a, int b, int c)
0194         : a_(a), b_(b), contained_(new SchemaEvolutionContained(c)) {}
0195     ~SchemaEvolutionPointerToUniquePtr() { delete contained_; }
0196     int a_;
0197     int b_;
0198     SchemaEvolutionContained* contained_;
0199 #else
0200     SchemaEvolutionPointerToUniquePtr() : a_(0), b_(0) {}
0201     SchemaEvolutionPointerToUniquePtr(int a, int b, int c)
0202         : a_(a), b_(b), contained_(std::make_unique<SchemaEvolutionContained>(c)) {}
0203     SchemaEvolutionPointerToUniquePtr(SchemaEvolutionPointerToUniquePtr const& other)
0204         : a_(other.a_), b_(other.b_), contained_(std::make_unique<SchemaEvolutionContained>(other.contained_->c_)) {}
0205     int a_;
0206     int b_;
0207     std::unique_ptr<SchemaEvolutionContained> contained_;
0208 #endif
0209   };
0210 
0211   class SchemaEvolutionCArrayToStdArray {
0212   public:
0213 #if defined DataFormats_TestObjects_USE_OLD
0214     SchemaEvolutionCArrayToStdArray() : a_{0, 0, 0} {}
0215     SchemaEvolutionCArrayToStdArray(int x, int y, int z) : a_{x, y, z} {}
0216     int a_[3];
0217 #else
0218     SchemaEvolutionCArrayToStdArray() : a_{{0, 0, 0}} {}
0219     SchemaEvolutionCArrayToStdArray(int x, int y, int z) : a_{{x, y, z}} {}
0220     std::array<int, 3> a_;
0221 #endif
0222   };
0223 
0224   class SchemaEvolutionCArrayToStdVector {
0225   public:
0226 #if defined DataFormats_TestObjects_USE_OLD
0227     SchemaEvolutionCArrayToStdVector() : a_{new int[fSize_]{0, 0, 0}} {}
0228     SchemaEvolutionCArrayToStdVector(int x, int y, int z) : a_{new int[fSize_]{x, y, z}} {}
0229     SchemaEvolutionCArrayToStdVector(SchemaEvolutionCArrayToStdVector const& other)
0230         : a_(new int[fSize_]{other.a_[0], other.a_[1], other.a_[2]}) {}
0231     SchemaEvolutionCArrayToStdVector(SchemaEvolutionCArrayToStdVector&&) = delete;
0232     SchemaEvolutionCArrayToStdVector& operator=(SchemaEvolutionCArrayToStdVector const&) = delete;
0233     SchemaEvolutionCArrayToStdVector& operator=(SchemaEvolutionCArrayToStdVector&&) = delete;
0234     ~SchemaEvolutionCArrayToStdVector() { delete[] a_; }
0235 
0236     int fSize_ = 3;
0237     int* a_;  //[fSize_]
0238 #else
0239     SchemaEvolutionCArrayToStdVector() : a_{0, 0, 0} {}
0240     SchemaEvolutionCArrayToStdVector(int x, int y, int z) : a_{x, y, z} {}
0241     std::vector<int> a_;
0242 #endif
0243   };
0244 
0245   class SchemaEvolutionVectorToList {
0246   public:
0247     SchemaEvolutionVectorToList() : a_{0, 0, 0} {}
0248     SchemaEvolutionVectorToList(int x, int y, int z) : a_{x, y, z} {}
0249 #if defined DataFormats_TestObjects_USE_OLD
0250     std::vector<int> a_;
0251 #else
0252     std::list<int> a_;
0253 #endif
0254   };
0255 
0256   class SchemaEvolutionMapToUnorderedMap {
0257   public:
0258     SchemaEvolutionMapToUnorderedMap() {
0259       a_.insert({0, 0});
0260       a_.insert({1, 0});
0261       a_.insert({2, 0});
0262     }
0263     SchemaEvolutionMapToUnorderedMap(int keyX, int x, int keyY, int y, int keyZ, int z) {
0264       a_.insert({keyX, x});
0265       a_.insert({keyY, y});
0266       a_.insert({keyZ, z});
0267     }
0268 #if defined DataFormats_TestObjects_USE_OLD
0269     std::map<int, int> a_;
0270 #else
0271     std::unordered_map<int, int> a_;
0272 #endif
0273   };
0274 
0275   class VectorVectorElement {
0276   public:
0277     VectorVectorElement();
0278     VectorVectorElement(int a,
0279                         int b,
0280                         SchemaEvolutionChangeOrder const&,
0281                         SchemaEvolutionAddMember const&,
0282                         SchemaEvolutionRemoveMember const&,
0283                         SchemaEvolutionMoveToBase const&,
0284                         SchemaEvolutionChangeType const&,
0285                         SchemaEvolutionAddBase const&,
0286                         SchemaEvolutionPointerToMember const&,
0287                         SchemaEvolutionPointerToUniquePtr const&,
0288                         SchemaEvolutionCArrayToStdArray const&,
0289                         // SchemaEvolutionCArrayToStdVector const&,
0290                         SchemaEvolutionVectorToList const&,
0291                         SchemaEvolutionMapToUnorderedMap const&);
0292 #if defined DataFormats_TestObjects_USE_OLD
0293     int a_;
0294     int b_;
0295 #else
0296     int a_;
0297     int b_;
0298     int c_ = 0;
0299 #endif
0300     SchemaEvolutionChangeOrder changeOrder_;
0301     SchemaEvolutionAddMember addMember_;
0302     SchemaEvolutionRemoveMember removeMember_;
0303     SchemaEvolutionMoveToBase moveToBase_;
0304     SchemaEvolutionChangeType changeType_;
0305     SchemaEvolutionAddBase addBase_;
0306     SchemaEvolutionPointerToMember pointerToMember_;
0307     SchemaEvolutionPointerToUniquePtr pointerToUniquePtr_;
0308     SchemaEvolutionCArrayToStdArray cArrayToStdArray_;
0309     // This one is commented out because it fails reading an old format
0310     // input file with an executable built with the modified format.
0311     // If the issue in ROOT is ever fixed and this is added back,
0312     // it also would need to be added into the constructor above.
0313     // SchemaEvolutionCArrayToStdVector cArrayToStdVector_;
0314     SchemaEvolutionVectorToList vectorToList_;
0315     SchemaEvolutionMapToUnorderedMap mapToUnorderedMap_;
0316   };
0317 
0318   class VectorVectorElementNonSplit {
0319   public:
0320     VectorVectorElementNonSplit();
0321     VectorVectorElementNonSplit(int a, int b);
0322 #if defined DataFormats_TestObjects_USE_OLD
0323     // This version of the class is forced to be non-split because
0324     // it has only one data member. The unit test this is used by
0325     // was developed in response to a ROOT bug in the version of ROOT
0326     // associated with CMSSW_13_0_0. This bug only affected non split
0327     // classes and this class was necessary to reproduce it.
0328     int a_;
0329 #else
0330     int a_;
0331     int b_;
0332 #endif
0333   };
0334 
0335 }  // namespace edmtest
0336 
0337 #endif