Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2025-02-21 05:46:28

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 int chainevent_looping_cint() {
0024   vector<string> files;
0025   files.push_back("empty_a.root");
0026   files.push_back("good_a.root");
0027   files.push_back("empty_a.root");
0028   files.push_back("good_b.root");
0029   files.push_back("empty_a.root");
0030   fwlite::ChainEvent e(files);
0031 
0032   int i = 0;
0033   int returnValue = 0;
0034   TFile* f = 0;
0035 
0036   for (; e.isValid(); ++e, ++i) {
0037     if (e.getTFile() != f) {
0038       f = e.getTFile();
0039       cout << "New file " << f->GetName() << endl;
0040     }
0041 
0042     fwlite::Handle<vector<edmtest::Thing> > pThing;
0043     //pThing.getByLabel(e,"Thing","","TEST"); //WORKS
0044     pThing.getByLabel(e, "Thing");
0045 
0046     for (i = 0; i != pThing.ref().size(); ++i) {
0047       cout << pThing.ref().at(i).a << " ";
0048     }
0049     cout << endl;
0050   }
0051   if (i == 0) {
0052     cout << "First loop failed!" << endl;
0053     returnValue = 1;
0054   }
0055   e.toBegin();
0056 
0057   i = 0;
0058   for (; e; ++e, ++i) {
0059   }
0060 
0061   if (i == 0) {
0062     cout << "Second loop failed!" << endl;
0063     returnValue = 1;
0064   }
0065 
0066   i = 0;
0067   for (e.toBegin(); !e.atEnd(); ++e, ++i) {
0068     fwlite::Handle<vector<edmtest::Thing> > pThing;
0069     //pThing.getByLabel(e,"Thing","","TEST"); //WORKS
0070     pThing.getByLabel(e, "Thing");
0071 
0072     for (i = 0; i != pThing.ref().size(); ++i) {
0073       cout << pThing.ref().at(i).a << " ";
0074     }
0075     cout << endl;
0076     //DOES NOT WORK in CINT
0077     //for(vector<edmtest::Thing>::const_iterator it = pThing.data()->begin(); it != pThing.data()->end();++it) {
0078     //   cout <<(*it).a<<endl;
0079     //}
0080   }
0081   if (i == 0) {
0082     cout << "Third loop failed!" << endl;
0083     returnValue = 1;
0084   }
0085   e.to(0);
0086   for (int j = 0; j < 20; ++j) {
0087     int k = rand() % 10;
0088     if (e.to(k)) {
0089       edm::EventID id = e.id();
0090       cout << "Entry " << k << " Run " << id.run() << " event " << id.event() << endl;
0091     } else {
0092       cout << "Entry " << k << " is not valid" << endl;
0093     }
0094   }
0095 
0096   e.to(0);
0097   long size = e.size();
0098   edm::EventID last;
0099   for (long l = 0; l < size; ++l) {
0100     e.to(l);
0101     edm::EventID id = e.id();
0102     cout << "Entry " << l << " Run " << id.run() << " event " << id.event() << endl;
0103     if (last == id) {
0104       returnValue = 1;
0105       cout << "duplicate event (" << id.run() << "," << id.event() << ") seen at index " << l << " while testing 'to'"
0106            << endl;
0107       break;
0108     }
0109   }
0110 
0111   return returnValue;
0112 }