CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_4_1_8_patch12/src/DQM/SiStripCommissioningSummary/src/ViewTranslator.cc

Go to the documentation of this file.
00001 #include "DQM/SiStripCommissioningSummary/interface/ViewTranslator.h"
00002 #include "DataFormats/SiStripCommon/interface/SiStripConstants.h"
00003 #include "DataFormats/SiStripCommon/interface/SiStripFecKey.h"
00004 #include "DataFormats/SiStripCommon/interface/SiStripFedKey.h"
00005 #include "DataFormats/SiStripCommon/interface/SiStripDetKey.h"
00006 #include "DataFormats/SiStripDetId/interface/SiStripDetId.h"
00007 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00008 #include <iostream>
00009 #include <sstream>
00010 #include <fstream>
00011 
00012 using namespace sistrip;
00013 
00014 // -----------------------------------------------------------------------------
00015 //
00016 void ViewTranslator::buildMaps( const SiStripFedCabling& cabling, 
00017                                 Mapping& det_to_fec, 
00018                                 Mapping& fed_to_fec ) {
00019   
00020 //   if ( !cabling ) {
00021 //     edm::LogWarning(mlCabling_) 
00022 //       << "[ViewTranslator::" << __func__ << "]"
00023 //       << " NULL pointer to FED cabling object!";
00024 //     return;
00025 //   }
00026   
00027   // Iterator through cabling, construct keys and push back into std::map
00028   std::vector<uint16_t>::const_iterator ifed = cabling.feds().begin();
00029   for ( ; ifed != cabling.feds().end(); ifed++ ) { 
00030 
00031     const std::vector<FedChannelConnection>& conns = cabling.connections( *ifed );
00032     std::vector<FedChannelConnection>::const_iterator ichan;
00033     for( ichan = conns.begin(); ichan != conns.end(); ichan++ ) {
00034       if( ichan->fedId() ) { 
00035         
00036         uint32_t fed = SiStripFedKey( *ifed, 
00037                                       SiStripFedKey::feUnit(ichan->fedCh()),
00038                                       SiStripFedKey::feChan(ichan->fedCh()) ).key();
00039         
00040         uint32_t fec = SiStripFecKey( ichan->fecCrate(),
00041                                       ichan->fecSlot(),
00042                                       ichan->fecRing(),
00043                                       ichan->ccuAddr(),
00044                                       ichan->ccuChan(),
00045                                       ichan->lldChannel() ).key();
00046         
00047         SiStripDetId det_id( ichan->detId(),
00048                              ichan->apvPairNumber() ); 
00049         uint32_t det = SiStripDetKey( det_id ).key();
00050         
00051         det_to_fec[det] = fec;
00052         fed_to_fec[fed] = fec;
00053         
00054       } 
00055     } 
00056   } 
00057   
00058   LogTrace(mlCabling_) 
00059     << "[ViewTranslator::" << __func__ << "]"
00060     << " Size of FedToFec std::map: " << fed_to_fec.size()
00061     << ", size of DetToFec std::map: " << det_to_fec.size(); 
00062   
00063 }
00064 
00065 
00066 // -----------------------------------------------------------------------------
00067 //
00068 uint32_t ViewTranslator::fedToFec( const uint32_t& fed_key_mask, 
00069                                    const Mapping& input,
00070                                    Mapping& output ) {
00071   
00072   if( input.empty() ) { 
00073     edm::LogWarning(mlCabling_) 
00074       << "[ViewTranslator::" << __func__ << "]"
00075       << " Input std::map is empty!";
00076     return 0; 
00077   }
00078   
00079 //   Mapping::iterator iter;
00080 //   SiStripFedKey fed_key( fed_key_mask );
00081   
00082 //   if( fed_key.detId() == sistrip::invalid_ ||
00083 //       fed_key.apvPair() == sistrip::invalid_ ) {
00084 //     edm::LogWarning(mlCabling_) 
00085 //       << "[ViewTranslator::" << __func__ << "]"
00086 //       << " DetKey is not defined!";
00087 //     output = input;
00088 //     return output.size(); 
00089 //   }
00090   
00091 //   if( fed_key.detId() != sistrip::invalid_ && 
00092 //       fed_key.apvPair() != sistrip::invalid_ ) {
00093 //     iter=input->find( fed_key_mask );
00094 //     output[ (*iter).first ] = (*iter).second;
00095 //     LogTrace(mlSummaryPlots_) << "both are not masked";
00096 //   }
00097   
00098 //   if( fed_key.detId()!=0xFFFFFFFF && fed_key.apvPair()==0xFFFF ) {
00099 //     LogTrace(mlSummaryPlots_) << "apv is masked";
00100 //     for(iter=input->begin() ; iter!=input->end() ; iter++) {
00101 //       DetKey = SiStripFedKey( (*iter).first );
00102 //       if(fed_key.detId()==DetKey.detId())
00103 //      output[ (*iter).first ]=( (*iter).second );
00104 //     } //for(iter=input->begin() ; iter!=input->end() ; iter++)
00105 //   }//if( fed_key.detId_!=0xFFFFFFFF && fed_key.apvPair_==0xFFFF )
00106 //   else LogTrace(mlSummaryPlots_) << "Cannot find the det to fec std::map in the root file. ";
00107 
00108   return 0;
00109   
00110 }
00111 
00112 // -----------------------------------------------------------------------------
00113 //
00114 uint32_t ViewTranslator::detToFec( const uint32_t& det_key_mask, 
00115                                    const Mapping& input,
00116                                    Mapping& output ) {
00117   
00118 //   if( input.empty() ) { 
00119 //     edm::LogWarning(mlCabling_) 
00120 //       << "[ViewTranslator::" << __func__ << "]"
00121 //       << " Input std::map is empty!";
00122 //     return 0 ;
00123 //   }
00124   
00125 //   Mapping::iterator iter;
00126 //   SiStripDetKey::Path det_key = SiStripDetKey::path( det_key_mask );
00127   
00128 //   if( det_key.detId_ == sistrip::invalid_ ||
00129 //       det_key.apvPair_ == sistrip::invalid_ ) {
00130 //     edm::LogWarning(mlCabling_) 
00131 //       << "[ViewTranslator::" << __func__ << "]"
00132 //       << " DetKey is not defined!";
00133 //     output = input;
00134 //     return output.size(); 
00135 //   }
00136   
00137 //   if( det_key.detId_ != sistrip::invalid_ && 
00138 //       det_key.apvPair_ != sistrip::invalid_ ) {
00139 //     iter=input->find( det_key_mask );
00140 //     output[ (*iter).first ] = (*iter).second;
00141 //     LogTrace(mlSummaryPlots_) << "both are not masked";
00142 //   }
00143   
00144 //   if( det_key.detId_!=0xFFFFFFFF && det_key.apvPair_==0xFFFF ) {
00145 //     LogTrace(mlSummaryPlots_) << "apv is masked";
00146 //     for(iter=input->begin() ; iter!=input->end() ; iter++) {
00147 //       DetKey = SiStripDetKey::path( (*iter).first );
00148 //       if(det_key.detId_==DetKey.detId_)
00149 //      output[ (*iter).first ]=( (*iter).second );
00150 //     } //for(iter=input->begin() ; iter!=input->end() ; iter++)
00151 //   }//if( det_key.detId_!=0xFFFFFFFF && det_key.apvPair_==0xFFFF )
00152 //   else LogTrace(mlSummaryPlots_) << "Cannot find the det to fec std::map in the root file. ";
00153 
00154   return 0; //@@ temp!
00155 
00156 }
00157 
00158 // -----------------------------------------------------------------------------
00159 //
00160 // void ViewTranslator::fedToFec( const uint32_t& fed_key_mask, 
00161 //                             const Mapping& input,
00162 //                             Mapping& output ) {
00163 
00164   
00165 //       Mapping::iterator iter;
00166 //       uint16_t fedId=0;   //fedId
00167 //       uint16_t feUnit=0;  //Front End Unit
00168 //       uint16_t feChan=0;   //Front End Channel
00169 //       uint16_t fedApv=0;
00170       
00171 //       //unpack the FED key to tranlsate into the corresponding FEC key(s)
00172 //       SiStripFedKey::Path FedKey = SiStripFedKey::path(fed_key_mask);
00173 //       fedId=FedKey.fedId_;
00174 //       feUnit=FedKey.feUnit_;
00175 //       feChan=FedKey.feChan_;
00176 //       fedApv=FedKey.fedApv_;
00177             
00178        
00179 //       if(fedId==0 && feUnit==0 && feChan==0 && fedApv == sistrip::invalid_ ) {
00180 //      output=*(input);
00181 //       }
00182       
00183 //       if(fedId!=0 && feUnit!=0 && feChan!=0 && fedApv == sistrip::invalid_) {
00184 //               iter=input->find(fed_key_mask);
00185 //       output[fed_key_mask]=(*iter).second;
00186 //        } 
00187        
00188        
00189 //        if(fedId!=0 && feUnit!=0 && feChan==0 && fedApv == sistrip::invalid_ ) {
00190 //       for(iter=input->begin(); iter!=input->end(); iter++) {
00191 //         FedKey = SiStripFedKey::path( (*iter).first );
00192 //         if(fedId==FedKey.fedId_ && feUnit==FedKey.feUnit_) {
00193 //           output[ (*iter).first ] = (*iter).second;
00194 //         }// if
00195 //       }// for 
00196 //        }// if 
00197        
00198 //        if(fedId!=0 && feUnit==0 && feChan==0) {
00199 //       for(iter=input->begin(); iter!=input->end(); iter++) {
00200 //         FedKey = SiStripFedKey::path( (*iter).first ); //FedKey is the key from the std::map
00201 //         if( fedId==FedKey.fedId_ ) {
00202 //           output[ (*iter).first ] = (*iter).second;
00203 //         } else LogTrace(mlSummaryPlots_) << "The fedId cannot be found. Please check readout path";
00204 //       } //for
00205 //        }//if 
00206        
00207       
00208       
00209 //     } else LogTrace(mlSummaryPlots_) << "The fed to fec std::map could not be found in the root file" << endl << "Please load the ViewTranslator module to create the requisite std::maps";
00210     
00211     
00212 //     f->Close();
00213         
00214 //   } //if(TFile::Open(fname.cstr())
00215 //   else LogTrace(mlSummaryPlots_) << "Error:Cannot open root file.";
00216 
00217 // }
00218 
00219 // -----------------------------------------------------------------------------
00220 //
00221 void ViewTranslator::writeMapsToFile( std::string fname, 
00222                                       Mapping& det, 
00223                                       Mapping& fed ) {
00224   
00225 //   Mapping *det_to_fec;
00226 //   Mapping *fed_to_fec;
00227   
00228 //   det_to_fec = &det;
00229 //   fed_to_fec = &fed;
00230   
00231 //   if(TFile::Open(fname.c_str())!=NULL) {
00232 //     TFile *f=TFile::Open(fname.c_str(), "UPDATE");
00233 //     gDirectory->cd();
00234 //     TDirectory *std::mapdir = gDirectory;
00235 //     gDirectory->cd("/DQMData/SiStrip");
00236 //     std::mapdir=gDirectory;
00237 //     std::mapdir->WriteObject(det_to_fec, "det_to_fec");
00238 //     std::mapdir->WriteObject(fed_to_fec, "fed_to_fec");
00239 //     LogTrace(mlSummaryPlots_) << "Wrote the std::maps";
00240 //     f->Close();
00241 //   } else LogTrace(mlSummaryPlots_) << "Cannot find root file. Maps not written.";
00242 
00243 }
00244