Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:04:11

0001 #include <vector>
0002 #include <TFile.h>
0003 using namespace std;
0004 
0005 #if defined(__CINT__) && !defined(__MAKECINT__)
0006 class loadFWLite {
0007    public:
0008       loadFWLite() {
0009          gSystem->Load("libFWCoreFWLite");
0010          FWLiteEnabler::enable();
0011       }
0012 };
0013 
0014 static loadFWLite lfw;
0015 #endif
0016 
0017 #include "DataFormats/FWLite/interface/Handle.h"
0018 
0019 #if !defined(__CINT__) && !defined(__MAKECINT__)
0020 #include "DataFormats/TestObjects/interface/ThingCollection.h"
0021 #endif
0022 
0023 void productid_cint()
0024 {
0025   TFile f1("prodmerge.root");
0026   fwlite::Event ev(&f1);
0027   fwlite::Handle<vector<edmtest::Thing> > pThing;
0028   fwlite::Handle<vector<edmtest::OtherThing> > oThing;
0029 
0030   // test that getProcessHistory() and getBranchName() work before getting the first event
0031   const vector<string>& hist = ev.getProcessHistory();
0032   for (unsigned int i=0; i != hist.size(); ++i) {
0033     cout << hist.at(i) << " " << pThing.getBranchNameFor(ev,"Thing","",hist.at(i).c_str()) << endl;
0034   }
0035   cout << "No such thing: "<< pThing.getBranchNameFor(ev,"NoSuchThing") << endl;
0036   
0037   for (ev.toBegin(); ! ev.atEnd(); ++ev) {
0038     edm::EventID id = ev.id();
0039     cout << "Run " << id.run() << " event " << id.event() << endl;
0040     pThing.getByLabel(ev,"Thing","","TEST");
0041     cout << pThing.getBranchNameFor(ev,"Thing","","TEST") << " ";
0042     for (unsigned int i=0; i != pThing.ref().size(); ++i) {
0043       cout <<pThing.ref().at(i).a<<" ";
0044     }
0045     cout << endl;
0046     pThing.getByLabel(ev,"Thing");
0047     cout << pThing.getBranchNameFor(ev,"Thing") << " ";
0048     for (unsigned int i=0; i != pThing.ref().size(); ++i) {
0049       cout <<pThing.ref().at(i).a<<" ";
0050     }
0051     cout << endl;
0052     oThing.getByLabel(ev,"OtherThing","","FOO");
0053     cout << "Nonexistent other thing valid: " << oThing.isValid() << " failedToGet: " << oThing.failedToGet() << endl;
0054   }
0055 
0056   bool t = ev.to(1,2);
0057   edm::EventID id = ev.id();
0058   pThing.getByLabel(ev,"Thing");
0059   cout << t << " Run " << id.run() << " event " << id.event() << " " << pThing.ref().at(0).a << endl;
0060 
0061   // nonexistent event
0062   t = ev.to(1,3);
0063   id = ev.id();
0064   pThing.getByLabel(ev,"Thing");
0065   cout << t << " Run " << id.run() << " event " << id.event() << " " << pThing.ref().at(0).a << endl;
0066 
0067   t = ev.to(10,2);
0068   id = ev.id();
0069   pThing.getByLabel(ev,"Thing");
0070   cout << t << " Run " << id.run() << " event " << id.event() << " " << pThing.ref().at(0).a << endl;
0071 }