Jpp  debug
the software that should make you happy
Public Types | Public Member Functions | Static Public Member Functions | Protected Member Functions | Protected Attributes | Friends | List of all members
JDATABASE::JDetectorIntegration_t Struct Reference

Detector integration. More...

#include <JDetectorIntegration_t.hh>

Inheritance diagram for JDATABASE::JDetectorIntegration_t:
std::vector< JProductIntegration_t >

Public Types

typedef std::multimap< JUPI_t, int > map_type
 
typedef std::pair< map_type::const_iterator, map_type::const_iterator > range_type
 
typedef map_type::const_iterator range_const_iterator
 
typedef map_type::const_iterator range_iterator
 

Public Member Functions

 JDetectorIntegration_t ()
 Default constructor. More...
 
void configure (const std::string &detid, const bool option=false)
 Configure detector integration for given detector identifier. More...
 
const JProductIntegration_ttrace (const JUPI_t &upi, const JPBS_t &pbs=PBS::DETECTOR) const
 Trace product up to given integration level. More...
 
void print (std::ostream &out, const JUPI_t &upi) const
 Print product trace. More...
 
void print (std::ostream &out, const JProductIntegration_t &product) const
 Print product trace. More...
 
void load (const char *const file_name, const std::string &separator=";")
 Load detector integration from CSV formatted input file. More...
 
range_type find (const JUPI_t &upi) const
 Find range of products with given UPI. More...
 
range_type find (const JPBS_t &pbs) const
 Find range of products with given PBS. More...
 
range_type get (const JUPI_t &upi) const
 Get components of product with given UPI. More...
 

Static Public Member Functions

static const char *const getName ()
 Table name. More...
 
static bool compare (const JProductIntegration_t &first, const JProductIntegration_t &second)
 Compare two product integrations. More...
 

Protected Member Functions

void configure (JProductIntegration_t &product, const JPeriod_t &period)
 Configure detector integration for given detector identifier. More...
 

Protected Attributes

map_type up
 up link UPI to integration data More...
 
map_type down
 down link UPI to integration data More...
 
map_type out
 link UPI to disintegrated data More...
 

Friends

bool operator>> (ResultSet &rs, JDetectorIntegration_t &detector)
 Read detector integration from result set. More...
 
std::istream & operator>> (std::istream &in, JDetectorIntegration_t &object)
 Read detector integration from input stream. More...
 
std::ostream & operator<< (std::ostream &out, const JDetectorIntegration_t &object)
 Write detector integration to output stream. More...
 

Detailed Description

Detector integration.

This class is used

Note that the method JDetectorIntegration_t::configure should be used to set up the integration data for a specific detector.

Definition at line 187 of file JDetectorIntegration_t.hh.

Member Typedef Documentation

◆ map_type

Definition at line 192 of file JDetectorIntegration_t.hh.

◆ range_type

typedef std::pair<map_type::const_iterator, map_type::const_iterator> JDATABASE::JDetectorIntegration_t::range_type

Definition at line 194 of file JDetectorIntegration_t.hh.

◆ range_const_iterator

Definition at line 195 of file JDetectorIntegration_t.hh.

◆ range_iterator

typedef map_type::const_iterator JDATABASE::JDetectorIntegration_t::range_iterator

Definition at line 196 of file JDetectorIntegration_t.hh.

Constructor & Destructor Documentation

◆ JDetectorIntegration_t()

JDATABASE::JDetectorIntegration_t::JDetectorIntegration_t ( )
inline

Default constructor.

Definition at line 202 of file JDetectorIntegration_t.hh.

203  {}

Member Function Documentation

◆ getName()

static const char* const JDATABASE::JDetectorIntegration_t::getName ( )
inlinestatic

Table name.

Definition at line 190 of file JDetectorIntegration_t.hh.

◆ configure() [1/2]

void JDATABASE::JDetectorIntegration_t::configure ( const std::string &  detid,
const bool  option = false 
)
inline

Configure detector integration for given detector identifier.

The components of the given detector are selected based on the following rules:

  1. the component should have a start date before that of the given detector;
  2. if multiple components appear at the same place in the same container, the one with the latest start date is taken.

The option can be used to retain only those products that are part of the given detector.

Parameters
detiddetector identifier
optionoption

Definition at line 219 of file JDetectorIntegration_t.hh.

220  {
221  using namespace std;
222  using namespace JPP;
223 
224  up .clear();
225  down.clear();
226  out .clear();
227 
228  for (size_t index = 0; index != this->size(); ++index) {
229 
230  JProductIntegration_t& product = (*this)[index];
231 
232  product.unset();
233 
234  if (product.content != JUPI_t()) {
235 
236  up .insert(make_pair(product.content .getUPI(), index));
237  down.insert(make_pair(product.container.getUPI(), index));
238 
239  } else {
240 
241  out .insert(make_pair(product.container.getUPI(), index));
242  }
243  }
244 
245  for (iterator product = this->begin(); product != this->end(); ++product) {
246  if (product->operation == detid) {
247  configure(*product, JPeriod_t(product->start_date, product->end_date));
248  }
249  }
250 
251  if (option) {
252  this->erase(partition(this->begin(), this->end(), make_predicate(&JProductIntegration_t::is_set, true)), this->end());
253  }
254 
255  up .clear();
256  down.clear();
257 
258  for (size_t index = 0; index != this->size(); ++index) {
259 
260  const JProductIntegration_t& product = (*this)[index];
261 
262  if (product.is_set()) {
263  up .insert(make_pair(product.content .getUPI(), index));
264  down.insert(make_pair(product.container.getUPI(), index));
265  }
266  }
267  }
JTOOLS::JRange< JDate_t > JPeriod_t
Type definition of period.
JPredicate< JResult_t T::*, JComparison::eq > make_predicate(JResult_t T::*member, const JResult_t value)
Helper method to create predicate for data member.
Definition: JPredicate.hh:128
This name space includes all other name spaces (except KM3NETDAQ, KM3NET and ANTARES).
Definition: JSTDTypes.hh:14
map_type out
link UPI to disintegrated data
map_type down
down link UPI to integration data
void configure(const std::string &detid, const bool option=false)
Configure detector integration for given detector identifier.
map_type up
up link UPI to integration data
Auxiliary class for product integration data.
bool is_set() const
Check product status.
Universal product identifier (UPI).
Definition: JUPI_t.hh:32
const JUPI_t & getUPI() const
Get UPI.
Definition: JUPI_t.hh:100

◆ trace()

const JProductIntegration_t& JDATABASE::JDetectorIntegration_t::trace ( const JUPI_t upi,
const JPBS_t pbs = PBS::DETECTOR 
) const
inline

Trace product up to given integration level.

Parameters
upiUPI
pbsPBS
Returns
product

Definition at line 277 of file JDetectorIntegration_t.hh.

279  {
280  using namespace std;
281 
282  if (upi.getPBS() >= pbs) {
283 
284  const range_type range = find(upi);
285 
286  switch (distance(range.first, range.second)) {
287 
288  case 1:
289  {
290  const JProductIntegration_t& product = (*this)[range.first->second];
291 
292  if (product.container.getPBS() == pbs)
293  return product;
294  else
295  return trace(product.container.getUPI(), pbs);
296  }
297 
298  case 0:
299  THROW(JDatabaseException, "Invalid UPI " << upi);
300 
301  default:
302  THROW(JDatabaseException, "Ambiguous integration of UPI " << upi);
303  }
304 
305  } else {
306 
307  THROW(JDatabaseException, "Invalid PBS " << upi.getPBS() << " < " << pbs);
308  }
309  }
#define THROW(JException_t, A)
Marco for throwing exception with std::ostream compatible message.
Definition: JException.hh:712
std::vector< T >::difference_type distance(typename std::vector< T >::const_iterator first, typename PhysicsEvent::const_iterator< T > second)
Specialisation of STL distance.
Database exception.
Definition: JException.hh:684
JKey_t first
Definition: JPair.hh:128
JValue_t second
Definition: JPair.hh:129
range_type find(const JUPI_t &upi) const
Find range of products with given UPI.
const JProductIntegration_t & trace(const JUPI_t &upi, const JPBS_t &pbs=PBS::DETECTOR) const
Trace product up to given integration level.
const JPBS_t & getPBS() const
Get PBS.
Definition: JPBS_t.hh:101

◆ print() [1/2]

void JDATABASE::JDetectorIntegration_t::print ( std::ostream &  out,
const JUPI_t upi 
) const
inline

Print product trace.

Parameters
outoutput stream
upiUPI

Definition at line 318 of file JDetectorIntegration_t.hh.

319  {
320  using namespace std;
321 
322  range_type range;
323 
324  range = find(upi);
325 
326  for (map_type::const_iterator i = range.first; i != range.second; ++i) {
327 
328  out << upi << " -> ";
329 
330  print(out, (*this)[i->second]);
331  }
332 
333  range = down.equal_range(upi);
334 
335  for (range_iterator i = range.first; i != range.second; ++i) {
336  out << "<- " << (*this)[i->second] << endl;
337  }
338  }
void print(std::ostream &out, const JUPI_t &upi) const
Print product trace.

◆ print() [2/2]

void JDATABASE::JDetectorIntegration_t::print ( std::ostream &  out,
const JProductIntegration_t product 
) const
inline

Print product trace.

Parameters
outoutput stream
productproduct

Definition at line 347 of file JDetectorIntegration_t.hh.

348  {
349  using namespace std;
350 
351  out << product.container.getUPI() << ' '
352  //<< JPeriod_t(product.start_date, product.end_date) << ' '
353  << "-> ";
354 
355  const range_type range = find(product.container.getUPI());
356 
357  for (map_type::const_iterator i = range.first; i != range.second; ++i) {
358  print(out, (*this)[i->second]);
359  }
360 
361  if (distance(range.first, range.second) != 1) {
362  out << product.operation << std::endl;
363  }
364  }

◆ load()

void JDATABASE::JDetectorIntegration_t::load ( const char *const  file_name,
const std::string &  separator = ";" 
)
inline

Load detector integration from CSV formatted input file.

The input should be conform output of JPrintDB -q "integration" -c ";" -W1.

Parameters
file_namefile name
separatorseparator

Definition at line 402 of file JDetectorIntegration_t.hh.

403  {
404  using namespace std;
405  using namespace JPP;
406 
407  ifstream in(file_name);
408 
409  in.ignore(numeric_limits<streamsize>::max(), '\n');
410 
411  for (string buffer; getline(in, buffer); ) {
412 
413  istringstream is(buffer);
414 
415  const locale loc(is.getloc(), new JWhiteSpacesFacet(is.getloc(), separator));
416 
417  is.imbue(loc);
418 
419  JProductIntegration parameters;
420 
421  is >> buffer; istringstream(trim(buffer)) >> parameters.OPERATIONID;
422  is >> buffer; istringstream(trim(buffer)) >> parameters.CITY;
423  is >> buffer; istringstream(trim(buffer)) >> parameters.LOCATIONID;
424  is >> buffer; istringstream(trim(buffer)) >> parameters.LOGIN;
425  is >> buffer; istringstream(trim(buffer)) >> parameters.USERID;
426  is >> buffer; istringstream(trim(buffer)) >> parameters.STARTD;
427  is >> buffer; istringstream(trim(buffer)) >> parameters.ENDD;
428  is >> buffer; istringstream(trim(buffer)) >> parameters.CONTAINER_UPI;
429  is >> buffer; istringstream(trim(buffer)) >> parameters.POSITION;
430  is >> buffer; istringstream(trim(buffer)) >> parameters.CONTENT_UPI;
431 
432  const JProductIntegration_t product(parameters);
433 
434  this->up .insert(make_pair(product.content .getUPI(), this->size()));
435  this->down.insert(make_pair(product.container.getUPI(), this->size()));
436 
437  this->push_back(product);
438  }
439 
440  in.close();
441  }
Auxiliary class to specify white space character(s) in currect locale.
char * loc(char *orig)
std::ostream & separator(std::ostream &out)
Print separator.
std::istream & getline(std::istream &in, JString &object)
Read string from input stream until end of line.
Definition: JString.hh:478
std::string trim(const std::string &buffer)
Trim string.
Definition: JLangToolkit.hh:79

◆ find() [1/2]

range_type JDATABASE::JDetectorIntegration_t::find ( const JUPI_t upi) const
inline

Find range of products with given UPI.


The returned range corresponds to the usual begin and end iterators, each pointing to an STL pair consisting of a UPI and index.

Parameters
upiUPI
Returns
index

Definition at line 492 of file JDetectorIntegration_t.hh.

493  {
494  return up.equal_range(upi);
495  }

◆ find() [2/2]

range_type JDATABASE::JDetectorIntegration_t::find ( const JPBS_t pbs) const
inline

Find range of products with given PBS.


The returned range corresponds to the usual begin and end iterators, each pointing to an STL pair consisting of a UPI and index.

Parameters
pbsPBS
Returns
range

Definition at line 506 of file JDetectorIntegration_t.hh.

507  {
508  range_const_iterator p = up.lower_bound(JUPI_t(pbs));
509  range_const_iterator q = p;
510 
511  while (q != up.end() && (*this)[q->second].content.getPBS() <= pbs) {
512  ++q;
513  }
514 
515  return range_type(p,q);
516  }
std::pair< map_type::const_iterator, map_type::const_iterator > range_type
map_type::const_iterator range_const_iterator

◆ get()

range_type JDATABASE::JDetectorIntegration_t::get ( const JUPI_t upi) const
inline

Get components of product with given UPI.


The returned range corresponds to the usual begin and end iterators, each pointing to an STL pair consisting of a UPI and index.

Parameters
upiUPI
Returns
index

Definition at line 527 of file JDetectorIntegration_t.hh.

528  {
529  return down.equal_range(upi);
530  }

◆ compare()

static bool JDATABASE::JDetectorIntegration_t::compare ( const JProductIntegration_t first,
const JProductIntegration_t second 
)
inlinestatic

Compare two product integrations.

Parameters
firstfirst product integration
secondsecond product integration
Returns
true if first integrated before second; else false

Definition at line 540 of file JDetectorIntegration_t.hh.

541  {
542  if (first.start_date == second.start_date)
543  return first.operation < second.operation;
544  else
545  return first.start_date < second.start_date;
546  }

◆ configure() [2/2]

void JDATABASE::JDetectorIntegration_t::configure ( JProductIntegration_t product,
const JPeriod_t period 
)
inlineprotected

Configure detector integration for given detector identifier.


This method recursively sets the status all related products.

Parameters
productproduct
periodvalidity period

Definition at line 557 of file JDetectorIntegration_t.hh.

558  {
559  using namespace std;
560 
561  range_type range;
562 
563  range = out.equal_range(product.container);
564 
565  for (range_iterator i = range.first; i != range.second; ++i) {
566 
567  const JProductIntegration_t& object = (*this)[i->second];
568 
569  if (object.position == product.position &&
570  object.start_date <= period.getLowerLimit() &&
571  object.start_date > product.start_date) {
572  return;
573  }
574  }
575 
576  product.set();
577 
578  map<int, int> zmap; // position -> index
579 
580  range = down.equal_range(product.content);
581 
582  for (range_iterator i = range.first; i != range.second; ++i) {
583 
584  const JProductIntegration_t& object = (*this)[i->second];
585 
586  if (object.start_date <= period.getLowerLimit()) {
587  if (zmap.count(object.position) == 0 || compare((*this)[zmap[object.position]], object)) {
588  zmap[object.position] = i->second;
589  }
590  }
591  }
592 
593  for (map<int, int>::iterator i = zmap.begin(); i != zmap.end(); ++i) {
594  configure((*this)[i->second], period);
595  }
596  }
T getLowerLimit() const
Get lower limit.
Definition: JRange.hh:202
static bool compare(const JProductIntegration_t &first, const JProductIntegration_t &second)
Compare two product integrations.

Friends And Related Function Documentation

◆ operator>> [1/2]

bool operator>> ( ResultSet &  rs,
JDetectorIntegration_t detector 
)
friend

Read detector integration from result set.

Parameters
rsresult set
detectordetector
Returns
true if read; else false

Definition at line 374 of file JDetectorIntegration_t.hh.

375  {
376  using namespace std;
377 
378  for (JProductIntegration parameters; rs >> parameters; ) {
379 
380  const JProductIntegration_t product(parameters);
381 
382  detector.up .insert(make_pair(product.content .getUPI(), detector.size()));
383  detector.down.insert(make_pair(product.container.getUPI(), detector.size()));
384 
385  detector.push_back(product);
386  }
387 
388  rs.Close();
389 
390  return true;
391  }
Detector file.
Definition: JHead.hh:227

◆ operator>> [2/2]

std::istream& operator>> ( std::istream &  in,
JDetectorIntegration_t object 
)
friend

Read detector integration from input stream.

Parameters
ininput stream
objectdetector integration
Returns
input stream

Definition at line 451 of file JDetectorIntegration_t.hh.

452  {
453  using namespace std;
454 
455  for (JProductIntegration_t product; in >> product; ) {
456 
457  object.up .insert(make_pair(product.content .getUPI(), object.size()));
458  object.down.insert(make_pair(product.container.getUPI(), object.size()));
459 
460  object.push_back(product);
461  }
462 
463  return in;
464  }

◆ operator<<

std::ostream& operator<< ( std::ostream &  out,
const JDetectorIntegration_t object 
)
friend

Write detector integration to output stream.

Parameters
outoutput stream
objectdetector integration
Returns
output stream

Definition at line 474 of file JDetectorIntegration_t.hh.

475  {
476  for (const_iterator i = object.begin(); i != object.end(); ++i) {
477  out << *i << std::endl;
478  }
479 
480  return out;
481  }

Member Data Documentation

◆ up

map_type JDATABASE::JDetectorIntegration_t::up
protected

up link UPI to integration data

Definition at line 599 of file JDetectorIntegration_t.hh.

◆ down

map_type JDATABASE::JDetectorIntegration_t::down
protected

down link UPI to integration data

Definition at line 600 of file JDetectorIntegration_t.hh.

◆ out

map_type JDATABASE::JDetectorIntegration_t::out
protected

link UPI to disintegrated data

Definition at line 601 of file JDetectorIntegration_t.hh.


The documentation for this struct was generated from the following file: