FiberBrightness_service.cc
Go to the documentation of this file.
2 //System Includes
3 #include <sys/stat.h>
4 #include "cetlib/search_path.h"
5 
6 namespace photrans
7 {
8  //------------------------------------------------------------
11  : fLevel(0)
12  {
13  fBrightnessLabel = pset.get< std::string >("BrightnessLabel");
14  fReadFromFile = pset.get< bool >("ReadFromFile");
15  fLevelInitAttempted = false;
16 
17  if (fReadFromFile) {
18  fBrightnessMapName = pset.get< std::string >("BrightnessMapName");
19  fBrightnessValueName = pset.get< std::string >("BrightnessValueName");
20  fBrightnessValueMapName = pset.get< std::string >("BrightnessValueMapName");
21 
22  fBrightnessFile_ND = pset.get< std::string >("BrightnessFile_ND");
23  fBrightnessFile_FD = pset.get< std::string >("BrightnessFile_FD");
24  }
25 
27  }
28 
29  //----------------------------------------------------------
31  {
32  if(fReadFromFile) delete fLevel;
33  }
34 
35  //------------------------------------------------------------
36  double FiberBrightness::getBrightness( unsigned int plane,
37  unsigned int cell) const
38  {
39  if( this->IsModeled() )
40  return fLevel->getBrightnessLevel(plane, cell);
41  else
42  return 1.0;
43  }
44 
45  //------------------------------------------------------------
46  unsigned int FiberBrightness::getBrightnessIndex( unsigned int plane,
47  unsigned int cell) const
48  {
49  if( this->IsModeled() )
50  return fLevel->getBrightnessIndex(plane, cell);
51  else
52  return 0;
53  }
54 
55  //------------------------------------------------------------
57  {
58  if( this->IsModeled() )
59  return fLevel->NumberBrightnessBins();
60  else
61  return 1;
62  }
63 
64 
65  //------------------------------------------------------------
67  {
69  std::cerr << "Do not use the FiberBrightness service before beginRun!"
70  << std::endl;
71  std::abort();
72  }
73  return fLevel;
74  }
75 
76 
77  //----------------------------------------------------------
79  {
80  fLevelInitAttempted = true;
81 
82  if( !fReadFromFile ){
84  run.getByLabel(fBrightnessLabel, hlevel);
85 
86  if( hlevel.failedToGet() ){
87 
88  LOG_DEBUG("FiberBrightness")
89  << "Unable to get brightness levels from the Run record label: "
91  << ".\n Reading from file is disabled. Assume there is no brightness "
92  << "information available.";
93 
94  return;
95  } // end no valid handle found
96  else{
97  fLevel = &(*hlevel);
98 
99  return;
100  } // end found a valid handle
101  } // end if we are getting the brightness from the file
102 
103  if(fLevel){
104  return; // already loaded from previous run
105  }
106 
107  cet::search_path sp("FW_SEARCH_PATH");
108  std::string brightness_file;
109 
110  if (fDet->DetId(run) == novadaq::cnv::kFARDET)
111  sp.find_file(fBrightnessFile_FD, brightness_file);
112  else if(fDet->DetId(run) == novadaq::cnv::kNEARDET)
113  sp.find_file(fBrightnessFile_ND, brightness_file);
114 
115  struct stat sb;
116  if ( brightness_file.empty() || stat(brightness_file.c_str(), &sb) != 0 )
117  throw cet::exception("NoBrightnessFile")
118  << "fiber brightness histo file " << brightness_file
119  << " not found!\n" << __FILE__ << ":" << __LINE__ << "\n";
120 
121  // constructor decides if initialized value is a path or an environment variable
122  fLevel = new BrightnessLevel(brightness_file,
126 
127  LOG_INFO("FiberBrightness")
128  << "No Fiber brightness product found with label: "
130  << ".\n Reading from file is enabled. Now read from file: "
131  << brightness_file
132  << ".\n";
133 
134  return;
135  }
136 
138 }
139 ////////////////////////////////////////////////////////////////////////
#define LOG_DEBUG(stream)
Definition: Messenger.h:149
novadaq::cnv::DetId DetId() const
What detector are we in?
#define DEFINE_ART_SERVICE(svc)
Definition: ServiceMacros.h:93
const BrightnessLevel * fLevel
OStream cerr
Definition: OStream.cxx:7
::xsd::cxx::tree::exception< char > exception
Definition: Database.h:225
unsigned int getBrightnessIndex(unsigned int plane, unsigned int cell) const
This slightly less simple photon transport uses a template for photon collection in time and in dista...
FiberBrightness(fhicl::ParameterSet const &pset, art::ActivityRegistry &reg)
unsigned int NumberBrightnessBins() const
std::string find_file(std::string const &filename) const
unsigned int NumberBrightnessBins() const
double getBrightness(unsigned int plane, unsigned int cell) const
Definition: Run.h:31
void preBeginRun(art::Run const &run)
unsigned int getBrightnessIndex(unsigned int plane, unsigned int cell) const
double getBrightnessLevel(unsigned int plane, unsigned int cell) const
Far Detector at Ash River, MN.
T get(std::string const &key) const
Definition: ParameterSet.h:231
std::string fBrightnessValueMapName
Near Detector in the NuMI cavern.
Definition: run.py:1
GlobalSignal< detail::SignalResponseType::FIFO, void(Run const &)> sPreBeginRun
::xsd::cxx::tree::string< char, simple_type > string
Definition: Database.h:154
std::string fBrightnessFile_FD
Relative path to the FD brightness correction file.
bool getByLabel(std::string const &label, std::string const &productInstanceName, Handle< PROD > &result) const
Definition: DataViewImpl.h:344
std::string fBrightnessFile_ND
Relative path to the ND brightness correction file.
#define LOG_INFO(stream)
Definition: Messenger.h:144
bool failedToGet() const
Definition: Handle.h:196
art::ServiceHandle< ds::DetectorService > fDet