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 
11 #define IGNORE_FOR_IMPORT_CASE( TYPENAME ) \
12  if( inputTypeName == #TYPENAME ){ \
13  match = true; \
14  payloadId = 0; \
15  newInsert = false; \
16  std::cout <<"WARNING: typename "<<inputTypeName<<" will be skipped in the import."<<std::endl; \
17  }
18 
19 #define FETCH_PAYLOAD_CASE( TYPENAME ) \
20  if( payloadTypeName == #TYPENAME ){ \
21  auto payload = deserialize<TYPENAME>( payloadTypeName, data, streamerInfo, isOra ); \
22  payloadPtr = payload; \
23  match = true; \
24  }
25 
33 
36 #include "CondFormats.h"
37 
38 //
39 #include <sstream>
40 
41 namespace cond {
42 
43  namespace persistency {
44 
45  std::pair<std::string,boost::shared_ptr<void> > fetchIfExists( const cond::Hash& payloadId, Session& session, bool& exists ){
46  boost::shared_ptr<void> payloadPtr;
48  cond::Binary streamerInfo;
49  std::string payloadTypeName;
50  exists = session.fetchPayloadData( payloadId, payloadTypeName, data, streamerInfo );
51  if( exists ) {
52  bool isOra = session.isOraSession();
53  return fetchOne(payloadTypeName, data, streamerInfo, payloadPtr, isOra);
54  } else return std::make_pair( std::string(""), boost::shared_ptr<void>() );
55  }
56 
57  cond::Hash import( Session& source, const cond::Hash& sourcePayloadId, const std::string& inputTypeName, const void* inputPtr, Session& destination ){
58  cond::Hash payloadId("");
59  bool newInsert = false;
60  bool match = false;
61  if( inputPtr ){
63  IMPORT_PAYLOAD_CASE( std::vector<unsigned long long> )
225  if( inputTypeName == "L1TriggerKeyList" ){
226  match = true;
227  const L1TriggerKeyList& obj = *static_cast<const L1TriggerKeyList*>( inputPtr );
228  L1TriggerKeyList converted;
229  for( const auto& kitem : obj.tscKeyToTokenMap() ){
230  std::string pid("0");
231  std::string sourcePid = source.parsePoolToken( kitem.second );
232  if( !destination.lookupMigratedPayload( source.connectionString(), sourcePid, pid ) ){
233  std::cout <<"WARNING: L1Trigger key stored on "<<sourcePid<<" has not been migrated (yet?). Attemping to do the export..."<<std::endl;
234  bool exists = false;
235  std::pair<std::string,boost::shared_ptr<void> > missingPayload = fetchIfExists( sourcePid, source, exists );
236  if( exists ) pid = import( source, sourcePid, missingPayload.first, missingPayload.second.get(), destination );
237  std::cout <<"WARNING: OID "<<sourcePid<<" will be mapped to HASH "<<pid<<std::endl;
238  if( pid != "0" ) destination.addMigratedPayload( source.connectionString(), sourcePid, pid );
239  }
240  converted.addKey( kitem.first, pid );
241  }
242  for( const auto& ritem : obj.recordTypeToKeyToTokenMap() ){
243  for( const auto& kitem : ritem.second ){
244  std::string pid("0");
245  std::string sourcePid = source.parsePoolToken( kitem.second );
246  if( !destination.lookupMigratedPayload( source.connectionString(), sourcePid, pid ) ){
247  std::cout <<"WARNING: L1Trigger key stored on "<<sourcePid<<" has not been migrated (yet?). Attemping to do the export..."<<std::endl;
248  bool exists = false;
249  std::pair<std::string,boost::shared_ptr<void> > missingPayload = fetchIfExists( sourcePid, source, exists );
250  if( exists ) pid = import( source, sourcePid, missingPayload.first, missingPayload.second.get(), destination );
251  std::cout <<"WARNING: OID "<<sourcePid<<" will be mapped to HASH "<<pid<<std::endl;
252  if( pid != "0" ) destination.addMigratedPayload( source.connectionString(), sourcePid, pid );
253  }
254  converted.addKey( ritem.first, kitem.first, pid );
255  }
256  }
257  payloadId = destination.storePayload( converted, boost::posix_time::microsec_clock::universal_time() );
258  }
259  //IMPORT_PAYLOAD_CASE( L1TriggerKeyList )
271  //IMPORT_PAYLOAD_CASE( PerformancePayload )
325  if( inputTypeName == "PhysicsTools::Calibration::Histogram3D<double,double,double,double>" ){
326  match = true;
328  payloadId = destination.storePayload( obj, boost::posix_time::microsec_clock::universal_time() );
329  }
330  if( inputTypeName == "PhysicsTools::Calibration::Histogram2D<double,double,double>" ){
331  match = true;
333  payloadId = destination.storePayload( obj, boost::posix_time::microsec_clock::universal_time() );
334  }
335  if( inputTypeName == "std::vector<unsignedlonglong,std::allocator<unsignedlonglong>>" ){
336  match = true;
337  const std::vector<unsigned long long>& obj = *static_cast<const std::vector<unsigned long long>*>( inputPtr );
338  payloadId = destination.storePayload( obj, boost::posix_time::microsec_clock::universal_time() );
339  }
340 
341  if( ! match ) throwException( "Payload type \""+inputTypeName+"\" is unknown.","import" );
342  }
343  return payloadId;
344  }
345 
346  std::pair<std::string,boost::shared_ptr<void> > fetch( const cond::Hash& payloadId, Session& session ){
347  boost::shared_ptr<void> payloadPtr;
349  cond::Binary streamerInfo;
350  std::string payloadTypeName;
351  bool found = session.fetchPayloadData( payloadId, payloadTypeName, data, streamerInfo );
352  if( !found ) throwException( "Payload with id "+boost::lexical_cast<std::string>(payloadId)+" has not been found in the database.","fetchAndCompare" );
353  //std::cout <<"--> payload type "<<payloadTypeName<<" has blob size "<<data.size()<<std::endl;
354  bool isOra = session.isOraSession();
355  return fetchOne(payloadTypeName, data, streamerInfo, payloadPtr, isOra);
356  }
357  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 isOra ){
358 
359  bool match = false;
361  FETCH_PAYLOAD_CASE( std::vector<unsigned long long> )
534  //FETCH_PAYLOAD_CASE( PerformancePayload )
589 
590  //
591  if( payloadTypeName == "PhysicsTools::Calibration::Histogram3D<double,double,double,double>" ){
592  auto payload = deserialize<PhysicsTools::Calibration::Histogram3D<double,double,double,double> >(payloadTypeName, data, streamerInfo, isOra );
593  payloadPtr = payload;
594  match = true;
595  }
596  if( payloadTypeName == "PhysicsTools::Calibration::Histogram2D<double,double,double>" ){
597  auto payload = deserialize<PhysicsTools::Calibration::Histogram2D<double,double,double> >(payloadTypeName, data, streamerInfo, isOra );
598  payloadPtr = payload;
599  match = true;
600  }
601  if( payloadTypeName == "std::vector<unsignedlonglong,std::allocator<unsignedlonglong>>" ){
602  auto payload = deserialize<std::vector<unsigned long long> >( payloadTypeName, data, streamerInfo, isOra );
603  payloadPtr = payload;
604  match = true;
605  }
606 
607  if( ! match ) throwException( "Payload type \""+payloadTypeName+"\" is unknown.","fetch" );
608  return std::make_pair( payloadTypeName, payloadPtr );
609  }
610 
611  }
612 }
613 
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)
#define FETCH_PAYLOAD_CASE(TYPENAME)
Definition: CondDBImport.cc:19
Definition: DTT0.h:53
QGLikelihoodObject containing valid range and entries with category, histogram and mean...
#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
std::pair< std::string, boost::shared_ptr< void > > fetch(const cond::Hash &payloadId, Session &session)
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:6
std::pair< std::string, boost::shared_ptr< void > > fetchIfExists(const cond::Hash &payloadId, Session &session, bool &exists)
Definition: CondDBImport.cc:45
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:43
void throwException(const std::string &message, const std::string &methodName)
Definition: Exception.cc:11