Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 14:14:50

0001 #include <cppunit/TestFixture.h>
0002 #include <cppunit/extensions/HelperMacros.h>
0003 #include <cppunit/TestResult.h>
0004 #include <cppunit/TestRunner.h>
0005 #include <cppunit/ui/text/TestRunner.h>
0006 #include <cppunit/TestResultCollector.h>
0007 #include <cppunit/TextTestProgressListener.h>
0008 #include <cppunit/CompilerOutputter.h>
0009 
0010 #include <vector>
0011 
0012 #include "CalibTracker/SiStripDCS/interface/SiStripDetVOffBuilder.h"
0013 
0014 std::vector<int> vectorDate(const int year,
0015                             const int month,
0016                             const int day,
0017                             const int hour,
0018                             const int minute,
0019                             const int second,
0020                             const int microsecond) {
0021   std::vector<int> timeVector;
0022   timeVector.push_back(year);
0023   timeVector.push_back(month);
0024   timeVector.push_back(day);
0025   timeVector.push_back(hour);
0026   timeVector.push_back(minute);
0027   timeVector.push_back(second);
0028   timeVector.push_back(microsecond);
0029   return timeVector;
0030 }
0031 
0032 class TestSiStripDetVOffBuilder : public CppUnit::TestFixture {
0033 public:
0034   TestSiStripDetVOffBuilder() {}
0035 
0036   void setUp() {
0037     edm::ParameterSet pset;
0038     // Must set the string type explicitly or it will take it as bool
0039     pset.addParameter("onlineDB", std::string("onlineDBString"));
0040     pset.addParameter("authPath", std::string("authPathString"));
0041     pset.addParameter("queryType", std::string("STATUSCHANGE"));
0042     pset.addParameter("lastValueFile", std::string("lastValueFileString"));
0043     pset.addParameter("lastValueFromFile", false);
0044 
0045     pset.addParameter("debugModeOn", true);
0046 
0047     pset.addParameter("Tmin", vectorDate(2009, 12, 7, 12, 0, 0, 000));
0048     pset.addParameter("Tmax", vectorDate(2009, 12, 8, 9, 0, 0, 000));
0049     pset.addParameter("TSetMin", vectorDate(2007, 11, 26, 0, 0, 0, 0));
0050     pset.addParameter<uint32_t>("DeltaTmin", 2);
0051     pset.addParameter<uint32_t>("MaxIOVlength", 90);
0052     pset.addParameter("DetIdListFile", std::string("CalibTracker/SiStripCommon/data/SiStripDetInfo.dat"));
0053     pset.addParameter("ExcludedDetIdListFile", std::string(""));
0054     pset.addParameter("HighVoltageOnThreshold", 0.97);
0055     pset.addParameter("PsuDetIdMapFile", std::string("CalibTracker/SiStripDCS/data/PsuDetIdMap.dat"));
0056 
0057     object = new SiStripDetVOffBuilder(pset, edm::ActivityRegistry());
0058     detVoff = new SiStripDetVOff;
0059   }
0060 
0061   void tearDown() {
0062     delete object;
0063     delete detVoff;
0064   }
0065 
0066   void testConstructor() {
0067     CPPUNIT_ASSERT(object->highVoltageOnThreshold_ == 0.97);
0068     CPPUNIT_ASSERT(object->whichTable == "STATUSCHANGE");
0069   }
0070 
0071   // Factorize the methods in SiStripDetVOffBuilder, do not call
0072   // coralInterface, but provide a list of modules built here.
0073 
0074   void testStatusChange() {
0075     object->coralInterface.reset(
0076         new SiStripCoralIface(object->onlineDbConnectionString, object->authenticationPath, false));
0077     SiStripDetVOffBuilder::TimesAndValues tStruct;
0078     object->statusChange(object->lastStoredCondObj.second, tStruct);
0079     CPPUNIT_ASSERT(tStruct.actualStatus.size() != 0);
0080   }
0081   void testBuildDetVOffObj() {
0082     // CPPUNIT_ASSERT( object->BuildDetVOffObj() );
0083   }
0084 
0085   void testReduction() {
0086     fillModulesOff();
0087 
0088     cout << "number of IOVs before reduction = " << object->modulesOff.size() << endl;
0089 
0090     object->reduction(1, 1000);
0091 
0092     cout << "number of IOVs after reduction = " << object->modulesOff.size() << endl;
0093     vector<pair<SiStripDetVOff *, cond::Time_t> >::const_iterator iovContent = object->modulesOff.begin();
0094     for (; iovContent != object->modulesOff.end(); ++iovContent) {
0095       coral::TimeStamp coralTime(object->getCoralTime(iovContent->second));
0096       cout << "iov seconds = " << coralTime.second() << ", nanoseconds = " << coralTime.nanosecond();
0097       cout << ", number of modules with HV off = " << iovContent->first->getHVoffCounts() << endl;
0098       cout << ", number of modules with LV off = " << iovContent->first->getLVoffCounts() << endl;
0099     }
0100 
0101     CPPUNIT_ASSERT(object->modulesOff.size() == 5);
0102   }
0103 
0104   void fillModulesOff() {
0105     // Initialization: all off
0106     fillModule(1, 1, 1, 0, 0);
0107     fillModule(2, 1, 1, 0, 1000);
0108     fillModule(3, 1, 1, 0, 2000);
0109 
0110     // Ramping up phase: LV going on
0111     fillModule(1, 1, 0, 5, 0);
0112     fillModule(2, 1, 0, 5, 1000);
0113     fillModule(3, 1, 0, 5, 2000);
0114     // HV going on
0115     fillModule(1, 0, 0, 10, 0);
0116     fillModule(2, 0, 0, 10, 1000);
0117     fillModule(3, 0, 0, 10, 2000);
0118 
0119     // Wait some time, then switch off HV
0120     fillModule(1, 1, 0, 15, 0);
0121     fillModule(2, 1, 0, 15, 1000);
0122     fillModule(3, 1, 0, 15, 2000);
0123     // LV off
0124     fillModule(1, 1, 1, 20, 0);
0125     fillModule(2, 1, 1, 20, 1000);
0126     fillModule(3, 1, 1, 20, 2000);
0127 
0128     // fillModule( 3,  1, 0,  25, 0 );
0129   }
0130 
0131   void fillModule(const unsigned int detId,
0132                   const unsigned int HVoff,
0133                   const unsigned int LVoff,
0134                   const unsigned int seconds,
0135                   const unsigned int nanoseconds) {
0136     // Build the cond time from the
0137     cond::Time_t condTime = object->getCondTime(coral::TimeStamp(2009, 12, 1, 1, 0, seconds, nanoseconds));
0138     // Carefull, there is a memory leakage here. Fine if the program is kept simple.
0139     detVoff->put(detId, HVoff, LVoff);
0140     SiStripDetVOff *localDetVoff = new SiStripDetVOff(*detVoff);
0141     object->modulesOff.push_back(make_pair(localDetVoff, condTime));
0142   }
0143 
0144   // Declare and build the test suite
0145   CPPUNIT_TEST_SUITE(TestSiStripDetVOffBuilder);
0146   CPPUNIT_TEST(testConstructor);
0147   // CPPUNIT_TEST( testStatusChange );
0148   CPPUNIT_TEST(testReduction);
0149   CPPUNIT_TEST_SUITE_END();
0150 
0151   SiStripDetVOffBuilder *object;
0152   SiStripDetVOff *detVoff;
0153 };
0154 
0155 // Register the test suite in the registry.
0156 // This way we will have to only pass the registry to the runner
0157 // and it will contain all the registered test suites.
0158 CPPUNIT_TEST_SUITE_REGISTRATION(TestSiStripDetVOffBuilder);