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 90 91 92 93 94 95 96 97 98 99 100
// -*- C++ -*-
//
// Package:     LibraryLoader
// Class  :     FWLiteEnabler
//
// Implementation:
//     <Notes on implementation>
//
//

// system include files
#include <iostream>
#include "TROOT.h"
#include "TInterpreter.h"
#include "TApplication.h"

// user include files
#include "FWCore/FWLite/interface/FWLiteEnabler.h"
#include "FWCore/FWLite/src/BareRootProductGetter.h"
#include "FWCore/PluginManager/interface/PluginManager.h"
#include "FWCore/PluginManager/interface/standard.h"

#include "FWCore/FWLite/interface/setRefStreamer.h"

//
// constants, enums and typedefs
//

//
// static data member definitions
//

bool FWLiteEnabler::enabled_(false);

//
// constructors and destructor
//
// Note: this ctor will never be invoked.
// All data and functions are static
FWLiteEnabler::FWLiteEnabler() {}

//
// member functions
//

void FWLiteEnabler::enable() {
  if (enabled_) {
    return;
  }
  enabled_ = true;

  edmplugin::PluginManager::configure(edmplugin::standard::config());
  static BareRootProductGetter s_getter;
  //this function must be called
  // so that the TClass we need will be available
  fwlite::setRefStreamer(&s_getter);

  //Make it easy to load our headers
  TInterpreter* intrp = gROOT->GetInterpreter();
  char const* env = std::getenv("CMSSW_FWLITE_INCLUDE_PATH");
  if (nullptr != env) {
    //this is a comma separated list
    char const* start = env;
    char const* end;
    do {
      //find end
      for (end = start; *end != 0 and *end != ':'; ++end)
        ;
      std::string dir(start, end);
      intrp->AddIncludePath(dir.c_str());
      start = end + 1;
    } while (*end != 0);
  }

  bool foundCMSIncludes = false;
  env = std::getenv("CMSSW_BASE");
  if (nullptr != env) {
    foundCMSIncludes = true;
    std::string dir(env);
    dir += "/src";
    intrp->AddIncludePath(dir.c_str());
  }

  env = std::getenv("CMSSW_RELEASE_BASE");
  if (nullptr != env) {
    foundCMSIncludes = true;
    std::string dir(env);
    dir += "/src";
    intrp->AddIncludePath(dir.c_str());
  }
  if (not foundCMSIncludes) {
    std::cerr << "Could not find the environment variables \n"
              << "  CMSSW_BASE or\n"
              << "  CMSSW_RELEASE_BASE\n"
              << " therefore attempting to '#include' any CMS headers will not work" << std::endl;
  }
  if (nullptr != gApplication) {
    gApplication->InitializeGraphics();
  }
}