CMS 3D CMS Logo

LinkDataXMLReader Class Reference

#include <IORawData/RPCFileReader/interface/LinkDataXMLReader.h>

Inheritance diagram for LinkDataXMLReader:

edm::ExternalInputSource edm::ConfigurableInputSource edm::InputSource edm::ProductRegistryHelper

List of all members.

Public Member Functions

 LinkDataXMLReader (const edm::ParameterSet &iConfig, edm::InputSourceDescription const &desc)
virtual bool produce (edm::Event &)
virtual void setRunAndEventInfo ()
virtual ~LinkDataXMLReader ()

Private Member Functions

void clear ()
void endElement (const XMLCh *const uri, const XMLCh *const localname, const XMLCh *const qname)
std::pair< int, intgetDCCInputChannelNum (int tcNumber, int tbNumber)
std::string IntToString (int i, int opt=0)
FEDRawDatarawData (int fedId, const std::vector< rpcrawtodigi::EventRecords > &result)
void startElement (const XMLCh *const uri, const XMLCh *const localname, const XMLCh *const qname, const Attributes &attrs)
int stringToInt (std::string str, int opt=0)

Private Attributes

XMLPScanToken aToken
bool endOfEvent_
bool endOfFile_
int event_
int eventCounter_
int eventPos_ [2]
int fileCounter_
bool isOpen_
std::string m_CurrElement
std::string m_xmlDir
bool noMoreData_
int opticalLinkNum
SAX2XMLReader * parser
std::map< int, std::vector
< rpcrawtodigi::EventRecords > > 
results
int run_
int triggerBoardNum
int triggerCrateNum

Static Private Attributes

static int m_instanceCount = 0


Detailed Description

Definition at line 40 of file LinkDataXMLReader.h.


Constructor & Destructor Documentation

LinkDataXMLReader::LinkDataXMLReader ( const edm::ParameterSet iConfig,
edm::InputSourceDescription const &  desc 
) [explicit]

Definition at line 93 of file LinkDataXMLReader.cc.

References clear(), endOfFile_, event_, eventCounter_, fileCounter_, FEDNumbering::getRPCFEDIds(), id, isOpen_, m_instanceCount, noMoreData_, results, run_, and xMLCh2String().

00094                                                                         :
00095   ExternalInputSource(iConfig, desc)
00096 {
00097 
00098 
00099  //register products
00100   produces<FEDRawDataCollection>();
00101   //if do put with a label
00102   //produces<FEDRawDataCollection>("someLabel");
00103 
00104   eventCounter_=0; fileCounter_ = 0;
00105   run_ = 0; 
00106   event_ = 0;
00107   isOpen_ = false; noMoreData_ = false; 
00108   endOfFile_ = false;
00109 
00110   pair<int,int> rpcFEDS=FEDNumbering::getRPCFEDIds();
00111   for (int id= rpcFEDS.first; id<=rpcFEDS.second; ++id){
00112     results[id] = std::vector<rpcrawtodigi::EventRecords>();
00113   }
00114 
00115   clear();
00116 
00117   if(m_instanceCount == 0) { 
00118     try {
00119       XMLPlatformUtils::Initialize();
00120       m_instanceCount++;
00121     }
00122     catch(const XMLException &toCatch)  {
00123       edm::LogError("LinkDataXMLReader")<< "Error during Xerces-c Initialization: " 
00124         + xMLCh2String(toCatch.getMessage());
00125     }
00126   }  
00127 }

LinkDataXMLReader::~LinkDataXMLReader (  )  [virtual]

Definition at line 132 of file LinkDataXMLReader.cc.

00132 {}


Member Function Documentation

void LinkDataXMLReader::clear ( void   )  [private]

Definition at line 407 of file LinkDataXMLReader.cc.

References FEDNumbering::getRPCFEDIds(), id, opticalLinkNum, results, triggerBoardNum, and triggerCrateNum.

Referenced by LinkDataXMLReader(), and setRunAndEventInfo().

00407                               { 
00408 
00409  triggerCrateNum = -1;
00410  triggerBoardNum = -1;
00411  opticalLinkNum  = -1;
00412 
00413  pair<int,int> rpcFEDS=FEDNumbering::getRPCFEDIds();
00414   for (int id= rpcFEDS.first; id<=rpcFEDS.second; ++id){
00415     results[id].clear();
00416   }
00417 }

void LinkDataXMLReader::endElement ( const XMLCh *const   uri,
const XMLCh *const   localname,
const XMLCh *const   qname 
) [private]

Definition at line 306 of file LinkDataXMLReader.cc.

References endOfEvent_, endOfFile_, m_CurrElement, and xMLCh2String().

00306                                                                                                                   {
00307  
00308   string m_CurrElement = xMLCh2String(localname);
00309 //Corr MG 07/01/2008
00310 //  following line has to be changed
00311 //  if(m_CurrElement=="bxData") endOfEvent_ = true; 
00312   if(m_CurrElement=="event") endOfEvent_ = true; 
00313   if(m_CurrElement=="rpctDataStream") endOfFile_ = true; 
00314 }

std::pair< int, int > LinkDataXMLReader::getDCCInputChannelNum ( int  tcNumber,
int  tbNumber 
) [private]

Definition at line 420 of file LinkDataXMLReader.cc.

Referenced by startElement().

00420                                                                                     {
00421 
00422   //int fedNumber = 790 + tcNumber/4;
00423 
00424   int fedNumber = 792 - tcNumber/4;
00425   int dccInputChannelNum = tbNumber + 9*(tcNumber%4);
00426 
00427   return std::pair<int,int>(fedNumber,dccInputChannelNum);
00428 }

std::string LinkDataXMLReader::IntToString ( int  i,
int  opt = 0 
) [private]

Definition at line 381 of file LinkDataXMLReader.cc.

References ss.

00381                                                       {
00382 
00383  std::stringstream ss;
00384  if(opt==1) ss << std::hex << i << std::dec;
00385  else ss << i ;
00386 
00387  return ss.str();
00388 
00389 }

bool LinkDataXMLReader::produce ( edm::Event ev  )  [virtual]

Implements edm::ConfigurableInputSource.

Definition at line 188 of file LinkDataXMLReader.cc.

References FEDNumbering::getRPCFEDIds(), noMoreData_, edm::Event::put(), rawData(), and results.

00188                                            {
00189 
00190   if(noMoreData_) return false;
00191 
00192   auto_ptr<FEDRawDataCollection> buffers( new FEDRawDataCollection );
00193 
00194   pair<int,int> rpcFEDS=FEDNumbering::getRPCFEDIds();
00195   //pair<int,int> rpcFEDS(790,790);
00196   for (int id= rpcFEDS.first; id<=rpcFEDS.second; ++id){
00197 
00198     FEDRawData *  rawData1 =  rawData(id, results[id]);
00199     FEDRawData& fedRawData = buffers->FEDData(id);
00200 
00201     fedRawData = *rawData1;
00202   }
00203   ev.put( buffers );  
00204 
00205   
00206   return true;
00207 }

FEDRawData* LinkDataXMLReader::rawData ( int  fedId,
const std::vector< rpcrawtodigi::EventRecords > &  result 
) [private]

Referenced by produce(), and startElement().

void LinkDataXMLReader::setRunAndEventInfo (  )  [virtual]

Reimplemented from edm::ConfigurableInputSource.

Definition at line 139 of file LinkDataXMLReader.cc.

References aToken, clear(), endOfEvent_, endOfFile_, event_, eventCounter_, eventPos_, fileCounter_, edm::ExternalInputSource::fileNames(), isOpen_, noMoreData_, parser, run_, edm::ConfigurableInputSource::setEventNumber(), edm::InputSource::setRunNumber(), and size.

00139                                            {
00140 
00141   bool triggeredOrEmpty = false;
00142   clear();
00143 
00144   if(endOfFile_){
00145     isOpen_ = false;
00146     if(parser) {
00147       delete parser;
00148       parser = 0;
00149     }
00150   }
00151 
00152   if(!isOpen_){
00153     if(fileCounter_<(int)fileNames().size()){
00154       eventPos_[0]=0; eventPos_[1]=0;
00155       isOpen_=true;
00156       endOfFile_ = false;
00157       fileCounter_++;
00158       ++run_;
00159       event_ = 0;
00160       edm::LogInfo("LinkDataXMLReader")<< "[LinkDataXMLReader::setRunAndEventInfo] "
00161                            << "Open for reading file no. " << fileCounter_
00162                            << " " << fileNames()[fileCounter_-1].substr(5); 
00163       parser = XMLReaderFactory::createXMLReader();
00164       parser->setContentHandler(this);  
00165       parser->parseFirst(fileNames()[fileCounter_-1].substr(5).c_str(),aToken);
00166     }
00167     else{
00168       edm::LogInfo("LinkDataXMLReader")<< "[LinkDataXMLReader::setRunAndEventInfo] "
00169                            << "No more events to read. Finishing after " 
00170                            << eventCounter_ << " events.";
00171       noMoreData_=true;
00172       return;
00173     }
00174   }
00175 
00176   endOfEvent_ = false;
00177   while(parser->parseNext(aToken) &&  !endOfEvent_){}
00178 
00179     ++event_;
00180     ++eventCounter_;
00181 
00182   setRunNumber(run_);
00183   setEventNumber(event_);
00184   //setTime(mktime(&aTime));  
00185   return;
00186 }

void LinkDataXMLReader::startElement ( const XMLCh *const   uri,
const XMLCh *const   localname,
const XMLCh *const   qname,
const Attributes &  attrs 
) [private]

Definition at line 212 of file LinkDataXMLReader.cc.

References Char2XMLCh, getDCCInputChannelNum(), local_bx, m_CurrElement, opticalLinkNum, rawData(), results, stringToInt(), triggerBoardNum, triggerCrateNum, and xMLCh2String().

00215                                                               {
00216   m_CurrElement = xMLCh2String(localname);
00217 //  std::cout<<"Start element: "<<m_CurrElement<<endl;
00218  
00219   int lbNum, partitionNum,  endOfData,  halfPartition,  partitionData;
00220   uint16_t rawData;
00221 //Corr MG 07/01/2008
00222   if(m_CurrElement=="bxData") {
00223     local_bx = stringToInt(xMLCh2String(attrs.getValue(Char2XMLCh("num"))),1);
00224 //edm::LogInfo(" ")<<" local_bx "<<local_bx;
00225   }
00226   if(m_CurrElement=="tc") triggerCrateNum = stringToInt(xMLCh2String(attrs.getValue(Char2XMLCh("num"))),1);
00227   if(m_CurrElement=="tb") triggerBoardNum = stringToInt(xMLCh2String(attrs.getValue(Char2XMLCh("num"))),1);
00228   if(m_CurrElement=="ol") opticalLinkNum = stringToInt(xMLCh2String(attrs.getValue(Char2XMLCh("num"))),1);  
00229   if(m_CurrElement=="lmd"){
00230         if(triggerCrateNum==-1 || triggerBoardNum==-1 || opticalLinkNum==-1){
00231         //std::cout<<"TC, TB or OL number not read!."<<std::endl;
00232         return;
00233         }
00234     //rawData = stringToInt(xMLCh2String(attrs.getValue(Char2XMLCh("raw"))),0);
00235     lbNum = stringToInt(xMLCh2String(attrs.getValue(Char2XMLCh("lb"))),1);
00236     partitionNum = stringToInt(xMLCh2String(attrs.getValue(Char2XMLCh("par"))),1);
00237     endOfData = stringToInt(xMLCh2String(attrs.getValue(Char2XMLCh("eod"))),1);
00238     halfPartition = 0;
00239     partitionData = stringToInt(xMLCh2String(attrs.getValue(Char2XMLCh("dat"))),0);
00240 
00241     // BX 
00242     int trigger_BX =  200;
00243 //Corr MG 07/01/2008
00244     int current_BX =  trigger_BX + local_bx;
00245 //    edm::LogInfo(" ")<<" local_bx "<<local_bx<<" current_BX "<<current_BX;
00246 //    std::cout<<" local_bx "<<local_bx<<" current_BX "<<current_BX<<endl;
00247     RecordBX bxr(current_BX);
00248 
00249     // TB 
00250     int tbLinkInputNumber = opticalLinkNum;    
00251     int rmb = getDCCInputChannelNum(triggerCrateNum, triggerBoardNum).second;
00252 edm::LogInfo(" ")
00253         <<"tc: "<<triggerCrateNum
00254         <<" tb: "<<triggerBoardNum
00255         <<" rmb: "<<rmb
00256         <<" fedID: "<<getDCCInputChannelNum(triggerCrateNum, triggerBoardNum).first
00257         <<" ol: "<< opticalLinkNum
00258         <<" partNum: "<<partitionNum
00259         <<" eod: "<<endOfData
00260         <<" hp: "<<halfPartition
00261         <<" raw data: "<<hex<<partitionData<<dec;
00262 
00263     RecordSLD tbr( tbLinkInputNumber, rmb);   
00264 
00265     // LB record
00266   uint16_t theData = 0;
00267   static const int PARTITION_DATA_MASK  = 0XFF;
00268   static const int PARTITION_DATA_SHIFT =0;
00269 
00270   static const int PARTITION_NUMBER_MASK = 0XF;
00271   static const int PARTITION_NUMBER_SHIFT =10;
00272 
00273   static const int HALFP_MASK = 0X1;
00274   static const int HALFP_SHIFT =8;
00275 
00276   static const int EOD_MASK = 0X1;
00277   static const int EOD_SHIFT =9;
00278 
00279   static const int LB_MASK = 0X3;
00280   static const int LB_SHIFT =14;
00281 
00282   static const int BITS_PER_PARTITION=8; 
00283   
00284   theData |= (endOfData<<EOD_SHIFT );
00285   theData |= (halfPartition<<HALFP_SHIFT);
00286   theData |= (partitionNum<<PARTITION_NUMBER_SHIFT);
00287   theData |= (lbNum<<LB_SHIFT);
00288   theData |= (partitionData<<PARTITION_DATA_SHIFT);
00289 
00290    RecordCD  lbr(theData);
00291 /*
00292     cout<<"lbr.Data.lbNumber: "<<lbr.lbData().lbNumber()<<endl;
00293     cout<<"lbr.Data.lbData: "<<hex<<lbr.lbData().lbData()<<dec<<endl;
00294     cout<<"lbr.Data.partNumber: "<<lbr.lbData().partitionNumber()<<endl;
00295  */
00296     int fedId = getDCCInputChannelNum(triggerCrateNum, triggerBoardNum).first;
00297     
00298     results[fedId].push_back(  EventRecords(trigger_BX, bxr, tbr, lbr) );
00299   }
00300 
00301 }

int LinkDataXMLReader::stringToInt ( std::string  str,
int  opt = 0 
) [private]

Definition at line 391 of file LinkDataXMLReader.cc.

References i.

Referenced by startElement().

00391                                                           {
00392 
00393   int number;
00394   std::stringstream lineStream(str);
00395   if(opt==0) lineStream>>hex>>number;
00396   if(opt==1) lineStream>>dec>>number;
00397   return number;
00398 
00399   for(unsigned int i = 0; i < str.size(); i++)
00400     if(str[i] < '0' || str[i] > '9')
00401        edm::LogError("LinkDataXMLReader")<< "Error in stringToInt(): the string: "
00402                                          <<str<<" cannot be converted to a number";
00403   return atoi(str.c_str());
00404 }


Member Data Documentation

XMLPScanToken LinkDataXMLReader::aToken [private]

Definition at line 82 of file LinkDataXMLReader.h.

Referenced by setRunAndEventInfo().

bool LinkDataXMLReader::endOfEvent_ [private]

Definition at line 71 of file LinkDataXMLReader.h.

Referenced by endElement(), and setRunAndEventInfo().

bool LinkDataXMLReader::endOfFile_ [private]

Definition at line 72 of file LinkDataXMLReader.h.

Referenced by endElement(), LinkDataXMLReader(), and setRunAndEventInfo().

int LinkDataXMLReader::event_ [private]

Definition at line 75 of file LinkDataXMLReader.h.

Referenced by LinkDataXMLReader(), and setRunAndEventInfo().

int LinkDataXMLReader::eventCounter_ [private]

Definition at line 74 of file LinkDataXMLReader.h.

Referenced by LinkDataXMLReader(), and setRunAndEventInfo().

int LinkDataXMLReader::eventPos_[2] [private]

Definition at line 73 of file LinkDataXMLReader.h.

Referenced by setRunAndEventInfo().

int LinkDataXMLReader::fileCounter_ [private]

Definition at line 74 of file LinkDataXMLReader.h.

Referenced by LinkDataXMLReader(), and setRunAndEventInfo().

bool LinkDataXMLReader::isOpen_ [private]

Definition at line 71 of file LinkDataXMLReader.h.

Referenced by LinkDataXMLReader(), and setRunAndEventInfo().

std::string LinkDataXMLReader::m_CurrElement [private]

Definition at line 77 of file LinkDataXMLReader.h.

Referenced by endElement(), and startElement().

int LinkDataXMLReader::m_instanceCount = 0 [static, private]

Definition at line 78 of file LinkDataXMLReader.h.

Referenced by LinkDataXMLReader().

std::string LinkDataXMLReader::m_xmlDir [private]

Definition at line 76 of file LinkDataXMLReader.h.

bool LinkDataXMLReader::noMoreData_ [private]

Definition at line 71 of file LinkDataXMLReader.h.

Referenced by LinkDataXMLReader(), produce(), and setRunAndEventInfo().

int LinkDataXMLReader::opticalLinkNum [private]

Definition at line 68 of file LinkDataXMLReader.h.

Referenced by clear(), and startElement().

SAX2XMLReader* LinkDataXMLReader::parser [private]

Definition at line 83 of file LinkDataXMLReader.h.

Referenced by setRunAndEventInfo().

std::map<int, std::vector<rpcrawtodigi::EventRecords> > LinkDataXMLReader::results [private]

Definition at line 80 of file LinkDataXMLReader.h.

Referenced by clear(), LinkDataXMLReader(), produce(), and startElement().

int LinkDataXMLReader::run_ [private]

Definition at line 75 of file LinkDataXMLReader.h.

Referenced by LinkDataXMLReader(), and setRunAndEventInfo().

int LinkDataXMLReader::triggerBoardNum [private]

Definition at line 70 of file LinkDataXMLReader.h.

Referenced by clear(), and startElement().

int LinkDataXMLReader::triggerCrateNum [private]

Definition at line 69 of file LinkDataXMLReader.h.

Referenced by clear(), and startElement().


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