DataWriter

Macros

Line Code
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89
#ifndef CondTools_L1Trigger_DataWriter_h
#define CondTools_L1Trigger_DataWriter_h

// Framework
#include "FWCore/Framework/interface/IOVSyncValue.h"
#include "FWCore/Framework/interface/EventSetup.h"
#include "FWCore/Framework/interface/DataKey.h"

#include "FWCore/ServiceRegistry/interface/Service.h"
#include "CondCore/DBOutputService/interface/PoolDBOutputService.h"
#include "CondCore/CondDB/interface/Session.h"

#include "DataFormats/Provenance/interface/RunID.h"

// L1T includes
#include "CondFormats/L1TObjects/interface/L1TriggerKeyList.h"
#include "CondFormats/L1TObjects/interface/L1TriggerKey.h"

#include "CondTools/L1Trigger/interface/WriterProxy.h"

#include <string>
#include <map>

namespace l1t {

  /* This class is used to write L1 Trigger configuration data to Pool DB.
 * It also has a function for reading L1TriggerKey directly from Pool.
 *
 * In order to use this class to write payloads, user has to make sure to register datatypes that she or he is
 * interested to write to the framework. This should be done with macro REGISTER_L1_WRITER(record, type) found in
 * WriterProxy.h file. Also, one should take care to register these data types to CondDB framework with macro
 * REGISTER_PLUGIN(record, type) from registration_macros.h found in PluginSystem.
 */

  class DataWriter {
  public:
    DataWriter();
    ~DataWriter();

    // Payload and IOV writing functions.

    // Get payload from EventSetup and write to DB with no IOV
    // recordType = "record@type", return value is payload token
    std::string writePayload(const edm::EventSetup& setup, const std::string& recordType);

    // Use PoolDBOutputService to append IOV with sinceRun to IOV sequence
    // for given ESRecord.  PoolDBOutputService knows the corresponding IOV tag.
    // Return value is true if IOV was updated; false if IOV was already
    // up to date.
    bool updateIOV(const std::string& esRecordName,
                   const std::string& payloadToken,
                   edm::RunNumber_t sinceRun,
                   bool logTransactions = false);

    // Write L1TriggerKeyList payload and set IOV.  Takes ownership of pointer.
    void writeKeyList(L1TriggerKeyList* keyList, edm::RunNumber_t sinceRun = 0, bool logTransactions = false);

    // Read object directly from Pool, not from EventSetup.
    template <class T>
    void readObject(const std::string& payloadToken, T& outputObject);

    std::string payloadToken(const std::string& recordName, edm::RunNumber_t runNumber);

    std::string lastPayloadToken(const std::string& recordName);

    bool fillLastTriggerKeyList(L1TriggerKeyList& output);

  protected:
  };

  template <class T>
  void DataWriter::readObject(const std::string& payloadToken, T& outputObject) {
    edm::Service<cond::service::PoolDBOutputService> poolDb;
    if (!poolDb.isAvailable()) {
      throw cond::Exception("DataWriter: PoolDBOutputService not available.");
    }

    cond::persistency::Session session = poolDb->session();
    session.transaction().start(true);

    // Get object from CondDB
    std::shared_ptr<T> ref = session.fetchPayload<T>(payloadToken);
    outputObject = *ref;
    session.transaction().commit();
  }

}  // namespace l1t

#endif