diff --git a/ForwardDetectors/AFP/AFP_DBTools/AFP_DBTools/SiAlignDBTester.h b/ForwardDetectors/AFP/AFP_DBTools/AFP_DBTools/SiAlignDBTester.h new file mode 100644 index 0000000000000000000000000000000000000000..d5fe8f9860acf7f3b65205714f23c2f072858768 --- /dev/null +++ b/ForwardDetectors/AFP/AFP_DBTools/AFP_DBTools/SiAlignDBTester.h @@ -0,0 +1,44 @@ +/* + Copyright (C) 2002-2021 CERN for the benefit of the ATLAS collaboration +*/ +#ifndef AFP_DBTOOLS_SIALIGNDBTESTER_H +#define AFP_DBTOOLS_SIALIGNDBTESTER_H + +#include "AthenaBaseComps/AthAlgorithm.h" +#include "StoreGate/ReadCondHandle.h" +#include "GaudiKernel/ServiceHandle.h" +#include "AthenaKernel/CondCont.h" +#include <string> + +#include "AthenaPoolUtilities/AthenaAttributeList.h" +#include "AthenaPoolUtilities/CondAttrListCollection.h" + +#include "CaloConditions/CaloLocalHadCoeff.h" +#include "GaudiKernel/EventContext.h" + +/** + * @class SiAlignDBTester + * @brief + **/ +class SiAlignDBTester : public AthAlgorithm { +public: + SiAlignDBTester(const std::string& name, ISvcLocator* pSvcLocator); + virtual ~SiAlignDBTester() override; + + virtual StatusCode initialize() override; + virtual StatusCode execute() override; + virtual StatusCode finalize() override; + +private: + SG::ReadCondHandleKey<CondAttrListCollection> m_rch_locshiftX {this, "locshiftXkey", "/FWD/AFP/LocalAlignment", "read cond handle local shiftXkey"}; + SG::ReadCondHandleKey<CondAttrListCollection> m_rch_globshiftX {this, "globshiftXkey", "/FWD/AFP/GlobalAlignment", "read cond handle global shiftXkey"}; + SG::ReadCondHandleKey<AthenaAttributeList> m_readKey { this, "BeamSpotFolder", "/Indet/Beampos", "DB folder from which to read raw beam spot data" }; + SG::ReadCondHandleKey<CaloLocalHadCoeff> m_key; + +}; + +#ifndef __CINT__ + CLASS_DEF( SiAlignDBTester , 8327923 , 1 ) +#endif + +#endif // AFP_DBTOOLS_SIALIGNDBTESTER_H diff --git a/ForwardDetectors/AFP/AFP_DBTools/CMakeLists.txt b/ForwardDetectors/AFP/AFP_DBTools/CMakeLists.txt index e5752d21f16d5cc49465befb33e9a8561ceeed5c..ecd67a9e4212e0fe8389ce34778df7b05d4900c8 100644 --- a/ForwardDetectors/AFP/AFP_DBTools/CMakeLists.txt +++ b/ForwardDetectors/AFP/AFP_DBTools/CMakeLists.txt @@ -10,7 +10,7 @@ find_package( Boost ) atlas_add_component( AFP_DBTools src/*.cxx src/components/*.cxx - LINK_LIBRARIES ${Boost_LIBRARIES} AthenaBaseComps AthenaKernel AthenaPoolUtilities ) + LINK_LIBRARIES ${Boost_LIBRARIES} AthenaBaseComps AthenaKernel AthenaPoolUtilities CaloConditions GaudiKernel StoreGateLib ) # Install files from the package: atlas_install_python_modules( python/*.py POST_BUILD_CMD ${ATLAS_FLAKE8} ) diff --git a/ForwardDetectors/AFP/AFP_DBTools/scripts/AFPLocalAlignDBCreate.py b/ForwardDetectors/AFP/AFP_DBTools/scripts/AFPLocalAlignDBCreate.py index 99cd27dc79df48a482456ebe4ef30a849fc912de..a58e2fe145052c13aa98e67c9d95f9dba2272766 100644 --- a/ForwardDetectors/AFP/AFP_DBTools/scripts/AFPLocalAlignDBCreate.py +++ b/ForwardDetectors/AFP/AFP_DBTools/scripts/AFPLocalAlignDBCreate.py @@ -54,7 +54,8 @@ def makeFolderAndSpec(db,folderName,tag): runLumi=True - folder=AtlCoolLib.ensureFolder(db,folderName,spec,AtlCoolLib.athenaDesc(runLumi,'AthenaAttributeList'),cool.FolderVersioning.MULTI_VERSION) + # if there are more channels, use "CondAttrListCollection"; if there is only one channel, use "AthenaAttributeList" + folder=AtlCoolLib.ensureFolder(db,folderName,spec,AtlCoolLib.athenaDesc(runLumi,'CondAttrListCollection'),cool.FolderVersioning.MULTI_VERSION) if(folder is None): sys.exit(1) @@ -84,15 +85,15 @@ def savePayload(folderBlk, stationID, layerID=-1, alignType="None", shiftX=0.0, payload=cool.Record(folderBlk.spec) # station 0 occupies channels 0-3, station 1 occupies channels 4-7, ..., and station 3 occupies channels 12-15 - # if you are insterested in e.g. "RP" constants, look at channels 1, 5, 9, and 13 + # if you are insterested in e.g. "beam" constants, look at channels 1, 5, 9, and 13 channel=0 if(alignType!="None"): channel=stationID*4 if(alignType=="tracker"): channel+=0 - elif(alignType=="RP"): - channel+=1 elif(alignType=="beam"): + channel+=1 + elif(alignType=="RP"): channel+=2 elif(alignType=="correction"): channel+=3 diff --git a/ForwardDetectors/AFP/AFP_DBTools/scripts/testAFPLocalDB.py b/ForwardDetectors/AFP/AFP_DBTools/scripts/testAFPLocalDB.py new file mode 100644 index 0000000000000000000000000000000000000000..e3147cb79f8e5ed819758b5c44fec6d35889123c --- /dev/null +++ b/ForwardDetectors/AFP/AFP_DBTools/scripts/testAFPLocalDB.py @@ -0,0 +1,87 @@ +#!/bin/env python + +# Copyright (C) 2002-2021 CERN for the benefit of the ATLAS collaboration + +# file testAFPLocalDB.py +# author Petr Balek <petr.balek@cern.ch> (with a lot of inspiration from Tomasz Bold) +# date 2021-03-22 + +# brief A script that will test reading from the local DB file. In order to test it: +# 0. setup athena enviroment +# 1. have the local database; either get it from somewhere else (will be done in future), or create a new one with AFPLocalAlignDBCreate.py: +# $ python AFPLocalAlignDBCreate.py +# 2. run this script as (feel free to change the input file): +# $ python testAFPLocalDB.py --filesInput=/afs/cern.ch/user/p/pbalek/workspace/public/data17_13TeV.00338480.physics_Main.daq.RAW/data17_13TeV.00338480.physics_Main.daq.RAW._lb0275._SFO-7._0007.data +# 2a. for another alignment constants, try this input file (n.b.: local constants are the same, only global are different): +# $ python testAFPLocalDB.py --filesInput=/afs/cern.ch/user/p/pbalek/workspace/public/data17_13TeV.00333380.physics_Main.daq.RAW/data17_13TeV.00333380.physics_Main.daq.RAW._lb0163._SFO-7._0001.data +# 3. the script will read the files and print out alignment variables for the events in the input file (based on run number and LB) + +# footnote: for the python setup with TopLocRecSeq, see AFP_LocReco/AFP_LocReco_joboptions.py + +from AthenaConfiguration.ComponentAccumulator import CompFactory, ComponentAccumulator + +def testAFPLocalDBCfg(flags): + acc = ComponentAccumulator() + + from IOVDbSvc.IOVDbSvcConfig import addFoldersSplitOnline + from IOVDbSvc.IOVDbSvcConfig import addFolders + + # these are two randomly picked conditions, checked for comparison + acc.merge(addFolders(flags, '/CALO/HadCalibration2/CaloEMFrac', 'CALO_ONL', className='CaloLocalHadCoeff', db='CONDBR2')) + acc.merge(addFoldersSplitOnline(flags, "INDET", "/Indet/Onl/Beampos", "/Indet/Beampos", className="AthenaAttributeList")) + + # set from where to read the local information + schema = "<db>sqlite://;schema=Example.db;dbname=CONDBR2</db>" + locFolder = "/FWD/AFP/LocalAlignment" + locTag = "<tag>AFPAlignLoc-00</tag>" + globFolder = "/FWD/AFP/GlobalAlignment" + globTag = "<tag>AFPAlignGlob-00</tag>" + acc.merge(addFolders(flags, schema+locFolder+locTag, className='CondAttrListCollection', db='CONDBR2' )) + acc.merge(addFolders(flags, schema+globFolder+globTag, className='CondAttrListCollection', db='CONDBR2' )) + + acc.addCondAlgo(CompFactory.SiAlignDBTester()) + + return acc + + +if __name__ == "__main__": + from AthenaConfiguration.MainServicesConfig import MainServicesCfg + from AthenaConfiguration.AllConfigFlags import ConfigFlags as flags + + from AthenaCommon.Configurable import Configurable + Configurable.configurableRun3Behavior = 1 + + #flags.Input.Files = [] # can hardcode file + # if you have issues wiht data dependencies and want to debug it + flags.Scheduler.CheckDependencies = True + flags.Scheduler.ShowDataDeps = True + flags.Scheduler.ShowDataFlow = True + flags.Scheduler.ShowControlFlow = True + flags.Scheduler.EnableVerboseViews = True + + # more threads and more concurent events; change both to 1 if something goes wrong + flags.Concurrency.NumThreads = 3 + flags.Concurrency.NumConcurrentEvents = 5 + + flags.Exec.MaxEvents = 500 + + # AFPP align constants are not included in these (yet) + flags.IOVDb.GlobalTag = "CONDBR2-BLKPA-2017-16" + flags.GeoModel.AtlasVersion = "ATLAS-R2-2016-01-00-01" + + acc = MainServicesCfg(flags) + parser = flags.getArgumentParser() + args = flags.fillFromArgs(parser=parser) + + flags.lock() + + + from ByteStreamCnvSvc.ByteStreamConfig import ByteStreamReadCfg + acc.merge(ByteStreamReadCfg(flags)) + + acc.merge(testAFPLocalDBCfg(flags)) + from AthenaCommon.Constants import DEBUG, VERBOSE + acc.foreach_component("*AFP*").OutputLevel=VERBOSE + acc.foreach_component("SiAlignDBTester").OutputLevel=DEBUG + acc.printConfig(withDetails=True, summariseProps=True) + acc.run() diff --git a/ForwardDetectors/AFP/AFP_DBTools/src/SiAlignDBTester.cxx b/ForwardDetectors/AFP/AFP_DBTools/src/SiAlignDBTester.cxx new file mode 100644 index 0000000000000000000000000000000000000000..782b7dbf97ad26c178b31cc79f588fbbcc944ce1 --- /dev/null +++ b/ForwardDetectors/AFP/AFP_DBTools/src/SiAlignDBTester.cxx @@ -0,0 +1,113 @@ +/* + Copyright (C) 2002-2021 CERN for the benefit of the ATLAS collaboration +*/ + +#include "AFP_DBTools/SiAlignDBTester.h" + +SiAlignDBTester::SiAlignDBTester(const std::string& name, ISvcLocator* pSvcLocator) : + AthAlgorithm(name, pSvcLocator), m_key("EMFracClassify") +{ + ATH_MSG_DEBUG("in the constructor of SiAlignDBTester"); +} + +SiAlignDBTester::~SiAlignDBTester() +{ + ATH_MSG_DEBUG("in the destructor of SiAlignDBTester"); +} + +StatusCode SiAlignDBTester::initialize() +{ + ATH_MSG_DEBUG("in the initialize of SiAlignDBTester, hello there"); + + ATH_CHECK( m_key.initialize() ); + ATH_MSG_INFO( "m_key id: " << m_key.fullKey() ); + ATH_CHECK( m_readKey.initialize() ); + ATH_MSG_INFO( "m_readKey id: " << m_readKey.fullKey() ); + ATH_CHECK( m_rch_locshiftX.initialize() ); + ATH_MSG_INFO( "m_rch_locshiftX id: " << m_rch_locshiftX.fullKey() ); + ATH_CHECK( m_rch_globshiftX.initialize() ); + ATH_MSG_INFO( "m_rch_globshiftX id: " << m_rch_globshiftX.fullKey() ); + return StatusCode::SUCCESS; +} + +StatusCode SiAlignDBTester::finalize() +{ + ATH_MSG_DEBUG("in the finalize of SiAlignDBTester, bye bye"); + return StatusCode::SUCCESS; +} + +StatusCode SiAlignDBTester::execute() +{ + const EventContext& ctx = Gaudi::Hive::currentContext(); + EventIDBase t( getContext().eventID() ); + +// check if calo conditions can be loaded + ATH_MSG_INFO("execute: "<<getContext().eventID().event_number()<<" , before CaloLocalHadCoeff"); + SG::ReadCondHandle<CaloLocalHadCoeff> rch(m_key, ctx); + const CaloLocalHadCoeff* condObject = *rch; + if(condObject==0) { + ATH_MSG_ERROR("Unable to access conditions object CaloLocalHadCoeff"); + return StatusCode::FAILURE; + } + +// check if beamspot conditions can be loaded + ATH_MSG_INFO("execute: "<<getContext().eventID().event_number()<<" , before beam pos"); + SG::ReadCondHandle<AthenaAttributeList> readHandle{ m_readKey, ctx }; + const AthenaAttributeList* raw { *readHandle }; + if ( raw == nullptr ) + { + ATH_MSG_ERROR("Beam Spot data for key " << m_readKey.fullKey() << " not found"); + return StatusCode::FAILURE; + } + float beamposX { (*raw)["posX"].data<float>() }; + ATH_MSG_INFO("execute: "<<getContext().eventID().event_number()<<" , beam pos X = "<<beamposX); + +// load local AFP alignment and print out something + ATH_MSG_INFO("execute: "<<getContext().eventID().event_number()<<" , before loc shiftX"); + SG::ReadCondHandle<CondAttrListCollection> ch_locshiftX( m_rch_locshiftX, ctx ); + const CondAttrListCollection* attrLocList { *ch_locshiftX }; + if ( attrLocList == nullptr ) + { + ATH_MSG_ERROR("local shiftX data for key " << m_rch_locshiftX.fullKey() << " not found"); + return StatusCode::FAILURE; + } + CondAttrListCollection::const_iterator chanIt=attrLocList->begin(); + CondAttrListCollection::const_iterator chanIt_e=attrLocList->end(); + for(;chanIt!=chanIt_e;++chanIt) { + const unsigned channel=chanIt->first; + if (channel>16) { + ATH_MSG_ERROR("Found unexpected COOL-channel number:" << channel); + return StatusCode::FAILURE; + } + const coral::AttributeList& attr=chanIt->second; + float shiftX = (attr)["shiftX"].data<float>(); + int layerID = (attr)["layerID"].data<int>(); + ATH_MSG_INFO("execute: run "<<getContext().eventID().run_number()<<", lb "<<getContext().eventID().lumi_block()<<", evnt "<<getContext().eventID().event_number()<<", channel "<<channel<<", layerID "<<layerID<<", shiftX = "<<shiftX); + } + +// load global AFP alignment and print out something else + ATH_MSG_INFO("test: "<<getContext().eventID().event_number()<<" , before glob shiftX"); + SG::ReadCondHandle<CondAttrListCollection> ch_globshiftX( m_rch_globshiftX, ctx ); + const CondAttrListCollection* attrGlobList { *ch_globshiftX }; + if ( attrGlobList == nullptr ) + { + ATH_MSG_ERROR("global shiftX data for key " << m_rch_globshiftX.fullKey() << " not found"); + return StatusCode::FAILURE; + } + CondAttrListCollection::const_iterator chanIt2=attrGlobList->begin(); + CondAttrListCollection::const_iterator chanIt2_e=attrGlobList->end(); + for(;chanIt2!=chanIt2_e;++chanIt2) { + const unsigned channel=chanIt2->first; + if (channel>16) { + ATH_MSG_ERROR("Found unexpected COOL-channel number:" << channel); + return StatusCode::FAILURE; + } + const coral::AttributeList& attr2=chanIt2->second; + float shiftX = (attr2)["shiftX"].data<float>(); + std::string alignType = (attr2)["alignType"].data<std::string>(); + ATH_MSG_INFO("execute: run "<<getContext().eventID().run_number()<<", lb "<<getContext().eventID().lumi_block()<<", evnt "<<getContext().eventID().event_number()<<", channel "<<channel<<", align type "<<alignType<<" , shiftX = "<<shiftX); + } + + return StatusCode::SUCCESS; +} + diff --git a/ForwardDetectors/AFP/AFP_DBTools/src/components/AFP_DBTools_entries.cxx b/ForwardDetectors/AFP/AFP_DBTools/src/components/AFP_DBTools_entries.cxx index 5f68cbc0a4c93fda0efba44ed2cbfe9016034c2d..42a930f40d64d4d32d7706e1d754a06009439a8b 100644 --- a/ForwardDetectors/AFP/AFP_DBTools/src/components/AFP_DBTools_entries.cxx +++ b/ForwardDetectors/AFP/AFP_DBTools/src/components/AFP_DBTools_entries.cxx @@ -4,8 +4,10 @@ #include "AFP_DBTools/SiLocAlignDBTool.h" #include "AFP_DBTools/SiGlobAlignDBTool.h" +#include "AFP_DBTools/SiAlignDBTester.h" using namespace AFP; DECLARE_COMPONENT(SiLocAlignDBTool) DECLARE_COMPONENT(SiGlobAlignDBTool) +DECLARE_COMPONENT(SiAlignDBTester) diff --git a/ForwardDetectors/AFP/AFP_Reconstruction/AFP_LocReco/share/AFP_LocReco_joboption.py b/ForwardDetectors/AFP/AFP_Reconstruction/AFP_LocReco/share/AFP_LocReco_joboption.py index f26c1c12e84ff3042ba4436932c236642b4a6e6b..f73d49d6462bcd3fda4eabe8c1e088f74ef977b9 100644 --- a/ForwardDetectors/AFP/AFP_Reconstruction/AFP_LocReco/share/AFP_LocReco_joboption.py +++ b/ForwardDetectors/AFP/AFP_Reconstruction/AFP_LocReco/share/AFP_LocReco_joboption.py @@ -1,3 +1,5 @@ +# Copyright (C) 2002-2021 CERN for the benefit of the ATLAS collaboration + #============================================================== # Job options file for the ALFA_LocRec package #============================================================== @@ -35,3 +37,21 @@ else: # select algo for timing reco and parameters AFP_TDLocReco.ListAlgoTD = ["TDZVertex"] AFP_TDLocReco.AmpThresh = 10. + +#-- SiAlignDBTester part ------------------------------------------------------------ +# this is a setup for ReadCondHandle (see AFP_DBTools/SiAlignDBTester) + +# from IOVDbSvc.CondDB import conddb + +# conddb.addFolder("CALO","/CALO/HadCalibration2/CaloEMFrac", className='CaloLocalHadCoeff') +# conddb.addFolderSplitOnline("INDET","/Indet/Onl/Beampos", "/Indet/Beampos", className='AthenaAttributeList') + +# schema = "<db>sqlite://;schema=Example.db;dbname=CONDBR2</db>" +# folder = "/FWD/AFP/LocalAlignment" +# locTag="<tag>AFPAlignLoc-00</tag>" + +# conddb.addFolder("", schema+folder+locTag, className='CondAttrListCollection') + +# from AFP_DBTools.AFP_DBToolsConf import SiAlignDBTester +# TopLocRecSeq += SiAlignDBTester("SiAlignDBTester", OutputLevel=DEBUG) +