Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:23:15

0001 #include <iostream>
0002 #include <string>
0003 #include <vector>
0004 #include <time.h>
0005 
0006 #include "OnlineDB/EcalCondDB/interface/EcalCondDBInterface.h"
0007 #include "OnlineDB/EcalCondDB/interface/all_monitoring_types.h"
0008 #include "OnlineDB/EcalCondDB/interface/all_od_types.h"
0009 
0010 
0011 using namespace std;
0012 
0013 class CondDBApp {
0014 public:
0015 
0016   /**
0017    *   App constructor; Makes the database connection
0018    */
0019   CondDBApp(string host, string sid, string user, string pass)
0020   {
0021     try {
0022       cout << "Making connection..." << flush;
0023       econn = new EcalCondDBInterface( sid, user, pass );
0024       cout << "Done." << endl;
0025     } catch (runtime_error &e) {
0026       cerr << e.what() << endl;
0027       exit(-1);
0028     }
0029 
0030     locations[0] = "H4";
0031     locations[1] = "867-1";
0032     locations[2] = "867-2";
0033     locations[3] = "867-3";
0034   }
0035 
0036 
0037 
0038   /**
0039    *  App destructor;  Cleans up database connection
0040    */
0041   ~CondDBApp() 
0042   {
0043     delete econn;
0044   }
0045 
0046 
0047   RunIOV makeRunIOV(int run_num)
0048   {
0049     // The objects necessary to identify a dataset
0050     LocationDef locdef;
0051     RunTypeDef rundef;
0052     RunTag runtag;
0053 
0054     locdef.setLocation("P5_Co");
0055 
0056     rundef.setRunType("COSMIC");
0057     runtag.setLocationDef(locdef);
0058     runtag.setRunTypeDef(rundef);
0059     runtag.setGeneralTag("GLOBAL");
0060 
0061     // Our beginning time will be the current GMT time
0062     // This is the time zone that should be written to the DB!
0063     // (Actually UTC)
0064     Tm startTm;
0065     startTm.setToCurrentGMTime();
0066     uint64_t microseconds = startTm.microsTime();
0067     startTm.setToMicrosTime(microseconds);
0068 
0069     // Our beginning run number will be the seconds representation
0070     // of that time, and we will increment our IoV based on 
0071     // a microsecond representation
0072 
0073 
0074     cout << "Run Time:    " << startTm.str() << endl;
0075     cout << "Run Number:     " << run_num << endl;
0076 
0077     // Set the properties of the iov
0078     RunIOV runiov;
0079 
0080     runiov.setRunNumber(run_num);
0081     runiov.setRunStart(startTm);
0082     runiov.setRunTag(runtag);
0083     
0084     return runiov;
0085   }
0086 
0087 
0088 
0089 
0090   /**
0091    *  Write MonPedestalsDat objects with associated RunTag and RunIOVs
0092    *  IOVs are written using automatic updating of the 'RunEnd', as if
0093    *  the time of the end of the run was not known at the time of writing.
0094    */
0095   void testWrite(int run_num, string config_tag)
0096   {
0097     cout << "Writing to database..." << endl;
0098     RunIOV runiov = this->makeRunIOV(run_num);
0099     RunTag runtag = runiov.getRunTag();
0100     run_t run = runiov.getRunNumber();
0101 
0102     // write to the DB
0103     cout << "Inserting run..." << flush;
0104     econn->insertRunIOV(&runiov);
0105     cout << "Done." << endl;
0106     printIOV(&runiov);
0107 
0108     int c = 1;
0109     EcalLogicID ecid;
0110     ecid = econn->getEcalLogicID("ECAL");
0111 
0112     // recuperare last version !!!
0113 
0114     FEConfigMainInfo cfg_info;
0115     cfg_info.setConfigTag(config_tag);
0116     econn->fetchConfigSet(&cfg_info);
0117 
0118 
0119     int iversion= cfg_info.getVersion();
0120 
0121 
0122     // Set the data
0123     RunTPGConfigDat cfgdat;
0124     map<EcalLogicID, RunTPGConfigDat> dataset;
0125 
0126     cfgdat.setConfigTag(config_tag);
0127     cfgdat.setVersion(iversion);
0128 
0129     // Fill the dataset
0130     dataset[ecid] = cfgdat;
0131 
0132     // Insert the dataset, identifying by iov
0133     cout << "Inserting dataset..." << flush;
0134     econn->insertDataSet(&dataset, &runiov);
0135     cout << "Done." << endl;
0136 
0137 
0138 
0139     cout << "Done." << endl << endl << endl;
0140   };
0141 
0142 
0143 
0144 private:
0145   CondDBApp();  // hidden default constructor
0146   EcalCondDBInterface* econn;
0147   string locations[4];
0148   uint64_t startmicros;
0149   uint64_t endmicros;
0150   run_t startrun;
0151   run_t endrun;
0152 
0153   int tablesTried;
0154   int tablesOK;
0155 
0156   /**
0157    *   Iterate through the dataset and print some data
0158    */
0159 
0160 
0161   /**
0162    *   Print out a RunTag
0163    */
0164   void printTag( const RunTag* tag) const
0165   {
0166     cout << endl;
0167     cout << "=============RunTag:" << endl;
0168     cout << "GeneralTag:         " << tag->getGeneralTag() << endl;
0169     cout << "Location:           " << tag->getLocationDef().getLocation() << endl;
0170     cout << "Run Type:           " << tag->getRunTypeDef().getRunType() << endl;
0171     cout << "====================" << endl;
0172   }
0173 
0174   void printIOV( const RunIOV* iov) const
0175   {
0176     cout << endl;
0177     cout << "=============RunIOV:" << endl;
0178     RunTag tag = iov->getRunTag();
0179     printTag(&tag);
0180     cout << "Run Number:         " << iov->getRunNumber() << endl;
0181     cout << "Run Start:          " << iov->getRunStart().str() << endl;
0182     cout << "Run End:            " << iov->getRunEnd().str() << endl;
0183     cout << "====================" << endl;
0184   }
0185 };
0186 
0187 
0188 
0189 int main (int argc, char* argv[])
0190 {
0191   string host;
0192   string sid;
0193   string user;
0194   string pass;
0195   int run_num;
0196   string config_tag;
0197 
0198   if (argc != 7) {
0199     cout << "Usage:" << endl;
0200     cout << "  " << argv[0] << " <host> <SID> <user> <pass> <run_num> <config_tag>" 
0201      << endl;
0202     exit(-1);
0203   }
0204 
0205   host = argv[1];
0206   sid = argv[2];
0207   user = argv[3];
0208   pass = argv[4];
0209   run_num = atoi(argv[5]);
0210   config_tag = argv[6];
0211 
0212   try {
0213     CondDBApp app(host, sid, user, pass);
0214 
0215     app.testWrite(run_num, config_tag);
0216 
0217   } catch (exception &e) {
0218     cout << "ERROR:  " << e.what() << endl;
0219   } catch (...) {
0220     cout << "Unknown error caught" << endl;
0221   }
0222 
0223   cout << "All Done." << endl;
0224 
0225   return 0;
0226 }