//***************************************************************************** // File: TriggerMap.cc // ---------------------------------------------------------------------------- // Type: Class implementation source // Package: Level3Mods // Class: TriggerMap // Language: Standard C++ // Project: CDF Run II Offline Software Upgrade // OrigAuth: Kevin McFarland, Tony Vaiciulis, Dmitri Litvintsev // Company: Fermilab //============================================================================= // RCS Current Revision Record //----------------------------------------------------------------------------- // $Source: /cdf/code/cdfcvs/run2/Level3Mods/src/TriggerMap.cc,v $ // $Revision: 1.18 $ // $Date: 2004/12/02 01:37:12 $ // $Author: litvinse $ // $State: Exp $ // $Locker: $ //***************************************************************************** //***************************************************************************** // Declarations and Definitions //***************************************************************************** #ifdef DEFECT_OLD_IOSTREAM_HEADERS #include #include #else #include #include #endif #ifdef DEFECT_OLD_STRINGSTREAM #include #define ostringstream ostrstream #else #include #endif // Namespace declarations of the above #ifndef DEFECT_NO_STDLIB_NAMESPACES using std::string; #endif #include using std::vector; #ifndef DEFECT_NO_IOSTREAM_NAMESPACES using std::cerr; using std::cout; using std::endl; using std::ostringstream ; using std::istringstream ; #endif #ifndef TRIGGERMAP_HH #include "Level3Mods/TriggerMap.hh" #endif #include "DBManager/ConControl.hh" #ifndef TRIGGERDB_HH #include "TriggerDB/tree/TriggerDB.hh" #endif //to get run number #include "AbsEnv/AbsEnv.hh" using namespace db; //***************************************************************************** // Class Implementation //***************************************************************************** //============================================================================= // Constructor //============================================================================= TriggerMap::TriggerMap(string databaseForTrigger) { // Get mapping of Level1 and Level2 triggers from online database // given a particular run number: // get trigger table name _triggerTableName.clear(); TriggerDB tdb(databaseForTrigger.c_str()); PhysicsTableKey pKey; pKey.setRunRange(gblEnv->runNumber()); PhysicsTables_var tables; Result res=tdb.findPhysicsTables(pKey,tables); if(res==Result::success) { if (tables->size()>1) { cerr << " found more than two Physics tables for run "<< gblEnv->runNumber() << endl; } PhysicsTable& table = tables->at(0); _triggerTableName = table.physicsTableName(); TriggerKey tkey(table.name(),table.tag()); if (table.daq_valid()==2) { tkey.setRun(gblEnv->runNumber()); } Triggers_var triggers; res=tdb.findTriggersForPhysicsTable(tkey,triggers); if(res==Result::success) { for(Triggers::iterator i=triggers->begin(); i!=triggers->end();++i){ if (i->level()==1) { _L1Bits.push_back(i->bit()); _L1Ids.push_back(i->id()); _L1Names.push_back(i->nameWithTag()); } else if (i->level()==2) { _L2Bits.push_back(i->bit()); _L2Ids.push_back(i->id()); _L2Names.push_back(i->nameWithTag()); } else if (i->level()==3) { _L3Bits.push_back(i->bit()); _L3Ids.push_back(i->id()); _L3Names.push_back(i->nameWithTag()); } } } else { cerr << " Failed to find Triggers " << res << endl; cerr << " retrieval using key " << tkey << endl; } } else { cerr << " Failed to find PhysicsTable" << endl; cerr << " retrieval using key " << pKey << endl; } // // this is a temporary kludge // ConControl::instance()->forceDisconnectAll(); } //============================================================================= // Destructor //============================================================================= TriggerMap::~TriggerMap() { } //============================================================================= // Print method //============================================================================= void TriggerMap::print() const{ vector::const_iterator theBit, theId; vector::const_iterator theName; std::cout << "Trigger Table Name: " << _triggerTableName << std::endl; std::cout << "L1 Triggers and Bits" << std::endl; theBit = _L1Bits.begin(); theName = _L1Names.begin(); theId = _L1Ids.begin(); while ( theBit != _L1Bits.end() ) { std::cout << *(theBit++) << " " << *(theName++) << " (Id#" << *(theId++) << ")" << std::endl; } std::cout << "L2 Triggers and Bits" << std::endl; theBit = _L2Bits.begin(); theName = _L2Names.begin(); theId = _L2Ids.begin(); while ( theBit != _L2Bits.end() ) { std::cout << *(theBit++) << " " << *(theName++) << " (Id#" << *(theId++) << ")" << std::endl; } std::cout << "L3 Triggers and Bits" << std::endl; theBit = _L3Bits.begin(); theName = _L3Names.begin(); theId = _L3Ids.begin(); while ( theBit != _L3Bits.end() ) { std::cout << *(theBit++) << " " << *(theName++) << " (Id#" << *(theId++) << ")" << std::endl; } } //============================================================================= // Accessors //============================================================================= int TriggerMap::getBit( const int triggerId, const int triggerLevel ) const{ int triggerBit=-1; vector::const_iterator theId; vector::const_iterator theBit; vector::const_iterator theIderEnd; // as opposed to theBitterEnd... if ( triggerLevel == 1 ) { theId = _L1Ids.begin(); theBit = _L1Bits.begin(); theIderEnd = _L1Ids.end(); } else if ( triggerLevel == 2 ) { theId = _L2Ids.begin(); theBit = _L2Bits.begin(); theIderEnd = _L2Ids.end(); } else if ( triggerLevel == 3 ) { theId = _L3Ids.begin(); theBit = _L3Bits.begin(); theIderEnd = _L3Ids.end(); } else return triggerBit; while ( theId != theIderEnd ) { if ( triggerId == *(theId++) ) { triggerBit = *theBit; } //std::cout << std::endl; theBit++; } return triggerBit; } int TriggerMap::getId( const int triggerBit, const int triggerLevel ) const{ int triggerId = -1; vector::const_iterator theBit; vector::const_iterator theId; vector::const_iterator theBiterEnd; // as opposed to theBitterEnd... if ( triggerLevel == 1 ) { theBit = _L1Bits.begin(); theId = _L1Ids.begin(); theBiterEnd = _L1Bits.end(); } else if ( triggerLevel == 2 ) { theBit = _L2Bits.begin(); theId = _L2Ids.begin(); theBiterEnd = _L2Bits.end(); } else if ( triggerLevel == 3 ) { theBit = _L3Bits.begin(); theId = _L3Ids.begin(); theBiterEnd = _L3Bits.end(); } else return triggerId; while ( theBit != theBiterEnd ) { if ( triggerBit == *(theBit++) ) { triggerId = *theId; } //std::cout << std::endl; theId++; } return triggerId; } string TriggerMap::getNameFromId( const int triggerId, const int triggerLevel ) const{ string triggerName; vector::const_iterator theId; vector::const_iterator theName; vector::const_iterator theIderEnd; // as opposed to theBitterEnd... if ( triggerLevel == 1 ) { theId = _L1Ids.begin(); theName = _L1Names.begin(); theIderEnd = _L1Ids.end(); } else if ( triggerLevel == 2 ) { theId = _L2Ids.begin(); theName = _L2Names.begin(); theIderEnd = _L2Ids.end(); } else if ( triggerLevel == 3 ) { theId = _L3Ids.begin(); theName = _L3Names.begin(); theIderEnd = _L3Ids.end(); } else return triggerName; while ( theId != theIderEnd ) { if ( triggerId == *(theId++) ) { triggerName = *theName; } //std::cout << std::endl; theName++; } return triggerName; } string TriggerMap::getNameFromBit( const int triggerBit, const int triggerLevel ) const{ string triggerName; vector::const_iterator theBit; vector::const_iterator theName; vector::const_iterator theBiterEnd; // as opposed to theBitterEnd... if ( triggerLevel == 1 ) { theBit = _L1Bits.begin(); theName = _L1Names.begin(); theBiterEnd = _L1Bits.end(); } else if ( triggerLevel == 2 ) { theBit = _L2Bits.begin(); theName = _L2Names.begin(); theBiterEnd = _L2Bits.end(); } else if ( triggerLevel == 3 ) { theBit = _L3Bits.begin(); theName = _L3Names.begin(); theBiterEnd = _L3Bits.end(); } else return triggerName; while ( theBit != theBiterEnd ) { if ( triggerBit == *(theBit++) ) { triggerName = *theName; } //std::cout << std::endl; theName++; } return triggerName; } vector TriggerMap::getBits( const string partialName, const int triggerLevel ) const{ vector triggerBits; vector::const_iterator theBit; vector::const_iterator theName; vector::const_iterator theNamerEnd; // as opposed to theBitterEnd... // convert to upper case string upperPartial = partialName; int i = upperPartial.size (); while (--i >= 0) upperPartial[i] = toupper (upperPartial[i]); //std::cout << "TriggerMap: getBits function for Level " << triggerLevel // << ", name " << upperPartial << std::endl; if ( triggerLevel == 1 ) { theBit = _L1Bits.begin(); theName = _L1Names.begin(); theNamerEnd = _L1Names.end(); } else if ( triggerLevel == 2 ) { theBit = _L2Bits.begin(); theName = _L2Names.begin(); theNamerEnd = _L2Names.end(); } else if ( triggerLevel == 3 ) { theBit = _L3Bits.begin(); theName = _L3Names.begin(); theNamerEnd = _L3Names.end(); } else return triggerBits; while ( theName != theNamerEnd ) { //std::cout << "checking trigger name " << *theName; // convert to upper case string upperTriggerName = *(theName++); int i = upperTriggerName.size (); while (--i >= 0) upperTriggerName[i] = toupper (upperTriggerName[i]); if ( upperTriggerName.find(upperPartial) != string::npos ) { triggerBits.push_back(*theBit); //std::cout << "... matched!!"; } //std::cout << std::endl; theBit++; } return triggerBits; } vector TriggerMap::getIds( const string partialName, const int triggerLevel ) const{ vector triggerIds; vector::const_iterator theId; vector::const_iterator theName; vector::const_iterator theNamerEnd; // as opposed to theBitterEnd... // convert to upper case string upperPartial = partialName; int i = upperPartial.size (); while (--i >= 0) upperPartial[i] = toupper (upperPartial[i]); //std::cout << "TriggerMap: getIds function for Level " << triggerLevel // << ", name " << upperPartial << std::endl; if ( triggerLevel == 1 ) { theId = _L1Ids.begin(); theName = _L1Names.begin(); theNamerEnd = _L1Names.end(); } else if ( triggerLevel == 2 ) { theId = _L2Ids.begin(); theName = _L2Names.begin(); theNamerEnd = _L2Names.end(); } else if ( triggerLevel == 3 ) { theId = _L3Ids.begin(); theName = _L3Names.begin(); theNamerEnd = _L3Names.end(); } else return triggerIds; while ( theName != theNamerEnd ) { //std::cout << "checking trigger name " << *theName; // convert to upper case string upperTriggerName = *(theName++); int i = upperTriggerName.size (); while (--i >= 0) upperTriggerName[i] = toupper (upperTriggerName[i]); if ( upperTriggerName.find(upperPartial) != string::npos ) { triggerIds.push_back(*theId); //std::cout << "... matched!!"; } //std::cout << std::endl; theId++; } return triggerIds; } vector TriggerMap::getBitsFromFullName( const string fullName, const int triggerLevel ) const{ vector triggerBits; vector::const_iterator theBit; vector::const_iterator theName; vector::const_iterator theNamerEnd; // as opposed to theBitterEnd... // convert to upper case string upperFull = fullName; int i = upperFull.size (); while (--i >= 0) upperFull[i] = toupper (upperFull[i]); //std::cout << "TriggerMap: getBits function for Level " << triggerLevel // << ", name " << upperFull << std::endl; if ( triggerLevel == 1 ) { theBit = _L1Bits.begin(); theName = _L1Names.begin(); theNamerEnd = _L1Names.end(); } else if ( triggerLevel == 2 ) { theBit = _L2Bits.begin(); theName = _L2Names.begin(); theNamerEnd = _L2Names.end(); } else if ( triggerLevel == 3 ) { theBit = _L3Bits.begin(); theName = _L3Names.begin(); theNamerEnd = _L3Names.end(); } else return triggerBits; while ( theName != theNamerEnd ) { //std::cout << "checking trigger name " << *theName; // convert to upper case string upperTriggerName = *(theName++); int i = upperTriggerName.size (); while (--i >= 0) upperTriggerName[i] = toupper (upperTriggerName[i]); int match = 1; if (upperFull.size() > upperTriggerName.size()) match=0; for (int i = 0; ((i < upperFull.size())&&(match)); i++) { if (upperFull[i] != upperTriggerName[i]) match=0; // std::cout << upperFull[i] << " " << upperTriggerName[i] << " | " ; } if (match){ triggerBits.push_back(*theBit); //std::cout << "... matched!!"; } // if (i==0) i++; // std::cout << std::endl << match << " " << i-1 // << " " << upperFull[i-1] << " " << upperTriggerName[i-1] // << " " << upperFull << " " << upperTriggerName << endl; //std::cout << std::endl; theBit++; } return triggerBits; } vector TriggerMap::getIdsFromFullName( const string fullName, const int triggerLevel ) const{ vector triggerIds; vector::const_iterator theId; vector::const_iterator theName; vector::const_iterator theNamerEnd; // as opposed to theBitterEnd... // convert to upper case string upperFull = fullName; int i = upperFull.size (); while (--i >= 0) upperFull[i] = toupper (upperFull[i]); //std::cout << "TriggerMap: getIds function for Level " << triggerLevel // << ", name " << upperFull << std::endl; if ( triggerLevel == 1 ) { theId = _L1Ids.begin(); theName = _L1Names.begin(); theNamerEnd = _L1Names.end(); } else if ( triggerLevel == 2 ) { theId = _L2Ids.begin(); theName = _L2Names.begin(); theNamerEnd = _L2Names.end(); } else if ( triggerLevel == 3 ) { theId = _L3Ids.begin(); theName = _L3Names.begin(); theNamerEnd = _L3Names.end(); } else return triggerIds; while ( theName != theNamerEnd ) { //std::cout << "checking trigger name " << *theName; // convert to upper case string upperTriggerName = *(theName++); int i = upperTriggerName.size (); while (--i >= 0) upperTriggerName[i] = toupper (upperTriggerName[i]); int match = 1; if (upperFull.size() > upperTriggerName.size()) match=0; for (int i = 0 ; ((i < upperFull.size())&&(match)); i++) if (upperFull[i] != upperTriggerName[i]) match=0; if (match){ triggerIds.push_back(*theId); //std::cout << "... matched!!"; } //std::cout << std::endl; theId++; } return triggerIds; } //***************************************************************************** // The End //*****************************************************************************