CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
TextToRaw.cc
Go to the documentation of this file.
1 
2 
4 
5 // system
6 #include <vector>
7 #include <string>
8 #include <fstream>
9 #include <iostream>
10 
11 // framework
13 
15 
16 // Raw data collection
18 
19 using std::vector;
20 using std::cerr;
21 using std::cout;
22 using std::endl;
23 using std::string;
24 using std::ios;
25 
26 const unsigned TextToRaw::EVT_MAX_SIZE;
27 
29  fedId_(iConfig.getUntrackedParameter<int>("fedId", 745)),
30  filename_(iConfig.getUntrackedParameter<std::string>("filename", "slinkOutput.txt")),
31  fileEventOffset_(iConfig.getUntrackedParameter<int>("FileEventOffset", 0)),
32  nevt_(0)
33 {
34  edm::LogInfo("TextToDigi") << "Reading ASCII dump from " << filename_ << std::endl;
35 
36  //register the products
37  produces<FEDRawDataCollection>();
38 
39 }
40 
41 
43 {
44 
45  // do anything here that needs to be done at desctruction time
46  // (e.g. close files, deallocate resources etc.)
47 
48 }
49 
50 
51 
54  std::auto_ptr<FEDRawDataCollection> rawColl(new FEDRawDataCollection());
55  //FEDRawData& feddata=rawColl->FEDData(fedId_);
56  //feddata.data()[0] = 0;
57  iEvent.put(rawColl);
58 }
59 
60 
61 // ------------ method called to produce the data ------------
62 void
64 {
65  using namespace edm;
66 
67  // Skip event if required
68  if (nevt_ < fileEventOffset_){
69  putEmptyDigi(iEvent);
70  nevt_++;
71  return;
72  } else if (nevt_==0 && fileEventOffset_<0) {
74  //skip first fileEventOffset input crossings
75  for(unsigned i=0; i<(unsigned)abs(fileEventOffset_); i++) {
76  unsigned iline=0;
77  while (getline(file_, line) && !line.empty()) {
78  iline++;
79  if(iline*4>=EVT_MAX_SIZE)
80  throw cms::Exception("TextToRawEventSizeOverflow")
81  << "TextToRaw::produce() : "
82  << " read too many lines (" << iline << ": " << line << ")"
83  << ", maximum event size is " << EVT_MAX_SIZE
84  << std::endl;
85  }
86  }
87  }
88 
89  nevt_++;
90 
91  // read file
93  unsigned i=0; // count 32-bit words
94 
95  // while not encountering dumb errors
96  while (getline(file_, line) && !line.empty() ) {
97 
98  // bail if we reached the EVT_MAX_SIZE
99  if (i*4>=EVT_MAX_SIZE) {
100  throw cms::Exception("TextToRaw")
101  << "Read too many lines from file. Maximum event size is " << EVT_MAX_SIZE << " lines" << std::endl;
102  }
103 
104  // convert string to int
105  std::istringstream iss(line);
106  unsigned long d;
107  iss >> std::hex >> d;
108 
109  // copy data
110  for (int j=0; j<4; j++) {
111  if ( (i*4+j) < EVT_MAX_SIZE ) {
112  char c = (d>>(8*j))&0xff;
113  data_[i*4+j] = c;
114  }
115  }
116 
117  ++i;
118 
119  // bail if we reached the EVT_MAX_SIZE
120  if (i>=EVT_MAX_SIZE) {
121  throw cms::Exception("TextToRaw")
122  << "Read too many lines from file. Maximum event size is " << EVT_MAX_SIZE << " lines" << std::endl;
123  }
124 
125  }
126 
127  unsigned evtSize = i * 4;
128 
129  // create the collection
130  std::auto_ptr<FEDRawDataCollection> rawColl(new FEDRawDataCollection());
131  // retrieve the target buffer
132  FEDRawData& feddata=rawColl->FEDData(fedId_);
133  // Allocate space for header+trailer+payload
134  feddata.resize(evtSize);
135 
136  // fill FEDRawData object
137  for (unsigned i=0; i<evtSize; ++i) {
138  feddata.data()[i] = data_[i];
139  }
140 
141  // put the collection in the event
142  iEvent.put(rawColl);
143 
144 }
145 
146 
147 // ------------ method called once each job just before starting event loop ------------
148 void
150 {
151  // open VME file
152  file_.open(filename_.c_str(), std::ios::in);
153  if(!file_.good()) { edm::LogInfo("TextToDigi") << "Failed to open ASCII file " << filename_ << std::endl; }
154 }
155 
156 
157 // ------------ method called once each job just after ending the event loop ------------
158 void
160  file_.close();
161 }
162 
int i
Definition: DBlmapReader.cc:9
std::ifstream file_
Definition: TextToRaw.h:57
void putEmptyDigi(edm::Event &)
Append empty digi collection.
Definition: TextToRaw.cc:53
int fileEventOffset_
Definition: TextToRaw.h:63
~TextToRaw()
Definition: TextToRaw.cc:42
int nevt_
Definition: TextToRaw.h:64
std::string filename_
Definition: TextToRaw.h:56
char data_[EVT_MAX_SIZE]
Definition: TextToRaw.h:61
static const unsigned EVT_MAX_SIZE
Definition: TextToRaw.h:60
virtual void beginJob()
Definition: TextToRaw.cc:149
tuple d
Definition: ztail.py:151
int iEvent
Definition: GenABIO.cc:230
TextToRaw(const edm::ParameterSet &)
Definition: TextToRaw.cc:28
void resize(size_t newsize)
Definition: FEDRawData.cc:32
OrphanHandle< PROD > put(std::auto_ptr< PROD > product)
Put a new product.
Definition: Event.h:120
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
int j
Definition: DBlmapReader.cc:9
virtual void endJob()
Definition: TextToRaw.cc:159
int fedId_
Definition: TextToRaw.h:53
tuple cout
Definition: gather_cfg.py:121
virtual void produce(edm::Event &, const edm::EventSetup &)
Definition: TextToRaw.cc:63