Go to the documentation of this file.00001
00002
00003
00004
00005
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031 #include "RctTextToRctDigi.h"
00032 #include "FWCore/ServiceRegistry/interface/Service.h"
00033 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00034 #include <iomanip>
00035
00036 using namespace edm;
00037 using namespace std;
00038
00039
00040 const static unsigned NUM_RCT_CRATES = 18;
00041
00042 RctTextToRctDigi::RctTextToRctDigi(const edm::ParameterSet& iConfig):
00043 m_textFileName(iConfig.getParameter<std::string>("TextFileName")),
00044 m_fileEventOffset(iConfig.getParameter<int>("FileEventOffset")),
00045 m_nevt(0)
00046 {
00047
00048 produces<L1CaloEmCollection>();
00049 produces<L1CaloRegionCollection>();
00050
00051
00052 for (unsigned i=0; i<NUM_RCT_CRATES; i++){
00053 std::stringstream fileStream;
00054 fileStream << m_textFileName << std::setw(2) << std::setfill('0') << i << ".txt";
00055 std::string fileName(fileStream.str());
00056 m_file[i].open(fileName.c_str(),std::ios::in);
00057
00058 if(!m_file[i].good())
00059 {
00060
00061 LogDebug("RctTextToRctDigi")
00062 << "RctTextToRctDigi::RctTextToRctDigi : "
00063 << " couldn't open the file " << fileName << "...skipping!" << std::endl;
00064 }
00065 }
00066 }
00067
00068 RctTextToRctDigi::~RctTextToRctDigi()
00069 {
00070
00071 for (unsigned i=0; i<NUM_RCT_CRATES; i++){
00072 m_file[i].close();
00073 }
00074 }
00075
00077 void RctTextToRctDigi::putEmptyDigi(edm::Event& iEvent) {
00078 std::auto_ptr<L1CaloEmCollection> em (new L1CaloEmCollection);
00079 std::auto_ptr<L1CaloRegionCollection> rgn (new L1CaloRegionCollection);
00080 for (unsigned i=0; i<NUM_RCT_CRATES; i++){
00081 for (unsigned j=0; j<4; j++) {
00082 em->push_back(L1CaloEmCand(0, i, true));
00083 em->push_back(L1CaloEmCand(0, i, false));
00084 }
00085 for (unsigned j=0; j<14; j++)
00086 rgn->push_back(L1CaloRegion(0,false,false,false,false,i,j/2,j%2));
00087 for (unsigned j=0; j<8; j++)
00088 rgn->push_back(L1CaloRegion(0,true,i,j));
00089 }
00090 iEvent.put(em);
00091 iEvent.put(rgn);
00092 }
00093
00095 void RctTextToRctDigi::bxSynchro(int &bx,int crate) {
00096 std::string tmp;
00097
00098 while(bx<m_nevt+m_fileEventOffset) {
00099 for (int j=0; j<6; j++){
00100 getline(m_file[crate],tmp);
00101 }
00102 m_file[crate] >> tmp >> bx;
00103 if(tmp!="Crossing")
00104 throw cms::Exception("RctTextToRctDigiTextFileReadError")
00105 << "RctTextToRctDigi::bxSynchro : "
00106 << " something screwy happened Crossing!=" << tmp << std::endl;
00107 }
00108 }
00109
00110
00111 void RctTextToRctDigi::produce(edm::Event& iEvent, const edm::EventSetup& iSetup)
00112 {
00113
00114
00115 if (m_nevt < m_fileEventOffset){
00116
00117
00118
00119
00120 putEmptyDigi(iEvent);
00121 m_nevt++;
00122 return;
00123 }
00124
00125
00126 std::auto_ptr<L1CaloEmCollection> em (new L1CaloEmCollection);
00127 std::auto_ptr<L1CaloRegionCollection> rgn (new L1CaloRegionCollection);
00128
00129
00130 for (unsigned i=0; i<NUM_RCT_CRATES; i++){
00131
00132 if(!m_file[i].good()) {
00133 continue;
00134 }
00135
00136
00137 if(m_file[i].eof())
00138 {
00139
00140 LogDebug("RctTextToRctDigi")
00141 << "RctTextToRctDigi::produce : "
00142 << " unexpected end of file " << m_textFileName << i
00143 << " adding empty collection for event !"
00144 << std::endl;
00145 putEmptyDigi(iEvent);
00146 continue;
00147 }
00148
00149
00150 std::string tmp;
00151 m_file[i]>> tmp;
00152 if(tmp!="Crossing")
00153 {
00154 throw cms::Exception("RctTextToRctDigiTextFileReadError")
00155 << "RctTextToRctDigi::produce : "
00156 << " something screwy happened Crossing!=" << tmp << std::endl;
00157 }
00158
00159
00160 dec(m_file[i]);
00161 int BXNum;
00162 m_file[i]>>BXNum;
00163
00165 bxSynchro(BXNum,i);
00166
00167 if(BXNum!=m_nevt+m_fileEventOffset)
00168 throw cms::Exception("RctTextToRctDigiTextSyncError")
00169 << "RctTextToRctDigi::produce : "
00170 << " something screwy happened "
00171 << "evt:" << m_nevt << " != bx:" << BXNum << " + " << m_fileEventOffset
00172 << std::endl;
00173
00174
00175 unsigned long int uLongBuffer;
00176 bool mipBitBuffer[14],qBitBuffer[14];
00177
00178
00179 hex(m_file[i]);
00180
00181
00182 for (unsigned j=0; j<4; j++){
00183 m_file[i] >> uLongBuffer;
00184 em->push_back(L1CaloEmCand(uLongBuffer, i, true, j,BXNum,0));
00185 }
00186
00187
00188 for (unsigned j=0; j<4; j++){
00189 m_file[i] >> uLongBuffer;
00190 em->push_back(L1CaloEmCand(uLongBuffer, i, false, j,BXNum,0));
00191 }
00192
00193
00194 for (unsigned j=0; j<14; j++){
00195 m_file[i] >> mipBitBuffer[j];
00196 }
00197
00198
00199 for (unsigned j=0; j<14; j++){
00200 m_file[i] >> qBitBuffer[j];
00201 }
00202
00203
00204 for (unsigned j=0; j<14; j++){
00205 m_file[i] >> uLongBuffer;
00206
00207 unsigned et = uLongBuffer & 0x3ff;
00208 uLongBuffer >>= 10;
00209
00210 bool overFlow = ((uLongBuffer & 0x1) != 0);
00211 bool tauVeto = (((uLongBuffer & 0x2) >> 1) != 0);
00212
00213 rgn->push_back(L1CaloRegion(et,overFlow,tauVeto,mipBitBuffer[j],qBitBuffer[j],i,j/2,j%2));
00214 }
00215
00216
00217 for (unsigned j=0; j<8; j++){
00218 m_file[i] >> uLongBuffer;
00219
00220 unsigned et = uLongBuffer & 0xff;
00221
00222 rgn->push_back(L1CaloRegion(et,true,i,j));
00223 }
00224
00225 dec(m_file[i]);
00226 }
00227
00228 iEvent.put(em);
00229 iEvent.put(rgn);
00230
00231 m_nevt++;
00232 }
00233
00234
00235