00001
00002
00003
00004
00005
00011
00012
00013
00014
00015
00016
00017
00018 #include "SourceCardTextToRctDigi.h"
00019 #include "FWCore/ServiceRegistry/interface/Service.h"
00020 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00021
00022 using namespace edm;
00023 using namespace std;
00024
00025
00026 const static unsigned NUM_LINES_PER_EVENT = 63;
00027 const static int NUM_RCT_CRATES = 18;
00028
00029 SourceCardTextToRctDigi::SourceCardTextToRctDigi(const edm::ParameterSet& iConfig):
00030 m_textFileName(iConfig.getParameter<std::string>("TextFileName")),
00031 m_fileEventOffset(iConfig.getParameter<int>("fileEventOffset")),
00032 m_nevt(0)
00033 {
00034
00035 produces<L1CaloEmCollection>();
00036 produces<L1CaloRegionCollection>();
00037
00038
00039 m_file.open(m_textFileName.c_str(),std::ios::in);
00040
00041 if(!m_file.good())
00042 {
00043 throw cms::Exception("SourceCardTextToRctDigiTextFileOpenError")
00044 << "SourceCardTextToRctDigi::SourceCardTextToRctDigi : "
00045 << " couldn't open the file " << m_textFileName << " for reading" << std::endl;
00046 }
00047
00048
00049 SourceCardRouting m_scRouting;
00050
00051 }
00052
00053 SourceCardTextToRctDigi::~SourceCardTextToRctDigi()
00054 {
00055
00056 m_file.close();
00057 }
00058
00060 void SourceCardTextToRctDigi::putEmptyDigi(edm::Event& iEvent) {
00061 std::auto_ptr<L1CaloEmCollection> em (new L1CaloEmCollection);
00062 std::auto_ptr<L1CaloRegionCollection> rgn (new L1CaloRegionCollection);
00063 for (int i=0; i<NUM_RCT_CRATES; i++){
00064 for (int j=0; j<4; j++) {
00065 em->push_back(L1CaloEmCand(0, i, true));
00066 em->push_back(L1CaloEmCand(0, i, false));
00067 }
00068 for (int j=0; j<14; j++)
00069 rgn->push_back(L1CaloRegion(0,false,false,false,false,i,j/2,j%2));
00070 for (unsigned j=0; j<8; j++)
00071 rgn->push_back(L1CaloRegion(0,true,i,j));
00072 }
00073 iEvent.put(em);
00074 iEvent.put(rgn);
00075 }
00076
00077
00078 void SourceCardTextToRctDigi::produce(edm::Event& iEvent, const edm::EventSetup& iSetup)
00079 {
00080
00081 if (m_nevt < m_fileEventOffset){
00082
00083
00084
00085
00086 putEmptyDigi(iEvent);
00087 m_nevt++;
00088 return;
00089 } else if (m_nevt==0 && m_fileEventOffset<0) {
00090
00091 std::string tmp;
00092 for(int i=0;i<abs(m_fileEventOffset); i++)
00093 for (unsigned line=0; line<NUM_LINES_PER_EVENT; line++)
00094 if(!getline(m_file,tmp))
00095 {
00096 throw cms::Exception("SourceCardTextToRctDigiTextFileReadError")
00097 << "SourceCardTextToRctDigi::produce() : "
00098 << " couldn't read from the file " << m_textFileName << std::endl;
00099 }
00100 }
00101
00102
00103
00104 std::auto_ptr<L1CaloEmCollection> em (new L1CaloEmCollection);
00105 std::auto_ptr<L1CaloRegionCollection> rgn (new L1CaloRegionCollection);
00106
00107
00108 unsigned long VHDCI[2][2];
00109 int routingMode;
00110 int crate;
00111 std::string dataString;
00112 unsigned short eventNumber;
00113 unsigned short logicalCardID;
00114
00115
00116 unsigned short eIsoRank[18][4];
00117 unsigned short eIsoCardId[18][4];
00118 unsigned short eIsoRegionId[18][4];
00119 unsigned short eNonIsoRank[18][4];
00120 unsigned short eNonIsoCardId[18][4];
00121 unsigned short eNonIsoRegionId[18][4];
00122
00123
00124 unsigned short RC[18][7][2];
00125 unsigned short RCof[18][7][2];
00126 unsigned short RCtau[18][7][2];
00127 unsigned short MIPbits[18][7][2];
00128 unsigned short Qbits[18][7][2];
00129 unsigned short HF[18][4][2];
00130 unsigned short HFQ[18][4][2];
00131
00132
00133 if(m_file.eof())
00134 {
00135 throw cms::Exception("SourceCardTextToRctDigiTextFileReadError")
00136 << "SourceCardTextToRctDigi::produce : "
00137 << " unexpected end of file " << m_textFileName << std::endl;
00138 }
00139
00140 int thisEventNumber=-1;
00141
00142 for (unsigned line=0; line<NUM_LINES_PER_EVENT; line++){
00143
00144 if(!getline(m_file,dataString))
00145 {
00146 throw cms::Exception("SourceCardTextToRctDigiTextFileReadError")
00147 << "SourceCardTextToRctDigi::SourceCardTextToRctDigi : "
00148 << " couldn't read from the file " << m_textFileName << std::endl;
00149 }
00150
00151
00152 m_scRouting.STRINGtoVHDCI(logicalCardID,eventNumber,dataString,VHDCI);
00153
00154
00155 if(line!=0) assert(eventNumber==thisEventNumber);
00156 thisEventNumber = eventNumber;
00157
00158
00159 m_scRouting.LogicalCardIDtoRoutingMode(logicalCardID,routingMode,crate);
00160
00161 if (routingMode==0){
00162
00163
00164 m_scRouting.VHDCItoEMU(eIsoRank[crate],eIsoCardId[crate],eIsoRegionId[crate],
00165 eNonIsoRank[crate],eNonIsoCardId[crate],eNonIsoRegionId[crate],
00166 MIPbits[crate],Qbits[crate],VHDCI);
00167
00168 } else if (routingMode==1) {
00169
00170
00171 m_scRouting.VHDCItoRC56HF(RC[crate],RCof[crate],RCtau[crate],HF[crate],HFQ[crate],VHDCI);
00172
00173 } else if (routingMode==2) {
00174
00175
00176 m_scRouting.VHDCItoRC012(RC[crate],RCof[crate],RCtau[crate],VHDCI);
00177
00178 } else if (routingMode==3) {
00179
00180
00181 m_scRouting.VHDCItoRC234(RC[crate],RCof[crate],RCtau[crate],RC[crate+9],RCof[crate+9],RCtau[crate+9],VHDCI);
00182
00183 } else {
00184
00185 throw cms::Exception("SourceCardtextToRctDigiError")
00186 << "SourceCardTextToRctDigi::produce : "
00187 << " unknown routing mode=" << routingMode << std::endl;
00188 }
00189 }
00190
00191
00192 for (crate=0; crate<NUM_RCT_CRATES; crate++){
00193
00194
00195 for (int i=0; i<4; i++){
00196 em->push_back(L1CaloEmCand(eIsoRank[crate][i],eIsoRegionId[crate][i],eIsoCardId[crate][i],crate,true,i,0));
00197 em->push_back(L1CaloEmCand(eNonIsoRank[crate][i],eNonIsoRegionId[crate][i],eNonIsoCardId[crate][i],crate,false,i,0));
00198 }
00199
00200
00201 for (int i=0; i<7; i++){
00202 for (int j=0; j<2; j++){
00203 rgn->push_back(L1CaloRegion::makeHBHERegion(RC[crate][i][j],RCof[crate][i][j],RCtau[crate][i][j],MIPbits[crate][i][j],Qbits[crate][i][j],crate,i,j));
00204 }
00205 }
00206
00207
00208 for (int i=0; i<4; i++){
00209 for (int j=0; j<2; j++){
00210 rgn->push_back(L1CaloRegion::makeHFRegion(HF[crate][i][j],HFQ[crate][i][j],crate,i+(4*j)));
00211 }
00212 }
00213 }
00214
00215
00216 for (L1CaloEmCollection::const_iterator iem=em->begin(); iem!=em->end(); iem++){
00217 LogDebug("Electrons") << (*iem);
00218 }
00219
00220 for (L1CaloRegionCollection::const_iterator irgn=rgn->begin(); irgn!=rgn->end(); irgn++){
00221 LogDebug("HFRegions") << (*irgn);
00222 }
00223
00224 iEvent.put(em);
00225 iEvent.put(rgn);
00226
00227 m_nevt++;
00228 }
00229