StaticMapService_service.cc
Go to the documentation of this file.
1 #ifndef CHANNELMAP_SERVICE__CC
2 #define CHANNELMAP_SERVICE__CC
3 ////////////////////////////////////////////////////////////////////////
4 /// \file ChannelMap_service.cc
5 ///
6 /// \brief A service to manipulate channel map, containing activity
7 ///
8 /// \author Andrey Sheshukov
9 ////////////////////////////////////////////////////////////////////////
10 
13 #include <boost/filesystem.hpp>
14 #include <algorithm>
15 
16 
17 namespace novaddt{
18 
21  fMapSource(p.get<std::string>("source")),
22  fFileWatcher(fMapSource)
23 {
24  //::mf::SetModuleName("StaticMapService");
25  ::mf::LogInfo("StaticMapService")<<"map source:"<<fMapSource;
26 
27  //set watcher to monitor file changes in the MapFile
29  reload();
30 }
31 
33  //reload themap from a new file, when the run number was changed
35  {
36  mf::LogInfo("MapRollover")<<" Map file changed. Updating the map..."<<std::endl;
38  reload();
39  }
40 }
41 
42 
44 {
45  ::mf::LogInfo("Progress")<<"reading map from file \""<<fname<<"\"";
46  //block until file is created
47  if(!boost::filesystem::exists(fname)){
48  ::mf::LogWarning("Progress")<<"File "<<fname<<"does not exist.\n";
49  return;
50  }
51 
52  std::ifstream s(fname.data(),std::ifstream::binary);
53  if(!s.good()){
54  ::mf::LogError("Progress")<<" error opening file \""<<fname<<"\"";
55  return;
56  }
57  s>>fMap;
58  ::mf::LogInfo("Progress")<<"Read map successfully:"
59  <<"zero channels:"<< std::count(fMap.data.begin(),fMap.data.end(),0)
60  <<" of "<<fMap.data.size() <<std::endl;
61 }
62 
64 }
65 #endif
bool isModified()
Definition: FileWatcher.h:15
MaybeLogger_< ELseverityLevel::ELsev_info, false > LogInfo
#define DEFINE_ART_SERVICE(svc)
Definition: ServiceMacros.h:93
void update()
Definition: FileWatcher.h:27
const char * p
Definition: xmltok.h:285
void preProcessEvent(const art::Event &event)
const XML_Char * s
Definition: expat.h:262
StaticMapService(fhicl::ParameterSet const &pset, art::ActivityRegistry &reg)
T get(std::string const &key) const
Definition: ParameterSet.h:231
GlobalSignal< detail::SignalResponseType::FIFO, void(Event const &)> sPreProcessEvent
void readMapFromFile(const std::string &fname)
enum BeamMode string