CMS 3D CMS Logo

DAQEcalTBInputService.cc

Go to the documentation of this file.
00001 /*
00002  *  $Date: 2008/04/13 07:43:19 $
00003  *  $Revision: 1.20 $
00004  *  \author N. Amapane - S. Argiro'
00005  *  \author G. Franzoni
00006  */
00007 
00008 #include "DAQEcalTBInputService.h"
00009 
00010 #include "IORawData/EcalTBInputService/src/EcalTBDaqFileReader.h"
00011 
00012 #include <FWCore/Framework/interface/Event.h>
00013 #include <FWCore/ParameterSet/interface/ParameterSet.h>
00014 
00015 #include <iostream>
00016 
00017 using namespace edm;
00018 using namespace std;
00019 
00020 DAQEcalTBInputService::DAQEcalTBInputService(const ParameterSet& pset, 
00021                                              const InputSourceDescription& desc) : 
00022   edm::ExternalInputSource(pset,desc), reader_(0), fileCounter_(0), eventRead_(0)
00023 {    
00024   isBinary_= pset.getUntrackedParameter<bool>("isBinary",true);
00025   if ( isBinary_ ) {
00026     LogInfo("EcalTBInputService") << "@SUB=DAQEcalTBInputService" << "BINARY input data file";
00027   } else {
00028     LogInfo("EcalTBInputService") << "@SUB=DAQEcalTBInputService" << "ASCII input data file";
00029   }
00030   runNumber_ = pset.getUntrackedParameter<unsigned int>("runNumber", 1);
00031   reader_ = new EcalTBDaqFileReader();
00032   produces<FEDRawDataCollection>();
00033 }
00034 
00035 
00036 DAQEcalTBInputService::~DAQEcalTBInputService(){
00037   if (reader_)
00038     delete reader_;
00039   //  clear();
00040 }
00041 
00042 
00043 // void DAQEcalTBInputService::clear() {
00044 //   for(map<int, DaqFEDRawData *>::iterator it = daqevdata_.begin();
00045 //       it != daqevdata_.end(); ++it) {
00046 //     delete (*it).second;
00047 //   }
00048 //   daqevdata_.clear();
00049 // }
00050 
00051 void DAQEcalTBInputService::setRunAndEventInfo()
00052 {
00053   
00054   eventRead_=false;
00055 
00056   if ( !reader_->isInitialized() || reader_->checkEndOfFile() )
00057     {
00058       if (fileCounter_>=(unsigned int)(fileNames().size())) return; // nothing good
00059       reader_->initialize(fileNames()[fileCounter_],isBinary_);
00060       fileCounter_++;
00061     }
00062   
00063   eventRead_=reader_->fillDaqEventData();
00064   
00065   if (eventRead_)
00066     {
00067       if ( reader_->getRunNumber() != 0 ) {
00068         setRunNumber(reader_->getRunNumber());
00069       } else {
00070         setRunNumber( runNumber_ );
00071       }
00072       //For the moment adding 1 by hand (CMS has event number starting from 1)
00073       setEventNumber(reader_->getEventNumber()+1);
00074       // time is a hack
00075       edm::TimeValue_t present_time = presentTime();
00076       unsigned long time_between_events = timeBetweenEvents();
00077       setTime(present_time + time_between_events);
00078     }
00079   else
00080     return;
00081 }
00082 
00083 bool DAQEcalTBInputService::produce(edm::Event& e) 
00084 {
00085   if (! eventRead_ )
00086     return false;
00087   
00088   std::auto_ptr<FEDRawDataCollection> bare_product(new  FEDRawDataCollection());
00089 
00090   FEDRawData& eventfeddata = (*bare_product).FEDData(reader_->getFedId());
00091   eventfeddata.resize(reader_->getFedData().len);
00092   copy(reader_->getFedData().fedData, reader_->getFedData().fedData + reader_->getFedData().len , eventfeddata.data());
00093 
00094   LogInfo("EcalTBInputService") << "@SUB=DAQEcalTBInputService::produce" << "read run " << reader_->getRunNumber() << " ev " << reader_->getEventNumber();
00095 
00096   e.put(bare_product);
00097 
00098   return true;
00099 }
00100 
00101 #include "FWCore/PluginManager/interface/ModuleDef.h"
00102 #include "FWCore/Framework/interface/InputSourceMacros.h"
00103 
00104 DEFINE_FWK_INPUT_SOURCE(DAQEcalTBInputService);

Generated on Tue Jun 9 17:39:24 2009 for CMSSW by  doxygen 1.5.4