Attachment 'calicetemp.cc'

Download

   1 // -- C++ headers 
   2 #include <string>
   3 #include <sstream>
   4 #include <cstdlib>
   5 #include <vector>
   6 
   7 // -- Root headers
   8 #include <TFile.h>
   9 #include <TTree.h>
  10 
  11 // -- LCIO headers
  12 #include "UTIL/LCTime.h"
  13 #define NPS 1000000000LL
  14 
  15 // -- LCCD headers
  16 #include "lccd/DBInterface.hh"
  17 #include "LCCondObjectMgr.hh"
  18 
  19 // -- CondDB headers
  20 #include "ConditionsDB/CondDBMySQLMgrFactory.h"
  21 #include "ConditionsDB/CondDBException.h"
  22 #include "ConditionsDB/SimpleTime.h"
  23 
  24 // -- calice userlib
  25 #include "AhcSlowReadoutModBlock.hh"
  26 
  27 ICondDBMgr* condDBmgr;
  28 string initstring ("flccaldb02.desy.de:calice:caliceon:Delice.1:3306");
  29 vector <std::string> folders;
  30 string treeFileName ("calicetemps.root");
  31 string treeName ("calicetemps");
  32 TTree *outputTree;
  33 Float_t temperature[7];
  34 Float_t hbabtemperature[4];
  35 Float_t hbabvoltage[12];
  36 UShort_t moduleID;
  37 ULong64_t sinceTimeStamp;
  38 ULong64_t tillTimeStamp;  
  39 bool overwrite=true;
  40 bool show_help=false;
  41 bool custom_folders=false;
  42 
  43 void print_help(const char *prg_name)
  44 {
  45   std::cout << prg_name << " [--help] [--initstring initstring] [--folder foldername] \\" << std::endl
  46 	    << "\t\t[--file filename] [--tree treename]" << std::endl
  47 	    << std::endl
  48 	    << "--help                       this text."<< std::endl
  49 	    << "--initstring initstring      init string for the database connection." << std::endl
  50             << "--folder foldername          folder name in the database." << std::endl
  51             << "--file filename              name of the root file written." << std::endl
  52             << "--tree treename              name of the tree in the root file written." << std::endl;
  53 }
  54 
  55 void initConnection() throw(CondDBException)
  56 {
  57   condDBmgr = CondDBMySQLMgrFactory::createCondDBMgr();
  58   condDBmgr->init(initstring);                        	
  59   condDBmgr->startRead();
  60   condDBmgr->openDatabase();
  61   condDBmgr->commit();
  62   
  63   TFile *tree_file=new TFile(treeFileName.c_str(),(overwrite ? "RECREATE" : "UPDATE"));
  64   if (!tree_file->IsOpen()) {
  65     delete tree_file;
  66     tree_file=new TFile(treeFileName.c_str(),"NEW");
  67   }
  68   outputTree = new TTree(treeName.c_str(),treeName.c_str());
  69   outputTree->SetAutoSave(32*1024*1024);
  70   outputTree->Branch("Temperature", &temperature, "T1/F:T2/F:T3/F:T4/F:T5/F:TCMBU/F:TCMBL/F");
  71   outputTree->Branch("HBABTemperature", &hbabtemperature, "THbabT1/F:THbabT2/F:THbabB1/F:THbabB2/F");
  72   outputTree->Branch("HBABVoltage", &hbabvoltage, "HvHbabTV/F:HvHbabBV/F:HvHbabTC/F:HVHbabBC/F:LvPHbabTV/F:LvPHbabBV/F:LvPHbabTC/F:LvPHbabBC/F:LvNHbabTV/F:LvNHbabBV/F:LvNHbabTC/F:LvNHbabBC/F");
  73   outputTree->Branch("ModuleID", &moduleID, "ModuleID/s");
  74   outputTree->Branch("Start", &sinceTimeStamp, "Start/l");
  75   outputTree->Branch("End", &tillTimeStamp, "End/l");
  76 }
  77 
  78 
  79 void closeConnection()
  80 {
  81   if (outputTree) {
  82     TFile *tree_file = outputTree->GetCurrentFile();
  83     tree_file->Write();
  84     delete tree_file;
  85   }
  86   CondDBMySQLMgrFactory::destroyCondDBMgr(condDBmgr); 
  87 }
  88 
  89 
  90 void printObj(ICondDBObject* condDBobj, const string folder, const string tag)
  91 {
  92   CondDBKey since(condDBobj->validSince());
  93   CondDBKey till(condDBobj->validTill());
  94   SimpleTime insertionTime; 
  95   condDBobj->insertionTime(insertionTime);
  96   long layerNum(condDBobj->layer()); 
  97   std::string description;
  98   condDBobj->description(description);
  99   UTIL::LCTime sincetimestamp(since);
 100   UTIL::LCTime tilltimestamp(till);
 101     
 102   lccd::DBInterface* db = new lccd::DBInterface(initstring, folder);
 103   lcio::LCCollection* col = db->findCollection(since, tag);
 104   for (unsigned int imod=0; imod < static_cast<unsigned int>(col->getNumberOfElements()); imod++) {
 105     CALICE::AhcSlowReadoutModBlock ahcSroModBlock(col->getElementAt(imod)); 
 106     unsigned icmbtemp=0;
 107     std::vector<double> cmbTemperatures(ahcSroModBlock.getCmbTemperatures());
 108     for (std::vector<double>::iterator vec_iter = cmbTemperatures.begin(); vec_iter != cmbTemperatures.end(); vec_iter++) {
 109       if (icmbtemp<7) temperature[icmbtemp] = (*vec_iter);
 110       icmbtemp++;
 111     }
 112     unsigned ihbabtemps=0;
 113     std::vector<double> hbabTemperatures(ahcSroModBlock.getHbabTemperatures());
 114     for (std::vector<double>::iterator vec_iter = hbabTemperatures.begin(); vec_iter != hbabTemperatures.end(); vec_iter++) {
 115       if (ihbabtemps<4) hbabtemperature[ihbabtemps] = (*vec_iter);
 116       ihbabtemps++;
 117     }
 118     unsigned ihbabvolts=0;
 119     std::vector<double> hbabVoltages(ahcSroModBlock.getHbabVoltages());
 120     for (std::vector<double>::iterator vec_iter = hbabVoltages.begin(); vec_iter != hbabVoltages.end(); vec_iter++) {
 121       if (ihbabvolts<12) hbabvoltage[ihbabvolts] = (*vec_iter);
 122       ihbabvolts++;
 123     }
 124     moduleID = ahcSroModBlock.getModuleNumber();
 125     sinceTimeStamp = since / NPS;
 126     tillTimeStamp = till / NPS;
 127     outputTree->Fill();
 128     
 129     std::cout << sincetimestamp.getDateString().c_str() << "-"
 130               << tilltimestamp.getDateString().c_str() << ": (" 
 131 	      << ahcSroModBlock.getModuleNumber() << ") "  
 132 //              << temperature[0] << ", " << temperature[1] << ", " << temperature[2] << ", " 
 133 //              << temperature[3] << ", " << temperature[4] << ", " << temperature[5] << ", "
 134 //	      << temperature[6] << ", " 
 135 //	      << hbabtemperature[0] << ", " << hbabtemperature[1] << ", " << hbabtemperature[2] << ", "
 136 //	      << hbabtemperature[3] << std::endl;
 137               << hbabvoltage[0] << std::endl;
 138   }
 139   std::cout << std::endl;  
 140   delete db;
 141 }
 142 
 143 
 144 void iterObjectsH(const string folder, const string tag) throw(CondDBException)
 145 {
 146   condDBmgr->startRead();
 147   ICondDBDataAccess* condDataAccess = condDBmgr->getCondDBDataAccess();
 148   ICondDBDataIterator* iterObjs = 0;
 149   condDataAccess->browseObjectsInTag(iterObjs, folder, tag == "HEAD" ? "" : tag);
 150   condDBmgr->commit();
 151     
 152   if (iterObjs == 0) {
 153     std::cerr << "No objects for tag " << tag << " in folder " << folder << "." << std::endl;
 154     return;
 155   }
 156   do {
 157     printObj(iterObjs->current(), folder, tag=="HEAD" ? "" : tag);
 158   } while (iterObjs->next());
 159   delete iterObjs;
 160 }
 161 
 162 
 163 int main (int argc, char* argv[])
 164 { 
 165   folders.push_back(std::string("/cd_calice_v0402_cerncomb/CALDAQ_AhcSroModData")); 
 166   folders.push_back(std::string("/cd_calice_v0402_cernhcal/CALDAQ_AhcSroModData"));
 167   folders.push_back(std::string("/cd_calice_v0402_cernecal/CALDAQ_AhcSroModData"));
 168 
 169   try {
 170     const UInt_t n_args=static_cast<UInt_t>(argc);
 171     for (UInt_t arg_i=1; arg_i<n_args; arg_i++) {
 172       if (strcmp(argv[arg_i],"--initstring")==0) {
 173 	if (arg_i+1>=n_args) {
 174 	  throw std::runtime_error("expected string argument for --initstring");
 175 	}
 176 	initstring=argv[++arg_i];
 177       }
 178       else if (strcmp(argv[arg_i],"--folder")==0) {
 179 	if (arg_i+1>=n_args) {
 180 	  throw std::runtime_error("expected string argument for --folder");
 181 	}
 182 	if (!custom_folders) folders.clear();
 183 	custom_folders = true;
 184 	folders.push_back(argv[++arg_i]);
 185      }
 186       else if (strcmp(argv[arg_i],"--file")==0) {
 187 	if (arg_i+1>=n_args) {
 188 	  throw std::runtime_error("expected string argument for --file");
 189 	}
 190 	treeFileName=argv[++arg_i];
 191       }
 192       else if (strcmp(argv[arg_i],"--tree")==0) {
 193 	if (arg_i+1>=n_args) {
 194 	  throw std::runtime_error("expected string argument for --tree");
 195 	}
 196 	treeName=argv[++arg_i];
 197       }
 198       else if (strcmp(argv[arg_i],"--help")==0) {
 199 	show_help=true;
 200       }
 201       else {
 202 	std::stringstream message;
 203 	message << "unknown argument \"" << argv[arg_i] << "\".";
 204 	throw std::runtime_error(message.str());
 205       }
 206     }
 207   }  
 208   catch (std::exception &error) {
 209     print_help(argv[0]);
 210     std::cerr << "Error while parsing arguments:" << error.what() << std::endl;
 211     return -2;
 212   }        
 213   if (show_help) {
 214     print_help(argv[0]);
 215     return -1;
 216   }
 217         
 218   try {
 219     initConnection();
 220     for (std::vector<std::string>::iterator vec_iter = folders.begin(); vec_iter != folders.end(); vec_iter++) {
 221       iterObjectsH(*vec_iter,"HEAD");
 222     }
 223   }  
 224   catch (CondDBException &e) {
 225     std::cerr << "# ConditionsDB [" << e.getErrorCode() << "]: " << e.getMessage() << std::endl;
 226   }  
 227   closeConnection();
 228 }

Attached Files

To refer to attachments on a page, use attachment:filename, as shown below in the list of files. Do NOT use the URL of the [get] link, since this is subject to change and can break easily.
  • [get | view] (2008-10-30 14:41:45, 8.0 KB) [[attachment:calicetemp.cc]]
 All files | Selected Files: delete move to page copy to page

You are not allowed to attach a file to this page.