CMS 3D CMS Logo

TextToRaw Class Reference

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

#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 (const edm::EventSetup &)
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 int EVT_MAX_SIZE = 4096


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 lat::endl(), and filename_.

00028                                                    :
00029   fedId_(iConfig.getUntrackedParameter<int>("fedId", 745)),
00030   filename_(iConfig.getUntrackedParameter<string>("filename", "slinkOutput.txt")),
00031   fileEventOffset_(iConfig.getUntrackedParameter<int>("FileEventOffset", 0)),
00032   nevt_(0)
00033 {
00034   edm::LogInfo("TextToDigi") << "Reading ASCII dump from " << filename_ << endl;
00035 
00036   //register the products
00037   produces<FEDRawDataCollection>();
00038 
00039 }

TextToRaw::~TextToRaw (  ) 

Definition at line 42 of file TextToRaw.cc.

00043 {
00044  
00045    // do anything here that needs to be done at desctruction time
00046    // (e.g. close files, deallocate resources etc.)
00047 
00048 }


Member Function Documentation

void TextToRaw::beginJob ( const edm::EventSetup  )  [private, virtual]

Reimplemented from edm::EDProducer.

Definition at line 149 of file TextToRaw.cc.

References lat::endl(), file_, filename_, and in.

00150 {
00151   // open VME file
00152   file_.open(filename_.c_str(), ios::in);
00153   if(!file_.good()) { edm::LogInfo("TextToDigi") << "Failed to open ASCII file " << filename_ << endl; }
00154 }

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

Reimplemented from edm::EDProducer.

Definition at line 159 of file TextToRaw.cc.

References file_.

00159                   {
00160   file_.close();
00161 }

void TextToRaw::produce ( edm::Event iEvent,
const edm::EventSetup iSetup 
) [private, virtual]

Implements edm::EDProducer.

Definition at line 63 of file TextToRaw.cc.

References funct::abs(), c, d, FEDRawData::data(), data_, lat::endl(), EVT_MAX_SIZE, Exception, fedId_, file_, fileEventOffset_, i, j, parsecf::pyparsing::line(), nevt_, edm::Event::put(), putEmptyDigi(), and FEDRawData::resize().

00064 {
00065   using namespace edm;
00066    
00067   // Skip event if required
00068   if (nevt_ < fileEventOffset_){
00069     putEmptyDigi(iEvent);
00070     nevt_++;
00071     return;
00072   } else if (nevt_==0 && fileEventOffset_<0) {
00073     string line;
00074     //skip first fileEventOffset input crossings 
00075     for(int i=0; i<abs(fileEventOffset_); i++) {
00076       int iline=0;
00077       while (getline(file_, line) && !line.empty()) {
00078         iline++;
00079         if(iline*4>=EVT_MAX_SIZE)       
00080           throw cms::Exception("TextToRawEventSizeOverflow")
00081             << "TextToRaw::produce() : "
00082             << " read too many lines (" << iline << ": " << line << ")" 
00083             << ", maximum event size is " << EVT_MAX_SIZE
00084             << std::endl;
00085       }
00086     }
00087   }
00088   
00089   nevt_++;
00090   
00091    // read file
00092    string line;
00093    int i=0; // count 32-bit words
00094 
00095    // while not encountering dumb errors
00096    while (getline(file_, line) && !line.empty() ) {
00097 
00098      // bail if we reached the EVT_MAX_SIZE
00099      if (i*4>=EVT_MAX_SIZE) {
00100        throw cms::Exception("TextToRaw")
00101          << "Read too many lines from file. Maximum event size is " << EVT_MAX_SIZE << " lines" << std::endl;
00102      }
00103 
00104      // convert string to int
00105      std::istringstream iss(line);
00106      unsigned long d;
00107      iss >> std::hex >> d;
00108 
00109      // copy data
00110      for (int j=0; j<4; j++) {
00111        if ( (i*4+j) < EVT_MAX_SIZE ) { 
00112          char c = (d>>(8*j))&0xff;
00113          data_[i*4+j] = c;
00114        }
00115      }
00116 
00117      ++i;
00118 
00119      // bail if we reached the EVT_MAX_SIZE
00120      if (i>=EVT_MAX_SIZE) {
00121        throw cms::Exception("TextToRaw")
00122          << "Read too many lines from file. Maximum event size is " << EVT_MAX_SIZE << " lines" << std::endl;
00123      }
00124 
00125    }
00126 
00127    int evtSize = i * 4;
00128 
00129    // create the collection
00130    std::auto_ptr<FEDRawDataCollection> rawColl(new FEDRawDataCollection()); 
00131    // retrieve the target buffer
00132    FEDRawData& feddata=rawColl->FEDData(fedId_);
00133    // Allocate space for header+trailer+payload
00134    feddata.resize(evtSize);
00135 
00136    // fill FEDRawData object
00137    for (unsigned i=0; i<evtSize; ++i) {
00138      feddata.data()[i] = data_[i];
00139    }
00140 
00141    // put the collection in the event
00142    iEvent.put(rawColl);
00143      
00144 }

void TextToRaw::putEmptyDigi ( edm::Event iEvent  )  [private]

Append empty digi collection.

Definition at line 53 of file TextToRaw.cc.

References edm::Event::put().

Referenced by produce().

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


Member Data Documentation

char TextToRaw::data_[EVT_MAX_SIZE] [private]

Definition at line 62 of file TextToRaw.h.

Referenced by produce().

const int TextToRaw::EVT_MAX_SIZE = 4096 [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().

int TextToRaw::fileEventOffset_ [private]

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().


The documentation for this class was generated from the following files:
Generated on Tue Jun 9 18:33:23 2009 for CMSSW by  doxygen 1.5.4