CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_3_0/src/CaloOnlineTools/HcalOnlineDb/src/LMap.cc

Go to the documentation of this file.
00001 // -*- C++ -*-
00002 //
00003 // Package:     XMLTools
00004 // Class  :     LMap
00005 // 
00006 // Implementation:
00007 //     <Notes on implementation>
00008 //
00009 // Original Author:  Gena Kukartsev, kukarzev@fnal.gov
00010 //         Created:  Tue Oct 23 14:30:20 CDT 2007
00011 // $Id: LMap.cc,v 1.16 2010/08/06 20:24:13 wmtan Exp $
00012 //
00013 
00014 // system include files
00015 #include <stdio.h>
00016 #include <iostream>
00017 #include <fstream>
00018 #include <sstream>
00019 #include <vector>
00020 
00021 
00022 // user include files
00023 #include "CaloOnlineTools/HcalOnlineDb/interface/LMap.h"
00024 #include "CaloOnlineTools/HcalOnlineDb/interface/RooGKCounter.h"
00025 #include "DataFormats/HcalDetId/interface/HcalGenericDetId.h"
00026 #include "DataFormats/HcalDetId/interface/HcalDetId.h"
00027 #include "CaloOnlineTools/HcalOnlineDb/interface/HcalAssistant.h"
00028 
00029 using namespace std;
00030 
00031 
00032 
00033 class LMap::impl {
00034 public:
00035   impl(){ }
00036   ~impl(){ }
00037 
00038   int read( std::string accessor, std::string type );
00039   std::map<int,LMapRow> & get_map( void ){ return _lmap; };
00040   
00041 private:
00042   std::vector<LMapRow> _table;
00043   std::map<int,LMapRow> _lmap;
00044 
00045 };
00046 
00047 
00048 
00049 LMap::LMap() : p_impl( new impl ) { }
00050 
00051 LMap::~LMap() { }
00052 
00053 
00054 
00055 int LMap::read( std::string accessor, std::string type )
00056 {
00057   return p_impl -> read( accessor, type );
00058 }
00059 
00060 std::map<int,LMapRow> & LMap::get_map( void )
00061 {
00062   return p_impl -> get_map();
00063 }
00064 
00065 int LMap::impl::read( std::string map_file, std::string type )
00066 {
00067 
00068   RooGKCounter lines;
00069 
00070   std::string _row;
00071   ifstream inFile( map_file . c_str(), std::ios::in );
00072   if (!inFile)
00073     {
00074       std::cout << "Unable to open file with the logical map: " << map_file << std::endl;
00075     }
00076   else
00077     {
00078       std::cout << "File with the logical map opened successfully: " << map_file << std::endl;
00079       std::cout << "Type: " << type << std::endl;
00080     }
00081   while ( getline( inFile, _row ) > 0 )
00082     {
00083       LMapRow aRow;
00084       char det[32];
00085       char rbx[32];
00086       char fpga[32];
00087       char slbin[32];
00088       char slbin2[32];
00089       char slnam[32];
00090       char rctnam[32];
00091 
00092       const char * let_code = "Z";
00093 
00094       int _read = 0;
00095       if ( type == "HBEF" )
00096         {
00097           const char * _format = " %d %d %d %d %d %s %s %d %d %d %d %d %d %d %d %d %s %d %d %d %d %d %s %s %s %d %d %d %s %d";
00098           _read = sscanf( _row . c_str(), _format,
00099                           &(aRow.side),
00100                           &(aRow.eta), &(aRow.phi), &(aRow.dphi), &(aRow.depth),
00101                           det,
00102                           rbx,
00103                           &(aRow.wedge), &(aRow.rm), &(aRow.pixel), &(aRow.qie), &(aRow.adc), &(aRow.rm_fi), &(aRow.fi_ch),
00104                           &(aRow.crate), &(aRow.htr),
00105                           fpga,
00106                           &(aRow.htr_fi),
00107                           &(aRow.dcc_sl), &(aRow.spigo), &(aRow.dcc), &(aRow.slb),
00108                           slbin, slbin2, slnam,
00109                           &(aRow.rctcra), &(aRow.rctcar), &(aRow.rctcon),
00110                           rctnam,
00111                           &(aRow.fedid) );
00112         }
00113       else if ( type == "HO" )
00114         {
00115           const char * _format = " %d %d %d %d %d %s %s %d %d %d %d %d %d %d %s %d %d %s %d %d %d %d %d";
00116           _read = sscanf( _row . c_str(), _format,
00117                           &(aRow.side),
00118                           &(aRow.eta), &(aRow.phi), &(aRow.dphi), &(aRow.depth),
00119                           det,
00120                           rbx,
00121                           &(aRow.wedge), &(aRow.rm), &(aRow.pixel), &(aRow.qie), &(aRow.adc), &(aRow.rm_fi), &(aRow.fi_ch),
00122                           &let_code,
00123                           &(aRow.crate), &(aRow.htr),
00124                           fpga,
00125                           &(aRow.htr_fi),
00126                           &(aRow.dcc_sl), &(aRow.spigo), &(aRow.dcc), &(aRow.slb) );
00127           //slbin, slbin2, slnam,
00128           //&(aRow.rctcra), &(aRow.rctcar), &(aRow.rctcon),
00129           //rctnam,
00130           //&(aRow.fedid) );
00131         }
00132       if ( _read >= 23 )
00133         {
00134           lines . count();
00135           
00136           std::string _det(det);
00137           if      ( _det.find("HB") != std::string::npos ) aRow . det = HcalBarrel;
00138           else if ( _det.find("HE") != std::string::npos ) aRow . det = HcalEndcap;
00139           else if ( _det.find("HF") != std::string::npos ) aRow . det = HcalForward;
00140           else if ( _det.find("HO") != std::string::npos ) aRow . det = HcalOuter;
00141           else                    aRow . det = HcalOther;
00142 
00143           aRow . rbx .append( rbx );
00144           aRow . fpga .append( fpga );
00145           aRow . slbin .append( slbin );
00146           aRow . slbin2 .append( slbin2 );
00147           aRow . slnam .append( slnam );
00148           aRow . rctnam .append( rctnam );
00149           aRow . let_code .append( let_code );
00150           
00151           _table . push_back( aRow );
00152 
00153           HcalDetId _hdid(aRow.det, aRow.side*aRow.eta, aRow.phi, aRow.depth);
00154 
00155           _lmap[_hdid.rawId()] = aRow;
00156 
00157         }
00158     }
00159   inFile.close();
00160   std::cout << "LMap: " << lines . getCount() << " lines read" << std::endl;
00161 
00162   return 0;
00163 }
00164 
00165 //_______________________________________________________________________
00166 //
00167 //_____ EMAP stuff
00168 //
00169 //_______________________________________________________________________
00170 
00171 EMap::EMap( const HcalElectronicsMap * emap ){
00172   if (emap){
00173     HcalAssistant _ass;
00174     //
00175     //_____ precision channels __________________________________________
00176     //
00177     std::vector <HcalElectronicsId> v_eId = emap->allElectronicsIdPrecision();
00178     for (std::vector <HcalElectronicsId>::const_iterator eId=v_eId.begin();
00179          eId!=v_eId.end();
00180          eId++){
00181       EMapRow row;
00182       //row.rawId     = eId->rawId();
00183       row.crate     = eId->readoutVMECrateId();
00184       row.slot      = eId->htrSlot();
00185       row.dcc       = eId->dccid();
00186       row.spigot    = eId->spigot();
00187       row.fiber     = eId->fiberIndex();
00188       row.fiberchan = eId->fiberChanId();
00189       if (eId->htrTopBottom()==1) row.topbottom = "t";
00190       else row.topbottom = "b";
00191       //
00192       HcalGenericDetId _gid( emap->lookup(*eId) );
00193       if ( !(_gid.null()) &&
00194            (_gid.genericSubdet()==HcalGenericDetId::HcalGenBarrel ||
00195             _gid.genericSubdet()==HcalGenericDetId::HcalGenEndcap ||
00196             _gid.genericSubdet()==HcalGenericDetId::HcalGenForward ||
00197             _gid.genericSubdet()==HcalGenericDetId::HcalGenOuter
00198             )
00199            ){
00200         HcalDetId _id( emap->lookup(*eId) );
00201         row.rawId     = _id.rawId();
00202         row.ieta      = _id.ieta();
00203         row.iphi      = _id.iphi();
00204         row.idepth    = _id.depth();
00205         row.subdet    = _ass.getSubdetectorString(_id.subdet());
00206         // fill the map
00207         map.push_back(row);
00208       }
00209       // ZDC channels
00210       else if ( !(_gid.null()) &&
00211            _gid.genericSubdet()==HcalGenericDetId::HcalGenZDC
00212            ){
00213         HcalZDCDetId _id( emap->lookup(*eId) );
00214         row.zdc_channel      = _id.channel();
00215         row.zdc_section      = _ass.getZDCSectionString(_id.section());
00216         row.idepth           = _id.depth();
00217         row.zdc_zside        = _id.zside();
00218         // fill the map
00219         map.push_back(row);
00220       }
00221     }
00222     //
00223     //_____ trigger channels __________________________________________
00224     //
00225     v_eId = emap->allElectronicsIdTrigger();
00226     for (std::vector <HcalElectronicsId>::const_iterator eId=v_eId.begin();
00227          eId!=v_eId.end();
00228          eId++){
00229       EMapRow row;
00230       //row.rawId     = eId->rawId();
00231       row.crate     = eId->readoutVMECrateId();
00232       row.slot      = eId->htrSlot();
00233       row.dcc       = eId->dccid();
00234       row.spigot    = eId->spigot();
00235       row.fiber     = eId->slbSiteNumber();
00236       row.fiberchan = eId->slbChannelIndex();
00237       if (eId->htrTopBottom()==1) row.topbottom = "t";
00238       else row.topbottom = "b";
00239       //
00240       HcalTrigTowerDetId _id( emap->lookupTrigger(*eId) );
00241       if ( !(_id.null()) ){
00242         row.rawId     = _id.rawId();
00243         row.ieta      = _id.ieta();
00244         row.iphi      = _id.iphi();
00245         row.idepth    = _id.depth();
00246         row.subdet    = _ass.getSubdetectorString(_id.subdet());
00247         // fill the map
00248         map.push_back(row);
00249       }
00250     }
00251   }
00252   else{
00253     std::cerr << "Pointer to HcalElectronicsMap is 0!!!" << std::endl;
00254   }
00255 }
00256 
00257 
00258 int EMap::read_map( std::string filename )
00259 {
00260   RooGKCounter lines;
00261 
00262   std::string _row;
00263   ifstream inFile( filename . c_str(), std::ios::in );
00264   if (!inFile){
00265     std::cout << "Unable to open file with the electronic map: " << filename << std::endl;
00266   }
00267   else{
00268     std::cout << "File with the electronic map opened successfully: " << filename << std::endl;
00269   }
00270   while ( getline( inFile, _row ) > 0 ){
00271     EMapRow aRow;
00272     char fpga[32];
00273     char subdet[32];
00274     
00275     int _read;
00276     const char * _format = "%d %d %d %s %d %d %d %d %s %d %d %d";
00277     _read = sscanf( _row . c_str(), _format,
00278                     &(aRow.rawId),
00279                     &(aRow.crate), &(aRow.slot),
00280                       fpga,
00281                     &(aRow.dcc),
00282                     &(aRow.spigot),&(aRow.fiber),&(aRow.fiberchan),
00283                     subdet,
00284                     &(aRow.ieta), &(aRow.iphi), &(aRow.idepth) );
00285     if ( _read >= 12 ){
00286       lines . count();
00287       
00288       aRow . subdet .append( subdet );
00289       aRow . topbottom .append( fpga );
00290       
00291       map . push_back( aRow );
00292       //std::cout << "DEBUG: " << _row << std::endl;
00293       //std::cout << "DEBUG: " << aRow.ieta << std::endl;
00294     }  
00295   }
00296   inFile.close();
00297   std::cout << "EMap: " << lines . getCount() << " lines read" << std::endl;
00298 
00299   return 0;
00300 }
00301   
00302 
00303 
00304 std::vector<EMap::EMapRow> & EMap::get_map( void )
00305 {
00306   return map;
00307 }
00308 
00309 
00310 bool EMap::EMapRow::operator<( const EMap::EMapRow & other) const{
00311   return rawId < other.rawId;
00312 }
00313 
00314 
00315 
00316 
00317 // ===> test procedures for the EMap class
00318 int EMap_test::test_read_map( std::string filename )
00319 {
00320   EMap map( filename );
00321   return 0;
00322 }
00323 
00324 // ===> test procedures for the LMap class
00325 LMap_test::LMap_test() :_lmap(new LMap){ }
00326 
00327 int LMap_test::test_read(std::string accessor, std::string type)
00328 {
00329   _lmap -> read(accessor,type);
00330   return 0;
00331 }