CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
DQMArchiver.cc
Go to the documentation of this file.
1 // $Id: DQMArchiver.cc,v 1.3 2011/03/30 15:33:43 mommsen Exp $
3 
12 
13 #include "TObject.h"
14 
15 #include <boost/foreach.hpp>
16 
17 #include <memory>
18 #include <string>
19 #include <vector>
20 
21 namespace smproxy
22 {
24  stateMachine_(stateMachine),
25  dqmArchivingParams_(stateMachine->getConfiguration()->getDQMArchivingParams()),
26  dqmEventQueueCollection_(stateMachine->getDQMEventQueueCollection())
27  {
29  {
31  thread_.reset(
32  new boost::thread( boost::bind(&DQMArchiver::activity, this) )
33  );
34  }
35  }
36 
38  {
39  if (thread_) thread_->join();
40  }
41 
43  {
44  try
45  {
46  doIt();
47  }
48  catch(xcept::Exception &e)
49  {
51  }
52  catch(std::exception &e)
53  {
54  XCEPT_DECLARE(exception::DQMArchival,
55  sentinelException, e.what());
56  stateMachine_->moveToFailedState(sentinelException);
57  }
58  catch(...)
59  {
60  std::string errorMsg = "Unknown exception in DQM archiving thread";
61  XCEPT_DECLARE(exception::DQMArchival,
62  sentinelException, errorMsg);
63  stateMachine_->moveToFailedState(sentinelException);
64  }
65  }
66 
68  {
69  stor::RegistrationCollectionPtr registrationCollection =
71  const stor::ConsumerID cid = regPtr_->consumerId();
72 
73  while ( registrationCollection->registrationIsAllowed(cid) )
74  {
76  dqmEventQueueCollection_->popEvent(cid);
77 
78  if ( dqmEvent.first.empty() )
79  ::sleep(1);
80  else
81  handleDQMEvent(dqmEvent.first);
82  }
83 
84  // run ended, write the last updates to file
85  BOOST_FOREACH(
86  const Records::value_type& pair,
88  )
89  {
90  writeDQMEventToFile(pair.second.getDQMEventMsgView(), true);
91  }
92  }
93 
95  {
96  const DQMEventMsgView view = record.getDQMEventMsgView();
97 
98  updateLastRecord(record);
99 
100  if (
103  )
104  {
105  writeDQMEventToFile(view, false);
106  }
107  }
108 
110  {
111  const DQMEventMsgView view = record.getDQMEventMsgView();
112  const std::string topFolderName = view.topFolderName();
113  Records::iterator pos = lastUpdateForFolders_.lower_bound(topFolderName);
114 
115  if (pos != lastUpdateForFolders_.end() &&
116  !(lastUpdateForFolders_.key_comp()(topFolderName, pos->first)))
117  {
118  // key already exists
119  pos->second = record;
120  }
121  else
122  {
123  lastUpdateForFolders_.insert(pos, Records::value_type(topFolderName, record));
124  }
125  }
126 
128  (
129  const DQMEventMsgView& view,
130  const bool endRun
131  ) const
132  {
133  edm::ParameterSet dqmStorePSet;
134  dqmStorePSet.addUntrackedParameter<bool>("collateHistograms", true);
135  DQMStore dqmStore(dqmStorePSet);
136 
137  std::ostringstream fileName;
138  fileName << dqmArchivingParams_.filePrefixDQM_
139  << "/DQM_R"
140  << std::setfill('0') << std::setw(9) << view.runNumber();
141  if ( ! endRun ) fileName << "_L" << std::setw(6) << view.lumiSection();
142  fileName << ".root";
143 
144  // don't require that the file exists
145  dqmStore.load(fileName.str(), DQMStore::StripRunDirs, false);
146 
147  edm::DQMHttpSource::addEventToDQMBackend(&dqmStore, view, false);
148 
149  dqmStore.save(fileName.str());
150 
152  stateMachine_->getStatisticsReporter()->getDQMEventMonitorCollection();
154  static_cast<double>(view.size()) / 0x100000
155  );
157  }
158 
160  {
161  edm::ParameterSet pset;
162  pset.addUntrackedParameter<std::string>("DQMconsumerName", "DQMArchiver");
163  pset.addUntrackedParameter<std::string>("topLevelFolderName",
165 
167  stateMachine_->getConfiguration()->getEventServingParams(),
168  "internal")
169  );
170 
171  stor::RegistrationCollectionPtr registrationCollection =
173 
174  const stor::ConsumerID cid = registrationCollection->getConsumerId();
175  regPtr_->setConsumerId(cid);
176 
177  const stor::QueueID qid = dqmEventQueueCollection_->createQueue(regPtr_);
178  regPtr_->setQueueId(qid);
179 
180  registrationCollection->addRegistrationInfo(regPtr_);
181  }
182 
183 } // namespace smproxy
184 
static void addEventToDQMBackend(DQMStore *, const DQMEventMsgView &, const bool overwrite)
void writeDQMEventToFile(const DQMEventMsgView &, const bool endRun) const
Definition: DQMArchiver.cc:128
DQMEventMsgView getDQMEventMsgView() const
stor::DQMEventQueueCollectionPtr dqmEventQueueCollection_
Definition: DQMArchiver.h:56
StateMachine * stateMachine_
Definition: DQMArchiver.h:54
unsigned int archiveIntervalDQM_
Definition: Configuration.h:52
JetCorrectorParameters::Record record
Definition: classes.h:11
void addSample(const double &value=1)
void moveToFailedState(xcept::Exception &e)
Definition: StateMachine.h:79
DQMArchiver(StateMachine *)
Definition: DQMArchiver.cc:23
void sleep(Duration_t)
Definition: Utils.h:163
uint32 updateNumber() const
const DQMArchivingParams dqmArchivingParams_
Definition: DQMArchiver.h:55
boost::shared_ptr< RegistrationCollection > RegistrationCollectionPtr
std::string topFolderName() const
void updateLastRecord(const stor::DQMTopLevelFolder::Record &)
Definition: DQMArchiver.cc:109
stor::DQMEventConsRegPtr regPtr_
Definition: DQMArchiver.h:57
ConfigurationPtr getConfiguration() const
Definition: StateMachine.h:93
void handleDQMEvent(const stor::DQMTopLevelFolder::Record &)
Definition: DQMArchiver.cc:94
Container::value_type value_type
void addUntrackedParameter(std::string const &name, T const &value)
Definition: ParameterSet.h:209
const MonitoredQuantity & getWrittenDQMEventSizeMQ() const
ExpirableQueue< T, RejectNewest< T > >::ValueType ValueType
uint32 lumiSection() const
std::string archiveTopLevelFolder_
Definition: Configuration.h:50
boost::scoped_ptr< boost::thread > thread_
Definition: DQMArchiver.h:59
const MonitoredQuantity & getNumberOfWrittenTopLevelFoldersMQ() const
uint32 size() const
Records lastUpdateForFolders_
Definition: DQMArchiver.h:62
uint32 runNumber() const
stor::RegistrationCollectionPtr getRegistrationCollection() const
Definition: StateMachine.h:97