CMS 3D CMS Logo

/afs/cern.ch/work/a/aaltunda/public/www/CMSSW_6_2_5/src/EventFilter/RawDataCollector/src/RawDataCollectorByLabel.cc

Go to the documentation of this file.
00001 
00006 #include "EventFilter/RawDataCollector/src/RawDataCollectorByLabel.h"
00007 #include <DataFormats/FEDRawData/interface/FEDRawDataCollection.h> 
00008 #include <DataFormats/FEDRawData/interface/FEDRawData.h>
00009 #include <DataFormats/FEDRawData/interface/FEDNumbering.h>
00010 
00011 #include <DataFormats/Common/interface/Handle.h>
00012 #include <FWCore/Framework/interface/Event.h>
00013 #include "DataFormats/Provenance/interface/ProcessHistory.h" 
00014 #include "FWCore/Framework/interface/ESHandle.h"
00015 #include "FWCore/Framework/interface/EventSetup.h"
00016 
00017 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00018 
00019 #include <iostream>
00020 
00021 using namespace edm;
00022 
00023 RawDataCollectorByLabel::RawDataCollectorByLabel(const edm::ParameterSet& pset) {
00024 
00025   inputTags_ = pset.getParameter<std::vector<InputTag> >("RawCollectionList");
00026   verbose_ = pset.getUntrackedParameter<int>("verbose",0);
00027 
00028   produces<FEDRawDataCollection>();
00029 }
00030 
00031 RawDataCollectorByLabel::~RawDataCollectorByLabel(){
00032 
00033 }
00034 
00035 
00036 void RawDataCollectorByLabel::produce(Event & e, const EventSetup& c){
00037 
00039  std::vector< Handle<FEDRawDataCollection> > rawData;
00040  for(tag_iterator_t inputTag = inputTags_.begin(); inputTag != inputTags_.end(); ++inputTag ) {
00041    Handle<FEDRawDataCollection> input;
00042    if (e.getByLabel(*inputTag,input)){
00043      rawData.push_back(input);
00044    }
00045    //else{     //skipping the inputtag requested. but this is a normal operation to bare data & MC. silent warning   }
00046  }
00047 
00048  std::auto_ptr<FEDRawDataCollection> producedData(new FEDRawDataCollection);
00049 
00050  for (unsigned int i=0; i< rawData.size(); ++i ) { 
00051 
00052    const FEDRawDataCollection *rdc=rawData[i].product();
00053 
00054    if ( verbose_ > 0 ) {
00055      std::cout << "\nRAW collection #" << i+1 << std::endl;
00056      std::cout << "branch name = " << rawData[i].provenance()->branchName() << std::endl;
00057      std::cout << "process index = " << rawData[i].provenance()->productID().processIndex() << std::endl;
00058    }
00059 
00060    for ( int j=0; j< FEDNumbering::MAXFEDID; ++j ) {
00061      const FEDRawData & fedData = rdc->FEDData(j);
00062      size_t size=fedData.size();
00063 
00064      if ( size > 0 ) {
00065        // this fed has data -- lets copy it
00066        if(verbose_ > 1) std::cout << "Copying data from FED #" << j << std::endl;
00067        FEDRawData & fedDataProd = producedData->FEDData(j);
00068        if ( fedDataProd.size() != 0 ) {
00069          if(verbose_ > 1) {
00070            std::cout << " More than one FEDRawDataCollection with data in FED ";
00071            std::cout << j << " Skipping the 2nd\n";
00072          }
00073          continue;
00074        } 
00075        fedDataProd.resize(size);
00076        unsigned char *dataProd=fedDataProd.data();
00077        const unsigned char *data=fedData.data();
00078        for ( unsigned int k=0; k<size; ++k ) {
00079          dataProd[k]=data[k];
00080        }
00081      }
00082    }
00083  }
00084 
00085  // Insert the new product in the event  
00086  e.put(producedData);  
00087 
00088 }
00089 
00090