Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:12:04

0001 #ifndef FWCore_Framework_NoDataException_h
0002 #define FWCore_Framework_NoDataException_h
0003 // -*- C++ -*-
0004 //
0005 // Package:     Framework
0006 // Module:      NoDataException
0007 //
0008 /**\class NoDataException NoDataException.h Exception/interface/NoDataException.h
0009 
0010  Description: An exception that is thrown whenever data was not available
0011               in the Frame
0012 
0013  Usage:
0014     NoDataException<> is thrown whenever an extract call fails because 
0015     the type of data being extract was not available in the Frame.
0016 
0017     If your program should continue even if the extract call fails, you should
0018     catch this exception.
0019 
0020     \code
0021     try {
0022       Item<DBEventHeader> eventHeader;
0023       extract(iFrame.record(Stream::kBeginRun), eventHeader);
0024 
0025       report(INFO, kFacilityString) << "run # " << eventHeader->runNumber()
0026                                      << "event # " << eventHeader->number()
0027                      << std::endl;
0028 
0029     } catch(NoDataException<Item<DBEventHeader>::contents> &iException) {
0030       report(WARNING, kFacilityString) << iException.what() << std::endl;
0031     }
0032       
0033     \endcode
0034 
0035     To make it easier to catch exceptions, all of the FAXXX types provide
0036     C preprocessor macros of the form
0037     \code
0038        NO_XXX_DATA_EXCEPTION(type)
0039     \endcode
0040      which are just shorthand ways of writing
0041      \code
0042        NoDataException<FAXXX<type>::contents>
0043      \endcode
0044     E.g.
0045        \code
0046        NO_ITEM_DATA_EXCEPTION(DBEventHeader)
0047        \endcode
0048        is the same as writing
0049        \code
0050        NoDataException<Item<DBEventHeader>::value_type>
0051        \endcode
0052 
0053     NOTE: NoDataException<> is only thrown when the data is unavailable. If
0054       the data should have been available but a problem occurred while obtaining
0055       the data, then a different type of exception will be thrown.
0056 
0057       To catch ALL possible exceptions that can occur from the Data Access 
0058       system you should catch exceptions of the type DAExceptionBase.
0059 */
0060 //
0061 // Author:      Chris D Jones
0062 // Created:     Tue Dec  7 09:10:34 EST 1999
0063 //
0064 
0065 // system include files
0066 #include <string>
0067 
0068 // user include files
0069 #include "FWCore/Framework/interface/DataKey.h"
0070 #include "FWCore/Framework/interface/EventSetupRecordKey.h"
0071 #include "FWCore/Framework/interface/HCTypeTag.h"
0072 #include "FWCore/Utilities/interface/Exception.h"
0073 
0074 // forward declarations
0075 namespace edm {
0076   namespace eventsetup {
0077 
0078     class NoDataExceptionBase : public cms::Exception {
0079     public:
0080       NoDataExceptionBase(const EventSetupRecordKey& iRecordKey,
0081                           const DataKey& iDataKey,
0082                           const char* category_name = "NoDataException");
0083       ~NoDataExceptionBase() noexcept override;
0084       const DataKey& dataKey() const;
0085 
0086     protected:
0087       static std::string providerButNoDataMessage(const EventSetupRecordKey& iKey);
0088       static std::string noProviderMessage();
0089       void constructMessage(const char* iClassName, const std::string& iExtraInfo);
0090 
0091     private:
0092       void beginDataTypeMessage(std::string&) const;
0093       void endDataTypeMessage(std::string&) const;
0094 
0095       // ---------- Constructors and destructor ----------------
0096       //NoDataExceptionBase(const NoDataExceptionBase&) ; //allow default
0097       //const NoDataExceptionBase& operator=(const NoDataExceptionBase&); // allow default
0098 
0099       // ---------- data members -------------------------------
0100       EventSetupRecordKey record_;
0101       DataKey dataKey_;
0102     };
0103 
0104     template <class T>
0105     class NoDataException : public NoDataExceptionBase {
0106     public:
0107       NoDataException(const EventSetupRecordKey& iRecordKey,
0108                       const DataKey& iDataKey,
0109                       const char* category_name = "NoDataException")
0110           : NoDataExceptionBase(iRecordKey, iDataKey, category_name) {
0111         constructMessage(heterocontainer::className<T>(), providerButNoDataMessage(iRecordKey));
0112       }
0113 
0114       NoDataException(const EventSetupRecordKey& iRecordKey,
0115                       const DataKey& iDataKey,
0116                       const char* category_name,
0117                       const std::string& iExtraInfo)
0118           : NoDataExceptionBase(iRecordKey, iDataKey, category_name) {
0119         constructMessage(heterocontainer::className<T>(), iExtraInfo);
0120       }
0121     };
0122 
0123   }  // namespace eventsetup
0124 }  // namespace edm
0125 #endif