ATLAS Offline Software
L1CaloRampRunPlan.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2020 CERN for the benefit of the ATLAS collaboration
3 */
4 
6 
7 #include <string>
8 #include <sstream>
9 #include <iostream>
10 
11 // AttributeList
12 #include "CoralBase/AttributeListSpecification.h"
14 
15 #include "GaudiKernel/MsgStream.h"
16 
17 
19  m_bEndOfRampRun(false),
20  m_nEventsPerStep(0),
21  m_itCurrentStep(0),
22  m_iCurrentEvent(-1)
23 {
24  this->addSpecification(eEventsPerStep, std::string("EventsPerStep"), std::string("int") );
25  this->addSpecification(eEnergySteps, std::string("EnergySteps"), std::string("string"));
26 }
27 
28 L1CaloRampRunPlan::L1CaloRampRunPlan(int nEventsPerStep, const std::vector<double>& vEnergySteps): AbstractL1CaloPersistentCondition("AthenaAttributeList"),
29  m_bEndOfRampRun(false),
30  m_nEventsPerStep(nEventsPerStep),
31  m_vEnergySteps(vEnergySteps),
32  m_iCurrentEvent(-1)
33 {
34  this->addSpecification(eEventsPerStep, std::string("EventsPerStep"), std::string("int") );
35  this->addSpecification(eEnergySteps, std::string("EnergySteps"), std::string("string"));
36 
38 }
39 
40 DataObject* L1CaloRampRunPlan::makePersistent() const {
41 
42  // Create AttributeListSpecification according to the attributes to be recorded
43  // this is required to create the AttributeList objs
44  coral::AttributeListSpecification* attrSpecification = this->createAttributeListSpecification();
45  if(!attrSpecification->size()) return NULL;
46 
47 
48  AthenaAttributeList* attrList = new AthenaAttributeList(*attrSpecification);
49 
50  // Set value of each row for the current channel
51  int nEventsPerStep = this->eventsPerStep();
52  std::vector<double> vEnergySteps = this->energySteps();
53 
54  (*attrList)[ this->specificationName(eEventsPerStep) ].data<int>() = nEventsPerStep;
55 
56 
57  // export energies to a string
58  std::ostringstream oss;
59  std::vector<double>::const_iterator energy_it = vEnergySteps.begin();
60  for (;energy_it!=vEnergySteps.end();++energy_it) {
61  oss << *energy_it << " ";
62  }
63  (*attrList)[ this->specificationName(eEnergySteps) ].data<std::string>()= oss.str();
64 
65  return (DataObject*) attrList;
66 }
67 
68 void L1CaloRampRunPlan::makeTransient(const AthenaAttributeList*& athenaAttributeList) {
69 
70  int nEventsPerStep = (*athenaAttributeList)[ this->specificationName(eEventsPerStep) ].data<int>();
71  std::string strEnergySteps = (*athenaAttributeList)[ this->specificationName(eEnergySteps) ].data<std::string>();
72 
73  //tokenize strTable
74  int buf;
75  std::stringstream ss(strEnergySteps); // insert the table string into a stream
76  std::vector<double> vEnergySteps; // create vector to hold our words
77  while (ss >> buf) vEnergySteps.push_back(buf);
78 
79  m_nEventsPerStep = nEventsPerStep;
80 
81  m_vEnergySteps = vEnergySteps;
83 }
84 
86  if(m_bEndOfRampRun) {
87  //log << MSG::INFO << "No more steps to generate - End of ramp run" << endmsg;
88  //std::cout << "End of ramp run - No more steps to iterate" << std::endl;
89  return;
90  }
91 
93 
97  if(m_itCurrentStep!=m_vEnergySteps.end()) {
98  //std::cout << "nEventsPerStep reached, next step: "<< *m_itCurrentStep << std::endl;
99  } else {
100  //std::cout << "nEventsPerStep reached, no more steps to iterate"<< std::endl;
101  m_iCurrentEvent = -1;
102  m_bEndOfRampRun = true;
103  return;
104  }
105  }
106 }
107 
109  std::ostringstream oss;
110  if(!m_bEndOfRampRun) {
111  oss << "L1CaloRampRunPlan - Current event: "<<m_iCurrentEvent<<", current step: "<<*m_itCurrentStep;
112  //if(m_itCurrentStep!=0) oss <<*m_itCurrentStep;
113  //else oss << "not initialized, there might be a problem !";
114  } else {
115  oss << "L1CaloRampRunPlan: No more events/steps to process";
116  }
117  return oss.str();
118 }
119 
120 
121 std::ostream& operator<<(std::ostream& output, const L1CaloRampRunPlan& rplan) {
122  output << "nEventsPerStep: "<< rplan.m_nEventsPerStep<<" ";
123  std::vector<double> vSteps = rplan.energySteps();
124  output<<" nsteps: "<< vSteps.size()<<" - steps: ";
125  std::vector<double>::const_iterator it = vSteps.begin();
126  for(;it!=vSteps.end();++it) {
127  output << *it<<" ";
128  }
129  return output;
130 }
131 
L1CaloRampRunPlan::makePersistent
virtual DataObject * makePersistent() const
Definition: L1CaloRampRunPlan.cxx:40
L1CaloRampRunPlan::eEnergySteps
@ eEnergySteps
Definition: L1CaloRampRunPlan.h:43
L1CaloRampRunPlan
Transient class defining ramps runplan objects defined by the online framework and retrieved from COO...
Definition: L1CaloRampRunPlan.h:21
PowhegControl_ttHplus_NLO.ss
ss
Definition: PowhegControl_ttHplus_NLO.py:83
L1CaloRampRunPlan::eventsPerStep
int eventsPerStep() const
Definition: L1CaloRampRunPlan.h:34
L1CaloRampRunPlan::status
std::string status()
Definition: L1CaloRampRunPlan.cxx:108
skel.it
it
Definition: skel.GENtoEVGEN.py:396
AbstractL1CaloPersistentCondition::addSpecification
void addSpecification(int specId, const std::string &specName, const std::string &specType)
Definition: AbstractL1CaloPersistentCondition.cxx:26
L1CaloRampRunPlan::m_iCurrentEvent
int m_iCurrentEvent
Definition: L1CaloRampRunPlan.h:52
AthenaAttributeList.h
L1CaloRampRunPlan::makeTransient
virtual void makeTransient(const AthenaAttributeList *&attributeList)
Definition: L1CaloRampRunPlan.cxx:68
L1CaloRampRunPlan::m_bEndOfRampRun
bool m_bEndOfRampRun
Definition: L1CaloRampRunPlan.h:45
L1CaloRampRunPlan::L1CaloRampRunPlan
L1CaloRampRunPlan()
Definition: L1CaloRampRunPlan.cxx:18
AbstractL1CaloPersistentCondition::createAttributeListSpecification
coral::AttributeListSpecification * createAttributeListSpecification() const
Definition: AbstractL1CaloPersistentCondition.cxx:31
L1CaloRampRunPlan::nextEvent
void nextEvent()
Definition: L1CaloRampRunPlan.cxx:85
L1CaloRampRunPlan::m_nEventsPerStep
int m_nEventsPerStep
Definition: L1CaloRampRunPlan.h:47
AthenaAttributeList
An AttributeList represents a logical row of attributes in a metadata table. The name and type of eac...
Definition: PersistentDataModel/PersistentDataModel/AthenaAttributeList.h:45
L1CaloRampRunPlan::energySteps
const std::vector< double > & energySteps() const
Definition: L1CaloRampRunPlan.h:35
merge.output
output
Definition: merge.py:17
L1CaloRampRunPlan::m_itCurrentStep
std::vector< double >::iterator m_itCurrentStep
Definition: L1CaloRampRunPlan.h:51
L1CaloRampRunPlan::m_vEnergySteps
std::vector< double > m_vEnergySteps
Definition: L1CaloRampRunPlan.h:48
operator<<
std::ostream & operator<<(std::ostream &output, const L1CaloRampRunPlan &rplan)
Definition: L1CaloRampRunPlan.cxx:121
AbstractL1CaloPersistentCondition::specificationName
std::string specificationName(int specId) const
Definition: AbstractL1CaloPersistentCondition.cxx:44
L1CaloRampRunPlan.h
L1CaloRampRunPlan::eEventsPerStep
@ eEventsPerStep
Definition: L1CaloRampRunPlan.h:43
AbstractL1CaloPersistentCondition
AbstractL1CaloConditionContainer abstract base class for L1Calo persistent conditions container objec...
Definition: AbstractL1CaloPersistentCondition.h:22