CMS 3D CMS Logo

/data/doxygen/doxygen-1.7.3/gen/CMSSW_4_2_8/src/L1Trigger/TextToDigi/plugins/SourceCardTextToRctDigi.cc

Go to the documentation of this file.
00001 // -*- C++ -*-
00002 //
00003 // Package:    SourceCardTextToRctDigi
00004 // Class:      SourceCardTextToRctDigi
00005 // 
00011 //
00012 // Original Author:  Alex Tapper
00013 //         Created:  Fri Mar  9 19:11:51 CET 2007
00014 // $Id: SourceCardTextToRctDigi.cc,v 1.8 2010/08/06 20:24:40 wmtan Exp $
00015 //
00016 //
00017 
00018 #include "SourceCardTextToRctDigi.h"
00019 #include "FWCore/ServiceRegistry/interface/Service.h" // Framework services
00020 #include "FWCore/MessageLogger/interface/MessageLogger.h" // Logger
00021 
00022 using namespace edm;
00023 using namespace std;
00024 
00025 // Set constants
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   // Produces collections
00035   produces<L1CaloEmCollection>();
00036   produces<L1CaloRegionCollection>();
00037 
00038   // Open the input file
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   // Make a SC routing object
00049   SourceCardRouting m_scRouting; 
00050 
00051 }
00052 
00053 SourceCardTextToRctDigi::~SourceCardTextToRctDigi()
00054 {
00055   // Close the input file
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 // ------------ method called to produce the data  ------------
00078 void SourceCardTextToRctDigi::produce(edm::Event& iEvent, const edm::EventSetup& iSetup)
00079 {
00080   // Skip event if required
00081   if (m_nevt < m_fileEventOffset){
00082     //    std::string tmp;
00083     // for (unsigned i=0;i<NUM_LINES_PER_EVENT;i++){
00084     //getline(m_file,tmp);
00085     //}
00086     putEmptyDigi(iEvent);
00087     m_nevt++;
00088     return;
00089   } else if (m_nevt==0 && m_fileEventOffset<0) {
00090     //skip first fileEventOffset input events
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   // New collections
00104   std::auto_ptr<L1CaloEmCollection> em (new L1CaloEmCollection);
00105   std::auto_ptr<L1CaloRegionCollection> rgn (new L1CaloRegionCollection);
00106 
00107   // General variables  
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   // Arrays to hold electron variables
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   // Arrays to hold region variables
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   // Check we're not at the end of the file
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   // Read in file one line at a time 
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     // Convert the string to useful info
00152     m_scRouting.STRINGtoVHDCI(logicalCardID,eventNumber,dataString,VHDCI);
00153     
00154     // Check crossing number
00155     if(line!=0) assert(eventNumber==thisEventNumber);
00156     thisEventNumber = eventNumber;
00157 
00158     // Are we looking at electrons or regions
00159     m_scRouting.LogicalCardIDtoRoutingMode(logicalCardID,routingMode,crate); 
00160     
00161     if (routingMode==0){     
00162 
00163       // Electrons
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       // Regions
00171       m_scRouting.VHDCItoRC56HF(RC[crate],RCof[crate],RCtau[crate],HF[crate],HFQ[crate],VHDCI);
00172 
00173     } else if (routingMode==2) {
00174 
00175       // Regions
00176       m_scRouting.VHDCItoRC012(RC[crate],RCof[crate],RCtau[crate],VHDCI);
00177 
00178     } else if (routingMode==3) {
00179 
00180       // Regions
00181       m_scRouting.VHDCItoRC234(RC[crate],RCof[crate],RCtau[crate],RC[crate+9],RCof[crate+9],RCtau[crate+9],VHDCI);
00182 
00183     } else {
00184       // Something went wrong
00185       throw cms::Exception("SourceCardtextToRctDigiError")
00186         << "SourceCardTextToRctDigi::produce : "
00187         << " unknown routing mode=" << routingMode << std::endl;
00188     }
00189   }
00190 
00191   // Make RCT digis
00192   for (crate=0; crate<NUM_RCT_CRATES; crate++){
00193 
00194     // Make EM collections
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     // Make region collections
00201     for (int i=0; i<7; i++){// Receiver card
00202       for (int j=0; j<2; j++){// Region
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     // Make HF region collections
00208     for (int i=0; i<4; i++){// Eta bin
00209       for (int j=0; j<2; j++){// HF0, HF1
00210         rgn->push_back(L1CaloRegion::makeHFRegion(HF[crate][i][j],HFQ[crate][i][j],crate,i+(4*j)));// region=eta+4*phi for eta 0-3 
00211       }
00212     }
00213   }
00214 
00215   // Debug info
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