00001 #include "SiPixelDigiToRaw.h"
00002 #include "DataFormats/Common/interface/Handle.h"
00003 #include "FWCore/Framework/interface/ESHandle.h"
00004
00005 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00006
00007 #include "DataFormats/Common/interface/DetSetVector.h"
00008 #include "DataFormats/SiPixelDigi/interface/PixelDigi.h"
00009 #include "DataFormats/FEDRawData/interface/FEDRawDataCollection.h"
00010 #include "DataFormats/FEDRawData/interface/FEDRawData.h"
00011
00012 #include "CondFormats/SiPixelObjects/interface/SiPixelFedCablingMap.h"
00013 #include "CondFormats/DataRecord/interface/SiPixelFedCablingMapRcd.h"
00014
00015
00016 #include "EventFilter/SiPixelRawToDigi/interface/PixelDataFormatter.h"
00017 #include "CondFormats/SiPixelObjects/interface/PixelFEDCabling.h"
00018 using namespace std;
00019
00020 SiPixelDigiToRaw::SiPixelDigiToRaw( const edm::ParameterSet& pset ) :
00021 eventCounter_(0),
00022 fedCablingMap_(0),
00023 config_(pset)
00024
00025 {
00026
00027
00028 string label = pset.getUntrackedParameter<string>("ProductLabel","sourceXXL");
00029 produces<FEDRawDataCollection>();
00030
00031 }
00032
00033
00034 SiPixelDigiToRaw::~SiPixelDigiToRaw() {
00035 }
00036
00037
00038 void SiPixelDigiToRaw::beginJob(const edm::EventSetup& setup)
00039 {
00040 }
00041
00042
00043 void SiPixelDigiToRaw::produce( edm::Event& ev,
00044 const edm::EventSetup& es)
00045 {
00046 using namespace sipixelobjects;
00047
00048 eventCounter_++;
00049 edm::LogInfo("SiPixelDigiToRaw") << "[SiPixelDigiToRaw::produce] "
00050 << "event number: "
00051 << eventCounter_;
00052
00053 edm::Handle< edm::DetSetVector<PixelDigi> > digiCollection;
00054 static string label = config_.getUntrackedParameter<string>("InputLabel","source");
00055 static string instance = config_.getUntrackedParameter<string>("InputInstance","");
00056 ev.getByLabel( label, instance, digiCollection);
00057
00058 PixelDataFormatter::Digis digis;
00059 typedef vector< edm::DetSet<PixelDigi> >::const_iterator DI;
00060
00061 static int allDigiCounter = 0;
00062 static int allWordCounter = 0;
00063 int digiCounter = 0;
00064 for (DI di=digiCollection->begin(); di != digiCollection->end(); di++) {
00065 digiCounter += (di->data).size();
00066 digis[ di->id] = di->data;
00067
00068 }
00069 allDigiCounter += digiCounter;
00070
00071 edm::ESHandle<SiPixelFedCablingMap> map;
00072 es.get<SiPixelFedCablingMapRcd>().get( map );
00073
00074 static bool debug = edm::MessageDrop::instance()->debugEnabled;
00075 if (debug) cout << map->version() << endl;
00076
00077 PixelDataFormatter formatter(map.product());
00078
00079
00080 std::auto_ptr<FEDRawDataCollection> buffers( new FEDRawDataCollection );
00081
00082 const vector<const PixelFEDCabling *> cabling = map->fedList();
00083
00084 typedef vector<const PixelFEDCabling *>::const_iterator FI;
00085 for (FI it = cabling.begin(); it != cabling.end(); it++) {
00086 LogDebug("SiPixelDigiToRaw")<<" PRODUCE DATA FOR FED_id: " << (**it).id();
00087 FEDRawData * rawData = formatter.formatData( ev.id().event(),(**it).id(), digis);
00088 FEDRawData& fedRawData = buffers->FEDData( (**it).id() );
00089 fedRawData = *rawData;
00090 LogDebug("SiPixelDigiToRaw")<<"size of data in fedRawData: "<<fedRawData.size();
00091 delete rawData;
00092 }
00093 allWordCounter += formatter.nWords();
00094 if (debug) cout << "Words/Digis this ev: "<<digiCounter<<"(fm:"<<formatter.nDigis()<<")/"
00095 <<formatter.nWords()
00096 <<" all: "<< allDigiCounter <<"/"<<allWordCounter<<endl;
00097
00098
00099 ev.put( buffers );
00100
00101 }
00102
00103
00104