Obtaining the loader context at any point in the code

Hi ,
I am trying to make a historical time series of my own.
I would like to know how we can understand the currently loaded Masters like security master and all…
Basically i need to map ObjectIdentifiable to the SecurityDocument.

Please let me know how this can be accomplished ?


Which version/branch are you using?

I am experimenting on this branch - demo/20120201

Take a look at something like DemoEquityPortfolioLoader.java in OG-Examples. In the main method you have something which loads the local spring context (in this case called demoPortfolioLoader.xml) from the classpath. It then pulls out the beans that it wants: in that case it’s an instance of the class you’re in, but managed and initialised by the Spring context. The spring file includes another file called loaderContext.xml, which is buried in OG-Financial/src/com/opengamma/financial/portfolio/loader/loaderContext.xml, which is basically a bean bundling all the master interfaces, which themselves are defined in OG-Financial/config/com/opengamma/financial/demoMasters.xml. You can inject this bean into your own class too, and then pull out the pre-initialised and connected masters and sources from there, ready for use. If you need e.g. a HistoricalTimeSeriesMaster, it’ll already be available as a bean in the context called ‘dbHtsMaster’ - this is not cached, so should only be used for inserts.

We know that this is overly complicated and horrible, which is why it’s since been replaced with a completely different component-based configuration system in the current head of the master branch. I would not however, recommend trying to use this branch as it’s still under development and may often break and we don’t support it. Additionally, the branch you are using is not supported either and was an internal branch for a customer demonstration.

Documentation on the new style of configuration is forthcoming by the end of the month, but to give you an idea it’s basically controlled by a single .ini file, which specifies which components to start (possibly over remote interfaces) together with a chain of 1 or more .properties files to specify any installation specific particulars. There’s then a simple template for all the command line tools that provides access to any required master/source interfaces.

I am not very familiar with spring and beans.
I was expecting a singleton object or something having all the masters i need.
Anyway seems the above also does the same.

Thanks Jim , for all your time.
Really appreciate it.

One more thing to add.
I did some goofing around and this static method caught my eye -


Hopefully this should give the LoaderContext i am looking for.

Finally i got the loader context but am not able to map historical time series ID to securty id.
So the id am getting from the method in getTimeSeries is something like DBHts~1006 and i need something like DbSec~1023 to obtain the related security.

What i did to get map the Historical time series ID with Securtiy ID is below
(Code is from HistoricalTImeSeriesMaster)

LoaderContext loader=PortfolioLoaderHelper.getLoaderContext(PortfolioLoaderHelper.getApplicationContext());
SecurityMaster sm=loader.getSecurityMaster();
SecuritySearchRequest sr=new  SecuritySearchRequest(); 
HistoricalTimeSeriesInfoDocument doc=this.get(objectId, versionCorrection);
ExternalIdSearch externals=new ExternalIdSearch();
for(ExternalIdWithDates eid : doc.getInfo().getExternalIdBundle().getExternalIds()){
SecuritySearchResult r= sm.search(sr);
SecurityDocument sd = sm.get(r.getFirstDocument().getSecurity().getUniqueId());

Though i got what i need using above code , i feel the above is not the right way to do the task.

@jim - Can you tell me how this can be achieved in the right way. Also a insight on how the uniform id scheme is carried out would be quite useful to understand the system.

Ok, I see. What you did above actually IS the correct way to do it, although it’d be much less code to use the SecuritySource rather than the SecurityMaster interface for searching.

The ExternalIdBundle represents a ‘soft’ link between time series and securities - there is no ‘hard’ id link because people may want to use the components in the absence of each other. This is a general theme across all of our data sources. UniqueId/ObjectId’s are only used within each master, not across masters.

Thanks @jim , that helped a lot to get a conceptual clarity.