CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
CondDBImport.cc
Go to the documentation of this file.
1 //
2 
3 //TO DO: add the comparison between stored object and input object - bool cond::serialization::equal( obj,read_back_copy )
4 #define IMPORT_PAYLOAD_CASE( TYPENAME ) \
5  if( inputTypeName == #TYPENAME ){ \
6  match = true; \
7  const TYPENAME& obj = *static_cast<const TYPENAME*>( inputPtr ); \
8  payloadId = destination.storePayload( obj, boost::posix_time::microsec_clock::universal_time() ); \
9  }
10 
12 
15 #include "CondFormats.h"
16 
17 //
18 #include <sstream>
19 
20 namespace cond {
21 
22  namespace persistency {
23 
24  std::pair<std::string,boost::shared_ptr<void> > fetchIfExists( const cond::Hash& payloadId, Session& session, bool& exists ){
25  boost::shared_ptr<void> payloadPtr;
27  cond::Binary streamerInfo;
28  std::string payloadTypeName;
29  exists = session.fetchPayloadData( payloadId, payloadTypeName, data, streamerInfo );
30  if( exists ) {
31  bool isOra = session.isOraSession();
32  return fetchOne(payloadTypeName, data, streamerInfo, payloadPtr, isOra);
33  } else return std::make_pair( std::string(""), boost::shared_ptr<void>() );
34  }
35 
36  cond::Hash import( Session& source, const cond::Hash& sourcePayloadId, const std::string& inputTypeName, const void* inputPtr, Session& destination ){
37  cond::Hash payloadId("");
38  bool newInsert = false;
39  bool match = false;
40  if( inputPtr ){
42  IMPORT_PAYLOAD_CASE( std::vector<unsigned long long> )
213  if( inputTypeName == "L1TriggerKeyList" ){
214  match = true;
215  const L1TriggerKeyList& obj = *static_cast<const L1TriggerKeyList*>( inputPtr );
216  L1TriggerKeyList converted;
217  for( const auto& kitem : obj.tscKeyToTokenMap() ){
218  std::string pid("0");
219  std::string sourcePid = source.parsePoolToken( kitem.second );
220  if( !destination.lookupMigratedPayload( source.connectionString(), sourcePid, pid ) ){
221  std::cout <<"WARNING: L1Trigger key stored on "<<sourcePid<<" has not been migrated (yet?). Attemping to do the export..."<<std::endl;
222  bool exists = false;
223  std::pair<std::string,boost::shared_ptr<void> > missingPayload = fetchIfExists( sourcePid, source, exists );
224  if( exists ) pid = import( source, sourcePid, missingPayload.first, missingPayload.second.get(), destination );
225  std::cout <<"WARNING: OID "<<sourcePid<<" will be mapped to HASH "<<pid<<std::endl;
226  if( pid != "0" ) destination.addMigratedPayload( source.connectionString(), sourcePid, pid );
227  }
228  converted.addKey( kitem.first, pid );
229  }
230  for( const auto& ritem : obj.recordTypeToKeyToTokenMap() ){
231  for( const auto& kitem : ritem.second ){
232  std::string pid("0");
233  std::string sourcePid = source.parsePoolToken( kitem.second );
234  if( !destination.lookupMigratedPayload( source.connectionString(), sourcePid, pid ) ){
235  std::cout <<"WARNING: L1Trigger key stored on "<<sourcePid<<" has not been migrated (yet?). Attemping to do the export..."<<std::endl;
236  bool exists = false;
237  std::pair<std::string,boost::shared_ptr<void> > missingPayload = fetchIfExists( sourcePid, source, exists );
238  if( exists ) pid = import( source, sourcePid, missingPayload.first, missingPayload.second.get(), destination );
239  std::cout <<"WARNING: OID "<<sourcePid<<" will be mapped to HASH "<<pid<<std::endl;
240  if( pid != "0" ) destination.addMigratedPayload( source.connectionString(), sourcePid, pid );
241  }
242  converted.addKey( ritem.first, kitem.first, pid );
243  }
244  }
245  payloadId = destination.storePayload( converted, boost::posix_time::microsec_clock::universal_time() );
246  }
247  //IMPORT_PAYLOAD_CASE( L1TriggerKeyList )
260  //IMPORT_PAYLOAD_CASE( PerformancePayload )
317  if( inputTypeName == "PhysicsTools::Calibration::Histogram3D<double,double,double,double>" ){
318  match = true;
320  payloadId = destination.storePayload( obj, boost::posix_time::microsec_clock::universal_time() );
321  }
322  if( inputTypeName == "PhysicsTools::Calibration::Histogram2D<double,double,double>" ){
323  match = true;
325  payloadId = destination.storePayload( obj, boost::posix_time::microsec_clock::universal_time() );
326  }
327  if( inputTypeName == "std::vector<unsignedlonglong,std::allocator<unsignedlonglong>>" ){
328  match = true;
329  const std::vector<unsigned long long>& obj = *static_cast<const std::vector<unsigned long long>*>( inputPtr );
330  payloadId = destination.storePayload( obj, boost::posix_time::microsec_clock::universal_time() );
331  }
332 
333  if( ! match ) throwException( "Payload type \""+inputTypeName+"\" is unknown.","import" );
334  }
335  return payloadId;
336  }
337 
338  }
339 }
340 
Definition: ESGain.h:7
string destination
std::pair< std::string, boost::shared_ptr< void > > fetchOne(const std::string &payloadTypeName, const cond::Binary &data, const cond::Binary &streamerInfo, boost::shared_ptr< void > payloadPtr, bool is Ora)
Definition: DTT0.h:53
QGLikelihoodObject containing valid range and entries with category and histogram (mean is not used a...
#define IMPORT_PAYLOAD_CASE(TYPENAME)
Definition: CondDBImport.cc:4
std::string Hash
Definition: Types.h:43
bool fetchPayloadData(const cond::Hash &payloadHash, std::string &payloadType, cond::Binary &payloadData, cond::Binary &streamerInfoData)
Definition: Session.cc:186
const RecordToKeyToToken & recordTypeToKeyToTokenMap() const
Category structure: ranges associated with QGLikelihood histograms.
tuple pid
Definition: sysUtil.py:22
const KeyToToken & tscKeyToTokenMap() const
Contains cabling info at the device level, including DetId, APV pair numbers, hardware addresses...
char data[epos_bytes_allocation]
Definition: EPOS_Wrapper.h:82
tuple cout
Definition: gather_cfg.py:121
std::pair< typename Association::data_type::first_type, double > match(Reference key, Association association, bool bestMatchByMaxValue)
Generic matching function.
Definition: Utils.h:10
std::pair< std::string, boost::shared_ptr< void > > fetchIfExists(const cond::Hash &payloadId, Session &session, bool &exists)
Definition: CondDBImport.cc:24
QGLikelihoodSystematicsObject containing the parameters for the systematic smearing.
bool addKey(const std::string &tscKey, const std::string &payloadToken, bool overwriteKey=false)
static std::string const source
Definition: EdmProvDump.cc:42
void throwException(const std::string &message, const std::string &methodName)
Definition: Exception.cc:11