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