Commit 8cd142fc authored by Joerg Stelzer's avatar Joerg Stelzer Committed by Graeme Stewart
Browse files

SessionMgr: dont delete the ReplicaSorter (it leads to a crash) (TrigConfStorage-03-00-79)

	* SessionMgr: dont delete the ReplicaSorter (it leads to a crash)
	* TrigConfStorage-03-00-79

2015-01-26 Joerg Stelzer
	* CoolFix.cxx: new interactive executable to simplify fixing COOL folders at
	P1. Not complete yet, but solves ATR-9469
	* TrigConfStorage-03-00-78

2015-01-24 Joerg Stelzer
	* Making DB connection and retrial timeout configurable (ATR-9008)
	* TrigConfStorage-03-00-77

2015-01-23 Joerg Stelzer
	* Suppress errors when CTP files are not in the DB
	* TrigConfStorage-03-00-76

2015-01-22 Joerg Stelzer
	* fix loading of BG from COOL
	* TrigConfStorage-03-00-75

...
(Long ChangeLog diff - truncated)
parent a1bd50ed
......@@ -42,7 +42,7 @@ namespace TrigConf {
void startSession();
/** @brief commit session if not already done */
void commitSession();
void commitSession() const;
/** @brief get l1 master from super master */
bool loadL1MasterKey(int SuperMasterKey, int& Lvl1MasterKey);
......@@ -55,8 +55,8 @@ namespace TrigConf {
virtual int verbose() const { return m_verbose; }
virtual void setVerbose(int v) { m_verbose=v; }
bool isRun1() const { return ! isRun2(); }
bool isRun2() const;
bool isRun1() { return ! isRun2(); }
bool isRun2();
private:
int m_verbose;
......@@ -76,7 +76,7 @@ namespace TrigConf {
static unsigned int s_l1Version;
private:
void loadSchemaVersion();
void loadSchemaVersion() const;
private:
static ENV m_env;
......
......@@ -17,7 +17,10 @@ namespace coral {
class ISessionProxy;
}
namespace TrigConf {
class ReplicaSorter;
/**@brief Manager of the database session
*
......@@ -30,32 +33,6 @@ namespace TrigConf {
/**@brief constructor */
SessionMgr();
// /**@brief constructor
// *
// * @param cs connection string
// * @param user user name, if not specified the XML authentication will be used
// * @param password password string (only used in connection with a user name)
// * @param o output stream for all messages
// */
// SessionMgr( const std::string& cs,
// const std::string& user = "",
// const std::string& password = "");
// /**@brief constructor
// *
// * @param type Server technology
// * @param server Server name
// * @param name Database name, or schema name, or, if server and type are not specified, alias name for lookup
// * @param user user name, if not specified the XML authentication will be used
// * @param password password string (only used in connection with a user name)
// * @param o output stream for all messages
// */
// SessionMgr( const std::string& type,
// const std::string& server,
// const std::string& name,
// const std::string& user,
// const std::string& password);
/**@brief destructor*/
~SessionMgr();
......@@ -64,7 +41,6 @@ namespace TrigConf {
/**@brief instantiates the session*/
coral::ISessionProxy& createSession();
// coral::ISession& createSessionOld(int retrialPeriod=30, int retrialTimeout=300, int connectionTimeout=5);
/**@brief SQL -> C++ type conversion mapping for Oracle database to match MySQL*/
void setTypeConversionRules();
......@@ -94,7 +70,6 @@ namespace TrigConf {
const std::string & dbUser() const { return m_user; }
const std::string & dbPassword() const { return m_password; }
private:
void buildConnectionString();
......@@ -115,6 +90,9 @@ namespace TrigConf {
int m_retrialPeriod {0};
int m_retrialTimeout {0};
int m_connectionTimeout {0};
ReplicaSorter * m_replicaSorter { nullptr }; // private replica sorter in case of standalone usage of SessionMgr
};
}
......
......@@ -105,6 +105,14 @@ namespace TrigConf {
void setUseFrontier(bool useFrontier) { m_useFrontier = useFrontier; }
bool useFrontier() const { return m_useFrontier; }
void setRetrialPeriod(int retrialPeriod) { m_retrialPeriod = retrialPeriod; }
void setRetrialTimeout(int retrialTimeout) { m_retrialTimeout = retrialTimeout; }
void setConnectionTimeout(int connectionTimeout) { m_connectionTimeout = connectionTimeout; }
int retrialPeriod() const { return m_retrialPeriod; }
int retrialTimeout() const { return m_retrialTimeout; }
int connectionTimeout() const { return m_connectionTimeout; }
private:
template< class L >
......@@ -124,6 +132,11 @@ namespace TrigConf {
std::string m_password {""};///< password
bool m_useFrontier {false}; ///< using frontier to connect to oracle (if set, disables sqlite)
std::ostream & m_ostream; ///< output stream
int m_retrialPeriod {0};
int m_retrialTimeout {0};
int m_connectionTimeout {0};
};
}
......
......@@ -30,6 +30,7 @@ namespace TrigConf {
class TriggerThreshold;
class BunchGroupSet;
class PIT;
class TIP;
class ThresholdMonitor;
namespace TrigConfCoolL1PayloadConverters {
......@@ -85,7 +86,7 @@ namespace TrigConf {
const TrigConf::Menu& lvl1Menu);
/** @brief build a COOL db record from a PIT-mapping string value */
cool::Record createLvl1InputMapPayload(cool::IFolderPtr, const TrigConf::PIT& pit);
cool::Record createLvl1InputMapPayload(cool::IFolderPtr, const TrigConf::TIP& tip);
/**@brief build a COOL db record from a monitoring-mapping string value
......
......@@ -169,6 +169,9 @@ namespace TrigConf {
void writeL1MenuPayload( ValidityRange vr, const TrigConf::Menu& lvl1Menu);
void writeL1MenuPayload( const RunRangeVec& runRanges, const TrigConf::Menu& lvl1Menu);
void writeL1CTPCoreInputMapping( ValidityRange vr, const Menu& lvl1Menu);
/**@brief Writing L1 run-wise monitoring configuration to COOL
*
* @param runNumber run number
......@@ -357,7 +360,9 @@ namespace TrigConf {
* @param runNumber run number
* @returns L1 Menu pointer
*/
void readL1Menu(unsigned int runNumber, Menu& menu);
void readL1Menu(unsigned int runNumber, CTPConfig & ctpc);
std::vector<std::string> checkPayloadSize(unsigned int run, unsigned int lb=1);
void addWriteFolder(const std::string& fname) { m_writeFolderList.push_back( fname ); }
......@@ -367,6 +372,8 @@ namespace TrigConf {
bool checkDbConnection(bool readonly);
bool HLTPrescaleFolderExists();
private:
friend class AutoDBOpen;
......
......@@ -58,6 +58,8 @@ macro_append TrigConfStorage_linkopts " $(Boost_linkopts_regex) \
apply_pattern trigconf_application name=2COOLApp
apply_pattern trigconf_application name=ConsistencyChecker
apply_pattern trigconf_application name=ReadWrite
apply_pattern trigconf_application name=CoolFix
apply_pattern trigconf_application name=TestTriggerDBCoolMix
#============================================================================
......
......@@ -14,17 +14,21 @@ help() {
echo " -h|--help ..... this help"
echo " -x|--examples ..... show examples"
echo " -c|--createdb ..... (re)create cool db"
echo " -w|--what <what> ..... what=[l1menu|hltmenu|l1ps|hltps]"
echo " -w|--what <what> ..... what=[bginfo|l1menu|hltmenu|l1ps|hltps]"
echo " -r|--run <runNr> ..... run number"
echo " --lb <lb> ..... LB number"
echo " -s|--smk <smk> ..... SMK "
echo " --l1psk <runNr> ..... L1 PSK"
echo " -b|--bgk <bgk> ..... BG key"
exit 0
}
examples() {
echo "Examples:
BG info:
./$prog -w bginfo -r 1000 -b 474
L1 menu:
./$prog -w l1menu -r 1000 -s 875
......@@ -47,7 +51,8 @@ lbnr=0
smk=0
l1psk=0
hltpsk=0
cooldb="sqlite://;schema=$sqlitefile;dbname=TRIGCONF"
bgk=0
cooldb="sqlite://;schema=$sqlitefile;dbname=CONDBR2"
triggerdb="TRIGGERDB"
while [ $# -gt 0 ]
......@@ -57,6 +62,7 @@ do
-x|--examples) examples;;
-s|--smk) shift; smk=$1;;
-w|--what) shift; what=$1;;
-b|--lbk) shift; bgk=$1;;
--l1psk) shift; l1psk=$1;;
--hltpsk) shift; hltpsk=$1;;
--lb) shift; lbnr=$1;;
......@@ -69,7 +75,7 @@ do
done
case $what in
l1menu|hltmenu|l1ps|hltps) ;;
bginfo|l1menu|hltmenu|l1ps|hltps) ;;
*)
echo "--what is not specified"
help
......@@ -107,5 +113,13 @@ case $what in
--trigdb $triggerdb --configkey $smk --run $runnr --lumiblock $lbnr --prescalekeyhlt $hltpsk
fi
;;
bginfo)
if [ "$smk" -ne 0 -a "$bgk" -ne 0 -a "$runnr" -ne 0 ]; then
echo TrigConf2COOLApp -e writel1 --cooldb \'$cooldb\' \
--trigdb $triggerdb --configkey $smk --run $runnr --bgkey $bgk
else
echo "SMK or run nr or bg key is missing"
fi
;;
esac
echo AtlCoolConsole.py \'$cooldb\'
......@@ -480,9 +480,13 @@ void TrigConf::CTPFilesLoader::parseHexString(std::vector<u_int>& vec,const std:
static u_int postFix = 1;
static u_int wordsize = (preFix + significantBits + postFix);
if(str.size() != wordsize * vec.size()) {
TRG_MSG_ERROR("File content of size " << str.size() << ", but expects " << wordsize * vec.size() << " [11 * " << vec.size() << "]");
throw std::runtime_error( "CTPFilesLoader: file of unexpected size" );
if(str.size() != 0) {
if(str.size() != wordsize * vec.size()) {
TRG_MSG_ERROR("File content from DB of size " << str.size() << ", but expects " << wordsize * vec.size() << " [11 * " << vec.size() << "]");
throw std::runtime_error( "CTPFilesLoader: file of unexpected size" );
}
} else {
TRG_MSG_INFO("DB File content is 0, which is expected for MC, Reprocessing, and ATN databases");
}
for(u_int i=0; i < vec.size(); ++i) {
......
......@@ -49,21 +49,18 @@ void TrigConf::DBLoader::startSession()
}
}
void TrigConf::DBLoader::commitSession()
void TrigConf::DBLoader::commitSession() const
{
//if ( m_session.transaction().isActive() && m_sessionOwner && !m_session.transaction().isReadOnly()) {
if ( m_session.transaction().isActive() && m_sessionOwner) {
//std::cout << "DBLoader: commitSession()" << std::endl;
m_session.transaction().commit();
}
}
bool
DBLoader::isRun2() const {
if(s_run==0) {
throw std::runtime_error( "DBLoader::isRun2() schema has not been checked yet" );
}
DBLoader::isRun2() {
if(s_run==0)
loadSchemaVersion();
return s_run == 2;
}
......@@ -85,7 +82,7 @@ DBLoader::setLevel(MSGTC::Level lvl) {
void
DBLoader::loadSchemaVersion()
DBLoader::loadSchemaVersion() const
{
bool mySession = false;
if ( ! m_session.transaction().isActive() ) {
......@@ -93,24 +90,21 @@ DBLoader::loadSchemaVersion()
mySession = true;
}
coral::ITable& table = m_session.nominalSchema().tableHandle( "TRIGGER_SCHEMA");
coral::IQuery* query = table.newQuery();
query->setRowCacheSize( 1 );
std::unique_ptr< coral::IQuery > q( m_session.nominalSchema().tableHandle( "TRIGGER_SCHEMA").newQuery() );
q->setRowCacheSize( 1 );
//Output data and types
coral::AttributeList attList;
attList.extend<int>( "TS_ID" );
query->defineOutput(attList);
query->addToOutputList( "TS_ID" );
q->defineOutput(attList);
q->addToOutputList( "TS_ID" );
query->addToOrderList("TS_ID desc");
//query->limitReturnedRows(1); doesn't work with the proxy?
coral::ICursor& cursor = query->execute();
q->addToOrderList("TS_ID desc");
coral::ICursor& cursor = q->execute();
if ( ! cursor.next() ) {
TRG_MSG_ERROR("Table TRIGGER_SCHEMA is not filled");
delete query;
commitSession();
if ( mySession ) m_session.transaction().commit();
throw std::runtime_error( "DBLoader::loadSchemaVersion() >> Table TRIGGER_SCHEMA is not filled" );
}
......@@ -119,14 +113,8 @@ DBLoader::loadSchemaVersion()
TRG_MSG_INFO("TriggerDB schema version: " << s_triggerDBSchemaVersion);
delete query;
s_run = m_session.nominalSchema().existsTable( "ACTIVE_MASTERS" ) ? 2 : 1;
// for( const std::string & s : m_session.nominalSchema().listTables() ) {
// cout << " Existing table " << s << endl;
// }
TRG_MSG_INFO("Database has Run " << s_run << " schema");
TRG_MSG_INFO("Total number of tables : " << m_session.nominalSchema().listTables().size());
......
......@@ -21,7 +21,7 @@ TrigConf::HLTChainLoader::load( HLTFrame& frame ) {
m_smk=frame.smk();
m_schemaversion = triggerDBSchemaVersion();
TRG_MSG_INFO("TriggerDB Schema version: " << m_schemaversion);
TRG_MSG_INFO("Loading HLT chains");
HLTChainList& chains = frame.theHLTChainList();
......@@ -49,7 +49,7 @@ TrigConf::HLTChainLoader::load( HLTFrame& frame ) {
void
TrigConf::HLTChainLoader::loadChains( HLTChainList& chainlist ) {
TRG_MSG_INFO("Start loading chains with SMK " << m_smk);
TRG_MSG_INFO("Loading chains with SMK " << m_smk);
std::unique_ptr< coral::IQuery > q( m_session.nominalSchema().newQuery() );
......@@ -250,8 +250,6 @@ TrigConf::HLTChainLoader::loadStreams( HLTChainList& chainlist ) {
q->setCondition( theCondition, bindings );
fillQuery(q.get(),output);
q->setDistinct();
coral::ICursor& cursor = q->execute();
......@@ -264,7 +262,11 @@ TrigConf::HLTChainLoader::loadStreams( HLTChainList& chainlist ) {
string streamname = rmtilde(row["TR.HTR_NAME"].data<string>());
string type = rmtilde(row["TR.HTR_TYPE"].data<string>());
bool obeyLB = row["TR.HTR_OBEYLB"].data<int>();
int prescale = boost::lexical_cast<int,string>(prescale_str);
int prescale = 1;
try {
prescale = boost::lexical_cast<int,string>(prescale_str);
}
catch(boost::bad_lexical_cast & e) {}
chainlist.chain(chainname)->addStream( new HLTStreamTag(streamname, type, obeyLB, prescale) );
}
cursor.close();
......
......@@ -31,6 +31,8 @@ TrigConf::HLTFrameLoader::load( HLTFrame& frame ) {
unsigned int smk = frame.smk();
if(smk==0) return false;
TRG_MSG_INFO("Loading HLT menu for SMK " << smk);
typedef pair<unsigned int, unsigned int> lbnpsk_t;
vector<lbnpsk_t> reqested_prescale_keys = frame.getPrescaleSetCollection().prescale_keys();
......@@ -114,7 +116,7 @@ TrigConf::HLTFrameLoader::load( HLTFrame& frame ) {
}
}
frame.print();
//frame.print();
}
catch (const std::exception& e) {
TRG_MSG_ERROR("exception " << e.what());
......
......@@ -17,9 +17,8 @@ TrigConf::HLTSequenceLoader::load( HLTFrame& frame ) {
m_smk=frame.smk();
m_schemaversion = triggerDBSchemaVersion();
if(verbose())
msg() << "HLTSequenceLoader: TriggerDB Schema version: "
<< m_schemaversion << endl;
TRG_MSG_INFO("Loading HLT sequences");
HLTSequenceList& sequences = frame.theHLTSequenceList();
......@@ -29,7 +28,7 @@ TrigConf::HLTSequenceLoader::load( HLTFrame& frame ) {
commitSession();
}
catch (const std::exception& e) {
msg() << "HLTSequenceLoader: exception: " << e.what() << endl;
TRG_MSG_ERROR("exception caught and rethrown : " << e.what());
throw;
}
return true;
......
......@@ -17,6 +17,7 @@
#include "TrigConfL1Data/TriggerThreshold.h"
#include "TrigConfL1Data/ThresholdMonitor.h"
#include "TrigConfL1Data/PIT.h"
#include "TrigConfL1Data/TIP.h"
#include "TrigConfL1Data/L1DataDef.h"
#include "boost/lexical_cast.hpp"
......@@ -370,8 +371,8 @@ TrigConf::MenuLoader::loadThresholds(TrigConf::Menu& menu) {
loadPIT(menu);
if(verbose()>1)
menu.thresholdConfig().print();
createTipFromDirectThresholds(menu);
}
......@@ -382,6 +383,9 @@ TrigConf::MenuLoader::loadPIT(TrigConf::Menu& menu) {
DBLoader::getEnv() == DBLoader::CTPOnl ||
DBLoader::getEnv() == DBLoader::COOLL1) ) return;
set<int> tipNumbersUsed;
unique_ptr< coral::IQuery > q( m_session.nominalSchema().newQuery() );
q->addToTableList ( "L1_TM_TO_TT", "TM2TT" );
q->addToTableList ( "L1_PITS", "PITS" );
......@@ -440,10 +444,57 @@ TrigConf::MenuLoader::loadPIT(TrigConf::Menu& menu) {
pit->setThresholdActive(tt->active());
pit->setThresholdMapping(tt->mapping());
menu.addPit(pit);
int phase = 0;
if(tipNumbersUsed.count(pitnum) > 0) {
phase = 1;
} else {
tipNumbersUsed.insert(pitnum);
}
TIP* tip = new TIP();
tip->setThresholdName(tt->name());
tip->setSlot(slot);
tip->setConnector( con );
tip->setTipNumber(pitnum + 160 * phase);
tip->setClock(phase);
tip->setThresholdBit(bitnum);
tip->setCableBit( tt->cableStart() + bitnum );
tip->setTmToTtId(tmtott);
tip->setTriggerThresholdId(ttid);
tip->setThresholdActive(tt->active());
tip->setThresholdMapping(tt->mapping());
tip->setIsDirect(false);
menu.addTip(tip);
}
}
void
TrigConf::MenuLoader::createTipFromDirectThresholds(TrigConf::Menu& menu) {
for(TriggerThreshold * thr : menu.thresholdConfig().getThresholdVector() ) {
if(thr->ttype()==L1DataDef::TOPO) {
TIP* tip = new TIP();
tip->setThresholdName(thr->name());
tip->setSlot(10);
const string & conn = thr->cableConnector(); // "CON0", "CON1", "CON2"
tip->setConnector( conn[3]-'0' );
//cout << *thr << " mapping " << thr->mapping() << " clock " << thr->clock() << " bitnum " << thr->bitnum() << endl;
tip->setTipNumber( 320 + thr->mapping() );
tip->setThresholdBit( thr->clock() );
tip->setCableBit( thr->cableStart() );
tip->setTriggerThresholdId(thr->id() );
tip->setThresholdActive(thr->active());
tip->setThresholdMapping(thr->mapping());
tip->setIsDirect(true);
menu.addTip(tip);
}
}
}
void
TrigConf::MenuLoader::loadCaloInfo(TrigConf::Menu& menu) {
// load the CaloInfo
......
......@@ -51,6 +51,7 @@ namespace TrigConf {
void loadPIT(TrigConf::Menu& menu);
void loadItems(TrigConf::Menu& menu);
void loadMonitoring(TrigConf::Menu& menu);
void createTipFromDirectThresholds(TrigConf::Menu& menu);
/**@brief New versions for item definition in string*/
TriggerItemNode* constructTree(const std::string& def, const std::vector<ThrInfo>&);
......
......@@ -27,13 +27,13 @@
using namespace std;
bool
TrigConf::PrescaleSetLoader::load( PrescaleSet& psTarget ) {
TrigConf::PrescaleSetLoader::load( PrescaleSet& prescaleSet ) {
TRG_MSG_INFO("loading data with ID = " << psTarget.id());
TRG_MSG_INFO("loading L1 prescale set with PSK " << prescaleSet.id());
CTPdataformatVersion ctpformat(s_ctpVersion);
psTarget.resize(ctpformat.getMaxTrigItems());
prescaleSet.resize(ctpformat.getMaxTrigItems());
try {
startSession();
......@@ -44,7 +44,7 @@ TrigConf::PrescaleSetLoader::load( PrescaleSet& psTarget ) {
coral::AttributeList bindList;
bindList.extend<int>("psId");
std::string cond = "L1PS_ID = :psId";
bindList[0].data<int>() = psTarget.id();
bindList[0].data<int>() = prescaleSet.id();
q->setCondition( cond, bindList );
//Output data and types
......@@ -60,7 +60,7 @@ TrigConf::PrescaleSetLoader::load( PrescaleSet& psTarget ) {
coral::ICursor& cursor = q->execute();
if ( ! cursor.next() ) {
TRG_MSG_ERROR("No such prescaleset exists " << psTarget.id());
TRG_MSG_ERROR("No such prescaleset exists " << prescaleSet.id());
throw std::runtime_error( "PrescaleSetLoader >> PrescaleSet not available" );
}
......@@ -70,15 +70,15 @@ TrigConf::PrescaleSetLoader::load( PrescaleSet& psTarget ) {
std::string comment = row["L1PS_COMMENT"].data<std::string>();
// fill the object with data
psTarget.setName( name );
psTarget.setVersion( version );
psTarget.setComment( comment );
prescaleSet.setName( name );
prescaleSet.setVersion( version );
prescaleSet.setComment( comment );
for (unsigned int ctpid=0; ctpid < ctpformat.getMaxTrigItems(); ++ctpid) {
int64_t val = row["L1PS_VAL" + boost::lexical_cast<string,unsigned int>(ctpid+1)].data<int64_t>();
if(isRun1()) {
psTarget.setPrescale(ctpid,val);
prescaleSet.setPrescale(ctpid,val);
} else {
psTarget.setCut(ctpid,val);
prescaleSet.setCut(ctpid,val);
}
}
......
......@@ -28,7 +28,7 @@ namespace TrigConf {
class PrescaleSetLoader : virtual public IPrescaleSetLoader, public DBLoader {
public:
PrescaleSetLoader( StorageMgr& sm, coral::ISessionProxy& session) : DBLoader(sm, session) {}
PrescaleSetLoader( StorageMgr& sm, coral::ISessionProxy& session) : DBLoader("PrescaleSetLoader", sm, session) {}
virtual ~PrescaleSetLoader(){};
virtual bool load( PrescaleSet& data);
......