Project

General

Profile

Bug #2509

Trying to initialize one service with data from a second one.

Added by Andrzej Szelc over 8 years ago. Updated over 8 years ago.

Status:
Closed
Priority:
Normal
Category:
Navigation
Target version:
Start date:
02/22/2012
Due date:
% Done:

100%

Estimated time:
Occurs In:
Scope:
Internal
Experiment:
-
SSI Package:
Duration:

Description

I'm trying to initialize ServiceB with a value that is in the configuration of service A in LArSoft:
Service A would be DetectorProperties (cut down version):

class DetectorProperties {
public:
DetectorProperties(fhicl::ParameterSet const& pset, art::ActivityRegistry& reg);
~DetectorProperties();
void reconfigure(fhicl::ParameterSet const& p);
const unsigned int NumberTimeSamples() const { return fNumberTimeSamples; }
private:
unsigned int fNumberTimeSamples; ///< number of clock ticks per readout window
};

and the constructor is (fNumberTimeSamples is not called in reconfigure) :

DetectorProperties::DetectorProperties(fhicl::ParameterSet const& pset, art::ActivityRegistry &reg) :
fNumberTimeSamples(pset.get< unsigned int >("NumberTimeSamples")) {
this->reconfigure(pset);
}

and Service B is LArFFT:

class LArFFT {
public:
LArFFT(fhicl::ParameterSet const& pset, art::ActivityRegistry& reg);
~LArFFT();
const unsigned int FFTSize() const { return fSize; }
private:
// void preBeginRun(art::Run const& run);
unsigned int fSize; //size of transform
}

and the constructor is:

util::LArFFT::LArFFT(fhicl::ParameterSet const& pset, art::ActivityRegistry& reg) :
fSize(art::ServiceHandle < util::DetectorProperties > ()->NumberTimeSamples()), //fSize (pset.get< int >("FFTSize")),
fOption (pset.get< std::string >("FFTOption")),
fFitBins (pset.get< int >("FitBins")) {
std:: cout << "++++++++ fft size : " << fSize << std::endl;
// bunch of other stuff
}

so I want LArFFT::fSize to pick up the DetectorProperties::fNumberTimeSamples.
The above code compiles, but when I try to run it I get a cet::exception:

%MSG-s ArtException:  lar 22-Feb-2012 13:52:02 CST JobSetup
cet::exception caught in art
---- OtherArt BEGIN
ServiceCreation
---- NotFound BEGIN
Service no ServiceRegistry has been set for this thread
---- NotFound END
cet::exception caught during construction of service type util::LArFFT:
---- OtherArt END
%MSG

Associated revisions

Revision deb72c9f (diff)
Added by Christopher Green over 8 years ago

Basic fix for issue #2509 (need to do something extra for reconfiguration).

Revision 8a44eeaf (diff)
Added by Christopher Green over 8 years ago

Second half of fix for issue #2509: allow reconfiguration hooks.

Revision 50cb78d4 (diff)
Added by Christopher Green over 8 years ago

Final part of fix to issue #2509: collapse to one ActivityRegistry to prevent signal propagation issues.

History

#1 Updated by Christopher Green over 8 years ago

  • Category set to Navigation
  • Status changed from New to Feedback
  • Assignee set to Christopher Green
  • Target version set to 1.00.09
  • % Done changed from 0 to 50

The basic problem has been identified and fixed with deb72c9. It does however raise a question as to what should happen when a service is reconfigured.

I propose that one can register for a callback to be triggered when a service is configured: the callback will be told what the service is and it can decide what, if anything to do about that fact. Does that sound reasonable?

#2 Updated by Christopher Green over 8 years ago

  • Status changed from Feedback to Resolved
  • % Done changed from 50 to 100

Hi Andrzej,

I have implemented a new signal to be used by a service interested in being notified of other service reconfigurations. Example code is below. Of course, you could avoid this entirely by caching the ServiceHandle instead of the actual value -- assuming the accessor in the called service is inline then there should be no calling cost and it's a whole lot less work to keep track of everything than caching.

  • ServiceUsing.h:
    #ifndef test_Integration_ServiceUsing_h
    #define test_Integration_ServiceUsing_h
    
    #include "art/Framework/Services/Registry/ActivityRegistry.h" 
    #include "art/Framework/Services/Registry/ServiceHandle.h" 
    #include "fhiclcpp/ParameterSet.h" 
    
    #include "test/Integration/Reconfigurable.h" 
    
    namespace arttest {
      class ServiceUsing;
    }
    
    class arttest::ServiceUsing {
    public:
      ServiceUsing(fhicl::ParameterSet const &, art::ActivityRegistry &);
    
      int getCachedValue() const;
    private:
      void maybeGetNewValue(std::string const & service_name);
    
      int getNewValue();
    
      int cached_debug_value_;
    };
    
    inline
    int
    arttest::ServiceUsing::
    getCachedValue() const
    {
      return cached_debug_value_;
    }
    
    inline
    arttest::ServiceUsing::
    ServiceUsing(fhicl::ParameterSet const &, art::ActivityRegistry & reg )
      :
      cached_debug_value_(getNewValue())
    {
      reg.watchPostServiceReconfigure(this, &arttest::ServiceUsing::maybeGetNewValue);
    }
    
    inline
    int
    arttest::ServiceUsing::
    getNewValue()
    {
      return art::ServiceHandle<Reconfigurable>()->get_debug_level();
    }
  • ServiceUsing_service.cc:
    // Service to make sure we can use another service.
    
    #include "art/Framework/Services/Registry/ServiceMacros.h" 
    #include "test/Integration/ServiceUsing.h" 
    
    void
    arttest::ServiceUsing::
    maybeGetNewValue(std::string const & service_name)
    {
      static std::string const watched_service("Reconfigurable");
      if (service_name == watched_service) {
        cached_debug_value_ = getNewValue();
      }
    }
    
    DEFINE_ART_SERVICE(arttest::ServiceUsing)

#3 Updated by Christopher Green over 8 years ago

  • Status changed from Resolved to Closed


Also available in: Atom PDF