![Logo](../../ATLAS-Logo-Square-Blue-RGB.png) |
ATLAS Offline Software
|
Go to the documentation of this file.
5 #ifndef ManagedMonitorToolBase_CXX
6 #define ManagedMonitorToolBase_CXX
20 #include "TEfficiency.h"
27 #include "Gaudi/Interfaces/IOptionsSvc.h"
28 #include "GaudiKernel/IHistogramSvc.h"
29 #include "GaudiKernel/IMessageSvc.h"
30 #include "GaudiKernel/ISvcLocator.h"
31 #include "GaudiKernel/MsgStream.h"
35 #include "GaudiKernel/ITHistSvc.h"
91 m_bench_book.finishMeasurement();
92 m_bench_total += m_bench_book;
93 m_benchNFillAfterbook = 0;
102 m_bench_tmp.startMeasurement();
108 if (!m_doResourceMon)
110 m_bench_tmp.finishMeasurement();
111 m_bench_total += m_bench_tmp;
112 ++m_benchNFillAfterbook;
113 if (m_benchNFillAfterbook==1) {
114 m_bench_fillfirst = m_bench_tmp;
116 m_bench_fillall += m_bench_tmp;
117 m_bench_filllast = m_bench_tmp;
124 if (!m_doResourceMon)
126 m_bench_proc.startMeasurement();
132 if (!m_doResourceMon)
134 m_bench_proc.finishMeasurement();
135 m_bench_total += m_bench_proc;
136 m_bench_fillall -= m_bench_filllast;
137 m_benchNFillAfterbook = 0;
145 if (!m_doResourceMon)
147 m_benchNFillAfterbook = 0;
149 m_bench_book.reset();
150 m_bench_fillfirst.reset();
151 m_bench_fillall.reset();
152 m_bench_filllast.reset();
153 m_bench_proc.reset();
154 m_bench_total.reset();
161 if (!m_doResourceMon)
169 m_bench_total.setUnitCount();
182 std::string strToLower(
const std::string&
str );
186 static std::atomic<unsigned> s_mmtb_mongroup_ncopies=0;
198 std::string hName(
h->GetName() );
199 HistMap_t::value_type valToInsert( hName,
h );
200 m_map.insert( valToInsert );
201 return m_tool->regHist(
h, *
this );
204 return StatusCode::FAILURE;
212 return m_tool->getHist(
h, hName, *
this );
215 return StatusCode::FAILURE;
225 std::string hName(
h->GetName() );
226 HistMapLW_t::value_type valToInsert( hName,
h );
227 m_mapLW.insert( valToInsert );
228 return m_tool->regHist(
h, *
this );
231 return StatusCode::FAILURE;
239 return m_tool->getHist(
h, hName, *
this );
241 return StatusCode::FAILURE;
250 return m_tool->getHist(
h, hName, *
this );
253 return StatusCode::FAILURE;
259 return m_tool->regEfficiency(
e, *
this );
261 return StatusCode::FAILURE;
270 return m_tool->regGraph(
g, *
this );
273 return StatusCode::FAILURE;
282 return m_tool->regTree(
t, *
this );
285 return StatusCode::FAILURE;
294 std::string hName(
h->GetName() );
295 m_map.erase( hName );
296 return m_tool->writeAndDelete(
h, *
this );
299 return StatusCode::FAILURE;
308 std::string hName(
h->GetName() );
309 m_map.erase( hName );
310 return m_tool->deregHist(
h );
313 return StatusCode::FAILURE;
320 std::string hName(
h->GetName() );
321 m_mapLW.erase( hName );
322 return m_tool->deregHist(
h );
325 return StatusCode::FAILURE;
334 return m_tool->deregGraph(
g );
337 return StatusCode::FAILURE;
346 return m_tool->deregObject( objName, *
this );
349 return StatusCode::FAILURE;
358 bool isSuccess(
true);
361 typedef HistMap_t::const_iterator MapIter_t;
362 MapIter_t mapEnd = m_map.end();
363 for( MapIter_t
i = m_map.begin();
i != mapEnd; ++
i ) {
364 sc = m_tool->deregHist(
i->second );
365 if( !
sc.isSuccess() )
369 typedef HistMapLW_t::const_iterator MapIterLW_t;
370 MapIterLW_t mapEndLW = m_mapLW.end();
371 for( MapIterLW_t
i = m_mapLW.begin();
i != mapEndLW; ++
i ) {
372 sc = m_tool->deregHist(
i->second );
373 if( !
sc.isSuccess() )
381 return StatusCode::SUCCESS;
384 return StatusCode::FAILURE;
390 const IInterface*
parent )
423 declareInterface<IMonitorToolBase>(
this);
460 newLowStatInterval =
false;
461 newMedStatInterval =
false;
462 newHigStatInterval =
false;
464 newLumiBlock =
false;
466 newEventsBlock =
false;
467 endOfEventsBlock =
false;
468 endOfLowStat =
false;
469 endOfLumiBlock =
false;
506 msg(MSG::ERROR) <<
"!! streamNameFunction() has not been initialized !!" <<
endmsg;
507 msg(MSG::ERROR) <<
" --> neither ManagedMonitorToolBase::initialize() nor" <<
endmsg;
508 msg(MSG::ERROR) <<
" --> ManagedMonitorToolBase::setMonManager() has been called." <<
endmsg;
509 msg(MSG::ERROR) <<
" --> Correct configuration cannot be guaranteed from this point." <<
endmsg;
590 std::string
str(
"file");
632 std::string lcstr( strToLower(
str) );
636 else if( lcstr ==
"fill" )
638 else if( lcstr ==
"run" )
640 else if( lcstr ==
"lowStat" )
642 else if( lcstr ==
"medStat" )
644 else if( lcstr ==
"higStat" )
646 else if( lcstr ==
"lumiBlock" )
648 else if( lcstr ==
"eventsBlock" )
650 else if( lcstr ==
"file" )
656 if(
sc.isSuccess() ) {
657 MsgStream
log(
ms,
"ManagedMonitorToolBase::intervalStringToEnum()" );
658 log << MSG::WARNING <<
"Unknown ManagedMonitorToolBase::Interval_t \""
659 <<
str <<
"\", returning \"file\"" <<
endmsg;
674 if( !
sc.isSuccess() )
675 return StatusCode::FAILURE;
682 if( !
sc.isSuccess() ) {
683 msg(MSG::ERROR) <<
"!! Unable to locate the THistSvc service !!" <<
endmsg;
690 if( !
sc.isSuccess() ) {
691 msg(MSG::ERROR) <<
"!! Unable to retrieve the TrigDecisionTool !!" <<
endmsg;
698 if ( !
sc.isSuccess() ) {
707 if(!
sc.isSuccess()) {
708 msg(MSG::WARNING) <<
"Error parsing the trigger chain list, using empty list" <<
endmsg;
721 if(!
sc.isSuccess()) {
722 msg(MSG::WARNING) <<
"Error parsing the trigger group names list, using empty list" <<
endmsg;
738 if( !
sc.isSuccess() ) {
750 auto getProp = [
this,joSvc](std::string&
var,
const std::string&
name) {
751 if (joSvc->has(
name))
777 return StatusCode::SUCCESS;
787 return StatusCode::SUCCESS;
798 msg(MSG::WARNING) <<
"ManagedMonitorToolBase::initialize() never called from reimplementation!" <<
endmsg;
809 newLumiBlock =
false;
815 newLowStatInterval =
false;
816 newMedStatInterval =
false;
817 newHigStatInterval =
false;
830 isNewEventsBlock =
true;
845 if( LBsLowStat*LBsMedStat*LBsHigStat == 0) {
846 msg(MSG::WARNING) <<
"zero LBs requested for interval" <<
endmsg;
898 std::vector<Interval_t> intervals_to_process;
903 for (
const auto interval: intervals_to_process) {
916 it.m_templateHist->LabelsInflate(
"X");
923 TH1* passedHist =
it.m_templateHist->GetCopyPassedHisto();
924 TH1* totalHist =
it.m_templateHist->GetCopyTotalHisto();
927 passedHist->LabelsInflate(
"X");
928 totalHist->LabelsInflate(
"X");
933 it.m_templateHist->SetPassedHistogram(*passedHist,
"f");
934 it.m_templateHist->SetTotalHistogram(*totalHist,
" ");
942 streamname->updateRunLB();
958 bool filterresult(
true);
961 for (; filterresult && (ifilter != filterend);
963 filterresult = (filterresult && (*ifilter)->accept());
993 if( LBsLowStat*LBsMedStat*LBsHigStat > 0) {
1001 return StatusCode::SUCCESS;
1011 size_t found=mdStreamName.rfind(
'/');
1013 if (
found != std::string::npos )
1014 mdStreamName.replace(
found, mdStreamName.length(),
"/metadata" );
1018 metadata =
new TTree(
"metadata",
"Monitoring Metadata" );
1019 if (!
metadata)
return StatusCode::FAILURE;
1021 if (scmd == StatusCode::FAILURE)
return StatusCode::FAILURE;
1028 return StatusCode::SUCCESS;
1047 bool allIsOk =
true;
1053 TH1* theHist = (*it).m_templateHist;
1056 TH1*
h =
static_cast<TH1*
>(theHist->Clone());
1060 std::string hName =
h->GetName();
1067 if (sc1 == StatusCode::FAILURE) allIsOk =
false;
1071 if (sc2 == StatusCode::FAILURE) allIsOk =
false;
1083 if (
smd != StatusCode::SUCCESS) allIsOk =
false;
1087 if (sc3 == StatusCode::FAILURE) allIsOk =
false;
1091 if (!allIsOk)
return StatusCode::FAILURE;
1093 return StatusCode::SUCCESS;
1110 bool graphRemoved =
false;
1113 TDirectory*
dir =
file->GetDirectory(directoryName.c_str());
1116 TObject*
obj =
dir->Remove(theGraph);
1118 graphRemoved =
true;
1121 if (!graphRemoved) {
1122 return StatusCode::FAILURE;
1125 return StatusCode::SUCCESS;
1133 bool allIsOk =
true;
1139 TGraph* theGraph = (*it).m_templateHist;
1142 TGraph*
g =
static_cast<TGraph*
>(theGraph->Clone());
1146 std::string gName =
g->GetName();
1153 if (sc1 == StatusCode::FAILURE)
1158 bool doneCleaning =
false;
1160 TSeqCollection *
filelist=gROOT->GetListOfFiles();
1165 if (sc2 == StatusCode::SUCCESS)
1166 doneCleaning =
true;
1170 if (!doneCleaning) {
1171 ATH_MSG_ERROR(
"THistSvc_deReg_fixTGraph: failed to apply TGraph fix for the THist Svc!");
1178 if (sc3 == StatusCode::FAILURE)
1185 if (
smd != StatusCode::SUCCESS)
1190 if (sc4 == StatusCode::FAILURE)
1195 if (!allIsOk)
return StatusCode::FAILURE;
1197 return StatusCode::SUCCESS;
1201 bool allIsOk =
true;
1202 for(
auto&
it : templateEfficiencies ) {
1205 TEfficiency* theEfficiency =
it.m_templateHist;
1206 TEfficiency*
e =
static_cast<TEfficiency*
>(theEfficiency->Clone());
1207 int nbins = theEfficiency->GetTotalHistogram()->GetNbinsX();
1208 int xlow = theEfficiency->GetTotalHistogram()->GetXaxis()->GetXmin();
1209 int xhigh = theEfficiency->GetTotalHistogram()->GetXaxis()->GetXmax();
1210 e->SetBins(
nbins,xlow,xhigh);
1211 std::string
name =
e->GetName();
1214 TGraph* theGraph =
reinterpret_cast<TGraph*
>(theEfficiency);
1215 TGraph*
g =
reinterpret_cast<TGraph*
>(
e);
1223 if (sc1 == StatusCode::FAILURE) allIsOk =
false;
1225 bool doneCleaning =
false;
1227 TSeqCollection *
filelist=gROOT->GetListOfFiles();
1232 if (sc2 == StatusCode::SUCCESS) doneCleaning =
true;
1235 if (!doneCleaning) {
1236 ATH_MSG_ERROR(
"THistSvc_deReg_fixTGraph: failed to apply TGraph fix for the THist Svc!");
1241 if (sc3 == StatusCode::FAILURE)
1248 if (
smd != StatusCode::SUCCESS) allIsOk =
false;
1251 if (sc4 == StatusCode::FAILURE) allIsOk =
false;
1254 if (!allIsOk)
return StatusCode::FAILURE;
1255 return StatusCode::SUCCESS;
1264 bool allIsOk =
true;
1270 TTree* theTree = (*it).m_templateHist;
1273 TTree*
t =
static_cast<TTree*
>(theTree->Clone());
1277 std::string
name =
t->GetName();
1284 if (sc1 == StatusCode::FAILURE) allIsOk =
false;
1288 if (sc2 == StatusCode::FAILURE) allIsOk =
false;
1300 if (
smd != StatusCode::SUCCESS) allIsOk =
false;
1304 if (sc3 == StatusCode::FAILURE) allIsOk =
false;
1308 if (!allIsOk)
return StatusCode::FAILURE;
1310 return StatusCode::SUCCESS;
1324 LWHist*
h = (*it).m_templateHist;
1348 endOfEventsBlock =
true;
1349 endOfLowStat =
true;
1350 endOfLumiBlock =
true;
1372 return StatusCode::SUCCESS;
1388 return StatusCode::SUCCESS;
1401 return StatusCode::SUCCESS;
1410 return StatusCode::SUCCESS;
1417 return StatusCode::SUCCESS;
1430 return StatusCode::SUCCESS;
1468 return StatusCode::FAILURE;
1481 ATH_MSG_WARNING(
"HEY! You're attempting to register " <<
h->GetName() <<
" as a per-LB histogram, but you're not setting the merge algorithm! This is a SUPER-BAD idea! Use \"merge\", at least.");
1488 return StatusCode::FAILURE;
1491 std::string hName =
h->GetName();
1499 std::string hName =
h->GetName();
1510 if (
smd != StatusCode::SUCCESS)
return StatusCode::FAILURE;
1528 return StatusCode::FAILURE;
1540 return StatusCode::FAILURE;
1547 std::string hName =
h->GetName();
1577 if (
h->usingROOTBackend())
1579 h->setOwnsROOTHisto(
false);
1583 return StatusCode::SUCCESS;
1589 getHist(
TH1*&
h,
const std::string& hName,
const std::string& system,
1622 return StatusCode::SUCCESS;
1625 return StatusCode::FAILURE;
1631 getHist(
TH2*&
h,
const std::string& hName,
const std::string& system,
1650 return StatusCode::FAILURE;
1652 TGraph*
g =
reinterpret_cast<TGraph*
>(
e);
1653 std::string
name =
e->GetName();
1659 ATH_MSG_WARNING(
"HEY! Attempting to register "<<
name<<
" as a per-LB histogram, but not setting the merge algorithm! Use \"merge\", at least.");
1666 return StatusCode::FAILURE;
1683 if (
smd != StatusCode::SUCCESS)
1684 return StatusCode::FAILURE;
1693 regGraph( TGraph*
g,
const std::string& system,
1706 return StatusCode::FAILURE;
1719 return StatusCode::FAILURE;
1722 std::string
name =
g->GetName();
1730 std::string gName =
g->GetName();
1741 if (
smd != StatusCode::SUCCESS)
return StatusCode::FAILURE;
1749 regTree( TTree*
t,
const std::string& system,
1773 return StatusCode::FAILURE;
1776 std::string
name =
t->GetName();
1785 std::string tName =
t->GetName();
1796 if (
smd != StatusCode::SUCCESS)
return StatusCode::FAILURE;
1806 return StatusCode::FAILURE;
1808 std::string hName =
h->GetName();
1814 return StatusCode::SUCCESS;
1830 return StatusCode::FAILURE;
1833 if (
h->usingROOTBackend()) {
1834 h->setOwnsROOTHisto(
true);
1838 return StatusCode::SUCCESS;
1852 deregObject(
const std::string& objName,
const std::string& system,
1874 return StatusCode::SUCCESS;
1888 return StatusCode::SUCCESS;
1896 return StatusCode::SUCCESS;
1906 return StatusCode::SUCCESS;
1928 return lumi->lbAverageInteractionsPerCrossing();
1931 ATH_MSG_DEBUG(
"Warning: lbAverageInteractionsPerCrossing() - luminosity tools are not retrieved or turned on (i.e. EnableLumi = False)");
1944 float muToLumi =
lumi->muToLumi();
1946 return lumi->lbLuminosityPerBCIDVector().at (ctx.eventID().bunch_crossing_id()) / muToLumi;
1951 ATH_MSG_DEBUG(
"Warning: lbInteractionsPerCrossing() - luminosity tools are not retrieved or turned on (i.e. EnableLumi = False)");
1964 return lumi->lbAverageLuminosity();
1967 ATH_MSG_DEBUG(
"Warning: lbAverageLuminosity() - luminosity tools are not retrieved or turned on (i.e. EnableLumi = False)");
1980 return lumi->lbLuminosityPerBCIDVector().at (ctx.eventID().bunch_crossing_id());
1983 ATH_MSG_DEBUG(
"Warning: lbLuminosityPerBCID() - luminosity tools are not retrieved or turned on (i.e. EnableLumi = False)");
2003 ATH_MSG_DEBUG(
"Warning: lbAverageLivefraction() - luminosity not availble (i.e. EnableLumi = False)");
2022 ATH_MSG_DEBUG(
"Warning: livefractionPerBCID() - luminosity retrieved available (i.e. EnableLumi = False)");
2037 ATH_MSG_DEBUG(
"Warning: lbLumiWeight() - luminosity tools are not retrieved or turned on (i.e. EnableLumi = False)");
2057 ATH_MSG_DEBUG(
"Warning: lbDuration() - luminosity tools are not retrieved or turned on (i.e. EnableLumi = False)");
2070 : m_charArrSize(100)
2094 delete [] m_mergeData;
2095 delete [] m_triggerData;
2096 delete [] m_intervalData;
2098 delete [] m_nameData;
2117 merge =
"<default>";
2119 copyString( m_nameData,
name );
2122 copyString( m_triggerData,
trigger );
2123 copyString( m_mergeData,
merge );
2133 const char*
f = from.c_str();
2134 while( (++
i < m_charArrSize) && ((*
to++ = *
f++) != 0) ) {};
2135 if(
i == m_charArrSize ) {
2158 std::string
root, rem;
2162 rem.erase(rem.rfind(
'/'), rem.length());
2181 return getStreamName(
tool,
group, objName, usePreviousInterval);
2203 return getStreamName(
tool,
group, objName, usePreviousInterval);
2222 bool isTemp =
false;
2224 bool useRunFolders =
group.interval() !=
all;
2226 bool useLBFolders = ( useRunFolders )
2229 bool useLowStatInterval = ( useRunFolders )
2232 bool useMedStatInterval = ( useRunFolders )
2235 bool useHigStatInterval = ( useRunFolders )
2244 if( useRunFolders ) {
2246 streamName <<
"run_" << m_prev_run_number <<
"/";
2252 if( useLBFolders ) {
2254 streamName <<
"lb_" << m_prev_lumi_block <<
"/";
2258 else if( useLowStatInterval ) {
2266 else if( useMedStatInterval ) {
2271 else if( useHigStatInterval ) {
2276 else if( useEBFolders ) {
2281 long eventsBlockNumber = 1;
2282 long procNEventsProp =
tool->get_procNEventsProp();
2284 if (procNEventsProp > 0) {
2285 eventsBlockNumber = (long)
nEvents / procNEventsProp;
2286 if ((
nEvents % procNEventsProp) != 0)
2287 eventsBlockNumber++;
2291 if (usePreviousInterval) {
2292 eventsBlockNumber--;
2295 streamName <<
"eb_" << eventsBlockNumber <<
"/";
2308 std::string
root, rem;
2312 rem.erase(rem.rfind(
'/'), rem.length());
2327 ATH_MSG_DEBUG(
"ManagedMonitorToolBase::trigChainsArePassed:");
2329 for(
unsigned int i=0;
i<vTrigNames.size();
i++) {
2331 ATH_MSG_DEBUG(
" + \"" << vTrigNames[
i] <<
"\" passed, returning \'true\'");
2346 std::stringstream
ss(
line);
2350 while ( std::getline(
ss,
item,
',') ) {
2351 std::stringstream iss(
item);
2358 return StatusCode::SUCCESS;
2364 for (
size_t i = 0;
i < vTrigChainNames.size(); ++
i) {
2365 std::string& thisName = vTrigChainNames[
i];
2366 if (thisName.compare(0, 9,
"CATEGORY_") ==0) {
2367 ATH_MSG_DEBUG(
"Found a trigger category: " << thisName <<
". We will unpack it.");
2369 std::ostringstream oss;
2371 for (
size_t itrig = 0; itrig <
triggers.size(); ++itrig) {
2379 std::string newval = oss.str();
2381 vTrigChainNames[
i] = newval;
2419 if (
pos == std::string::npos) {
2456 std::string strToLower(
const std::string&
str )
2458 std::string lstr(
str);
2459 std::string::const_iterator from =
str.begin();
2460 std::string::const_iterator strend =
str.end();
2462 while( from != strend ) {
2470 std::string strToUpper(
const std::string&
str )
2472 std::string ustr(
str);
2473 std::string::const_iterator from =
str.begin();
2474 std::string::const_iterator strend =
str.end();
2476 while( from != strend ) {
2477 *
to++ = toupper(*from++);
virtual LWHist * ownedLWHistOfKey(const std::string &key) const
JetConstituentVector::iterator iterator
virtual LWHist * writeAndDeleteLWHist(const std::string &key, const std::string &streamName)
Gaudi::Details::PropertyBase & declareProperty(Gaudi::Property< T > &t)
virtual LWHist * writeAndResetLWHist(const std::string &key, const std::string &streamName)
static unsigned int runNumber()
virtual std::string fileKey() const
virtual void passOwnership(TObject *h, const std::string &key)
Pass ownership of a TObject/LWHist to this manager so that it will be deleted appropriately.
static Environment_t envStringToEnum(const std::string &str)
Converts a string to an Environment_t of the same name.
bool msgLvl(const MSG::Level lvl) const
static void setStreamName(LWHist *, const std::string &streamName)
bool empty() const
Test if the key is blank.
static unsigned int getLBsLowStat()
float lbAverageLiveFraction(bool highPriority=true) const
Luminosity-averaged live fraction over all physics BCIDs.
static Environment_t environment()
Returns the running environment of the monitoring application to help ManagedMonitorToolBase objects ...
static const std::string & streamName(LWHist *)
static unsigned int getLBsMedStat()
bool usingROOTBackend() const
static void removeCustomData(LWHist *)
static DataType_t dataType()
Returns the data type that the monitoring application is running over to help ManagedMonitorToolBase ...
An Algorithm that manages a set of modules, each inheriting from ManagedMonitorToolBase,...
static const std::string & key(LWHist *)
static DataType_t dataTypeStringToEnum(const std::string &str)
Converts a string to a DataType_t of the same name.
::StatusCode StatusCode
StatusCode definition for legacy code.
void tolower(std::string &s)
virtual void writeAndDelete(const std::string &key)
If the TObject is owned by this manager, its Write() method is called and it is deleted.
void fcn(int &, double *, double &result, double par[], int)
this is where we write out chi2
const std::vector< float > & l1LiveFractionVector(bool highPriority=true) const
Return vector with all BCIDs indexed by BCID number.
double lbDuration() const
static const MSG::Level s_resourceMonThreshold
static unsigned int getLBsHigStat()
static void setKey(LWHist *, const std::string &key)
StatusCode initialize(bool used=true)
void setOwnsROOTHisto(bool b)
#define ATH_MSG_WARNING(x)
filelist
print ("Checking files %s..." % fullfile)
static unsigned int lumiBlockNumber()
virtual TH1 * getROOTHistBase()=0