Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 13:29:44

0001 #include <string>
0002 #include <iostream>
0003 
0004 #if !defined(__CINT__) && !defined(__MAKECINT__)
0005 //Headers for the data items
0006 #include "DataFormats/FWLite/interface/Handle.h"
0007 #include "DataFormats/FWLite/interface/Event.h"
0008 #include "SimDataFormats/RandomEngine/interface/RandomEngineState.h"
0009 #endif
0010 
0011 template<typename T>
0012 class PrintToStdOut{
0013    public: 
0014       PrintToStdOut(const std::string& prefix = ""): prefix_(prefix) {}
0015       void operator()(const T& item){std::cout << prefix_ << item << std::endl;}
0016    private:
0017       std::string prefix_;
0018 };
0019 
0020 void printSeeds(const std::vector<std::string>& fileNames, int maxEvents = -1, const char* processName = "HLT"){
0021 
0022    std::cout << ">>> Reading files: " << std::endl;
0023    for(std::vector<std::string>::const_iterator it = fileNames.begin(); it != fileNames.end(); ++it) std::cout << "  " << *it << std::endl; 
0024    // Chain the input files
0025    fwlite::ChainEvent ev(fileNames);
0026 
0027    // Loop over the events
0028    int nEvts = 0;
0029    std::vector<std::string> labelNames;
0030    labelNames.push_back("@source");
0031    labelNames.push_back("generator");
0032    for( ev.toBegin(); ! ev.atEnd(); ++ev) {
0033 
0034      if((maxEvents > 0)&&(nEvts == maxEvents)) break;
0035 
0036      ++nEvts;
0037      std::cout << ">>> Event number: " << nEvts << endl;
0038 
0039      fwlite::Handle<std::vector<RandomEngineState> > rndmEngineStateCollection;
0040      rndmEngineStateCollection.getByLabel(ev,"randomEngineStateProducer","",processName);
0041 
0042      const std::vector<RandomEngineState>& randomEngineStates = *rndmEngineStateCollection;
0043 
0044      std::vector<RandomEngineState>::const_iterator it_rndm = randomEngineStates.begin();
0045      std::vector<RandomEngineState>::const_iterator it_rndm_end = randomEngineStates.end();
0046      for(; it_rndm != it_rndm_end; ++it_rndm){
0047         if(std::find(labelNames.begin(),labelNames.end(),it_rndm->getLabel()) == labelNames.end()) continue;
0048 
0049         //std::cout << "   label " << it_rndm->getLabel() << std::endl;
0050         //const std::vector<unsigned int>& states = it_rndm->getState();
0051         const std::vector<unsigned int>& seeds = it_rndm->getSeed();
0052         //std::for_each(states.begin(),states.end(),PrintToStdOut<unsigned int>());
0053         std::for_each(seeds.begin(),seeds.end(),PrintToStdOut<unsigned int>(it_rndm->getLabel() + "  "));
0054      }
0055    }
0056 }