Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 13:32:14

0001 #include <iostream>
0002 #include <string>
0003 #include <vector>
0004 #include <time.h>
0005 #include <cstdlib>
0006 #include "OnlineDB/EcalCondDB/interface/EcalCondDBInterface.h"
0007 #include "OnlineDB/EcalCondDB/interface/RunTag.h"
0008 #include "OnlineDB/EcalCondDB/interface/RunIOV.h"
0009 #include "OnlineDB/EcalCondDB/interface/MonRunTag.h"
0010 #include "OnlineDB/EcalCondDB/interface/MonRunIOV.h"
0011 #include "OnlineDB/EcalCondDB/interface/MonPedestalsDat.h"
0012 
0013 
0014 using namespace std;
0015 
0016 class CondDBApp {
0017 public:
0018 
0019   /**
0020    *   App constructor; Makes the database connection
0021    */
0022   CondDBApp(string host, string sid, string user, string pass)
0023   {
0024     try {
0025       cout << "Making connection..." << flush;
0026       if (host != "?") {
0027     econn = new EcalCondDBInterface(host, sid, user, pass );
0028       } else {
0029     econn = new EcalCondDBInterface( sid, user, pass );
0030       }
0031       cout << "Done." << endl;
0032     } catch (runtime_error &e) {
0033       cerr << e.what() << endl;
0034       exit(-1);
0035     }
0036   }
0037 
0038 
0039 
0040   /**
0041    *  App destructor;  Cleans up database connection
0042    */
0043   ~CondDBApp() 
0044   {
0045     delete econn;
0046   }
0047 
0048 
0049   /**
0050    *  Write MonPedestalsDat objects with associated RunTag and RunIOVs
0051    *  IOVs are written using automatic updating of the 'RunEnd', as if
0052    *  the time of the end of the run was not known at the time of writing.
0053    */
0054   void testWrite(int startrun, int numruns)
0055   {
0056     // initial run
0057     run_t run = startrun;
0058 
0059     cout << "Writing MonPedestalsDat Objects to database..." << endl;
0060     // The objects necessary to identify a dataset
0061     LocationDef locdef;
0062     RunTypeDef rundef;
0063     RunTag runtag;
0064     RunIOV runiov;
0065 
0066     MonVersionDef monverdef;
0067     MonRunTag montag;
0068     MonRunIOV moniov;
0069 
0070     Tm startTm;
0071     Tm endTm;
0072     uint64_t oneMin = 1 * 60 * 1000000;
0073     uint64_t twentyMin = 20 * 60 * 1000000;
0074 
0075     // Set the beginning time
0076     startTm.setToString("2007-01-01 00:00:00");
0077     uint64_t microseconds = startTm.microsTime();
0078     microseconds += (startrun-1)*twentyMin;
0079 
0080     // The number of channels and IOVs we will write
0081 
0082     // The objects necessary to define a dataset
0083     EcalLogicID ecid;
0084     map<EcalLogicID, MonPedestalsDat> dataset;
0085 
0086     // Set the properties of the tag
0087     // The objects necessary to identify a dataset
0088     locdef.setLocation("H4");
0089     rundef.setRunType("PEDESTAL");
0090     
0091     runtag.setLocationDef(locdef);
0092     runtag.setRunTypeDef(rundef);
0093 
0094     runiov.setRunTag(runtag);
0095 
0096     monverdef.setMonitoringVersion("test01");
0097     montag.setMonVersionDef(monverdef);
0098 
0099     moniov.setMonRunTag(montag);
0100 
0101 
0102 
0103 
0104     // Get a set of channels to use
0105     cout << "Getting EB channel set..." << flush;
0106     vector<EcalLogicID> channels_barrel;
0107     channels_barrel = econn->getEcalLogicIDSet("EB_crystal_number",
0108                     1, 36,   // SM
0109                     1, 1700 // crystal
0110                     ,EcalLogicID::NULLID, EcalLogicID::NULLID, "EB_crystal_number");
0111     cout << "Done size is:"<< channels_barrel.size() << endl;
0112 
0113 
0114 
0115     // Get a set of channels to use
0116     cout << "Getting EE channel set..." << flush;
0117     vector<EcalLogicID> channels;
0118     channels = econn->getEcalLogicIDSet("EE_crystal_number",
0119                     -1, 1,   // z 
0120                     -110, 100, // crystal x
0121                     -110 ,100, "EE_crystal_number"); // crystal y
0122     cout << "Done." << endl;
0123 
0124     // Get a set of channels to use
0125     cout << "Getting ECAL channel..." << flush;
0126     EcalLogicID channel_ecal;
0127     channel_ecal = econn->getEcalLogicID("ECAL");
0128     cout << "Done." << endl;
0129 
0130 
0131     cout << "Writing " << numruns << " sets of pedestals..." << endl;
0132     for (int i=1; i<=numruns; i++) {  // For every IOV we will write
0133       // Set the properties of the runiov
0134       startTm.setToMicrosTime(microseconds);
0135       endTm.setToMicrosTime(microseconds + oneMin);
0136       runiov.setRunNumber(run);
0137       runiov.setRunStart(startTm);
0138       runiov.setRunEnd(endTm);
0139 
0140       // Write runiov
0141       econn->insertRunIOV(&runiov);
0142 
0143       map<EcalLogicID, RunTPGConfigDat> dataset_tpg;
0144       RunTPGConfigDat rtpg;
0145       rtpg.setConfigTag("TPGTrivial_config");
0146       dataset_tpg[channel_ecal]=rtpg;
0147       // Insert the dataset, identifying by moniov
0148       cout << "Writing IOV " << i << " of " << numruns 
0149        << " (run " << run << ")..." << flush;
0150       econn->insertDataSet(&dataset_tpg, &runiov );
0151       cout << "Done." << endl;
0152 
0153 
0154       // Set the properties of the moniov
0155       moniov.setRunIOV(runiov);
0156       moniov.setSubRunNumber(0);
0157       moniov.setSubRunStart(startTm);
0158       moniov.setSubRunEnd(endTm);
0159 
0160 
0161 
0162       for (int j=0; j<(int)channels.size(); j++) {
0163 
0164     MonPedestalsDat ped;
0165       
0166     // Set the data
0167     float val = 1 + rand();
0168     ped.setPedMeanG1(val);
0169     ped.setPedMeanG6(val);
0170     ped.setPedMeanG12(val);
0171     ped.setPedRMSG1(val);
0172     ped.setPedRMSG6(val);
0173     ped.setPedRMSG12(val);
0174     ped.setTaskStatus(1);
0175     
0176     // Fill the dataset
0177     dataset[channels[j]] = ped;
0178       }
0179 
0180       // Insert the dataset, identifying by moniov
0181       cout << "Writing IOV " << i << " of " << numruns 
0182        << " (run " << run << ")..." << flush;
0183       econn->insertDataArraySet(&dataset, &moniov );
0184       cout << "Done." << endl;
0185 
0186     map<EcalLogicID, MonPedestalsDat> dataset_bar;
0187 
0188       for (int j=0; j<(int)channels_barrel.size(); j++) {
0189       
0190     // Set the data
0191     MonPedestalsDat ped;
0192     float val = 1 + rand();
0193     ped.setPedMeanG1(val);
0194     ped.setPedMeanG6(val);
0195     ped.setPedMeanG12(val);
0196     ped.setPedRMSG1(val);
0197     ped.setPedRMSG6(val);
0198     ped.setPedRMSG12(val);
0199     ped.setTaskStatus(1);
0200     
0201     // Fill the dataset
0202     dataset_bar[channels_barrel[j]] = ped;
0203       }
0204 
0205       // Insert the dataset, identifying by moniov
0206       cout << "Writing IOV " << i << " of " << numruns 
0207        << " (run " << run << ")..." << flush;
0208       econn->insertDataArraySet(&dataset_bar, &moniov );
0209       cout << "Done." << endl;
0210 
0211       // Increment IOV run, start_time
0212       run++;  // one run
0213       microseconds += twentyMin;
0214     }
0215     cout << "Done." << endl << endl;
0216   }
0217 
0218 
0219 
0220 private:
0221   CondDBApp();  // hidden default constructor
0222   EcalCondDBInterface* econn;
0223 };
0224 
0225 
0226 
0227 int main (int argc, char* argv[])
0228 {
0229   string host;
0230   string sid;
0231   string user;
0232   string pass;
0233   int startrun;
0234   int numruns;
0235 
0236   if (argc != 7) {
0237     cout << "Usage:" << endl;
0238     cout << "  " << argv[0] << " <host> <SID> <user> <pass> <start run> <num runs>" << endl;
0239     exit(-1);
0240   }
0241 
0242   host = argv[1];
0243   sid = argv[2];
0244   user = argv[3];
0245   pass = argv[4];
0246   startrun = atoi(argv[5]);
0247   numruns = atoi(argv[6]);
0248 
0249   try {
0250     cout << "Host:  " << host << endl;
0251     cout << "SID:   " << sid << endl;
0252     cout << "User:  " << user << endl;
0253     
0254     CondDBApp app(host, sid, user, pass);
0255 
0256     app.testWrite(startrun, numruns);
0257   } catch (runtime_error &e) {
0258     cout << "ERROR:  " << e.what() << endl;
0259   } catch (...) {
0260     cout << "Unknown error caught" << endl;
0261   }
0262 
0263   cout << "All Done." << endl;
0264 
0265   return 0;
0266 }