00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015 #include <stdio.h>
00016 #include <iostream>
00017 #include <fstream>
00018 #include <sstream>
00019 #include <vector>
00020
00021
00022
00023 #include "CaloOnlineTools/HcalOnlineDb/interface/LMap.h"
00024 #include "CaloOnlineTools/HcalOnlineDb/interface/RooGKCounter.h"
00025 #include "DataFormats/HcalDetId/interface/HcalDetId.h"
00026
00027 using namespace std;
00028
00029
00030
00031 class LMap::impl {
00032 public:
00033 impl(){ }
00034 ~impl(){ }
00035
00036 int read( string accessor, string type );
00037 std::map<int,LMapRow> & get_map( void ){ return _lmap; };
00038
00039 private:
00040 std::vector<LMapRow> _table;
00041 std::map<int,LMapRow> _lmap;
00042
00043 };
00044
00045
00046
00047 LMap::LMap() : p_impl( new impl ) { }
00048
00049 LMap::~LMap() { }
00050
00051
00052
00053 int LMap::read( string accessor, string type )
00054 {
00055 return p_impl -> read( accessor, type );
00056 }
00057
00058 std::map<int,LMapRow> & LMap::get_map( void )
00059 {
00060 return p_impl -> get_map();
00061 }
00062
00063 int LMap::impl::read( string map_file, string type )
00064 {
00065
00066 RooGKCounter lines;
00067
00068 string _row;
00069 ifstream inFile( map_file . c_str(), ios::in );
00070 if (!inFile)
00071 {
00072 cout << "Unable to open file with the logical map: " << map_file << endl;
00073 }
00074 else
00075 {
00076 cout << "File with the logical map opened successfully: " << map_file << endl;
00077 cout << "Type: " << type << endl;
00078 }
00079 while ( getline( inFile, _row ) > 0 )
00080 {
00081 LMapRow aRow;
00082 char det[32];
00083 char rbx[32];
00084 char fpga[32];
00085 char slbin[32];
00086 char slbin2[32];
00087 char slnam[32];
00088 char rctnam[32];
00089
00090 char * let_code = "Z";
00091
00092 int _read;
00093 if ( type == "HBEF" )
00094 {
00095 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";
00096 _read = sscanf( _row . c_str(), _format,
00097 &(aRow.side),
00098 &(aRow.eta), &(aRow.phi), &(aRow.dphi), &(aRow.depth),
00099 det,
00100 rbx,
00101 &(aRow.wedge), &(aRow.rm), &(aRow.pixel), &(aRow.qie), &(aRow.adc), &(aRow.rm_fi), &(aRow.fi_ch),
00102 &(aRow.crate), &(aRow.htr),
00103 fpga,
00104 &(aRow.htr_fi),
00105 &(aRow.dcc_sl), &(aRow.spigo), &(aRow.dcc), &(aRow.slb),
00106 slbin, slbin2, slnam,
00107 &(aRow.rctcra), &(aRow.rctcar), &(aRow.rctcon),
00108 rctnam,
00109 &(aRow.fedid) );
00110 }
00111 else if ( type == "HO" )
00112 {
00113 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";
00114 _read = sscanf( _row . c_str(), _format,
00115 &(aRow.side),
00116 &(aRow.eta), &(aRow.phi), &(aRow.dphi), &(aRow.depth),
00117 det,
00118 rbx,
00119 &(aRow.wedge), &(aRow.rm), &(aRow.pixel), &(aRow.qie), &(aRow.adc), &(aRow.rm_fi), &(aRow.fi_ch),
00120 &let_code,
00121 &(aRow.crate), &(aRow.htr),
00122 fpga,
00123 &(aRow.htr_fi),
00124 &(aRow.dcc_sl), &(aRow.spigo), &(aRow.dcc), &(aRow.slb) );
00125
00126
00127
00128
00129 }
00130 if ( _read >= 23 )
00131 {
00132 lines . count();
00133
00134 string _det(det);
00135 if ( _det.find("HB") != string::npos ) aRow . det = HcalBarrel;
00136 else if ( _det.find("HE") != string::npos ) aRow . det = HcalEndcap;
00137 else if ( _det.find("HF") != string::npos ) aRow . det = HcalForward;
00138 else if ( _det.find("HO") != string::npos ) aRow . det = HcalOuter;
00139 else aRow . det = HcalOther;
00140
00141 aRow . rbx .append( rbx );
00142 aRow . fpga .append( fpga );
00143 aRow . slbin .append( slbin );
00144 aRow . slbin2 .append( slbin2 );
00145 aRow . slnam .append( slnam );
00146 aRow . rctnam .append( rctnam );
00147 aRow . let_code .append( let_code );
00148
00149 _table . push_back( aRow );
00150
00151 HcalDetId _hdid(aRow.det, aRow.side*aRow.eta, aRow.phi, aRow.depth);
00152
00153 _lmap[_hdid.rawId()] = aRow;
00154
00155 }
00156 }
00157 inFile.close();
00158 cout << "LMap: " << lines . getCount() << " lines read" << endl;
00159
00160 return 0;
00161 }
00162
00163
00164
00165 LMap_test::LMap_test() :_lmap(new LMap){ }
00166
00167 int LMap_test::test_read(string accessor, string type)
00168 {
00169 _lmap -> read(accessor,type);
00170 return 0;
00171 }