00001
00002
00003
00004
00005 #include "OnlineDB/SiStripESSources/interface/SiStripCondObjBuilderFromDb.h"
00006 #include "OnlineDB/SiStripESSources/interface/SiStripFedCablingBuilderFromDb.h"
00007 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00008 #include "DataFormats/SiStripCommon/interface/SiStripFecKey.h"
00009 #include "CondFormats/SiStripObjects/interface/SiStripPedestals.h"
00010 #include "CondFormats/SiStripObjects/interface/SiStripNoises.h"
00011 #include "CondFormats/SiStripObjects/interface/SiStripThreshold.h"
00012 #include "CondFormats/SiStripObjects/interface/SiStripFedCabling.h"
00013 #include "CondFormats/SiStripObjects/interface/FedChannelConnection.h"
00014 #include "CalibFormats/SiStripObjects/interface/SiStripFecCabling.h"
00015 #include "CalibFormats/SiStripObjects/interface/SiStripDetCabling.h"
00016 #include "CalibFormats/SiStripObjects/interface/SiStripQuality.h"
00017 #include <cstdlib>
00018 #include <iostream>
00019 #include <sstream>
00020 #include <iomanip>
00021 #include "Fed9UUtils.hh"
00022
00023 using namespace std;
00024 using namespace sistrip;
00025
00026
00028 SiStripCondObjBuilderFromDb::SiStripCondObjBuilderFromDb(const edm::ParameterSet&,
00029 const edm::ActivityRegistry&)
00030 {
00031 LogTrace(mlESSources_)
00032 << "[SiStripCondObjBuilderFromDb::" << __func__ << "]"
00033 << " Constructing object...";
00034 }
00035
00036
00038 SiStripCondObjBuilderFromDb::SiStripCondObjBuilderFromDb()
00039 {
00040 LogTrace(mlESSources_)
00041 << "[SiStripCondObjBuilderFromDb::" << __func__ << "]"
00042 << " Constructing object...";
00043 }
00044
00045
00047 SiStripCondObjBuilderFromDb::~SiStripCondObjBuilderFromDb() {
00048 LogTrace(mlESSources_)
00049 << "[SiStripCondObjBuilderFromDb::" << __func__ << "]"
00050 << " Destructing object...";
00051 }
00052
00053
00055 void SiStripCondObjBuilderFromDb::checkUpdate() {
00056 if (!(dbParams_==dbParams())){
00057 dbParams_=dbParams();
00058 buildCondObj();
00059 }
00060 }
00061
00062
00064 void SiStripCondObjBuilderFromDb::buildCondObj() {
00065 LogTrace(mlESSources_)
00066 << "[SiStripCondObjBuilderFromDb::" << __func__ << "]";
00067
00068
00069 if ( db_ ) {
00070
00071
00072 if ( db_->deviceFactory() ||
00073 db_->databaseCache() ) {
00074
00075
00076 SiStripFecCabling fec_cabling;
00077 SiStripFedCablingBuilderFromDb::buildFecCabling( &*db_,
00078 fec_cabling,
00079 sistrip::CABLING_FROM_CONNS );
00080
00081
00082 fed_cabling_=new SiStripFedCabling;
00083 SiStripFedCablingBuilderFromDb::getFedCabling( fec_cabling, *fed_cabling_ );
00084 SiStripDetCabling det_cabling( *fed_cabling_ );
00085
00086 buildStripRelatedObjects( &*db_, det_cabling );
00087
00088
00089
00090
00091 } else {
00092 edm::LogWarning(mlESSources_)
00093 << "[SiStripCondObjBuilderFromDb::" << __func__ << "]"
00094 << " NULL pointer to DeviceFactory returned by SiStripConfigDb!"
00095 << " Cannot build Pedestals object!";
00096 }
00097 } else {
00098 edm::LogWarning(mlESSources_)
00099 << "[SiStripCondObjBuilderFromDb::" << __func__ << "]"
00100 << " NULL pointer to SiStripConfigDb returned by DB \"service\"!"
00101 << " Cannot build Pedestals object!";
00102 }
00103 }
00104
00105
00107 void SiStripCondObjBuilderFromDb::buildStripRelatedObjects( SiStripConfigDb* const db,
00108 const SiStripDetCabling& det_cabling){
00109
00110
00111 SiStripConfigDb::FedDescriptionsRange descriptions = db->getFedDescriptions();
00112 if ( descriptions.empty() ) {
00113 edm::LogWarning(mlESSources_)
00114 << "SiStripCondObjBuilderFromDb::" << __func__ << "]"
00115 << " Unable to build Pedestals object!"
00116 << " No FED descriptions found!";
00117 return;
00118 }
00119
00120
00121 vector<uint32_t> det_ids;
00122 det_cabling.addActiveDetectorsRawIds(det_ids);
00123 if ( det_ids.empty() ) {
00124 edm::LogWarning(mlESSources_)
00125 << "SiStripCondObjBuilderFromDb::" << __func__ << "]"
00126 << " Unable to build Pedestals object!"
00127 << " No DetIds found!";
00128 return;
00129 }
00130 LogTrace(mlESSources_)
00131 << "SiStripCondObjBuilderFromDb::" << __func__ << "]"
00132 << " Found " << det_ids.size() << " active DetIds";
00133
00134 pedestals_=new SiStripPedestals();
00135 noises_=new SiStripNoises();
00136 threshold_= new SiStripThreshold();
00137 quality_=new SiStripQuality();
00138
00139
00140 vector<uint32_t>::const_iterator det_id = det_ids.begin();
00141 for ( ; det_id != det_ids.end(); det_id++ ) {
00142
00143
00144 if ( !(*det_id) ) { continue; }
00145 if ( *det_id == sistrip::invalid32_ ) { continue; }
00146
00147
00148
00149
00150 const vector<FedChannelConnection>& conns = det_cabling.getConnections(*det_id);
00151 if (conns.size()==0){
00152 edm::LogWarning(mlESSources_)
00153 << "SiStripCondObjBuilderFromDb::" << __func__ << "]"
00154 << " Unable to build Pedestals object!"
00155 << " No FED channel connections found for detid "<< *det_id;
00156 continue;
00157 }
00158
00159 vector<FedChannelConnection>::const_iterator ipair = conns.begin();
00160 vector< vector<FedChannelConnection>::const_iterator > listConns(ipair->nApvPairs(),conns.end());
00161 for ( ; ipair != conns.end(); ipair++ ){
00162
00163 if (ipair->fedId() && ipair->apvPairNumber()<3){
00164
00165
00166 listConns[ipair-conns.begin()]=ipair;
00167 } else {
00168 edm::LogWarning(mlESSources_)
00169 << "SiStripCondObjBuilderFromDb::" << __func__ << "]"
00170 << " DetId " << ipair->detId()
00171 << " is missing \n a) APV pair number " << ipair->apvPairNumber()
00172 << " out of " << ipair->nApvPairs() << " APV pairs\n or \n b) fedId " << ipair->fedId();
00173 }
00174 }
00175
00176
00177
00178
00179
00180
00181 SiStripPedestals::InputVector inputPedestals;
00182 SiStripNoises::InputVector inputNoises;
00183 SiStripThreshold::InputVector inputThreshold;
00184 SiStripQuality::InputVector inputQuality;
00185
00186 uint16_t apvPair;
00187 vector< vector<FedChannelConnection>::const_iterator >::const_iterator ilistConns=listConns.begin();
00188 for ( ; ilistConns != listConns.end(); ++ilistConns ) {
00189 ipair=*ilistConns;
00190 apvPair=(ilistConns-listConns.begin());
00191
00192 if ( ipair == conns.end() ) {
00193
00194 edm::LogWarning(mlESSources_)
00195 << "SiStripCondObjBuilderFromDb::" << __func__ << "]"
00196 << " Unable to find FED connection for detid : " << *det_id << " APV pair number " << apvPair
00197 << " Writing default values";
00198 uint16_t istrip = apvPair*sistrip::STRIPS_PER_FEDCH;
00199 inputQuality.push_back(quality_->encode(istrip,sistrip::STRIPS_PER_FEDCH));
00200 threshold_->setData( istrip, 0., 0., inputThreshold );
00201 for ( ;istrip < (apvPair+1)*sistrip::STRIPS_PER_FEDCH; ++istrip ){
00202 pedestals_->setData( 0.,inputPedestals );
00203 noises_->setData( 0., inputNoises );
00204
00205 }
00206 continue;
00207 }
00208
00209
00210
00211
00212
00213
00214 SiStripConfigDb::FedDescriptionsV::const_iterator description = descriptions.begin();
00215 while ( description != descriptions.end() ) {
00216 if ( (*description)->getFedId() ==ipair->fedId() ) { break; }
00217 description++;
00218 }
00219 if ( description == descriptions.end() ) {
00220 edm::LogWarning(mlESSources_)
00221 << "SiStripCondObjBuilderFromDb::" << __func__ << "]"
00222 << " Unable to find FED description for FED id: " << ipair->fedId() << " detid : " << *det_id << " APV pair number " << apvPair
00223 << " Writing default values";
00224 uint16_t istrip = apvPair*sistrip::STRIPS_PER_FEDCH;
00225 inputQuality.push_back(quality_->encode(istrip,sistrip::STRIPS_PER_FEDCH));
00226 threshold_->setData( istrip, 0., 0., inputThreshold );
00227 for ( ;istrip < (apvPair+1)*sistrip::STRIPS_PER_FEDCH; ++istrip ){
00228 pedestals_->setData( 0.,inputPedestals );
00229 noises_->setData( 0., inputNoises );
00230
00231 }
00232 continue;
00233 }
00234
00235
00236 const Fed9U::Fed9UStrips& strips = (*description)->getFedStrips();
00237
00238
00239 for ( uint16_t iapv = 2*ipair->fedCh(); iapv < 2*ipair->fedCh()+2; iapv++ ) {
00240
00241
00242 Fed9U::Fed9UAddress addr;
00243 addr.setFedApv(iapv);
00244 vector<Fed9U::Fed9UStripDescription> strip = strips.getApvStrips(addr);
00245
00246
00247
00248
00249 vector<Fed9U::Fed9UStripDescription>::const_iterator istrip = strip.begin();
00250 uint16_t jstrip = ipair->apvPairNumber()*sistrip::STRIPS_PER_FEDCH;
00251 for ( ; istrip != strip.end(); istrip++ ) {
00252
00253
00254
00255 pedestals_->setData( istrip->getPedestal() , inputPedestals);
00256 noises_ ->setData( istrip->getNoise() , inputNoises );
00257 threshold_->setData( jstrip, istrip->getLowThresholdFactor(),
00258 istrip->getHighThresholdFactor(), inputThreshold );
00259 if(istrip->getDisable())
00260 inputQuality.push_back(quality_->encode(jstrip,1));
00261 jstrip++;
00262 }
00263 }
00264 }
00265
00266
00267 if ( !pedestals_->put( *det_id, inputPedestals ) ) {
00268 edm::LogWarning(mlESSources_)
00269 << "[SiStripCondObjBuilderFromDb::" << __func__ << "]"
00270 << " Unable to insert values into SiStripPedestals object!"
00271 << " DetId already exists!";
00272 }
00273
00274
00275 if ( !noises_->put( *det_id, inputNoises ) ) {
00276 edm::LogWarning(mlESSources_)
00277 << "[SiStripCondObjBuilderFromDb::" << __func__ << "]"
00278 << " Unable to insert values into SiStripNoises object!"
00279 << " DetId already exists!";
00280 }
00281
00282
00283 if ( !threshold_->put( *det_id, inputThreshold ) ) {
00284 edm::LogWarning(mlESSources_)
00285 << "[SiStripCondObjBuilderFromDb::" << __func__ << "]"
00286 << " Unable to insert values into SiStripThreshold object!"
00287 << " DetId already exists!";
00288 }
00289
00290
00291 uint32_t detid=*det_id;
00292 if (inputQuality.size()){
00293 quality_->compact(detid,inputQuality);
00294 if ( !quality_->put( *det_id, inputQuality ) ) {
00295 edm::LogWarning(mlESSources_)
00296 << "[SiStripCondObjBuilderFromDb::" << __func__ << "]"
00297 << " Unable to insert values into SiStripThreshold object!"
00298 << " DetId already exists!";
00299 }
00300 }
00301
00302
00303 }
00304
00305 }