Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:19:09

0001 // Use something like the following to run this file:
0002 //
0003 //   root.exe -b -l -q SchemaEvolutionTest.root 'IOPool/Input/test/testForStreamerInfo.C(gFile)' | sort -u
0004 //
0005 // In the output, lines with "Missing" indicate problems.
0006 
0007 // Note the script ignores classes whose name start with "T"
0008 // to ignore ROOT classes. In the context this is used, none
0009 // of the interesting classes start with "T" (although if used
0010 // generally use I can imagine this could cause some confusion...).
0011 
0012 // This is a modified version of some temporary code Philippe Canal
0013 // provided us while debugging a problem.
0014 
0015 #include "TFile.h"
0016 #include "TStreamerInfo.h"
0017 #include "TList.h"
0018 #include "TVirtualCollectionProxy.h"
0019 #include "TStreamerElement.h"
0020 #include <iostream>
0021 
0022 void check(TClass &cl, TList &streamerInfoList) {
0023   std::string name(cl.GetName());
0024   if (name == "string")
0025     return;
0026   if (0 == name.compare(0, strlen("pair<"), "pair<"))
0027     return;
0028   std::cout << "check TClass: " << name << std::endl;
0029   bool found = streamerInfoList.FindObject(cl.GetName()) != 0;
0030   if (!found)
0031     std::cout << "Missing: " << cl.GetName() << '\n';
0032 }
0033 
0034 void check(TVirtualCollectionProxy &proxy, TList &streamerInfoList) {
0035   auto inner = proxy.GetValueClass();
0036   if (inner) {
0037     auto subproxy = inner->GetCollectionProxy();
0038     if (subproxy) {
0039       check(*subproxy, streamerInfoList);
0040     } else {
0041       check(*inner, streamerInfoList);
0042     }
0043   }
0044 }
0045 
0046 void check(TStreamerElement &element, TList &streamerInfoList) {
0047   auto cl = element.GetClass();
0048   if (cl == nullptr) {
0049     return;
0050   }
0051   // Ignore all classes that start with a T with the intent
0052   // to ignore all internal ROOT classes
0053   // (In general this might ignore other interesting classes,
0054   // but this is intended to be used in a specific test where the
0055   // the interesting classes don't start with T).
0056   if (*(cl->GetName()) == 'T') {
0057     return;
0058   }
0059   if (cl->GetCollectionProxy()) {
0060     check(*cl->GetCollectionProxy(), streamerInfoList);
0061   } else {
0062     check(*cl, streamerInfoList);
0063   }
0064 }
0065 
0066 // This is called once for each TStreamerInfo in
0067 // streamerInfoList. The info is the first argument
0068 // and the list of all the infos is the second argument.
0069 void scan(TStreamerInfo &info, TList &streamerInfoList) {
0070   auto cl = TClass::GetClass(info.GetName());
0071   // print error message and do skip the info if there
0072   // is not a TClass available.
0073   if (!cl) {
0074     //std::cerr << "Error no TClass for " << info.GetName() << '\n';
0075     return;
0076   }
0077   auto proxy = cl->GetCollectionProxy();
0078   if (proxy)
0079     check(*proxy, streamerInfoList);
0080   for (auto e : TRangeDynCast<TStreamerElement>(*info.GetElements())) {
0081     if (!e)
0082       continue;
0083     check(*e, streamerInfoList);
0084   }
0085 }
0086 
0087 void scan(TList *streamerInfoList) {
0088   if (!streamerInfoList)
0089     return;
0090   for (auto l : TRangeDynCast<TStreamerInfo>(*streamerInfoList)) {
0091     if (!l)
0092       continue;
0093     // Ignore all classes that start with a T with the intent
0094     // to ignore all internal ROOT classes
0095     // (In general this might ignore other interesting classes,
0096     // but this is intended to be used in a specific test where the
0097     // the interesting classes don't start with T).
0098     if (*(l->GetName()) == 'T') {
0099       continue;
0100     }
0101     //std::cout << "Seeing: " << l->GetName() << " " << l->GetClassVersion() << '\n';
0102     scan(*l, *streamerInfoList);
0103   }
0104   delete streamerInfoList;
0105 }
0106 
0107 void testForStreamerInfo(TFile *file) {
0108   if (!file)
0109     return;
0110   scan(file->GetStreamerInfoList());
0111 }