Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Code Block
[info:my_ana_pkg.my_ana_mod] time: 2010-07-31 20:05:30.043360843-07, charge: 0.233403, energy: 4393.24
[info:my_ana_pkg.my_ana_mod] time: 2010-07-31 20:05:30.093381914-07, charge: 0.248759, energy: 4380.69
[info:my_ana_pkg.my_ana_mod] time: 2010-07-31 20:05:30.143398446-07, charge: 0.243547, energy: 4384.99
[info:my_ana_pkg.my_ana_mod] time: 2010-07-31 20:05:30.193412744-07, charge: 0.249897, energy: 4393.3
[info:my_ana_pkg.my_ana_mod] time: 2010-07-31 20:05:30.243427879-07, charge: 0.248667, energy: 4389.08
[info:my_ana_pkg.my_ana_mod] time: 2010-07-31 20:05:30.293446716-07, charge: 0.245666, energy: 4392.14
[info:my_ana_pkg.my_ana_mod] time: 2010-07-31 20:05:30.343468975-07, charge: 0.251093, energy: 4389.05
[info:my_ana_pkg.my_ana_mod] time: 2010-07-31 20:05:30.393488859-07, charge: 0.253302, energy: 4389.31
...

This is probably the simplest module that you can create and it does not use any interesting features such as module parameters. Here is an example of slightly more advanced module, it's job is to count fraction of events with beam energy above certain threshold. Replace code in module files with this:

Code Block
titlemy_ana_pkg/include/my_ana_mod.h

#ifndef MY_ANA_PKG_MY_ANA_MOD_H
#define MY_ANA_PKG_MY_ANA_MOD_H

#include "psana/Module.h"

namespace my_ana_pkg {

class my_ana_mod : public Module {
public:

  my_ana_mod (const std::string& name) ;

  virtual ~my_ana_mod () ;

  virtual void event(Event& evt, Env& env);

  virtual void endJob(Env& env);
  
private:
  double m_threshold;
  unsigned long m_count;
  unsigned long m_total;
};

}
#endif // MY_ANA_PKG_MY_ANA_MOD_H
Code Block
titlemy_ana_pkg/src/my_ana_mod.cpp

#include "my_ana_pkg/my_ana_mod.h"

#include "MsgLogger/MsgLogger.h"
#include "psddl_psana/bld.ddl.h"

// This declares this class as psana module
using namespace my_ana_pkg;
PSANA_MODULE_FACTORY(my_ana_mod)

namespace my_ana_pkg {

my_ana_mod::my_ana_mod (const std::string& name)
  : Module(name)
  , m_threshold(0.0)
  , m_count(0)
  , m_total(0)
{
  m_threshold = config("threshold");
}

my_ana_mod::~my_ana_mod ()
{
}

void 
my_ana_mod::event(Event& evt, Env& env)
{
  // get beam data
  boost::shared_ptr<Psana::Bld::BldDataEBeam> ebeam = evt.get(Source());
  if (ebeam.get()) {
    if (ebeam->ebeamL3Energy() > m_threshold) {
      ++ m_count;
    }
    ++ m_total;
  }
}

void 
my_ana_mod::endJob(Env& env)
{
    MsgLog(name(), info, "Fraction of events with energy>" << m_threshold 
            << " is " << m_count*100.0/m_total << "%");
}

}

This module requires input parameter (threshold) from configuration file. Create file psana.cfg in current directory with this contents:

Code Block

[psana]
modules = my_ana_pkg.my_ana_mod

[my_ana_pkg.my_ana_mod]
threshold = 4400

And run the job, module name is specified in config file so it is not needed on the command line:

Code Block

% scons
% psana /reg/d/psdm/AMO/amo14110/xtc/e43-r0100-s0*
[info:my_ana_pkg.my_ana_mod] Fraction of events with energy>4400 is 15.9316%