Skip to content
Snippets Groups Projects
Commit d3d5ae1e authored by Marjorie Shapiro's avatar Marjorie Shapiro Committed by Graeme Stewart
Browse files

Add CreateLumiBlockFromFile_jobOptions.py for use with...

Add CreateLumiBlockFromFile_jobOptions.py for use with RecExCommon_topOptions.py (LumiBlockComps-01-00-03)

	* Add protection if stream name or folder not specified
	* Add CreateLumiBlockFromFile_jobOptions.py to be called from RecExCommon_topOptions.py
	* tag as LumiBlockComps-01-00-03

2015-03-20 Marjorie Shapiro <mdshapiro@lbl.gov>
	* Add protection if stream name or folder not specified
	* tag as LumiBlockComps-01-00-02

2015-03-18 Marjorie Shapiro <mdshapiro@lbl.gov>
	* Update to use new xAOD classes and to handle files that don't respect LB boundaries
	* tag as LumiBlockComps-01-00-01
parent d5580b7f
No related branches found
No related tags found
No related merge requests found
......@@ -21,11 +21,12 @@
#include <vector>
#include <map>
#include <utility>
#include <string>
#include <stdint.h>
#include "LumiBlockData/LumiBlockCollection.h"
#include "GaudiKernel/ServiceHandle.h"
#include "GaudiKernel/IIncidentListener.h"
#include "AthenaKernel/IOVSvcDefs.h"
class StoreGateSvc;
......@@ -39,6 +40,8 @@ public:
/// Incident service handle listening for BeginFile and EndFile.
void handle(const Incident& incident);
/// Callback for database access
virtual StatusCode updateCache(IOVSVC_CALLBACK_ARGS);
protected:
......@@ -50,20 +53,20 @@ protected:
typedef std::map<IOVTime,inOut> RLBMap;
RLBMap m_LumiBlockInfo;
uint32_t m_lastRun; // remember run from last event
uint32_t m_lastLumiBlock; // remember lumiBlock from last event
IOVTime m_lastIOVTime; // could remake from the previous 2, but for efficiency save it
bool m_checkEventsExpected;
uint32_t m_lastRun; // remember RunNumber from last event
uint32_t m_lastLumiBlock; // remember LumiBlock from last event
uint32_t m_channel; // database channel holding number of events expected
std::string m_streamName; // Stream name
IOVTime m_lastIOVTime; // could remake from m_lastRun and m_lastLumiBlock, but for efficiency save it
uint32_t m_numExpected; // number of expected events for this LumiBlock
bool m_checkEventsExpected; // should we read the database?
ServiceHandle<StoreGateSvc> m_metaStore; //cache the StoreGateSvc ptr for efficiency
StringProperty m_LBColl_name;
StringProperty m_unfinishedLBColl_name;
StringProperty m_suspectLBColl_name;
StringProperty m_evtStoreName;
StringProperty m_detStoreName;
StringProperty m_userStoreName;
std::string m_LBColl_name;
std::string m_unfinishedLBColl_name;
std::string m_suspectLBColl_name;
std::string m_folderName;
};
......
......@@ -18,18 +18,20 @@
#include "GaudiKernel/ServiceHandle.h"
#include "AthenaPoolKernel/IMetaDataTool.h"
#include "LumiBlockComps/ILumiBlockMetaDataTool.h"
#include "LumiBlockData/LumiBlockCollection.h"
#include "GaudiKernel/ITHistSvc.h"
#include "TTree.h"
#include "TString.h"
#include "xAODLuminosity/LumiBlockRangeContainer.h"
#include "xAODLuminosity/LumiBlockRangeAuxContainer.h"
#include <vector>
#include <string>
class StoreGateSvc;
class ILumiCalcSvc;
class IGoodRunsListSelectorTool;
class LumiBlockCollectionConverter;
//class LumiBlockCollectionConverter;
class ITriggerRegistryTool;
namespace Root {
......@@ -60,30 +62,31 @@ public:
private:
/// Fill metaDataStore and ntuples
void finishUp();
/// Functions to filter out LBs with bad DQ flags. Passes new lbc that you own.
LumiBlockCollection* FilterOnDQFlags( const LumiBlockCollection& lbc,
const std::vector<std::string>& grlnameVec=std::vector<std::string>(),
const std::vector<std::string>& brlnameVec=std::vector<std::string>() ) ;
/// record lbc in metadatastore
StatusCode RecordInMetaDataStore( LumiBlockCollection* plbc, const TString& lbcname ) ;
/// loop over grlselector registrations, and add dq-approved lbc to grlcollection
StatusCode AddDQCollections( const LumiBlockCollection& lbc, const TString& lbcprefix, const TString& grlprefix="" ) ;
/// make copy of lb collection
LumiBlockCollection* GetCopyOfCollection( const LumiBlockCollection& lbc );
StatusCode fillFromXML( LumiBlockCollection* lbc_target, const std::string& xmlString );
StatusCode finishUp();
typedef ServiceHandle<StoreGateSvc> StoreGateSvc_t;
StoreGateSvc_t m_pMetaDataStore;
StoreGateSvc_t m_pInputStore;
StoreGateSvc_t m_tagDataStore;
LumiBlockCollection* m_cacheLBColl;
LumiBlockCollection* m_unfinishedLBColl;
LumiBlockCollection* m_tempLBColl;
StringProperty m_LBColl_name;
StringProperty m_unfinishedLBColl_name;
// The m_cacheInputRangeContainer stores the LumiBlockRange info for files that are open
// We need to keep suspect lumiblocks separated from complete and incomplete ones
// since something that comes in as suspect always stays suspect
xAOD::LumiBlockRangeContainer* m_cacheInputRangeContainer;
xAOD::LumiBlockRangeAuxContainer* m_cacheInputRangeAuxContainer;
xAOD::LumiBlockRangeContainer* m_cacheSuspectInputRangeContainer;
xAOD::LumiBlockRangeAuxContainer* m_cacheSuspectInputRangeAuxContainer;
// The m_cacheOutputRangeContainer stores the LumiBlockRange info for files that have been read and closed
xAOD::LumiBlockRangeContainer* m_cacheOutputRangeContainer;
xAOD::LumiBlockRangeAuxContainer* m_cacheOutputRangeAuxContainer;
xAOD::LumiBlockRangeContainer* m_cacheSuspectOutputRangeContainer;
xAOD::LumiBlockRangeAuxContainer* m_cacheSuspectOutputRangeAuxContainer;
std::string m_LBColl_name;
std::string m_unfinishedLBColl_name;
std::string m_suspectLBColl_name;
std::string m_version;
TString m_DQLBColl_name;
TString m_unfinishedDQLBColl_name;
......@@ -94,7 +97,7 @@ private:
bool m_calcLumi;
bool m_storexmlfiles;
bool m_applydqcuts;
LumiBlockCollectionConverter* m_converter;
// LumiBlockCollectionConverter* m_converter;
Root::TGRLCollection* m_grlcollection;
ServiceHandle<ILumiCalcSvc> m_lcSvc;
......
......@@ -7,7 +7,6 @@ use AtlasPolicy AtlasPolicy-*
branches run
use GaudiInterface GaudiInterface-* External
use LumiBlockData LumiBlockData-* LumiBlock
use AthenaPoolKernel AthenaPoolKernel-* Database/AthenaPOOL
use AtlasROOT AtlasROOT-* External
use AthenaBaseComps AthenaBaseComps-* Control
......@@ -16,6 +15,7 @@ use AtlasCORAL AtlasCORAL-* External
use StoreGate StoreGate-* Control
use LumiCalc LumiCalc-* LumiBlock
use CoolLumiUtilities CoolLumiUtilities-* Database
use xAODLuminosity xAODLuminosity-* Event/xAOD
private
use AtlasCOOL AtlasCOOL-* External
......
# Create LumiBlock meta data containers *before* creating the output StreamESD/AOD
from LumiBlockComps.LumiBlockCompsConf import CreateLumiBlockCollectionFromFile
createlb = CreateLumiBlockCollectionFromFile()
topSequence += createlb
if globalflags.DataSource()=='data':
from IOVDbSvc.CondDB import conddb
countfolder="/GLOBAL/FILECOUNT/PROMPT <tag>GlobalFileCountPrompt-Tier0</tag>"
conddb.addFolder('GLOBAL_OFL',countfolder)
trstreamName=str(rec.triggerStream())
if(trstreamName != "") :
createlb.streamName = "physics_"+trstreamName
......@@ -2,7 +2,6 @@
Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration
*/
#include "LumiBlockComps/CreateLumiBlockCollectionFromFile.h"
#include "GaudiKernel/FileIncident.h"
#include "GaudiKernel/ISvcLocator.h"
......@@ -11,26 +10,32 @@
#include "EventInfo/EventID.h"
#include "StoreGate/StoreGateSvc.h"
#include "xAODLuminosity/LumiBlockRangeContainer.h"
#include "xAODLuminosity/LumiBlockRangeAuxContainer.h"
#include "AthenaPoolUtilities/CondAttrListCollection.h"
#include "AthenaPoolUtilities/AthenaAttributeList.h"
#include "CoolKernel/IObject.h"
#include "CoralBase/Blob.h"
CreateLumiBlockCollectionFromFile::CreateLumiBlockCollectionFromFile(const std::string& name, ISvcLocator* pSvcLocator) :
// ********************************************************************************************************************
AthAlgorithm(name, pSvcLocator), m_lastRun(9999999), m_lastLumiBlock(9999999), m_lastIOVTime(0),
m_metaStore("StoreGateSvc/MetaDataStore", name)
AthAlgorithm(name, pSvcLocator), m_lastRun(9999999), m_lastLumiBlock(9999999),
m_lastIOVTime(0), m_numExpected(0),m_metaStore("StoreGateSvc/MetaDataStore", name)
{
declareProperty("streamName",m_streamName="");
declareProperty("channelNumber",m_channel=0);
declareProperty("LBCollName",m_LBColl_name = "LumiBlocks");
declareProperty("unfinishedLBCollName",m_unfinishedLBColl_name = "IncompleteLumiBlocks");
declareProperty("suspectLBCollName",m_suspectLBColl_name = "SuspectLumiBlocks");
declareProperty("checkEventsExpected",m_checkEventsExpected=false);
declareProperty("DBfolderName",m_folderName="/GLOBAL/FILECOUNT/PROMPT");
declareProperty("checkEventsExpected",m_checkEventsExpected=true);
}
StatusCode CreateLumiBlockCollectionFromFile::initialize(){
//*******************************************************
ATH_MSG_INFO( "initialize() and create listeners" );
declareProperty ("EvtStore", m_evtStoreName);
declareProperty ("DetStore", m_detStoreName);
declareProperty ("UserStore", m_userStoreName);
// Locate the StoreGateSvc and initialize our local ptr
// ****************************************************
......@@ -48,6 +53,19 @@ StatusCode CreateLumiBlockCollectionFromFile::initialize(){
m_LumiBlockInfo.clear();
const DataHandle<CondAttrListCollection> aptr;
if(m_folderName.empty()) {
ATH_MSG_INFO( "No folderName specified" );
}
else if(m_streamName.empty()) {
ATH_MSG_INFO( "No streamName specified" );
}
else if (detStore()->contains<CondAttrListCollection>(m_folderName)) {
CHECK(detStore()->regFcn(&CreateLumiBlockCollectionFromFile::updateCache, this , aptr, m_folderName));
}
else {
ATH_MSG_FATAL( "detStore() does not contain folder " << m_folderName );
}
return StatusCode::SUCCESS;
}
......@@ -60,14 +78,6 @@ StatusCode CreateLumiBlockCollectionFromFile::execute() {
// Check for event header
const DataHandle<EventInfo> evt;
ATH_CHECK( evtStore()->retrieve(evt) );
if (!evt.isValid()) {
ATH_MSG_FATAL( "Could not find event" );
return(StatusCode::FAILURE);
}
ATH_MSG_DEBUG( "EventInfo event: " << evt->event_ID()->event_number()
<< " run: " << evt->event_ID()->run_number()
<< " lumi block: " << evt->event_ID()->lumi_block() );
if(m_lastRun!=evt->event_ID()->run_number() ||
m_lastLumiBlock!=evt->event_ID()->lumi_block()) {
......@@ -75,15 +85,8 @@ StatusCode CreateLumiBlockCollectionFromFile::execute() {
RLBMap::iterator mitr;
mitr=m_LumiBlockInfo.find(iovtime);
if (mitr==m_LumiBlockInfo.end()) {
// Here is where we should access the database
// ==============================================
unsigned int expectedEvents = 0;
if(m_checkEventsExpected) {
ATH_MSG_WARNING( "Database access to number of expected events not implemented" );
expectedEvents = 8; // JUST FOR TESTING
}
inOut lbInOut(expectedEvents,1);
ATH_MSG_INFO( "Fill LumiBlockInfo with numExpected="<<m_numExpected );
inOut lbInOut(m_numExpected,1);
m_LumiBlockInfo[iovtime] = lbInOut;
}
else {
......@@ -97,7 +100,6 @@ StatusCode CreateLumiBlockCollectionFromFile::execute() {
else {
m_LumiBlockInfo[m_lastIOVTime].second++;
}
return (StatusCode::SUCCESS);
}
......@@ -116,18 +118,21 @@ StatusCode CreateLumiBlockCollectionFromFile::fillLumiBlockCollection()
// ********************************************************************
{
// Create the LumiBlockCollection
LumiBlockCollection* piovComplete = new LumiBlockCollection();
LumiBlockCollection* piovUnfinished = new LumiBlockCollection();
LumiBlockCollection* piovSuspect = new LumiBlockCollection();
xAOD::LumiBlockRangeContainer* piovComplete = new xAOD::LumiBlockRangeContainer();
xAOD::LumiBlockRangeAuxContainer* piovCompleteAux = new xAOD::LumiBlockRangeAuxContainer();
piovComplete->setStore( piovCompleteAux );
for(RLBMap::iterator mitr=m_LumiBlockInfo.begin(); mitr!=m_LumiBlockInfo.end(); mitr++) {
// Create our LB_IOVRange object
// Looks a bit wierd, but our map is <iovTime, pair<unit32_t,uint32_t> >
LB_IOVRange* iovr = new LB_IOVRange(mitr->first,mitr->first);
iovr->setNumExpected(mitr->second.first);
iovr->setNumSeen(mitr->second.second);
xAOD::LumiBlockRangeContainer* piovUnfinished = new xAOD::LumiBlockRangeContainer();
xAOD::LumiBlockRangeAuxContainer* piovUnfinishedAux = new xAOD::LumiBlockRangeAuxContainer();
piovUnfinished->setStore( piovUnfinishedAux );
xAOD::LumiBlockRangeContainer* piovSuspect = new xAOD::LumiBlockRangeContainer();
xAOD::LumiBlockRangeAuxContainer* piovSuspectAux = new xAOD::LumiBlockRangeAuxContainer();
piovSuspect->setStore( piovSuspectAux );
for(RLBMap::iterator mitr=m_LumiBlockInfo.begin(); mitr!=m_LumiBlockInfo.end(); mitr++) {
xAOD::LumiBlockRange* iovr = new xAOD::LumiBlockRange();
// Decide which collection it goes into depending on whether the LB is complete
// =============================================================================
......@@ -141,52 +146,79 @@ StatusCode CreateLumiBlockCollectionFromFile::fillLumiBlockCollection()
else {
piovUnfinished->push_back(iovr);
}
iovr->setStartRunNumber(mitr->first.run());
iovr->setStartLumiBlockNumber(mitr->first.event());
iovr->setStopRunNumber(mitr->first.run());
iovr->setStopLumiBlockNumber(mitr->first.event());
iovr->setEventsExpected(mitr->second.first);
iovr->setEventsSeen(mitr->second.second);
}
ATH_MSG_INFO( "Summary of LumiBlock Info:" );
if(piovComplete->size()>0) {
ATH_MSG_INFO( "Complete LumiBlocks:" );
piovComplete->dump(std::cout);
ATH_MSG_INFO( "Number of Complete LumiBlocks:" << piovComplete->size() );
xAOD::LumiBlockRangeContainer::const_iterator it;
for(it=piovComplete->begin(); it!=piovComplete->end(); it++) {
msg(MSG::INFO) << "\t [ ("
<< (*it)->startRunNumber() << "," << (*it)->startLumiBlockNumber()
<< "):("
<< (*it)->startRunNumber() << "," << (*it)->startLumiBlockNumber()
<< ") eventsSeen = " << (*it)->eventsSeen()
<< ", eventsExpected = " << (*it)->eventsExpected()
<< " ]"
<< endreq;
}
}
if(piovUnfinished->size()>0) {
ATH_MSG_INFO( "Unfinished LumiBlocks:" );
piovUnfinished->dump(std::cout);
ATH_MSG_INFO( "Number of Unfinished LumiBlocks:" << piovUnfinished->size() );
xAOD::LumiBlockRangeContainer::const_iterator it;
for(it=piovUnfinished->begin(); it!=piovUnfinished->end(); it++) {
msg(MSG::INFO) << "\t [ ("
<< (*it)->startRunNumber() << "," << (*it)->startLumiBlockNumber()
<< "):("
<< (*it)->startRunNumber() << "," << (*it)->startLumiBlockNumber()
<< ") eventsSeen = " << (*it)->eventsSeen()
<< ", eventsExpected = " << (*it)->eventsExpected()
<< " ]"
<< endreq;
}
}
if(piovSuspect->size()>0) {
ATH_MSG_INFO( "Suspect LumiBlocks:" );
piovSuspect->dump(std::cout);
ATH_MSG_INFO( "Number of Suspect LumiBlocks:" << piovSuspect->size() );
xAOD::LumiBlockRangeContainer::const_iterator it;
for(it=piovSuspect->begin(); it!=piovSuspect->end(); it++) {
msg(MSG::INFO) << "\t [ ("
<< (*it)->startRunNumber() << "," << (*it)->startLumiBlockNumber()
<< "):("
<< (*it)->startRunNumber() << "," << (*it)->startLumiBlockNumber()
<< ") eventsSeen = " << (*it)->eventsSeen()
<< ", eventsExpected = " << (*it)->eventsExpected()
<< " ]"
<< endreq;
}
}
// Store the LumiBlockCollection in the metadata store
// =======================================================
StatusCode sc;
if(piovComplete->size()>0) {
sc = m_metaStore->record(piovComplete, m_LBColl_name);
if (sc.isFailure()) {
ATH_MSG_ERROR("could not register complete LumiBlockCollection");
}
ATH_CHECK( m_metaStore->record( piovComplete, m_LBColl_name ) );
ATH_CHECK( m_metaStore->record( piovCompleteAux, m_LBColl_name + "Aux." ) );
}
if(piovUnfinished->size()>0) {
sc = m_metaStore->record(piovUnfinished, m_unfinishedLBColl_name);
if (sc.isFailure()) {
ATH_MSG_ERROR("could not register incomplete LumiBlockCollection");
}
ATH_CHECK( m_metaStore->record( piovUnfinished, m_unfinishedLBColl_name ) );
ATH_CHECK( m_metaStore->record( piovUnfinishedAux, m_unfinishedLBColl_name + "Aux." ) );
}
if(piovSuspect->size()>0) {
sc = m_metaStore->record(piovSuspect, m_suspectLBColl_name);
if (sc.isFailure()) {
ATH_MSG_ERROR("could not register suspect LumiBlockCollection");
}
ATH_CHECK( m_metaStore->record( piovSuspect, m_suspectLBColl_name ) );
ATH_CHECK( m_metaStore->record( piovSuspectAux, m_suspectLBColl_name + "Aux." ) );
}
// Then clear m_LumiBlockInfo. This is in case we decide to store the
// LBColl separately for each input or output file.
// LBColl separately for each input or output file.
m_LumiBlockInfo.clear();
return StatusCode::SUCCESS;
}
......@@ -226,7 +258,6 @@ void CreateLumiBlockCollectionFromFile:: finishUp() {
// ********************************************************************
ATH_MSG_INFO( " finishUp: write lumiblocks to meta data store " );
ATH_MSG_INFO( "LumiBlockInfo.size= "<< m_LumiBlockInfo.size() );
if(m_LumiBlockInfo.size()>0) {
StatusCode sc=fillLumiBlockCollection();
if (sc.isFailure()) {
......@@ -234,3 +265,60 @@ void CreateLumiBlockCollectionFromFile:: finishUp() {
}
}
}
StatusCode CreateLumiBlockCollectionFromFile::updateCache(IOVSVC_CALLBACK_ARGS) {
// Check if we have anything to do
// Shouldn't actually get a callback if this folder doesn't exist...
ATH_MSG_INFO( "In updateCache callback" );
m_numExpected = 0;
if (m_folderName.empty()) return StatusCode::SUCCESS;
if(m_streamName=="") return StatusCode::SUCCESS;
ATH_MSG_INFO( "folder is not empty" );
const CondAttrListCollection* attrListColl = 0;
CHECK(detStore()->retrieve(attrListColl, m_folderName));
CondAttrListCollection::const_iterator it = attrListColl->begin();
CondAttrListCollection::const_iterator last = attrListColl->end();
CondAttrListCollection::const_iterator match = attrListColl->end();
for (; it != last; ++it) {
if (attrListColl->name_size()>0) {
CondAttrListCollection::name_const_iterator nitr=attrListColl->chanNamePair((*it).first);
int chan = (*it).first;
std::string theName = nitr->second;
ATH_MSG_INFO( "channel " << chan << " name " << theName);
if(theName==m_streamName) {
m_channel = chan;
match=it;
break;
}
}
}
// Make sure we found it
if (match == last) {
ATH_MSG_WARNING( "Stream " << m_streamName << " not found in " << m_folderName << "!" );
m_numExpected = 0;
return StatusCode::SUCCESS;
}
// OK, get number of events
std::ostringstream attrStr1;
(*match).second.toOutputStream( attrStr1 );
const coral::AttributeList& attrList = (*match).second;
// Check data availability
if (attrList["NEventRec"].isNull()) {
ATH_MSG_WARNING( " NEventRec not in database. Set it to 0 " );
return StatusCode::SUCCESS;
}
cool::Int32 nev = attrList["NEventRec"].data<cool::Int32>();
m_numExpected = (uint32_t) nev;
ATH_MSG_INFO( "database returns NEventRec=" << nev );
return StatusCode::SUCCESS;
}
......@@ -14,9 +14,7 @@
#include "GoodRunsLists/ITriggerRegistryTool.h"
#include "LumiCalc/LumiBlockCollectionConverter.h"
#include "LumiBlockComps/ILumiCalcSvc.h"
// the user data-class defintions
#include "LumiBlockData/LumiBlockCollection.h"
#include "xAODLuminosity/SortLumiBlockRangeByStart.h"
#include "GaudiKernel/ToolFactory.h"
#include "GaudiKernel/IIncidentSvc.h"
......@@ -42,7 +40,6 @@ LumiBlockMetaDataTool::LumiBlockMetaDataTool(const std::string& type, const std:
m_tagDataStore ("StoreGateSvc/TagMetaDataStore", name),
m_nfiles(0),
m_fileCurrentlyOpened(false),
m_converter(new LumiBlockCollectionConverter()),
m_grlcollection(new Root::TGRLCollection()),
m_lcSvc("LumiCalcSvc/LumiCalcSvc",name),
m_GoodRunsListSelectorTool("GoodRunsListSelectorTool"),
......@@ -53,15 +50,39 @@ LumiBlockMetaDataTool::LumiBlockMetaDataTool(const std::string& type, const std:
declareProperty("LBCollName",m_LBColl_name = "LumiBlocks");
declareProperty("unfinishedLBCollName",m_unfinishedLBColl_name = "IncompleteLumiBlocks");
declareProperty("suspectLBCollName", m_suspectLBColl_name="SuspectLumiBlocks");
declareProperty("VersionString",m_version = "10");
declareProperty("calcLumi", m_calcLumi = false);
declareProperty("storeXMLFiles", m_storexmlfiles = true);
declareProperty("applyDQCuts", m_applydqcuts = true);
declareProperty("storeXMLFiles", m_storexmlfiles = false);
declareProperty("applyDQCuts", m_applydqcuts = false);
declareProperty("lumicalcSvc", m_lcSvc);
m_cacheLBColl = new LumiBlockCollection(); // Complete LB where EOF has been seen
m_tempLBColl = new LumiBlockCollection(); // Temp storage while reading the file
m_unfinishedLBColl = new LumiBlockCollection(); // Incomplete LB's from input file
// Here is where we create the LumiBlockRange objects. When we open a
// file, we fill the m_cacheInputRangeContainer from the input metadata store.
// When the file closes, we move the LumiBlockRange objects to the
// m_cacheOutputRangeContainer. Objects in the m_cacheOutputRangeContainer
// will be sorted and merged at the end of the job
// Note: the Suspect Range objects are kept in separate containers because
// once an object is suspect, it remains suspect forever
// If a file is only partially read, the objects in the m_cacheInputRangeContainer
// will be moved to the m_suspectOutputRangeContainer
m_cacheInputRangeContainer = new xAOD::LumiBlockRangeContainer();
m_cacheInputRangeAuxContainer = new xAOD::LumiBlockRangeAuxContainer();
m_cacheInputRangeContainer->setStore( m_cacheInputRangeAuxContainer );
m_cacheSuspectInputRangeContainer = new xAOD::LumiBlockRangeContainer();
m_cacheSuspectInputRangeAuxContainer = new xAOD::LumiBlockRangeAuxContainer();
m_cacheSuspectInputRangeContainer->setStore( m_cacheSuspectInputRangeAuxContainer );
m_cacheOutputRangeContainer = new xAOD::LumiBlockRangeContainer();
m_cacheOutputRangeAuxContainer = new xAOD::LumiBlockRangeAuxContainer();
m_cacheOutputRangeContainer->setStore( m_cacheOutputRangeAuxContainer );
m_cacheSuspectOutputRangeContainer = new xAOD::LumiBlockRangeContainer();
m_cacheSuspectOutputRangeAuxContainer = new xAOD::LumiBlockRangeAuxContainer();
m_cacheSuspectOutputRangeContainer->setStore( m_cacheSuspectOutputRangeAuxContainer );
m_DQLBColl_name = TString(m_LBColl_name)+"_GoodDQ";
m_unfinishedDQLBColl_name = TString(m_unfinishedLBColl_name)+"_GoodDQ";
......@@ -69,10 +90,17 @@ LumiBlockMetaDataTool::LumiBlockMetaDataTool(const std::string& type, const std:
//___________________________________________________________________________
LumiBlockMetaDataTool::~LumiBlockMetaDataTool() {
delete m_cacheLBColl; m_cacheLBColl = 0;
delete m_tempLBColl; m_tempLBColl = 0;
delete m_unfinishedLBColl; m_unfinishedLBColl = 0;
if (m_converter!=0) { delete m_converter; m_converter=0; }
delete m_cacheInputRangeContainer; m_cacheInputRangeContainer = 0;
delete m_cacheInputRangeAuxContainer; m_cacheInputRangeAuxContainer = 0;
delete m_cacheSuspectInputRangeContainer; m_cacheSuspectInputRangeContainer = 0;
delete m_cacheSuspectInputRangeAuxContainer; m_cacheSuspectInputRangeAuxContainer = 0;
delete m_cacheOutputRangeContainer; m_cacheOutputRangeContainer = 0;
delete m_cacheOutputRangeAuxContainer; m_cacheOutputRangeAuxContainer = 0;
delete m_cacheSuspectOutputRangeContainer; m_cacheSuspectOutputRangeContainer = 0;
delete m_cacheSuspectOutputRangeAuxContainer; m_cacheSuspectOutputRangeAuxContainer = 0;
if (m_grlcollection!=0) { delete m_grlcollection; m_grlcollection=0; }
}
......@@ -90,8 +118,8 @@ StatusCode LumiBlockMetaDataTool::initialize() {
incSvc->addListener(this, "BeginTagFile", 60); // pri has to be < 100 to be after MetaDataSvc.
incSvc->addListener(this, "BeginInputFile", 60); // pri has to be < 100 to be after MetaDataSvc.
incSvc->addListener(this, "EndTagFile", 50); // pri has to be > 10 to be before MetaDataSvc.
// incSvc->addListener(this, "EndInputFile", 50); // pri has to be > 10 to be before MetaDataSvc.
incSvc->addListener(this, "LastInputFile", 50); // pri has to be > 20 to be before MetaDataSvc and AthenaOutputStream.
incSvc->addListener(this, "MetaDataStop", 70);
ATH_CHECK( m_lcSvc.retrieve() );
......@@ -105,582 +133,276 @@ StatusCode LumiBlockMetaDataTool::initialize() {
// Retrieve the TriggerRegistry tool using the ToolHandles
ATH_CHECK( m_TriggerRegistryTool.retrieve() );
m_cacheLBColl->clear();
m_tempLBColl->clear();
m_unfinishedLBColl->clear();
return(StatusCode::SUCCESS);
}
//___________________________________________________________________________
StatusCode LumiBlockMetaDataTool::finalize() {
if(m_cacheLBColl->size() >0) {
ATH_MSG_INFO( " Luminosity Blocks Recorded in Metadata store: " );
m_cacheLBColl->dump();
}
else {
ATH_MSG_INFO( "No Complete Luminosity Blocks read in this job" );
}
if(m_tempLBColl->size()>0 ) {
ATH_MSG_INFO( "Incomplete File Reading led to suspect LumiBlocks: " );
m_tempLBColl->dump();
}
if(m_unfinishedLBColl->size()>0 ) {
ATH_MSG_INFO( "Transferring Incomplete LB metadata from input file for suspect LumiBlocks: " );
m_unfinishedLBColl->dump();
}
m_grlcollection->Summary();
return(StatusCode::SUCCESS);
}
//__________________________________________________________________________
void LumiBlockMetaDataTool::handle(const Incident& inc) {
// This handle is fired when files are opened or closed.
// The "MetaDataStop" incident is fired when the final write
// of metadata to the output store should occur
const FileIncident* fileInc = dynamic_cast<const FileIncident*>(&inc);
std::string fileName;
if (fileInc == 0) { fileName = "Undefined "; }
else { fileName = fileInc->fileName(); }
ATH_MSG_INFO( "handle() " << inc.type() << " for file: " << fileName );
ATH_MSG_INFO( "handle() " << inc.type());
// This incident is called whether or not a Tag file is being read. If there is no Tag file,
// this incident serves the same purpose as BeginInputFile
if (inc.type() == "BeginTagFile") {
//
// Retrieve LB info from TAG metadata and cache it locally
// ========================================================
CollectionMetadata* metadataMap = 0;
if(!m_tagDataStore->contains<CollectionMetadata>("CollectionMetadata")) return;
StatusCode status = m_tagDataStore->retrieve(metadataMap, "CollectionMetadata");
if (!status.isSuccess()) {
ATH_MSG_WARNING( "Cannot retrieve Metadata map from TagDataStore." );
return;
}
std::string myValue = "NotFound";
CollectionMetadata::iterator iter = metadataMap->find("OutputLumirange");
if (iter != metadataMap->end()) {
myValue = iter->second;
}
ATH_MSG_DEBUG( "OutputLumirange: " << myValue );
if (myValue != "NotFound") {
StatusCode status = fillFromXML(m_tempLBColl, myValue);
if (!status.isSuccess()) {
ATH_MSG_WARNING( "fillFromXML failed!" );
}
ATH_MSG_DEBUG( "This should now be parsed to get the GoodRunsList" );
ATH_MSG_DEBUG( " Size of CollectionMetadata is: " << metadataMap->size() );
for (iter = metadataMap->begin(); iter != metadataMap->end(); iter++) {
ATH_MSG_INFO( " first: " << iter->first << " second: " << iter->second );
}
} else {
for (CollectionMetadata::iterator cmit = metadataMap->begin(); cmit != metadataMap->end(); cmit++) {
ATH_MSG_DEBUG( "CollectionMetadata has " << cmit->first << ", " << cmit->second );
}
}
// We still need to add Tag file functionality back into the new tool
return;
} else if (inc.type() == "BeginInputFile") {
m_nfiles++;
m_fileCurrentlyOpened=true;
//
// Look for LB information on input store and transfer it to temporay cache
// ===========================================================================
if (m_pInputStore->contains<LumiBlockCollection>(m_LBColl_name)) {
std::list<SG::ObjectWithVersion<LumiBlockCollection> > allVersions;
StatusCode sc = m_pInputStore->retrieveAllVersions(allVersions, m_LBColl_name);
if (m_pInputStore->contains<xAOD::LumiBlockRangeContainer>(m_LBColl_name)) {
msg(MSG::INFO) << " Contains xAOD::LumiBlockRangeContainer " << m_LBColl_name << endreq;
const xAOD::LumiBlockRangeContainer* lbrange =0;
StatusCode sc = m_pInputStore->retrieve(lbrange,m_LBColl_name);
if (!sc.isSuccess()) {
ATH_MSG_DEBUG( "Could not find LumiBlockColl in input metatdata store" );
ATH_MSG_INFO( "Could not find unfinished xAOD::LumiBlockRangeContainer in input metatdata store" );
return;
}
for(std::list<SG::ObjectWithVersion<LumiBlockCollection> >::const_iterator iter = allVersions.begin(); iter != allVersions.end(); iter++) {
const DataHandle<LumiBlockCollection> lbc = iter->dataObject;
LumiBlockCollection::const_iterator i(lbc->begin()), ie(lbc->end());
LumiBlockCollection::const_iterator ilast(lbc->begin());
// Now cache it locally
m_tempLBColl->reserve(m_tempLBColl->size()+lbc->size());
if(i!=ie) m_tempLBColl->push_back(new LB_IOVRange(*(*i++)));
while (i != ie) {
if(**i!=**ilast ) { m_tempLBColl->push_back(new LB_IOVRange(*(*i))); }
else {
ATH_MSG_DEBUG( "Remove duplicate with range " << **i );
}
ilast = i;
i++;
}
ATH_MSG_INFO( "xAOD::LumiBlockRangeContainer size" << lbrange->size() );
for ( const auto* lb : *lbrange ) {
xAOD::LumiBlockRange* iovr = new xAOD::LumiBlockRange(*lb);
m_cacheInputRangeContainer->push_back(iovr);
}
m_tempLBColl->sort(LumiBlockCollection::SortIOVRangeByStart());
m_tempLBColl->erase( std::unique( m_tempLBColl->begin(), m_tempLBColl->end() ), m_tempLBColl->end() );
}
//
// Look for information on incomplete LB in input store and transfer it to unfinished cache
// ==========================================================================================
if (m_pInputStore->contains<LumiBlockCollection>(m_unfinishedLBColl_name)) {
std::list<SG::ObjectWithVersion<LumiBlockCollection> > allVersions;
StatusCode sc = m_pInputStore->retrieveAllVersions(allVersions, m_unfinishedLBColl_name);
if (!sc.isSuccess()) {
ATH_MSG_DEBUG( "Could not find Incomplete LumiBlockColl in input metatdata store" );
return;
}
for(std::list<SG::ObjectWithVersion<LumiBlockCollection> >::const_iterator iter = allVersions.begin(); iter != allVersions.end(); iter++) {
const DataHandle<LumiBlockCollection> lbc = iter->dataObject;
LumiBlockCollection::const_iterator i(lbc->begin()), ie(lbc->end());
LumiBlockCollection::const_iterator ilast(lbc->begin());
// Now cache it locally
m_unfinishedLBColl->reserve(m_unfinishedLBColl->size()+lbc->size());
if(i!=ie) m_unfinishedLBColl->push_back(new LB_IOVRange(*(*i++)));
while (i != ie) {
if(**i!=**ilast ) { m_unfinishedLBColl->push_back(new LB_IOVRange(*(*i))); }
else {
ATH_MSG_DEBUG( "Remove duplicate in unfinished collection with range " << **i );
}
ilast = i;
i++;
}
if (m_pInputStore->contains<xAOD::LumiBlockRangeContainer>(m_unfinishedLBColl_name)) {
msg(MSG::INFO) << " Contains xAOD::LumiBlockRangeContainer " << m_unfinishedLBColl_name << endreq;
const xAOD::LumiBlockRangeContainer* lbrange =0;
StatusCode sc = m_pInputStore->retrieve(lbrange,m_unfinishedLBColl_name);
if (!sc.isSuccess()) {
ATH_MSG_INFO( "Could not find unfinished xAOD::LumiBlockRangeContainer in input metatdata store" );
return;
}
ATH_MSG_INFO( "xAOD::LumiBlockRangeContainer size" << lbrange->size() );
for ( const auto* lb : *lbrange ) {
xAOD::LumiBlockRange* iovr = new xAOD::LumiBlockRange(*lb);
m_cacheInputRangeContainer->push_back(iovr);
}
}
if (m_pInputStore->contains<xAOD::LumiBlockRangeContainer>(m_suspectLBColl_name)) {
msg(MSG::INFO) << " Contains xAOD::LumiBlockRangeContainer " << m_suspectLBColl_name << endreq;
const xAOD::LumiBlockRangeContainer* lbrange =0;
StatusCode sc = m_pInputStore->retrieve(lbrange,m_suspectLBColl_name);
if (!sc.isSuccess()) {
ATH_MSG_INFO( "Could not find suspect xAOD::LumiBlockRangeContainer in input metatdata store" );
return;
}
ATH_MSG_INFO( "xAOD::LumiBlockRangeContainer size" << lbrange->size() );
for ( const auto* lb : *lbrange ) {
xAOD::LumiBlockRange* iovr = new xAOD::LumiBlockRange(*lb);
m_cacheSuspectInputRangeContainer->push_back(iovr);
}
}
}
else if (inc.type() == "EndTagFile") {
//
// The file ended properly. Move the LB ranges into the cache of completed LB
// ============================================================================
if(m_tempLBColl->size() >0 ) {
m_cacheLBColl->reserve(m_cacheLBColl->size()+m_tempLBColl->size());
LumiBlockCollection::const_iterator i(m_tempLBColl->begin()), ie(m_tempLBColl->end());
while (i != ie) {m_cacheLBColl->push_back(new LB_IOVRange(*(*i++)));}
m_tempLBColl->clear();
}
m_fileCurrentlyOpened=false;
xAOD::LumiBlockRangeContainer::const_iterator it;
for(it=m_cacheInputRangeContainer->begin(); it!=m_cacheInputRangeContainer->end(); it++) {
xAOD::LumiBlockRange* iovr = new xAOD::LumiBlockRange(*(*it));
m_cacheOutputRangeContainer->push_back(iovr);
}
m_cacheInputRangeContainer->clear();
for(it=m_cacheSuspectInputRangeContainer->begin(); it!=m_cacheSuspectInputRangeContainer->end(); it++) {
xAOD::LumiBlockRange* iovr = new xAOD::LumiBlockRange(*(*it));
m_cacheSuspectOutputRangeContainer->push_back(iovr);
}
m_cacheSuspectInputRangeContainer->clear();
}
else if (inc.type() == "LastInputFile") {
finishUp();
else if (inc.type() == "MetaDataStop") {
if(m_fileCurrentlyOpened) {
ATH_MSG_INFO( "MetaDataStop called when input file open: LumiBlock is suspect" );
xAOD::LumiBlockRangeContainer::const_iterator it;
for(it=m_cacheInputRangeContainer->begin(); it!=m_cacheInputRangeContainer->end(); it++) {
xAOD::LumiBlockRange* iovr = new xAOD::LumiBlockRange(*(*it));
m_cacheSuspectOutputRangeContainer->push_back(iovr);
}
m_cacheInputRangeContainer->clear();
}
StatusCode sc = finishUp();
if (!sc.isSuccess()) {
ATH_MSG_INFO( "finishup failed" );
return;
}
}
}
//__________________________________________________________________________
void LumiBlockMetaDataTool::finishUp() {
StatusCode LumiBlockMetaDataTool::finishUp() {
//
// stop() is called whenever the event loop is finished.
// ======================================================
ATH_MSG_INFO( " finishUp: write lumiblocks to meta data store " );
// if(m_nfiles >1 && m_cacheLBColl->size()>0)
if(m_cacheLBColl->size()>0)
m_cacheLBColl->sort(LumiBlockCollection::SortIOVRangeByStart());
// if(m_nfiles >1 && m_unfinishedLBColl->size()>0)
if(m_unfinishedLBColl->size()>0)
m_unfinishedLBColl->sort(LumiBlockCollection::SortIOVRangeByStart());
//
// Fill the metadata store here for all cases where the full file was read
// =========================================================================
if(m_cacheLBColl->size()>0) {
// *** We still don't have checking for duplicates or merging
// use DV sort instead of std::sort as the latter leaks memory with DV
LumiBlockCollection* tmpColl = new LumiBlockCollection();
// We have to do this because the copy constructor of DataVector only
// copies the pointers...
LumiBlockCollection::const_iterator i(m_cacheLBColl->begin()), ie(m_cacheLBColl->end());
tmpColl->push_back(new LB_IOVRange(*(*i++)));
while (i != ie) {
tmpColl->push_back(new LB_IOVRange(*(*i)));
i++;
}
if(tmpColl->size()>0) {
if (m_pMetaDataStore->contains<LumiBlockCollection>(m_LBColl_name)) {
DataHandle<LumiBlockCollection> tmp;
StatusCode ss = m_pMetaDataStore->retrieve(tmp,m_LBColl_name);
if(ss.isSuccess()) {m_pMetaDataStore->remove(tmp.ptr());}
else {
ATH_MSG_ERROR("Error removing exisiting LB collection from MetaDataStore " );
}
}
StatusCode sc = m_pMetaDataStore->record(tmpColl, m_LBColl_name);
if (!sc.isSuccess()) {
delete tmpColl; tmpColl = 0;
ATH_MSG_ERROR( "Could not record LumiBlockColl : " << m_LBColl_name );
//return sc;
}
if (m_applydqcuts) {
sc = this->AddDQCollections(*m_cacheLBColl,m_DQLBColl_name,"luminosity_");
if (!sc.isSuccess()) {
ATH_MSG_ERROR( "Could not apply DQ selection to LumiBlockColl : " << m_LBColl_name );
//return sc;
}
}
} else {
delete tmpColl; tmpColl = 0;
}
}
xAOD::LumiBlockRangeContainer* piovComplete = new xAOD::LumiBlockRangeContainer();
xAOD::LumiBlockRangeAuxContainer* piovCompleteAux = new xAOD::LumiBlockRangeAuxContainer();
piovComplete->setStore( piovCompleteAux );
//
// Handle the case where a file is partially read in this job or previous jobs
// ============================================================================
if (m_tempLBColl->size()>0 || m_unfinishedLBColl->size()>0) {
// collect incomplete LB collections
LumiBlockCollection* tmp2Coll = new LumiBlockCollection();
if (m_tempLBColl->size()>0 || m_unfinishedLBColl->size()>0) {
LumiBlockCollection::const_iterator i(m_tempLBColl->begin()), ie(m_tempLBColl->end());
while (i != ie) { tmp2Coll->push_back(new LB_IOVRange(*(*i++)));}
LumiBlockCollection::const_iterator j(m_unfinishedLBColl->begin()), je(m_unfinishedLBColl->end());
while (j != je) { tmp2Coll->push_back(new LB_IOVRange(*(*j++)));}
tmp2Coll->sort(LumiBlockCollection::SortIOVRangeByStart());
}
xAOD::LumiBlockRangeContainer* piovUnfinished = new xAOD::LumiBlockRangeContainer();
xAOD::LumiBlockRangeAuxContainer* piovUnfinishedAux = new xAOD::LumiBlockRangeAuxContainer();
piovUnfinished->setStore( piovUnfinishedAux );
StatusCode sc = m_pMetaDataStore->record(tmp2Coll, m_unfinishedLBColl_name);
if (!sc.isSuccess()) {
ATH_MSG_ERROR( "Could not record Unfinished LumiBlockColl : " << m_unfinishedLBColl_name );
//return sc;
}
if (m_applydqcuts) {
sc = this->AddDQCollections(*tmp2Coll,m_unfinishedDQLBColl_name,"incomplete_luminosity_");
if (!sc.isSuccess()) {
ATH_MSG_ERROR( "Could not apply DQ selection to LumiBlockColl : " << m_unfinishedLBColl_name );
//return sc;
}
}
}
xAOD::LumiBlockRangeContainer* piovSuspect = new xAOD::LumiBlockRangeContainer();
xAOD::LumiBlockRangeAuxContainer* piovSuspectAux = new xAOD::LumiBlockRangeAuxContainer();
piovSuspect->setStore( piovSuspectAux );
// process xml string/file
m_grlxmlstring = m_converter->GetXMLString(*m_grlcollection);
Root::TUniqueGRLString& uniquestr = Root::TUniqueGRLString::instance();
uniquestr.SetTo(m_grlxmlstring);
if (m_storexmlfiles) {
TString subname;
TString complete = m_converter->GetSuggestedName(*m_cacheLBColl);
TString incomplete = m_converter->GetSuggestedName(*m_unfinishedLBColl);
if (complete=="grl_empty" && incomplete!="grl_empty") { subname = incomplete; }
else { subname = complete; }
TString filename = "luminosity_" + subname + ".xml";
m_converter->CreateXMLFile(*m_grlcollection,filename.Data());
}
xAOD::LumiBlockRangeContainer::const_iterator it;
//
// Call LumiCalcSvc to calculate integrated luminosity
// ============================================================================
if(m_calcLumi == true){
StatusCode sc = m_lcSvc->calcLumi();
if (!sc.isSuccess()) {
ATH_MSG_WARNING( "Couldn't calculate lumi!" );
//return sc;
if(m_cacheSuspectOutputRangeContainer->size()>0) {
msg(MSG::INFO) << "Suspect OutputRangeCollection with size " << m_cacheSuspectOutputRangeContainer->size() << endreq;
for(it=m_cacheSuspectOutputRangeContainer->begin(); it!=m_cacheSuspectOutputRangeContainer->end(); it++) {
xAOD::LumiBlockRange* iovr = new xAOD::LumiBlockRange(*(*it));
piovSuspect->push_back(iovr);
}
}
//return(StatusCode::SUCCESS);
}
if(m_cacheOutputRangeContainer->size()>0) {
msg(MSG::INFO) << "OutputRangeCollection with size " << m_cacheOutputRangeContainer->size() << endreq;
m_cacheOutputRangeContainer->sort(xAOD::SortLumiBlockRangeByStart());
// Use tmp collection to do the merging
xAOD::LumiBlockRangeContainer* p_tempLBColl = new xAOD::LumiBlockRangeContainer();
xAOD::LumiBlockRangeAuxContainer* p_tempAuxLBColl = new xAOD::LumiBlockRangeAuxContainer();
p_tempLBColl->setStore( p_tempAuxLBColl );
// Sort and Merge LumiBlockRange objects if necessary
// Merge LumiBlockRange objects for same run and lumiblock
xAOD::LumiBlockRangeContainer::const_iterator i = m_cacheOutputRangeContainer->begin();
xAOD::LumiBlockRangeContainer::const_iterator ie = m_cacheOutputRangeContainer->end();
xAOD::LumiBlockRangeContainer::const_iterator ilast = m_cacheOutputRangeContainer->begin();
xAOD::LumiBlockRange* iovr = new xAOD::LumiBlockRange(*(*i));
p_tempLBColl->push_back(iovr);
ATH_MSG_INFO( "Push_back tmpLBColl with run "
<< (*i)->startRunNumber() << " LB " << (*i)->startLumiBlockNumber() << " events seen "
<< (*ilast)->eventsExpected() << " expected " << (*i)->eventsExpected());
i++;
while (i != ie) {
if( ((*i)->startRunNumber()==(*ilast)->startRunNumber()) &&
((*i)->stopRunNumber()==(*ilast)->stopRunNumber()) &&
((*i)->startLumiBlockNumber()==(*ilast)->startLumiBlockNumber()) &&
((*i)->startLumiBlockNumber()==(*ilast)->startLumiBlockNumber()) ) {
if((*ilast)->eventsExpected()!=(*i)->eventsExpected()) {
ATH_MSG_WARNING( "Error: tmpLBColl with run " << (*i)->startRunNumber() << " LB " << (*i)->startLumiBlockNumber() << " events expected "
<< (*ilast)->eventsExpected() << " and " << (*i)->eventsExpected() );
}
else {
ATH_MSG_INFO( "Merge Run " << (*i)->startRunNumber() << " LB " << (*i)->startLumiBlockNumber() << " events seen "
<< (*ilast)->eventsSeen() << "+" << (*i)->eventsSeen() << " and events expected "
<< (*ilast)->eventsExpected() );
iovr->setEventsSeen((*i)->eventsSeen()+(*ilast)->eventsSeen());
}
}
else {
iovr = new xAOD::LumiBlockRange(*(*i));
ATH_MSG_INFO( "Push_back tmpLBColl with run " << (*i)->startRunNumber() << " LB " << (*i)->startLumiBlockNumber() << " events seen "
<< (*ilast)->eventsExpected() << "+" << (*i)->eventsExpected() );
p_tempLBColl->push_back(iovr);
ilast = i;
}
i++;
}
LumiBlockCollection*
LumiBlockMetaDataTool::GetCopyOfCollection( const LumiBlockCollection& lbc )
{
LumiBlockCollection* copyColl = new LumiBlockCollection();
LumiBlockCollection::const_iterator itr(lbc.begin()), end(lbc.end());
for (; itr!=end; ++itr) { copyColl->push_back(new LB_IOVRange(*(*itr))); }
copyColl->sort(LumiBlockCollection::SortIOVRangeByStart());
for(it=p_tempLBColl->begin(); it!=p_tempLBColl->end(); it++) {
xAOD::LumiBlockRange* iovr = new xAOD::LumiBlockRange(*(*it));
if((*it)->eventsSeen() == (*it)->eventsExpected() ) {piovComplete->push_back(iovr);}
else if((*it)->eventsSeen() > (*it)->eventsExpected() ) {piovSuspect->push_back(iovr);}
else {piovUnfinished->push_back(iovr);}
}
delete p_tempLBColl;
}
return copyColl;
}
if(piovComplete->size()>0) {
ATH_MSG_INFO( "Number of Complete LumiBlocks:" << piovComplete->size() );
xAOD::LumiBlockRangeContainer::const_iterator it;
for(it=piovComplete->begin(); it!=piovComplete->end(); it++) {
msg(MSG::INFO) << "\t [ ("
<< (*it)->startRunNumber() << "," << (*it)->startLumiBlockNumber()
<< "):("
<< (*it)->startRunNumber() << "," << (*it)->startLumiBlockNumber()
<< ") eventsSeen = " << (*it)->eventsSeen()
<< ", eventsExpected = " << (*it)->eventsExpected()
<< " ]"
<< endreq;
}
}
LumiBlockCollection*
LumiBlockMetaDataTool::FilterOnDQFlags( const LumiBlockCollection& lbc,
const std::vector<std::string>& grlnameVec,
const std::vector<std::string>& brlnameVec )
{
LumiBlockCollection* iovc = new LumiBlockCollection();
bool somethingtostore(false);
int lastoklbnr(-1), cur_runnbr(-1), cur_lbstart(-1), cur_lbstop(-1);
for( LumiBlockCollection::const_iterator it=lbc.begin(); it != lbc.end(); ++it ) {
const LB_IOVRange* iovr = (*it);
cur_runnbr = iovr->start().run();
cur_lbstart = iovr->start().event();
cur_lbstop = iovr->stop().event();
for (int lbnr=cur_lbstart; lbnr<=cur_lbstop; ++lbnr) {
bool lbOk = m_GoodRunsListSelectorTool->passRunLB(cur_runnbr,lbnr,grlnameVec,brlnameVec);
if (lbOk) {
lastoklbnr=lbnr; // store last known good lb's number
if (!somethingtostore) { // fresh lb-range?
somethingtostore=true;
cur_lbstart = lbnr;
}
} else if (somethingtostore) {
iovc->push_back( new LB_IOVRange(IOVTime(cur_runnbr, cur_lbstart),IOVTime(cur_runnbr, lastoklbnr)) );
somethingtostore=false;
}
if(piovUnfinished->size()>0) {
ATH_MSG_INFO( "Number of Unfinished LumiBlocks:" << piovUnfinished->size() );
xAOD::LumiBlockRangeContainer::const_iterator it;
for(it=piovUnfinished->begin(); it!=piovUnfinished->end(); it++) {
msg(MSG::INFO) << "\t [ ("
<< (*it)->startRunNumber() << "," << (*it)->startLumiBlockNumber()
<< "):("
<< (*it)->startRunNumber() << "," << (*it)->startLumiBlockNumber()
<< ") eventsSeen = " << (*it)->eventsSeen()
<< ", eventsExpected = " << (*it)->eventsExpected()
<< " ]"
<< endreq;
}
// store remaining good iovrange
if (somethingtostore) {
iovc->push_back( new LB_IOVRange(IOVTime(cur_runnbr, cur_lbstart),IOVTime(cur_runnbr, lastoklbnr)) );
somethingtostore=false;
}
if(piovSuspect->size()>0) {
ATH_MSG_INFO( "Number of Suspect LumiBlocks:" << piovSuspect->size() );
xAOD::LumiBlockRangeContainer::const_iterator it;
for(it=piovSuspect->begin(); it!=piovSuspect->end(); it++) {
msg(MSG::INFO) << "\t [ ("
<< (*it)->startRunNumber() << "," << (*it)->startLumiBlockNumber()
<< "):("
<< (*it)->startRunNumber() << "," << (*it)->startLumiBlockNumber()
<< ") eventsSeen = " << (*it)->eventsSeen()
<< ", eventsExpected = " << (*it)->eventsExpected()
<< " ]"
<< endreq;
}
}
iovc->sort(LumiBlockCollection::SortIOVRangeByStart());
return iovc;
}
StatusCode LumiBlockMetaDataTool::fillFromXML(LumiBlockCollection* lbc_target,
const std::string& xmlString) {
ATH_MSG_INFO( "Entering LumiBlockMetaDataTool::fillFromXML with xmlString " << xmlString );
ATH_MSG_INFO( "Try decoding it" );
std::string decoded_string;
urldecode::decoder_state state;
state.state = urldecode::ST_SYM;
std::pair<std::string,int> decoded = urldecode::urldecode(&state, xmlString, xmlString.size());
decoded_string = decoded.first;
if (decoded.second < 0) {
ATH_MSG_INFO( "URL Decoding failed : " << decoded_string << " . Trying undecoded string instead." );
decoded_string = xmlString;
//return StatusCode::FAILURE;
}
// Use parser from GoodRunsLists package (Root based)
Root::TGoodRunsListReader reader;
ATH_MSG_DEBUG( "Now parsing xml string " << decoded_string );
reader.SetXMLString(decoded_string);
if (!reader.Interpret()) {
ATH_MSG_WARNING( "GRL interpretation failed : " << decoded_string << " . Return Failure." );
return StatusCode::FAILURE;
} else {
ATH_MSG_DEBUG( "GRL interpretation successful." );
}
// Since parse worked, get the good run list
Root::TGoodRunsList grl = reader.GetMergedGoodRunsList();
// A GoodRunsList is simply a map of run to list of lumiblock ranges
// Iterate over runs
for (std::map<Int_t,Root::TGoodRun>::const_iterator it = grl.begin(); it != grl.end(); it++) {
int run = it->first;
// Iterate over lumiblock ranges for that run and fill LumiBlockCollection argument
ATH_MSG_INFO( "About to fill LBCollection with " << it->second.size() << "items" );
for (std::vector<Root::TLumiBlockRange>::const_iterator lbrit = it->second.begin(); lbrit != it->second.end(); lbrit++) {
lbc_target->push_back(new LB_IOVRange(IOVTime(run, lbrit->Begin()), IOVTime(run, lbrit->End())));
}
// Ready for next LumiBlockCollection
} // grl loop
return StatusCode::SUCCESS;
}
StatusCode
LumiBlockMetaDataTool::RecordInMetaDataStore( LumiBlockCollection* plbc, const TString& lbcname )
{
StatusCode sc = StatusCode::SUCCESS;
if (plbc->empty()) {
ATH_MSG_DEBUG("RecordInMetaDataStore() : Input lbc is empty. Not storing in MetaDataStore " );
return sc;
}
if (m_pMetaDataStore->contains<LumiBlockCollection>(lbcname.Data())) {
DataHandle<LumiBlockCollection> tmp;
StatusCode ss = m_pMetaDataStore->retrieve(tmp,lbcname.Data());
if(ss.isSuccess()) { m_pMetaDataStore->remove(tmp.ptr()); }
else {
ATH_MSG_ERROR("Error removing exisiting LB collection <" << lbcname << "> from MetaDataStore " );
}
// Store the LumiBlockRangeContainer in the metadata store
// =======================================================
if(piovComplete->size()>0) {
ATH_MSG_INFO( "Write Complete LumiBlocks with size " << piovComplete->size());
ATH_CHECK( m_pMetaDataStore->record( piovComplete, m_LBColl_name ) );
ATH_CHECK( m_pMetaDataStore->record( piovCompleteAux, m_LBColl_name + "Aux." ) );
}
sc = m_pMetaDataStore->record(plbc, lbcname.Data());
if (!sc.isSuccess()) {
ATH_MSG_ERROR( "Could not record LumiBlockColl : " << lbcname );
} else {
ATH_MSG_DEBUG( "RecordInMetaDataStore() : Stored lbc <" << lbcname << "> in MetaDataStore " );
if(piovUnfinished->size()>0) {
ATH_MSG_INFO( "Write Unfinished LumiBlocks with size " << piovUnfinished->size());
ATH_CHECK( m_pMetaDataStore->record( piovUnfinished, m_unfinishedLBColl_name ) );
ATH_CHECK( m_pMetaDataStore->record( piovUnfinishedAux, m_unfinishedLBColl_name + "Aux." ) );
}
return sc;
}
StatusCode
LumiBlockMetaDataTool::AddDQCollections( const LumiBlockCollection& lbc, const TString& lbcprefix, const TString& grlprefix )
{
StatusCode sc = StatusCode::SUCCESS;
if (lbc.empty()) return sc;
ATH_CHECK( m_GoodRunsListSelectorTool.retrieve() );
/// construct metadata from triggers passed to lumicalcsvc
/// may be overwritten below
//std::map<TString,TString> metadata;
//for (unsigned int j=0; j<m_lcSvc->getTriggerList().size(); ++j)
// metadata[Form("TriggerChain%d",j)] = m_lcSvc->getTriggerList()[j];
const std::map< std::string, vvPair >& grlselectors = m_GoodRunsListSelectorTool->getGRLSelectorRegistry();
const std::map< TString, tvtPair >& trigselectors = m_TriggerRegistryTool->getTriggerSelectorRegistry();
std::map< TString, tvtPair >::const_iterator trItr;
LumiBlockCollection* iovc(0);
Root::TGoodRunsList* grl(0);
TString lbcname, grldescription, grlquery, trigselector, trigselection;
std::list<TString> trignames;
// multiple final states, specific grl selectors have been defined.
if (!grlselectors.empty()) {
std::map< std::string, vvPair >::const_iterator gsItr = grlselectors.begin();
for (int i=0; gsItr!=grlselectors.end(); ++gsItr, ++i) {
// get grl selection info
const std::vector<std::string>& grlnameVec = gsItr->second.first;
const std::vector<std::string>& brlnameVec = gsItr->second.second;
// get trigger selection info
trigselector=gsItr->first;
trItr = trigselectors.find(trigselector);
trigselection = (trItr!=trigselectors.end() ? trItr->second.first : "");
trignames = (trItr!=trigselectors.end() ? trItr->second.second : std::list<TString>());
// get lbc with DQ criteria applied and store in metadata
iovc = this->FilterOnDQFlags(lbc,grlnameVec,brlnameVec) ;
lbcname = lbcprefix + Form("%d",i);
sc = this->RecordInMetaDataStore(iovc,lbcname); // iovc taken over by metadatastore
if (!sc.isSuccess()) {
ATH_MSG_ERROR( "Could not store in metadatastore LumiBlockColl: " << lbcname );
return sc;
}
// make corresponding grl, store below
grlquery = "";
grl = m_converter->GetGRLObject(*iovc,std::map<TString,TString>(),m_version.c_str());
grl->SetName(lbcname.Data());
grldescription = grlprefix + gsItr->first;
// only one input grl: copy metadata from there
if (grlnameVec.size()==1)
if ( m_GoodRunsListSelectorTool->getGRLCollection()->HasGoodRunsList(grlnameVec[0]) )
grl->SetMetaData( m_GoodRunsListSelectorTool->getGRLCollection()->find(grlnameVec[0])->GetMetaData() );
// add descr name to metadata
grl->AddMetaData("Description",grldescription);
// add additional grl metadata
std::vector<std::string>::const_iterator gitr;
int gj;
for (gj=0, gitr=grlnameVec.begin(); gitr!=grlnameVec.end(); ++gj, ++gitr) {
grlquery += "_OR_"+(*gitr);
grl->AddMetaData(Form("GoodRunsList%d",gj),(*gitr));
}
for (gj=0, gitr=brlnameVec.begin(); gitr!=brlnameVec.end(); ++gj, ++gitr) {
grlquery += "_AND_NOT_"+(*gitr);
grl->AddMetaData(Form("BadRunsList%d",gj),(*gitr));
}
if (!grlquery.IsNull()) {
grl->AddMetaData("GRLQuery",grlquery);
grldescription += " __ GRLQuery = "+grlquery;
}
// add additional trigger metadata
std::list<TString>::iterator titr=trignames.begin();
for (int tj=0; titr!=trignames.end(); ++titr, ++tj)
grl->AddMetaData(Form("TriggerName%d",tj),*titr);
if (!trigselection.IsNull()) {
grl->AddMetaData("SelectionTrigger",trigselection);
grldescription += " __ TriggerSelection = "+trigselection;
}
// and store grl
if (!grl->IsEmpty()) {
grl->Compress(); // MB: delete duplicate LBs, seen on first data
m_grlcollection->push_back(*grl);
}
delete grl;
// register corresponding lb collection in lumicalcsvc
m_lcSvc->registerLBCollection(lbcname,grldescription,trignames);
}
// grlselector tool run as preeventselector tool, one grl selection only
} else {
// get lbc with DQ criteria applied and store in metadata
iovc = this->FilterOnDQFlags(lbc) ;
lbcname = lbcprefix + "0";
sc = this->RecordInMetaDataStore(iovc,lbcname); // iovc taken over by metadatastore
if (!sc.isSuccess()) {
ATH_MSG_ERROR( "Could not store in metadatastore LumiBlockColl: " << lbcname );
return sc;
}
// get trigger selection info
trItr = trigselectors.begin(); // one instance of GRL tool, so assume one trigger selection only
trigselection = (trItr!=trigselectors.end() ? trItr->second.first : "");
trignames = (trItr!=trigselectors.end() ? trItr->second.second : std::list<TString>());
// construct corresponding grl
grlquery = "";
grl = m_converter->GetGRLObject(*iovc,std::map<TString,TString>(),m_version.c_str());
grl->SetName(lbcname.Data());
grldescription = grlprefix + "uniquegrlselector";
// copy existing metadata
if ( m_GoodRunsListSelectorTool->getGRLCollection()->size()==1 )
grl->SetMetaData( m_GoodRunsListSelectorTool->getGRLCollection()->begin()->GetMetaData() );
// add descr name to metadata
grl->AddMetaData("Description",grldescription);
// add additional grl metadata
std::vector<Root::TGoodRunsList>::const_iterator gitr;
int gj;
for (gj=0, gitr=m_GoodRunsListSelectorTool->getGRLCollection()->begin(); gitr!=m_GoodRunsListSelectorTool->getGRLCollection()->end(); ++gj, ++gitr) {
grlquery += TString("_OR_")+gitr->GetName();
grl->AddMetaData(Form("GoodRunsList%d",gj),gitr->GetName());
}
for (gj=0, gitr=m_GoodRunsListSelectorTool->getBRLCollection()->begin(); gitr!=m_GoodRunsListSelectorTool->getBRLCollection()->end(); ++gj, ++gitr) {
grlquery += TString("_AND_NOT_")+gitr->GetName();
grl->AddMetaData(Form("BadRunsList%d",gj),gitr->GetName());
}
if (!grlquery.IsNull()) {
grl->AddMetaData("GRLQuery",grlquery);
grldescription += " __ GRLQuery = "+grlquery;
}
// add additional trigger metadata
std::list<TString>::iterator titr=trignames.begin();
for (int tj=0; titr!=trignames.end(); ++titr, ++tj)
grl->AddMetaData(Form("TriggerName%d",tj),*titr);
if (!trigselection.IsNull()) {
grl->AddMetaData("SelectionTrigger",trigselection);
grldescription += " __ TriggerSelection = "+trigselection;
}
// store grl
if (!grl->IsEmpty()) {
grl->Compress(); //// MB: delete duplicate LBs. Seen when merging dpds
m_grlcollection->push_back(*grl);
}
delete grl;
// register corresponding lb collection in lumicalcsvc
m_lcSvc->registerLBCollection(lbcname,grldescription,trignames);
if(piovSuspect->size()>0) {
ATH_MSG_INFO( "Write Suspect LumiBlocks with size " << piovSuspect->size());
ATH_CHECK( m_pMetaDataStore->record( piovSuspect, m_suspectLBColl_name ) );
ATH_CHECK( m_pMetaDataStore->record( piovSuspectAux, m_suspectLBColl_name + "Aux." ) );
}
return sc;
return(StatusCode::SUCCESS);
}
const TString
LumiBlockMetaDataTool::getGRLString( const TString& grlname ) const
{
/*
std::vector< Root::TGoodRunsList >::const_iterator itr = m_grlcollection->find( grlname );
if (itr!=m_grlcollection->end())
return m_converter->GetXMLString(*itr);
ATH_MSG_WARNING("getGRLString() : GoodRunsList with name <" << grlname << "> not found. Return empty string." );
*/
return "";
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment