 |
ATLAS Offline Software
|
Go to the documentation of this file.
5 #ifndef ManagedMonitorToolBase_CXX
6 #define ManagedMonitorToolBase_CXX
20 #include "TEfficiency.h"
24 #include "Gaudi/Interfaces/IOptionsSvc.h"
25 #include "GaudiKernel/IHistogramSvc.h"
26 #include "GaudiKernel/IMessageSvc.h"
27 #include "GaudiKernel/ISvcLocator.h"
28 #include "GaudiKernel/MsgStream.h"
32 #include "GaudiKernel/ITHistSvc.h"
88 m_bench_book.finishMeasurement();
89 m_bench_total += m_bench_book;
90 m_benchNFillAfterbook = 0;
99 m_bench_tmp.startMeasurement();
105 if (!m_doResourceMon)
107 m_bench_tmp.finishMeasurement();
108 m_bench_total += m_bench_tmp;
109 ++m_benchNFillAfterbook;
110 if (m_benchNFillAfterbook==1) {
111 m_bench_fillfirst = m_bench_tmp;
113 m_bench_fillall += m_bench_tmp;
114 m_bench_filllast = m_bench_tmp;
121 if (!m_doResourceMon)
123 m_bench_proc.startMeasurement();
129 if (!m_doResourceMon)
131 m_bench_proc.finishMeasurement();
132 m_bench_total += m_bench_proc;
133 m_bench_fillall -= m_bench_filllast;
134 m_benchNFillAfterbook = 0;
142 if (!m_doResourceMon)
144 m_benchNFillAfterbook = 0;
146 m_bench_book.reset();
147 m_bench_fillfirst.reset();
148 m_bench_fillall.reset();
149 m_bench_filllast.reset();
150 m_bench_proc.reset();
151 m_bench_total.reset();
158 if (!m_doResourceMon)
166 m_bench_total.setUnitCount();
179 std::string strToLower(
const std::string&
str );
183 static std::atomic<unsigned> s_mmtb_mongroup_ncopies=0;
195 std::string hName(
h->GetName() );
196 m_map.emplace( hName,
h );
197 return m_tool->regHist(
h, *
this );
200 return StatusCode::FAILURE;
205 getHist( TH1*&
h,
const std::string& hName )
208 return m_tool->getHist(
h, hName, *
this );
211 return StatusCode::FAILURE;
217 getHist( TH2*&
h,
const std::string& hName )
220 return m_tool->getHist(
h, hName, *
this );
223 return StatusCode::FAILURE;
229 return m_tool->regEfficiency(
e, *
this );
231 return StatusCode::FAILURE;
240 return m_tool->regGraph(
g, *
this );
243 return StatusCode::FAILURE;
252 return m_tool->regTree(
t, *
this );
255 return StatusCode::FAILURE;
264 std::string hName(
h->GetName() );
265 m_map.erase( hName );
266 return m_tool->writeAndDelete(
h, *
this );
269 return StatusCode::FAILURE;
278 std::string hName(
h->GetName() );
279 m_map.erase( hName );
280 return m_tool->deregHist(
h );
283 return StatusCode::FAILURE;
292 return m_tool->deregGraph(
g );
295 return StatusCode::FAILURE;
304 return m_tool->deregObject( objName, *
this );
307 return StatusCode::FAILURE;
316 bool isSuccess(
true);
319 typedef HistMap_t::const_iterator MapIter_t;
320 MapIter_t mapEnd = m_map.end();
321 for( MapIter_t
i = m_map.begin();
i != mapEnd; ++
i ) {
322 sc = m_tool->deregHist(
i->second );
323 if( !
sc.isSuccess() )
330 return StatusCode::SUCCESS;
333 return StatusCode::FAILURE;
339 const IInterface*
parent )
372 declareInterface<IMonitorToolBase>(
this);
408 newLowStatInterval =
false;
409 newMedStatInterval =
false;
410 newHigStatInterval =
false;
412 newLumiBlock =
false;
414 newEventsBlock =
false;
415 endOfEventsBlock =
false;
416 endOfLowStat =
false;
417 endOfLumiBlock =
false;
454 msg(MSG::ERROR) <<
"!! streamNameFunction() has not been initialized !!" <<
endmsg;
455 msg(MSG::ERROR) <<
" --> neither ManagedMonitorToolBase::initialize() nor" <<
endmsg;
456 msg(MSG::ERROR) <<
" --> ManagedMonitorToolBase::setMonManager() has been called." <<
endmsg;
457 msg(MSG::ERROR) <<
" --> Correct configuration cannot be guaranteed from this point." <<
endmsg;
538 std::string
str(
"file");
580 std::string lcstr( strToLower(
str) );
584 else if( lcstr ==
"fill" )
586 else if( lcstr ==
"run" )
588 else if( lcstr ==
"lowStat" )
590 else if( lcstr ==
"medStat" )
592 else if( lcstr ==
"higStat" )
594 else if( lcstr ==
"lumiBlock" )
596 else if( lcstr ==
"eventsBlock" )
598 else if( lcstr ==
"file" )
604 MsgStream
log(
ms,
"ManagedMonitorToolBase::intervalStringToEnum()" );
605 log << MSG::WARNING <<
"Unknown ManagedMonitorToolBase::Interval_t \""
606 <<
str <<
"\", returning \"file\"" <<
endmsg;
621 if( !
sc.isSuccess() )
622 return StatusCode::FAILURE;
629 if( !
sc.isSuccess() ) {
630 msg(MSG::ERROR) <<
"!! Unable to locate the THistSvc service !!" <<
endmsg;
637 if( !
sc.isSuccess() ) {
638 msg(MSG::ERROR) <<
"!! Unable to retrieve the TrigDecisionTool !!" <<
endmsg;
645 if ( !
sc.isSuccess() ) {
654 if(!
sc.isSuccess()) {
655 msg(MSG::WARNING) <<
"Error parsing the trigger chain list, using empty list" <<
endmsg;
668 if(!
sc.isSuccess()) {
669 msg(MSG::WARNING) <<
"Error parsing the trigger group names list, using empty list" <<
endmsg;
685 if( !
sc.isSuccess() ) {
697 auto getProp = [
this,&joSvc](std::string&
var,
const std::string&
name) {
698 if (joSvc->has(
name))
724 return StatusCode::SUCCESS;
734 return StatusCode::SUCCESS;
745 msg(MSG::WARNING) <<
"ManagedMonitorToolBase::initialize() never called from reimplementation!" <<
endmsg;
756 newLumiBlock =
false;
762 newLowStatInterval =
false;
763 newMedStatInterval =
false;
764 newHigStatInterval =
false;
777 isNewEventsBlock =
true;
792 if( LBsLowStat*LBsMedStat*LBsHigStat == 0) {
793 msg(MSG::WARNING) <<
"zero LBs requested for interval" <<
endmsg;
845 std::vector<Interval_t> intervals_to_process;
850 for (
const auto interval: intervals_to_process) {
862 it.m_templateHist->LabelsInflate(
"X");
869 TH1* passedHist =
it.m_templateHist->GetCopyPassedHisto();
870 TH1* totalHist =
it.m_templateHist->GetCopyTotalHisto();
873 passedHist->LabelsInflate(
"X");
874 totalHist->LabelsInflate(
"X");
879 it.m_templateHist->SetPassedHistogram(*passedHist,
"f");
880 it.m_templateHist->SetTotalHistogram(*totalHist,
" ");
888 streamname->updateRunLB();
898 bool filterresult(
true);
901 for (; filterresult && (ifilter != filterend);
903 filterresult = (filterresult && (*ifilter)->accept());
933 if( LBsLowStat*LBsMedStat*LBsHigStat > 0) {
941 return StatusCode::SUCCESS;
951 size_t found=mdStreamName.rfind(
'/');
953 if (
found != std::string::npos )
954 mdStreamName.replace(
found, mdStreamName.length(),
"/metadata" );
958 metadata =
new TTree(
"metadata",
"Monitoring Metadata" );
959 if (!
metadata)
return StatusCode::FAILURE;
961 if (scmd == StatusCode::FAILURE)
return StatusCode::FAILURE;
967 return StatusCode::SUCCESS;
992 TH1* theHist = (*it).m_templateHist;
995 TH1*
h =
static_cast<TH1*
>(theHist->Clone());
999 std::string hName =
h->GetName();
1006 if (sc1 == StatusCode::FAILURE) allIsOk =
false;
1010 if (sc2 == StatusCode::FAILURE) allIsOk =
false;
1022 if (
smd != StatusCode::SUCCESS) allIsOk =
false;
1026 if (sc3 == StatusCode::FAILURE) allIsOk =
false;
1030 if (!allIsOk)
return StatusCode::FAILURE;
1032 return StatusCode::SUCCESS;
1049 bool graphRemoved =
false;
1052 TDirectory*
dir =
file->GetDirectory(directoryName.c_str());
1055 TObject*
obj =
dir->Remove(theGraph);
1057 graphRemoved =
true;
1060 if (!graphRemoved) {
1061 return StatusCode::FAILURE;
1064 return StatusCode::SUCCESS;
1072 bool allIsOk =
true;
1078 TGraph* theGraph = (*it).m_templateHist;
1081 TGraph*
g =
static_cast<TGraph*
>(theGraph->Clone());
1085 std::string gName =
g->GetName();
1092 if (sc1 == StatusCode::FAILURE)
1097 bool doneCleaning =
false;
1099 TSeqCollection *
filelist=gROOT->GetListOfFiles();
1104 if (sc2 == StatusCode::SUCCESS)
1105 doneCleaning =
true;
1109 if (!doneCleaning) {
1110 ATH_MSG_ERROR(
"THistSvc_deReg_fixTGraph: failed to apply TGraph fix for the THist Svc!");
1117 if (sc3 == StatusCode::FAILURE)
1124 if (
smd != StatusCode::SUCCESS)
1129 if (sc4 == StatusCode::FAILURE)
1134 if (!allIsOk)
return StatusCode::FAILURE;
1136 return StatusCode::SUCCESS;
1140 bool allIsOk =
true;
1141 for(
auto&
it : templateEfficiencies ) {
1144 TEfficiency* theEfficiency =
it.m_templateHist;
1145 TEfficiency*
e =
static_cast<TEfficiency*
>(theEfficiency->Clone());
1146 int nbins = theEfficiency->GetTotalHistogram()->GetNbinsX();
1147 int xlow = theEfficiency->GetTotalHistogram()->GetXaxis()->GetXmin();
1148 int xhigh = theEfficiency->GetTotalHistogram()->GetXaxis()->GetXmax();
1149 e->SetBins(
nbins,xlow,xhigh);
1150 std::string
name =
e->GetName();
1153 TGraph* theGraph =
reinterpret_cast<TGraph*
>(theEfficiency);
1154 TGraph*
g =
reinterpret_cast<TGraph*
>(
e);
1162 if (sc1 == StatusCode::FAILURE) allIsOk =
false;
1164 bool doneCleaning =
false;
1166 TSeqCollection *
filelist=gROOT->GetListOfFiles();
1171 if (sc2 == StatusCode::SUCCESS) doneCleaning =
true;
1174 if (!doneCleaning) {
1175 ATH_MSG_ERROR(
"THistSvc_deReg_fixTGraph: failed to apply TGraph fix for the THist Svc!");
1180 if (sc3 == StatusCode::FAILURE)
1187 if (
smd != StatusCode::SUCCESS) allIsOk =
false;
1190 if (sc4 == StatusCode::FAILURE) allIsOk =
false;
1193 if (!allIsOk)
return StatusCode::FAILURE;
1194 return StatusCode::SUCCESS;
1203 bool allIsOk =
true;
1209 TTree* theTree = (*it).m_templateHist;
1212 TTree*
t =
static_cast<TTree*
>(theTree->Clone());
1216 std::string
name =
t->GetName();
1223 if (sc1 == StatusCode::FAILURE) allIsOk =
false;
1227 if (sc2 == StatusCode::FAILURE) allIsOk =
false;
1239 if (
smd != StatusCode::SUCCESS) allIsOk =
false;
1243 if (sc3 == StatusCode::FAILURE) allIsOk =
false;
1247 if (!allIsOk)
return StatusCode::FAILURE;
1249 return StatusCode::SUCCESS;
1269 endOfEventsBlock =
true;
1270 endOfLowStat =
true;
1271 endOfLumiBlock =
true;
1279 return StatusCode::SUCCESS;
1291 return StatusCode::SUCCESS;
1300 return StatusCode::SUCCESS;
1307 return StatusCode::SUCCESS;
1320 return StatusCode::SUCCESS;
1344 regHist( TH1*
h,
const std::string& system,
1358 return StatusCode::FAILURE;
1371 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.");
1378 return StatusCode::FAILURE;
1381 std::string hName =
h->GetName();
1389 std::string hName =
h->GetName();
1400 if (
smd != StatusCode::SUCCESS)
return StatusCode::FAILURE;
1408 getHist( TH1*&
h,
const std::string& hName,
const std::string& system,
1427 getHist( TH2*&
h,
const std::string& hName,
const std::string& system,
1446 return StatusCode::FAILURE;
1448 TGraph*
g =
reinterpret_cast<TGraph*
>(
e);
1449 std::string
name =
e->GetName();
1455 ATH_MSG_WARNING(
"HEY! Attempting to register "<<
name<<
" as a per-LB histogram, but not setting the merge algorithm! Use \"merge\", at least.");
1462 return StatusCode::FAILURE;
1479 if (
smd != StatusCode::SUCCESS)
1480 return StatusCode::FAILURE;
1489 regGraph( TGraph*
g,
const std::string& system,
1502 return StatusCode::FAILURE;
1515 return StatusCode::FAILURE;
1518 std::string
name =
g->GetName();
1526 std::string gName =
g->GetName();
1537 if (
smd != StatusCode::SUCCESS)
return StatusCode::FAILURE;
1545 regTree( TTree*
t,
const std::string& system,
1569 return StatusCode::FAILURE;
1572 std::string
name =
t->GetName();
1581 std::string tName =
t->GetName();
1592 if (
smd != StatusCode::SUCCESS)
return StatusCode::FAILURE;
1602 return StatusCode::FAILURE;
1604 std::string hName =
h->GetName();
1610 return StatusCode::SUCCESS;
1632 deregObject(
const std::string& objName,
const std::string& system,
1656 return StatusCode::SUCCESS;
1664 return StatusCode::SUCCESS;
1674 return StatusCode::SUCCESS;
1696 return lumi->lbAverageInteractionsPerCrossing();
1699 ATH_MSG_DEBUG(
"Warning: lbAverageInteractionsPerCrossing() - luminosity tools are not retrieved or turned on (i.e. EnableLumi = False)");
1712 float muToLumi =
lumi->muToLumi();
1714 return lumi->lbLuminosityPerBCIDVector().at (ctx.eventID().bunch_crossing_id()) / muToLumi;
1719 ATH_MSG_DEBUG(
"Warning: lbInteractionsPerCrossing() - luminosity tools are not retrieved or turned on (i.e. EnableLumi = False)");
1732 return lumi->lbAverageLuminosity();
1735 ATH_MSG_DEBUG(
"Warning: lbAverageLuminosity() - luminosity tools are not retrieved or turned on (i.e. EnableLumi = False)");
1748 return lumi->lbLuminosityPerBCIDVector().at (ctx.eventID().bunch_crossing_id());
1751 ATH_MSG_DEBUG(
"Warning: lbLuminosityPerBCID() - luminosity tools are not retrieved or turned on (i.e. EnableLumi = False)");
1771 ATH_MSG_DEBUG(
"Warning: lbAverageLivefraction() - luminosity not availble (i.e. EnableLumi = False)");
1790 ATH_MSG_DEBUG(
"Warning: livefractionPerBCID() - luminosity retrieved available (i.e. EnableLumi = False)");
1805 ATH_MSG_DEBUG(
"Warning: lbLumiWeight() - luminosity tools are not retrieved or turned on (i.e. EnableLumi = False)");
1825 ATH_MSG_DEBUG(
"Warning: lbDuration() - luminosity tools are not retrieved or turned on (i.e. EnableLumi = False)");
1838 : m_charArrSize(100)
1862 delete [] m_mergeData;
1863 delete [] m_triggerData;
1864 delete [] m_intervalData;
1866 delete [] m_nameData;
1875 std::string trigger,
1882 if( trigger.empty() )
1885 merge =
"<default>";
1887 copyString( m_nameData,
name );
1890 copyString( m_triggerData, trigger );
1891 copyString( m_mergeData,
merge );
1901 const char*
f = from.c_str();
1902 while( (++
i < m_charArrSize) && ((*
to++ = *
f++) != 0) ) {};
1903 if(
i == m_charArrSize ) {
1926 std::string
root, rem;
1930 rem.erase(rem.rfind(
'/'), rem.length());
1949 return getStreamName(
tool,
group, objName, usePreviousInterval);
1971 return getStreamName(
tool,
group, objName, usePreviousInterval);
1990 bool isTemp =
false;
1992 bool useRunFolders =
group.interval() !=
all;
1994 bool useLBFolders = ( useRunFolders )
1997 bool useLowStatInterval = ( useRunFolders )
2000 bool useMedStatInterval = ( useRunFolders )
2003 bool useHigStatInterval = ( useRunFolders )
2012 if( useRunFolders ) {
2014 streamName <<
"run_" << m_prev_run_number <<
"/";
2020 if( useLBFolders ) {
2022 streamName <<
"lb_" << m_prev_lumi_block <<
"/";
2026 else if( useLowStatInterval ) {
2034 else if( useMedStatInterval ) {
2039 else if( useHigStatInterval ) {
2044 else if( useEBFolders ) {
2049 long eventsBlockNumber = 1;
2050 long procNEventsProp =
tool->get_procNEventsProp();
2052 if (procNEventsProp > 0) {
2053 eventsBlockNumber = (long)
nEvents / procNEventsProp;
2054 if ((
nEvents % procNEventsProp) != 0)
2055 eventsBlockNumber++;
2059 if (usePreviousInterval) {
2060 eventsBlockNumber--;
2063 streamName <<
"eb_" << eventsBlockNumber <<
"/";
2076 std::string
root, rem;
2080 rem.erase(rem.rfind(
'/'), rem.length());
2095 ATH_MSG_DEBUG(
"ManagedMonitorToolBase::trigChainsArePassed:");
2097 for(
unsigned int i=0;
i<vTrigNames.size();
i++) {
2099 ATH_MSG_DEBUG(
" + \"" << vTrigNames[
i] <<
"\" passed, returning \'true\'");
2114 std::stringstream
ss(
line);
2118 while ( std::getline(
ss,
item,
',') ) {
2119 std::stringstream iss(
item);
2126 return StatusCode::SUCCESS;
2132 for (
size_t i = 0;
i < vTrigChainNames.size(); ++
i) {
2133 std::string& thisName = vTrigChainNames[
i];
2134 if (thisName.compare(0, 9,
"CATEGORY_") ==0) {
2135 ATH_MSG_DEBUG(
"Found a trigger category: " << thisName <<
". We will unpack it.");
2137 std::ostringstream oss;
2139 for (
size_t itrig = 0; itrig <
triggers.size(); ++itrig) {
2147 std::string newval = oss.str();
2149 vTrigChainNames[
i] = std::move(newval);
2187 if (
pos == std::string::npos) {
2224 std::string strToLower(
const std::string&
str )
2226 std::string lstr(
str);
2227 std::string::const_iterator from =
str.begin();
2228 std::string::const_iterator strend =
str.end();
2230 while( from != strend ) {
2238 std::string strToUpper(
const std::string&
str )
2240 std::string ustr(
str);
2241 std::string::const_iterator from =
str.begin();
2242 std::string::const_iterator strend =
str.end();
2244 while( from != strend ) {
2245 *
to++ = toupper(*from++);
JetConstituentVector::iterator iterator
static unsigned int runNumber()
virtual std::string fileKey() const
virtual void passOwnership(TObject *h, const std::string &key)
Pass ownership of a TObject 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
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 unsigned int getLBsMedStat()
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 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.
Gaudi::Details::PropertyBase & declareProperty(Gaudi::Property< T, V, H > &t)
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.
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()
StatusCode initialize(bool used=true)
#define ATH_MSG_WARNING(x)
filelist
print ("Checking files %s..." % fullfile)
static unsigned int lumiBlockNumber()