CMS 3D CMS Logo

Public Member Functions | Private Member Functions | Private Attributes | Static Private Attributes

TextToRaw Class Reference

#include <L1Triggr/TextToDigi/src/TextToRaw.cc>

Inheritance diagram for TextToRaw:
edm::EDProducer edm::ProducerBase edm::ProductRegistryHelper

List of all members.

Public Member Functions

 TextToRaw (const edm::ParameterSet &)
 ~TextToRaw ()

Private Member Functions

virtual void beginJob ()
virtual void endJob ()
virtual void produce (edm::Event &, const edm::EventSetup &)
void putEmptyDigi (edm::Event &)
 Append empty digi collection.

Private Attributes

char data_ [EVT_MAX_SIZE]
int fedId_
std::ifstream file_
int fileEventOffset_
std::string filename_
int nevt_

Static Private Attributes

static const unsigned EVT_MAX_SIZE = 8192

Detailed Description

Description: Convert ASCII dump of a raw event to FEDRawData format for unpacking

Implementation: Input format is a 32 bit hex string per line (LSW first). Events separated with blank line.

Definition at line 41 of file TextToRaw.h.


Constructor & Destructor Documentation

TextToRaw::TextToRaw ( const edm::ParameterSet iConfig) [explicit]

Definition at line 28 of file TextToRaw.cc.

References filename_.

                                                   :
  fedId_(iConfig.getUntrackedParameter<int>("fedId", 745)),
  filename_(iConfig.getUntrackedParameter<std::string>("filename", "slinkOutput.txt")),
  fileEventOffset_(iConfig.getUntrackedParameter<int>("FileEventOffset", 0)),
  nevt_(0)
{
  edm::LogInfo("TextToDigi") << "Reading ASCII dump from " << filename_ << std::endl;

  //register the products
  produces<FEDRawDataCollection>();

}
TextToRaw::~TextToRaw ( )

Definition at line 42 of file TextToRaw.cc.

{
 
   // do anything here that needs to be done at desctruction time
   // (e.g. close files, deallocate resources etc.)

}

Member Function Documentation

void TextToRaw::beginJob ( void  ) [private, virtual]

Reimplemented from edm::EDProducer.

Definition at line 149 of file TextToRaw.cc.

References file_, filename_, and recoMuon::in.

{
  // open VME file
  file_.open(filename_.c_str(), std::ios::in);
  if(!file_.good()) { edm::LogInfo("TextToDigi") << "Failed to open ASCII file " << filename_ << std::endl; }
}
void TextToRaw::endJob ( void  ) [private, virtual]

Reimplemented from edm::EDProducer.

Definition at line 159 of file TextToRaw.cc.

References file_.

                  {
  file_.close();
}
void TextToRaw::produce ( edm::Event iEvent,
const edm::EventSetup iSetup 
) [private, virtual]

Implements edm::EDProducer.

Definition at line 63 of file TextToRaw.cc.

References abs, trackerHits::c, data_, EVT_MAX_SIZE, Exception, fedId_, ExpressReco_HICollisions_FallBack::FEDRawDataCollection, file_, fileEventOffset_, i, ntuplemaker::iline, j, geometryCSVtoXML::line, nevt_, edm::Event::put(), putEmptyDigi(), and FEDRawData::resize().

{
  using namespace edm;
   
  // Skip event if required
  if (nevt_ < fileEventOffset_){
    putEmptyDigi(iEvent);
    nevt_++;
    return;
  } else if (nevt_==0 && fileEventOffset_<0) {
    std::string line;
    //skip first fileEventOffset input crossings 
    for(unsigned i=0; i<(unsigned)abs(fileEventOffset_); i++) {
      unsigned iline=0;
      while (getline(file_, line) && !line.empty()) {
        iline++;
        if(iline*4>=EVT_MAX_SIZE)       
          throw cms::Exception("TextToRawEventSizeOverflow")
            << "TextToRaw::produce() : "
            << " read too many lines (" << iline << ": " << line << ")" 
            << ", maximum event size is " << EVT_MAX_SIZE
            << std::endl;
      }
    }
  }
  
  nevt_++;
  
   // read file
   std::string line;
   unsigned i=0; // count 32-bit words

   // while not encountering dumb errors
   while (getline(file_, line) && !line.empty() ) {

     // bail if we reached the EVT_MAX_SIZE
     if (i*4>=EVT_MAX_SIZE) {
       throw cms::Exception("TextToRaw")
         << "Read too many lines from file. Maximum event size is " << EVT_MAX_SIZE << " lines" << std::endl;
     }

     // convert string to int
     std::istringstream iss(line);
     unsigned long d;
     iss >> std::hex >> d;

     // copy data
     for (int j=0; j<4; j++) {
       if ( (i*4+j) < EVT_MAX_SIZE ) { 
         char c = (d>>(8*j))&0xff;
         data_[i*4+j] = c;
       }
     }

     ++i;

     // bail if we reached the EVT_MAX_SIZE
     if (i>=EVT_MAX_SIZE) {
       throw cms::Exception("TextToRaw")
         << "Read too many lines from file. Maximum event size is " << EVT_MAX_SIZE << " lines" << std::endl;
     }

   }

   unsigned evtSize = i * 4;

   // create the collection
   std::auto_ptr<FEDRawDataCollection> rawColl(new FEDRawDataCollection()); 
   // retrieve the target buffer
   FEDRawData& feddata=rawColl->FEDData(fedId_);
   // Allocate space for header+trailer+payload
   feddata.resize(evtSize);

   // fill FEDRawData object
   for (unsigned i=0; i<evtSize; ++i) {
     feddata.data()[i] = data_[i];
   }

   // put the collection in the event
   iEvent.put(rawColl);
     
}
void TextToRaw::putEmptyDigi ( edm::Event iEvent) [private]

Append empty digi collection.

Definition at line 53 of file TextToRaw.cc.

References ExpressReco_HICollisions_FallBack::FEDRawDataCollection, and edm::Event::put().

Referenced by produce().

                                             {
  std::auto_ptr<FEDRawDataCollection> rawColl(new FEDRawDataCollection()); 
  //FEDRawData& feddata=rawColl->FEDData(fedId_);
  //feddata.data()[0] = 0;
  iEvent.put(rawColl);
}

Member Data Documentation

char TextToRaw::data_[EVT_MAX_SIZE] [private]

Definition at line 62 of file TextToRaw.h.

Referenced by produce().

const unsigned TextToRaw::EVT_MAX_SIZE = 8192 [static, private]

Definition at line 61 of file TextToRaw.h.

Referenced by produce().

int TextToRaw::fedId_ [private]

Definition at line 54 of file TextToRaw.h.

Referenced by produce().

std::ifstream TextToRaw::file_ [private]

Definition at line 58 of file TextToRaw.h.

Referenced by beginJob(), endJob(), and produce().

Definition at line 64 of file TextToRaw.h.

Referenced by produce().

std::string TextToRaw::filename_ [private]

Definition at line 57 of file TextToRaw.h.

Referenced by beginJob(), and TextToRaw().

int TextToRaw::nevt_ [private]

Definition at line 65 of file TextToRaw.h.

Referenced by produce().